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