Add spacestate CSS generator
This commit is contained in:
parent
15fd1195b2
commit
a0b7f10db5
1 changed files with 60 additions and 0 deletions
60
spacestate.php
Normal file
60
spacestate.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate");
|
||||
header("Content-Type: text/css");
|
||||
|
||||
const CACHE_KEY = "techinc_spacestate";
|
||||
const CACHE_TTL = 10;
|
||||
|
||||
function getSpaceState() {
|
||||
$in_cache = false;
|
||||
$is_open = apcu_fetch(CACHE_KEY, $in_cache);
|
||||
|
||||
if ($in_cache) {
|
||||
return $is_open;
|
||||
}
|
||||
|
||||
$state = file_get_contents("https://techinc.nl/space/spacestate.json");
|
||||
|
||||
if ($state == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$json = json_decode($state);
|
||||
if (is_null($json)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$is_open = $json?->open ?? false;
|
||||
|
||||
apcu_store(CACHE_KEY, $is_open, CACHE_TTL);
|
||||
|
||||
return $is_open;
|
||||
}
|
||||
|
||||
$spaceState = getSpaceState();
|
||||
|
||||
?>
|
||||
#p-navigation:before {
|
||||
content: " ";
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
<?php if ($spaceState) { ?>
|
||||
#p-logo:after {
|
||||
content: "OPEN" ;
|
||||
border-radius: 3px;
|
||||
background: green;
|
||||
color: white;
|
||||
margin-left: 51px;
|
||||
padding: 3px 7px;
|
||||
}
|
||||
<?php } else { ?>
|
||||
#p-logo:after {
|
||||
content: "CLOSED" ;
|
||||
border-radius: 3px;
|
||||
background: red;
|
||||
color: white;
|
||||
margin-left: 43px;
|
||||
padding: 3px 7px;
|
||||
}
|
||||
<?php } ?>
|
||||
Loading…
Reference in a new issue