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