/** * Convert an XML to Array * * @access public static * @param string $node_name - name of the root node to be converted * @param array $arr - aray to be converterd * @return DOMDocument * @since 1.1 */ public static function &createArray($input_xml) { $xml = self::getXMLRoot(); if(is_string($input_xml)) { $parsed = $xml->loadXML($input_xml); if(!$parsed) { throw new Exception('[XML2Array] Error parsing the XML string.'); } } else { if(get_class($input_xml) != 'DOMDocument') { throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.'); } $xml = self::$xml = $input_xml; } $array[$xml->documentElement->tagName] = self::convert($xml->documentElement); self::$xml = null; // clear the xml node in the class for 2nd time use. return $array; }
/** * Write Controller' specifics params into XML before send it * * @access protected * @since 1.0 */ protected function writeParams() { // We check if we aren't passed here with the dispatcher if ($this->_output == "xhtml") { if (strpos($this->_generic->getBufferXML(),"<ControllerParams>") === false) { $controllersParams = new SLS_XMLToolbox(false); $controllersParams->startTag("action"); $controllersParams->startTag("metas"); $controllersParams->addFullTag("title", $this->_pageTitle, true); $controllersParams->addFullTag("description", $this->_metas['description'], true); $controllersParams->addFullTag("keywords", $this->_metas['keywords'], true); $controllersParams->addFullTag("robots", $this->_metas['robots'], true); $controllersParams->addFullTag("author", $this->_metas['author'], true); $controllersParams->addFullTag("copyright", $this->_metas['copyright'], true); $controllersParams->addFullTag("favicon", $this->_metas['favicon'], true); $controllersParams->endTag("metas"); $controllersParams->startTag("links"); $links = $this->_generic->getRegisteredLinks(); for($i=0;$i<count($links);$i++) { $controllersParams->startTag("link"); $controllersParams->addFullTag("name", strtoupper($links[$i]['codeName']), true); $controllersParams->addFullTag("href", $links[$i]['href'], true); $controllersParams->endTag("link"); } $controllersParams->endTag("links"); $controllersParams->endTag("action"); // Save it into the XML's buffer $this->_generic->setBufferXML($controllersParams->getXML(), true, "//root/Statics/Sls/Configs"); } // Set Protocol $xml = new SLS_XMLToolbox($this->_generic->getBufferXML()); $xml->setTag("//root/Statics/Sls/Configs/site/protocol", $this->_generic->getProtocol(), true); $xml->setTag("//root/Statics/Sls/Configs/site/siteprotocol", $this->_generic->getSiteConfig('protocol'), true); $this->_generic->setBufferXML($xml->getXML(), false); } elseif ($this->_output == "json") { $xml = new SLS_XMLToolbox($this->_generic->getBufferXML()); $output = json_encode(SLS_XMLToArray::createArray($xml->getNode("//root/View"))); header('Content-Type: application/json'); header('X-Robots-Tag: noindex,nofollow,noarchive'); print($output); exit; } else if ($this->_output == "rss" || $this->_output == "atom") { if ($this->_output == "rss") header('Content-Type: application/rss+xml'); else header('Content-Type: application/atom+xml'); print($this->_outputOptions); exit; } else { header("Content-type: text/xml"); if (!is_null($this->_outputOptions)) print($this->_outputOptions); else { $xml = new SLS_XMLToolbox($this->_generic->getBufferXML()); $view = $xml->getNode("//root/View"); print('<?xml version="1.0" encoding="UTF-8"?>'.$view); } exit; } }