"; $x = str_replace('%', '(percent)', $x); $x = str_replace(';', '(semicolon)', $x); $x = str_replace('*', '(asterisk)', $x); $x = str_replace('/', '(slash)', $x); $x = str_replace("\\", '(backslash)', $x); $x = str_replace('~', '(tilda)', $x); $x = str_replace('>', '(GT)', $x); $x = str_replace('<', '(LT)', $x); $x = str_replace('?', '(question)', $x); $x = str_replace('-', '(minus)', $x); system ("/usr/bin/logger -t guidepostphp '$x'"); } ################################################################################ function get_param($param) ################################################################################ { if (isset($_GET[$param])) {return($_GET[$param]);} if (isset($_POST[$param])) {return($_POST[$param]);} return ""; } ################################################################################ function page_header() ################################################################################ { if (get_param("source") == "mobile") { return; } print "\n"; print "\n"; print " \n"; print " \n"; print " openstreetmap.cz image upload\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } ################################################################################ function page_footer() ################################################################################ { if (get_param("source") == "mobile") { return; } print " \n"; print "\n"; } ################################################################################ function show_upload_dialog() ################################################################################ { $PHP_SELF = $_SERVER['PHP_SELF']; print " \n"; $title_help = "Pokud víte že má obrázek Exif souřadnice, můžete nechat lat, lon na 0,0 (není nutno zatrhávat exif)"; print "


Rozcestník Mapa Panorama Informační tabule

Uploading...

\n"; } ################################################################################ function show_iphone_upload_dialog() ################################################################################ { $PHP_SELF = $_SERVER['PHP_SELF']; print"\n"; print " \n"; $title_help = "Pokud má obrázek Exif souřadnice, můžete nechat lat, lon na 0,0"; print "

id='upload_process'>Uploading...

