issue111, first try of auto completion for tag search box
[phpfspot.git] / phpfspot.class.php
index 7e7d4dd8ff6ad0ac067d13c54b15408459a4eb2f..9c1126dc4a7479a44d2348ec609a5420bbe3861e 100644 (file)
@@ -689,6 +689,45 @@ class PHPFSPOT {
 
    } // resetTags()
 
+   /**
+    * returns the value for the autocomplet tag-search
+    */
+   public function get_xml_tag_list()
+   {
+      if(!isset($_GET['search']) || !is_string($_GET['search']))
+         $_GET['search'] = '';
+      
+      if(!isset($_GET['length']) || !is_numeric($_GET['length']))
+         $_GET['length'] = 5;
+         
+         
+      /* retrive tags from database */
+      $this->get_tags();
+
+      $matched_tags = Array();
+
+      foreach($this->avail_tags as $tag)
+      {
+         if(!empty($_GET['search']) &&
+            preg_match("/". $_GET['search'] ."/i", $this->tags[$tag]) &&
+            count($matched_tags) < $_GET['length']) {
+
+            array_push($matched_tags, $this->tags[$tag] .",". $this->tags[$tag]);
+         }
+
+         /* if we have collected enough items, break out */
+         if(count($matched_tags) >= $_GET['length'])
+            break;
+      }
+
+      if(empty($matched_tags))
+         return;
+
+      return implode('|', $matched_tags);
+
+   } // get_xml_tag_list()
+
+
    /**
     * reset single photo
     *