X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapitimelinepublic.php;h=07dcace942457b254660005ca48b18135c5e837d;hb=4de125dd843359c8a705c7c76eb2aa5f74efce68;hp=30f9f4cda6735ac6dbf5899156d1d08d819e9b48;hpb=2260d6ec7c1f2b9c63196a4d8c6c99750a89eb10;p=quix0rs-gnu-social.git diff --git a/actions/apitimelinepublic.php b/actions/apitimelinepublic.php index 30f9f4cda6..07dcace942 100644 --- a/actions/apitimelinepublic.php +++ b/actions/apitimelinepublic.php @@ -29,6 +29,7 @@ * @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/ */ @@ -37,8 +38,6 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/lib/apiprivateauth.php'; - /** * Returns the most recent notices (default 20) posted by everybody * @@ -143,10 +142,8 @@ require_once INSTALLDIR . '/lib/apiprivateauth.php'; @endverbatim */ - class ApiTimelinePublicAction extends ApiPrivateAuthAction { - var $notices = null; /** @@ -157,8 +154,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * @return boolean success flag * */ - - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -172,33 +168,37 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * * Just show the notices * - * @param array $args $_REQUEST data (unused) - * * @return void */ - - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); $this->showTimeline(); } + function title() + { + // TRANS: Title for site timeline. %s is the GNU social sitename. + return sprintf(_("%s public timeline"), common_config('site', 'name')); + } + /** * Show the timeline of notices * * @return void */ - function showTimeline() { - $sitename = common_config('site', 'name'); + $nonapi_action = substr($this->action, strlen('apitimeline')); // Just so we don't need to set this explicitly + $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'); - $title = sprintf(_("%s public timeline"), $sitename); + $title = $this->title(); $taguribase = TagURI::base(); - $id = "tag:$taguribase:PublicTimeline"; - $link = common_local_url('public'); + $id = "tag:$taguribase:" . ucfirst($nonapi_action) . 'Timeline'; // Public or Networkpublic probably + $link = common_local_url($nonapi_action); $self = $this->getSelfUri(); - $subtitle = sprintf(_("%s updates from everyone!"), $sitename); + // TRANS: Subtitle for site timeline. %s is the GNU social sitename. + $subtitle = sprintf(_("%s updates from everyone!"), common_config('site', 'name')); switch($this->format) { case 'xml': @@ -219,14 +219,14 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction header('Content-Type: application/atom+xml; charset=utf-8'); - $atom = new AtomNoticeFeed(); + $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->addLink(common_local_url($nonapi_action)); $atom->setSelfLink($self); $atom->addEntryFromNotices($this->notices); @@ -236,7 +236,16 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction case 'json': $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: + // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), $code = 404); break; } @@ -247,23 +256,29 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * * @return array notices */ - function getNotices() { $notices = array(); - $notice = Notice::publicStream( - ($this->page - 1) * $this->count, $this->count, $this->since_id, - $this->max_id - ); + $stream = $this->getStream(); - while ($notice->fetch()) { - $notices[] = clone($notice); - } + $notice = $stream->getNotices(($this->page - 1) * $this->count, + $this->count, + $this->since_id, + $this->max_id); + + $notices = $notice->fetchAll(); + + NoticeList::prefill($notices); return $notices; } + protected function getStream() + { + return new PublicNoticeStream($this->scoped); + } + /** * Is this action read only? * @@ -271,7 +286,6 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * * @return boolean true */ - function isReadOnly($args) { return true; @@ -282,7 +296,6 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * * @return string datestamp of the latest notice in the stream */ - function lastModified() { if (!empty($this->notices) && (count($this->notices) > 0)) { @@ -300,7 +313,6 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction * * @return string etag */ - function etag() { if (!empty($this->notices) && (count($this->notices) > 0)) { @@ -310,6 +322,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction 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)) @@ -319,5 +332,4 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction return null; } - }