\n"; //set widht and height to display debug output } ################################################################################ function insert_to_db($lat, $lon, $url ,$file, $author, $ref, $note, $license) ################################################################################ { global $global_error_message; $database = new SQLite3('guidepost');; if (!$database) { $global_error_message = (file_exists('guidepost')) ? "Impossible to open, check permissions" : "Impossible to create, check permissions"; return 0; } $q = "insert into guidepost values (NULL, '$lat', '$lon', '$url', '$file', '$author', '$ref', '$note', '$license')"; $query = $database->exec($q); if (!$query) { $global_error_message = "Error: $query_error"; return 0; } printdebug("insert_to_db(): insert successful"); return 1; } ################################################################################ function process_file() ################################################################################ { global $_POST; global $global_error_message; $result = 0; printdebug("!!! START !!!"); $filename = $_FILES['uploadedfile']['name']; $error_message = "OK"; printdebug("name: $filename"); printdebug("type: ".$_FILES['uploadedfile']['type']); printdebug("size: ".$_FILES['uploadedfile']['size']); printdebug("tmp: ".$_FILES['uploadedfile']['tmp_name']); printdebug("error: ".$_FILES['uploadedfile']['error']); $license = $_POST['license']; $lat = $_POST['lat']; $lon = $_POST['lon']; $author = $_POST['author']; if (isset($_POST['ref'])) { $ref = $_POST['ref']; } else { $ref = "none"; } $note = $_POST['note']; printdebug("ref: ".$ref); printdebug("note: ".$note); printdebug("lat:lon:author:license"); printdebug("before $lat:$lon:$author:$license"); $author = preg_replace('/[^-a-zA-Z0-9_ěščřžýáíéĚŠČŘŽÁÍÉúůÚľĽ .]/', '', $author); $note = preg_replace('/[^-a-zA-Z0-9_ěščřžýáíéĚŠČŘŽÁÍÉúůÚľĽ .]/', '', $note); $lat = preg_replace('/,/', '\.', $lat); $lon = preg_replace('/,/', '\.', $lon); $lat = preg_replace('/[^0-9.]/', '', $lat); $lon = preg_replace('/[^0-9.]/', '', $lon); $ref = preg_replace('/[^a-zA-Z0-9.,\/]/', '', $ref); $license = preg_replace('/[^CBYSA2340plus]/', '', $license); printdebug("after $lat:$lon:$author:$license"); $file = basename($filename); $target_path = "uploads/" . $file; $final_path = "img/guidepost/" . $file; printdebug("target: $target_path"); #keep this as the first test if (file_exists($_FILES['uploadedfile']['tmp_name'])) { printdebug("soubor byl uspesne uploadnut do tmp\n"); $result = 1; } else { printdebug("cannot upload file\n"); $error_message = "nepodarilo se uploadnout soubor"; $result = 0; } if ($_FILES['uploadedfile']['error'] == "1") { $error_message = "soubor je prilis velky"; $result = 0; } if (!is_utf8($author)) { printdebug("author is not valid utf8"); $error_message = "author is not valid utf8"; $result = 0; } if (!is_utf8($note)) { printdebug("note is not valid utf8"); $error_message = "note is not valid utf8"; $result = 0; } if ($lat > 180 or $lon > 180 or $lat < -180 or $lon < -180) { printdebug("neplatna souradnice\n"); $error_message = "bad coordinates"; $result = 0; } if ($author == "") { $error_message = "author nezadan"; $result = 0; } if ($author === "android" or $author === "autor") { $error_message = "zmente vase jmeno"; $result = 0; } #sanitize filename if (strpos($filename, ';') !== FALSE) { $error_message = "spatny soubor strednik"; $result = 0; } if (strpos($filename, '&') !== FALSE) { $error_message = "spatny soubor divnaosmicka"; $result = 0; } $file_parts = pathinfo($filename); $ext = $file_parts['extension']; if ($ext !== "jpg" && $ext !== "JPG") { $error_message = "spatny soubor, pouzijte jpeg " . $file_parts['extension']; $result = 0; } if (file_exists("img/guidepost/$file")) { $error_message = "file already exists ($file), please rename your copy"; $result = 0; } if ($result) { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { printdebug("File '$file' has been moved from tmp to $target_path"); if (!$lat && !$lon) { printdebug("soubor byl poslan se souradnicemi 0,0 -> exifme"); $command = "/var/www/mapy/exifme.pl '$target_path' '$author' img/guidepost/ '$ref' '$note' '$license'"; $out = system ($command, $errlvl); printdebug("command:output(exit code) - $command:$out($errlvl)"); if (!$errlvl) { $result = 1; } else { $result = 0; $error_message = "poslano latlon 0,0 a nepodarilo se zjistit souradnice z exif" . $out; printdebug("exifme error $error_message"); } } else { printdebug("soubor byl poslan se souradnicemi ve formulari"); if (!copy ("uploads/$file","img/guidepost/$file")) { $error_message = "failed to copy $file to destination ... "; $result = 0; } else { $ret_db = insert_to_db($lat, $lon, $final_path, $file, $author, $ref, $note, $license); if ($ret_db) { if (!unlink ("uploads/$file")) { printdebug("$file cannot be deleted from upload, inserted successfuly"); } } else { $error_message = "failed to insert to db" . $global_error_message; $result = 0; } } } printdebug("error message:".$error_message); } else { $error_message = "Chyba pri otevirani souboru, mozna je prilis velky"; $result = 0; } } else { printdebug("Upload refused: ".$error_message); } if ($result == 0 and $error_message == "") { $error_message = "Divna chyba"; } if (get_param("source") == "mobile") { print "$result-$error_message"; } else { print " \n"; print " \n"; print "
\n"; } printdebug("!!! END !!!"); return $result; } ################################################################################ function create_db() ################################################################################ { global $db; global $create_query; $create_query = "CREATE TABLE guidepost ( id int, lat numeric, lon numeric, url varchar, name varchar, PRIMARY KEY (id) );"; $db->queryExec($create_query); $db->queryExec("insert into guidepost values (NULL, 50.1, 17.1, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.2, 17.2, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.3, 17.3, 'x', 'znacka');"); $db->queryExec("insert into guidepost values (NULL, 50.4, 17.4, 'x', 'znacka');"); } $action = get_param("action"); switch ($action) { case "show_dialog": page_header(); show_upload_dialog(); page_footer(); break; case "file": page_header(); process_file(); page_footer(); break; case "": $bbox = get_param('bbox'); if ($bbox == "") { printdebug("no bbox"); die("No bbox provided\n"); } else { printdebug("bbox: " . $bbox); } list($minlon, $minlat, $maxlon, $maxlat) = preg_split('/,/', $bbox, 4); $db = new SQLite3('guidepost'); if ($db) { $i = 0; $result = array(); $query = "select * from guidepost where lat < $maxlat and lat > $minlat and lon < $maxlon and lon > $minlon"; printdebug("query " . $query); $results = $db->query($query); while ($row = $results->fetchArray()) { $result[$i++] = $row; } print json_encode($result); } else { printdebug("db open error: " + $err); die($err); } break; } ?>