/** * Get notices * * @param integer $limit max number of notices to return * * @return array notices */ function getNotices($limit = 0) { $notices = array(); $notice = Notice::publicStream(0, $limit == 0 ? 48 : $limit); while ($notice->fetch()) { $notices[] = clone $notice; } return $notices; }
function public_timeline($args, $apidata) { parent::handle($args); $sitename = common_config('site', 'name'); $title = sprintf(_("%s public timeline"), $sitename); $taguribase = common_config('integration', 'taguri'); $id = "tag:{$taguribase}:PublicTimeline"; $link = common_root_url(); $subtitle = sprintf(_("%s updates from everyone!"), $sitename); // Number of public statuses to return by default -- Twitter sends 20 $MAX_PUBSTATUSES = 20; // FIXME: To really live up to the spec we need to build a list // of notices by users who have custom avatars, so fix this SQL -- Zach $page = $this->arg('page'); $since_id = $this->arg('since_id'); $before_id = $this->arg('before_id'); // NOTE: page, since_id, and before_id are extensions to Twitter API -- TB if (!$page) { $page = 1; } if (!$since_id) { $since_id = 0; } if (!$before_id) { $before_id = 0; } $since = strtotime($this->arg('since')); $notice = Notice::publicStream(($page - 1) * $MAX_PUBSTATUSES, $MAX_PUBSTATUSES, $since_id, $before_id, $since); if ($notice) { switch ($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notice); break; case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notice); break; default: $this->clientError(_('API method not found!'), $code = 404); break; } } else { $this->serverError(_('Couldn\'t find any statuses.'), $code = 503); } }
/** * Read and validate arguments * * @param array $args URL parameters * * @return boolean success value */ function prepare($args) { parent::prepare($args); $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; if ($this->page > MAX_PUBLIC_PAGE) { $this->clientError(sprintf(_("Beyond the page limit (%s)."), MAX_PUBLIC_PAGE)); } common_set_returnto($this->selfUrl()); $this->notice = Notice::publicStream(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if (!$this->notice) { $this->serverError(_('Could not retrieve public stream.')); return; } if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404) $this->serverError(_('您访问的网页不存在'), $code = 404); } return true; }
/** * Fill the content area * * Shows a list of the notices in the public stream, with some pagination * controls. * * @return void */ function showContent() { $notice = Notice::publicStream(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if (!$notice) { $this->serverError(_('Could not retrieve public stream.')); return; } $nl = new NoticeList($notice, $this); $cnt = $nl->show(); $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'public'); }
/** * Get notices * * @return array notices */ function getNotices() { $notices = array(); $notice = Notice::publicStream(($this->page - 1) * $this->count, $this->count, $this->since_id, $this->max_id); while ($notice->fetch()) { $notices[] = clone $notice; } return $notices; }
/** * Get notices * * @param integer $limit max number of notices to return * * @return array notices */ protected function getNotices() { $stream = Notice::publicStream(0, $this->limit); return $stream->fetchAll(); }