Add switch for disabling event calendar (SARS-CoV-2 Switch™)
This commit is contained in:
parent
cecb461dd7
commit
ae66ce4633
33
index.php
33
index.php
@ -3,6 +3,7 @@ require_once 'vendor/autoload.php';
|
|||||||
use ICal\ICal;
|
use ICal\ICal;
|
||||||
static $DATE_FORMAT = 'd.m.Y H:i';
|
static $DATE_FORMAT = 'd.m.Y H:i';
|
||||||
static $VISITORS_FILE = '/media/sg/dorf.jetzt_visitors';
|
static $VISITORS_FILE = '/media/sg/dorf.jetzt_visitors';
|
||||||
|
static $ENABLE_CALENDAR = false;
|
||||||
static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics';
|
static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics';
|
||||||
$state_map = array(
|
$state_map = array(
|
||||||
'closed' => (object) array(
|
'closed' => (object) array(
|
||||||
@ -12,7 +13,7 @@ $state_map = array(
|
|||||||
),
|
),
|
||||||
'maybe_open' => (object) 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>
|
'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',
|
'svg' => 'done',
|
||||||
'color' => 'brown',
|
'color' => 'brown',
|
||||||
),
|
),
|
||||||
@ -51,22 +52,22 @@ $hash_to_state = array(
|
|||||||
$img = file_get_contents('https://chaosdorf.de/raumstatus/status.png');
|
$img = file_get_contents('https://chaosdorf.de/raumstatus/status.png');
|
||||||
$hash = md5($img);
|
$hash = md5($img);
|
||||||
$state = $hash_to_state[$hash];
|
$state = $hash_to_state[$hash];
|
||||||
|
if ($ENABLE_CALENDAR){
|
||||||
$ical = new ICal(false, array(
|
$ical = new ICal(false, array(
|
||||||
'defaultSpan' => 2,
|
'defaultSpan' => 2,
|
||||||
'defaultTimeZone' => 'Europe/Berlin',
|
'defaultTimeZone' => 'Europe/Berlin',
|
||||||
'defaultWeekStart' => 'MO',
|
'defaultWeekStart' => 'MO',
|
||||||
'filterDaysBefore' => '1',
|
'filterDaysBefore' => '1',
|
||||||
));
|
));
|
||||||
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
|
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
|
||||||
$events = $ical->eventsFromInterval('2 week');
|
$events = $ical->eventsFromInterval('2 week');
|
||||||
$first_event = $events[0];
|
$first_event = $events[0];
|
||||||
$events = array_slice($events, 1);
|
$events = array_slice($events, 1);
|
||||||
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
if ($locale !== null){
|
if ($locale !== null){
|
||||||
setlocale(LC_TIME, $locale);
|
setlocale(LC_TIME, $locale);
|
||||||
}
|
}
|
||||||
$v = file_get_contents($VISITORS_FILE);
|
function format_event($event): string{
|
||||||
function format_event($event): string{
|
|
||||||
global $DATE_FORMAT, $ical;
|
global $DATE_FORMAT, $ical;
|
||||||
$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
|
$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
|
||||||
$startdate_str = $startdate_loop->format($DATE_FORMAT);
|
$startdate_str = $startdate_loop->format($DATE_FORMAT);
|
||||||
@ -77,7 +78,9 @@ function format_event($event): string{
|
|||||||
$enddate_str = $startdate_loop->add($interval_loop)->format('H:i');
|
$enddate_str = $startdate_loop->add($interval_loop)->format('H:i');
|
||||||
}
|
}
|
||||||
return $startdate_str . ' – ' . $enddate_str;
|
return $startdate_str . ' – ' . $enddate_str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$v = file_get_contents($VISITORS_FILE);
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
@ -107,6 +110,7 @@ function format_event($event): string{
|
|||||||
<div class="card mb-3 text-center">
|
<div class="card mb-3 text-center">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">Events</h5>
|
<h5 class="card-title">Events</h5>
|
||||||
|
<?php if ($ENABLE_CALENDAR){ ?>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">Nächste Veranstaltung</h6>
|
<h6 class="card-subtitle mb-2 text-muted">Nächste Veranstaltung</h6>
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
<h5 class="font-weight-bold"><?= htmlspecialchars($first_event->summary, ENT_QUOTES, 'UTF-8') ?></h5>
|
<h5 class="font-weight-bold"><?= htmlspecialchars($first_event->summary, ENT_QUOTES, 'UTF-8') ?></h5>
|
||||||
@ -124,6 +128,15 @@ function format_event($event): string{
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user