PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.2
JetFormBuilder — Dynamic Blocks Form Builder v3.1.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 / friendly-captcha / friendly-captcha.php
jetformbuilder / modules / captcha / friendly-captcha Last commit date
friendly-captcha.php 2 years ago verify-token-action.php 2 years ago
friendly-captcha.php
119 lines
1 <?php
2
3
4 namespace JFB_Modules\Captcha\Friendly_Captcha;
5
6 use Jet_Form_Builder\Blocks\Validation;
7 use Jet_Form_Builder\Exceptions\Gateway_Exception;
8 use Jet_Form_Builder\Exceptions\Repository_Exception;
9 use JFB_Modules\Captcha\Abstract_Captcha\Base_Captcha;
10 use JFB_Modules\Captcha\Abstract_Captcha\Base_Captcha_From_Options;
11 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Separate_Editor_Script;
12 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Separate_Frontend_Script;
13 use JFB_Modules\Captcha\Module;
14 use JFB_Modules\Security\Exceptions\Spam_Exception;
15
16 class Friendly_Captcha extends Base_Captcha_From_Options implements
17 Captcha_Separate_Frontend_Script,
18 Captcha_Separate_Editor_Script {
19
20 public function get_id(): string {
21 return 'friendly';
22 }
23
24 public function get_title(): string {
25 return __( 'Friendly Captcha', 'jet-form-builder' );
26 }
27
28 public function verify( array $request ) {
29 $action = ( new Verify_Token_Action() )
30 ->set_secret( $this->options['secret'] ?? '' )
31 ->set_site_key( $this->options['key'] ?? '' )
32 ->set_solution( $request[ self::FIELD ] ?? '' );
33
34 try {
35 $action->send_request();
36 } catch ( Gateway_Exception $exception ) {
37 throw new Spam_Exception(
38 'captcha_failed',
39 $exception->getMessage(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
40 ...$exception->get_additional() // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
41 );
42 }
43 }
44
45 /**
46 * @return string
47 */
48 public function render(): string {
49 $captcha_args = apply_filters(
50 'jet-form-builder/friendly-captcha/options',
51 array(
52 'sitekey' => $this->options['key'] ?? '',
53 )
54 );
55
56 if ( empty( $captcha_args['sitekey'] ) ) {
57 return '';
58 }
59
60 $handle = $this->get_handle();
61 wp_enqueue_script( $handle );
62
63 /**
64 * In some themes, the "the_content" filter may be executed before the "wp_enqueue_scripts" action.
65 * Therefore, we should make sure that our script is registered before adding an inline script.
66 */
67 $this->register_frontend_scripts();
68 $this->module()->add_inline_config( $captcha_args, $handle );
69
70 return sprintf(
71 '<div class="jet-form-builder-row captcha-token-container" data-validation-type="inherit">
72 <input type="hidden" class="%1$s" name="%2$s" value="" data-jfb-sync required="required">
73 <div class="captcha-token-container--inner"></div>
74 </div>',
75 self::FIELD_CLASS,
76 self::FIELD
77 );
78 }
79
80 public function on_save_options( array $post_request ): array {
81 // phpcs:disable WordPress.Security.NonceVerification.Missing
82 $secret = sanitize_text_field( $post_request['secret'] ?? '' );
83 $key = sanitize_text_field( $post_request['key'] ?? '' );
84
85 // phpcs:enable WordPress.Security.NonceVerification.Missing
86
87 return array(
88 'secret' => $secret,
89 'key' => $key,
90 );
91 }
92
93 public function enqueue_editor_script() {
94 wp_enqueue_script(
95 $this->get_handle(),
96 $this->module()->get_url( 'assets-build/js/friendly.captcha/editor.js' ),
97 array(),
98 jet_form_builder()->get_version(),
99 true
100 );
101 }
102
103 public function register_frontend_scripts() {
104 $handle = $this->get_handle();
105
106 if ( wp_script_is( $handle, 'registered' ) ) {
107 return;
108 }
109
110 wp_register_script(
111 $handle,
112 $this->module()->get_url( 'assets-build/js/friendly.captcha/frontend.js' ),
113 array( 'jet-plugins' ),
114 jet_form_builder()->get_version(),
115 true
116 );
117 }
118 }
119