Siteβ―Builder
Editing:
tools-hours.php
writable 0666
<?php /************************************************************************** * HOURS MODULE βΒ v4.3 Β (βNovΒ 11β label finally renders correctly) **************************************************************************/ if (function_exists('get_hours')) { $hoursData = get_hours(); } else { $jsonFile = dirname(__DIR__, 2) . '/hours.json'; $hoursData = is_readable($jsonFile) ? json_decode(file_get_contents($jsonFile), true) ?: [] : []; } if (!$hoursData) return; /* ββ unpack βββββββββββββββββββββββββββββββββββββββββββββ */ $tzLabel = $hoursData['timezone'] ?? ''; $weekly = $hoursData['weekly'] ?? []; $specials = $hoursData['special'] ?? []; /* ββ order weekdays βββββββββββββββββββββββββββββββββββββ */ $dayOrder=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']; usort($weekly, fn($a,$b)=>array_search($a['day'],$dayOrder)<=>array_search($b['day'],$dayOrder)); function fmtTime(string $t): string { if (!preg_match('/^(\d{1,2}):(\d{2})$/', $t, $m)) return htmlspecialchars($t); [$h,$min] = [(int)$m[1], $m[2]]; $ampm = $h >= 12 ? 'pm' : 'am'; $h = $h % 12 ?: 12; return $h . ($min === '00' ? '' : ':' . $min) . $ampm; } /* ββ keep specials within nextΒ 180β―days βββββββββββββββββ */ $today = new DateTimeImmutable('today'); $cut = $today->modify('+180 days'); $specials = array_filter($specials, function ($s) use ($today, $cut) { $raw = $s['date'] ?? ''; $d = DateTimeImmutable::createFromFormat('Y-m-d', $raw) ?: DateTimeImmutable::createFromFormat(DATE_ATOM, $raw); return $d && $d >= $today && $d <= $cut; }); if (!$weekly && !$specials) return; ?> <section class="hrs-shell"> <div class="hrs-card"> <h2>πΒ HoursΒ ofΒ Operation</h2> <?php if ($weekly): ?> <table class="hrs-table"> <?php foreach ($weekly as $row): ?> <tr> <td class="day"><?= htmlspecialchars($row['day']) ?></td> <td class="time"> <?php if (!empty($row['closed'])): ?> <span class="closed">Closed</span> <?php else: ?> <?= fmtTime($row['open']) ?>β―ββ―<?= fmtTime($row['close']) ?> <?php endif; ?> </td> </tr> <?php endforeach; ?> </table> <?php endif; ?> <?php if ($specials): ?> <h3 class="sp-heading">SpecialΒ Dates</h3> <ul class="sp-list"> <?php foreach ($specials as $s): $raw = $s['date'] ?? ''; $d = DateTimeImmutable::createFromFormat('Y-m-d', $raw) ?: DateTimeImmutable::createFromFormat(DATE_ATOM, $raw); /* β escape FIRST, then replace space with nbsp */ $label = $d ? str_replace(' ', ' ', htmlspecialchars($d->format('M j'))) : htmlspecialchars($raw); ?> <li> <strong><?= $label ?>:</strong> <?php if (!empty($s['closed'])): ?> Closed<?= !empty($s['note']) ? ' βΒ ' . htmlspecialchars($s['note']) : '' ?> <?php else: ?> <?= fmtTime($s['open']) ?>β―ββ―<?= fmtTime($s['close']) ?> <?= !empty($s['note']) ? ' βΒ ' . htmlspecialchars($s['note']) : '' ?> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php endif; ?> <?php if ($tzLabel): ?> <div class="tz-note">Times shown: <?= htmlspecialchars($tzLabel) ?></div> <?php endif; ?> </div> </section> <style> /* ------------ layout ------------ */ .hrs-shell{margin:2.6rem auto;max-width:clamp(480px,70vw,720px);width:100%; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif} .hrs-card{background:#fff;padding:1.8rem 1.6rem;border:3.5px solid #ffb63b; border-radius:27px;box-shadow:0 8px 26px rgba(0,0,0,.06);text-align:center} .hrs-card h2{margin:0 0 1rem;font-size:1.35rem;font-weight:700;color:#102a66} /* weekly table */ .hrs-table{width:100%;border-collapse:collapse;margin:0 auto;max-width:460px} .hrs-table td{padding:.45rem .3rem;font-size:1.05rem} .day{text-align:left;font-weight:600;color:#333} .time{text-align:right;color:#333} .closed{color:#a00;font-weight:600} /* specials */ .sp-heading{margin:1.6rem 0 .6rem;font-size:1.1rem;font-weight:700;color:#102a66} .sp-list{list-style:none;padding:0;margin:0 auto;max-width:460px;text-align:left} .sp-list li{margin:.5rem 0;font-size:.96rem;color:#333} /* timeβzone caption */ .tz-note{margin-top:.6rem;font-size:.9rem;color:#555;font-style:italic} </style>
Save changes
Create folder
writable 0777
Create
Cancel