2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 // XXX: put that function somewhere else. It's used in changes.php
6 function relative_path ($url_str) {
7 $url = parse_url ($url_str);
8 if ($url ['host'] != $_SERVER ['HTTP_HOST']) {
12 // first strip common directory names
13 $url_path = split ('/', $url ['path']);
14 $script_path = split ('/', $_SERVER ['SCRIPT_NAME']);
15 $len = min (count ($url_path), count ($script_path));
16 while ($url_path [0] == $script_path [0]) {
17 array_shift ($url_path);
18 array_shift ($script_path);
21 // $url_path contains $script_path; abort
22 if (count ($script_path) == 0) {
26 // now, create relative path
28 for ($i = 0; $i < (count ($script_path) - 1); $i++) {
31 $relpath .= join ("/", $url_path);
36 private $imgurl = null;
37 private $title = null;
38 private $description = null;
42 const err_lonlat_invalid = 1;
44 function __construct ($imgurl, $title, $description, $lon, $lat) {
46 // tries to transform full url in relative path
47 $relpath = relative_path ($imgurl);
48 if (isset ($relpath)) {
49 $this->imgurl = $relpath;
51 $this->imgurl = $imgurl;
55 $this->title = $title;
58 $this->description = $description;
61 if (!isset ($lon) || !is_numeric ($lon) ||
62 ($lon < -180) || ($lon > 180)) {
63 throw new Exception ($this->err_lonlat_invalid);
68 if (!isset ($lat) || !is_numeric ($lat) ||
69 ($lat < -90) || ($lat > 90)) {
70 throw new Exception ($this->err_lonlat_invalid);
75 public function __get ($attr) {
76 if (isset ($this->$attr)) return $this->$attr;
77 else throw new Exception ('Unknow attribute '.$attr);
80 public function __set ($attr,$value) {
81 throw new Exception ('properties can only be set in constructor');
84 public function imgurl_exists () {
85 if (file_exists ($this->imgurl)) {
88 if (!function_exists ("curl_init")) {
91 $handle = curl_init ($this->imgurl);
92 if ($handle === false)
96 curl_setopt ($handle, CURLOPT_NOBODY, true);
97 curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 10);
98 curl_setopt ($handle, CURLOPT_TIMEOUT, 10);
99 $connectable = curl_exec ($handle);
100 curl_close ($handle);
105 interface anydbConnection {
106 const err_driver_unavailable = 1;
107 const err_connection = 2;
108 const err_unknown_database = 3;
112 * connect to database; That method may be called multiple times.
114 public function connect($host, $user, $pwd, $dbname, $dbprefix);
117 * return true if users table already exists
119 public function users_table_exists();
122 * create users table; if $error_if_exists is true; throws an err_query
123 * error in case users table already exists.
125 public function create_users_table($error_if_exists);
128 * return true if items table already exists
130 public function items_table_exists();
133 * create items table; if $error_if_exists is true; throws an err_query
134 * error in case items table already exists.
136 public function create_items_table($error_if_exists);
139 * set password $pwd for user $usrname. If $usrname does not exist, create
142 public function setpwd($usrname, $pwd);
145 * check that $pwd_md5 is md5 for $username password.
147 public function checkpwdmd5($usrname, $pwd_md5);
150 * saves feature in database. Returns false if $feature does not exist and
151 * if $feature->imgurl is not accessible; returns true otherwise.
153 public function save_feature($feature);
156 * delete feature from database. Returns true in case of success, even if
157 * image was not referenced in the database.
159 public function delete_feature($feature);
162 * Returns feature with given imgurl. If none exists, returns null.
164 public function getfeature($imgurl);
167 * returns an array of available features
169 public function listfeatures();
172 * returns true if a feature with imgurl exists
174 public function imgurl_exists($imgurl);
177 * returns Minimum Bounding Rectangle containing all feature locations.
178 * That function must return a result even if database is not functional.
179 * Minimum Bounding Rectangle is presented as an Array:
180 * [bottom, left, top, right]
182 public function mbr();
185 * get name of database backend
187 public function getdbname();