fix adminsearch
[plewww.git] / planetlab / common / adminsearch.php
index b47d6f3..354b179 100644 (file)
@@ -33,7 +33,11 @@ if ( ! plc_is_admin()) {
 $pattern="";
 if (isset($_GET['pattern'])) { $pattern=$_GET['pattern']; }
 if (isset($_POST['pattern'])) { $pattern=$_POST['pattern']; }
-$tokens=split(" ",$pattern);
+
+$tokens=explode(" ",$pattern);
+function token_filter ($t) { $t = trim($t); if (empty($t)) return false; return true; }
+$tokens=array_filter($tokens, "token_filter");
+
 
 ////////////////////
 // from a single search form, extract all tokens entered 
@@ -81,14 +85,21 @@ function generic_search ($type,$field,$tokens) {
   global $api;
   $results=array();
   $methodname='Get'.$type;
+  /*
+    This was broken after 598e1e840b55262fd40c6d1700148e4f0b508065 change in plcapi.
+    We no longer generate a list of methods but let the api (php) object pass them through.
+
   if ( ! method_exists($api,$methodname)) {
     plc_error("generic_search failed with methodname=$methodname");
     return $results;
   }
+  */
   foreach ($tokens as $token) {
     $filter=array($field=>token_pattern($token));
-    $results = 
-      array_merge ($results,$api->$methodname($filter));
+    $new_results = $api->$methodname($filter);
+    if (is_array($new_results)) {
+        $results = array_merge ($results, $new_results);
+    }
   }
   return $results;
 }