Completely change how the lockdown mode works

This commit is contained in:
iwonder 2020-03-13 12:28:48 +00:00
parent ae66ce4633
commit 684139cef0

View File

@ -3,7 +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 $DORF_IN_LOCKDOWN = true;
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(
@ -48,11 +48,10 @@ $hash_to_state = array(
'86c75c0ad413b06ff8291673162d0b64' => 'unknown', '86c75c0ad413b06ff8291673162d0b64' => 'unknown',
'0' => 'error', '0' => 'error',
); );
$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){ if (! $DORF_IN_LOCKDOWN){
$ical = new ICal(false, array( $ical = new ICal(false, array(
'defaultSpan' => 2, 'defaultSpan' => 2,
'defaultTimeZone' => 'Europe/Berlin', 'defaultTimeZone' => 'Europe/Berlin',
@ -67,6 +66,7 @@ if ($ENABLE_CALENDAR){
if ($locale !== null){ if ($locale !== null){
setlocale(LC_TIME, $locale); setlocale(LC_TIME, $locale);
} }
}
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]);
@ -79,7 +79,6 @@ if ($ENABLE_CALENDAR){
} }
return $startdate_str . ' – ' . $enddate_str; return $startdate_str . ' – ' . $enddate_str;
} }
}
$v = file_get_contents($VISITORS_FILE); $v = file_get_contents($VISITORS_FILE);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -110,7 +109,7 @@ $v = file_get_contents($VISITORS_FILE);
<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){ ?> <?php if (! $DORF_IN_LOCKDOWN && !empty($events)) : ?>
<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>
@ -128,15 +127,23 @@ $v = file_get_contents($VISITORS_FILE);
</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 { ?> <?php else: ?>
<h6 class="card-subtitle mb-2 text-muted">Aktuell keine Veranstaltungen.</h6> <h6 class="card-subtitle mb-2 text-muted">Aktuell keine Veranstaltungen.</h6>
<?php if ($DORF_IN_LOCKDOWN): ?>
<p class="card-text"> <p class="card-text">
<span class="font-weight-normal"> <span class="font-weight-normal">
Aktuell finden als Vorsichtsmaßnahme keine öffentlichen Veranstaltungen statt.<br> 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. Bitte beobachte <a href="https://chaosdorf.de">den Blog des Chaosdorf</a> für weitere Informationen.
</span> </span>
</p> </p>
<?php } ?> <?php else: ?>
<p class="card-text">
<span class="font-weight-normal">
Es stehen aktuell keine Veranstaltungen an.
</span>
</p>
<?php endif ?>
<?php endif ?>
</div> </div>
</div> </div>
</div> </div>