PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.3.3
JetFormBuilder — Dynamic Blocks Form Builder v3.3.3
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
142 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 wp_enqueue_script(
92 $this->module()->get_handle( $this->get_id() ),
93 $this->module()->get_url( 'assets-build/js/hcaptcha/editor.js' ),
94 array(),
95 jet_form_builder()->get_version(),
96 true
97 );
98 }
99
100 public function register_frontend_scripts() {
101 $handle = $this->get_handle();
102
103 if ( wp_script_is( $handle, 'registered' ) ) {
104 return;
105 }
106
107 $captcha_url = esc_url_raw(
108 apply_filters(
109 'jet-form-builder/h-captcha/url',
110 'https://js.hcaptcha.com/1/api.js?onload=jfbHCaptchaOnLoad&render=explicit'
111 )
112 );
113
114 wp_register_script(
115 $handle,
116 $this->module()->get_url( 'assets-build/js/hcaptcha/frontend.js' ),
117 array( 'jet-plugins' ),
118 jet_form_builder()->get_version(),
119 true
120 );
121
122 wp_register_script(
123 $handle . '-api',
124 $captcha_url,
125 array( $handle ),
126 '1.0.0',
127 true
128 );
129 }
130
131 public function register_frontend_styles() {
132 wp_add_inline_style(
133 'jet-form-builder-frontend',
134 '
135 div[style*="z-index: 2147483647"] div[style*="border-width: 11px"][style*="position: absolute"][style*="pointer-events: none"] {
136 border-style: none;
137 }
138 '
139 );
140 }
141 }
142