/** * * @param User $user * @param boolean $indent * @param boolean $outputMode: UserActivityStream::OUTPUT_STRING to return a string, * or UserActivityStream::OUTPUT_RAW to go to raw output. * Raw output mode will attempt to stream, keeping less * data in memory but will leave $this->activities incomplete. */ function __construct($user, $indent = true, $outputMode = UserActivityStream::OUTPUT_STRING) { parent::__construct($user, null, $indent); $this->outputMode = $outputMode; if ($this->outputMode == self::OUTPUT_STRING) { // String buffering? Grab all the notices now. $notices = $this->getNotices(); } elseif ($this->outputMode == self::OUTPUT_RAW) { // Raw output... need to restructure from the stringer init. $this->xw = new XMLWriter(); $this->xw->openURI('php://output'); if (is_null($indent)) { $indent = common_config('site', 'indent'); } $this->xw->setIndent($indent); // We'll fetch notices later. $notices = array(); } else { throw new Exception('Invalid outputMode provided to ' . __METHOD__); } // Assume that everything but notices is feasible // to pull at once and work with in memory... $subscriptions = $this->getSubscriptions(); $subscribers = $this->getSubscribers(); $groups = $this->getGroups(); $faves = $this->getFaves(); $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices); // Sort by create date usort($objs, 'UserActivityStream::compareObject'); // We'll keep these around for later, and interleave them into // the output stream with the user's notices. foreach ($objs as $obj) { $this->activities[] = $obj->asActivity(); } }
function __construct($user, $indent = true) { parent::__construct($user, null, $indent); $subscriptions = $this->getSubscriptions(); $subscribers = $this->getSubscribers(); $groups = $this->getGroups(); $faves = $this->getFaves(); $notices = $this->getNotices(); $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices); // Sort by create date usort($objs, 'UserActivityStream::compareObject'); foreach ($objs as $obj) { $act = $obj->asActivity(); // Only show the author sub-element if it's different from default user $str = $act->asString(false, $act->actor->id != $this->user->uri); $this->addEntryRaw($str); } }
/** * Show the timeline of notices * * @return void */ function showTimeline() { // We'll use the shared params from the Atom stub // for other feed types. $atom = new AtomUserNoticeFeed($this->target->getUser(), $this->auth_user); $link = common_local_url('showstream', array('nickname' => $this->target->nickname)); $self = $this->getSelfUri(); // FriendFeed's SUP protocol // Also added RSS and Atom feeds $suplink = common_local_url('sup', null, null, $this->target->id); header('X-SUP-ID: ' . $suplink); // paging links $nextUrl = !empty($this->next_id) ? common_local_url('ApiTimelineUser', array('format' => $this->format, 'id' => $this->target->id), array('max_id' => $this->next_id)) : null; $prevExtra = array(); if (!empty($this->notices)) { assert($this->notices[0] instanceof Notice); $prevExtra['since_id'] = $this->notices[0]->id; } $prevUrl = common_local_url('ApiTimelineUser', array('format' => $this->format, 'id' => $this->target->id), $prevExtra); $firstUrl = common_local_url('ApiTimelineUser', array('format' => $this->format, 'id' => $this->target->id)); switch ($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': $this->showRssTimeline($this->notices, $atom->title, $link, $atom->subtitle, $suplink, $atom->logo, $self); break; case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); $atom->setId($self); $atom->setSelfLink($self); // Add navigation links: next, prev, first // Note: we use IDs rather than pages for navigation; page boundaries // change too quickly! if (!empty($this->next_id)) { $atom->addLink($nextUrl, array('rel' => 'next', 'type' => 'application/atom+xml')); } if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) { $atom->addLink($prevUrl, array('rel' => 'prev', 'type' => 'application/atom+xml')); } if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) { $atom->addLink($firstUrl, array('rel' => 'first', 'type' => 'application/atom+xml')); } $atom->addEntryFromNotices($this->notices); $this->raw($atom->getString()); break; case 'json': $this->showJsonTimeline($this->notices); break; case 'as': header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE); $doc = new ActivityStreamJSONDocument($this->auth_user); $doc->setTitle($atom->title); $doc->addLink($link, 'alternate', 'text/html'); $doc->addItemsFromNotices($this->notices); if (!empty($this->next_id)) { $doc->addLink($nextUrl, array('rel' => 'next', 'type' => ActivityStreamJSONDocument::CONTENT_TYPE)); } if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) { $doc->addLink($prevUrl, array('rel' => 'prev', 'type' => ActivityStreamJSONDocument::CONTENT_TYPE)); } if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) { $doc->addLink($firstUrl, array('rel' => 'first', 'type' => ActivityStreamJSONDocument::CONTENT_TYPE)); } $this->raw($doc->asString()); break; default: // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), 404); } }
/** * Build a single-item version of the sending user's Atom feed. * @return string */ function userFeedForNotice() { $atom = new AtomUserNoticeFeed($this->user); $atom->addEntryFromNotice($this->notice); $feed = $atom->getString(); return $feed; }
/** * Show the timeline of notices * * @return void */ function showTimeline() { $profile = $this->user->getProfile(); // We'll use the shared params from the Atom stub // for other feed types. $atom = new AtomUserNoticeFeed($this->user, $this->auth_user); $link = common_local_url('showstream', array('nickname' => $this->user->nickname)); $self = $this->getSelfUri(); // FriendFeed's SUP protocol // Also added RSS and Atom feeds $suplink = common_local_url('sup', null, null, $this->user->id); header('X-SUP-ID: ' . $suplink); switch ($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': $this->showRssTimeline($this->notices, $atom->title, $link, $atom->subtitle, $suplink, $atom->logo, $self); break; case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); $atom->setId($self); $atom->setSelfLink($self); $atom->addEntryFromNotices($this->notices); $this->raw($atom->getString()); break; case 'json': $this->showJsonTimeline($this->notices); break; default: $this->clientError(_('API method not found.'), $code = 404); break; } }
/** * Show the timeline of notices * * @return void */ function showTimeline() { $profile = $this->user->getProfile(); // We'll use the shared params from the Atom stub // for other feed types. $atom = new AtomUserNoticeFeed($this->user, $this->auth_user); $link = common_local_url('showstream', array('nickname' => $this->user->nickname)); $self = $this->getSelfUri(); // FriendFeed's SUP protocol // Also added RSS and Atom feeds $suplink = common_local_url('sup', null, null, $this->user->id); header('X-SUP-ID: ' . $suplink); switch ($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': $this->showRssTimeline($this->notices, $atom->title, $link, $atom->subtitle, $suplink, $atom->logo, $self); break; case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); $atom->setId($self); $atom->setSelfLink($self); // Add navigation links: next, prev, first // Note: we use IDs rather than pages for navigation; page boundaries // change too quickly! if (!empty($this->next_id)) { $nextUrl = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $this->user->id), array('max_id' => $this->next_id)); $atom->addLink($nextUrl, array('rel' => 'next', 'type' => 'application/atom+xml')); } if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) { $lastNotice = $this->notices[0]; $lastId = $lastNotice->id; $prevUrl = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $this->user->id), array('since_id' => $lastId)); $atom->addLink($prevUrl, array('rel' => 'prev', 'type' => 'application/atom+xml')); } if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) { $firstUrl = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $this->user->id)); $atom->addLink($firstUrl, array('rel' => 'first', 'type' => 'application/atom+xml')); } $atom->addEntryFromNotices($this->notices); $this->raw($atom->getString()); break; case 'json': $this->showJsonTimeline($this->notices); break; case 'as': header('Content-Type: application/json; charset=utf-8'); $doc = new ActivityStreamJSONDocument($this->auth_user); $doc->setTitle($atom->title); $doc->addLink($link, 'alternate', 'text/html'); $doc->addItemsFromNotices($this->notices); // XXX: Add paging extension? $this->raw($doc->asString()); break; default: // TRANS: Client error displayed when trying to handle an unknown API method. $this->clientError(_('API method not found.'), $code = 404); break; } }