summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TReCaptcha.php
diff options
context:
space:
mode:
authorctrlaltca <>2013-01-06 18:17:30 +0000
committerctrlaltca <>2013-01-06 18:17:30 +0000
commitb5f4be7ea0b8bdf220297893a907fe59c017fbd5 (patch)
treeb8954dbdefcfa3a6ea997aa4dae8c6787473927d /framework/Web/UI/WebControls/TReCaptcha.php
parent11f2517f24aca0580fec7d3560108458da787342 (diff)
backported r3236 to trunk/
Diffstat (limited to 'framework/Web/UI/WebControls/TReCaptcha.php')
-rw-r--r--framework/Web/UI/WebControls/TReCaptcha.php66
1 files changed, 51 insertions, 15 deletions
diff --git a/framework/Web/UI/WebControls/TReCaptcha.php b/framework/Web/UI/WebControls/TReCaptcha.php
index b63edad8..c6cf4185 100644
--- a/framework/Web/UI/WebControls/TReCaptcha.php
+++ b/framework/Web/UI/WebControls/TReCaptcha.php
@@ -135,6 +135,16 @@ class TReCaptcha extends TWebControl implements IValidatable
return $this->setViewState('Language', TPropertyValue::ensureString($value));
}
+ public function getCallbackScript()
+ {
+ return $this->getViewState('CallbackScript');
+ }
+
+ public function setCallbackScript($value)
+ {
+ return $this->setViewState('CallbackScript', TPropertyValue::ensureString($value));
+ }
+
protected function getChallengeFieldName()
{
return /*$this->ClientID.'_'.*/self::ChallengeFieldName;
@@ -212,21 +222,47 @@ class TReCaptcha extends TWebControl implements IValidatable
public function renderContents($writer)
{
- $writer->write(TJavaScript::renderScriptBlock(
- 'var RecaptchaOptions = '.TJavaScript::jsonEncode($this->getClientSideOptions()).';'
- ));
-
- $html = recaptcha_get_html($this->getPublicKey());
- /*
- reCAPTCHA currently does not support multiple validations per page
- $html = str_replace(
- array(self::ChallengeFieldName,self::ResponseFieldName),
- array($this->getChallengeFieldName(),$this->getResponseFieldName()),
- $html
- );
- */
- $writer->write($html);
+ $readyscript = 'Event.fire(document, '.TJavaScript::quoteString('captchaready:'.$this->getClientID()).')';
+ $cs = $this->Page->ClientScript;
+ $id = $this->getClientID();
+ $divid = $id.'_1_recaptchadiv';
+ $writer->write('<div id="'.htmlspecialchars($divid).'">');
+
+ if (!$this->Page->IsCallback)
+ {
+ $writer->write(TJavaScript::renderScriptBlock(
+ 'var RecaptchaOptions = '.TJavaScript::jsonEncode($this->getClientSideOptions()).';'
+ ));
+
+ $html = recaptcha_get_html($this->getPublicKey());
+ /*
+ reCAPTCHA currently does not support multiple validations per page
+ $html = str_replace(
+ array(self::ChallengeFieldName,self::ResponseFieldName),
+ array($this->getChallengeFieldName(),$this->getResponseFieldName()),
+ $html
+ );
+ */
+ $writer->write($html);
+
+ $cs->registerEndScript('ReCaptcha::EventScript', 'Event.observe(document, "dom:loaded", function() { '.$readyscript.'; } );');
+ }
+ else
+ {
+ $options = $this->getClientSideOptions();
+ $options['callback'] = new TJavaScriptLiteral('function() { '.$readyscript.'; '.$this->getCallbackScript().'; }');
+ $cs->registerScriptFile('ReCaptcha::AjaxScript', 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
+ $cs->registerEndScript('ReCaptcha::CreateScript::'.$id, implode(' ', array(
+ 'if (!$('.TJavaScript::quoteString($this->getResponseFieldName()).'))',
+ 'Recaptcha.create(',
+ TJavaScript::quoteString($this->getPublicKey()).', ',
+ TJavaScript::quoteString($divid).', ',
+ TJavaScript::encode($options),
+ ');',
+ )));
+ }
+
+ $writer->write('</div>');
}
}
-