72 lines
No EOL
2.3 KiB
PHP
72 lines
No EOL
2.3 KiB
PHP
<?php
|
|
|
|
#ini_set('display_errors', 1);
|
|
#ini_set('display_startup_errors', 1);
|
|
#error_reporting(E_ALL);
|
|
|
|
|
|
# config
|
|
$ical = 'https://cloud.hacknang.de/remote.php/dav/public-calendars/nZTMSHpd29ZRpAr6/?export';
|
|
$cachefile = 'cache/hacknang.ics';
|
|
$cachetime = 120; // 2 min
|
|
|
|
# requirements
|
|
require_once 'ICal/ICal.php';
|
|
require_once 'ICal/Event.php';
|
|
|
|
# Init Calendar
|
|
$iCal = new \ICal\ICal();
|
|
|
|
# Caching and load calendar
|
|
if(@filemtime($cachefile) + $cachetime < time()) {
|
|
$ical_str = file_get_contents($ical);
|
|
file_put_contents($cachefile, $ical_str);
|
|
$iCal->initString($ical_str);
|
|
} else {
|
|
$iCal->initFile($cachefile);
|
|
}
|
|
//$iCal->initURL($ical);
|
|
|
|
# Load calendar entries
|
|
$months = max(filter_input(INPUT_GET, 'period', FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 12))), 1);
|
|
$events = $iCal->sortEventsWithOrder($iCal->eventsFromInterval($months.' month'));
|
|
|
|
$filter = filter_input(INPUT_GET, 'filter', FILTER_SANITIZE_SPECIAL_CHARS);
|
|
|
|
$result = [];
|
|
foreach ($events as $event) {
|
|
|
|
if ($filter && strpos($event->categories, $filter) === false) {
|
|
continue;
|
|
}
|
|
|
|
if (isset($event->categories) && strpos($event->categories, "hidden")) {
|
|
continue;
|
|
}
|
|
|
|
$start = new DateTime($event->dtstart);
|
|
$end = new DateTime($event->dtend);
|
|
$uid = $event->uid;
|
|
|
|
$interval = DateInterval::createFromDateString('1 day');
|
|
$period = new DatePeriod($start, $interval, $end);
|
|
|
|
foreach ($period as $dt) {
|
|
$date = $dt->format("Y-m-d");
|
|
|
|
$result[$date][$uid]["dtstart"] = $iCal->iCalDateToDateTime($event->dtstart_array[3])->format(DateTime::ATOM);
|
|
$result[$date][$uid]["dtend"] = $iCal->iCalDateToDateTime($event->dtend_array[3])->format(DateTime::ATOM);
|
|
$result[$date][$uid]["datestr"] = (isset($event->dtstart_array[0]["VALUE"]) && $event->dtstart_array[0]["VALUE"] == 'DATE')?'':$start->format('H:i');
|
|
$result[$date][$uid]["summary"] = mb_strimwidth($event->summary, 0, 255, "...");
|
|
$result[$date][$uid]["location"] = mb_strimwidth($event->location, 0, 255, "...");
|
|
$result[$date][$uid]["description"] = mb_strimwidth($event->description, 0, 255, "...");
|
|
if(isset($event->categories)) $result[$date][$uid]["categories"] = $event->categories;
|
|
}
|
|
|
|
}
|
|
|
|
# Allow every page to load this json
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Content-Type: application/json");
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_SLASHES); |