From 8237b5101ec3f483b53613442e31dff3af7415eb Mon Sep 17 00:00:00 2001 From: Alok Patel Date: Wed, 25 Oct 2017 15:38:11 +0530 Subject: [PATCH] CRM-21104: Displaying warning message on contribution page if ReCaptcha settings are not available. --- CRM/Contribute/Form/Contribution/Main.php | 2 +- CRM/Contribute/Form/ContributionBase.php | 9 +++++++-- CRM/Utils/ReCAPTCHA.php | 12 ++++++++++++ templates/CRM/Contribute/Form/Contribution/Main.tpl | 6 ++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 240f128af2..b1649521e2 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -302,7 +302,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->buildComponentForm($this->_id, $this); } - if (count($this->_paymentProcessors) == 1 && get_class($this->_paymentProcessors[0]["object"]) == "CRM_Core_Payment_Manual" && !$this->get_template_vars("isCaptcha")) { + if (count($this->_paymentProcessors) >= 1 && !isset($this->_paymentProcessors[0]) && !$this->get_template_vars("isCaptcha") && !$this->_userID) { $this->enableCaptchaOnForm(); } diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index d9479c0e82..48fd87673f 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -781,8 +781,13 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { */ protected function enableCaptchaOnForm() { $captcha = CRM_Utils_ReCAPTCHA::singleton(); - $captcha->add($this); - $this->assign('isCaptcha', TRUE); + if ($captcha->hasSettingsAvailable()) { + $captcha->add($this); + $this->assign('isCaptcha', TRUE); + } + else { + $this->assign('displayCaptchaWarning', TRUE); + } } /** diff --git a/CRM/Utils/ReCAPTCHA.php b/CRM/Utils/ReCAPTCHA.php index aa27d26dd6..5da3e41d69 100644 --- a/CRM/Utils/ReCAPTCHA.php +++ b/CRM/Utils/ReCAPTCHA.php @@ -62,6 +62,18 @@ class CRM_Utils_ReCAPTCHA { return self::$_singleton; } + + /** + * Check if reCaptcha settings is avilable to add on form. + */ + public static function hasSettingsAvailable() { + $config = CRM_Core_Config::singleton(); + if ($config->recaptchaPublicKey == NULL || $config->recaptchaPublicKey == "") { + return FALSE; + } + return TRUE; + } + /** * Add element to form. * diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 1137637e5b..261d12df1e 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -66,6 +66,12 @@ {include file="CRM/Contribute/Form/Contribution/PreviewHeader.tpl"} {/if} + {if $displayCaptchaWarning} +
+ {ts}To display reCAPTCHA on form you must get an API key from
https://www.google.com/recaptcha/admin/create{/ts} +
+ {/if} + {include file="CRM/common/TrackingFields.tpl"}
-- 2.25.1