| @@ -1,13 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('ABSPATH')){ | |
| 4 | - die('HACKING ATTEMPT!'); | |
| 3 | +// Get the client IP | |
| 4 | +function lz_getip(){ | |
| 5 | + if(isset($_SERVER["REMOTE_ADDR"])){ | |
| 6 | + return $_SERVER["REMOTE_ADDR"]; | |
| 7 | + }elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){ | |
| 8 | + return $_SERVER["HTTP_X_FORWARDED_FOR"]; | |
| 9 | + }elseif(isset($_SERVER["HTTP_CLIENT_IP"])){ | |
| 10 | + return $_SERVER["HTTP_CLIENT_IP"]; | |
| 11 | + } | |
| 5 | 12 | } |
| 6 | 13 | |
| 7 | -include_once(LOGINIZER_DIR.'/lib/IPv6/IPv6.php'); | |
| 8 | -include_once(LOGINIZER_DIR .'/common.php'); | |
| 9 | - | |
| 10 | 14 | // Execute a select query and return an array |
| 11 | 15 | function lz_selectquery($query, $array = 0){ |
| 12 | 16 | global $wpdb; |
| 13 | 17 | |
| @@ -19,8 +23,17 @@ | ||
| 19 | 23 | return $result; |
| 20 | 24 | } |
| 21 | 25 | } |
| 22 | 26 | |
| 27 | +// Check if an IP is valid | |
| 28 | +function lz_valid_ip($ip){ | |
| 29 | + | |
| 30 | + if(!ip2long($ip)){ | |
| 31 | + return false; | |
| 32 | + } | |
| 33 | + return true; | |
| 34 | +} | |
| 35 | + | |
| 23 | 36 | // Check if a field is posted via POST else return default value |
| 24 | 37 | function lz_optpost($name, $default = ''){ |
| 25 | 38 | |
| 26 | 39 | if(!empty($_POST[$name])){ |
| @@ -52,21 +65,15 @@ | ||
| 52 | 65 | |
| 53 | 66 | // For filling in posted values |
| 54 | 67 | function lz_POSTval($name, $default = ''){ |
| 55 | 68 | |
| 56 | - return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : esc_html($_POST[$name])) : $default); | |
| 69 | + return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : $_POST[$name]) : $default); | |
| 57 | 70 | |
| 58 | 71 | } |
| 59 | 72 | |
| 60 | -function lz_POSTchecked($name, $default = false, $submit_name = ''){ | |
| 73 | +function lz_POSTchecked($name, $default = false){ | |
| 61 | 74 | |
| 62 | - if(!empty($submit_name)){ | |
| 63 | - $post_to_check = isset($_POST[$submit_name]) ? $_POST[$submit_name] : ''; | |
| 64 | - }else{ | |
| 65 | - $post_to_check = $_POST; | |
| 66 | - } | |
| 67 | - | |
| 68 | - return (!empty($post_to_check) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : '')); | |
| 75 | + return (!empty($_POST) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : '')); | |
| 69 | 76 | |
| 70 | 77 | } |
| 71 | 78 | |
| 72 | 79 | function lz_POSTselect($name, $value, $default = false){ |
| @@ -84,18 +91,21 @@ | ||
| 84 | 91 | } |
| 85 | 92 | |
| 86 | 93 | } |
| 87 | 94 | |
| 88 | -function lz_POSTradio($name, $val, $default = null){ | |
| 89 | - | |
| 90 | - return (!empty($_POST) ? (@$_POST[$name] == $val ? 'checked="checked"' : '') : (!is_null($default) && $default == $val ? 'checked="checked"' : '')); | |
| 91 | - | |
| 92 | -} | |
| 93 | - | |
| 94 | 95 | function lz_inputsec($string){ |
| 95 | 96 | |
| 96 | - $string = addslashes($string); | |
| 97 | + if(!get_magic_quotes_gpc()){ | |
| 97 | 98 | |
| 99 | + $string = addslashes($string); | |
| 100 | + | |
| 101 | + }else{ | |
| 102 | + | |
| 103 | + $string = stripslashes($string); | |
| 104 | + $string = addslashes($string); | |
| 105 | + | |
| 106 | + } | |
| 107 | + | |
| 98 | 108 | // This is to replace ` which can cause the command to be executed in exec() |
| 99 | 109 | $string = str_replace('`', '\`', $string); |
| 100 | 110 | |
| 101 | 111 | return $string; |
| @@ -144,9 +154,9 @@ | ||
| 144 | 154 | if(empty($error)){ |
| 145 | 155 | return true; |
| 146 | 156 | } |
| 147 | 157 | |
| 148 | - $error_string = '<b>'.__('Please fix the below error(s)', 'loginizer').' :</b> <br />'; | |
| 158 | + $error_string = '<b>Please fix the below error(s) :</b> <br />'; | |
| 149 | 159 | |
| 150 | 160 | foreach($error as $ek => $ev){ |
| 151 | 161 | $error_string .= '* '.$ev.'<br />'; |
| 152 | 162 | } |
| @@ -151,9 +161,9 @@ | ||
| 151 | 161 | $error_string .= '* '.$ev.'<br />'; |
| 152 | 162 | } |
| 153 | 163 | |
| 154 | 164 | echo '<div id="message" class="error"><p>' |
| 155 | - . $error_string | |
| 165 | + . __($error_string, 'loginizer') | |
| 156 | 166 | . '</p></div>'; |
| 157 | 167 | } |
| 158 | 168 | |
| 159 | 169 | // Report a notice |
| @@ -171,9 +181,9 @@ | ||
| 171 | 181 | }else{ |
| 172 | 182 | $notice_class = 'updated'; |
| 173 | 183 | } |
| 174 | 184 | |
| 175 | - $notice_string = '<b>'.__('Please check the below notice(s)', 'loginizer').' :</b> <br />'; | |
| 185 | + $notice_string = '<b>Please check the below notice(s) :</b> <br />'; | |
| 176 | 186 | |
| 177 | 187 | foreach($notice as $ek => $ev){ |
| 178 | 188 | $notice_string .= '* '.$ev.'<br />'; |
| 179 | 189 | } |
| @@ -178,9 +188,9 @@ | ||
| 178 | 188 | $notice_string .= '* '.$ev.'<br />'; |
| 179 | 189 | } |
| 180 | 190 | |
| 181 | 191 | echo '<div id="message" class="'.$notice_class.'"><p>' |
| 182 | - . $notice_string | |
| 192 | + . __($notice_string, 'loginizer') | |
| 183 | 193 | . '</p></div>'; |
| 184 | 194 | } |
| 185 | 195 | |
| 186 | 196 | // Convert an objext to array |
| @@ -234,440 +244,5 @@ | ||
| 234 | 244 | } |
| 235 | 245 | return $randomString; |
| 236 | 246 | } |
| 237 | 247 | |
| 238 | -function lz_print($array){ | |
| 239 | 248 | |
| 240 | - echo '<pre>'; | |
| 241 | - print_r($array); | |
| 242 | - echo '</pre>'; | |
| 243 | - | |
| 244 | -} | |
| 245 | - | |
| 246 | -function lz_cleanpath($path){ | |
| 247 | - $path = str_replace('\\\\', '/', $path); | |
| 248 | - $path = str_replace('\\', '/', $path); | |
| 249 | - $path = str_replace('//', '/', $path); | |
| 250 | - return rtrim($path, '/'); | |
| 251 | -} | |
| 252 | - | |
| 253 | -// Returns the Numeric Value of results Per Page | |
| 254 | -function lz_get_page($get = 'page', $resperpage = 50){ | |
| 255 | - | |
| 256 | - $resperpage = (!empty($_REQUEST['reslen']) && is_numeric($_REQUEST['reslen']) ? (int) lz_optreq('reslen') : $resperpage); | |
| 257 | - | |
| 258 | - if(lz_optget($get)){ | |
| 259 | - $pg = (int) lz_optget($get); | |
| 260 | - $pg = $pg - 1; | |
| 261 | - $page = ($pg * $resperpage); | |
| 262 | - $page = ($page <= 0 ? 0 : $page); | |
| 263 | - }else{ | |
| 264 | - $page = 0; | |
| 265 | - } | |
| 266 | - return $page; | |
| 267 | -} | |
| 268 | - | |
| 269 | -// Replaces the Variables with the supplied ones | |
| 270 | -function lz_lang_vars_name($str, $array){ | |
| 271 | - | |
| 272 | - foreach($array as $k => $v){ | |
| 273 | - | |
| 274 | - $str = str_replace('$'.$k, $v, $str); | |
| 275 | - | |
| 276 | - } | |
| 277 | - | |
| 278 | - return $str; | |
| 279 | - | |
| 280 | -} | |
| 281 | - | |
| 282 | -// Check if Loginizer is premium | |
| 283 | -function loginizer_is_premium(){ | |
| 284 | - return defined('LOGINIZER_PREMIUM'); | |
| 285 | -} | |
| 286 | - | |
| 287 | -function loginizer_feature_available($feature = '', $return = 0){ | |
| 288 | - | |
| 289 | - if(loginizer_is_premium()){ | |
| 290 | - return true; | |
| 291 | - } | |
| 292 | - | |
| 293 | - $msg = ''; | |
| 294 | - | |
| 295 | - if(!empty($feature)){ | |
| 296 | - $msg .= '<b>'.$feature.'</b> is available in the Pro version of Loginizer. '; | |
| 297 | - } | |
| 298 | - | |
| 299 | - $msg .= '<a href="'.LOGINIZER_PRICING_URL.'" target="_blank" style="text-decoration:none; color:green;"><b>Upgrade to Pro</b></a>'; | |
| 300 | - | |
| 301 | - if(!empty($return)){ | |
| 302 | - return $msg; | |
| 303 | - }else{ | |
| 304 | - echo '<div style="color:#a94442; background-color:#f2dede; border-color:#ebccd1; padding:15px; margin-bottom:20px; border:1px solid transparent; border-radius:4px;">'.$msg.'</div>'; | |
| 305 | - } | |
| 306 | - | |
| 307 | -} | |
| 308 | - | |
| 309 | -// Checks if the email is valid | |
| 310 | -function lz_valid_email($email){ | |
| 311 | - | |
| 312 | - return filter_var($email, FILTER_VALIDATE_EMAIL); | |
| 313 | - | |
| 314 | -} | |
| 315 | - | |
| 316 | -function loginizer_blocked_page($lz_error){ | |
| 317 | - | |
| 318 | - // We are checking if this is a login page or not | |
| 319 | - if(false === stripos(wp_login_url(), $_SERVER['REQUEST_URI'])){ | |
| 320 | - return; | |
| 321 | - } | |
| 322 | - | |
| 323 | - echo '<!DOCTYPE html><html><head> | |
| 324 | - <meta name="robots" content="noindex, noarchive"> | |
| 325 | - <meta name="referrer" content="strict-origin-when-cross-origin"> | |
| 326 | - <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| 327 | - <title>'.__('You can not access this page', 'loginizer').'</title> | |
| 328 | - <style>html,body{height:100%} | |
| 329 | - .loginizer-blocked-wrapper{display:flex; align-items:center; justify-content:space-between; flex-direction:column; height:100%;} footer{border-top:1px solid #dadada; width:40vh; text-align:center;}</style> | |
| 330 | - </head> | |
| 331 | - <body style="font-family:sans-serif; font-size:calc(15px + 0.390625vw);margin:0;"> | |
| 332 | - <div class="loginizer-blocked-wrapper"> | |
| 333 | - <div style="margin-top:10em;"> | |
| 334 | - <h1 align="center">'.__('You can not access this page', 'loginizer').'</h1> | |
| 335 | - <p align="center">'.wp_kses_post(implode('', $lz_error)).'</p> | |
| 336 | - </div> | |
| 337 | - <footer>'; | |
| 338 | - if(!defined('LOGINIZER_PREMIUM')){ | |
| 339 | - echo '<p>Powered by Loginizer</p>'; | |
| 340 | - } else { | |
| 341 | - echo '<p>Powered by ' . esc_html(get_bloginfo('name')) . '</p>'; | |
| 342 | - } | |
| 343 | - | |
| 344 | - echo '</footer></div></body></html>'; | |
| 345 | - die(); | |
| 346 | -} | |
| 347 | - | |
| 348 | -function loginizer_social_css($position = 'below'){ | |
| 349 | - global $loginizer; | |
| 350 | - | |
| 351 | - // Starting the CSS | |
| 352 | - $css = '#lz-social-login-btns{display:none;max-width:350px;width:100%;box-sizing:border-box}.lz-social-login-btns-icon{flex-direction:row;flex-wrap:wrap;gap:8px}.lz-social-login-btns-full{flex-wrap:wrap;}.lz-social-top-padding{padding-top:20px}.lz-social-bottom-padding{padding-bottom:20px}.loginizer-social-button{display:flex;align-items:center;cursor:pointer;margin-bottom:10px;box-sizing:border-box;text-align:center;line-height:1;border:none;outline:none}.lz-social-button-icon{padding:0;width:40px;height:40px}.lz-social-button-icon-circle{border-radius:20px}.lz-social-button-icon-square{border-radius:3px}.lz-social-button-btn{padding:0 12px;width:100%;max-width:400px}.loginizer-social-button img{border-radius:2px;max-width:24px !important;}.loginizer-social-btn-logo{display:flex;padding:8px;align-items:center}.loginizer-social-btn-text{text-align:center;margin-left:15px;padding:10px 0;font-size:16px}'; | |
| 353 | - | |
| 354 | - // CSS for the divider with the text OR in the middle | |
| 355 | - if(!empty($loginizer['social_settings']) && ($position === 'below' || $position === 'above')){ | |
| 356 | - $css .= '.loginizer-social-divider{flex: 1 0 100%; font-size:17px; font-weight:700; margin-bottom:10px; display:flex;align-items:center}.loginizer-social-divider::after,.loginizer-social-divider::before{flex:1;content:"";padding:1px;background-color:#ececec;margin:5px}'; | |
| 357 | - } | |
| 358 | - | |
| 359 | - wp_register_style('loginizer-social', '', [], LOGINIZER_VERSION); | |
| 360 | - wp_enqueue_style('loginizer-social'); | |
| 361 | - wp_add_inline_style('loginizer-social', $css); | |
| 362 | -} | |
| 363 | - | |
| 364 | -// Echos the HTML of the Social button | |
| 365 | -function loginizer_social_btn($return = false, $page_type = 'login', $short_atts = []){ | |
| 366 | - global $loginizer, $loginizer_login_providers; | |
| 367 | - | |
| 368 | - // We don't want to give social login option to blacklisted IP's | |
| 369 | - if(loginizer_is_blacklisted() || !loginizer_can_login()){ | |
| 370 | - return; | |
| 371 | - } | |
| 372 | - | |
| 373 | - $provider_settings = get_option('loginizer_provider_settings', []); | |
| 374 | - $provider_order = get_option('loginizer_social_order', []); // in what order the icons are to be shown | |
| 375 | - | |
| 376 | - $providers = []; | |
| 377 | - | |
| 378 | - // Sorting according to the saved order of the providers. | |
| 379 | - if(!empty($provider_order)){ | |
| 380 | - foreach($provider_order as $key => $num){ | |
| 381 | - if(!empty($provider_settings[$key])){ | |
| 382 | - $providers[$key] = $provider_settings[$key]; | |
| 383 | - } | |
| 384 | - } | |
| 385 | - } else { | |
| 386 | - $providers = $provider_settings; | |
| 387 | - } | |
| 388 | - | |
| 389 | - if(empty($providers)){ | |
| 390 | - return; | |
| 391 | - } | |
| 392 | - | |
| 393 | - // ------ HTML STARTS HERE -------- // | |
| 394 | - | |
| 395 | - $style = 'icon'; | |
| 396 | - $shape = 'square'; | |
| 397 | - $position = 'below'; | |
| 398 | - if(!empty($loginizer['social_settings'])){ | |
| 399 | - $social_settings = $loginizer['social_settings']; | |
| 400 | - | |
| 401 | - // Setting Button Style | |
| 402 | - if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'full'){ | |
| 403 | - $style = 'full'; | |
| 404 | - } | |
| 405 | - | |
| 406 | - // Setting Button Shape | |
| 407 | - if(!empty($social_settings[$page_type]['button_shape']) && $social_settings[$page_type]['button_shape'] !== 'square'){ | |
| 408 | - $shape = $social_settings[$page_type]['button_shape']; | |
| 409 | - } | |
| 410 | - | |
| 411 | - // Setting position | |
| 412 | - if(!empty($social_settings[$page_type]['button_position']) && $social_settings[$page_type]['button_position'] !== 'below'){ | |
| 413 | - $position = $social_settings[$page_type]['button_position']; | |
| 414 | - } | |
| 415 | - } | |
| 416 | - | |
| 417 | - $container_alignment = isset($loginizer['social_settings'][$page_type]['alignment']) ? $loginizer['social_settings'][$page_type]['alignment'] : 'auto'; | |
| 418 | - $button_alignment = isset($loginizer['social_settings'][$page_type]['button_alignment']) ? $loginizer['social_settings'][$page_type]['button_alignment'] : 'center'; | |
| 419 | - | |
| 420 | - // Shortcode style | |
| 421 | - if(!empty($short_atts['type'])){ | |
| 422 | - $style = esc_html($short_atts['type']); | |
| 423 | - } | |
| 424 | - | |
| 425 | - // Shortcode Shape square or circle | |
| 426 | - if(!empty($short_atts['shape'])){ | |
| 427 | - $shape = esc_html($short_atts['shape']); | |
| 428 | - } | |
| 429 | - | |
| 430 | - // Shortcode for Container alignment | |
| 431 | - if(!empty($short_atts['container_alignment'])){ | |
| 432 | - $container_alignment = esc_html($short_atts['container_alignment']); | |
| 433 | - } | |
| 434 | - | |
| 435 | - // Shortcode for Button alignment | |
| 436 | - if(!empty($short_atts['button_alignment'])){ | |
| 437 | - $button_alignment = esc_html($short_atts['button_alignment']); | |
| 438 | - } | |
| 439 | - | |
| 440 | - // Setting divider position | |
| 441 | - $divider_pos = ''; | |
| 442 | - if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){ | |
| 443 | - $divider_pos = 'above'; | |
| 444 | - }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'below_plus'){ | |
| 445 | - $divider_pos = 'above'; | |
| 446 | - }elseif(!empty($short_atts['divider']) && $short_atts['divider'] == 'below'){ | |
| 447 | - $divider_pos = 'below'; | |
| 448 | - }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'above_plus'){ | |
| 449 | - $divider_pos = 'below'; | |
| 450 | - } | |
| 451 | - | |
| 452 | - loginizer_social_css($divider_pos); | |
| 453 | - | |
| 454 | - $padding = [ | |
| 455 | - 'above' => 'bottom', | |
| 456 | - 'below' => 'top' | |
| 457 | - ]; | |
| 458 | - | |
| 459 | - $social_buttons = '<div id="lz-social-login-btns" class="'.($style == 'icon' ? 'lz-social-login-btns-icon' : 'lz-social-login-btns-full').' '.($position == 'above' || $position == 'below' ? 'lz-social-'.$padding[$position].'-padding' : '').'" style="justify-self:'.esc_attr($container_alignment).'; justify-content:'.esc_attr($button_alignment).';">'; | |
| 460 | - | |
| 461 | - // HTML of the divider in case the buttons are below the login fields | |
| 462 | - if(!empty($divider_pos) && $divider_pos == 'above'){ | |
| 463 | - $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>'; | |
| 464 | - } | |
| 465 | - | |
| 466 | - include_once LOGINIZER_DIR . '/main/login-providers.php'; | |
| 467 | - | |
| 468 | - foreach($providers as $provider => $settings){ | |
| 469 | - if(empty($settings['enabled']) || empty($settings['tested'])){ | |
| 470 | - continue; | |
| 471 | - } | |
| 472 | - | |
| 473 | - // Filters Pro Only Auth | |
| 474 | - if(!empty($loginizer_login_providers[$provider]['premium']) && !defined('LOGINIZER_PREMIUM')){ | |
| 475 | - continue; | |
| 476 | - } | |
| 477 | - | |
| 478 | - $name = $loginizer_login_providers[$provider]['name']; | |
| 479 | - $color = $loginizer_login_providers[$provider]['color']; | |
| 480 | - | |
| 481 | - $btn_style = 'default'; | |
| 482 | - if(!empty($provider_settings[$provider]['button_style'])){ | |
| 483 | - $btn_style = $provider_settings[$provider]['button_style']; | |
| 484 | - } | |
| 485 | - | |
| 486 | - // TODO:: Improve the comment here | |
| 487 | - // The image is named based on button style as Facebook has different images for different style | |
| 488 | - // And if some more social options are added they could have the same behaviour too. | |
| 489 | - $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'.png'; | |
| 490 | - if('default' !== $btn_style){ | |
| 491 | - if(file_exists(LOGINIZER_DIR .'/assets/images/social/'.$provider.'-'.$btn_style.'.png')){ | |
| 492 | - $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png'; | |
| 493 | - } | |
| 494 | - } | |
| 495 | - | |
| 496 | - $social_buttons .= '<div class="loginizer-social-button '.($style == 'icon' ? 'lz-social-button-icon' : 'lz-social-button-btn').' '.($shape == 'circle' ? 'lz-social-button-icon-circle' : 'lz-social-button-icon-square').'" onclick="loginizer_auth_popup(\''.esc_js($provider).'\', '.esc_js(!empty($settings['loginizer_social_key']) ? true : 0).')" style="'.((!empty($loginizer_login_providers[$provider]['styles']) && !empty($loginizer_login_providers[$provider]['styles'][$btn_style])) ? esc_attr($loginizer_login_providers[$provider]['styles'][$btn_style]) : esc_attr('background-color:'. esc_attr($color)). '; color:#FFF;') .'"> | |
| 497 | - <div class="loginizer-social-btn-logo"> | |
| 498 | - <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/> | |
| 499 | - </div>'; | |
| 500 | - | |
| 501 | - // Button text in case of full button | |
| 502 | - if(!empty($loginizer['social_settings']) && $style === 'full'){ | |
| 503 | - $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html__('Login With', 'loginizer').' <strong>'.esc_html($name).'</strong> | |
| 504 | - </div>'; | |
| 505 | - } | |
| 506 | - | |
| 507 | - $social_buttons .= '</div>'; | |
| 508 | - } | |
| 509 | - | |
| 510 | - if(empty($social_buttons)){ | |
| 511 | - $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer'); | |
| 512 | - } | |
| 513 | - | |
| 514 | - // HTML of the divider in case the buttons are above the login fields | |
| 515 | - if(!empty($divider_pos) && $divider_pos == 'below'){ | |
| 516 | - $social_buttons .= '<br><div class="loginizer-social-divider">OR</div>'; | |
| 517 | - } | |
| 518 | - | |
| 519 | - $social_buttons .= '</div>'; | |
| 520 | - loginizer_add_social_js($page_type); | |
| 521 | - | |
| 522 | - if($return){ | |
| 523 | - return $social_buttons; | |
| 524 | - } | |
| 525 | - | |
| 526 | - echo wp_kses($social_buttons, [ | |
| 527 | - 'div' => ['class' => true, 'id' => true, 'style' => true, 'onclick' => true], | |
| 528 | - 'img' => ['src' => true, 'height' => true, 'alt' => true, 'width' => true], | |
| 529 | - 'strong' => true, | |
| 530 | - ]); | |
| 531 | -} | |
| 532 | - | |
| 533 | -function loginizer_add_social_js($page_type){ | |
| 534 | - global $loginizer; | |
| 535 | - | |
| 536 | - if(wp_script_is('loginizer-social-js') || loginizer_is_blacklisted() || !empty($loginizer['social_script_added'])){ | |
| 537 | - return; | |
| 538 | - } | |
| 539 | - | |
| 540 | - $loginizer['social_script_added'] = false; | |
| 541 | - $func = 'append'; | |
| 542 | - if(!empty($loginizer['social_settings']) && !empty($loginizer['social_settings'][$page_type]['button_position']) && strpos($loginizer['social_settings'][$page_type]['button_position'], 'above') !== FALSE){ | |
| 543 | - $func = 'prepend'; | |
| 544 | - } | |
| 545 | - | |
| 546 | - $target_window = 'same'; | |
| 547 | - if(isset($_GET['interim-login']) && $_GET['interim-login'] == 1){ | |
| 548 | - $target_window = 'popup'; | |
| 549 | - } elseif(!empty($loginizer['social_settings']['general']['target_window'])){ | |
| 550 | - $target_window = $loginizer['social_settings']['general']['target_window']; | |
| 551 | - } | |
| 552 | - | |
| 553 | - $social_nonce = wp_create_nonce('loginizer_social_check'); | |
| 554 | - | |
| 555 | - wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]); | |
| 556 | - wp_enqueue_script('loginizer-social-js'); | |
| 557 | - wp_add_inline_script('loginizer-social-js', ' | |
| 558 | - | |
| 559 | - | |
| 560 | - | |
| 561 | - let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"), | |
| 562 | - lz_social_btns = document.querySelectorAll("#lz-social-login-btns"), | |
| 563 | - lz_target_window = "'.esc_html($target_window).'", | |
| 564 | - lz_is_interim = "'.(!empty($_GET['interim-login']) ? '&interim-login=0' : '').'"; // as for interim it should only open a popup | |
| 565 | - | |
| 566 | - if(lz_target_window == "same"){ | |
| 567 | - let loader = "<style>#loginizer-social-loader-wrap{display:none; align-items:center; justify-content:center; position:fixed; top:0; left:0; width:100%; height:100vh; background-color:rgba(0, 0, 0, 0.2);} .loginizer-social-loader{width:48px;height:48px;border:5px solid #fff;border-bottom-color:transparent;border-radius:50%;display:inline-block;box-sizing:border-box;animation:1s linear infinite rotation}@keyframes rotation{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style>"; | |
| 568 | - loader += "<div id=\"loginizer-social-loader-wrap\"><div class=\"loginizer-social-loader\"></div></div>"; | |
| 569 | - | |
| 570 | - jQuery("body").append(loader); | |
| 571 | - } | |
| 572 | - | |
| 573 | - | |
| 574 | - lz_social_btns.forEach((btns) => { | |
| 575 | - btns.style.display="flex"; | |
| 576 | - }); | |
| 577 | - | |
| 578 | - if(lz_form.length > 0){ | |
| 579 | - lz_form.forEach((form, index) => { | |
| 580 | - if (lz_social_btns[index]) { | |
| 581 | - lz_social_btns[index].style.display="flex"; | |
| 582 | - form.'.esc_html($func).'(lz_social_btns[index]); | |
| 583 | - } | |
| 584 | - }); | |
| 585 | - } | |
| 586 | - | |
| 587 | - function loginizer_auth_popup(provider, isAPI) { | |
| 588 | - let target_url = "'.esc_url(wp_login_url()).'?social_security='.esc_html($social_nonce).'&lz_social_provider=" + provider+lz_is_interim; | |
| 589 | - | |
| 590 | - if(isAPI){ | |
| 591 | - target_url += "&lz_api=1"; | |
| 592 | - } | |
| 593 | - | |
| 594 | - let redirect_to = "'.(!empty($_GET['redirect_to']) ? wp_validate_redirect(esc_url($_GET['redirect_to'])) : '') .'"; | |
| 595 | - | |
| 596 | - if(redirect_to.length){ | |
| 597 | - target_url += "&ref="+redirect_to; | |
| 598 | - } else { | |
| 599 | - target_url += "&ref='.esc_url((is_ssl() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']).'" | |
| 600 | - } | |
| 601 | - | |
| 602 | - if(lz_target_window == "same"){ | |
| 603 | - jQuery("#loginizer-social-loader-wrap").css("display", "flex"); | |
| 604 | - | |
| 605 | - window.location.href = target_url; | |
| 606 | - | |
| 607 | - return; | |
| 608 | - } | |
| 609 | - | |
| 610 | - let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft, | |
| 611 | - screen_y = window.screenY !== undefined ? window.screenY : window.screenTop, | |
| 612 | - outer_width = window.outerWidth !== undefined ? window.outerWidth : document.documentElement.clientWidth, | |
| 613 | - outer_height = window.outerHeight !== undefined ? window.outerHeight : document.documentElement.clientHeight - 22, | |
| 614 | - target_width = 600, | |
| 615 | - target_height = 600, | |
| 616 | - right = parseInt(screen_y + (outerHeight - target_height) / 2.5, 10), | |
| 617 | - left = parseInt(screen_x + (outerWidth - target_width) / 2, 10), | |
| 618 | - attributes = []; | |
| 619 | - | |
| 620 | - if(target_width !== null){ | |
| 621 | - attributes.push("width=" + target_width); | |
| 622 | - } | |
| 623 | - if(target_height !== null){ | |
| 624 | - attributes.push("height=" + target_height); | |
| 625 | - } | |
| 626 | - attributes.push("left=" + left); | |
| 627 | - attributes.push("top=" + right); | |
| 628 | - attributes.push("scrollbars=1"); | |
| 629 | - | |
| 630 | - var auth_window = window.open(target_url, "authWindow", attributes.join(",")); | |
| 631 | - | |
| 632 | - if(window.focus){ | |
| 633 | - auth_window.focus(); | |
| 634 | - } | |
| 635 | - return false; | |
| 636 | - }' | |
| 637 | - ); | |
| 638 | - | |
| 639 | - $loginizer['social_script_added'] = true; | |
| 640 | - | |
| 641 | -} | |
| 642 | - | |
| 643 | -function loginizer_social_btn_login($return = false, $id = ''){ | |
| 644 | - loginizer_social_btn($return, 'login'); | |
| 645 | -} | |
| 646 | - | |
| 647 | -function loginizer_get_social_error(){ | |
| 648 | - global $loginizer; | |
| 649 | - | |
| 650 | - // If we already have the error set | |
| 651 | - if(!empty($loginizer['social_errors'])){ | |
| 652 | - return; | |
| 653 | - } | |
| 654 | - | |
| 655 | - if(empty($_COOKIE) || empty($_COOKIE['lz_social_error'])){ | |
| 656 | - return; | |
| 657 | - } | |
| 658 | - | |
| 659 | - $error_identifier = sanitize_text_field(wp_unslash($_COOKIE['lz_social_error'])); | |
| 660 | - $social_errors = get_site_transient($error_identifier); | |
| 661 | - | |
| 662 | - if(empty($social_errors['errors'])){ | |
| 663 | - return; | |
| 664 | - } | |
| 665 | - | |
| 666 | - // Setting error data | |
| 667 | - $loginizer['retries_left'] = $social_errors['retries_left']; | |
| 668 | - $loginizer['social_errors'] = $social_errors['errors']; | |
| 669 | - | |
| 670 | - // Cleaning the error data | |
| 671 | - delete_site_transient($error_identifier); // Deleting the data | |
| 672 | - //setcookie('lz_social_error', '', time() - 300, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); // have to delete | |
| 673 | -} | |