]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/rssaction.php
let avatars be served over SSL
[quix0rs-gnu-social.git] / lib / rssaction.php
index 0aca965664ded103b19de87ed7b0f661ebacad5c..62e3f21b61dc1f074547666cb3edbba681b1990d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Base class for RSS 1.0 feed actions
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Mail
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
  * @author    Earle Martin <earle@downlode.org>
- * @copyright 2008-9 Control Yourself, Inc.
+ * @copyright 2008-9 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 define('DEFAULT_RSS_LIMIT', 48);
 
@@ -52,7 +52,7 @@ class Rss10Action extends Action
      * @see Action::__construct
      */
 
-    function __construct($output='php://output', $indent=true)
+    function __construct($output='php://output', $indent=null)
     {
         parent::__construct($output, $indent);
     }
@@ -78,31 +78,18 @@ class Rss10Action extends Action
     function prepare($args)
     {
         parent::prepare($args);
+
         $this->limit = (int) $this->trimmed('limit');
+
         if ($this->limit == 0) {
             $this->limit = DEFAULT_RSS_LIMIT;
         }
-        return true;
-    }
-
-    /**
-     * Handle a request
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return void
-     */
-
-    function handle($args)
-    {
-        // Parent handling, including cache check
-        parent::handle($args);
 
         if (common_config('site', 'private')) {
             if (!isset($_SERVER['PHP_AUTH_USER'])) {
 
                 # This header makes basic auth go
-                header('WWW-Authenticate: Basic realm="Laconica RSS"');
+                header('WWW-Authenticate: Basic realm="StatusNet RSS"');
 
                 # If the user hits cancel -- bam!
                 $this->show_basic_auth_error();
@@ -122,8 +109,21 @@ class Rss10Action extends Action
             }
         }
 
-        // Get the list of notices
-        $this->notices = $this->getNotices($this->limit);
+        return true;
+    }
+
+    /**
+     * Handle a request
+     *
+     * @param array $args Arguments from $_REQUEST
+     *
+     * @return void
+     */
+
+    function handle($args)
+    {
+        // Parent handling, including cache check
+        parent::handle($args);
         $this->showRss();
     }
 
@@ -140,7 +140,7 @@ class Rss10Action extends Action
     }
 
     /**
-     * Get the notices to output in this stream
+     * Get the notices to output in this stream.
      *
      * @return array an array of Notice objects sorted in reverse chron
      */
@@ -176,8 +176,10 @@ class Rss10Action extends Action
         $this->showChannel();
         $this->showImage();
 
-        foreach ($this->notices as $n) {
-            $this->showItem($n);
+        if (count($this->notices)) {
+            foreach ($this->notices as $n) {
+                $this->showItem($n);
+            }
         }
 
         $this->showCreators();
@@ -203,8 +205,10 @@ class Rss10Action extends Action
         $this->elementStart('items');
         $this->elementStart('rdf:Seq');
 
-        foreach ($this->notices as $notice) {
-            $this->element('rdf:li', array('rdf:resource' => $notice->uri));
+        if (count($this->notices)) {
+            foreach ($this->notices as $notice) {
+                $this->element('rdf:li', array('rdf:resource' => $notice->uri));
+            }
         }
 
         $this->elementEnd('rdf:Seq');
@@ -244,7 +248,17 @@ class Rss10Action extends Action
         $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
         $this->element('foaf:maker', array('rdf:resource' => $creator_uri));
         $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
-        $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
+        $location = $notice->getLocation();
+        if ($location && isset($location->lat) && isset($location->lon)) {
+            $location_uri = $location->getRdfURL();
+            $attrs = array('geo:lat' => $location->lat,
+                'geo:long' => $location->lon);
+            if (strlen($location_uri)) {
+                $attrs['rdf:resource'] = $location_uri;
+            }
+            $this->element('statusnet:origin', $attrs);
+        }
+        $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
         $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
         if ($notice->reply_to) {
             $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
@@ -258,28 +272,22 @@ class Rss10Action extends Action
         $attachments = $notice->attachments();
         if($attachments){
             foreach($attachments as $attachment){
-                if ($attachment->isEnclosure()) {
-                    // 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;
+                $enclosure=$attachment->getEnclosure();
+                if ($enclosure) {
+                    $attribs = array('rdf:resource' => $enclosure->url);
+                    if ($enclosure->title) {
+                        $attribs['dc:title'] = $enclosure->title;
                     }
-                    if ($attachment->modified) {
-                        $attribs['dc:date'] = common_date_w3dtf($attachment->modified);
+                    if ($enclosure->modified) {
+                        $attribs['dc:date'] = common_date_w3dtf($enclosure->modified);
                     }
-                    if ($attachment->size) {
-                        $attribs['length'] = $attachment->size;
+                    if ($enclosure->size) {
+                        $attribs['enc:length'] = $enclosure->size;
                     }
-                    if ($attachment->mimetype) {
-                        $attribs['type'] = $attachment->mimetype;
+                    if ($enclosure->mimetype) {
+                        $attribs['enc:type'] = $enclosure->mimetype;
                     }
-                    $this->element('enclosure', $attribs);
+                    $this->element('enc:enclosure', $attribs);
                 }
                 $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
             }
@@ -347,14 +355,18 @@ class Rss10Action extends Action
                                               'http://commontag.org/ns#',
                                               'xmlns:foaf' =>
                                               'http://xmlns.com/foaf/0.1/',
+                                              'xmlns:enc' =>
+                                              'http://purl.oclc.org/net/rss_2.0/enc#',
                                               'xmlns:sioc' =>
                                               'http://rdfs.org/sioc/ns#',
                                               'xmlns:sioct' =>
                                               'http://rdfs.org/sioc/types#',
                                               'xmlns:rdfs' =>
                                               'http://www.w3.org/2000/01/rdf-schema#',
-                                              'xmlns:laconica' =>
-                                              'http://laconi.ca/ont/',
+                                              'xmlns:geo' =>
+                                              'http://www.w3.org/2003/01/geo/wgs84_pos#',
+                                              'xmlns:statusnet' =>
+                                              'http://status.net/ont/',
                                               'xmlns' => 'http://purl.org/rss/1.0/'));
         $this->elementStart('sioc:Site', array('rdf:about' => common_root_url()));
         $this->element('sioc:name', null, common_config('site', 'name'));