[aur-dev] (no subject)

aur-dev at archlinux.org aur-dev at archlinux.org
Fri May 30 03:42:02 EDT 2008


>From ab0903d0361049e6b7e85db3b55614bd838bdeff Mon Sep 17 00: 00:00 2001
From: Sylvester Johansson <syljo361 at gmail.com>
Date: Fri, 30 May 2008 09:33:17 +0200
To: aur-dev at archlinux.org
Subject: [PATCH] simplified query method
Message-ID: <483fafc9.2135440a.1f22.ffff8c6f at mx.google.com>

---
 web/html/rpc.php          |    3 ++-
 web/lib/aurjson.class.php |   30 +++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/web/html/rpc.php b/web/html/rpc.php
index 033cba5..d4b69f4 100644
--- a/web/html/rpc.php
+++ b/web/html/rpc.php
@@ -18,7 +18,8 @@ if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
         echo 'The methods currently allowed are: <br />';
         echo '<ul>';
         echo '<li>search</li>';
-        echo '<li>info</li>';
+	echo '<li>info</li>';
+	echo '<li>query</li>';
         echo '</ul><br />';
         echo 'Each method requires the following HTTP GET syntax:<br />';
         echo '&nbsp;&nbsp; type=<i>methodname</i>&arg=<i>data</i> <br /><br />';
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index be92c25..c691295 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -21,7 +21,7 @@ if (!extension_loaded('json'))
  **/
 class AurJSON {
     private $dbh = false;
-    private $exposed_methods = array('search','info');
+    private $exposed_methods = array('search','info','query');
 
     /**
      * Handles post data, and routes the request.
@@ -137,5 +137,33 @@ class AurJSON {
             return $this->json_error('No result found');
         }
     }
+
+    /**
+     * returns the info on the search term
+     * @param	$term is the searchterm (Name,Description) 
+     * @return mixed Returns an array array with package information
+     */
+    private function query($term) {
+	$term = mysql_real_escape_string($term);
+	
+	//build the search query
+        $base_query = "SELECT ID,Name,Version,Description,URL,URLPath,License,NumVotes,OutOfDate FROM Packages WHERE DummyPkg=0 AND " .
+	    sprintf("( Name LIKE '%%%s%%' OR Description LIKE '%%%s%%' )",$term,$term);
+
+	$results = db_query($base_query,$this->dbh);
+	if( $results && (mysql_num_rows($results) >0 )){
+
+	    $search_data = array();
+	    while($row = mysql_fetch_assoc($results)) {
+		array_push($search_data,$row);
+	    }
+ 	    mysql_free_result($results);
+	    return $this->json_results('query',$search_data);
+	}
+	else {
+	    return $this->json_error('No matches found');
+	}
+    }
 }
+
 ?>
-- 
1.5.5.1





More information about the aur-dev mailing list