CRM-21104: Forcing reCaptcha on Contribution pages(with online payments) which have no Profile associated with them.
'recaptchaOptions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recaptchaPublicKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recaptchaPrivateKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+ 'forceRecaptcha' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'wkhtmltopdfPath' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recentItemsMaxCount' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recentItemsProviders' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
$this->buildComponentForm($this->_id, $this);
}
+ if (count($this->_paymentProcessors) >= 1 && !isset($this->_paymentProcessors[0]) && !$this->get_template_vars("isCaptcha") && $this->hasToAddForcefully()) {
+ if (!$this->_userID) {
+ $this->enableCaptchaOnForm();
+ }
+ else {
+ $this->displayCaptchaWarning();
+ }
+ }
+
// Build payment processor form
CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
}
if ($addCaptcha && !$viewOnly) {
- $captcha = CRM_Utils_ReCAPTCHA::singleton();
- $captcha->add($this);
- $this->assign('isCaptcha', TRUE);
+ $this->enableCaptchaOnForm();
}
}
}
}
+ /**
+ * Enable ReCAPTCHA on Contribution form
+ */
+ protected function enableCaptchaOnForm() {
+ $captcha = CRM_Utils_ReCAPTCHA::singleton();
+ if ($captcha->hasSettingsAvailable()) {
+ $captcha->add($this);
+ $this->assign('isCaptcha', TRUE);
+ }
+ }
+
+ /**
+ * Display ReCAPTCHA warning on Contribution form
+ */
+ protected function displayCaptchaWarning() {
+ if (CRM_Core_Permission::check("administer CiviCRM")) {
+ $captcha = CRM_Utils_ReCAPTCHA::singleton();
+ if (!$captcha->hasSettingsAvailable()) {
+ $this->assign('displayCaptchaWarning', TRUE);
+ }
+ }
+ }
+
+ /**
+ * Check if ReCAPTCHA has to be added on Contribution form forcefully.
+ */
+ protected function hasToAddForcefully() {
+ $captcha = CRM_Utils_ReCAPTCHA::singleton();
+ return $captcha->hasToAddForcefully();
+ }
+
/**
* Add onbehalf/honoree profile fields and native module fields.
*
'recaptchaOptions' => array('setting'),
'recaptchaPublicKey' => array('setting'),
'recaptchaPrivateKey' => array('setting'),
+ 'forceRecaptcha' => array('setting'),
'replyTo' => array('setting'),
'secondDegRelPermissions' => array('setting'),
'smartGroupCacheTimeout' => array('setting'),
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;
+ }
+
+ /**
+ * Check if reCaptcha has to be added on form forcefully.
+ */
+ public static function hasToAddForcefully() {
+ $config = CRM_Core_Config::singleton();
+ if (!$config->forceRecaptcha) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+
/**
* Add element to form.
*
'description' => NULL,
'help_text' => NULL,
),
+ 'forceRecaptcha' => array(
+ 'add' => '4.7',
+ 'help_text' => NULL,
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'group_name' => 'CiviCRM Preferences',
+ 'group' => 'core',
+ 'name' => 'forceRecaptcha',
+ 'type' => 'Boolean',
+ 'quick_form_type' => 'YesNo',
+ 'html_type' => '',
+ 'default' => '0',
+ 'title' => 'Force reCAPTCHA on Contribution pages',
+ 'description' => 'If enabled, reCAPTCHA will show on all contribution pages.',
+ ),
'recaptchaPrivateKey' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
</span>
</td>
</tr>
+ <tr class="crm-miscellaneous-form-block-recaptchaPrivateKey">
+ <td class="label">{$form.forceRecaptcha.label}</td>
+ <td>
+ {$form.forceRecaptcha.html}
+ <p class="description">{ts}If enabled, reCAPTCHA will show on all contribution pages.{/ts}</p>
+ </td>
+ </tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
{include file="CRM/Contribute/Form/Contribution/PreviewHeader.tpl"}
{/if}
+ {if $displayCaptchaWarning}
+ <div class="messages status no-popup">
+ {ts}To display reCAPTCHA on form you must get an API key from<br /> <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>{/ts}
+ </div>
+ {/if}
+
{include file="CRM/common/TrackingFields.tpl"}
<div class="crm-contribution-page-id-{$contributionPageID} crm-block crm-contribution-main-form-block">