]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php
Final fixes for variable inserting
[shipsimu.git] / inc / classes / main / helper / captcha / web / class_GraphicalCodeCaptcha.php
index 64f5788575939bdf584bfb48fc74a0c21722f1f0..3e57d241e65dddf8c1fba3773db2b3f679f9ad61 100644 (file)
@@ -51,16 +51,16 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
        /**
         * Creates an instance of this captcha class
         *
-        * @param       $templateInstance       An instance of a template engine
+        * @param       $helperInstance         An instance of a helper class
         * @param       $extraInstance          An extra instance, just for better hash data
         * @return      $captchaInstance        An instance of this captcha class
         */
-       public final static function createGraphicalCodeCaptcha (CompileableTemplate $templateInstance, FrameworkInterface $extraInstance = null) {
+       public final static function createGraphicalCodeCaptcha (HelpableTemplate $helperInstance, FrameworkInterface $extraInstance = null) {
                // Get a new instance
                $captchaInstance = new GraphicalCodeCaptcha();
 
                // Set template instance
-               $captchaInstance->setTemplateInstance($templateInstance);
+               $captchaInstance->setHelperInstance($helperInstance);
 
                // Initialize the RNG
                $captchaInstance->initializeRandomNumberGenerator($extraInstance);
@@ -133,18 +133,29 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
         * @return      void
         */
        public function renderCode () {
+               // Get helper instance
+               $helperInstance = $this->getHelperInstance();
+
+               // Get template instance
+               $templateInstance = $helperInstance->getTemplateInstance();
+
                // Load a template for this CAPTCHA
-               $this->getTemplateInstance()->loadCodeTemplate("captch_graphic_code");
+               $templateInstance->loadCodeTemplate("captch_graphic_code");
+
+               // Rename variable
+               $templateInstance->renameVariable('captcha_code', $helperInstance->getFormName().'_captcha');
+               $templateInstance->renameVariable('captcha_hash', $helperInstance->getFormName().'_hash');
+               $templateInstance->renameVariable('encrypted_code', $helperInstance->getFormName().'_encrypt');
 
                // Assign variables
-               $this->getTemplateInstance()->assignVariable('encrypted_code', urlencode(base64_encode($this->encryptedString)));
-               $this->getTemplateInstance()->assignVariable('captcha_hash', $this->hashedString);
+               $templateInstance->assignVariable($helperInstance->getFormName().'_encrypt', urlencode(base64_encode($this->encryptedString)));
+               $templateInstance->assignVariable($helperInstance->getFormName().'_hash', $this->hashedString);
 
                // Compile the template
-               $this->getTemplateInstance()->compileTemplate();
+               $templateInstance->compileTemplate();
 
                // Get the content back
-               $this->addContent($this->getTemplateInstance()->getRawTemplateData());
+               $this->addContent($templateInstance->getRawTemplateData());
        }
 }