Fix Calendar Loading Problems

This commit is contained in:
2025-12-18 19:00:05 +01:00
parent afadbbc835
commit bbe05bd765
3 changed files with 228 additions and 177 deletions
+23 -10
View File
@@ -1,4 +1,3 @@
<?php
// URL der öffentlichen ICS-Datei
define(
@@ -83,13 +82,10 @@ function format_ics_date_with_timezone($date, $timezone = null)
}
}
// ICS-Datei laden
$ics = @file_get_contents(CAL_URL);
if (!$ics) {
echo '<div class="text-red-600">Kalender konnte nicht geladen werden.</div>';
return;
}
// Cache für 24 Stunden (in Minuten)
$cacheDuration = 24 * 60;
$cacheId = 'google_calendar_events';
$cache = kirby()->cache('pages');
// Termine parsen
function parse_ics($ics)
@@ -134,9 +130,26 @@ function parse_ics($ics)
return $events;
}
$events = parse_ics($ics);
return function () use ($cache, $cacheId, $cacheDuration) {
// Versuche Daten aus dem Cache zu laden
$events = $cache->get($cacheId);
if ($events === null) {
// Wenn nicht im Cache, neu laden
$ics = @file_get_contents(CAL_URL);
if (!$ics) {
// Fehler beim Laden (z.B. 429 Error)
return null;
}
// Termine parsen
$events = parse_ics($ics);
// In Cache speichern
$cache->set($cacheId, $events, $cacheDuration);
}
return function () use ($events) {
return $events;
};