Site Builder
Editing:
modules-hoursgggggggggggg.php
writable 0666
<?php /************************************************************************** * HOURS MODULE – v4.1 (self‑contained, helper‑aware) * ---------------------------------------------------------------------- * • If get_hours() exists (loaded from helpers.php) we use it. * • Otherwise reads ../../hours.json directly. * • Accepts specials stored either as YYYY‑MM‑DD *or* full ISO‑8601 * (e.g. 2024‑11‑11T05:55:00Z) and filters to the next 180 days. * • Fully responsive; card width matches other gold cards. **************************************************************************/ /* ---------- 1. Load data ---------- */ if (function_exists('get_hours')) { $hoursData = get_hours(); // cached by helpers.php } else { $jsonFile = dirname(__DIR__, 2) . '/hours.json'; $hoursData = is_readable($jsonFile) ? json_decode(file_get_contents($jsonFile), true) ?: [] : []; } if (!$hoursData) return; // nothing to show /* ---------- 2. Extract pieces ---------- */ $tzLabel = $hoursData['timezone'] ?? ''; // e.g. "Eastern Time (ET)" $weekly = $hoursData['weekly'] ?? []; $specials = $hoursData['special'] ?? []; /* ---------- 3. Helpers ---------- */ $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; } /* ---------- 4. Filter specials to the next 180 days ---------- */ $today = new DateTimeImmutable('today'); $cut = $today->modify('+180 days'); $specials = array_filter($specials, function ($s) use ($today,$cut) { $raw = $s['date'] ?? ''; /* allow both YYYY‑MM‑DD and full ISO‑8601 */ $d = DateTimeImmutable::createFromFormat('Y-m-d', $raw) ?: DateTimeImmutable::createFromFormat(DATE_ATOM, $raw); return $d && $d >= $today && $d <= $cut; }); /* ---------- 5. Bail if still nothing ---------- */ if (!$weekly && !$specials) return; ?> <!-- ===== HOURS (gold‑outline card) ===== --> <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); ?> <li> <strong><?= $d ? $d->format('M j') : htmlspecialchars($raw) ?>:</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