/* 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;
+ private $date = 0;
+ private $user = 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, $date, $user) {
+ $this->imgpath = $imgpath;
+
+ // id
+ if (isset ($id)) {
+ $this->id = $id;
}
// title
// description
$this->description = $description;
+ // date
+ $this->date = $date;
+
+ // user
+ $this->user = $user;
+
// longitude
if (!isset ($lon) || !is_numeric ($lon) ||
($lon < -180) || ($lon > 180)) {
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 users_table_exists();
/*
- * create users table; if $error_if_exists is true; throws an err_query
- * error in case users table already exists.
+ * create users table;
+ * throws an err_query error in case users table already exists.
*/
- public function create_users_table($error_if_exists);
+ public function create_users_table();
/*
* return true if items table already exists
public function items_table_exists();
/*
- * create items table; if $error_if_exists is true; throws an err_query
- * error in case items table already exists.
+ * create items table;
+ * throws an err_query error in case items table already exists.
+ */
+ public function create_items_table();
+
+ /*
+ * returns true if $usrname is name of an existing user, false otherwise.
*/
- public function create_items_table($error_if_exists);
+ public function user_exists ($usrname);
/*
* set password $pwd for user $usrname. If $usrname does not exist, create
* it.
+ * throws an err_query error in case $pwd is null
*/
public function setpwd($usrname, $pwd);
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
+ * returns an array of features managed by $user. If $user is undefined or
+ * if user is "admin", return all available features.
*/
- public function listfeatures();
+ public function listfeatures($user);
/*
- * returns true if a feature with imgurl exists
+ * returns the most recent features sorted by date. If $num_features is not
+ * defined or is null, returns all features sorted by date.
*/
- public function imgurl_exists($imgurl);
+ public function mostrecentfeatures($num_features);
/*
- * returns Minimum Bounding Rectangle containing all feature locations.
- * That function must return a result even if database is not functional.
- * Minimum Bounding Rectangle is presented as an Array:
- * [bottom, left, top, right]
+ * returns true if a feature with imgpath exists
*/
- public function mbr();
+ public function imgpath_exists($imgpath);
/*
* get name of database backend