57 lines
1.7 KiB
PHP
Executable File
57 lines
1.7 KiB
PHP
Executable File
<?php
|
|
// Set header to tell clients it's a calendar feed
|
|
header('Content-Type: text/calendar; charset=utf-8');
|
|
header('Content-Disposition: inline; filename=calendar.ics');
|
|
|
|
// Use Brisbane timezone (no DST)
|
|
date_default_timezone_set('Australia/Brisbane');
|
|
|
|
// Read and parse the JSON file
|
|
$json = file_get_contents('events.json');
|
|
$events = json_decode($json, true);
|
|
|
|
// Start of the iCalendar content
|
|
echo "BEGIN:VCALENDAR\r\n";
|
|
echo "VERSION:2.0\r\n";
|
|
echo "PRODID:-//Homelab Brisbane//Event Calendar//EN\r\n";
|
|
echo "CALSCALE:GREGORIAN\r\n";
|
|
echo "METHOD:PUBLISH\r\n";
|
|
echo "X-WR-TIMEZONE:Australia/Brisbane\r\n";
|
|
|
|
// Add VTIMEZONE block for Australia/Brisbane
|
|
echo "BEGIN:VTIMEZONE\r\n";
|
|
echo "TZID:Australia/Brisbane\r\n";
|
|
echo "BEGIN:STANDARD\r\n";
|
|
echo "DTSTART:19700101T000000\r\n";
|
|
echo "TZOFFSETFROM:+1000\r\n";
|
|
echo "TZOFFSETTO:+1000\r\n";
|
|
echo "TZNAME:AEST\r\n";
|
|
echo "END:STANDARD\r\n";
|
|
echo "END:VTIMEZONE\r\n";
|
|
|
|
// Generate VEVENTS
|
|
foreach ($events as $event) {
|
|
$uid = uniqid() . "@homelabbrisbane.com.au";
|
|
|
|
$dtstart = date("Ymd\THis", strtotime($event["start"]));
|
|
$dtend = date("Ymd\THis", strtotime($event["end"]));
|
|
$summary = htmlspecialchars($event["title"]);
|
|
$location = htmlspecialchars($event["location"]);
|
|
$description = isset($event["description"]) ? htmlspecialchars($event["description"]) : '';
|
|
|
|
|
|
echo "BEGIN:VEVENT\r\n";
|
|
echo "UID:$uid\r\n";
|
|
echo "DTSTAMP:" . gmdate("Ymd\THis\Z") . "\r\n";
|
|
echo "DTSTART;TZID=Australia/Brisbane:$dtstart\r\n";
|
|
echo "DTEND;TZID=Australia/Brisbane:$dtend\r\n";
|
|
echo "SUMMARY:$summary\r\n";
|
|
echo "LOCATION:$location\r\n";
|
|
echo "DESCRIPTION:$description\r\n";
|
|
echo "END:VEVENT\r\n";
|
|
}
|
|
|
|
// End of calendar
|
|
echo "END:VCALENDAR\r\n";
|
|
?>
|