32 lines
1,023 B
PHP
32 lines
1,023 B
PHP
<?php
|
|
$sent_secret = $_GET["secret"];
|
|
$config_file = file_get_contents("merge-calendars-config.json");
|
|
$data = json_decode($config_file);
|
|
|
|
if(is_null($sent_secret) || $sent_secret !== $data->secret)
|
|
header('HTTP/1.0 403 Forbidden');
|
|
else {
|
|
$all_calendars = "";
|
|
foreach ($data->calendars as &$calendar) {
|
|
$ical = file_get_contents($calendar);
|
|
$all_calendars = $all_calendars . $ical;
|
|
}
|
|
unset($calendar);
|
|
|
|
$pattern = "/(\r?)\nEND:VCALENDARBEGIN:VCALENDAR/";
|
|
$replacement = "";
|
|
$all_calendars = preg_replace($pattern, $replacement, $all_calendars);
|
|
|
|
$calendar_filename = "calendar.ics";
|
|
file_put_contents($calendar_filename, $all_calendars);
|
|
header("Content-disposition: attachment;filename=$calendar_filename");
|
|
header('Content-Type: text/calendar');
|
|
readfile($calendar_filename);
|
|
|
|
ob_end_flush();
|
|
flush();
|
|
|
|
unlink($calendar_filename);
|
|
}
|
|
?>
|