Beispiel #1
0
 function toXML(&$definition, $part = false, $replaceVars = false)
 {
     //return back xml
     $result = "";
     if (!$definition && is_object($this)) {
         $definition = $this->_arrOutput;
     }
     if (!$definition) {
         parent::raiseError("No definition found");
         return '';
     }
     $c = 0;
     while (isset($definition[$c])) {
         //assign node value
         if (isset($definition[$c]["textnode"])) {
             //replacements on text nodes
             if ($replaceVars) {
                 $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_CONTEXT));
                 $result .= $dummyTag->replaceVars((string) $definition[$c]["textnode"]);
             } else {
                 $result .= (string) $definition[$c]["textnode"];
             }
         } elseif (isset($definition[$c]["phpnode"])) {
             //replacements on text nodes
             if ($replaceVars) {
                 $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_TAG_CONTEXT));
                 $result .= '<?php ' . $dummyTag->replaceVars($definition[$c]["phpnode"]) . ' ?>';
             } else {
                 $result .= '<?php ' . $definition[$c]["phpnode"] . ' ?>';
             }
         } else {
             $autoclosed = in_array($definition[$c]["nodename"], CMS_xml2Array::$autoClosedTagsList) || substr($definition[$c]["nodename"], 0, 3) == 'atm' && !isset($definition[$c]["childrens"]);
             if (!$part || $part == self::ARRAY2XML_START_TAG) {
                 $tagOpening = '<' . $definition[$c]["nodename"];
                 if (is_array($definition[$c]["attributes"])) {
                     while (list($key, $value) = each($definition[$c]["attributes"])) {
                         $tagOpening .= ' ' . $key . '="' . $value . '"';
                     }
                 }
                 $tagOpening .= $autoclosed ? ' />' : '>';
                 $tagOpenReplaced = false;
                 if ($replaceVars) {
                     $dummyTag = new CMS_XMLTag('html', array(), array(), array('context' => CMS_XMLTag::HTML_TAG_CONTEXT));
                     $prepared = addcslashes($tagOpening, '"');
                     $replaced = $dummyTag->replaceVars($prepared);
                     if ($replaced != $prepared) {
                         $tagOpening = '<?php echo "' . $replaced . '"; ?>';
                         $tagOpenReplaced = true;
                     }
                 }
                 $result .= $tagOpening;
             }
             if (!$part) {
                 if (isset($definition[$c]["childrens"])) {
                     $result .= $this->toXML($definition[$c]["childrens"], $part);
                 }
             }
             if ((!$part || $part == self::ARRAY2XML_END_TAG) && !$autoclosed) {
                 $tagClose = '</' . $definition[$c]["nodename"] . '>';
                 if (isset($tagOpenReplaced) && $tagOpenReplaced) {
                     $tagClose = '<?php echo "' . $tagClose . '"; ?>';
                 }
                 $result .= $tagClose;
             }
         }
         $c++;
     }
     return $result;
 }