]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/atomnoticefeed.php
Naming stuff GNUsocial rather than StatusNet
[quix0rs-gnu-social.git] / lib / atomnoticefeed.php
index a626ab549bd2621cb4711e09d8fcf4b1fd4b048e..b8821729185fa2eb800331b4b26c9d948d5e9c80 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * StatusNet, the distributed open-source microblogging tool
  *
- * Class for building and Atom feed from a collection of notices
+ * Class for building an Atom feed from a collection of notices
  *
  * PHP version 5
  *
@@ -27,7 +27,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')
+if (!defined('STATUSNET'))
 {
     exit(1);
 }
@@ -44,31 +44,59 @@ if (!defined('STATUSNET')
  */
 class AtomNoticeFeed extends Atom10Feed
 {
-    function __construct($indent = true) {
+    var $cur;
+
+    /**
+     * Constructor - adds a bunch of XML namespaces we need in our
+     * notice-specific Atom feeds, and allows setting the current
+     * authenticated user (useful for API methods).
+     *
+     * @param User    $cur     the current authenticated user (optional)
+     * @param boolean $indent  Whether to indent XML output
+     *
+     */
+    function __construct($cur = null, $indent = true) {
         parent::__construct($indent);
 
+        $this->cur = $cur;
+
         // Feeds containing notice info use these namespaces
 
         $this->addNamespace(
-            'xmlns:thr',
+            'thr',
             'http://purl.org/syndication/thread/1.0'
         );
 
         $this->addNamespace(
-            'xmlns:georss',
+            'georss',
             'http://www.georss.org/georss'
         );
 
         $this->addNamespace(
-            'xmlns:activity',
+            'activity',
             'http://activitystrea.ms/spec/1.0/'
         );
 
+        $this->addNamespace(
+            'media',
+            'http://purl.org/syndication/atommedia'
+        );
+
+        $this->addNamespace(
+            'poco',
+            'http://portablecontacts.net/spec/1.0'
+        );
+
         // XXX: What should the uri be?
         $this->addNamespace(
-            'xmlns:ostatus',
+            'ostatus',
             'http://ostatus.org/schema/1.0'
         );
+
+        $this->addNamespace(
+            'statusnet',
+            'http://status.net/schema/api/1/'
+        );
     }
 
     /**
@@ -85,7 +113,7 @@ class AtomNoticeFeed extends Atom10Feed
             }
         } else {
             while ($notices->fetch()) {
-                $this->addEntryFromNotice($notice);
+                $this->addEntryFromNotice($notices);
             }
         }
     }
@@ -97,7 +125,26 @@ class AtomNoticeFeed extends Atom10Feed
      */
     function addEntryFromNotice($notice)
     {
-        $this->addEntryRaw($notice->asAtomEntry());
+        try {
+            $source = $this->showSource();
+            $author = $this->showAuthor();
+
+            $cur = empty($this->cur) ? common_current_user() : $this->cur;
+
+            $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur));
+        } catch (Exception $e) {
+            common_log(LOG_ERR, $e->getMessage());
+            // we continue on exceptions
+        }
+    }
+
+    function showSource()
+    {
+        return true;
     }
 
+    function showAuthor()
+    {
+        return true;
+    }
 }