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