X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=4db73b617de299fc4c976bb955506c8a622ee28d;hp=7db635e0783f85671ee1f40c5c490dd1fb9c4776;hb=efba981c9bf18c733dfde945b09111ff4b6007ce;hpb=ed7ca64368d512574efeda0f6b8d8e970d41aa1d diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 7db635e..4db73b6 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -174,7 +174,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $var The variable we are looking for * @return $content Content of the variable or null if not found */ - private function readVariable ($var) { + protected function readVariable ($var) { // First everything is not found $content = null; @@ -232,7 +232,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @param $groupName Name of variable group * @param $add Wether add this group - * @return void + * @retur4n void */ public function setVariableGroup ($groupName, $add = true) { // Set group name @@ -461,7 +461,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $rawTemplateData The raw data from the template * @return void */ - private final function setRawTemplateData ($rawTemplateData) { + protected final function setRawTemplateData ($rawTemplateData) { // And store it in this class //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($rawTemplateData)." Bytes set.
\n"; //* DEBUG: */ echo $this->currGroup." variables: ".count($this->varStack[$this->currGroup]).", groups=".count($this->varStack)."
\n"; @@ -491,6 +491,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Getter for compiled templates + * + * @return $compiledData Compiled template data */ public final function getCompiledData () { //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->compiledData)." Bytes read.
\n"; @@ -967,18 +969,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { ); // This loop does remove the backslashes (\) in PHP parameters - while (strpos($eval, ""))); @@ -1246,6 +1242,47 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Set the code back $this->setRawTemplateData($rawData); } + + /** + * Renders the given XML content + * + * @param $content Valid XML content or if not set the current loaded raw content + * @return void + * @throws XmlParserException If an XML error was found + */ + public final function renderXmlContent ($content = null) { + // Is the content set? + if (is_null($content)) { + // Get current content + $content = $this->getRawTemplateData(); + } // END - if + + // Convert all to UTF8 + $content = recode("html..utf8", $content); + + // Get an XML parser + $xmlParser = xml_parser_create(); + + // Force case-folding to on + xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, true); + + // Set object + xml_set_object($xmlParser, $this); + + // Set handler call-backs + xml_set_element_handler($xmlParser, 'startElement', 'endElement'); + xml_set_character_data_handler($xmlParser, 'characterHandler'); + + // Now parse the XML tree + if (!xml_parse($xmlParser, $content)) { + // Error found in XML! + //die("
".htmlentities($content)."
"); + throw new XmlParserException(array($this, $xmlParser), BaseHelper::EXCEPTION_XML_PARSER_ERROR); + } // END - if + + // Free the parser + xml_parser_free($xmlParser); + } } // [EOF]