From: Roland Häder Date: Mon, 23 Jun 2008 18:32:22 +0000 (+0000) Subject: Fixes for template engine X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cc75d90baeef97069f2285757b9fbb610e9dfcc5;p=shipsimu.git Fixes for template engine --- diff --git a/application/ship-simu/templates/de/code/captch_graphic_code.ctp b/application/ship-simu/templates/de/code/captch_graphic_code.ctp index bb422da..de17efb 100644 --- a/application/ship-simu/templates/de/code/captch_graphic_code.ctp +++ b/application/ship-simu/templates/de/code/captch_graphic_code.ctp @@ -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] diff --git a/inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php b/inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php index d40a1ba..64f5788 100644 --- a/inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php +++ b/inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php @@ -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(); diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 00691ef..8a53c46 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -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."
\n"; $this->addVariable($var, $value); } elseif (!empty($value)) { // Modify the stack entry + //* DEBUG: */ echo "MOD: ".$var."
\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