/* 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
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 {
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);
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
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.