X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fxmloutputter.php;h=463f91be305a8d542b24e42d188589170f585cfd;hb=4ea396f8718648ef6b900ea2aa8a7cad9f14d721;hp=64935da4081b6b5e63d21efaefdfe888c7cdd93d;hpb=4b9df58c90e25ea79aeec64c6e96f828fe06d7df;p=quix0rs-gnu-social.git diff --git a/lib/xmloutputter.php b/lib/xmloutputter.php index 64935da408..463f91be30 100644 --- a/lib/xmloutputter.php +++ b/lib/xmloutputter.php @@ -1,6 +1,6 @@ . * * @category Output - * @package Laconica - * @author Evan Prodromou - * @author Sarven Capadisli - * @copyright 2008 Control Yourself, Inc. + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @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 - * @author Sarven Capadisli + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli * @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 */ @@ -63,14 +63,20 @@ class XMLOutputter * * Initializes the wrapped XMLWriter. * - * @param string $output URL for outputting, defaults to stdout + * @param string $output URL for outputting, if null it defaults to stdout ('php://output') * @param boolean $indent Whether to indent output, default true */ - function __construct($output='php://output', $indent=true) + function __construct($output=null, $indent=null) { + if (is_null($output)) { + $output = 'php://output'; + } $this->xw = new XMLWriter(); $this->xw->openURI($output); + if(is_null($indent)) { + $indent = common_config('site', 'indent'); + } $this->xw->setIndent($indent); } @@ -139,6 +145,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 +181,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 +215,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 +268,15 @@ class XMLOutputter { $this->xw->writeComment($txt); } + + /** + * Flush output buffers + * + * @return void + */ + + function flush() + { + $this->xw->flush(); + } }