]> git.mxchange.org Git - core.git/commitdiff
Check for config variables first, than general to avoid a bug: If the same
authorRoland Häder <roland@mxchange.org>
Sun, 6 May 2012 00:43:29 +0000 (00:43 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 6 May 2012 00:43:29 +0000 (00:43 +0000)
variable is set in general and config. This needs fixing! :(

inc/classes/main/helper/web/forms/class_WebFormHelper.php
inc/classes/main/images/class_BaseImage.php
inc/classes/main/template/class_BaseTemplateEngine.php

index 4fb8f08fd0bbc7a3d6449f56402a30ae9aa91cf6..718fa4481677efdf3141de3f7468b07d3c8f4148 100644 (file)
@@ -189,7 +189,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
        public function addInputTextFieldWithDefault ($fieldName) {
                // Get the value from instance
                $fieldValue = $this->getValueField($fieldName);
-               //* DEBUG: */ echo __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
+               //* DEBUG: */ print __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
 
                // Add the text field
                $this->addInputTextField($fieldName, $fieldValue);
@@ -257,7 +257,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
        public function addInputHiddenFieldWithDefault ($fieldName) {
                // Get the value from instance
                $fieldValue = $this->getValueField($fieldName);
-               //* DEBUG: */ echo __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
+               //* DEBUG: */ print __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
 
                // Add the text field
                $this->addInputHiddenField($fieldName, $fieldValue);
@@ -273,7 +273,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
        public function addInputHiddenConfiguredField ($fieldName, $prefix) {
                // Get the value from instance
                $fieldValue = $this->getConfigInstance()->getConfigEntry("{$prefix}_{$fieldName}");
-               //* DEBUG: */ echo __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
+               //* DEBUG: */ print __METHOD__.':'.$fieldName.'='.$fieldValue."<br />\n";
 
                // Add the text field
                $this->addInputHiddenField($fieldName, $fieldValue);
@@ -929,7 +929,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                }
 
                // Send content to template engine
-               //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->renderContent())."<br />\n";
+               //* DEBUG: */ print __METHOD__.": form=".$this->getFormName().", size=".strlen($this->renderContent())."<br />\n";
                $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->renderContent());
        }
 }
index 18c565aaeace721647b331bd98aaa12c0c1b8263..578cee0fa740c6be425d078eb1d0b8bd1e274de1 100644 (file)
@@ -516,7 +516,7 @@ class BaseImage extends BaseFrameworkSystem implements Registerable {
                                        $size = $templateInstance->compileRawCode($this->getFontSize());
 
                                        // Set the image string
-                                       //* DEBUG: */ echo __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}<br />\n";
+                                       //* DEBUG: */ print __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}<br />\n";
                                        imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor);
                                } // END - foreach
                                break;
index d8a6719a5440dbbd4464104dee74e88d86fc69f9..cc9739aab3b0dd41168245a304f061f98f643876 100644 (file)
@@ -176,17 +176,21 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $found = false;
 
                // If the stack is null, use the current group
-               if (is_null($stack)) $stack = $this->currGroup;
+               if (is_null($stack)) {
+                       // Use current group
+                       //* DEBUG: */ print __METHOD__.' currGroup=' . $this->currGroup . ' set as stack!<br />' . chr(10);
+                       $stack = $this->currGroup;
+               } // END - if
 
                // Is the group there?
                if ($this->isVarStackSet($stack)) {
                        // Now search for it
                        foreach ($this->getVarStack($stack) as $index => $currEntry) {
-                               //* DEBUG: */ echo __METHOD__.":currGroup={$stack},idx={$index},currEntry={$currEntry['name']},var={$var}<br />\n";
+                               //* DEBUG: */ print __METHOD__.":currGroup={$stack},idx={$index},currEntry={$currEntry['name']},var={$var}<br />\n";
                                // Is the entry found?
                                if ($currEntry['name'] == $var) {
                                        // Found!
-                                       //* DEBUG: */ echo __METHOD__.":FOUND!<br />\n";
+                                       //* DEBUG: */ print __METHOD__.":FOUND!<br />\n";
                                        $found = $index;
                                        break;
                                } // END - if
@@ -244,7 +248,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $content = NULL;
 
                // If the stack is null, use the current group
-               if (is_null($stack)) $stack = $this->currGroup;
+               if (is_null($stack)) {
+                       // Use current group
+                       //* DEBUG: */ print __METHOD__.' currGroup=' . $this->currGroup . ' set as stack!<br />' . chr(10);
+                       $stack = $this->currGroup;
+               } // END - if
 
                // Get variable index
                $found = $this->getVariableIndex($var, $stack);
@@ -256,7 +264,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                } // END - if
 
                // Return the current position
-               //* DEBUG: */ echo __METHOD__.": group=".$stack.",var=".$var.", content[".gettype($content)."]=".$content."<br />\n";
+               //* DEBUG: */ print __METHOD__.': group='.$stack.',var='.$var.', content['.gettype($content).']='.$content.'<br />' . chr(10);
                return $content;
        }
 
