]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/xmloutputter.php
Added new 'Scroller' plugin from @buttle which aims to replace the out-dated
[quix0rs-gnu-social.git] / lib / xmloutputter.php
index 9ca0c91bd6fec72cbd21da6e78d553b9d6dee741..71d57e2d56647afad12e413dda029a912c6e19bc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Low-level generator for XML
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Output
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @author    Sarven Capadisli <csarven@controlyourself.ca>
- * @copyright 2008 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Sarven Capadisli <csarven@status.net>
+ * @copyright 2008 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')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -40,11 +40,11 @@ if (!defined('LACONICA')) {
  * an element.
  *
  * @category Output
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
- * @author   Sarven Capadisli <csarven@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
  * @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/
  * @see      Action
  * @see      HTMLOutputter
  */
@@ -67,12 +67,14 @@ class XMLOutputter
      * @param boolean $indent Whether to indent output, default true
      */
 
-    function __construct($output='php://output', $indent=true)
+    function __construct($output='php://output', $indent=null)
     {
         $this->xw = new XMLWriter();
         $this->xw->openURI($output);
+        if(is_null($indent)) {
+            $indent = common_config('site', 'indent');
+        }
         $this->xw->setIndent($indent);
-        $this->xw->startDocument('1.0', 'UTF-8');
     }
 
     /**
@@ -87,6 +89,7 @@ class XMLOutputter
 
     function startXML($doc=null, $public=null, $system=null)
     {
+        $this->xw->startDocument('1.0', 'UTF-8');
         if ($doc) {
             $this->xw->writeDTD($doc, $public, $system);
         }
@@ -139,6 +142,15 @@ class XMLOutputter
         $this->elementEnd($tag);
     }
 
+    function elementNS(array $ns, $tag, $attrs=null, $content=null)
+    {
+        $this->elementStartNS($ns, $tag, $attrs);
+        if (!is_null($content)) {
+            $this->xw->text($content);
+        }
+        $this->elementEnd($tag);
+    }
+
     /**
      * output a start tag for an element
      *
@@ -166,6 +178,20 @@ class XMLOutputter
         }
     }
 
+    function elementStartNS(array $ns, $tag, $attrs=null)
+    {
+        reset($ns); // array pointer to 0
+        $uri = key($ns);
+        $this->xw->startElementNS($ns[$uri], $tag, $uri);
+        if (is_array($attrs)) {
+            foreach ($attrs as $name => $value) {
+                $this->xw->writeAttribute($name, $value);
+            }
+        } else if (is_string($attrs)) {
+            $this->xw->writeAttribute('class', $attrs);
+        }
+    }
+
     /**
      * output an end tag for an element
      *
@@ -186,7 +212,7 @@ class XMLOutputter
     {
         static $empty_tag = array('base', 'meta', 'link', 'hr',
                                   'br', 'param', 'img', 'area',
-                                  'input', 'col');
+                                  'input', 'col', 'source');
         // XXX: check namespace
         if (in_array($tag, $empty_tag)) {
             $this->xw->endElement();
@@ -239,4 +265,15 @@ class XMLOutputter
     {
         $this->xw->writeComment($txt);
     }
+
+    /**
+     * Flush output buffers
+     *
+     * @return void
+     */
+
+    function flush()
+    {
+        $this->xw->flush();
+    }
 }