Support multiple CAPTCHA instances on the same page

This commit is contained in:
Kijin Sung 2016-06-08 00:04:32 +09:00
parent 5012bc194b
commit fe63f24617
5 changed files with 19 additions and 6 deletions

View file

@ -9,7 +9,7 @@ if ($addon_info->use_signup === 'Y' && preg_match('/^(?:disp|proc)Member(?:SignU
{
$enable_captcha = true;
}
if ($addon_info->use_recovery === 'Y' && preg_match('/^(?:disp|proc)Member(?:FindAccount|ResendAuthMail)/i', Context::get('act')))
elseif ($addon_info->use_recovery === 'Y' && preg_match('/^(?:disp|proc)Member(?:FindAccount|ResendAuthMail)/i', Context::get('act')))
{
$enable_captcha = true;
}

View file

@ -5,6 +5,7 @@ class reCAPTCHA
protected static $verify = 'https://www.google.com/recaptcha/api/siteverify';
protected static $config = null;
protected static $script_added = false;
protected static $sequence = 1;
public static function init($config)
{
@ -49,12 +50,13 @@ class reCAPTCHA
if (!self::$script_added)
{
Context::addHtmlFooter('<script src="https://www.google.com/recaptcha/api.js" async defer></script>');
Context::loadFile(array('./addons/recaptcha/recaptcha.js', 'body'));
Context::addHtmlFooter('<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=reCaptchaCallback" async defer></script>');
self::$script_added = true;
}
$html = '<div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-size="%s"></div>';
$html = sprintf($html, escape(self::$config->site_key), self::$config->theme ?: 'light', self::$config->size ?: 'normal');
$html = '<div id="recaptcha-instance-%d" class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-size="%s"></div>';
$html = sprintf($html, self::$sequence++, escape(self::$config->site_key), self::$config->theme ?: 'light', self::$config->size ?: 'normal');
return $html;
}
}

View file

@ -0,0 +1,11 @@
function reCaptchaCallback() {
$(".g-recaptcha").each(function() {
var instance = $(this);
grecaptcha.render(instance.attr("id"), {
sitekey: instance.data("sitekey"),
size: instance.data("size"),
theme: instance.data("theme")
});
});
}

View file

@ -318,7 +318,7 @@ $lang->cmd_no = 'No';
$lang->cmd_set_multilingual = 'Select Language';
$lang->cmd_multilingual = 'Language';
$lang->find_site = 'Find Site';
$lang->captcha = 'Captcha';
$lang->captcha = 'Spam Check';
$lang->reload = 'reload';
$lang->play = 'play';
$lang->use_and_display = 'Use and Display Vote List';

View file

@ -319,7 +319,7 @@ $lang->cmd_no = '아니오';
$lang->cmd_set_multilingual = '다국어 설정';
$lang->cmd_multilingual = '다국어';
$lang->find_site = '사이트 찾기';
$lang->captcha = 'Captcha';
$lang->captcha = '스팸 방지 기능';
$lang->reload = '새로고침';
$lang->play = '음성재생';
$lang->use_and_display = '사용 + 추천내역 공개';