diff --git a/modules/spamfilter/spamfilter.controller.php b/modules/spamfilter/spamfilter.controller.php index b6e2a8d3e..8a1091110 100644 --- a/modules/spamfilter/spamfilter.controller.php +++ b/modules/spamfilter/spamfilter.controller.php @@ -239,19 +239,19 @@ class spamfilterController extends spamfilter return; } - $enable = false; + $target_actions = []; foreach (['signup', 'login', 'recovery', 'document', 'comment'] as $action) { if ($config->captcha->target_actions[$action]) { if (preg_match(self::$_captcha_actions[$action], $obj->act) || ($action === 'comment' && (!$obj->act || $obj->act === 'dispBoardContent') && Context::get('document_srl'))) { - $enable = true; + $target_actions[$action] = true; } } } - if ($enable) + if (count($target_actions)) { include_once __DIR__ . '/spamfilter.lib.php'; spamfilter_reCAPTCHA::init($config->captcha); @@ -262,7 +262,9 @@ class spamfilterController extends spamfilter } else { - Context::set('captcha', new spamfilter_reCAPTCHA()); + $captcha = new spamfilter_reCAPTCHA(); + $captcha->setTargetActions($target_actions); + Context::set('captcha', $captcha); } } } diff --git a/modules/spamfilter/spamfilter.lib.php b/modules/spamfilter/spamfilter.lib.php index 3a0df0f35..02b001f8a 100644 --- a/modules/spamfilter/spamfilter.lib.php +++ b/modules/spamfilter/spamfilter.lib.php @@ -7,6 +7,7 @@ class spamfilter_reCAPTCHA protected static $scripts_added = false; protected static $instances_inserted = 0; protected static $sequence = 1; + protected $_target_actions = []; public static function init($config) { @@ -60,6 +61,16 @@ class spamfilter_reCAPTCHA } } + public function setTargetActions(array $target_actions) + { + $this->_target_actions = $target_actions; + } + + public function isTargetAction(string $action): bool + { + return isset($this->_target_actions[$action]); + } + public function __toString() { return sprintf('
', self::$instances_inserted++);