PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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 1 year ago verify-token-action.php 1 year ago
hcaptcha.php
152 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\Captcha\Module;
12 use JFB_Modules\Security\Exceptions\Spam_Exception;
13
14 class Hcaptcha extends Base_Captcha_From_Options implements
15 Captcha_Separate_Frontend_Script,
16 Captcha_Separate_Editor_Script,
17 Captcha_Frontend_Style_It {
18
19 public function get_id(): string {
20 return 'hcaptcha';
21 }
22
23 public function get_title(): string {
24 return __( 'hCaptcha', 'jet-form-builder' );
25 }
26
27 public function verify( array $request ) {
28 $action = ( new Verify_Token_Action() )
29 ->set_secret( $this->options['secret'] ?? '' )
30 ->set_token( $request[ self::FIELD ] ?? '' )
31 ->set_action( jet_fb_live()->form_id );
32
33 try {
34 $action->send_request();
35 } catch ( Gateway_Exception $exception ) {
36 throw new Spam_Exception(
37 Module::SPAM_EXCEPTION, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
38 $exception->getMessage(), // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
39 ...$exception->get_additional() // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
40 );
41 }
42 }
43
44 /**
45 * @return string
46 */
47 public function render(): string {
48 $captcha_args = apply_filters(
49 'jet-form-builder/h-captcha/options',
50 array(
51 'sitekey' => $this->options['key'] ?? '',
52 )
53 );
54
55 if ( empty( $captcha_args['sitekey'] ) ) {
56 return '';
57 }
58
59 $handle = $this->get_handle( '-api' );
60 wp_enqueue_script( $handle );
61
62 /**
63 * In some themes, the "the_content" filter may be executed before the "wp_enqueue_scripts" action.
64 * Therefore, we should make sure that our script is registered before adding an inline script.
65 */
66 $this->register_frontend_scripts();
67 $this->module()->add_inline_config( $captcha_args, $handle );
68
69 return sprintf(
70 '<div class="jet-form-builder-row captcha-token-container" data-validation-type="inherit">
71 <input type="hidden" class="%1$s" name="%2$s" value="" data-jfb-sync required="required">
72 </div>',
73 self::FIELD_CLASS,
74 self::FIELD
75 );
76 }
77
78 public function on_save_options( array $post_request ): array {
79 // phpcs:disable WordPress.Security.NonceVerification.Missing
80 $secret = sanitize_text_field( $post_request['secret'] ?? '' );
81 $key = sanitize_text_field( $post_request['key'] ?? '' );
82
83 // phpcs:enable WordPress.Security.NonceVerification.Missing
84
85 return array(
86 'secret' => $secret,
87 'key' => $key,
88 );
89 }
90
91 public function enqueue_editor_script() {
92 $script_asset = require_once $this->module()->get_dir( 'assets/build/hcaptcha/editor.asset.php' );
93
94 wp_enqueue_script(
95 $this->module()->get_handle( $this->get_id() ),
96 $this->module()->get_url( 'assets/build/hcaptcha/editor.js' ),
97 $script_asset['dependencies'],
98 $script_asset['version'],
99 true
100 );
101 }
102
103 public function register_frontend_scripts() {
104 $handle = $this->get_handle();
105 $script_asset = require_once $this->module()->get_dir( 'assets/build/hcaptcha/frontend.asset.php' );
106
107 // scripts have already registered
108 if ( true === $script_asset ) {
109 return;
110 }
111
112 $captcha_url = esc_url_raw(
113 apply_filters(
114 'jet-form-builder/h-captcha/url',
115 'https://js.hcaptcha.com/1/api.js?onload=jfbHCaptchaOnLoad&render=explicit'
116 )
117 );
118
119 array_push(
120 $script_asset['dependencies'],
121 'jet-plugins'
122 );
123
124 wp_register_script(
125 $handle,
126 $this->module()->get_url( 'assets/build/hcaptcha/frontend.js' ),
127 $script_asset['dependencies'],
128 $script_asset['version'],
129 true
130 );
131
132 wp_register_script(
133 $handle . '-api',
134 $captcha_url,
135 array( $handle ),
136 '1.0.0',
137 true
138 );
139 }
140
141 public function register_frontend_styles() {
142 wp_add_inline_style(
143 'jet-form-builder-frontend',
144 '
145 div[style*="z-index: 2147483647"] div[style*="border-width: 11px"][style*="position: absolute"][style*="pointer-events: none"] {
146 border-style: none;
147 }
148 '
149 );
150 }
151 }
152