Files
schachfreunde-badsteben/site/collections/termine.php
T
tfeigel 69217afce4 feat: introduce event carousel and ICS integration for homepage
Added an event carousel to the homepage to display upcoming events dynamically. Integrated ICS parsing to fetch and format calendar data for future events. Enhanced layout and responsiveness with scroll functionality and improved styling.
2025-07-06 19:35:14 +02:00

66 lines
1.9 KiB
PHP

<?php
// URL der öffentlichen ICS-Datei
define(
'CAL_URL',
'https://calendar.google.com/calendar/ical/jv1bq94un3ivoa8ka0rk9ngq4k%40group.calendar.google.com/public/basic.ics',
);
function format_ics_date($date)
{
// Unterstützt sowohl ganztägige als auch Zeitangaben
if (strpos($date, 'T') !== false) {
$dt = DateTime::createFromFormat('Ymd\THis', substr($date, 0, 15));
return $dt ? $dt->format('d.m.Y H:i') : $date;
} else {
$dt = DateTime::createFromFormat('Ymd', $date);
return $dt ? $dt->format('d.m.Y') : $date;
}
}
// ICS-Datei laden
$ics = @file_get_contents(CAL_URL);
if ( ! $ics) {
echo '<div class="text-red-600">Kalender konnte nicht geladen werden.</div>';
return;
}
// Termine parsen
function parse_ics($ics)
{
$lines = explode("\n", $ics);
$events = [];
$event = [];
$inEvent = false;
foreach ($lines as $line) {
$line = trim($line);
if ($line === 'BEGIN:VEVENT') {
$inEvent = true;
$event = [];
} elseif ($line === 'END:VEVENT') {
$inEvent = false;
$events[] = $event;
} elseif ($inEvent) {
// Property kann Parameter enthalten, z.B. DTSTART;TZID=Europe/Berlin:20240701T19000000
$parts = explode(':', $line, 2);
if (count($parts) === 2) {
$key = $parts[0];
$val = $parts[1];
// Nur den eigentlichen Property-Namen extrahieren
$key = strtoupper(preg_replace('/;.+$/', '', $key));
$event[$key] = $val;
}
}
}
return $events;
}
$events = parse_ics($ics);
return function() use ($events) {
return $events;
}
?>