]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php
Comment header cosmetics applied
[shipsimu.git] / inc / classes / main / helper / captcha / web / class_GraphicalCodeCaptcha.php
index b3e3b55148e5f855a1ba36fb99470189ee7694f9..3734bbc7647534577d10008da35c7c3f045756d9 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -19,7 +19,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
        /**
@@ -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);
@@ -100,7 +100,7 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
                $searchChars = $this->getConfigInstance()->readConfig('captcha_search_chars');
 
                // Get fixed salt and use it as "replacement characters"
-               $replaceChars = $this->getRngInstance()->getFixedSalt();
+               $replaceChars = $this->getRngInstance()->getExtraSalt();
 
                // Remove any plus, equals or slashes
                for ($searchIdx = 0; $searchIdx < strlen($searchChars); $searchIdx++) {
@@ -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);
        }
 
        /**
@@ -133,7 +133,29 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
         * @return      void
         */
        public function renderCode () {
-               $this->partialStub("Please implement this method.");
+               // Get helper instance
+               $helperInstance = $this->getHelperInstance();
+
+               // Get template instance
+               $templateInstance = $helperInstance->getTemplateInstance();
+
+               // Load a template for this CAPTCHA
+               $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
+               $templateInstance->assignVariable($helperInstance->getFormName().'_encrypt', urlencode(base64_encode($this->encryptedString)));
+               $templateInstance->assignVariable($helperInstance->getFormName().'_hash', $this->hashedString);
+
+               // Compile the template
+               $templateInstance->compileTemplate();
+
+               // Get the content back
+               $this->addContent($templateInstance->getRawTemplateData());
        }
 }