diff options
author | Andreas Unterkircher <unki@netshadow.at> | 2008-03-28 17:02:18 +0100 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2008-03-28 17:02:18 +0100 |
commit | 144f16a71f7289bb891c52995061aee21e3e08f9 (patch) | |
tree | b8cd9492463dad0cb0dbe751145e45a8fd54b53b /phpfspot.class.php | |
parent | af0be8f9546fb5dec947be33e465bb6d9e85d0a7 (diff) |
remove autocomplete and use autosuggest instead
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
Diffstat (limited to 'phpfspot.class.php')
-rw-r--r-- | phpfspot.class.php | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php index 9c1126d..d6ecaed 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -697,33 +697,45 @@ class PHPFSPOT { if(!isset($_GET['search']) || !is_string($_GET['search'])) $_GET['search'] = ''; - if(!isset($_GET['length']) || !is_numeric($_GET['length'])) - $_GET['length'] = 5; - + $length = 15; + $i = 1; /* retrive tags from database */ $this->get_tags(); $matched_tags = Array(); + header("Content-Type: text/xml"); + + $string = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; + $string.= "<results>\n"; + foreach($this->avail_tags as $tag) { if(!empty($_GET['search']) && preg_match("/". $_GET['search'] ."/i", $this->tags[$tag]) && - count($matched_tags) < $_GET['length']) { + count($matched_tags) < $length) { - array_push($matched_tags, $this->tags[$tag] .",". $this->tags[$tag]); + $count = $this->get_num_photos($tag); + + if($count == 1) { + $string.= " <rs id=\"". $i ."\" info=\"". $count ." photo\">". $this->tags[$tag] ."</rs>\n"; + } + else { + $string.= " <rs id=\"". $i ."\" info=\"". $count ." photos\">". $this->tags[$tag] ."</rs>\n"; + + } + $i++; } /* if we have collected enough items, break out */ - if(count($matched_tags) >= $_GET['length']) + if(count($matched_tags) >= $length) break; } - if(empty($matched_tags)) - return; + $string.= "</results>\n"; - return implode('|', $matched_tags); + return $string; } // get_xml_tag_list() @@ -2310,6 +2322,25 @@ class PHPFSPOT { { return $this->get_web_protocol() ."://". $this->get_server_name() . $this->cfg->web_path; } // get_phpfspot_url() + + /** + * returns the number of photos which are tagged with $tag_id + */ + public function get_num_photos($tag_id) + { + if($result = $this->db->db_fetchSingleRow(" + SELECT count(*) as number + FROM photo_tags + WHERE + tag_id LIKE '". $tag_id ."'")) { + + return $result['number']; + + } + + return 0; + + } // get_num_photos() /** * check file exists and is readable |