/** * Load data of search * * Loads route data from overpass api. */ public function getData() { // add GET to variables $this->variables = $_GET; //array of keys that should be requested $keys = array("ref", "network", "operator", "to", "from"); // build link $query = '<query type="relation">'; foreach ($keys as $key) { if (isset($this->variables[$key]) && $this->variables[$key]) { $query .= '<has-kv case="ignore" k="' . $key . '" regv="' . htmlspecialchars($this->variables[$key]) . '"/>'; } } $query .= '<has-kv k="type" v="route"/><has-kv k="route" regv="train|tram|light_rail|subway"/></query><print/>'; if (Overpass::sendRequest($query)) { $this->content = Overpass::$result; return true; } else { $this->error = Overpass::$error; return false; } }
/** * Load data of route * * Loads route data from overpass api, when not available yet. */ public function getData() { if (isset($_POST["id"])) { $_GET["id"] = $_POST["id"]; if (isset($_POST["train"])) { $_GET["train"] = $_POST["train"]; } } // no id set if (!isset($_GET["id"])) { // show error return_error("no_id", "full"); die; } // get route id $get_id = $_GET["id"]; // id is not a valid number if (!is_numeric($get_id) || round($get_id) != $get_id) { // exception for user routes of the scheme 12345_0 if (preg_match("/^[0-9]+[_][0-9]+\$/", $get_id)) { $file = "./osmdata/user" . $get_id . ".osm"; if (file_exists($file)) { $spl = preg_split("[_]", $get_id); $this->id = $spl[0]; $this->filexml = $file; $this->custom = true; $this->custom_id = $get_id; return; } else { return_error("invalid_id", "full"); die; } } // show error return_error("invalid_id", "full"); die; } // save id $this->id = $get_id; if (isset($_FILES["osmfile"])) { $uploaddir = './osmdata/'; $uploadfile = $uploaddir . "user" . $this->id . "_"; $i = 0; while (file_exists($uploadfile . $i . ".osm")) { $i++; } $uploadfile .= $i . ".osm"; // try uploading file if (move_uploaded_file($_FILES['osmfile']['tmp_name'], $uploadfile)) { if (!@simplexml_load_file($uploadfile)) { return_error("invalid_xml_file", "full"); unlink($uploadfile); die; } } else { return_error("upload_error", "full"); print_r($_FILES); log_error("File upload error:" . print_r($_FILES["osmfile"]["error"])); die; } $this->filexml = $uploadfile; $this->custom = true; $this->custom_id = $get_id . "_" . $i; } else { // build file name $file_name = "osmdata/data" . $this->id . ".osm"; // check if data needs to be refreshed $refresh = true; // default value // relation was already loaded if (file_exists($file_name)) { // check age of data $this->filemtime = filemtime($file_name); // data is younger than 7 days if ($this->filemtime > time() - 7 * 24 * 60 * 60) { $refresh = false; } } // forced refresh if (isset($_GET["rf"]) && $_GET["rf"] == "1") { $refresh = true; } if (isset($_GET["maxspeed"]) && $_GET["maxspeed"] > 0) { $this->vmz = $_GET["maxspeed"]; } // get data from overpass-api when needed if ($refresh) { // build link to overpass api $overpass_query = "[out:xml];(relation(" . $get_id . ");rel(br););out;(relation(" . $get_id . ");>>;);out;"; if (Overpass::sendRequest($overpass_query)) { $this->refresh_success = true; file_put_contents($file_name, Overpass::$result); $this->filemtime = time(); } else { $this->refresh_success = false; } } $this->filexml = $file_name; } }