From: Evan Prodromou Date: Mon, 12 Nov 2012 02:27:11 +0000 (-0500) Subject: Divert tag and url searches X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=edf28790211d707df05e65d158119b345c8b76d9;p=quix0rs-gnu-social.git Divert tag and url searches --- diff --git a/actions/apisearchjson.php b/actions/apisearchjson.php index 7ee353440f..dcdf055c6f 100644 --- a/actions/apisearchjson.php +++ b/actions/apisearchjson.php @@ -122,9 +122,24 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction // TODO: Support search operators like from: and to:, boolean, etc. - $stream = new SearchNoticeStream($q, $this->auth_profile); + if (preg_match('/^#([\pL\pN_\-\.]{1,64})/ue', $this->q)) { + $stream = new TagNoticeStream(substr($q, 1), $this->auth_profile); + } else if ($this->isAnURL($q)) { + $canon = File_redirection::_canonUrl($q); + $file = File::staticGet('url', $canon); + if (!empty($file)) { + $stream = new FileNoticeStream($file, $this->auth_profile); + } + } else { + $stream = new SearchNoticeStream($q, $this->auth_profile); + } - $notice = $stream->getNotices(($this->page - 1) * $this->rpp, $this->rpp + 1); + 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); + } // TODO: max_id, lang, geocode @@ -135,6 +150,47 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction $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\-\_\:\.]+(?