X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapitimelinepublic.php;h=47e253d5fd6124dbca30354fe747995b89a03ea2;hb=7150c54a3f437043eac95d57ac9fc0672adef564;hp=10bde6f37d1beafad7f78db7297c1536f5db1944;hpb=4e1b95db283285f1ae0668745a151a6fdb5171eb;p=quix0rs-gnu-social.git diff --git a/actions/apitimelinepublic.php b/actions/apitimelinepublic.php index 10bde6f37d..47e253d5fd 100644 --- a/actions/apitimelinepublic.php +++ b/actions/apitimelinepublic.php @@ -21,8 +21,15 @@ * * @category API * @package StatusNet + * @author Craig Andrews + * @author Evan Prodromou + * @author Jeffery To + * @author mac65 + * @author Mike Cochrane + * @author Robin Millette * @author Zach Copley * @copyright 2009 StatusNet, Inc. + * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -31,21 +38,114 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR.'/lib/twitterapi.php'; +require_once INSTALLDIR . '/lib/apiprivateauth.php'; /** * Returns the most recent notices (default 20) posted by everybody * * @category API * @package StatusNet + * @author Craig Andrews + * @author Evan Prodromou + * @author Jeffery To + * @author mac65 + * @author Mike Cochrane + * @author Robin Millette * @author Zach Copley * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiTimelinePublicAction extends TwitterapiAction -{ +/* External API usage documentation. Please update when you change how this method works. */ + +/*! @page publictimeline statuses/public_timeline + + @section Description + Returns the 20 most recent notices from users throughout the system who have + uploaded their own avatars. Depending on configuration, it may or may not + not include notices from automatic posting services. + + @par URL patterns + @li /api/statuses/public_timeline.:format + + @par Formats (:format) + xml, json, rss, atom + + @par HTTP Method(s) + GET + + @par Requires Authentication + No + + @param since_id (Optional) Returns only statuses with an ID greater + than (that is, more recent than) the specified ID. + @param max_id (Optional) Returns only statuses with an ID less than + (that is, older than) or equal to the specified ID. + @param count (Optional) Specifies the number of statuses to retrieve. + @param page (Optional) Specifies the page of results to retrieve. + @sa @ref apiroot + + @subsection usagenotes Usage notes + @li The URL pattern is relative to the @ref apiroot. + @li The XML response uses GeoRSS + to encode the latitude and longitude (see example response below ). + + @subsection exampleusage Example usage + + @verbatim + curl http://identi.ca/api/statuses/friends_timeline/evan.xml?count=1&page=2 + @endverbatim + + @subsection exampleresponse Example response + + @verbatim + + + + @skwashd oh, commbank reenabled me super quick both times. but disconcerting when you don't expect it though + false + Sat Apr 17 00:49:12 +0000 2010 + 28838393 + xmpp + 28838456 + 39303 + skwashd + + false + + 44517 + joshua may + notjosh + + + http://avatar.identi.ca/44517-48-20090321004106.jpeg + + false + 17 + + + + + + 20 + Sat Mar 21 00:40:25 +0000 2009 + 0 + 0 + UTC + + false + 100 + false + false + + + [....] + +@endverbatim +*/ +class ApiTimelinePublicAction extends ApiPrivateAuthAction +{ var $notices = null; /** @@ -56,17 +156,10 @@ class ApiTimelinePublicAction extends TwitterapiAction * @return boolean success flag * */ - function prepare($args) { parent::prepare($args); - $this->page = (int)$this->arg('page', 1); - $this->count = (int)$this->arg('count', 20); - $this->max_id = (int)$this->arg('max_id', 0); - $this->since_id = (int)$this->arg('since_id', 0); - $this->since = $this->arg('since'); - $this->notices = $this->getNotices(); return true; @@ -81,7 +174,6 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return void */ - function handle($args) { parent::handle($args); @@ -93,35 +185,66 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return void */ - function showTimeline() { $sitename = common_config('site', 'name'); + $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'); + // TRANS: Title for site timeline. %s is the StatusNet sitename. $title = sprintf(_("%s public timeline"), $sitename); - $taguribase = common_config('integration', 'taguri'); + $taguribase = TagURI::base(); $id = "tag:$taguribase:PublicTimeline"; - $link = common_root_url(); + $link = common_local_url('public'); + $self = $this->getSelfUri(); + // TRANS: Subtitle for site timeline. %s is the StatusNet sitename. $subtitle = sprintf(_("%s updates from everyone!"), $sitename); - switch($this->arg('format')) { + switch($this->format) { case 'xml': - $this->show_xml_timeline($this->notices); + $this->showXmlTimeline($this->notices); break; case 'rss': - $this->show_rss_timeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline( + $this->notices, + $title, + $link, + $subtitle, + null, + $sitelogo, + $self + ); break; case 'atom': - $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; - $this->show_atom_timeline( - $this->notices, $title, $id, $link, - $subtitle, null, $selfuri - ); + + header('Content-Type: application/atom+xml; charset=utf-8'); + + $atom = new AtomNoticeFeed($this->auth_user); + + $atom->setId($id); + $atom->setTitle($title); + $atom->setSubtitle($subtitle); + $atom->setLogo($sitelogo); + $atom->setUpdated('now'); + $atom->addLink(common_local_url('public')); + $atom->setSelfLink($self); + $atom->addEntryFromNotices($this->notices); + + $this->raw($atom->getString()); + break; case 'json': - $this->show_json_timeline($this->notices); + $this->showJsonTimeline($this->notices); + break; + case 'as': + header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE); + $doc = new ActivityStreamJSONDocument($this->auth_user); + $doc->setTitle($title); + $doc->addLink($link, 'alternate', 'text/html'); + $doc->addItemsFromNotices($this->notices); + $this->raw($doc->asString()); break; default: - $this->clientError(_('API method not found!'), $code = 404); + // TRANS: Client error displayed when coming across a non-supported API method. + $this->clientError(_('API method not found.'), $code = 404); break; } } @@ -131,14 +254,13 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return array notices */ - function getNotices() { $notices = array(); $notice = Notice::publicStream( ($this->page - 1) * $this->count, $this->count, $this->since_id, - $this->max_id, $this->since + $this->max_id ); while ($notice->fetch()) { @@ -155,7 +277,6 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return boolean true */ - function isReadOnly($args) { return true; @@ -166,7 +287,6 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return string datestamp of the latest notice in the stream */ - function lastModified() { if (!empty($this->notices) && (count($this->notices) > 0)) { @@ -184,7 +304,6 @@ class ApiTimelinePublicAction extends TwitterapiAction * * @return string etag */ - function etag() { if (!empty($this->notices) && (count($this->notices) > 0)) { @@ -194,6 +313,7 @@ class ApiTimelinePublicAction extends TwitterapiAction return '"' . implode( ':', array($this->arg('action'), + common_user_cache_hash($this->auth_user), common_language(), strtotime($this->notices[0]->created), strtotime($this->notices[$last]->created)) @@ -203,5 +323,4 @@ class ApiTimelinePublicAction extends TwitterapiAction return null; } - }