Changeset 1613
- Timestamp:
- 10/24/06 16:45:25 (3 years ago)
- Location:
- trunk/gregarius
- Files:
-
- 1 added
- 2 modified
-
api.php (modified) (2 diffs)
-
cls/search.php (modified) (5 diffs)
-
extlib/JSON.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/gregarius/api.php
r1544 r1613 49 49 blGetItems($cid,$date,$markread); 50 50 break; 51 } 51 case 'search': 52 rss_require('extlib/JSON.php'); 53 $json = new Services_JSON(); 54 $query = sanitize(@$_REQUEST['q'], RSS_SANITIZER_WORDS); 55 if ($query) { 56 $res = osSearch($query); 57 } else { 58 $res = array($query,array()); 59 } 60 header('Content-Type: application/json'); 61 die ($json->encode($res)); 62 break; 63 } 64 52 65 } 53 66 … … 195 208 196 209 } 210 211 function osSearch($q) { 212 rss_require('cls/search.php'); 213 $sil = new SearchItemList($q,5); 214 $results = array(); 215 foreach($sil -> feeds as $feed) { 216 foreach($feed -> items as $item) { 217 $results[] = $item -> title; 218 } 219 } 220 return array($q,$results); 221 } 197 222 ?> -
trunk/gregarius/cls/search.php
r1561 r1613 43 43 define ('QUERY_MATCH_EXACT','exact'); 44 44 45 // This is needed for some constants 46 rss_require('cls/wrappers/toolkit.php'); 45 47 46 48 class SearchItemList extends ItemList { … … 51 53 52 54 var $currentPage; 53 var $resultsPerPage ;55 var $resultsPerPage = 0; 54 56 var $startItem; 55 57 var $endItem; … … 58 60 var $logicSep; 59 61 60 function SearchItemList( ) {62 function SearchItemList($query=null,$results=0) { 61 63 parent::ItemList(); 64 if ($query) { 65 $this -> query=$query; 66 } elseif(isset($_REQUEST[QUERY_PRM])) { 67 $this->query = $_REQUEST[QUERY_PRM]; 68 }else{ 69 $this -> query = null; 70 } 71 72 73 // Sanitize the query parameters: 74 // fixme: this probably breaks on queries with weird characters, depending 75 // on the locale. 76 // see: http://php.benscom.com/manual/en/reference.pcre.pattern.syntax.php 77 if ($this -> query) { 78 $this -> query = trim(preg_replace('#[^\w\s\x80-\xff]#','',$this -> query)); 79 } 80 81 $this->resultsPerPage = (int) $results; 82 62 83 $this -> populate(); 63 84 … … 101 122 102 123 function populate() { 103 if (!isset($_REQUEST[QUERY_PRM])) {104 return;105 }106 107 // fixme: this probably breaks on queries with weird characters, depending108 // on the locale.109 // see: http://php.benscom.com/manual/en/reference.pcre.pattern.syntax.php110 $this->query = trim(preg_replace('#[^\w\s\x80-\xff]#','',$_REQUEST[QUERY_PRM]));111 124 112 125 if (!$this->query) { … … 122 135 RSS_SANITIZER_NUMERIC); 123 136 124 $this->resultsPerPage = sanitize( 125 ((array_key_exists(QUERY_RESULTS, $_REQUEST)) ? $_REQUEST[QUERY_RESULTS] : INFINE_RESULTS), 126 RSS_SANITIZER_NUMERIC); 127 137 if (!$this->resultsPerPage) { 138 $this->resultsPerPage = sanitize( 139 ((array_key_exists(QUERY_RESULTS, $_REQUEST)) ? $_REQUEST[QUERY_RESULTS] : INFINE_RESULTS), 140 RSS_SANITIZER_NUMERIC); 141 } 142 128 143 $this->currentPage = sanitize( 129 144 (array_key_exists(QUERY_CURRENT_PAGE, $_REQUEST) ? $_REQUEST[QUERY_CURRENT_PAGE] : 0),
