PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.2
JetFormBuilder — Dynamic Blocks Form Builder v3.4.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / captcha / hcaptcha / hcaptcha.php
jetformbuilder / modules / captcha / hcaptcha Last commit date
hcaptcha.php 2 years ago verify-token-action.php 2 years ago
hcaptcha.php
151 lines
1 <?php
2
3
4 namespace JFB_Modules\Captcha\Hcaptcha;
5
6 use Jet_Form_Builder\Exceptions\Gateway_Exception;
7 use JFB_Modules\Captcha\Abstract_Captcha\Base_Captcha_From_Options;
8 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Frontend_Style_It;
9 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Separate_Editor_Script;
10 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Separate_Frontend_Script;
11 use JFB_Modules\Security\Exceptions\Spam_Exception;
12
13 class Hcaptcha extends Base_Captcha_From_Options implements
14 Captcha_Separate_Frontend_Script,
15 Captcha_Separate_Editor_Script,
16 Captcha_Frontend_Style_It {
17
18 public function get_id(): string {
19 return 'hcaptcha';
20 }
21
22 public function get_title(): string {
23 return __( 'hCaptcha', 'jet-form-builder' );
24 }
25
26 public function verify( array $request ) {
27 $action = ( new Verify_Token_Action() )
28 ->set_secret( $this->options['secret'] ?? '' )
29 ->set_token( $request[ self::FIELD ] ?? '' )
30 ->set_action( jet_fb_live()->form_id );
31
32 try {
33 $action->send_request();
34 } catch ( Gateway_Exception $exception ) {
35 throw new Spam_Exception(
36 'captcha_failed',
37 $exception->getMessage(), // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
38 ...$exception->get_additional() // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
39 );
40 }
41 }
42
43 /**
44 * @return string
45 */
46 public function render(): string {
47 $captcha_args = apply_filters(
48 'jet-form-builder/h-captcha/options',
49 array(
50 'sitekey' => $this->options['key'] ?? '',
51 )
52 );
53
54 if ( empty( $captcha_args['sitekey'] ) ) {
55 return '';
56 }
57
58 $handle = $this->get_handle( '-api' );
59 wp_enqueue_script( $handle );
60
61 /**
62 * In some themes, the "the_content" filter may be executed before the "wp_enqueue_scripts" action.
63 * Therefore, we should make sure that our script is registered before adding an inline script.
64 */
65 $this->register_frontend_scripts();
66 $this->module()->add_inline_config( $captcha_args, $handle );
67
68 return sprintf(
69 '<div class="jet-form-builder-row captcha-token-container" data-validation-type="inherit">
70 <input type="hidden" class="%1$s" name="%2$s" value="" data-jfb-sync required="required">
71 </div>',
72 self::FIELD_CLASS,
73 self::FIELD
74 );
75 }
76
77 public function on_save_options( array $post_request ): array {
78 // phpcs:disable WordPress.Security.NonceVerification.Missing
79 $secret = sanitize_text_field( $post_request['secret'] ?? '' );
80 $key = sanitize_text_field( $post_request['key'] ?? '' );
81
82 // phpcs:enable WordPress.Security.NonceVerification.Missing
83
84 return array(
85 'secret' => $secret,
86 'key' => $key,
87 );
88 }
89
90 public function enqueue_editor_script() {
91 $script_asset = require_once $this->module()->get_dir( 'assets/build/hcaptcha/editor.asset.php' );
92
93 wp_enqueue_script(
94 $this->module()->get_handle( $this->get_id() ),
95 $this->module()->get_url( 'assets/build/hcaptcha/editor.js' ),
96 $script_asset['dependencies'],
97 $script_asset['version'],
98 true
99 );
100 }
101
102 public function register_frontend_scripts() {
103 $handle = $this->get_handle();
104 $script_asset = require_once $this->module()->get_dir( 'assets/build/hcaptcha/frontend.asset.php' );
105
106 // scripts have already registered
107 if ( true === $script_asset ) {
108 return;
109 }
110
111 $captcha_url = esc_url_raw(
112 apply_filters(
113 'jet-form-builder/h-captcha/url',
114 'https://js.hcaptcha.com/1/api.js?onload=jfbHCaptchaOnLoad&render=explicit'
115 )
116 );
117
118 array_push(
119 $script_asset['dependencies'],
120 'jet-plugins'
121 );
122
123 wp_register_script(
124 $handle,
125 $this->module()->get_url( 'assets/build/hcaptcha/frontend.js' ),
126 $script_asset['dependencies'],
127 $script_asset['version'],
128 true
129 );
130
131 wp_register_script(
132 $handle . '-api',
133 $captcha_url,
134 array( $handle ),
135 '1.0.0',
136 true
137 );
138 }
139
140 public function register_frontend_styles() {
141 wp_add_inline_style(
142 'jet-form-builder-frontend',
143 '
144 div[style*="z-index: 2147483647"] div[style*="border-width: 11px"][style*="position: absolute"][style*="pointer-events: none"] {
145 border-style: none;
146 }
147 '
148 );
149 }
150 }
151