X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapisearchjson.php;h=794f23077bacbc1184c972888dad3c7db2b774c8;hb=ad3b62cf2f857d53113692f5a12adce616f17829;hp=710ccdcccf94830efa7d8cf205ec230205fe9d02;hpb=2a4dc77a633cc78907934fd93200ac16d55be78e;p=quix0rs-gnu-social.git diff --git a/actions/apisearchjson.php b/actions/apisearchjson.php index 710ccdcccf..794f23077b 100644 --- a/actions/apisearchjson.php +++ b/actions/apisearchjson.php @@ -20,19 +20,15 @@ * along with this program. If not, see . * * @category Search - * @package StatusNet + * @package GNUsocial * @author Zach Copley * @copyright 2008-2010 StatusNet, Inc. + * @copyright 2013 Free Software Foundation, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @link http://www.gnu.org/software/social/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/apiprivateauth.php'; -require_once INSTALLDIR.'/lib/jsonsearchresultslist.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Action handler for Twitter-compatible API search @@ -89,12 +85,6 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction $this->since_id = $this->trimmed('since_id'); $this->geocode = $this->trimmed('geocode'); - if (!empty($this->auth_user)) { - $this->auth_profile = $this->auth_user->getProfile(); - } else { - $this->auth_profile = null; - } - return true; } @@ -118,77 +108,20 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction */ function showResults() { - $q = strtolower($this->query); - // TODO: Support search operators like from: and to:, boolean, etc. - if (preg_match('/^#([\pL\pN_\-\.]{1,64})$/ue', $q)) { - $stream = new TagNoticeStream(substr($q, 1), $this->auth_profile); - } else if ($this->isAnURL($q)) { - $canon = File_redirection::_canonUrl($q); - $file = File::getKV('url', $canon); - if (!empty($file)) { - $stream = new FileNoticeStream($file, $this->auth_profile); - } - } else { - $stream = new SearchNoticeStream($q, $this->auth_profile); - } + $notice = new Notice(); - if (empty($stream)) { - // XXX: This is hackish, but need some simple way to say "There's no results" - $notice = new ArrayWrapper(array()); - } else { - $notice = $stream->getNotices(($this->page - 1) * $this->rpp, $this->rpp + 1); + $this->notices = array(); + $search_engine = $notice->getSearchEngine('notice'); + $search_engine->set_sort_mode('chron'); + $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1); + if ($search_engine->query($this->query)) { + $cnt = $notice->find(); + $this->notices = $notice->fetchAll(); } - // TODO: max_id, lang, geocode - - $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page, $this->since_id); - - $this->initDocument('json'); - $results->show(); - $this->endDocument('json'); - } - - function isAnURL($q) { - $regex = '#^'. - '(?:^|[\s\<\>\(\)\[\]\{\}\\\'\\\";]+)(?![\@\!\#])'. - '('. - '(?:'. - '(?:'. //Known protocols - '(?:'. - '(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://)'. - '|'. - '(?:(?:mailto|aim|tel|xmpp):)'. - ')'. - '(?:[\pN\pL\-\_\+\%\~]+(?::[\pN\pL\-\_\+\%\~]+)?\@)?'. //user:pass@ - '(?:'. - '(?:'. - '\[[\pN\pL\-\_\:\.]+(?showJsonTimeline($this->notices); } /**