From 212b20e876fac3b989cd79b1b896b88f50995a37 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 11 Mar 2010 23:43:03 +0000 Subject: Add self link to user and group rss2 feeds --- actions/apitimelineuser.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'actions/apitimelineuser.php') diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index 2d0047c04..5c4bcace4 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -116,13 +116,19 @@ class ApiTimelineUserAction extends ApiBareAuthAction // We'll use the shared params from the Atom stub // for other feed types. $atom = new AtomUserNoticeFeed($this->user); - $title = $atom->title; - $link = common_local_url( + + $link = common_local_url( 'showstream', array('nickname' => $this->user->nickname) ); - $subtitle = $atom->subtitle; - $logo = $atom->logo; + + // Calculate self link + $id = $this->arg('id'); + $aargs = array('format' => $this->format); + if (!empty($id)) { + $aargs['id'] = $id; + } + $self = $this->getSelfUri('ApiTimelineUser', $aargs); // FriendFeed's SUP protocol // Also added RSS and Atom feeds @@ -136,25 +142,22 @@ class ApiTimelineUserAction extends ApiBareAuthAction break; case 'rss': $this->showRssTimeline( - $this->notices, $title, $link, - $subtitle, $suplink, $logo + $this->notices, + $atom->title, + $link, + $atom->subtitle, + $suplink, + $atom->logo, + $self ); break; case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); - $id = $this->arg('id'); - $aargs = array('format' => 'atom'); - if (!empty($id)) { - $aargs['id'] = $id; - } - $self = $this->getSelfUri('ApiTimelineUser', $aargs); $atom->setId($self); $atom->setSelfLink($self); - $atom->addEntryFromNotices($this->notices); - $this->raw($atom->getString()); break; -- cgit v1.2.3-54-g00ecf From e1537d83871811cf3446a592e44f56d26e961afe Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Mar 2010 01:40:52 +0000 Subject: More generalized method for calculating Atom rel="self" links --- actions/apitimelinegroup.php | 8 +------- actions/apitimelineuser.php | 8 +------- lib/apiaction.php | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 15 deletions(-) (limited to 'actions/apitimelineuser.php') diff --git a/actions/apitimelinegroup.php b/actions/apitimelinegroup.php index c4f8cbc65..da816c40a 100644 --- a/actions/apitimelinegroup.php +++ b/actions/apitimelinegroup.php @@ -107,13 +107,7 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction // We'll pull common formatting out of this for other formats $atom = new AtomGroupNoticeFeed($this->group); - // Calculate self link - $id = $this->arg('id'); - $aargs = array('format' => $this->format); - if (!empty($id)) { - $aargs['id'] = $id; - } - $self = $this->getSelfUri('ApiTimelineGroup', $aargs); + $self = $this->getSelfUri(); switch($this->format) { case 'xml': diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index 5c4bcace4..11431a82c 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -122,13 +122,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction array('nickname' => $this->user->nickname) ); - // Calculate self link - $id = $this->arg('id'); - $aargs = array('format' => $this->format); - if (!empty($id)) { - $aargs['id'] = $id; - } - $self = $this->getSelfUri('ApiTimelineUser', $aargs); + $self = $this->getSelfUri(); // FriendFeed's SUP protocol // Also added RSS and Atom feeds diff --git a/lib/apiaction.php b/lib/apiaction.php index cef5d1c1e..a01809ed9 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -1358,8 +1358,22 @@ class ApiAction extends Action } } - function getSelfUri($action, $aargs) + /** + * Calculate the complete URI that called up this action. Used for + * Atom rel="self" links. Warning: this is funky. + * + * @return string URL a URL suitable for rel="self" Atom links + */ + function getSelfUri() { + $action = mb_substr(get_class($this), 0, -6); // remove 'Action' + + $id = $this->arg('id'); + $aargs = array('format' => $this->format); + if (!empty($id)) { + $aargs['id'] = $id; + } + parse_str($_SERVER['QUERY_STRING'], $params); $pstring = ''; if (!empty($params)) { -- cgit v1.2.3-54-g00ecf