Skip to content

Instantly share code, notes, and snippets.

@dromer
Last active August 29, 2015 14:00
Show Gist options
  • Save dromer/11379447 to your computer and use it in GitHub Desktop.
Save dromer/11379447 to your computer and use it in GitHub Desktop.
]( LAG SpaceAPI in PHP
<?php
$thekey = "PASSWORDGOESHERE";
function displaystate(){
$file = "spaceapi.json";
$json = json_decode(file_get_contents($file), true);
$nowstate = $json['state']['open'];
echo "<div align=center style='color:#BDBDBD'>";
if($nowstate == true){
echo "<img src='open.png'></br>";
echo "The space is open :]";
} elseif ($nowstate == false){
echo "<img src='closed.png'></br>";
echo "The space is closed :(";
} else {
echo "There is something wrong with the spaceapi implementation.</br>
Please contact the administrator.";
}
echo "</div>";
}
$state = isset($_GET["state"]) ? $_GET["state"] : '';
$key = isset($_GET["key"]) ? $_GET["key"] : '';
if(!empty($state) and $key == $thekey){
if($state == "open"){
$newstate = true;
} elseif ($state == "closed"){
$newstate = false;
} else {
displaystate();
exit;
}
} else {
displaystate();
exit;
}
$spaceapi = array (
'api' => '0.13',
'space' => 'LAG',
'logo' => 'http://laglab.org/logo.png',
'url' => 'http://laglab.org',
'location' => array(
'address' => 'Eerste Schinkelstraat 16, 1075 TX Amsterdam, The Netherlands',
'lat' => (float) 52.35406,
'lon' => (float) 4.85423
),
'contact' => array(
'irc' => 'irc://irc.indymedia.nl/#lag',
'email' => 'info@laglab.org'
),
'issue_report_channels' => array(
'email'
),
'state' => array(
'open' => $newstate,
'icon' => array(
'open' => 'https://state.laglab.org/open.png',
'closed' => 'https://state.laglab.org/closed.png'
)
)
);
$fp = fopen('spaceapi.json', 'w');
fwrite($fp, json_encode($spaceapi));
fclose($fp);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment