[aur-dev] [PATCH] simplified query method
--- 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 ' 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
participants (1)
-
Sylvester Johansson