PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.2.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.2.1
3.6.4.1 3.6.4 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 1 month ago verify-token-action.php 1 month ago
friendly-captcha.php
128 lines
1 <?php
2
3
4 namespace JFB_Modules\Captcha\Friendly_Captcha;
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_Separate_Editor_Script;
9 use JFB_Modules\Captcha\Abstract_Captcha\Captcha_Separate_Frontend_Script;
10 use JFB_Modules\Captcha\Module;
11 use JFB_Modules\Security\Exceptions\Spam_Exception;
12
13 class Friendly_Captcha extends Base_Captcha_From_Options implements
14 Captcha_Separate_Frontend_Script,
15 Captcha_Separate_Editor_Script {
16
17 public function get_id(): string {
18 return 'friendly';
19 }
20
21 public function get_title(): string {
22 return __( 'Friendly Captcha', 'jet-form-builder' );
23 }
24
25 public function verify( array $request ) {
26 $action = ( new Verify_Token_Action() )
27 ->set_secret( $this->options['secret'] ?? '' )
28 ->set_site_key( $this->options['key'] ?? '' )
29 ->set_solution( $request[ self::FIELD ] ?? '' );
30
31 try {
32 $action->send_request();
33 } catch ( Gateway_Exception $exception ) {
34 throw new Spam_Exception(
35 Module::SPAM_EXCEPTION, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
36 $exception->getMessage(), // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
37 ...$exception->get_additional() // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
38 );
39 }
40 }
41
42 /**
43 * @return string
44 */
45 public function render(): string {
46 $captcha_args = apply_filters(
47 'jet-form-builder/friendly-captcha/options',
48 array(
49 'sitekey' => $this->options['key'] ?? '',
50 )
51 );
52
53 if ( empty( $captcha_args['sitekey'] ) ) {
54 return '';
55 }
56
57 $handle = $this->get_handle();
58 wp_enqueue_script( $handle );
59
60 /**
61 * In some themes, the "the_content" filter may be executed before the "wp_enqueue_scripts" action.
62 * Therefore, we should make sure that our script is registered before adding an inline script.
63 */
64 $this->register_frontend_scripts();
65 $this->module()->add_inline_config( $captcha_args, $handle );
66
67 return sprintf(
68 '<div class="jet-form-builder-row captcha-token-container" data-validation-type="inherit">
69 <input type="hidden" class="%1$s" name="%2$s" value="" data-jfb-sync required="required">
70 <div class="captcha-token-container--inner"></div>
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/friendly.captcha/editor.asset.php' );
92
93 if ( true === $script_asset ) {
94 return;
95 }
96
97 wp_enqueue_script(
98 $this->get_handle(),
99 $this->module()->get_url( 'assets/build/friendly.captcha/editor.js' ),
100 $script_asset['dependencies'],
101 $script_asset['version'],
102 true
103 );
104 }
105
106 public function register_frontend_scripts() {
107 $script_asset = require_once $this->module()->get_dir( 'assets/build/friendly.captcha/frontend.asset.php' );
108
109 // scripts have already registered
110 if ( true === $script_asset ) {
111 return;
112 }
113
114 array_push(
115 $script_asset['dependencies'],
116 'jet-plugins'
117 );
118
119 wp_register_script(
120 $this->get_handle(),
121 $this->module()->get_url( 'assets/build/friendly.captcha/frontend.js' ),
122 $script_asset['dependencies'],
123 $script_asset['version'],
124 true
125 );
126 }
127 }
128