Add switch for disabling event calendar (SARS-CoV-2 Switch™)

This commit is contained in:
iwonder 2020-03-13 11:41:00 +00:00
parent cecb461dd7
commit ae66ce4633

View File

@ -3,6 +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 $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics';
$state_map = array(
'closed' => (object) array(
@ -12,7 +13,7 @@ $state_map = array(
),
'maybe_open' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>vielleicht geöffnet</em>: </p><p>Der Clubraum ist offen, aber es findet keine Veranstaltung statt.</p><p>
Der Status kann sich also kstartdate_loopurzfristig ändern.',
Der Status kann sich also kurzfristig ändern.',
'svg' => 'done',
'color' => 'brown',
),
@ -51,33 +52,35 @@ $hash_to_state = array(
$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);
'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 . ' &ndash; ' . $enddate_str;
}
}
$v = file_get_contents($VISITORS_FILE);
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 . ' &ndash; ' . $enddate_str;
}
?>
<!DOCTYPE html>
<html lang="de">
@ -107,6 +110,7 @@ function format_event($event): string{
<div class="card mb-3 text-center">
<div class="card-body">
<h5 class="card-title">Events</h5>
<?php if ($ENABLE_CALENDAR){ ?>
<h6 class="card-subtitle mb-2 text-muted">Nächste Veranstaltung</h6>
<p class="card-text">
<h5 class="font-weight-bold"><?= htmlspecialchars($first_event->summary, ENT_QUOTES, 'UTF-8') ?></h5>
@ -123,7 +127,16 @@ function format_event($event): string{
<?php endforeach ?>
</tbody>
</table>
<a href="https://wiki.chaosdorf.de/Chaosdorf_Wiki:Current_events" class="btn btn-lg btn-block btn-primary">Event-Kalender</a>
<a href="https://wiki.chaosdorf.de/Chaosdorf_Wiki:Current_events" class="btn btn-lg btn-block btn-primary">Event-Kalender</a>
<?php } else { ?>
<h6 class="card-subtitle mb-2 text-muted">Aktuell keine Veranstaltungen.</h6>
<p class="card-text">
<span class="font-weight-normal">
Aktuell finden als Vorsichtsmaßnahme keine öffentlichen Veranstaltungen statt.<br>
Bitte beobachte <a href="https://chaosdorf.de">den Blog des Chaosdorf</a> für weitere Informationen.
</span>
</p>
<?php } ?>
</div>
</div>
</div>