Site Builder
Editing:
modules-hours1.php
writable 0666
<?php /************************************************************************** * HOURS MODULE – Opening times table (gold outline) * ---------------------------------------------------------------------- * • Reads ../../hours.json * • Shows weekly schedule + optional upcoming special dates (≤30 days ahead) **************************************************************************/ /* ---------- 1. Load hours.json ---------- */ $hoursPath = dirname(__DIR__, 2) . '/hours.json'; $raw = is_readable($hoursPath) ? file_get_contents($hoursPath) : '[]'; $data = json_decode($raw, true) ?: []; /* Separate weekly vs date‑specific entries */ $weekly = $specials = []; foreach ($data as $row) { if (!empty($row['day'])) $weekly[] = $row; elseif (!empty($row['date'])) $specials[] = $row; } /* Nothing to show? */ if (!$weekly && !$specials) return; /* helper: convert 24‑hour → 9 am format */ function fmtTime(string $t): string { if (preg_match('/^(\d{1,2}):(\d{2})$/', $t, $m)) { $h=$m[1]; $min=$m[2]; $ampm=$h>=12?'pm':'am'; $h=$h%12 ?: 12; return "$h:" . ($min==='00'?'':$min) . $ampm; } return $t; // already formatted } /* helper: 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)); /* keep only specials within next 30 days */ $today = new DateTimeImmutable(); $cut = $today->modify('+30 days'); $specials = array_filter($specials, function($s) use ($today,$cut){ $d = DateTime::createFromFormat('Y-m-d', $s['date'] ?? '') ?: null; return $d && $d >= $today && $d <= $cut; }); ?> <section class="hrs-shell"> <div class="hrs-card"> <h2>🕑 Hours of Operation</h2> <?php if ($weekly): ?> <table class="hrs-table"> <?php foreach ($weekly as $w): ?> <tr> <td class="day"><?= htmlspecialchars($w['day']) ?></td> <td class="time"> <?php if (!empty($w['closed'])): ?> <span class="closed">Closed</span> <?php else: ?> <?= fmtTime($w['open']) ?> – <?= fmtTime($w['close']) ?> <?php endif; ?> </td> </tr> <?php endforeach; ?> </table> <?php endif; ?> <?php if ($specials): ?> <h3 class="sp-heading">Upcoming Special Hours</h3> <ul class="sp-list"> <?php foreach ($specials as $s): $d = DateTime::createFromFormat('Y-m-d', $s['date']); ?> <li> <strong><?= $d->format('M j') ?>:</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; ?> </div> </section> <style> /* wrapper like other gold modules */ .hrs-shell{margin:2.6rem auto;max-width:clamp(480px,70vw,720px);width:100%; font-family:system-ui,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} .sp-heading{margin:1.6rem 0 .6rem;font-size:1.1rem;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} .hrs-table .day{text-align:left;font-weight:600;color:#333} .hrs-table .time{text-align:right;color:#333} .closed{color:#a00;font-weight:600} /* specials */ .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} </style>
Save changes
Create folder
writable 0777
Create
Cancel