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\-\_\:\.]+(?