]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/template/class_BaseTemplateEngine.php
Debug mailer finished and debug messages removed:
[shipsimu.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 7db635e0783f85671ee1f40c5c490dd1fb9c4776..4db73b617de299fc4c976bb955506c8a622ee28d 100644 (file)
@@ -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
         */
         * @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;
 
                // 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
         *
         * @param       $groupName      Name of variable group
         * @param       $add            Wether add this group
-        * @retur     void
+        * @retur4n     void
         */
        public function setVariableGroup ($groupName, $add = true) {
                // Set group name
         */
        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
         */
         * @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.<br />\n";
                //* DEBUG: */ echo $this->currGroup." variables: ".count($this->varStack[$this->currGroup]).", groups=".count($this->varStack)."<br />\n";
                // And store it in this class
                //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($rawTemplateData)." Bytes set.<br />\n";
                //* DEBUG: */ echo $this->currGroup." variables: ".count($this->varStack[$this->currGroup]).", groups=".count($this->varStack)."<br />\n";
@@ -491,6 +491,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
        /**
         * Getter for compiled templates
 
        /**
         * Getter for compiled templates
+        *
+        * @return      $compiledData   Compiled template data
         */
        public final function getCompiledData () {
                //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->compiledData)." Bytes read.<br />\n";
         */
        public final function getCompiledData () {
                //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->compiledData)." Bytes read.<br />\n";
@@ -967,18 +969,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        );
 
                        // This loop does remove the backslashes (\) in PHP parameters
                        );
 
                        // This loop does remove the backslashes (\) in PHP parameters
-                       while (strpos($eval, "<?") !== false) {
+                       while (strpos($eval, "<?php") !== false) {
                                // Get left part before "<?"
                                // Get left part before "<?"
-                               $evalLeft = substr($eval, 0, strpos($eval, "<?"));
+                               $evalLeft = substr($eval, 0, strpos($eval, "<?php"));
 
                                // Get all from right of "<?"
 
                                // Get all from right of "<?"
-                               $evalRight = substr($eval, (strpos($eval, "<?") + 2));
-
-                               // Is this a full PHP tag?
-                               if (substr(strtolower($evalRight), 0, 3) == "php") {
-                                       // Remove "php" string from full PHP tag
-                                       $evalRight = substr($evalRight, 3);
-                               } // END - if
+                               $evalRight = substr($eval, (strpos($eval, "<?php") + 5));
 
                                // Cut middle part out and remove escapes
                                $evalMiddle = trim(substr($evalRight, 0, strpos($evalRight, "?>")));
 
                                // Cut middle part out and remove escapes
                                $evalMiddle = trim(substr($evalRight, 0, strpos($evalRight, "?>")));
@@ -1246,6 +1242,47 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Set the code back
                $this->setRawTemplateData($rawData);
        }
                // 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("<pre>".htmlentities($content)."</pre>");
+                       throw new XmlParserException(array($this, $xmlParser), BaseHelper::EXCEPTION_XML_PARSER_ERROR);
+               } // END - if
+
+               // Free the parser
+               xml_parser_free($xmlParser);
+       }
 }
 
 // [EOF]
 }
 
 // [EOF]