From 4f6094c6c672942057ca283ffbc3cc4816d184a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Tue, 5 May 2026 23:45:05 +0200 Subject: [PATCH] =?UTF-8?q?Afficher=20les=20prochains=20=C3=A9v=C3=A9nemen?= =?UTF-8?q?ts=20du=20calendrier=20public=20sur=20la=20page=20d'accueil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajoute web/inc/calendar.php : récupère le flux iCal via ?p=webcal, cache le résultat 1h dans /tmp, parse les VEVENT à venir - Intègre le bloc "Prochains événements" dans index.php avant les services Closes #1 Co-Authored-By: Claude Sonnet 4.6 --- web/inc/calendar.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ web/index.php | 15 ++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 web/inc/calendar.php diff --git a/web/inc/calendar.php b/web/inc/calendar.php new file mode 100644 index 0000000..05c1913 --- /dev/null +++ b/web/inc/calendar.php @@ -0,0 +1,47 @@ += $ttl) { + $data = @file_get_contents($url); + if ($data !== false) file_put_contents($cache, $data); + } + + if (!file_exists($cache)) return []; + + return _ical_upcoming(file_get_contents($cache), $n); +} + +function _ical_upcoming(string $ical, int $n): array { + $events = []; + $now = time(); + + preg_match_all('/BEGIN:VEVENT(.+?)END:VEVENT/s', $ical, $blocks); + + foreach ($blocks[1] as $b) { + $e = []; + + if (preg_match('/^SUMMARY[^:]*:(.+)$/m', $b, $m)) + $e['title'] = trim($m[1]); + + if (preg_match('/^LOCATION[^:]*:(.+)$/m', $b, $m)) + $e['location'] = trim($m[1]); + + if (preg_match('/^DTSTART[^:]*:(\d+)/m', $b, $m)) { + $r = $m[1]; + $e['start'] = strlen($r) === 8 + ? mktime(0, 0, 0, substr($r, 4, 2), substr($r, 6, 2), substr($r, 0, 4)) + : strtotime($r); + } + + if (isset($e['start'], $e['title']) && $e['start'] >= $now) + $events[] = $e; + } + + usort($events, fn($a, $b) => $a['start'] - $b['start']); + + return array_slice($events, 0, $n); +} diff --git a/web/index.php b/web/index.php index e063a59..89781d0 100644 --- a/web/index.php +++ b/web/index.php @@ -2,6 +2,7 @@ require_once __DIR__ . '/inc/config.php'; require_once __DIR__ . '/inc/auth.php'; require_once __DIR__ . '/inc/services.php'; +require_once __DIR__ . '/inc/calendar.php'; session_start_safe(); @@ -64,6 +65,20 @@ require __DIR__ . '/views/layout.php'; + +
+

Prochains événements

+
+ +
+
+

+
+ +
+
+ +

Nos services