Make Atom timelines in the API use Atom10feed

This commit is contained in:
Zach Copley 2010-02-11 13:54:40 -08:00
parent c8d5c8442f
commit c465f675d9
11 changed files with 308 additions and 98 deletions

View File

@ -100,11 +100,11 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile(); $profile = $this->user->getProfile();
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
$title = sprintf( $title = sprintf(
_('%1$s / Favorites from %2$s'), _('%1$s / Favorites from %2$s'),
$sitename, $sitename,
$this->user->nickname $this->user->nickname
@ -112,32 +112,69 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
$taguribase = common_config('integration', 'taguri'); $taguribase = common_config('integration', 'taguri');
$id = "tag:$taguribase:Favorites:" . $this->user->id; $id = "tag:$taguribase:Favorites:" . $this->user->id;
$link = common_local_url(
'favorites', $subtitle = sprintf(
array('nickname' => $this->user->nickname)
);
$subtitle = sprintf(
_('%1$s updates favorited by %2$s / %2$s.'), _('%1$s updates favorited by %2$s / %2$s.'),
$sitename, $sitename,
$profile->getBestName(), $profile->getBestName(),
$this->user->nickname $this->user->nickname
); );
$logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); $logo = !empty($avatar)
? $avatar->displayUrl()
: Avatar::defaultImage(AVATAR_PROFILE_SIZE);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
$this->showXmlTimeline($this->notices); $this->showXmlTimeline($this->notices);
break; break;
case 'rss': case 'rss':
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); $link = common_local_url(
'showfavorites',
array('nickname' => $this->user->nickname)
);
$this->showRssTimeline(
$this->notices,
$title,
$link,
$subtitle,
null,
$logo
);
break; break;
case 'atom': case 'atom':
$selfuri = common_root_url() .
ltrim($_SERVER['QUERY_STRING'], 'p='); header('Content-Type: application/atom+xml; charset=utf-8');
$this->showAtomTimeline(
$this->notices, $title, $id, $link, $subtitle, $atom = new AtomNoticeFeed();
null, $selfuri, $logo
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($logo);
$atom->setUpdated('now');
$atom->addLink(
common_local_url(
'showfavorites',
array('nickname' => $this->user->nickname)
)
); );
$id = $this->arg('id');
$aargs = array('format' => 'atom');
if (!empty($id)) {
$aargs['id'] = $id;
}
$atom->addLink(
$this->getSelfUri('ApiTimelineFavorites', $aargs),
array('rel' => 'self', 'type' => 'application/atom+xml')
);
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -114,39 +114,71 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
$title = sprintf(_("%s and friends"), $this->user->nickname); $title = sprintf(_("%s and friends"), $this->user->nickname);
$taguribase = common_config('integration', 'taguri'); $taguribase = common_config('integration', 'taguri');
$id = "tag:$taguribase:FriendsTimeline:" . $this->user->id; $id = "tag:$taguribase:FriendsTimeline:" . $this->user->id;
$link = common_local_url(
'all', array('nickname' => $this->user->nickname) $subtitle = sprintf(
); _('Updates from %1$s and friends on %2$s!'),
$subtitle = sprintf( $this->user->nickname, $sitename
_('Updates from %1$s and friends on %2$s!'), );
$this->user->nickname, $sitename
); $logo = (!empty($avatar))
$logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); ? $avatar->displayUrl()
: Avatar::defaultImage(AVATAR_PROFILE_SIZE);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
$this->showXmlTimeline($this->notices); $this->showXmlTimeline($this->notices);
break; break;
case 'rss': case 'rss':
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo);
$link = common_local_url(
'all', array(
'nickname' => $this->user->nickname
)
);
$this->showRssTimeline(
$this->notices,
$title,
$link,
$subtitle,
null,
$logo
);
break; break;
case 'atom': case 'atom':
$target_id = $this->arg('id'); header('Content-Type: application/atom+xml; charset=utf-8');
if (isset($target_id)) { $atom = new AtomNoticeFeed();
$selfuri = common_root_url() .
'api/statuses/friends_timeline/' . $atom->setId($id);
$target_id . '.atom'; $atom->setTitle($title);
} else { $atom->setSubtitle($subtitle);
$selfuri = common_root_url() . $atom->setLogo($logo);
'api/statuses/friends_timeline.atom'; $atom->setUpdated('now');
$atom->addLink(
common_local_url(
'all',
array('nickname' => $this->user->nickname)
)
);
$id = $this->arg('id');
$aargs = array('format' => 'atom');
if (!empty($id)) {
$aargs['id'] = $id;
} }
$this->showAtomTimeline( $atom->addLink(
$this->notices, $title, $id, $link, $this->getSelfUri('ApiTimelineFriends', $aargs),
$subtitle, null, $selfuri, $logo array('rel' => 'self', 'type' => 'application/atom+xml')
); );
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -115,39 +115,67 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
$title = sprintf(_("%s and friends"), $this->user->nickname); $title = sprintf(_("%s and friends"), $this->user->nickname);
$taguribase = common_config('integration', 'taguri'); $taguribase = common_config('integration', 'taguri');
$id = "tag:$taguribase:HomeTimeline:" . $this->user->id; $id = "tag:$taguribase:HomeTimeline:" . $this->user->id;
$link = common_local_url(
'all', array('nickname' => $this->user->nickname)
);
$subtitle = sprintf( $subtitle = sprintf(
_('Updates from %1$s and friends on %2$s!'), _('Updates from %1$s and friends on %2$s!'),
$this->user->nickname, $sitename $this->user->nickname, $sitename
); );
$logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
$logo = (!empty($avatar))
? $avatar->displayUrl()
: Avatar::defaultImage(AVATAR_PROFILE_SIZE);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
$this->showXmlTimeline($this->notices); $this->showXmlTimeline($this->notices);
break; break;
case 'rss': case 'rss':
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); $link = common_local_url(
'all',
array('nickname' => $this->user->nickname)
);
$this->showRssTimeline(
$this->notices,
$title,
$link,
$subtitle,
null,
$logo
);
break; break;
case 'atom': case 'atom':
$target_id = $this->arg('id'); header('Content-Type: application/atom+xml; charset=utf-8');
if (isset($target_id)) { $atom = new AtomNoticeFeed();
$selfuri = common_root_url() .
'api/statuses/home_timeline/' . $atom->setId($id);
$target_id . '.atom'; $atom->setTitle($title);
} else { $atom->setSubtitle($subtitle);
$selfuri = common_root_url() . $atom->setLogo($logo);
'api/statuses/home_timeline.atom'; $atom->setUpdated('now');
$atom->addLink(
common_local_url(
'all',
array('nickname' => $this->user->nickname)
)
);
$id = $this->arg('id');
$aargs = array('format' => 'atom');
if (!empty($id)) {
$aargs['id'] = $id;
} }
$this->showAtomTimeline( $atom->addLink(
$this->notices, $title, $id, $link, $this->getSelfUri('ApiTimelineHome', $aargs),
$subtitle, null, $selfuri, $logo array('rel' => 'self', 'type' => 'application/atom+xml')
); );
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -137,12 +137,36 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo);
break; break;
case 'atom': case 'atom':
$selfuri = common_root_url() .
ltrim($_SERVER['QUERY_STRING'], 'p='); $atom = new AtomNoticeFeed();
$this->showAtomTimeline(
$this->notices, $title, $id, $link, $subtitle, $atom->setId($id);
null, $selfuri, $logo $atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($logo);
$atom->setUpdated('now');
$atom->addLink(
common_local_url(
'replies',
array('nickname' => $this->user->nickname)
)
); );
$id = $this->arg('id');
$aargs = array('format' => 'atom');
if (!empty($id)) {
$aargs['id'] = $id;
}
$atom->addLink(
$this->getSelfUri('ApiTimelineMentions', $aargs),
array('rel' => 'self', 'type' => 'application/atom+xml')
);
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -74,7 +74,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction
parent::prepare($args); parent::prepare($args);
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
if ($this->since) { if ($this->since) {
throw new ServerException("since parameter is disabled for performance; use since_id", 403); throw new ServerException("since parameter is disabled for performance; use since_id", 403);
} }
@ -122,11 +122,28 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $sitelogo); $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $sitelogo);
break; break;
case 'atom': case 'atom':
$selfuri = common_root_url() . 'api/statuses/public_timeline.atom';
$this->showAtomTimeline( $atom = new AtomNoticeFeed();
$this->notices, $title, $id, $link,
$subtitle, null, $selfuri, $sitelogo $atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($sitelogo);
$atom->setUpdated('now');
$atom->addLink(common_local_url('public'));
$atom->addLink(
$this->getSelfUri(
'ApiTimelinePublic', array('format' => 'atom')
),
array('rel' => 'self', 'type' => 'application/atom+xml')
); );
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -99,6 +99,8 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
$strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id); $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
common_debug(var_export($strm, true));
switch ($this->format) { switch ($this->format) {
case 'xml': case 'xml':
$this->showXmlTimeline($strm); $this->showXmlTimeline($strm);
@ -112,10 +114,38 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
$title = sprintf(_("Repeats of %s"), $this->auth_user->nickname); $title = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
$taguribase = common_config('integration', 'taguri'); $taguribase = common_config('integration', 'taguri');
$id = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id; $id = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
$link = common_local_url('showstream',
array('nickname' => $this->auth_user->nickname));
$this->showAtomTimeline($strm, $title, $id, $link); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed();
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setUpdated('now');
$atom->addLink(
common_local_url(
'showstream',
array('nickname' => $this->auth_user->nickname)
)
);
$id = $this->arg('id');
$aargs = array('format' => 'atom');
if (!empty($id)) {
$aargs['id'] = $id;
}
$atom->addLink(
$this->getSelfUri('ApiTimelineRetweetsOfMe', $aargs),
array('rel' => 'self', 'type' => 'application/atom+xml')
);
$atom->addEntryFromNotices($strm);
$this->raw($atom->getString());
break; break;
default: default:

View File

@ -100,10 +100,6 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
$sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'); $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
$title = sprintf(_("Notices tagged with %s"), $this->tag); $title = sprintf(_("Notices tagged with %s"), $this->tag);
$link = common_local_url(
'tag',
array('tag' => $this->tag)
);
$subtitle = sprintf( $subtitle = sprintf(
_('Updates tagged with %1$s on %2$s!'), _('Updates tagged with %1$s on %2$s!'),
$this->tag, $this->tag,
@ -117,22 +113,51 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
$this->showXmlTimeline($this->notices); $this->showXmlTimeline($this->notices);
break; break;
case 'rss': case 'rss':
$this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $sitelogo); $link = common_local_url(
break; 'tag',
case 'atom': array('tag' => $this->tag)
$selfuri = common_root_url() . );
'api/statusnet/tags/timeline/' . $this->showRssTimeline(
$this->tag . '.atom';
$this->showAtomTimeline(
$this->notices, $this->notices,
$title, $title,
$id,
$link, $link,
$subtitle, $subtitle,
null, null,
$selfuri,
$sitelogo $sitelogo
); );
break;
case 'atom':
header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed();
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($logo);
$atom->setUpdated('now');
$atom->addLink(
common_local_url(
'tag',
array('tag' => $this->tag)
)
);
$aargs = array('format' => 'atom');
if (!empty($this->tag)) {
$aargs['tag'] = $this->tag;
}
$atom->addLink(
$this->getSelfUri('ApiTimelineTag', $aargs),
array('rel' => 'self', 'type' => 'application/atom+xml')
);
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
break; break;
case 'json': case 'json':
$this->showJsonTimeline($this->notices); $this->showJsonTimeline($this->notices);

View File

@ -150,6 +150,12 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed();
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($logo);
$atom->setUpdated('now');
$atom->addLink( $atom->addLink(
common_local_url( common_local_url(
'showstream', 'showstream',
@ -157,25 +163,14 @@ class ApiTimelineUserAction extends ApiBareAuthAction
) )
); );
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setLogo($logo);
$atom->setUpdated('now');
$id = $this->arg('id'); $id = $this->arg('id');
$aargs = array('format' => 'atom');
if ($id) { if (!empty($id)) {
$selfuri = common_root_url() . $aargs['id'] = $id;
'api/statuses/user_timeline/' .
rawurlencode($id) . '.atom';
} else {
$selfuri = common_root_url() .
'api/statuses/user_timeline.atom';
} }
$atom->addLink( $atom->addLink(
$selfuri, $this->getSelfUri('ApiTimelineUser', $aargs),
array('rel' => 'self', 'type' => 'application/atom+xml') array('rel' => 'self', 'type' => 'application/atom+xml')
); );

View File

@ -1321,4 +1321,22 @@ class ApiAction extends Action
} }
} }
function getSelfUri($action, $aargs)
{
parse_str($_SERVER['QUERY_STRING'], $params);
$pstring = '';
if (!empty($params)) {
unset($params['p']);
$pstring = http_build_query($params);
}
$uri = common_local_url($action, $aargs);
if (!empty($pstring)) {
$uri .= '?' . $pstring;
}
return $uri;
}
} }

View File

@ -27,7 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') if (!defined('STATUSNET'))
{ {
exit(1); exit(1);
} }
@ -108,7 +108,11 @@ class Atom10Feed extends XMLStringer
$this->element('id', null, $this->id); $this->element('id', null, $this->id);
$this->element('title', null, $this->title); $this->element('title', null, $this->title);
$this->element('subtitle', null, $this->subtitle); $this->element('subtitle', null, $this->subtitle);
$this->element('logo', null, $this->logo);
if (!empty($this->logo)) {
$this->element('logo', null, $this->logo);
}
$this->element('updated', null, $this->updated); $this->element('updated', null, $this->updated);
$this->renderLinks(); $this->renderLinks();

View File

@ -27,7 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') if (!defined('STATUSNET'))
{ {
exit(1); exit(1);
} }
@ -85,7 +85,7 @@ class AtomNoticeFeed extends Atom10Feed
} }
} else { } else {
while ($notices->fetch()) { while ($notices->fetch()) {
$this->addEntryFromNotice($notice); $this->addEntryFromNotice($notices);
} }
} }
} }