X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftwitapisearchatom.php;h=1cb8d7efe6d507ced64fa7597e3683eefac4daee;hb=185e229f7974c3bee2070ee7a2e4b8aaf01ee35e;hp=3ab82bfb646949d71142eb8e2f24bb186ebfcffd;hpb=bffd931c37618c8623eb2465150ee8d9d85b7184;p=quix0rs-gnu-social.git diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index 3ab82bfb64..1cb8d7efe6 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -1,6 +1,6 @@ . * * @category Search - * @package Laconica - * @author Zach Copley - * @copyright 2008-2009 Control Yourself, Inc. + * @package StatusNet + * @author Zach Copley + * @copyright 2008-2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/twitterapi.php'; +require_once INSTALLDIR.'/lib/api.php'; /** * Action for outputting search results in Twitter compatible Atom @@ -41,18 +41,17 @@ require_once INSTALLDIR.'/lib/twitterapi.php'; * RSS10Action. * * @category Search - * @package Laconica - * @author Zach Copley + * @package StatusNet + * @author Zach Copley * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ * - * @see TwitterapiAction + * @see ApiAction */ -class TwitapisearchatomAction extends TwitterapiAction +class TwitapisearchatomAction extends ApiAction { - var $notices; var $cnt; var $query; var $lang; @@ -72,7 +71,7 @@ class TwitapisearchatomAction extends TwitterapiAction * @see Action::__construct */ - function __construct($output='php://output', $indent=true) + function __construct($output='php://output', $indent=null) { parent::__construct($output, $indent); } @@ -156,33 +155,40 @@ class TwitapisearchatomAction extends TwitterapiAction { // TODO: Support search operators like from: and to:, boolean, etc. + $notices = array(); $notice = new Notice(); // lcase it for comparison $q = strtolower($this->query); - $search_engine = $notice->getSearchEngine('identica_notices'); + $search_engine = $notice->getSearchEngine('notice'); $search_engine->set_sort_mode('chron'); $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true); - $search_engine->query($q); - $this->cnt = $notice->find(); + if (false === $search_engine->query($q)) { + $this->cnt = 0; + } else { + $this->cnt = $notice->find(); + } $cnt = 0; + $this->max_id = 0; - while ($notice->fetch()) { + if ($this->cnt > 0) { + while ($notice->fetch()) { - ++$cnt; + ++$cnt; - if (!$this->max_id) { - $this->max_id = $notice->id; - } + if (!$this->max_id) { + $this->max_id = $notice->id; + } - if ($cnt > $this->rpp) { - break; - } + if ($cnt > $this->rpp) { + break; + } - $notices[] = clone($notice); + $notices[] = clone($notice); + } } return $notices; @@ -218,19 +224,22 @@ class TwitapisearchatomAction extends TwitterapiAction { // TODO: A9 OpenSearch stuff like search.twitter.com? - $lang = common_config('site', 'language'); $server = common_config('site', 'server'); $sitename = common_config('site', 'name'); - // XXX: Use xmlns:laconica instead? + // XXX: Use xmlns:statusnet instead? $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', + + // XXX: xmlns:twitter causes Atom validation to fail + // It's used for the source attr on notices + 'xmlns:twitter' => 'http://api.twitter.com/', - 'xml:lang' => $lang)); + 'xml:lang' => 'en-US')); // XXX Other locales ? - $year = date('Y'); - $this->element('id', null, "tag:$server,$year:search/$server"); + $taguribase = common_config('integration', 'taguri'); + $this->element('id', null, "tag:$taguribase:search/$server"); $site_uri = common_path(false); @@ -251,13 +260,18 @@ class TwitapisearchatomAction extends TwitterapiAction // self link - $self_uri = $search_uri . '&page=' . $this->page; + $self_uri = $search_uri; + $self_uri .= ($this->page > 1) ? '&page=' . $this->page : ''; $this->element('link', array('type' => 'application/atom+xml', 'rel' => 'self', 'href' => $self_uri)); $this->element('title', null, "$this->query - $sitename Search"); + $this->element('updated', null, common_date_iso8601('now')); + + // XXX: The below "rel" links are not valid Atom, but it's what + // Twitter does... // refresh link @@ -308,24 +322,25 @@ class TwitapisearchatomAction extends TwitterapiAction $this->elementStart('entry'); - $year = date('Y', strtotime($notice->created)); + $taguribase = common_config('integration', 'taguri'); - $this->element('id', null, "tag:$server,$year:$notice->id"); + $this->element('id', null, "tag:$taguribase:$notice->id"); $this->element('published', null, common_date_w3dtf($notice->created)); $this->element('link', array('type' => 'text/html', 'rel' => 'alternate', 'href' => $nurl)); $this->element('title', null, common_xml_safe_str(trim($notice->content))); - $this->element('content', array('type' => 'text/html'), $notice->rendered); + $this->element('content', array('type' => 'html'), $notice->rendered); $this->element('updated', null, common_date_w3dtf($notice->created)); $this->element('link', array('type' => 'image/png', - 'rel' => 'image', + // XXX: Twitter uses rel="image" (not valid) + 'rel' => 'related', 'href' => $profile->avatarUrl())); // TODO: Here is where we'd put in a link to an atom feed for threads $this->element("twitter:source", null, - htmlentities($this->source_link($notice->source))); + htmlentities($this->sourceLink($notice->source))); $this->elementStart('author');