| 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 string |
| 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 |
* Initialize the properties based on block attributes. |
| 82 |
* |
| 83 |
* @param array<mixed> $attributes Block attributes. |
| 84 |
* @since 0.0.2 |
| 85 |
*/ |
| 86 |
public function __construct( $attributes ) { |
| 87 |
$this->set_properties( $attributes ); |
| 88 |
$this->slug = 'inline-button'; |
| 89 |
$this->button_text = isset( $attributes['buttonText'] ) ? $attributes['buttonText'] : ''; |
| 90 |
$this->btn_from_theme = Helper::get_meta_value( $this->form_id, '_srfm_inherit_theme_button' ); |
| 91 |
$this->is_page_break = Helper::get_meta_value( $this->form_id, '_srfm_is_page_break' ); |
| 92 |
$this->recaptcha_version = Helper::get_meta_value( $this->form_id, '_srfm_form_recaptcha' ); |
| 93 |
$this->google_captcha_site_key = ''; |
| 94 |
$this->global_setting_options = []; |
| 95 |
if ( 'none' !== $this->recaptcha_version ) { |
| 96 |
$this->global_setting_options = get_option( 'srfm_security_settings_options' ); |
| 97 |
} |
| 98 |
|
| 99 |
if ( is_array( $this->global_setting_options ) ) { |
| 100 |
switch ( $this->recaptcha_version ) { |
| 101 |
case 'v2-checkbox': |
| 102 |
$this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_checkbox_site_key'] ) ? $this->global_setting_options['srfm_v2_checkbox_site_key'] : ''; |
| 103 |
break; |
| 104 |
case 'v2-invisible': |
| 105 |
$this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v2_invisible_site_key'] ) ? $this->global_setting_options['srfm_v2_invisible_site_key'] : ''; |
| 106 |
break; |
| 107 |
case 'v3-reCAPTCHA': |
| 108 |
$this->google_captcha_site_key = isset( $this->global_setting_options['srfm_v3_site_key'] ) ? $this->global_setting_options['srfm_v3_site_key'] : ''; |
| 109 |
break; |
| 110 |
default: |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
$theme_name = wp_get_theme()->get( 'Name' ); |
| 115 |
$this->add_button_padding = true; |
| 116 |
if ( 'Astra' === $theme_name || 'Blocksy' === $theme_name ) { |
| 117 |
$this->add_button_padding = false; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Render inline button markup |
| 123 |
* |
| 124 |
* @since 0.0.2 |
| 125 |
* @return string|boolean|void |
| 126 |
*/ |
| 127 |
public function markup() { |
| 128 |
ob_start(); ?> |
| 129 |
<?php if ( '1' !== $this->is_page_break ) : ?> |
| 130 |
<?php if ( 'v2-checkbox' === $this->recaptcha_version ) : ?> |
| 131 |
<?php echo "<div class='g-recaptcha' data-sitekey='" . esc_attr( strval( $this->google_captcha_site_key ) ) . "'></div>"; ?> |
| 132 |
<?php endif; ?> |
| 133 |
<div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" style="padding: 0 .3em; " 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' : '' ); ?>"> |
| 134 |
<?php echo wp_kses_post( Helper::generate_common_form_markup( $this->form_id, 'label', '', '', '', false ) ); ?> |
| 135 |
<?php |
| 136 |
if ( 'v3-reCAPTCHA' === $this->recaptcha_version ) : |
| 137 |
wp_enqueue_script( 'srfm-google-recaptchaV3', 'https://www.google.com/recaptcha/api.js?render=' . esc_js( $this->google_captcha_site_key ), [], SRFM_VER, true ); |
| 138 |
endif; |
| 139 |
|
| 140 |
if ( 'v2-checkbox' === $this->recaptcha_version ) : |
| 141 |
wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true ); |
| 142 |
endif; |
| 143 |
|
| 144 |
if ( 'v2-invisible' === $this->recaptcha_version ) : |
| 145 |
wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true ); |
| 146 |
endif; |
| 147 |
?> |
| 148 |
<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-butto srfm-submit-button srfm-btn-bg-color 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 ) : ''; ?>> |
| 149 |
<div class="srfm-submit-wrap"> |
| 150 |
<?php echo esc_html( $this->button_text ); ?> |
| 151 |
<div class="srfm-loader"></div> |
| 152 |
</div> |
| 153 |
</button> |
| 154 |
</div> |
| 155 |
<?php |
| 156 |
endif; |
| 157 |
return ob_get_clean(); |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|