Completely change how the lockdown mode works
This commit is contained in:
		
							
								
								
									
										69
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								index.php
									
									
									
									
									
								
							@@ -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,37 +48,36 @@ $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',
 | 
				
			||||||
			'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);
 | 
				
			||||||
	}
 | 
					}
 | 
				
			||||||
	function format_event($event): string{
 | 
					}
 | 
				
			||||||
		global $DATE_FORMAT, $ical;
 | 
					function format_event($event): string{
 | 
				
			||||||
		$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
 | 
						global $DATE_FORMAT, $ical;
 | 
				
			||||||
		$startdate_str = $startdate_loop->format($DATE_FORMAT);
 | 
						$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
 | 
				
			||||||
		$interval_loop = new DateInterval($event->duration);
 | 
						$startdate_str = $startdate_loop->format($DATE_FORMAT);
 | 
				
			||||||
		if ($interval_loop->d != 0 || $interval_loop->h >= 24){
 | 
						$interval_loop = new DateInterval($event->duration);
 | 
				
			||||||
			$enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT);
 | 
						if ($interval_loop->d != 0 || $interval_loop->h >= 24){
 | 
				
			||||||
		}else{
 | 
							$enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT);
 | 
				
			||||||
			$enddate_str = $startdate_loop->add($interval_loop)->format('H:i');
 | 
						}else{
 | 
				
			||||||
		}
 | 
							$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);
 | 
					$v = file_get_contents($VISITORS_FILE);
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
@@ -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>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user