]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/atom10feed.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / atom10feed.php
index 806a9684b702f8ec4cd40fd4592d5ad3bcfef257..2bba6d0a91474bf5ac7271c3cc35aa83b2574e2c 100644 (file)
@@ -49,6 +49,8 @@ class Atom10FeedException extends Exception
 class Atom10Feed extends XMLStringer
 {
     public  $xw;
+
+    // @fixme most of these should probably be read-only properties
     private $namespaces;
     private $authors;
     private $subject;
@@ -57,10 +59,12 @@ class Atom10Feed extends XMLStringer
     private $generator;
     private $icon;
     private $links;
-    private $logo;
+    private $selfLink;
+    private $selfLinkType;
+    public $logo;
     private $rights;
-    private $subtitle;
-    private $title;
+    public $subtitle;
+    public $title;
     private $published;
     private $updated;
     private $entries;
@@ -78,7 +82,7 @@ class Atom10Feed extends XMLStringer
         $this->authors    = array();
         $this->links      = array();
         $this->entries    = array();
-        $this->addNamespace('xmlns', 'http://www.w3.org/2005/Atom');
+        $this->addNamespace('', 'http://www.w3.org/2005/Atom');
     }
 
     /**
@@ -105,15 +109,16 @@ class Atom10Feed extends XMLStringer
             $xs->element('name', null, $name);
         } else {
             throw new Atom10FeedException(
-                'author element must contain a name element.'
+                // TRANS: Atom feed exception thrown when an author element does not contain a name element.
+                _('Author element must contain a name element.')
             );
         }
 
-        if (!is_null($uri)) {
+        if (isset($uri)) {
             $xs->element('uri', null, $uri);
         }
 
-        if (!is_null(email)) {
+        if (isset($email)) {
             $xs->element('email', null, $email);
         }
 
@@ -141,18 +146,6 @@ class Atom10Feed extends XMLStringer
         }
     }
 
-    /**
-     * Add a activity feed subject via raw XML string
-     *
-     * @param string $xmlSubject An XML string representation of the subject
-     *
-     * @return void
-     */
-    function setActivitySubject($xmlSubject)
-    {
-        $this->subject = $xmlSubject;
-    }
-
     function getNamespaces()
     {
         return $this->namespaces;
@@ -160,11 +153,26 @@ class Atom10Feed extends XMLStringer
 
     function initFeed()
     {
-        $this->xw->startDocument('1.0', 'UTF-8');
+        $this->startXML();
         $commonAttrs = array('xml:lang' => 'en-US');
-        $commonAttrs = array_merge($commonAttrs, $this->namespaces);
+        foreach ($this->namespaces as $prefix => $uri) {
+            if ($prefix == '') {
+                $attr = 'xmlns';
+            } else {
+                $attr = 'xmlns:' . $prefix;
+            }
+            $commonAttrs[$attr] = $uri;
+        }
         $this->elementStart('feed', $commonAttrs);
 
+        $this->element(
+            'generator', array(
+                'uri'     => 'https://gnu.io/social',
+                'version' => GNUSOCIAL_VERSION
+            ),
+            'GNU social'
+        );
+
         $this->element('id', null, $this->id);
         $this->element('title', null, $this->title);
         $this->element('subtitle', null, $this->subtitle);
@@ -175,6 +183,12 @@ class Atom10Feed extends XMLStringer
 
         $this->element('updated', null, $this->updated);
 
+        $this->renderAuthors();
+
+        if ($this->selfLink) {
+            $this->addLink($this->selfLink, array('rel' => 'self',
+                                                  'type' => $this->selfLinkType));
+        }
         $this->renderLinks();
     }
 
@@ -221,17 +235,20 @@ class Atom10Feed extends XMLStringer
 
     function getString()
     {
-        $this->validate();
+        if (Event::handle('StartApiAtom', array($this))) {
 
-        $this->initFeed();
-        $this->renderAuthors();
+            $this->validate();
+            $this->initFeed();
 
-        if (!empty($this->subject)) {
-            $this->raw($this->subject);
-        }
+            if (!empty($this->subject)) {
+                $this->raw($this->subject);
+            }
 
-        $this->renderEntries();
-        $this->endFeed();
+            $this->renderEntries();
+            $this->endFeed();
+
+            Event::handle('EndApiAtom', array($this));
+        }
 
         return $this->xw->outputMemory();
     }
@@ -241,6 +258,12 @@ class Atom10Feed extends XMLStringer
         $this->id = $id;
     }
 
+    function setSelfLink($url, $type='application/atom+xml')
+    {
+        $this->selfLink = $url;
+        $this->selfLinkType = $type;
+    }
+
     function setTitle($title)
     {
         $this->title = $title;
@@ -289,5 +312,4 @@ class Atom10Feed extends XMLStringer
 
         array_push($this->links, $attrs);
     }
-
 }