PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / storeengine-login-form / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/storeengine-login-form/block.php

253 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\StoreengineLoginForm;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Background;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Color;
17
18
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'storeengine-login-form';
21
22 public function __construct() {
23 parent::__construct();
24
25 add_filter( 'storeengine/shortcode/login_form_is_user_logged_in', [
26 $this,
27 'force_showing_login_form_in_editor'
28 ] );
29
30 }
31
32 public function force_showing_login_form_in_editor( $flag ) {
33 if ( Helper::is_gutenberg_editor() ) {
34 return false;
35 }
36
37 return $flag;
38 }
39
40 public function build_css( $attributes ) {
41 $css_generator = new CssGenerator( $attributes );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .storeengine-login-form-heading',
44 $this->get_form_title_css( $attributes ),
45 $this->get_form_title_css( $attributes, 'Tablet' ),
46 $this->get_form_title_css( $attributes, 'Mobile' )
47 );
48
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .storeengine-login-form-heading:hover',
51 $this->form_title_desktop_hover_css( $attributes )
52 );
53
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form .storeengine-form-group
56 label',
57 $this->get_input_field_label_css( $attributes ),
58 $this->get_input_field_label_css( $attributes, 'Tablet' ),
59 $this->get_input_field_label_css( $attributes, 'Mobile' )
60 );
61
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form .storeengine-form-group
64 label:hover',
65 $this->get_input_field_label_hover_css( $attributes ),
66 $this->get_input_field_label_hover_css( $attributes, 'Tablet' ),
67 $this->get_input_field_label_hover_css( $attributes, 'Mobile' )
68 );
69
70 $css_generator->add_class_styles(
71 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form .storeengine-form-group input',
72 $this->get_input_field_css( $attributes ),
73 $this->get_input_field_css( $attributes, 'Tablet' ),
74 $this->get_input_field_css( $attributes, 'Mobile' )
75 );
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form .storeengine-form-group input:hover',
78 $this->get_input_field_hover_css( $attributes ),
79 $this->get_input_field_hover_css( $attributes, 'Tablet' ),
80 $this->get_input_field_hover_css( $attributes, 'Mobile' )
81 );
82
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form .storeengine-form-group input::placeholder',
85 $this->get_input_field_placeholder_css( $attributes ),
86 $this->get_input_field_placeholder_css( $attributes, 'Tablet' ),
87 $this->get_input_field_placeholder_css( $attributes, 'Mobile' )
88 );
89
90 $css_generator->add_class_styles(
91 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-form-group button',
92 $this->get_login_form_button_css( $attributes ),
93 $this->get_login_form_button_css( $attributes, 'Tablet' ),
94 $this->get_login_form_button_css( $attributes, 'Mobile' )
95 );
96
97 $css_generator->add_class_styles(
98 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-form-group button:hover',
99 $this->get_login_btn_hover_css( $attributes ),
100 $this->get_login_btn_hover_css( $attributes, 'Tablet' ),
101 $this->get_login_btn_hover_css( $attributes, 'Mobile' )
102 );
103 $css_generator->add_class_styles(
104 '{{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form-info p,
105 {{WRAPPER}} .storeengine-login-form-wrapper .storeengine-login-form-info p a ',
106 $this->get_login_form_footer_css( $attributes ),
107 $this->get_login_form_footer_css( $attributes, 'Tablet' ),
108 $this->get_login_form_footer_css( $attributes, 'Mobile' )
109 );
110
111 $css_generator->add_class_styles(
112 '{{WRAPPER}} .storeengine-login-form-wrapper',
113 $this->get_form_card_css( $attributes ),
114 $this->get_form_card_css( $attributes, 'Tablet' ),
115 $this->get_form_card_css( $attributes, 'Mobile' )
116 );
117
118 $css_generator->add_class_styles(
119 '{{WRAPPER}} .storeengine-login-form-wrapper:hover',
120 $this->get_form_card_hover_css( $attributes ),
121 $this->get_form_card_hover_css( $attributes, 'Tablet' ),
122 $this->get_form_card_hover_css( $attributes, 'Mobile' )
123 );
124
125 return $css_generator->generate_css();
126 }
127
128 public function get_form_title_css( $attributes, $device = '' ) {
129 $form_title_typography_css = ! empty( $attributes['title_typography'] ) ? $attributes['title_typography'] : [];
130 $typographyGlobal = ( isset( $attributes['title_typographyGlobal'] ) ? $attributes['title_typographyGlobal'] : '' );
131 return array_merge(
132 [ 'color' => Color::get_css( isset( $attributes['title_color'] ) ? $attributes['title_color'] : '' ) ],
133 Typography::get_css( $form_title_typography_css, '', $device, $typographyGlobal ),
134 );
135 }
136
137 public function get_input_field_label_css( $attributes, $device = '' ) {
138 $input_field_label_typography_css = ! empty( $attributes['input_field_label_typography'] ) ? $attributes['input_field_label_typography'] : [];
139 $typographyGlobal = ( isset( $attributes['input_field_label_typographyGlobal'] ) ? $attributes['input_field_label_typographyGlobal'] : '' );
140
141 return array_merge(
142 [ 'color' => Color::get_css( isset( $attributes['input_field_label_color'] ) ? $attributes['input_field_label_color'] : '' ) ],
143 Typography::get_css( $input_field_label_typography_css, '', $device, $typographyGlobal ),
144 );
145 }
146
147 public function get_input_field_label_hover_css( $attributes, $device = '' ) {
148 return [ 'color' => Color::get_css( isset( $attributes['input_field_label_hover_color'] ) ? $attributes['input_field_label_hover_color'] : '' ) ];
149 }
150
151 public function get_input_field_css( $attributes, $device = '' ) {
152 $input_border_css = ! empty( $attributes['input_field_border'] ) ? Border::get_css( $attributes['input_field_border'], '', $device ) : array();
153 $input_field_padding = ! empty( $attributes['input_field_padding'] ) ? Dimensions::get_css( $attributes['input_field_padding'], 'padding', $device ) : array();
154
155 return array_merge(
156 [ 'color' => Color::get_css( isset( $attributes['inputFieldColor'] ) ? $attributes['inputFieldColor'] : '' ) ],
157 [ 'background' => Color::get_css( isset( $attributes['input_field_bg_color'] ) ? $attributes['input_field_bg_color'] : '' ) ],
158 $input_border_css,
159 $input_field_padding
160 );
161 }
162
163 public function get_input_field_hover_css( $attributes, $device = '' ) {
164 return array_merge(
165 [ 'color' => Color::get_css( isset( $attributes['inputFieldColorH'] ) ? $attributes['inputFieldColorH'] : '' ) ],
166 [ 'background' => Color::get_css( isset( $attributes['input_field_bg_hover_color'] ) ? $attributes['input_field_bg_hover_color'] : '' ) ],
167 );
168 }
169
170
171 public function get_input_field_placeholder_css( $attributes, $device = '' ) {
172 return [ 'color' => Color::get_css( isset( $attributes['inputFieldColor'] ) ? $attributes['inputFieldColor'] : '' ) ];
173 }
174
175
176 public function get_login_form_button_css( $attributes, $device = '' ) {
177 $login_form_button_typography_css = ! empty( $attributes['login_btn_typography'] ) ? $attributes['login_btn_typography'] : [];
178 $typographyGlobal = ( isset( $attributes['login_btn_typographyGlobal'] ) ? $attributes['login_btn_typographyGlobal'] : '' );
179 return array_merge(
180 Typography::get_css( $login_form_button_typography_css, '', $device, $typographyGlobal ),
181 [ 'background' => Color::get_css( isset( $attributes['login_btn_bg_color'] ) ? $attributes['login_btn_bg_color'] : '' ) ],
182 [ 'color' => Color::get_css( isset( $attributes['login_btn_color'] ) ? $attributes['login_btn_color'] : '' ) ],
183 );
184 }
185
186 public function get_login_btn_hover_css( $attributes, $device = '' ) {
187 return array_merge(
188 [ 'color' => Color::get_css( isset( $attributes['login_btn_hover_color'] ) ? $attributes['login_btn_hover_color'] : '' ) ],
189 [ 'background' => Color::get_css( isset( $attributes['login_btn_bg_hover_color'] ) ? $attributes['login_btn_bg_hover_color'] : '' ) ],
190 );
191 }
192
193 public function get_login_form_footer_css( $attributes, $device = '' ) {
194 $login_form_footer_typography_css = ! empty( $attributes['form_footer_title_typography'] ) ? $attributes['form_footer_title_typography'] : [];
195 $typographyGlobal = ( isset( $attributes['form_footer_title_typographyGlobal'] ) ? $attributes['form_footer_title_typographyGlobal'] : '' );
196
197 return array_merge(
198 [ 'color' => Color::get_css( isset( $attributes['form_footer_title_color'] ) ? $attributes['form_footer_title_color'] : '' ) ],
199 // $login_form_footer_typography_css
200 Typography::get_css( $login_form_footer_typography_css, '', $device, $typographyGlobal ),
201 );
202 }
203
204 public function get_form_card_css( $attributes, $device = '' ) {
205 $form_background_css = ! empty( $attributes['form_bg_color'] ) ? Background::get_css( $attributes['form_bg_color'], 'background', $device ) : array();
206 $form_border = ! empty( $attributes['form_border'] ) ? Border::get_css( $attributes['form_border'], '', $device ) : array();
207 $form_padding = ! empty( $attributes['form_padding'] ) ? Dimensions::get_css( $attributes['form_padding'], 'padding', $device ) : array();
208
209 return array_merge(
210 $form_background_css,
211 $form_border,
212 $form_padding
213 );
214 }
215
216 public function get_form_card_hover_css( $attributes, $device = '' ) {
217 $form_background_hover_css = ! empty( $attributes['form_bg_color'] ) ? Background::get_hover_css( $attributes['form_bg_color'], 'background', $device ) : array();
218
219 return $form_background_hover_css;
220 }
221 public function form_title_desktop_hover_css( $attributes, $device = '' ) {
222
223 return [ 'color' => Color::get_css( isset( $attributes['title_hover_color'] ) ? $attributes['title_hover_color'] : '' ) ];
224 }
225
226 public function render_block_content( $attributes, $content, $block_instance ) {
227 $attr_array = [
228 'form_title' => Helper::get_attribute_value( $attributes, 'form_title' ),
229 'username_label' => Helper::get_attribute_value( $attributes, 'username_label' ),
230 'username_placeholder' => Helper::get_attribute_value( $attributes, 'username_placeholder' ),
231 'password_label' => Helper::get_attribute_value( $attributes, 'password_label' ),
232 'password_placeholder' => Helper::get_attribute_value( $attributes, 'password_placeholder' ),
233 'remember_label' => Helper::get_attribute_value( $attributes, 'remember_label' ),
234 'login_button_label' => Helper::get_attribute_value( $attributes, 'login_button_label' ),
235 'reset_password_label' => Helper::get_attribute_value( $attributes, 'reset_password_label' ),
236 'show_logged_in_message' => Helper::get_attribute_value( $attributes, 'show_logged_in_message' ),
237 'register_url' => Helper::get_attribute_value( $attributes, 'register_url' ),
238 'login_redirect_url' => Helper::get_attribute_value( $attributes, 'login_redirect_url' ),
239 'logout_redirect_url' => Helper::get_attribute_value( $attributes, 'logout_redirect_url' ),
240 ];
241 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
242 if ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) ) {
243 add_filter( 'storeengine/shortcode/login_form_is_user_logged_in', function () {
244 return false;
245 } );
246 }
247
248 $shortcode = '[storeengine_login_form ' . Helper::attr_shortcode( $attr_array ) . ']';
249 echo do_shortcode( $shortcode );
250 }
251
252 }
253