2020-07-02 22:52:40 +00:00
|
|
|
<?php
|
2020-07-03 02:30:22 +00:00
|
|
|
$from = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "last sunday" : "sunday"));
|
|
|
|
$to = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "sunday" : "next sunday"));
|
2020-07-03 01:53:12 +00:00
|
|
|
include 'schedule.php';
|
2020-07-02 22:52:40 +00:00
|
|
|
|
2020-07-03 02:48:06 +00:00
|
|
|
function ics_formatdate($date) {
|
|
|
|
return gmdate("Ymd\THis\Z", strtotime($date));
|
|
|
|
}
|
|
|
|
|
2020-07-02 22:52:40 +00:00
|
|
|
// ICS generation. Here be dragons.
|
|
|
|
// I created the file using a Python script and reverse-engineered it to figure this out.
|
|
|
|
|
2020-07-03 02:30:22 +00:00
|
|
|
header("Content-Type: text/calendar");
|
|
|
|
|
|
|
|
// the iCalendar Validator throws a hissy fit if lines aren't CRLF terminated
|
|
|
|
define("ICS_EOL","\r\n");
|
|
|
|
|
2020-07-02 22:52:40 +00:00
|
|
|
// Header.
|
2020-07-03 02:30:22 +00:00
|
|
|
echo "BEGIN:VCALENDAR".ICS_EOL;
|
|
|
|
echo "VERSION:2.0".ICS_EOL;
|
|
|
|
echo "PRODID:tilderadio schedule".ICS_EOL;
|
2020-07-03 02:48:06 +00:00
|
|
|
echo "DTSTAMP:".ics_formatdate("now").ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
|
|
|
|
foreach ($schedule as $event) {
|
|
|
|
// The VEVENT structure's pretty easy to generate, especially since we're already in UTC.
|
2020-07-03 02:30:22 +00:00
|
|
|
echo "BEGIN:VEVENT".ICS_EOL;
|
|
|
|
// First, we need a creation date.
|
|
|
|
// Just go with now.
|
2020-07-03 02:48:06 +00:00
|
|
|
echo "DTSTAMP:".ics_formatdate("now").ICS_EOL;
|
2020-07-03 02:30:22 +00:00
|
|
|
// Next, the event start and end.
|
2020-07-03 02:48:06 +00:00
|
|
|
echo "DTEND:".ics_formatdate($event["end"]).ICS_EOL;
|
|
|
|
echo "DTSTART:".ics_formatdate($event["start"]).ICS_EOL;
|
2020-07-03 02:30:22 +00:00
|
|
|
// Next, the recurrence rule.
|
|
|
|
// We assume the format is weekly. (No DJs have requested any other frequency yet.)
|
|
|
|
echo "RRULE:FREQ=WEEKLY".ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
// Next, the event title, or "summary" as the spec calls it.
|
2020-07-03 02:30:22 +00:00
|
|
|
echo "SUMMARY:DJ ".$event["title"].ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
// Finally, a unique ID for this event.
|
|
|
|
// To make absolutely certain we don't repeat the same event ID, I decided to use a SHA256 hash of the event structure.
|
|
|
|
echo "UID:";
|
|
|
|
echo hash("sha256",json_encode($event));
|
2020-07-03 02:30:22 +00:00
|
|
|
// to avoid the validator complaining about lines longer than 75 characters, split after the hash
|
|
|
|
echo ICS_EOL." ";
|
|
|
|
// Now finish the address UID
|
|
|
|
echo "@tilderadio.org".ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
// Finally, close the VEVENT structure.
|
2020-07-03 02:30:22 +00:00
|
|
|
echo "END:VEVENT".ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
// Next event?
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, close out the VCALENDAR structure.
|
2020-07-03 02:30:22 +00:00
|
|
|
echo "END:VCALENDAR".ICS_EOL;
|
2020-07-02 22:52:40 +00:00
|
|
|
|
|
|
|
?>
|