/**
* 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);
* @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());
}
}