This repository has been archived on 2024-02-15. You can view files and clone it, but cannot push or open issues or pull requests.
webseite-krautspace/src/getContent.php
+++ 2048026c27 neue ordnerstruktur, php-code hinzugefügt
die ordner public und src hinzugefügt,
zapcallib.php für iCalendar files hinzugefügt,
getContent.php und getEvent.php hinzugefügt
2022-02-18 11:59:12 +01:00

103 lines
2.2 KiB
PHP

<?php
/**
* User: vincent
* Date: 14/12/2016
* Time: 2:55 PM
*/
/* include_once("config.php"); */
$status = getStatus();
function getContent() {
$pagename = filter_input(INPUT_GET, 'title', FILTER_SANITIZE_URL);
$page = $root_url . '/content/' . $pagename . '.txt';
$file = fopen($page, 'rb');
if($file) {
echo stream_get_contents($file);
fclose($file);
} else {
echo "Page not found";
}
}
/**
* @return string[][]
*/
function apiRequest()
{
$ch = curl_init('https://status.kraut.space/api');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
/**
* @return bool
*/
function getStatus(): bool
{
try { return apiRequest()['state']['open']; }
catch (Error $e) { return false; }
}
function getKrautButtonColor($status) {
if ($status) {
echo "<img src='./img/icons/users.svg' id='krauticon'>";
} else {
echo "<img src='./img/icons/user-times.svg' id='krauticon'>";
}
}
function getKrautStatus($status) {
if ($status) {
echo "Raum ist offen";
} else {
echo "Raum ist geschlossen";
}
}
function getKrautSidebar($status)
{
if ($status) {
echo <<<END
<div class="sidebar-heading">
<div class="icondiv"><img src="./img/icons/users.svg" class="icon" alt="Person"></div>
<h4>Raum ist geöffnet</h4>
<p>Schaut einfach vorbei</p>
</div>
END;
} else {
echo <<<END
<div class="sidebar-heading">
<div class="icondiv"><img src="./img/icons/user-times.svg" class="icon" alt="niemand"></div>
<h4>Niemand ist im Raum</h4>
<p>Keine Hackerseele anwesend</p>
</div>
END;
}
}
function getKrautButton(bool $status)
{
if ($status) {
echo <<<END
<div id="roombutton" class="krautopen">
<img src="./img/icons/users.svg" id="roomicon" alt="Person">
<p>Raum ist geöffnet</p>
</div>
END;
} else {
echo <<<END
<div id="roombutton" class="krautclose">
<img src="./img/icons/user-times.svg" id="roomicon" alt="niemand">
<p>Raum ist geschlossen</p>
</div>
END;
}
}