PluginProbe
Contact Forms by Cimatti / 2.2.0
Contact Forms by Cimatti v2.2.0
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / classes / Element / Captcha2.php

Captcha2.php in Contact Forms by Cimatti 2.2.0, at classes/Element/Captcha2.php

62 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
7 public function __construct($label = "", $unused = null, array $properties = null) {
8 if ($properties === null && is_array($unused)) {
9 $properties = $unused;
10 }
11 parent::__construct($label, "recaptcha_response_field", $properties);
12 $validator = new AccuaForm_Validation_Captcha2b(__("The reCAPTCHA response provided was incorrect. Please retry.", 'contact-forms'));
13 $validator->configure(array('privateKey'=>$this->privateKey));
14 $this->setValidation($validator);
15 }
16
17 public function render() {
18 $js_lang = _accua_forms_json_encode($this->form->getLanguage());
19 $js_field_id = _accua_forms_json_encode($this->attributes["id"]);//$this->form->attributes['id'] per id del form
20 $js_publicKey = _accua_forms_json_encode($this->publicKey);
21 $js_path = _accua_forms_json_encode(ACCUA_FORMS_DIR_URL . 'assets/js/frontend/recaptcha2.js');
22
23 $field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES);
24 echo <<<EOT
25 <script type="text/javascript">
26 <!--
27 if (typeof(accuaform_recaptcha2_ajax_loaded) == "undefined" || !accuaform_recaptcha2_ajax_loaded) {
28 var accuaform_recaptcha2_ajax_loaded = true;
29 var accuaform_recaptcha2_ajax_delaying = true;
30 var accuaform_recaptcha2_ajax_loading = true ;
31 var accuaform_recaptcha2_ajax_controller = jQuery({});
32 var accuaform_recaptcha2_ajax_initialized = {};
33 jQuery(".accuaforms-field-required, .pfbc-fieldwrap > *").one('change', function() {
34 if(accuaform_recaptcha2_ajax_delaying){
35 accuaform_recaptcha2_ajax_delaying = false;
36 jQuery.getScript( $js_path , function(){
37 jQuery.getScript( "https://www.recaptcha.net/recaptcha/api.js?onload=accua_forms_onload_recaptcha2&render=explicit&hl=" + $js_lang );
38 accuaform_recaptcha2_ajax_loading = false;
39 accuaform_recaptcha2_ajax_controller.trigger('loaded');
40 });
41 }
42 });
43 }
44 if (!accuaform_recaptcha2_ajax_initialized[ $js_field_id ]) {
45 accuaform_recaptcha2_ajax_initialized[ $js_field_id ] = true;
46 jQuery(function(){
47 if (accuaform_recaptcha2_ajax_loading) {
48 accuaform_recaptcha2_ajax_controller.one('loaded', function(){
49 accua_forms_show_recaptcha2( $js_field_id , { sitekey: $js_publicKey });
50 })
51 } else {
52 accua_forms_show_recaptcha2( $js_field_id , { sitekey: $js_publicKey });
53 }
54 });
55 }
56 // -->
57 </script>
58 <div id="{$field_id}" class="accua_forms_recaptcha2_container" style="min-height: 78px !important;"></div>
59 EOT;
60 }
61 }
62