123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- require_once INSTALLDIR . '/lib/feeds/atomlistnoticefeed.php';
- class ApiTimelineListAction extends ApiPrivateAuthAction
- {
- var $list = null;
- var $notices = array();
- var $next_cursor = 0;
- var $prev_cursor = 0;
- var $cursor = -1;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->cursor = (int) $this->arg('cursor', -1);
- $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (empty($this->list)) {
-
- $this->clientError(_('List not found.'), 404);
- }
- $this->getNotices();
- $this->showTimeline();
- }
-
- function showTimeline()
- {
-
- $atom = new AtomListNoticeFeed($this->list, $this->auth_user);
- $self = $this->getSelfUri();
- switch($this->format) {
- case 'xml':
- $this->initDocument('xml');
- $this->elementStart('statuses_list',
- array('xmlns:statusnet' => 'http://status.net/schema/api/1/'));
- $this->elementStart('statuses', array('type' => 'array'));
- foreach ($this->notices as $n) {
- $twitter_status = $this->twitterStatusArray($n);
- $this->showTwitterXmlStatus($twitter_status);
- }
- $this->elementEnd('statuses');
- $this->element('next_cursor', null, $this->next_cursor);
- $this->element('previous_cursor', null, $this->prev_cursor);
- $this->elementEnd('statuses_list');
- $this->endDocument('xml');
- break;
- case 'rss':
- $this->showRssTimeline(
- $this->notices,
- $atom->title,
- $this->list->getUri(),
- $atom->subtitle,
- null,
- $atom->logo,
- $self
- );
- break;
- case 'atom':
- header('Content-Type: application/atom+xml; charset=utf-8');
- try {
- $atom->setId($self);
- $atom->setSelfLink($self);
- $atom->addEntryFromNotices($this->notices);
- $this->raw($atom->getString());
- } catch (Atom10FeedException $e) {
-
-
- $this->serverError(sprintf(_('Could not generate feed for list - %s'), $e->getMessage()));
- }
- break;
- case 'json':
- $this->initDocument('json');
- $statuses = array();
- foreach ($this->notices as $n) {
- $twitter_status = $this->twitterStatusArray($n);
- array_push($statuses, $twitter_status);
- }
- $statuses_list = array('statuses' => $statuses,
- 'next_cursor' => $this->next_cusror,
- 'next_cursor_str' => strval($this->next_cusror),
- 'previous_cursor' => $this->prev_cusror,
- 'previous_cursor_str' => strval($this->prev_cusror)
- );
- $this->showJsonObjects($statuses_list);
- $this->initDocument('json');
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function getNotices()
- {
- $fn = array($this->list, 'getNotices');
- list($this->notices, $this->next_cursor, $this->prev_cursor) =
- Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
- if (!$this->notices) {
- $this->notices = array();
- }
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- if (!empty($this->notices) && (count($this->notices) > 0)) {
- return strtotime($this->notices[0]->created);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->notices) && (count($this->notices) > 0)) {
- $last = count($this->notices) - 1;
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_language(),
- $this->list->id,
- strtotime($this->notices[0]->created),
- strtotime($this->notices[$last]->created))
- )
- . '"';
- }
- return null;
- }
- }
|