3 * Laconica, the distributed open-source microblogging tool
5 * Action for showing Twitter-like JSON search results
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@controlyourself.ca>
25 * @copyright 2008-2009 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/twitterapi.php';
35 require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
38 * Action handler for Twitter-compatible API search
42 * @author Zach Copley <zach@controlyourself.ca>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://laconi.ca/
45 * @see TwitterapiAction
48 class TwitapisearchjsonAction extends TwitterapiAction
61 * @param array $args Web and URL arguments
63 * @return boolean true if nothing goes wrong
66 function prepare($args)
68 parent::prepare($args);
70 $this->query = $this->trimmed('q');
71 $this->lang = $this->trimmed('lang');
72 $this->rpp = $this->trimmed('rpp');
78 if ($this->rpp > 100) {
82 $this->page = $this->trimmed('page');
88 $this->since_id = $this->trimmed('since_id');
89 $this->geocode = $this->trimmed('geocode');
97 * @param array $args Arguments from $_REQUEST
102 function handle($args)
104 parent::handle($args);
105 $this->showResults();
109 * Show search results
114 function showResults()
117 // TODO: Support search operators like from: and to:, boolean, etc.
119 $notice = new Notice();
121 // lcase it for comparison
122 $q = strtolower($this->query);
124 $search_engine = $notice->getSearchEngine('identica_notices');
125 $search_engine->set_sort_mode('chron');
126 $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
127 $search_engine->query($q);
128 $cnt = $notice->find();
130 // TODO: since_id, lang, geocode
132 $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page);
134 $this->init_document('json');
136 $this->end_document('json');
140 * Do we need to write to the database?
142 * @return boolean true
145 function isReadOnly($args)