@@ -303,7 +311,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function setVariableGroup ($groupName, $add = true) {
                // Set group name
-               //* DEBIG: */ echo __METHOD__.": currGroup=".$groupName."<br />\n";
+               //* DEBIG: */ print __METHOD__.": currGroup=".$groupName."<br />\n";
                $this->currGroup = $groupName;
 
                // Skip group 'general'
@@ -321,7 +329,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         */
        public function addGroupVariable ($var, $value) {
-               //* DEBUG: */ echo __METHOD__.": group=".$this->currGroup.", var=".$var.", value=".$value."<br />\n";
+               //* DEBUG: */ print __METHOD__.": group=".$this->currGroup.", var=".$var.", value=".$value."<br />\n";
 
                // Get current variables in group
                $currVars = $this->readCurrentGroup();
@@ -625,8 +633,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        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->getVarStack($this->currGroup)).', groups='.count($this->varStack).'<br />\n';
+               //* DEBUG: */ print __METHOD__.': '.strlen($rawTemplateData).' Bytes set.' . chr(10);
+               //* DEBUG: */ print $this->currGroup.' variables: '.count($this->getVarStack($this->currGroup)).', groups='.count($this->varStack).'' . chr(10);
                $this->rawTemplateData = (string) $rawTemplateData;
        }
 
@@ -636,7 +644,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      $rawTemplateData        The raw data from the template
         */
        public final function getRawTemplateData () {
-               //* DEBUG: */ echo __METHOD__.':'.$this->getUniqueId().': '.strlen($this->rawTemplateData).' Bytes read.<br />\n';
+               //* DEBUG: */ print __METHOD__.': '.strlen($this->rawTemplateData).' Bytes read.' . chr(10);
                return $this->rawTemplateData;
        }
 
@@ -647,7 +655,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private final function setCompiledData ($compiledData) {
                // And store it in this class
-               //* DEBUG: */ echo __METHOD__.':'.$this->getUniqueId().': '.strlen($compiledData).' Bytes set.<br />\n';
+               //* DEBUG: */ print __METHOD__.': '.strlen($compiledData).' Bytes set.' . chr(10);
                $this->compiledData = (string) $compiledData;
        }
 
@@ -657,7 +665,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      $compiledData   Compiled template data
         */
        public final function getCompiledData () {
-               //* DEBUG: */ echo __METHOD__.':'.$this->getUniqueId().': '.strlen($this->compiledData).' Bytes read.<br />\n';
+               //* DEBUG: */ print __METHOD__.': '.strlen($this->compiledData).' Bytes read.' . chr(10);
                return $this->compiledData;
        }
 
@@ -734,7 +742,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $ioInstance = $this->getFileIoInstance();
 
                // Some debug code to look on the file which is being loaded
-               //* DEBUG: */ echo __METHOD__.": FQFN=".$fqfn."<br />\n";
+               //* DEBUG: */ print __METHOD__.": FQFN=".$fqfn."<br />\n";
 
                // Load the raw template
                $rawTemplateData = $ioInstance->loadFileContents($fqfn);
@@ -813,7 +821,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $backup = $this->getRawTemplateData();
 
                // Initialize some arrays
