From 8c8edea32ac7b2fe56530bb13e4b58c029da5ee0 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 10 Jun 2009 13:16:11 +0000 Subject: [PATCH 1/4] Laconica defaults to a locale 'en' which uses language 'en'. Unfortunately, this language doesn't exist -- properly it's en_US. This causes a lot of spammy messages in syslog. This fix simply changes 'en' to have the same properties as 'en-us', i.e. a language of en_US and a description of 'English (US)'. --- lib/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.php b/lib/language.php index cd6498d30b..3ea3dd2aa0 100644 --- a/lib/language.php +++ b/lib/language.php @@ -108,7 +108,7 @@ function get_all_languages() { 'el' => array('q' => 0.1, 'lang' => 'el', 'name' => 'Greek', 'direction' => 'ltr'), 'en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'), 'en-gb' => array('q' => 1, 'lang' => 'en_GB', 'name' => 'English (British)', 'direction' => 'ltr'), - 'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English', 'direction' => 'ltr'), + 'en' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'), 'es' => array('q' => 1, 'lang' => 'es', 'name' => 'Spanish', 'direction' => 'ltr'), 'fi' => array('q' => 1, 'lang' => 'fi', 'name' => 'Finnish', 'direction' => 'ltr'), 'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'), From a68773df63aa925d860d555d621d5180798f83db Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Mon, 13 Jul 2009 15:16:10 +0100 Subject: [PATCH 2/4] Improve output for files/attachments. --- lib/rssaction.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/rssaction.php b/lib/rssaction.php index fe3fd6f4a2..abc83fe3a5 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' => From ae2bc6a8500f2878ed376f60c81c3c53c8ab5b87 Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Mon, 13 Jul 2009 15:37:15 +0100 Subject: [PATCH 3/4] Add notice tags to RSS 1.0 output. --- lib/rssaction.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/rssaction.php b/lib/rssaction.php index abc83fe3a5..183c09f473 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' => From 38784141d108a96cc173167e16a1c79d9098722a Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Mon, 13 Jul 2009 16:56:52 +0100 Subject: [PATCH 4/4] Copy isset($attachment->filename) fix from RSS 1.0 to RSS 2.0 and Atom 1.0 feeds. --- classes/Notice.php | 10 ++++++---- lib/twitterapi.php | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 75044cf638..fc28f35588 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1170,11 +1170,13 @@ class Notice extends Memcached_DataObject $attachments = $this->attachments(); if($attachments){ foreach($attachments as $attachment){ - $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size); - if($attachment->title){ - $attributes['title']=$attachment->title; + if (isset($attachment->filename)) { + $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size); + if($attachment->title){ + $attributes['title']=$attachment->title; + } + $xs->element('link', $attributes, null); } - $xs->element('link', $attributes, null); } } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 4f3a5c0b6f..ce188e00d8 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -218,11 +218,13 @@ class TwitterapiAction extends Action if($attachments){ $entry['enclosures']=array(); foreach($attachments as $attachment){ - $enclosure=array(); - $enclosure['url']=$attachment->url; - $enclosure['mimetype']=$attachment->mimetype; - $enclosure['size']=$attachment->size; - $entry['enclosures'][]=$enclosure; + if (isset($attachment->filename)) { + $enclosure=array(); + $enclosure['url']=$attachment->url; + $enclosure['mimetype']=$attachment->mimetype; + $enclosure['size']=$attachment->size; + $entry['enclosures'][]=$enclosure; + } } }