Initial commit
This commit is contained in:
commit
3a59408fc5
6 changed files with 2988 additions and 0 deletions
64
index.php
Normal file
64
index.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
# config
|
||||
$ical = 'https://cloud.MYURL/remote.php/dav/public-calendars/CALENDARID/?export';
|
||||
$cachefile = 'cache/hackcal.ics';
|
||||
$cachetime = 120; // 2 min
|
||||
setlocale(LC_TIME, "de_DE.utf8");
|
||||
|
||||
# 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
|
||||
$events = $iCal->sortEventsWithOrder($iCal->eventsFromInterval('1 month'));
|
||||
|
||||
$filter = filter_input(INPUT_GET, 'filter', FILTER_SANITIZE_SPECIAL_CHARS);
|
||||
|
||||
$result = [];
|
||||
foreach ($events as $event) {
|
||||
|
||||
if ($filter && strpos($event->categories, $filter) === false) {
|
||||
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]["name"] = strftime('%e. %B %Y', $dt->getTimestamp());
|
||||
$result[$date]["weekday"] = strftime('%A', $dt->getTimestamp());
|
||||
$result[$date]["events"][$uid]["dtstart"] = $event->dtstart; #TODO: Zeitzone aus lib auslesen
|
||||
$result[$date]["events"][$uid]["dtend"] = $event->dtend; #TODO: Zeitzone aus lib auslesen
|
||||
$result[$date]["events"][$uid]["datestr"] = (isset($event->dtstart_array[0]["VALUE"]) && $event->dtstart_array[0]["VALUE"] == 'DATE')?'Ganztägig':$start->format('H:i');
|
||||
$result[$date]["events"][$uid]["summary"] = $event->summary;
|
||||
$result[$date]["events"][$uid]["location"] = $event->location;
|
||||
$result[$date]["events"][$uid]["description"] = $event->description;
|
||||
$result[$date]["events"][$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_PRETTY_PRINT);
|
Loading…
Add table
Add a link
Reference in a new issue