From a68773df63aa925d860d555d621d5180798f83db Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Mon, 13 Jul 2009 15:16:10 +0100 Subject: Improve output for files/attachments. --- lib/rssaction.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'lib/rssaction.php') diff --git a/lib/rssaction.php b/lib/rssaction.php index fe3fd6f4a..abc83fe3a 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -219,7 +219,30 @@ class Rss10Action extends Action $attachments = $notice->attachments(); if($attachments){ foreach($attachments as $attachment){ - $this->element('enc:enclosure', array('rdf:resource'=>$attachment->url,'enc:type'=>$attachment->mimetype,'enc:length'=>$attachment->size), null); + if (isset($attachment->filename)) { + // DO NOT move xmlns declaration to root element. Making it + // the default namespace here improves compatibility with + // real-world feed readers. + $attribs = array( + 'rdf:resource' => $attachment->url, + 'url' => $attachment->url, + 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#' + ); + if ($attachment->title) { + $attribs['dc:title'] = $attachment->title; + } + if ($attachment->modified) { + $attribs['dc:date'] = common_date_w3dtf($attachment->modified); + } + if ($attachment->size) { + $attribs['length'] = $attachment->size; + } + if ($attachment->mimetype) { + $attribs['type'] = $attachment->mimetype; + } + $this->element('enclosure', $attribs); + } + $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url)); } } @@ -258,8 +281,6 @@ class Rss10Action extends Action 'http://creativecommons.org/ns#', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', - 'xmlns:enc' => - 'http://purl.oclc.org/net/rss_2.0/enc#', 'xmlns:foaf' => 'http://xmlns.com/foaf/0.1/', 'xmlns:sioc' => -- cgit v1.2.3-54-g00ecf From ae2bc6a8500f2878ed376f60c81c3c53c8ab5b87 Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Mon, 13 Jul 2009 15:37:15 +0100 Subject: Add notice tags to RSS 1.0 output. --- lib/rssaction.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'lib/rssaction.php') diff --git a/lib/rssaction.php b/lib/rssaction.php index abc83fe3a..183c09f47 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -192,6 +192,24 @@ class Rss10Action extends Action } } + // XXX: Surely there should be a common function to do this? + function extract_tags ($string) + { + $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($string), $match); + if (!count) + { + return array(); + } + + $rv = array(); + foreach ($match[1] as $tag) + { + $rv[] = common_canonical_tag($tag); + } + + return array_unique($rv); + } + function showItem($notice) { $profile = Profile::staticGet($notice->profile_id); @@ -245,7 +263,20 @@ class Rss10Action extends Action $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url)); } } - + $tags = $this->extract_tags($notice->content); + if (!empty($tags)) { + foreach ($tags as $tag) + { + $tagpage = common_local_url('tag', array('tag' => $tag)); + $tagrss = common_local_url('tagrss', array('tag' => $tag)); + $this->elementStart('ctag:tagged'); + $this->elementStart('ctag:Tag', array('rdf:about'=>$tagpage.'#concept', 'ctag:label'=>$tag)); + $this->element('foaf:page', array('rdf:resource'=>$tagpage)); + $this->element('rdfs:seeAlso', array('rdf:resource'=>$tagrss)); + $this->elementEnd('ctag:Tag'); + $this->elementEnd('ctag:tagged'); + } + } $this->elementEnd('item'); $this->creators[$creator_uri] = $profile; } @@ -281,6 +312,8 @@ class Rss10Action extends Action 'http://creativecommons.org/ns#', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', + 'xmlns:ctag' => + 'http://commontag.org/ns#', 'xmlns:foaf' => 'http://xmlns.com/foaf/0.1/', 'xmlns:sioc' => -- cgit v1.2.3-54-g00ecf From 593af9feb6cdbb88e250501938722e656fe4a17a Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 14 Jul 2009 13:33:40 -0400 Subject: Moved the decision logic as to whether an attachment should be an enclosure to the File class --- classes/File.php | 13 +++++++++++++ classes/Notice.php | 2 +- lib/rssaction.php | 2 +- lib/twitterapi.php | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/rssaction.php') diff --git a/classes/File.php b/classes/File.php index 533cc6e71..289c6e441 100644 --- a/classes/File.php +++ b/classes/File.php @@ -193,5 +193,18 @@ class File extends Memcached_DataObject return 'http://'.$server.$path.$filename; } + + function isEnclosure(){ + if(isset($this->filename)){ + return true; + } + $notEnclosureMimeTypes = array('text/html'); + $mimetype = strtolower($this->mimetype); + $semicolon = strpos($mimetype,';'); + if($semicolon){ + $mimetype = substr($mimetype,0,$semicolon); + } + return(! in_array($mimetype,$notEnclosureMimeTypes)); + } } diff --git a/classes/Notice.php b/classes/Notice.php index fc28f3558..08125cf7b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1170,7 +1170,7 @@ class Notice extends Memcached_DataObject $attachments = $this->attachments(); if($attachments){ foreach($attachments as $attachment){ - if (isset($attachment->filename)) { + if ($attachment->isEnclosure()) { $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size); if($attachment->title){ $attributes['title']=$attachment->title; diff --git a/lib/rssaction.php b/lib/rssaction.php index 183c09f47..ffa1f9e99 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -237,7 +237,7 @@ class Rss10Action extends Action $attachments = $notice->attachments(); if($attachments){ foreach($attachments as $attachment){ - if (isset($attachment->filename)) { + if ($attachment->isEnclosure()) { // DO NOT move xmlns declaration to root element. Making it // the default namespace here improves compatibility with // real-world feed readers. diff --git a/lib/twitterapi.php b/lib/twitterapi.php index ce188e00d..655b6c777 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -218,7 +218,7 @@ class TwitterapiAction extends Action if($attachments){ $entry['enclosures']=array(); foreach($attachments as $attachment){ - if (isset($attachment->filename)) { + if ($attachment->isEnclosure()) { $enclosure=array(); $enclosure['url']=$attachment->url; $enclosure['mimetype']=$attachment->mimetype; -- cgit v1.2.3-54-g00ecf