]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Notice attachments are enclosures in feeds (Atom, RSS 1.0/RDF, and RSS 2.0).
authorCraig Andrews <candrews@integralblue.com>
Thu, 9 Jul 2009 17:18:57 +0000 (13:18 -0400)
committerCraig Andrews <candrews@integralblue.com>
Thu, 9 Jul 2009 17:18:57 +0000 (13:18 -0400)
http://laconi.ca/trac/ticket/1690

classes/Notice.php
lib/rssaction.php
lib/twitterapi.php

index 5ec0692d90e5e3eadffc2da8a529be7263b6347f..e975cab93ce6b44e8bef11375c866ec1d3304382 100644 (file)
@@ -1164,6 +1164,18 @@ class Notice extends Memcached_DataObject
         }
         $tag->free();
 
+        # Enclosures
+        $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;
+                }
+                $xs->element('link', $attributes, null);
+            }
+        }
+
         $xs->elementEnd('entry');
 
         return $xs->getString();
index 0c8188e88021a8aca153d0eefb09ecf2b5805861..fe3fd6f4a289871a601d286814690b2f16ba2844 100644 (file)
@@ -216,6 +216,13 @@ class Rss10Action extends Action
             $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
             $this->element('sioc:reply_of', array('rdf:resource' => $replyurl));
         }
+        $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);
+            }
+        }
+
         $this->elementEnd('item');
         $this->creators[$creator_uri] = $profile;
     }
@@ -251,6 +258,8 @@ 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' =>
index 40e5b5067796e45e1d914a3d2bca335ddd16524a..8f902cbcaf87066ab58cc5d1cd2e693d19145db0 100644 (file)
@@ -207,7 +207,6 @@ class TwitterapiAction extends Action
 
     function twitter_rss_entry_array($notice)
     {
-
         $profile = $notice->getProfile();
         $entry = array();
 
@@ -224,6 +223,19 @@ class TwitterapiAction extends Action
         $entry['updated'] = $entry['published'];
         $entry['author'] = $profile->getBestName();
 
+        # Enclosure
+        $attachments = $notice->attachments();
+        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;
+            }
+        }
+
         # RSS Item specific
         $entry['description'] = $entry['content'];
         $entry['pubDate'] = common_date_rfc2822($notice->created);
@@ -378,6 +390,13 @@ class TwitterapiAction extends Action
         $this->element('pubDate', null, $entry['pubDate']);
         $this->element('guid', null, $entry['guid']);
         $this->element('link', null, $entry['link']);
+
+        # RSS only supports 1 enclosure per item
+        if($entry['enclosures']){
+            $enclosure = $entry['enclosures'][0];
+            $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null);
+        }
+        
         $this->elementEnd('item');
     }