PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.7
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.7
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
sureforms / inc / fields / inlinebutton-markup.php
inlinebutton-markup.php
231 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms Inline Button Markup Class file.
4 *
5 * @package sureforms.
6 * @since 0.0.1
7 */
8
9 namespace SRFM\Inc\Fields;
10
11 use SRFM\Inc\Helper;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Sureforms Inline Button Markup Class.
19 *
20 * @since 0.0.2
21 */
22 class Inlinebutton_Markup extends Base {
23
24 /**
25 * Text displayed on the button.
26 *
27 * @var string
28 * @since 0.0.2
29 */
30 protected $button_text;
31
32 /**
33 * Button style inherited from the theme.
34 *
35 * @var string
36 * @since 0.0.2
37 */
38 protected $btn_from_theme;
39
40 /**
41 * Used as a flag which decides whether page break is added.
42 *
43 * @var bool
44 * @since 0.0.2
45 */
46 protected $is_page_break;
47
48 /**
49 * Version of reCAPTCHA to use.
50 *
51 * @var string
52 * @since 0.0.2
53 */
54 protected $recaptcha_version;
55
56 /**
57 * Site key for Google reCAPTCHA.
58 *
59 * @var string
60 * @since 0.0.2
61 */
62 protected $google_captcha_site_key;
63
64 /**
65 * Global setting options for security settings.
66 *
67 * @var array<mixed>|mixed
68 * @since 0.0.2
69 */
70 protected $global_setting_options;
71
72 /**
73 * Flag indicating if padding should be added to the button.
74 *
75 * @var bool
76 * @since 0.0.2
77 */
78 protected $add_button_padding;
79
80 /**
81 * Security type.
82 *
83 * @var string
84 * @since 0.0.5
85 */
86 protected $captcha_security_type;
87
88 /**
89 * Cloudflare Turnstile site key.
90 *
91 * @var string
92 * @since 0.0.5
93 */
94 protected $cf_turnstile_site_key;
95
96 /**
97 * Cloudflare Turnstile appearance mode
98 *
99 * @var string
100 * @since 0.0.5
101 */
102 protected $cf_appearance_mode;
103
104 /**
105 * Security - hCaptcha site key.
106 *
107 * @var string
108 * @since 0.0.5
109 */
110 protected $hcaptcha_site_key;
111
112 /**
113 * Initialize the properties based on block attributes.
114 *
115 * @param array<mixed> $attributes Block attributes.
116 * @since 0.0.2
117 */
118 public function __construct( $attributes ) {
119 $this->set_properties( $attributes );
120 $this->slug = 'inline-button';
121 $this->button_text = isset( $attributes['buttonText'] ) ? $attributes['buttonText'] : '';
122 $this->btn_from_theme = Helper::get_meta_value( $this->form_id, '_srfm_inherit_theme_button' );
123 $this->is_page_break = defined( 'SRFM_PRO_VER' ) && Helper::get_meta_value( $this->form_id, '_srfm_is_page_break' );
124 $this->captcha_security_type = Helper::get_meta_value( $this->form_id, '_srfm_captcha_security_type' );
125 $this->recaptcha_version = Helper::get_meta_value( $this->form_id, '_srfm_form_recaptcha' );
126 $this->google_captcha_site_key = '';
127 $this->global_setting_options = [];
128 if ( 'none' !== $this->captcha_security_type ) {
129 $this->global_setting_options = get_option( 'srfm_security_settings_options' );
130 }
131
132 if ( is_array( $this->global_setting_options ) ) {
133 switch ( $this->recaptcha_version ) {
134 case 'v2-checkbox':
135 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_checkbox_site_key'] ) ? $this->global_setting_options['srfm_v2_checkbox_site_key'] : '';
136 break;
137 case 'v2-invisible':
138 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_invisible_site_key'] ) ? $this->global_setting_options['srfm_v2_invisible_site_key'] : '';
139 break;
140 case 'v3-reCAPTCHA':
141 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v3_site_key'] ) ? $this->global_setting_options['srfm_v3_site_key'] : '';
142 break;
143 default:
144 break;
145 }
146 if ( 'cf-turnstile' === $this->captcha_security_type ) {
147 $this->cf_turnstile_site_key = isset( $this->global_setting_options['srfm_cf_turnstile_site_key'] ) ? $this->global_setting_options['srfm_cf_turnstile_site_key'] : '';
148 $this->cf_appearance_mode = isset( $this->global_setting_options['srfm_cf_appearance_mode'] ) ? $this->global_setting_options['srfm_cf_appearance_mode'] : 'auto';
149 }
150 if ( 'hcaptcha' === $this->captcha_security_type ) {
151 $this->hcaptcha_site_key = isset( $this->global_setting_options['srfm_hcaptcha_site_key'] ) ? $this->global_setting_options['srfm_hcaptcha_site_key'] : '';
152 }
153 }
154 $theme_name = wp_get_theme()->get( 'Name' );
155 $this->add_button_padding = true;
156 if ( 'Astra' === $theme_name || 'Blocksy' === $theme_name ) {
157 $this->add_button_padding = false;
158 }
159 }
160
161 /**
162 * Render inline button markup
163 *
164 * @since 0.0.2
165 * @return string|boolean|void
166 */
167 public function markup() {
168 ob_start(); ?>
169 <?php if ( ! $this->is_page_break ) : ?>
170 <?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) : ?>
171 <div class="srfm-captcha-container">
172 <?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) : ?>
173 <?php echo "<div class='g-recaptcha' data-callback='onSuccess' recaptcha-type='" . esc_attr( $this->recaptcha_version ) . "' data-sitekey='" . esc_attr( strval( $this->google_captcha_site_key ) ) . "'></div>"; ?>
174 <?php endif; ?>
175 <?php if ( 'cf-turnstile' === $this->captcha_security_type && $this->cf_turnstile_site_key ) : ?>
176 <?php echo "<div id='srfm-cf-sitekey' class='cf-turnstile' data-callback='onSuccess' data-theme='" . esc_attr( strval( $this->cf_appearance_mode ) ) . "' data-sitekey='" . esc_attr( strval( $this->cf_turnstile_site_key ) ) . "'></div>"; ?>
177 <?php endif; ?>
178 <?php if ( 'hcaptcha' === $this->captcha_security_type && $this->hcaptcha_site_key ) : ?>
179 <?php echo "<div id='srfm-hcaptcha-sitekey' data-callback='onSuccess' class='h-captcha' data-sitekey='" . esc_attr( strval( $this->hcaptcha_site_key ) ) . "'></div>"; ?>
180 <?php endif; ?>
181 <div class="srfm-validation-error" id="captcha-error" style="display: none;"><?php echo esc_attr__( 'Please verify that you are not a robot.', 'sureforms' ); ?></div>
182 </div>
183 <?php endif; ?>
184 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?> srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo esc_attr( $this->block_width ); ?> srfm-block srfm-custom-button-ctn <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button' : '' ); ?>">
185 <?php
186 if ( 'g-recaptcha' === $this->captcha_security_type ) :
187 if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) :
188 wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . esc_js( $this->google_captcha_site_key ), [], SRFM_VER, true );
189 endif;
190
191 if ( 'v2-checkbox' === $this->recaptcha_version ) :
192 wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true );
193 endif;
194
195 if ( 'v2-invisible' === $this->recaptcha_version ) :
196 wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true );
197 endif;
198 endif;
199
200 if ( 'cf-turnstile' === $this->captcha_security_type ) :
201 // Cloudflare Turnstile script.
202 wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
203 SRFM_SLUG . '-cf-turnstile',
204 'https://challenges.cloudflare.com/turnstile/v0/api.js',
205 [],
206 null,
207 [
208 false,
209 'defer' => true,
210 ]
211 );
212 endif;
213 if ( 'hcaptcha' === $this->captcha_security_type ) :
214 wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
215 endif;
216 ?>
217 <button style="<?php echo $this->btn_from_theme ? '' : ' font-family: inherit; font-weight: var(--wp--custom--font-weight--medium); line-height: normal;'; ?>width:100%;" id="srfm-submit-btn" class="<?php echo esc_attr( 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? 'g-recaptcha ' : '' ); ?> <?php echo esc_attr( '1' === $this->btn_from_theme ? 'wp-block-button__link' : 'srfm-button srfm-submit-button srfm-btn-frontend srfm-custom-button' ); ?> " <?php echo 'v2-invisible' === $this->recaptcha_version || 'v3-reCAPTCHA' === $this->recaptcha_version ? esc_attr( 'recaptcha-type=' . $this->recaptcha_version . ' data-sitekey=' . $this->google_captcha_site_key ) : ''; ?>>
218 <div class="srfm-submit-wrap">
219 <?php echo esc_html( $this->button_text ); ?>
220 <div class="srfm-loader"></div>
221 </div>
222 </button>
223 <div class="srfm-error-wrap"></div>
224 </div>
225 <?php
226 endif;
227 return ob_get_clean();
228 }
229
230 }
231