PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.2
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 in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 1.0.2, at inc/fields/inlinebutton-markup.php

233 lines 8.8 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 $page_break_settings = defined( 'SRFM_PRO_VER' ) ? get_post_meta( (int) $this->form_id, '_srfm_page_break_settings', true ) : [];
124 $page_break_settings = is_array( $page_break_settings ) ? $page_break_settings : [];
125 $this->is_page_break = isset( $page_break_settings['is_page_break'] ) ? $page_break_settings['is_page_break'] : false;
126 $this->captcha_security_type = Helper::get_meta_value( $this->form_id, '_srfm_captcha_security_type' );
127 $this->recaptcha_version = Helper::get_meta_value( $this->form_id, '_srfm_form_recaptcha' );
128 $this->google_captcha_site_key = '';
129 $this->global_setting_options = [];
130 if ( 'none' !== $this->captcha_security_type ) {
131 $this->global_setting_options = get_option( 'srfm_security_settings_options' );
132 }
133
134 if ( is_array( $this->global_setting_options ) ) {
135 switch ( $this->recaptcha_version ) {
136 case 'v2-checkbox':
137 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_checkbox_site_key'] ) ? $this->global_setting_options['srfm_v2_checkbox_site_key'] : '';
138 break;
139 case 'v2-invisible':
140 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_invisible_site_key'] ) ? $this->global_setting_options['srfm_v2_invisible_site_key'] : '';
141 break;
142 case 'v3-reCAPTCHA':
143 $this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v3_site_key'] ) ? $this->global_setting_options['srfm_v3_site_key'] : '';
144 break;
145 default:
146 break;
147 }
148 if ( 'cf-turnstile' === $this->captcha_security_type ) {
149 $this->cf_turnstile_site_key = isset( $this->global_setting_options['srfm_cf_turnstile_site_key'] ) ? $this->global_setting_options['srfm_cf_turnstile_site_key'] : '';
150 $this->cf_appearance_mode = isset( $this->global_setting_options['srfm_cf_appearance_mode'] ) ? $this->global_setting_options['srfm_cf_appearance_mode'] : 'auto';
151 }
152 if ( 'hcaptcha' === $this->captcha_security_type ) {
153 $this->hcaptcha_site_key = isset( $this->global_setting_options['srfm_hcaptcha_site_key'] ) ? $this->global_setting_options['srfm_hcaptcha_site_key'] : '';
154 }
155 }
156 $theme_name = wp_get_theme()->get( 'Name' );
157 $this->add_button_padding = true;
158 if ( 'Astra' === $theme_name || 'Blocksy' === $theme_name ) {
159 $this->add_button_padding = false;
160 }
161 }
162
163 /**
164 * Render inline button markup
165 *
166 * @since 0.0.2
167 * @return string|boolean|void
168 */
169 public function markup() {
170 ob_start(); ?>
171 <?php if ( ! $this->is_page_break ) : ?>
172 <?php if ( $this->captcha_security_type && 'none' !== $this->captcha_security_type ) : ?>
173 <div class="srfm-captcha-container <?php echo esc_attr( 'v3-reCAPTCHA' === $this->recaptcha_version || 'v2-invisible' === $this->recaptcha_version ? 'srfm-display-none' : '' ); ?>">
174 <?php if ( 'g-recaptcha' === $this->captcha_security_type && 'v2-checkbox' === $this->recaptcha_version ) : ?>
175 <?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>"; ?>
176 <?php endif; ?>
177 <?php if ( 'cf-turnstile' === $this->captcha_security_type && $this->cf_turnstile_site_key ) : ?>
178 <?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>"; ?>
179 <?php endif; ?>
180 <?php if ( 'hcaptcha' === $this->captcha_security_type && $this->hcaptcha_site_key ) : ?>
181 <?php echo "<div id='srfm-hcaptcha-sitekey' data-callback='onSuccess' class='h-captcha' data-sitekey='" . esc_attr( strval( $this->hcaptcha_site_key ) ) . "'></div>"; ?>
182 <?php endif; ?>
183 <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>
184 </div>
185 <?php endif; ?>
186 <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' : '' ); ?>">
187 <?php
188 if ( 'g-recaptcha' === $this->captcha_security_type ) :
189 if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) :
190 wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . esc_js( $this->google_captcha_site_key ), [], SRFM_VER, true );
191 endif;
192
193 if ( 'v2-checkbox' === $this->recaptcha_version ) :
194 wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true );
195 endif;
196
197 if ( 'v2-invisible' === $this->recaptcha_version ) :
198 wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true );
199 endif;
200 endif;
201
202 if ( 'cf-turnstile' === $this->captcha_security_type ) :
203 // Cloudflare Turnstile script.
204 wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
205 SRFM_SLUG . '-cf-turnstile',
206 'https://challenges.cloudflare.com/turnstile/v0/api.js',
207 [],
208 null,
209 [
210 false,
211 'defer' => true,
212 ]
213 );
214 endif;
215 if ( 'hcaptcha' === $this->captcha_security_type ) :
216 wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
217 endif;
218 ?>
219 <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 ) : ''; ?>>
220 <div class="srfm-submit-wrap">
221 <?php echo esc_html( $this->button_text ); ?>
222 <div class="srfm-loader"></div>
223 </div>
224 </button>
225 <div class="srfm-error-wrap"></div>
226 </div>
227 <?php
228 endif;
229 return ob_get_clean();
230 }
231
232 }
233