Code base synced
[mailer.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 4db73b617de299fc4c976bb955506c8a622ee28d..2bbec445b092f3c9dcc661f14ef3ff3037f2c4f8 100644 (file)
@@ -69,11 +69,6 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private $varStack = array();
 
-       /**
-        * Configuration variables in a simple array
-        */
-       private $configVariables = array();
-
        /**
         * Loaded templates for recursive protection and detection
         */
@@ -154,10 +149,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Is the group there?
                if (isset($this->varStack[$this->currGroup])) {
                        // Now search for it
-                       foreach ($this->varStack[$this->currGroup] as $idx=>$currEntry) {
+                       foreach ($this->varStack[$this->currGroup] as $idx => $currEntry) {
+                               //* DEBUG: */ echo __METHOD__.":currGroup={$this->currGroup},idx={$idx},currEntry={$currEntry['name']},var={$var}<br />\n";
                                // Is the entry found?
                                if ($currEntry['name'] == $var) {
                                        // Found!
+                                       //* DEBUG: */ echo __METHOD__.":FOUND!<br />\n";
                                        $found = $idx;
                                        break;
                                } // END - if
@@ -586,7 +583,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Did we find some variables?
                if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
                        // Initialize all missing variables
-                       foreach ($variableMatches[3] as $key=>$var) {
+                       foreach ($variableMatches[3] as $key => $var) {
                                // Variable name
                                $varName = $variableMatches[1][$key];
 
@@ -628,10 +625,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) {
 
                                // Template not found, but maybe variable assigned?
+                               //* DEBUG: */ echo __METHOD__.":template={$template}<br />\n";
                                if ($this->isVariableAlreadySet($template) !== false) {
                                        // Use that content here
                                        $this->loadedRawData[$template] = $this->readVariable($template);
 
+                                       // Recursive protection:
+                                       $this->loadedTemplates[] = $template;
+                               } elseif (isset($this->varStack['config'][$template])) {
+                                       // Use that content here
+                                       $this->loadedRawData[$template] = $this->varStack['config'][$template];
+
                                        // Recursive protection:
                                        $this->loadedTemplates[] = $template;
                                } else {
@@ -671,7 +675,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                if (in_array($template, $this->compiledTemplates)) {
                        // Abort here...
                        return;
-               }
+               } // END - if
 
                // Remember this template being compiled
                $this->compiledTemplates[] = $template;
@@ -703,7 +707,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function insertAllTemplates (array $templateMatches) {
                // Run through all loaded codes
-               foreach ($this->loadedRawData as $template=>$code) {
+               foreach ($this->loadedRawData as $template => $code) {
 
                        // Search for the template
                        $foundIndex = array_search($template, $templateMatches[1]);
@@ -766,7 +770,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function assignAllVariables (array $varMatches) {
                // Search for all variables
-               foreach ($varMatches[1] as $key=>$var) {
+               foreach ($varMatches[1] as $key => $var) {
 
                        // Detect leading equals
                        if (substr($varMatches[2][$key], 0, 1) == "=") {
@@ -796,7 +800,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                if (count($this->loadedRawData) > 0) {
 
                        // Then compile all!
-                       foreach ($this->loadedRawData as $template=>$code) {
+                       foreach ($this->loadedRawData as $template => $code) {
 
                                // Is this template already compiled?
                                if (in_array($template, $this->compiledTemplates)) {
@@ -836,7 +840,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function insertRawTemplates () {
                // Load all templates
-               foreach ($this->rawTemplates as $template=>$content) {
+               foreach ($this->rawTemplates as $template => $content) {
                        // Set the template as a variable with the content
                        $this->assignVariable($template, $content);
                }
@@ -895,7 +899,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function assignConfigVariable ($var) {
                // Sweet and simple...
-               $this->configVariables[$var] = $this->getConfigInstance()->readConfig($var);
+               //* DEBUG: */ echo __METHOD__.":var={$var}<br />\n";
+               $this->varStack['config'][$var] = $this->getConfigInstance()->readConfig($var);
        }
 
        /**
@@ -916,7 +921,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        /**
         * Load a specified code template into the engine
         *
-        * @param               $template               The code template we shall load which is
+        * @param       $template       The code template we shall load which is
         *                                              located in "code" by default
         * @return      void
         */
@@ -944,14 +949,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Transfer it's name/value combination to the $content array
                        //* DEBUG: */ echo $currVariable['name']."=<pre>".htmlentities($currVariable['value'])."</pre>\n";
                        $dummy[$currVariable['name']] = $currVariable['value'];
-
                }// END - if
 
-               // Set the new variable (don't remove the second dollar !)
+               // Set the new variable (don't remove the second dollar!)
                $$validVar = $dummy;
 
                // Prepare all configuration variables
-               $config = $this->configVariables;
+               $config = null;
+               if (isset($this->varStack['config'])) {
+                       $config = $this->varStack['config'];
+               } // END - if
 
                // Remove some variables
                unset($idx);
@@ -1091,7 +1098,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
                default: // Unknown type found
                        // Construct message
-                       $msg = sprintf("[%s-&gt;%s] Unknown/unsupported template type <strong>%s</strong> detected.",
+                       $msg = sprintf("[%s-&gt;%s] Unknown/unsupported template type <span class=\"data\">%s</span> detected.",
                                $this->__toString(),
                                __FUNCTION__,
                                $this->getTemplateType()
@@ -1184,6 +1191,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
                // Get version number and assign it
                $this->assignVariable('app_version'   , $appInstance->getAppVersion());
+
+               // Assign extra application-depending data
+               $appInstance->assignExtraTemplateData($this);
        }
 
        /**