From 023f258b63c2c47b1af74811c39ab274b170e6b0 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 11 Mar 2010 23:05:56 +0000 Subject: - Output georss xmlns in rss element - Only output geopoint in rss if one is set --- lib/apiaction.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index e4a1df3d1..fd09f3d42 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -541,13 +541,12 @@ class ApiAction extends Action function showGeoRSS($geo) { - if (empty($geo)) { - // empty geo element - $this->element('geo'); - } else { - $this->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss')); - $this->element('georss:point', null, $geo['coordinates'][0] . ' ' . $geo['coordinates'][1]); - $this->elementEnd('geo'); + if (!empty($geo)) { + $this->element( + 'georss:point', + null, + $geo['coordinates'][0] . ' ' . $geo['coordinates'][1] + ); } } @@ -1138,7 +1137,14 @@ class ApiAction extends Action function initTwitterRss() { $this->startXML(); - $this->elementStart('rss', array('version' => '2.0', 'xmlns:atom'=>'http://www.w3.org/2005/Atom')); + $this->elementStart( + 'rss', + array( + 'version' => '2.0', + 'xmlns:atom' => 'http://www.w3.org/2005/Atom', + 'xmlns:georss' => 'http://www.georss.org/georss' + ) + ); $this->elementStart('channel'); Event::handle('StartApiRss', array($this)); } -- cgit v1.2.3-54-g00ecf From 7e1a1506f5afd26da8dbe654f5f67f5c11d9d6e9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 11 Mar 2010 23:28:41 +0000 Subject: Output self link in rss2 feeds, if available --- lib/apiaction.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index fd09f3d42..73777f4e8 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -618,13 +618,25 @@ class ApiAction extends Action $this->endDocument('xml'); } - function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null, $logo=null) + function showRssTimeline($notice, $title, $link, $subtitle, $suplink = null, $logo = null, $self = null) { $this->initDocument('rss'); $this->element('title', null, $title); $this->element('link', null, $link); + + if (!is_null($self)) { + $this->element( + 'atom:link', + array( + 'type' => 'application/rss+xml', + 'href' => $self, + 'rel' => 'self' + ) + ); + } + if (!is_null($suplink)) { // For FriendFeed's SUP protocol $this->element('link', array('xmlns' => 'http://www.w3.org/2005/Atom', -- cgit v1.2.3-54-g00ecf From b12c3449309870c7c391ed0e2c7783f7a05a2334 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 11 Mar 2010 23:44:50 +0000 Subject: Generator tag should have 'uri' attr not 'url' --- lib/atom10feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/atom10feed.php b/lib/atom10feed.php index 2d342e785..a46d49f35 100644 --- a/lib/atom10feed.php +++ b/lib/atom10feed.php @@ -178,7 +178,7 @@ class Atom10Feed extends XMLStringer $this->element( 'generator', array( - 'url' => 'http://status.net', + 'uri' => 'http://status.net', 'version' => STATUSNET_VERSION ), 'StatusNet' -- cgit v1.2.3-54-g00ecf From 78f0d6bbd21ed84733e960201c4652e69c565450 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Mar 2010 01:12:30 +0000 Subject: Scrub all atom output with common_xml_safe_str() --- classes/Notice.php | 8 ++++++-- classes/User_group.php | 8 ++++++-- lib/activity.php | 23 +++++++++++++++++------ lib/apiaction.php | 12 ++++++++---- 4 files changed, 37 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/classes/Notice.php b/classes/Notice.php index 40a6263e5..a704053a0 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1151,7 +1151,7 @@ class Notice extends Memcached_DataObject $xs->elementEnd('source'); } - $xs->element('title', null, $this->content); + $xs->element('title', null, common_xml_safe_str($this->content)); if ($author) { $xs->raw($profile->asAtomAuthor()); @@ -1227,7 +1227,11 @@ class Notice extends Memcached_DataObject } } - $xs->element('content', array('type' => 'html'), $this->rendered); + $xs->element( + 'content', + array('type' => 'html'), + common_xml_safe_str($this->rendered) + ); $tag = new Notice_tag(); $tag->notice_id = $this->id; diff --git a/classes/User_group.php b/classes/User_group.php index f29594502..63a407b4c 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -379,7 +379,7 @@ class User_group extends Memcached_DataObject } $xs->element('title', null, $this->nickname); - $xs->element('summary', null, $this->description); + $xs->element('summary', null, common_xml_safe_str($this->description)); $xs->element('link', array('rel' => 'alternate', 'href' => $this->permalink())); @@ -389,7 +389,11 @@ class User_group extends Memcached_DataObject $xs->element('published', null, common_date_w3dtf($this->created)); $xs->element('updated', null, common_date_w3dtf($this->modified)); - $xs->element('content', array('type' => 'html'), $this->description); + $xs->element( + 'content', + array('type' => 'html'), + common_xml_safe_str($this->description) + ); $xs->elementEnd('entry'); diff --git a/lib/activity.php b/lib/activity.php index 2cb80f9e1..125d391b0 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -78,7 +78,7 @@ class PoCoAddress if (!empty($this->formatted)) { $xs = new XMLStringer(true); $xs->elementStart('poco:address'); - $xs->element('poco:formatted', null, $this->formatted); + $xs->element('poco:formatted', null, common_xml_safe_str($this->formatted)); $xs->elementEnd('poco:address'); return $xs->getString(); } @@ -279,7 +279,7 @@ class PoCo ); if (!empty($this->note)) { - $xs->element('poco:note', null, $this->note); + $xs->element('poco:note', null, common_xml_safe_str($this->note)); } if (!empty($this->address)) { @@ -805,7 +805,6 @@ class ActivityObject return $object; } - function asString($tag='activity:object') { $xs = new XMLStringer(true); @@ -817,16 +816,28 @@ class ActivityObject $xs->element(self::ID, null, $this->id); if (!empty($this->title)) { - $xs->element(self::TITLE, null, $this->title); + $xs->element( + self::TITLE, + null, + common_xml_safe_str($this->title) + ); } if (!empty($this->summary)) { - $xs->element(self::SUMMARY, null, $this->summary); + $xs->element( + self::SUMMARY, + null, + common_xml_safe_str($this->summary) + ); } if (!empty($this->content)) { // XXX: assuming HTML content here - $xs->element(ActivityUtils::CONTENT, array('type' => 'html'), $this->content); + $xs->element( + ActivityUtils::CONTENT, + array('type' => 'html'), + common_xml_safe_str($this->content) + ); } if (!empty($this->link)) { diff --git a/lib/apiaction.php b/lib/apiaction.php index 73777f4e8..cef5d1c1e 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -743,8 +743,12 @@ class ApiAction extends Action function showTwitterAtomEntry($entry) { $this->elementStart('entry'); - $this->element('title', null, $entry['title']); - $this->element('content', array('type' => 'html'), $entry['content']); + $this->element('title', null, common_xml_safe_str($entry['title'])); + $this->element( + 'content', + array('type' => 'html'), + common_xml_safe_str($entry['content']) + ); $this->element('id', null, $entry['id']); $this->element('published', null, $entry['published']); $this->element('updated', null, $entry['updated']); @@ -859,7 +863,7 @@ class ApiAction extends Action $this->initDocument('atom'); - $this->element('title', null, $title); + $this->element('title', null, common_xml_safe_str($title)); $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); @@ -869,7 +873,7 @@ class ApiAction extends Action } $this->element('updated', null, common_date_iso8601('now')); - $this->element('subtitle', null, $subtitle); + $this->element('subtitle', null, common_xml_safe_str($subtitle)); if (is_array($group)) { foreach ($group as $g) { -- 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 'lib') 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 From 13556e7ba967c4184009688348082fed1480a5d4 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Mar 2010 04:08:31 +0000 Subject: Add Atom self link to tag timeline --- actions/apitimelinetag.php | 38 ++++++++++++++++---------------------- lib/apiaction.php | 5 +++++ 2 files changed, 21 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/actions/apitimelinetag.php b/actions/apitimelinetag.php index a29061fcc..fed1437ea 100644 --- a/actions/apitimelinetag.php +++ b/actions/apitimelinetag.php @@ -25,7 +25,7 @@ * @author Evan Prodromou * @author Jeffery To * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -67,6 +67,8 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction { parent::prepare($args); + common_debug("apitimelinetag prepare()"); + $this->tag = $this->arg('tag'); $this->notices = $this->getNotices(); @@ -108,22 +110,28 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction $taguribase = TagURI::base(); $id = "tag:$taguribase:TagTimeline:".$tag; + $link = common_local_url( + 'tag', + array('tag' => $this->tag) + ); + + $self = $this->getSelfUri(); + + common_debug("self link is: $self"); + switch($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': - $link = common_local_url( - 'tag', - array('tag' => $this->tag) - ); $this->showRssTimeline( $this->notices, $title, $link, $subtitle, null, - $sitelogo + $sitelogo, + $self ); break; case 'atom': @@ -138,22 +146,8 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction $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->addLink($link); + $atom->setSelfLink($self); $atom->addEntryFromNotices($this->notices); $this->raw($atom->getString()); diff --git a/lib/apiaction.php b/lib/apiaction.php index a01809ed9..b90607862 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -1374,6 +1374,11 @@ class ApiAction extends Action $aargs['id'] = $id; } + $tag = $this->arg('tag'); + if (!empty($tag)) { + $aargs['tag'] = $tag; + } + parse_str($_SERVER['QUERY_STRING'], $params); $pstring = ''; if (!empty($params)) { -- cgit v1.2.3-54-g00ecf From 3dc84dd02d5558b7e2e9de903eac04edcd73aec7 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Mar 2010 05:39:36 +0000 Subject: Output enclosing geo elements and GeoRSS xmlns in XML timelines --- lib/apiaction.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/apiaction.php b/lib/apiaction.php index b90607862..e6aaf9316 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -491,7 +491,7 @@ class ApiAction extends Action $this->showXmlAttachments($twitter_status['attachments']); break; case 'geo': - $this->showGeoRSS($value); + $this->showGeoXML($value); break; case 'retweeted_status': $this->showTwitterXmlStatus($value, 'retweeted_status'); @@ -539,6 +539,18 @@ class ApiAction extends Action } } + function showGeoXML($geo) + { + if (empty($geo)) { + // empty geo element + $this->element('geo'); + } else { + $this->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss')); + $this->element('georss:point', null, $geo['coordinates'][0] . ' ' . $geo['coordinates'][1]); + $this->elementEnd('geo'); + } + } + function showGeoRSS($geo) { if (!empty($geo)) { -- cgit v1.2.3-54-g00ecf