-               if (is_null($this->loadedRawData)) { $this->loadedRawData = array(); $this->rawTemplates = array(); }
+               if (is_null($this->loadedRawData)) {
+                       // Initialize both
+                       $this->loadedRawData = array();
+                       $this->rawTemplates = array();
+               } // END - if
 
                // Load all requested templates
                foreach ($templateMatches[1] as $template) {
@@ -823,16 +835,16 @@ 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->getVariableIndex($template) !== false) {
+                               //* DEBUG: */ print __METHOD__.":template={$template}<br />\n";
+                               if ($this->getVariableIndex($template, 'config') !== false) {
                                        // Use that content here
-                                       $this->loadedRawData[$template] = $this->readVariable($template);
+                                       $this->loadedRawData[$template] = $this->readVariable($template, 'config');
 
                                        // Recursive protection:
                                        $this->loadedTemplates[] = $template;
-                               } elseif ($this->getVariableIndex($template, 'config')) {
+                               } elseif ($this->getVariableIndex($template) !== false) {
                                        // Use that content here
-                                       $this->loadedRawData[$template] = $this->readVariable($template, 'config');
+                                       $this->loadedRawData[$template] = $this->readVariable($template);
 
                                        // Recursive protection:
                                        $this->loadedTemplates[] = $template;
@@ -999,7 +1011,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                if (in_array($template, $this->compiledTemplates)) {
                                        // Then skip it
                                        continue;
-                               }
+                               } // END - if
 
                                // Search for the template
                                $foundIndex = array_search($template, $templateMatches[1]);
@@ -1047,7 +1059,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        private function finalizeVariableCompilation () {
                // Get the content
                $content = $this->getRawTemplateData();
-               //* DEBUG: */ echo __METHOD__.': content before='.strlen($content).' ('.md5($content).')<br />\n';
+               //* DEBUG: */ print __METHOD__.': content before='.strlen($content).' ('.md5($content).')' . chr(10);
 
                // Do we have the stack?
                if (!$this->isVarStackSet('general')) {
@@ -1058,7 +1070,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
                // Walk through all variables
                foreach ($this->getVarStack('general') as $currEntry) {
-                       //* DEBUG: */ echo __METHOD__.': name='.$currEntry['name'].', value=<pre>'.htmlentities($currEntry['value']).'</pre>\n';
+                       //* DEBUG: */ print __METHOD__.': name='.$currEntry['name'].', value=<pre>'.htmlentities($currEntry['value']).'</pre>\n';
                        // Replace all [$var] or {?$var?} with the content
                        // @TODO Old behaviour, will become obsolete!
                        $content = str_replace('$content[' . $currEntry['name'] . ']', $currEntry['value'], $content);
@@ -1070,7 +1082,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        $content = str_replace('{?' . $currEntry['name'] . '?}', $currEntry['value'], $content);
                } // END - for
 
-               //* DEBUG: */ echo __METHOD__.': content after='.strlen($content).' ('.md5($content).')<br />\n';
+               //* DEBUG: */ print __METHOD__.': content after='.strlen($content).' ('.md5($content).')' . chr(10);
 
                // Set the content back
                $this->setRawTemplateData($content);
@@ -1099,7 +1111,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function assignConfigVariable ($var) {
                // Sweet and simple...
-               //* DEBUG: */ echo __METHOD__.':var={$var}<br />\n';
+               //* DEBUG: */ print __METHOD__.': var=' . $var . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($var) . chr(10);
                $this->setVariable('config', $var, $this->getConfigInstance()->getConfigEntry($var));
        }
 
@@ -1142,6 +1154,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        $this->removeVariable($index, 'general');
 
                        // Re-assign the variable
+                       //* DEBUG: */ print __METHOD__.': value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index . chr(10);
                        $this->assignConfigVariable($value);
                } // END - foreach
        }
@@ -1380,11 +1393,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function compileRawCode ($rawCode, $setMatchAsCode=false) {
                // Find the variables
-               //* DEBUG: */ echo __METHOD__.":rawCode=<pre>".htmlentities($rawCode)."</pre>\n";
+               //* DEBUG: */ print __METHOD__.":rawCode=<pre>".htmlentities($rawCode)."</pre>\n";
                preg_match_all($this->regExpVarValue, $rawCode, $varMatches);
 
                // Compile all variables
-               //* DEBUG: */ echo __METHOD__.":<pre>".print_r($varMatches, true)."</pre>\n";
+               //* DEBUG: */ print __METHOD__.":<pre>".print_r($varMatches, true)."</pre>\n";
                foreach ($varMatches[0] as $match) {
                        // Add variable tags around it
                        $varCode = '{?' . $match . '?}';
@@ -1393,7 +1406,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        if (strpos($rawCode, $varCode) !== false) {
                                // Replace the variable with it's value, if found
                                $value = $this->readVariable($match);
-                               //* DEBUG: */ echo __METHOD__.": match=".$match.",value[".gettype($value)."]=".$value."<br />\n";
+                               //* DEBUG: */ print __METHOD__.": match=".$match.",value[".gettype($value)."]=".$value."<br />\n";
                                if (($setMatchAsCode === true) && (is_null($value))) {
                                        // Insert match
                                        $rawCode = str_replace($varCode, $match, $rawCode);
@@ -1405,7 +1418,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                } // END - foreach
 
                // Return the compiled data
-               //* DEBUG: */ echo __METHOD__.":rawCode=<pre>".htmlentities($rawCode)."</pre>\n";
+               //* DEBUG: */ print __METHOD__.":rawCode=<pre>".htmlentities($rawCode)."</pre>\n";
                return $rawCode;
        }
 
@@ -1426,7 +1439,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         */
        public function renameVariable ($oldName, $newName) {
-               //* DEBUG: */ echo __METHOD__.": oldName={$oldName}, newName={$newName}<br />\n";
+               //* DEBUG: */ print __METHOD__.": oldName={$oldName}, newName={$newName}<br />\n";
                // Get raw template code
                $rawData = $this->getRawTemplateData();