From 684139cef00cae9e2e387edc284c45938e004de0 Mon Sep 17 00:00:00 2001 From: iwonder Date: Fri, 13 Mar 2020 12:28:48 +0000 Subject: [PATCH] Completely change how the lockdown mode works --- index.php | 69 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/index.php b/index.php index 2f21495..cc99504 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ require_once 'vendor/autoload.php'; use ICal\ICal; static $DATE_FORMAT = 'd.m.Y H:i'; static $VISITORS_FILE = '/media/sg/dorf.jetzt_visitors'; -static $ENABLE_CALENDAR = false; +static $DORF_IN_LOCKDOWN = true; static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics'; $state_map = array( 'closed' => (object) array( @@ -48,37 +48,36 @@ $hash_to_state = array( '86c75c0ad413b06ff8291673162d0b64' => 'unknown', '0' => 'error', ); - $img = file_get_contents('https://chaosdorf.de/raumstatus/status.png'); $hash = md5($img); $state = $hash_to_state[$hash]; -if ($ENABLE_CALENDAR){ - $ical = new ICal(false, array( - 'defaultSpan' => 2, - 'defaultTimeZone' => 'Europe/Berlin', - 'defaultWeekStart' => 'MO', - 'filterDaysBefore' => '1', - )); - $ical->initUrl($ICAL_URL, $acceptLanguage = 'de'); - $events = $ical->eventsFromInterval('2 week'); - $first_event = $events[0]; - $events = array_slice($events, 1); - $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); - if ($locale !== null){ - setlocale(LC_TIME, $locale); - } - function format_event($event): string{ - global $DATE_FORMAT, $ical; - $startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]); - $startdate_str = $startdate_loop->format($DATE_FORMAT); - $interval_loop = new DateInterval($event->duration); - if ($interval_loop->d != 0 || $interval_loop->h >= 24){ - $enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT); - }else{ - $enddate_str = $startdate_loop->add($interval_loop)->format('H:i'); - } - return $startdate_str . ' – ' . $enddate_str; +if (! $DORF_IN_LOCKDOWN){ +$ical = new ICal(false, array( + 'defaultSpan' => 2, + 'defaultTimeZone' => 'Europe/Berlin', + 'defaultWeekStart' => 'MO', + 'filterDaysBefore' => '1', + )); +$ical->initUrl($ICAL_URL, $acceptLanguage = 'de'); +$events = $ical->eventsFromInterval('2 week'); +$first_event = $events[0]; +$events = array_slice($events, 1); +$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); +if ($locale !== null){ + setlocale(LC_TIME, $locale); +} +} +function format_event($event): string{ + global $DATE_FORMAT, $ical; + $startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]); + $startdate_str = $startdate_loop->format($DATE_FORMAT); + $interval_loop = new DateInterval($event->duration); + if ($interval_loop->d != 0 || $interval_loop->h >= 24){ + $enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT); + }else{ + $enddate_str = $startdate_loop->add($interval_loop)->format('H:i'); } + return $startdate_str . ' – ' . $enddate_str; } $v = file_get_contents($VISITORS_FILE); ?> @@ -110,7 +109,7 @@ $v = file_get_contents($VISITORS_FILE);
Events
- +
Nächste Veranstaltung

summary, ENT_QUOTES, 'UTF-8') ?>
@@ -128,15 +127,23 @@ $v = file_get_contents($VISITORS_FILE); Event-Kalender - +
Aktuell keine Veranstaltungen.
+

Aktuell finden als Vorsichtsmaßnahme keine öffentlichen Veranstaltungen statt.
Bitte beobachte den Blog des Chaosdorf für weitere Informationen.

- + +

+ + Es stehen aktuell keine Veranstaltungen an. + +

+ +