'http://status.bytespeicher.org',
'Makerspace' => 'http://status.makerspace-erfurt.de',
];
// Max width of icon (small = 100, large = 200)
$cssMaxWidth = 100;
// JSON path for URI
$statusJsonPath = '/status-minimal.json';
// Create stream context with low timeout
$context = stream_context_create([
'http' => [
'method' => "GET",
'timeout' => 1
]
]);
// Check every space
// No output on errors
foreach ($spaces as $spaceName => $statusUrl) {
// Get minimal status from spacestatus webpage
$jsonContent = file_get_contents($statusUrl . $statusJsonPath, false, $context);
if ($jsonContent === false) {
// Status could not be received, skip it
continue;
}
// Decode JSON with max depth of 2
$jsonContent = json_decode($jsonContent, false, 2);
if (is_null($jsonContent) || !isset($jsonContent->open) || !isset($jsonContent->icon)) {
// JSON could not be decoded or entries missing
continue;
}
// Output spaces
$text = 'Der ' . $spaceName . ' ist ' . ($jsonContent->open === true ? 'offen' : 'geschlossen') . '!';
echo '
';
echo 'icon . '\' title=\'' . $text . '\' alt=\'Raumstatus des ' . $spaceName . '\' style=\'width:100%;max-width:' . $cssMaxWidth . 'px;\' />';
echo '';
}
?>