]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/template/class_TemplateEngine.php
Registration form nearly done, partial stub support added
[shipsimu.git] / inc / classes / main / template / class_TemplateEngine.php
index f929b8a1b8296373d6f9862c4943d1825426cf9d..a8e478b5b32070e64cabc19bdc5b71f8f81ee8c1 100644 (file)
@@ -611,15 +611,8 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
                        // Initialize all missing variables
                        foreach ($variableMatches[3] as $key=>$var) {
-                               // Is the variable name valid?
-                               // @TODO Find a better way than ignoring our instance variable $this
-                               if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config") && ($variableMatches[1][$key] != "this")) {
-                                       // Invalid variable name
-                                       throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR);
-                               } elseif ($variableMatches[1][$key] != "this") {
-                                       // Try to assign it, empty strings are being ignored
-                                       $this->assignTemplateVariable($variableMatches[1][$key], $var);
-                               }
+                               // Try to assign it, empty strings are being ignored
+                               $this->assignTemplateVariable($variableMatches[1][$key], $var);
                        }
                }
        }
@@ -983,57 +976,65 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                unset($idx);
                unset($currVariable);
 
-               // Finalize the compilation of template variables
-               $this->finalizeVariableCompilation();
-
-               // Prepare the eval() command for comiling the template
-               $eval = sprintf("\$result = \"%s\";",
-                       addslashes($this->getRawTemplateData())
-               );
-
-               // This loop does remove the backslashes (\) in PHP parameters
-               // @TODO Make this some nicer...
-               while (strpos($eval, "<?") !== false) {
-                       // Get left part before "<?"
-                       $evalLeft = substr($eval, 0, strpos($eval, "<?"));
+               // Run the compilation twice to get content from helper classes in
+               $cnt = 0;
+               while ($cnt < 2) {
+                       // Finalize the compilation of template variables
+                       $this->finalizeVariableCompilation();
 
-                       // Get all from right of "<?"
-                       $evalRight = substr($eval, (strpos($eval, "<?") + 2));
+                       // Prepare the eval() command for comiling the template
+                       $eval = sprintf("\$result = \"%s\";",
+                               addslashes($this->getRawTemplateData())
+                       );
 
-                       // Is this a full PHP tag?
-                       if (substr(strtolower($evalRight), 0, 3) == "php") {
-                               // Remove "php" string from full PHP tag
-                               $evalRight = substr($evalRight, 3);
-                       }
+                       // This loop does remove the backslashes (\) in PHP parameters
+                       // @TODO Make this some nicer...
+                       while (strpos($eval, "<?") !== false) {
+                               // Get left part before "<?"
+                               $evalLeft = substr($eval, 0, strpos($eval, "<?"));
+
+                               // 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
+
+                               // Cut middle part out and remove escapes
+                               $evalMiddle = trim(substr($evalRight, 0, strpos($evalRight, "?>")));
+                               $evalMiddle = stripslashes($evalMiddle);
+
+                               // Remove the middle part from right one
+                               $evalRight = substr($evalRight, (strpos($evalRight, "?>") + 2));
+
+                               // And put all together
+                               $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight);
+                       } // END - while
+
+                       // Prepare PHP code for eval() command
+                       $eval = str_replace(
+                               "<%php", "\";",
+                               str_replace(
+                                       "%>", "\$result .= \"", $eval
+                               )
+                       );
 
-                       // Cut middle part out and remove escapes
-                       $evalMiddle = trim(substr($evalRight, 0, strpos($evalRight, "?>")));
-                       $evalMiddle = stripslashes($evalMiddle);
+                       // Debug message
+                       if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command: <pre><em>%s</em></pre><br />\n",
+                               $this->__toString(),
+                               htmlentities($eval)
+                       ));
 
-                       // Remove the middle part from right one
-                       $evalRight = substr($evalRight, (strpos($evalRight, "?>") + 2));
+                       // Run the constructed command. This will "compile" all variables in
+                       eval($eval);
 
-                       // And put all together
-                       $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight);
+                       // Set raw template data
+                       $this->setRawTemplateData($result);
+                       $cnt++;
                }
 
-               // Prepare PHP code for eval() command
-               $eval = str_replace(
-                       "<%php", "\";",
-                       str_replace(
-                               "%>", "\$result = \"", $eval
-                       )
-               );
-
-               // Debug message
-               if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command: <pre><em>%s</em></pre><br />\n",
-                       $this->__toString(),
-                       htmlentities($eval)
-               ));
-
-               // Run the constructed command. This will "compile" all variables in
-               eval($eval);
-
                // Set the new content
                $this->setCompiledData($result);
        }
@@ -1043,9 +1044,9 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
         *
         * @return      void
         * @throws      UnexpectedTemplateTypeException If the template type is
-        *                                                                              not "code"
+        *                                                                                      not "code"
         * @throws      InvalidArrayCountException              If an unexpected array
-        *                                                                              count has been found
+        *                                                                                      count has been found
         */
        public final function compileTemplate () {
                // We will only work with template type "code" from configuration