| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.Security.EscapeOutput.HeredocOutputNotEscaped, PluginCheck.CodeAnalysis.Heredoc -- PFBC framework extension, HTML output is controlled |
| 3 |
class AccuaForm_Element_Captcha2 extends Element { |
| 4 |
protected $privateKey = ""; |
| 5 |
protected $publicKey = ""; |
| 6 |
protected $captchaAction = ""; |
| 7 |
protected $spamAction = ""; |
| 8 |
|
| 9 |
public function __construct($label = "", $unused = null, ?array $properties = null) { |
| 10 |
if ($properties === null && is_array($unused)) { |
| 11 |
$properties = $unused; |
| 12 |
} |
| 13 |
parent::__construct($label, "recaptcha_response_field", $properties); |
| 14 |
$validator = new AccuaForm_Validation_Captcha2b(__("The reCAPTCHA response provided was incorrect. Please retry.", 'contact-forms')); |
| 15 |
$validator->configure(array('privateKey' => $this->privateKey, 'captchaAction' => $this->captchaAction, 'spamAction' => $this->spamAction)); |
| 16 |
$this->setValidation($validator); |
| 17 |
} |
| 18 |
|
| 19 |
public function render() { |
| 20 |
wp_enqueue_script( |
| 21 |
'accua-forms-recaptcha2', |
| 22 |
ACCUA_FORMS_DIR_URL . 'assets/js/frontend/recaptcha2.js', |
| 23 |
array('jquery'), |
| 24 |
ACCUA_FORMS_JS_VERSION, |
| 25 |
true |
| 26 |
); |
| 27 |
|
| 28 |
$js_registration = _accua_forms_json_encode(array( |
| 29 |
$this->attributes["id"], |
| 30 |
array('sitekey' => $this->publicKey), |
| 31 |
$this->form->getLanguage(), |
| 32 |
)); |
| 33 |
$field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES); |
| 34 |
// No input with the element name exists in the DOM (the widget POSTs g-recaptcha-response), |
| 35 |
// so expose the name here for the error JS label/anchor fallback. |
| 36 |
$field_name = htmlspecialchars($this->attributes["name"], ENT_QUOTES); |
| 37 |
echo <<<EOT |
| 38 |
<div id="{$field_id}" class="accua_forms_recaptcha2_container" data-accua-name="{$field_name}" style="min-height: 78px !important;"></div> |
| 39 |
<script type="text/javascript"> |
| 40 |
(window.accuaformRecaptcha2Queue = window.accuaformRecaptcha2Queue || []).push( $js_registration ); |
| 41 |
</script> |
| 42 |
EOT; |
| 43 |
} |
| 44 |
} |
| 45 |
|