X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=6b8145f46c629e939e4f9956b9ffa08d0e5998cf;hp=577c4ea6a9b0bdd2504e7b64d423d39c56f90c3a;hb=57bbfb3dec01126b0e4e0b2cdebaca155880cc54;hpb=4cf4ee9ebd395d0141c6ae707492dcb618710044 diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 577c4ea6..6b8145f4 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -2,11 +2,11 @@ /** * A generic template engine * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -178,7 +178,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // First everything is not found $found = FALSE; - // If the stack is null, use the current group + // If the stack is NULL, use the current group if (is_null($variableGroup)) { // Use current group //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!'); @@ -253,7 +253,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // First everything is not found $content = NULL; - // If the stack is null, use the current group + // If the stack is NULL, use the current group if (is_null($variableGroup)) { // Use current group //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!'); @@ -345,7 +345,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $currVars = $this->readCurrentGroup(); // Append our variable - $currVars[] = $this->generateVariableArray($variableName, $value); + array_push($currVars, $this->generateVariableArray($variableName, $value)); // Add it to the stack $this->setVarStack($this->currGroup, $currVars); @@ -419,8 +419,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Is the variable set? if ($index === FALSE) { + // Is the stack there? + if (!isset($this->varStack[$varGroup])) { + // Then initialize it here + $this->varStack[$varGroup] = array(); + } // END - if + // Not found, add it - $this->varStack[$varGroup][] = $this->generateVariableArray($variableName, $value); + array_push($this->varStack[$varGroup], $this->generateVariableArray($variableName, $value)); } else { // Then modify it $this->setVariableValue($this->currGroup, $index, $value); @@ -718,7 +724,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Is language support enabled? if ($this->isLanguageSupportEnabled()) { // Construct the FQFN for the template by honoring the current language - $fqfn = sprintf("%s%s%s%s/%s/%s%s", + $fqfn = sprintf('%s%s%s%s/%s/%s%s', $this->getConfigInstance()->getConfigEntry('base_path'), $this->getTemplateBasePath(), $this->getGenericBasePath(), @@ -729,7 +735,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { ); } else { // Construct the FQFN for the template without language - $fqfn = sprintf("%s%s%s%s/%s%s", + $fqfn = sprintf('%s%s%s%s/%s%s', $this->getConfigInstance()->getConfigEntry('base_path'), $this->getTemplateBasePath(), $this->getGenericBasePath(), @@ -879,13 +885,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->loadedRawData[$template] = $this->readVariable($template, 'config'); // Recursive protection: - $this->loadedTemplates[] = $template; + array_push($this->loadedTemplates, $template); } elseif ($this->getVariableIndex($template) !== FALSE) { // Use that content here $this->loadedRawData[$template] = $this->readVariable($template); // Recursive protection: - $this->loadedTemplates[] = $template; + array_push($this->loadedTemplates, $template); } else { // Then try to search for code-templates try { @@ -895,10 +901,10 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Remember this template for recursion detection // RECURSIVE PROTECTION! - $this->loadedTemplates[] = $template; + array_push($this->loadedTemplates, $template); } catch (FileIoException $e) { // Even this is not done... :/ - $this->rawTemplates[] = $template; + array_push($this->rawTemplates, $template); } } } // END - if @@ -923,7 +929,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } // END - if // Remember this template being compiled - $this->compiledTemplates[] = $template; + array_push($this->compiledTemplates, $template); // Compile the loaded code in five steps: // @@ -994,7 +1000,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Remember this template for recursion detection // RECURSIVE PROTECTION! - $this->loadedTemplates[] = $template; + array_push($this->loadedTemplates, $template); } catch (FileIoException $e) { // This template was never found. We silently ignore it unset($this->rawTemplates[$key]); @@ -1205,10 +1211,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Remove it from stack $this->removeVariable($currVariable['name'], 'general'); - - // Re-assign the variable //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index); - $this->setVariable('config', $currVariable['name'], $value); + + // Is it a configuration key? + if ($this->getConfigInstance()->isConfigurationEntrySet($value)) { + // The value itself is a configuration entry + $this->assignConfigVariable($value); + } else { + // Re-assign the value directly + $this->setVariable('config', $currVariable['name'], $value); + } } // END - foreach } @@ -1244,7 +1256,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->finalizeVariableCompilation(); // Prepare the eval() command for comiling the template - $eval = sprintf("\$result = \"%s\";", + $eval = sprintf('$result = "%s";', addslashes($this->getRawTemplateData()) ); @@ -1264,14 +1276,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $evalRight = substr($evalRight, (strpos($evalRight, $this->codeEnd) + 2)); // And put all together - $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight); + $eval = sprintf('%s<%%php %s %%>%s', $evalLeft, $evalMiddle, $evalRight); } // END - while // Prepare PHP code for eval() command $eval = str_replace( - "<%php", "\";", + '<%php', '";', str_replace( - "%>", + '%>', "\n\$result .= \"", $eval ) @@ -1283,7 +1295,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Goes something wrong? if ((!isset($result)) || (empty($result))) { // Output eval command - self::createDebugInstance(__CLASS__)->debugOutput(sprintf("Failed eval() code:
%s
", $this->markupCode($eval, TRUE)), TRUE); + self::createDebugInstance(__CLASS__)->debugOutput(sprintf('Failed eval() code:
%s
', $this->markupCode($eval, TRUE)), TRUE); // Output backtrace here $this->debugBackTrace();