From ec18bf34bdb8140c3f9e53797172a8d280b15e37 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 25 Apr 2022 02:02:29 +0900 Subject: [PATCH] Fix #1930 add option to autodetect dark mode in reCAPTCHA --- modules/spamfilter/lang/en.php | 1 + modules/spamfilter/lang/ko.php | 3 ++- modules/spamfilter/spamfilter.lib.php | 2 +- modules/spamfilter/tpl/config_captcha.html | 1 + modules/spamfilter/tpl/js/recaptcha.js | 6 +++++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/spamfilter/lang/en.php b/modules/spamfilter/lang/en.php index 2c5502287..a5b3234c6 100644 --- a/modules/spamfilter/lang/en.php +++ b/modules/spamfilter/lang/en.php @@ -46,6 +46,7 @@ $lang->msg_faillist = '
Error (already blocked)
%s '; $lang->use_captcha = 'Use CAPTCHA'; $lang->about_captcha_position = 'The skin file for your login form, write form, etc. should indicate the CAPTCHA position with the following code: {$captcha}
The CAPTCHA may be inserted in an unexpected position if the form does not contain the code.'; $lang->recaptcha_theme = 'Color Theme'; +$lang->recaptcha_theme_auto = 'Auto'; $lang->recaptcha_theme_light = 'Light'; $lang->recaptcha_theme_dark = 'Dark'; $lang->recaptcha_size = 'Display Size'; diff --git a/modules/spamfilter/lang/ko.php b/modules/spamfilter/lang/ko.php index 8ad3b0c71..5c9d8955d 100644 --- a/modules/spamfilter/lang/ko.php +++ b/modules/spamfilter/lang/ko.php @@ -46,6 +46,7 @@ $lang->msg_faillist = '
실패 (이미 차단되어 있습니다)
%s $lang->use_captcha = '캡챠 사용'; $lang->about_captcha_position = '로그인 폼, 글쓰기 폼 등의 스킨에서 캡챠를 표시할 위치에 {$captcha} 코드가 들어 있어야 합니다.
코드가 없는 경우 임의의 위치에 캡챠가 삽입되므로 디자인이 틀어질 수 있습니다.'; $lang->recaptcha_theme = '색상 테마'; +$lang->recaptcha_theme_auto = '자동'; $lang->recaptcha_theme_light = '밝은 색상'; $lang->recaptcha_theme_dark = '어두운 색상'; $lang->recaptcha_size = '캡챠 크기'; @@ -64,4 +65,4 @@ $lang->recaptcha_target_every_time = '매번 사용'; $lang->msg_recaptcha_connection_error = 'reCAPTCHA 스팸방지 서버에 접속하는 도중 오류가 발생했습니다.'; $lang->msg_recaptcha_server_error = 'reCAPTCHA 스팸방지 서버와 통신하는 도중 오류가 발생했습니다.'; $lang->msg_recaptcha_invalid_response = 'reCAPTCHA 스팸방지 기능을 체크해 주십시오.'; -$lang->msg_recaptcha_keys_not_set = 'reCAPTCHA Site Key 및 Secret Key를 입력하여 주십시오.'; \ No newline at end of file +$lang->msg_recaptcha_keys_not_set = 'reCAPTCHA Site Key 및 Secret Key를 입력하여 주십시오.'; diff --git a/modules/spamfilter/spamfilter.lib.php b/modules/spamfilter/spamfilter.lib.php index 54560ddc1..8967cff45 100644 --- a/modules/spamfilter/spamfilter.lib.php +++ b/modules/spamfilter/spamfilter.lib.php @@ -56,7 +56,7 @@ class spamfilter_reCAPTCHA Context::loadFile(array('./modules/spamfilter/tpl/js/recaptcha.js', 'body')); Context::addHtmlFooter(''); $html = '
'; - $html = sprintf($html, escape(self::$config->site_key), self::$config->theme ?: 'light', self::$config->size ?: 'normal', implode(',', array_keys($this->_target_actions))); + $html = sprintf($html, escape(self::$config->site_key), self::$config->theme ?: 'auto', self::$config->size ?: 'normal', implode(',', array_keys($this->_target_actions))); Context::addHtmlFooter($html); } } diff --git a/modules/spamfilter/tpl/config_captcha.html b/modules/spamfilter/tpl/config_captcha.html index eb7ed67aa..4b13f7678 100644 --- a/modules/spamfilter/tpl/config_captcha.html +++ b/modules/spamfilter/tpl/config_captcha.html @@ -34,6 +34,7 @@
diff --git a/modules/spamfilter/tpl/js/recaptcha.js b/modules/spamfilter/tpl/js/recaptcha.js index 91a93af9d..d8dd25698 100644 --- a/modules/spamfilter/tpl/js/recaptcha.js +++ b/modules/spamfilter/tpl/js/recaptcha.js @@ -47,10 +47,14 @@ function reCaptchaCallback() { recaptcha_instances.each(function() { var instance = $(this); + var theme = recaptcha_config.data("theme"); + if (theme === 'auto') { + theme = getColorScheme(); + } grecaptcha.render(instance.attr("id"), { sitekey: recaptcha_config.data("sitekey"), size: recaptcha_config.data("size"), - theme: recaptcha_config.data("theme") + theme: theme }); }); }