PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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 / logout / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/logout/block.php

231 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Logout;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Alignment;
11 use ABlocks\Controls\Range;
12 use ABlocks\Controls\Border;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\TextShadow;
15 use ABlocks\Controls\TextStroke;
16
17
18 class Block extends BlockBaseAbstract {
19 protected $block_name = 'logout';
20
21 public function build_css( $attributes ) {
22
23 // Generate CSS start
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .ablocks-block-logout__label',
28 $this->get_log_out_label_color( $attributes )
29 );
30
31 $css_generator->add_class_styles(
32 '{{WRAPPER}} .ablocks-block-logout',
33 $this->get_log_out_css( $attributes ),
34 $this->get_log_out_css( $attributes, 'Tablet' ),
35 $this->get_log_out_css( $attributes, 'Mobile' )
36 );
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .ablocks-block-logout__name',
39 $this->get_name_css( $attributes ),
40 );
41
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .ablocks-block-logout__avatar',
44 $this->get_avatar_css( $attributes ),
45 $this->get_avatar_css( $attributes, 'Tablet' ),
46 $this->get_avatar_css( $attributes, 'Mobile' )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .ablocks-block-logout__avatar:hover',
50 $this->get_avatar_border_hover_css( $attributes ),
51 $this->get_avatar_border_hover_css( $attributes, 'Tablet' ),
52 $this->get_avatar_border_hover_css( $attributes, 'Mobile' )
53 );
54
55 return $css_generator->generate_css();
56 }
57
58
59 public function get_log_out_label_color( $attributes, $device = '' ) {
60 $log_out_label_color_css = [];
61 if ( ! empty( $attributes['logOutLabelColor'] ) ) {
62 $log_out_label_color_css['color'] = $attributes['logOutLabelColor'];
63 }
64 if ( ! empty( $attributes['logOutLabelBgColor'] ) ) {
65 $log_out_label_color_css['background'] = $attributes['logOutLabelBgColor'];
66 }
67
68 $typography = isset( $attributes['labelTypography'] ) ? $attributes['labelTypography'] : '';
69 $text_stroke = isset( $attributes['labelTextStroke'] ) ? $attributes['labelTextStroke'] : '';
70 $text_shadow = isset( $attributes['labelTextShadow'] ) ? $attributes['labelTextShadow'] : '';
71
72 return array_merge(
73 Typography::get_css( $typography, '', $device ),
74 TextStroke::get_css( $text_stroke, '', $device ),
75 TextShadow::get_css( $text_shadow, '', $device ),
76 $log_out_label_color_css
77 );
78 }
79
80 public function get_log_out_css( $attributes, $device = '' ) {
81 $log_out_css = [];
82
83 if ( ! empty( $attributes['logOutLabelBgColor'] ) ) {
84 $log_out_css ['background'] = $attributes['logOutLabelBgColor'];
85 }
86 if ( ! empty( $attributes['direction'][ 'value' . $device ] ) ) {
87 $log_out_css['flex-direction'] = $attributes['direction'][ 'value' . $device ];
88 }
89
90 if ( isset( $attributes['labelAlignment'][ 'value' . $device ] ) ) {
91 $log_out_css['justify-content'] = $attributes['labelAlignment'][ 'value' . $device ];
92 }
93
94 return $log_out_css;
95 }
96
97
98 public function get_avatar_css( $attributes, $device = '' ) {
99 $avatar_css = [];
100
101 if ( ! empty( $attributes['avatarWidth'][ 'value' . $device ] ) ) {
102 $width_value = $attributes['avatarWidth'][ 'value' . $device ];
103 $width_unit = $attributes['avatarWidth'][ 'valueUnit' . $device ] ?? 'px';
104 $avatar_css['width'] = $width_value . $width_unit;
105 }
106
107 if ( ! empty( $attributes['avatarHeight'][ 'value' . $device ] ) ) {
108 $height_value = $attributes['avatarHeight'][ 'value' . $device ];
109 $height_unit = ! empty( $attributes['avatarHeight'][ 'valueUnit' . $device ] )
110 ? $attributes['avatarHeight'][ 'valueUnit' . $device ]
111 : 'px';
112
113 $avatar_css['height'] = $height_value . $height_unit;
114 }
115
116 return array_merge(
117 Range::get_css([
118 'attributeValue' => $attributes['avatarWidth'],
119 'attribute_object_key' => 'value',
120 'isResponsive' => true,
121 'defaultValue' => 40,
122 'hasUnit' => true,
123 'unitDefaultValue' => 'px',
124 'property' => 'width',
125 'device' => $device,
126 ]),
127 Range::get_css([
128 'attributeValue' => $attributes['avatarHeight'],
129 'attribute_object_key' => 'value',
130 'isResponsive' => true,
131 'defaultValue' => 40,
132 'hasUnit' => true,
133 'unitDefaultValue' => 'px',
134 'property' => 'height',
135 'device' => $device,
136 ]),
137 isset( $attributes['avatarBorder'] ) ? Border::get_css( $attributes['avatarBorder'], '', $device ) : [],
138 $avatar_css,
139 );
140 }
141
142 public function get_avatar_border_hover_css( $attributes, $device = '' ) {
143 return array_merge(
144 isset( $attributes['avatarBorder'] ) ? Border::get_hover_css( $attributes['avatarBorder'], '', $device ) : []
145 );
146 }
147
148 public function get_name_css( $attributes, $device = '' ) {
149 $name_css = [];
150
151 if ( ! empty( $attributes['nameColor'] ) ) {
152 $name_css ['color'] = $attributes['nameColor'];
153 }
154 $typography = isset( $attributes['nameTypography'] ) ? $attributes['nameTypography'] : '';
155 $text_stroke = isset( $attributes['nameTextStroke'] ) ? $attributes['nameTextStroke'] : '';
156 $text_shadow = isset( $attributes['nameTextShadow'] ) ? $attributes['nameTextShadow'] : '';
157
158 return array_merge(
159 Typography::get_css( $typography, '', $device ),
160 TextStroke::get_css( $text_stroke, '', $device ),
161 TextShadow::get_css( $text_shadow, '', $device ),
162 $name_css
163 );
164 }
165
166
167
168 public function render_block_content( $attributes, $content, $block_instance ) {
169 $logout_redirect_option = isset( $attributes['logoutRedirect'] ) ? $attributes['logoutRedirect'] : 'current-url';
170
171 if ( $logout_redirect_option === 'current-url' ) {
172 $logout_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
173 } elseif ( $logout_redirect_option === 'custom-url' ) {
174 $logout_redirect_url = isset( $attributes['logoutCustomUrl'] ) && ! empty( $attributes['logoutCustomUrl'] )
175 ? esc_url( $attributes['logoutCustomUrl'] )
176 : home_url();
177 }
178
179 $login_redirect_option = isset( $attributes['loginRedirect'] ) ? $attributes['loginRedirect'] : 'current-url';
180
181 if ( $login_redirect_option === 'current-url' ) {
182 $login_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
183 } elseif ( $login_redirect_option === 'custom-url' ) {
184 $login_redirect_url = isset( $attributes['loginCustomUrl'] ) && ! empty( $attributes['loginCustomUrl'] )
185 ? esc_url( $attributes['loginCustomUrl'] )
186 : home_url();
187 }
188
189 $current_user = wp_get_current_user();
190 $profile_picture = get_avatar_url( $current_user->ID );
191 $display_name = $current_user->display_name;
192
193 $button_icon_url = isset( $attributes['buttonIconUrl'] ) && ! empty( $attributes['buttonIconUrl'] )
194 ? esc_url( $attributes['buttonIconUrl'] )
195 : '';
196
197 $button_class = isset( $attributes['buttonClass'] ) ? esc_attr( $attributes['buttonClass'] ) : 'ablocks-block-logout__label';
198 $is_logged_in = is_user_logged_in();
199 $is_show_avatar = isset( $attributes['isShowAvatar'] ) && $attributes['isShowAvatar'];
200 $is_show_name = isset( $attributes['isShowName'] ) && $attributes['isShowName'];
201
202 $button_text = $is_logged_in
203 ? ( isset( $attributes['logOutLabel'] ) ? esc_html( $attributes['logOutLabel'] ) : __( '(Log Out)', 'ablocks' ) )
204 : ( isset( $attributes['logInLabel'] ) ? esc_html( $attributes['logInLabel'] ) : __( '(Log In)', 'ablocks' ) );
205
206 $action_url = $is_logged_in ? wp_logout_url( $logout_redirect_url ) : wp_login_url( $login_redirect_url );
207
208 ob_start();
209 ?>
210 <div class="ablocks-block-logout">
211 <?php if ( $is_logged_in && $is_show_avatar ) : ?>
212 <img
213 src="<?php echo esc_url( $profile_picture ); ?>"
214 alt="<?php echo esc_attr( $display_name ); ?>"
215 class="ablocks-block-logout__avatar"
216 />
217 <?php endif; ?>
218 <?php if ( $is_logged_in && $is_show_name ) : ?>
219 <span class="ablocks-block-logout__name"><?php echo esc_html( $display_name ); ?></span>
220 <?php endif; ?>
221 <a href="<?php echo esc_url( $action_url ); ?>" class="<?php echo esc_attr( $button_class ); ?>">
222 (<span><?php echo esc_html( $button_text ); ?></span>)
223 </a>
224 </div>
225 <?php
226
227 return ob_get_clean();
228 }
229
230 }
231