} // Query $queryobj = json_decode($query, true); switch ($queryobj["get"]) { // stations // TODO: status 304 if not modified // TODO: work in queues? list may become quite large... case "stations": $filename = "../json/stations.json"; $json["data"] = fr($filename); if (!$json["data"]) { error("Error: file '{$filename}' not found"); } $json["data"] = json_decode($json["data"], true); if (!$json["data"]) { error("Error decoding json string: " . getJsonError(json_last_error())); } $json["info"]["last_update_time_ms"] = filemtime($filename) * 1000; // TODO: More info? $json["info"]["desc"] = $queryobj["get"]; $jsons = gzencode(json_encode($json)); header('Content-Encoding: gzip'); echo $jsons; break; // station_info // station_info case "station_info": if (!$queryobj["station_id"]) { error("Error: 'station_id' not defined for get:station_info"); } $filename = "../json/station_info." . $queryobj["station_id"] . ".json";
if (!$query) { error("GET['query'] is not defined for action '$action'"); } // Query $queryobj = json_decode($query,true); switch($queryobj["get"]) { // stations // TODO: status 304 if not modified // TODO: work in queues? list may become quite large... case "stations": $filename = "../json/stations.json"; $json["data"] = fr($filename); if (!$json["data"]) { error("Error: file '$filename' not found"); } $json["data"] = json_decode($json["data"],true); if (!$json["data"]) { error("Error decoding json string: ". getJsonError(json_last_error())); } $json["info"]["last_update_time_ms"] = filemtime($filename)*1000; // TODO: More info? $json["info"]["desc"] = $queryobj["get"]; $jsons = gzencode(json_encode($json)); header('Content-Encoding: gzip'); echo $jsons; break; // station_info case "station_info": if (!$queryobj["station_id"]) { error("Error: 'station_id' not defined for get:station_info"); } $filename = "../json/station_info.".$queryobj["station_id"].".json"; if (@filemtime($filename)<time()-30) { // refresh file every xx secs if (!$queryobj["station_port"]) { $queryobj["station_port"] = 80; } // $id3_reader_url = "http://". $_SERVER['HTTP_HOST'] ."/icerrr/php/tests/test-readid3.php?q="; // TODO: rejh.nl only opens fsock on port 80 $id3_reader_url = $cfg["icerrr_local_url"] . "php/tests/test-readid3.php?q=";