]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/atom10feed.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / lib / atom10feed.php
index ccca76a09e2a76cac4e20c08e91c17d01273543c..5e17b20d3ab8816507ea4ebe96fb99786a97e6f3 100644 (file)
@@ -51,6 +51,7 @@ class Atom10Feed extends XMLStringer
     public  $xw;
     private $namespaces;
     private $authors;
+    private $subject;
     private $categories;
     private $contributors;
     private $generator;
@@ -74,9 +75,10 @@ class Atom10Feed extends XMLStringer
     function __construct($indent = true) {
         parent::__construct($indent);
         $this->namespaces = array();
+        $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');
     }
 
     /**
@@ -93,6 +95,64 @@ class Atom10Feed extends XMLStringer
         $this->namespaces = array_merge($this->namespaces, $ns);
     }
 
+    function addAuthor($name, $uri = null, $email = null)
+    {
+        $xs = new XMLStringer(true);
+
+        $xs->elementStart('author');
+
+        if (!empty($name)) {
+            $xs->element('name', null, $name);
+        } else {
+            throw new Atom10FeedException(
+                'author element must contain a name element.'
+            );
+        }
+
+        if (!is_null($uri)) {
+            $xs->element('uri', null, $uri);
+        }
+
+        if (!is_null(email)) {
+            $xs->element('email', null, $email);
+        }
+
+        $xs->elementEnd('author');
+
+        array_push($this->authors, $xs->getString());
+    }
+
+    /**
+     * Add an Author to the feed via raw XML string
+     *
+     * @param string $xmlAuthor An XML string representation author
+     *
+     * @return void
+     */
+    function addAuthorRaw($xmlAuthor)
+    {
+        array_push($this->authors, $xmlAuthor);
+    }
+
+    function renderAuthors()
+    {
+        foreach ($this->authors as $author) {
+            $this->raw($author);
+        }
+    }
+
+    /**
+     * 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;
@@ -102,7 +162,14 @@ class Atom10Feed extends XMLStringer
     {
         $this->xw->startDocument('1.0', 'UTF-8');
         $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('id', null, $this->id);
@@ -115,6 +182,8 @@ class Atom10Feed extends XMLStringer
 
         $this->element('updated', null, $this->updated);
 
+        $this->renderAuthors();
+
         $this->renderLinks();
     }
 
@@ -136,9 +205,9 @@ class Atom10Feed extends XMLStringer
         }
     }
 
-    function addEntryRaw($entry)
+    function addEntryRaw($xmlEntry)
     {
-        array_push($this->entries, $entry);
+        array_push($this->entries, $xmlEntry);
     }
 
     function addEntry($entry)
@@ -161,11 +230,20 @@ class Atom10Feed extends XMLStringer
 
     function getString()
     {
-        $this->validate();
+        if (Event::handle('StartApiAtom', array($this))) {
 
-        $this->initFeed();
-        $this->renderEntries();
-        $this->endFeed();
+            $this->validate();
+            $this->initFeed();
+
+            if (!empty($this->subject)) {
+                $this->raw($this->subject);
+            }
+
+            $this->renderEntries();
+            $this->endFeed();
+
+            Event::handle('EndApiAtom', array($this));
+        }
 
         return $this->xw->outputMemory();
     }