$path = "/home/turistickamapa/public_html";
include_once("$path/common/friendly_id.php");
$destination_path = getcwd().DIRECTORY_SEPARATOR."files".DIRECTORY_SEPARATOR;
$result = 0;
$src = $_GET['src'];
if ($src != ""){
$src = rawurldecode($src);
$out = false;
if (preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $src)){
if (file_exists($src)) $out = file_get_contents($src);
} else {
$src = str_replace("..", "", $src);
$src = str_replace("index.php", "", $src);
$src = ltrim($src,'/');
if (is_file("/home/hiking/public_html/dev/download/$src")){
$out = file_get_contents("/home/hiking/public_html/dev/download/$src");
} elseif (is_file("$path/gpx/files/$src")){
$out = file_get_contents("$path/gpx/files/$src");
} else {
//die("Document not found");
}
}
if ($out === false) die();
$result = $out;
$init = "";
} else {
$existing_files = array();
if ($handle = opendir("$path/gpx/files")) {
while (false !== ($file = readdir($handle))) {
$a = explode(".",$file);
$existing_files[] = $a[0];
}
closedir($handle);
}
if ($handle = opendir('/home/hiking/public_html/dev/download')) {
while (false !== ($file = readdir($handle))) {
$a = explode(".",$file);
$existing_files[] = $a[0];
}
closedir($handle);
}
$target_path = $destination_path . str_replace(".gpx","",friendly_id(basename($_FILES['tm_gpx_file']['name']),$existing_files)).".gpx";
if(@move_uploaded_file($_FILES['tm_gpx_file']['tmp_name'], $target_path)) {
$result = file_get_contents($target_path);
}
$init = "window.top.window.stopGpxUpload();";
}
?>
$xdoc = new DomDocument;
if (@$xdoc->loadXML($result) === false) die("invalid XML");
$xmlschema1 = "gpx1-1.xsd";
$xmlschema2 = "gpx1-0.xsd";
//if (@$xdoc->schemaValidate($xmlschema1) || @$xdoc->schemaValidate($xmlschema2)) {
$out = $result;
$out = preg_replace('@]*?>.*?@siu','',$out);
//$out = preg_replace('@(.*?)/>.*?@siu',"$1>\n",$out);
//echo $out;
//} else {
//echo "Not a valid GPX file.";
//}
if ( (strstr($_SERVER['HTTP_REFERER'], "http://mapy.hiking.sk/index-test.php") !== false ) || $_GET["debug"]=="1") {
$xdoc->preserveWhiteSpace = true;
if ($xdoc->loadXML($out) === false) {
die("invalid XML");
} else {
foreach ($xdoc->getElementsByTagName("rte") as $xparent){
$trk = $xdoc->createElement('trk','');
$xdoc->appendChild($trk);
$xparent->parentNode->insertBefore($trk, $xparent);
$trkseg = $xdoc->createElement('name','Test');
$xdoc->appendChild($trkseg);
$trk->insertBefore($trkseg);
$trkseg = $xdoc->createElement('trkseg','');
$xdoc->appendChild($trkseg);
$trk->insertBefore($trkseg);
foreach ($xparent->getElementsByTagName("rtept") as $xnode ){
$new = $xdoc->createElement('trkpt','');
$xdoc->appendChild($new);
$new_attr = $xdoc->createAttribute("lat");
$new->appendChild($new_attr);
$new_text = $xdoc->createTextNode($xnode->getAttribute('lat'));
$new_attr->appendChild($new_text);
$new_attr = $xdoc->createAttribute("lon");
$new->appendChild($new_attr);
$new_text = $xdoc->createTextNode($xnode->getAttribute('lon'));
$new_attr->appendChild($new_text);
$trkseg->insertBefore($new);
$xparent->removeChild($xnode);
$ele = $xdoc->createElement('ele','0');
$xdoc->appendChild($ele);
$new->insertBefore($ele);
}
$xparent->parentNode->removeChild($xparent);
}
foreach ( $xdoc->getElementsByTagName("copyright") as $xnode ){
$xnode->parentNode->removeChild($xnode);
}
//$xdoc->SchemaValidate($xmlschema1);
echo $xdoc->saveXML();
}
} else {
echo $out;
}
?>
if ($init != "") { ?>
} ?>