From a7007416f1f7cd0286f6c3c1ef76f20191be59d2 Mon Sep 17 00:00:00 2001 From: Elisandro Date: Mon, 10 Jun 2024 12:16:24 +0100 Subject: [PATCH] 24: make captcha_enabled per-instance --- classes/MagicForm.php | 5 +++-- classes/ReCaptcha.php | 4 ++-- classes/SharedProperties.php | 1 + components/partials/recaptcha.htm | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/classes/MagicForm.php b/classes/MagicForm.php index 4855b0b..622ddde 100644 --- a/classes/MagicForm.php +++ b/classes/MagicForm.php @@ -25,8 +25,9 @@ abstract class MagicForm extends ComponentBase public function onRun() { - $this->page['recaptcha_enabled'] = $this->isReCaptchaEnabled(); - $this->page['recaptcha_misconfigured'] = $this->isReCaptchaMisconfigured(); + $this->recaptcha_enabled = $this->isReCaptchaEnabled(); + $this->page['recaptcha_enabled'] = $this->page['recaptcha_enabled'] || $this->isReCaptchaEnabled(); + $this->page['recaptcha_misconfigured'] = $this->page['recaptcha_misconfigured'] || $this->isReCaptchaMisconfigured(); if ($this->isReCaptchaEnabled()) { $this->loadReCaptcha(); diff --git a/classes/ReCaptcha.php b/classes/ReCaptcha.php index 5181f98..fe22610 100644 --- a/classes/ReCaptcha.php +++ b/classes/ReCaptcha.php @@ -26,11 +26,11 @@ public function init() { } private function isReCaptchaEnabled() { - return ($this->property('recaptcha_enabled') && Settings::get('recaptcha_site_key') != '' && Settings::get('recaptcha_secret_key') != ''); + return $this->property('recaptcha_enabled') && !$this->isReCaptchaMisconfigured(); } private function isReCaptchaMisconfigured() { - return ($this->property('recaptcha_enabled') && (Settings::get('recaptcha_site_key') == '' || Settings::get('recaptcha_secret_key') == '')); + return Settings::get('recaptcha_site_key') == '' || Settings::get('recaptcha_secret_key') == ''; } private function getReCaptchaLang($lang='') { diff --git a/classes/SharedProperties.php b/classes/SharedProperties.php index 0c56430..3f04001 100644 --- a/classes/SharedProperties.php +++ b/classes/SharedProperties.php @@ -5,6 +5,7 @@ use Lang; trait SharedProperties { + public $recaptcha_enabled = false; public function defineProperties() { return [ diff --git a/components/partials/recaptcha.htm b/components/partials/recaptcha.htm index b677c50..74e6252 100644 --- a/components/partials/recaptcha.htm +++ b/components/partials/recaptcha.htm @@ -1,5 +1,5 @@ -{% if (recaptcha_enabled) %} +{% if (__SELF__.recaptcha_enabled) %}
{% elseif (recaptcha_misconfigured) %}
{{ recaptcha_warn }}
-{% endif %} \ No newline at end of file +{% endif %}