PluginProbe
Contact Forms by Cimatti / 2.3.6
Contact Forms by Cimatti v2.3.6
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 / Cap.php

Cap.php in Contact Forms by Cimatti 2.3.6, at classes/Element/Cap.php

77 lines 3.3 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_Cap extends Element {
4 protected $instanceUrl = "";
5 protected $siteKey = "";
6 protected $secretKey = "";
7
8 public function __construct($label = "", $unused = null, ?array $properties = null) {
9 if ($properties === null && is_array($unused)) {
10 $properties = $unused;
11 }
12 parent::__construct($label, "accua-forms-cap-response", $properties);
13 $validator = new AccuaForm_Validation_Cap(__("Captcha verification failed. Please retry.", 'contact-forms'));
14 $validator->configure(array('instanceUrl' => $this->instanceUrl, 'siteKey' => $this->siteKey, 'secretKey' => $this->secretKey));
15 $this->setValidation($validator);
16 }
17
18 public function render() {
19 wp_enqueue_script(
20 'accua-forms-cap',
21 ACCUA_FORMS_DIR_URL . 'assets/js/frontend/cap.js',
22 array('jquery'),
23 ACCUA_FORMS_JS_VERSION,
24 true
25 );
26
27 $instance_url = trailingslashit($this->instanceUrl);
28
29 /**
30 * Filter the URL the Cap widget script is loaded from.
31 *
32 * Defaults to the assets server of the configured Cap Standalone instance
33 * (requires ENABLE_ASSETS_SERVER=true on the instance).
34 *
35 * @param string $widget_url URL of the cap-widget script.
36 * @param string $instance_url The configured Cap instance URL.
37 */
38 $widget_url = apply_filters('accua_forms_cap_widget_url', $instance_url . 'assets/widget.js', $this->instanceUrl);
39
40 /**
41 * Filter the URL of the WASM solver loaded by the Cap widget.
42 *
43 * @param string $wasm_url URL of the Cap WASM binary.
44 * @param string $instance_url The configured Cap instance URL.
45 */
46 $wasm_url = apply_filters('accua_forms_cap_wasm_url', $instance_url . 'assets/cap_wasm_bg.wasm', $this->instanceUrl);
47
48 $js_registration = _accua_forms_json_encode(array(
49 $this->attributes["id"],
50 array(
51 'endpoint' => $instance_url . rawurlencode($this->siteKey) . '/',
52 'widgetUrl' => $widget_url,
53 'wasmUrl' => $wasm_url,
54 'i18n' => array(
55 /* translators: Label shown on the Cap captcha widget before verification */
56 'initial-state' => __("I'm a human", 'contact-forms'),
57 /* translators: Label shown on the Cap captcha widget while verifying */
58 'verifying-label' => __('Verifying…', 'contact-forms'),
59 /* translators: Label shown on the Cap captcha widget after verification */
60 'solved-label' => __('Verified', 'contact-forms'),
61 /* translators: Label shown on the Cap captcha widget on error */
62 'error-label' => __('Verification failed. Try again.', 'contact-forms'),
63 ),
64 ),
65 $this->form ? $this->form->getLanguage() : '',
66 ));
67 $field_id = htmlspecialchars($this->attributes["id"], ENT_QUOTES);
68 echo <<<EOT
69 <input type="hidden" name="accua-forms-cap-response" id="{$field_id}" class="accua_forms_cap_input" value="" />
70 <div id="{$field_id}-widget" class="accua_forms_cap_container"></div>
71 <script type="text/javascript">
72 (window.accuaformCapQueue = window.accuaformCapQueue || []).push( $js_registration );
73 </script>
74 EOT;
75 }
76 }
77