X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=inc%2Fdb%2Fanydb.php;h=c88367a46277fb081309b020288e58eed88a6647;hp=7706506420d5615de4d7a98b5cdff4a8c4d1d855;hb=57511b4efd7402ef58de66ac1fe2c01ed1b1d7b5;hpb=7282fabcfef34ef95b8c6bd414f34d77037451e1 diff --git a/inc/db/anydb.php b/inc/db/anydb.php index 7706506..c88367a 100644 --- a/inc/db/anydb.php +++ b/inc/db/anydb.php @@ -2,53 +2,22 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -// XXX: put that function somewhere else. It's used in changes.php -function relative_path ($url_str) { - $url = parse_url ($url_str); - if ($url ['host'] != $_SERVER ['HTTP_HOST']) { - return null; - } - - // first strip common directory names - $url_path = split ('/', $url ['path']); - $script_path = split ('/', $_SERVER ['SCRIPT_NAME']); - $len = min (count ($url_path), count ($script_path)); - while ($url_path [0] == $script_path [0]) { - array_shift ($url_path); - array_shift ($script_path); - } - - // $url_path contains $script_path; abort - if (count ($script_path) == 0) { - return null; - } - - // now, create relative path - $relpath = ""; - for ($i = 0; $i < (count ($script_path) - 1); $i++) { - $relpath .= "../"; - } - $relpath .= join ("/", $url_path); - return $relpath; -} - class feature { - private $imgurl = null; - private $title = null; - private $description = null; + private $id = null; private $lon = null; private $lat = null; + private $imgpath = null; + private $title = null; + private $description = null; const err_lonlat_invalid = 1; - function __construct ($imgurl, $title, $description, $lon, $lat) { - // imgurl - // tries to transform full url in relative path - $relpath = relative_path ($imgurl); - if (isset ($relpath)) { - $this->imgurl = $relpath; - } else { - $this->imgurl = $imgurl; + function __construct ($id, $lon, $lat, $imgpath, $title, $description) { + $this->imgpath = $imgpath; + + // id + if (isset ($id)) { + $this->id = $id; } // title @@ -81,25 +50,6 @@ class feature { throw new Exception ('properties can only be set in constructor'); } - public function imgurl_exists () { - if (file_exists ($this->imgurl)) { - return true; - } - if (!function_exists ("curl_init")) { - return false; - } - $handle = curl_init ($this->imgurl); - if ($handle === false) - { - return false; - } - curl_setopt ($handle, CURLOPT_NOBODY, true); - curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt ($handle, CURLOPT_TIMEOUT, 10); - $connectable = curl_exec ($handle); - curl_close ($handle); - return $connectable; - } } interface anydbConnection { @@ -147,8 +97,8 @@ interface anydbConnection { public function checkpwdmd5($usrname, $pwd_md5); /* - * saves feature in database. Returns false if $feature does not exist and - * if $feature->imgurl is not accessible; returns true otherwise. + * saves feature in database. If feature has an id, feature will be updated + * in database; otherwise it will be created. Returns saved feature */ public function save_feature($feature); @@ -159,9 +109,9 @@ interface anydbConnection { public function delete_feature($feature); /* - * Returns feature with given imgurl. If none exists, returns null. + * Returns feature with given id. If none exists, returns null. */ - public function getfeature($imgurl); + public function getfeature($id); /* * returns an array of available features @@ -169,9 +119,9 @@ interface anydbConnection { public function listfeatures(); /* - * returns true if a feature with imgurl exists + * returns true if a feature with imgpath exists */ - public function imgurl_exists($imgurl); + public function imgpath_exists($imgpath); /* * returns Minimum Bounding Rectangle containing all feature locations.