Fixes for template engine
authorRoland Häder <roland@mxchange.org>
Mon, 23 Jun 2008 18:32:22 +0000 (18:32 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 23 Jun 2008 18:32:22 +0000 (18:32 +0000)
application/ship-simu/templates/de/code/captch_graphic_code.ctp
inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php
inc/classes/main/template/class_BaseTemplateEngine.php

index bb422daa939990e996c54e0c528027d9a2ebeeea..de17efba62079bbbe5acc4505232f857c245a499 100644 (file)
@@ -4,6 +4,7 @@ $helper = WebFormHelper::createWebFormHelper($this, "captcha_code", false, false
 $helper->addFormGroup('captcha_code', "Unser Spiel ist durch ein grafisches CAPTCHA gesichert. Du musst den angezeigten Code wiederholen, damit du unser Spiel nutzen kannst.");
 $helper->addFieldText('captcha_code', "Bitte wiederhole den Code:");
 $helper->addInputTextField('captcha_code');
+$helper->addInputHiddenField('captcha_hash', $this->readVariable('captcha_hash'));
 $helper->flushContent();
 
 // [EOF]
index d40a1ba146ce660a40931adccea702d04602a836..64f5788575939bdf584bfb48fc74a0c21722f1f0 100644 (file)
@@ -120,11 +120,11 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
                // Get crypto instance
                $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
 
+               // Hash the CAPTCHA code for later comparison
+               $this->hashedString = $cryptoInstance->hashString($captchaString);
+
                // Encrypt the string for later usage
                $this->encryptedString = $cryptoInstance->encryptString($captchaString);
-
-               // Hash the encrypted string for later comparison
-               $this->hashedString = $cryptoInstance->hashString($this->encryptedString);
        }
 
        /**
@@ -136,8 +136,9 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
                // Load a template for this CAPTCHA
                $this->getTemplateInstance()->loadCodeTemplate("captch_graphic_code");
 
-               // Assign variable
+               // Assign variables
                $this->getTemplateInstance()->assignVariable('encrypted_code', urlencode(base64_encode($this->encryptedString)));
+               $this->getTemplateInstance()->assignVariable('captcha_hash', $this->hashedString);
 
                // Compile the template
                $this->getTemplateInstance()->compileTemplate();
index 00691efa515ccc45bcfee424e748deda9738a4ef..8a53c46859771174e3df40bd82c16e922b868da2 100644 (file)
@@ -429,17 +429,29 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $var    The variable we are looking for
         * @param       $value  The value we want to store in the variable
         * @return      void
+        * @throws      EmptyVariableException  If the variable name is left empty
         */
        public final function assignVariable ($var, $value) {
+               // Trim spaces of variable name
+               $var = trim($var);
+
+               // Empty variable found?
+               if (empty($var)) {
+                       // Throw an exception
+                       throw new EmptyVariableException(array($this, 'var'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } // END - if
+
                // First search for the variable if it was already added
                $idx = $this->isVariableAlreadySet($var);
 
                // Was it found?
                if ($idx === false) {
                        // Add it to the stack
+                       //* DEBUG: */ echo "ADD: ".$var."<br />\n";
                        $this->addVariable($var, $value);
                } elseif (!empty($value)) {
                        // Modify the stack entry
+                       //* DEBUG: */ echo "MOD: ".$var."<br />\n";
                        $this->modifyVariable($var, $value);
                }
        }
@@ -595,8 +607,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
                        // Initialize all missing variables
                        foreach ($variableMatches[3] as $key=>$var) {
-                               // Try to assign it, empty strings are being ignored
-                               $this->assignTemplateVariable($variableMatches[1][$key], $var);
+                               // Variable name
+                               $varName = $variableMatches[1][$key];
+
+                               // Workarround: Do not assign empty variables
+                               if (!empty($var)) {
+                                       // Try to assign it, empty strings are being ignored
+                                       $this->assignTemplateVariable($varName, $var);
+                               } // END - if
                        } // END - foreach
                } // END - if
        }
@@ -1015,7 +1033,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        );
 
                        // Did something change?
-                       if (strlen($eval) != $eval) {
+                       if (strlen($eval) != $evalLength) {
                                // Run the constructed command. This will "compile" all variables in
                                @eval($eval);
                        } // END - if