PluginProbe
Loginizer / 2.0.6
Loginizer v2.0.6
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
← All changes | functions.php +55 -111 1.9.82.0.6 View file →
@@ -4,60 +4,10 @@
4 4 die('HACKING ATTEMPT!');
5 5 }
6 6
7 7 include_once(LOGINIZER_DIR.'/lib/IPv6/IPv6.php');
8 +include_once(LOGINIZER_DIR .'/common.php');
8 9
9 -// Get the client IP
10 -function _lz_getip(){
11 - if(isset($_SERVER["REMOTE_ADDR"])){
12 - return $_SERVER["REMOTE_ADDR"];
13 - }elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
14 - return $_SERVER["HTTP_X_FORWARDED_FOR"];
15 - }elseif(isset($_SERVER["HTTP_CLIENT_IP"])){
16 - return $_SERVER["HTTP_CLIENT_IP"];
17 - }
18 -}
19 -
20 -// Get the client IP
21 -function lz_getip(){
22 -
23 - global $loginizer;
24 -
25 - // Just so that we have something
26 - $ip = _lz_getip();
27 -
28 - $loginizer['ip_method'] = (int) @$loginizer['ip_method'];
29 -
30 - if(isset($_SERVER["REMOTE_ADDR"])){
31 - $ip = $_SERVER["REMOTE_ADDR"];
32 - }
33 -
34 - if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && @$loginizer['ip_method'] == 1){
35 - if(strpos($_SERVER["HTTP_X_FORWARDED_FOR"], ',')){
36 - $temp_ip = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);
37 - $ip = trim($temp_ip[0]);
38 - }else{
39 - $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
40 - }
41 - }
42 -
43 - if(isset($_SERVER["HTTP_CLIENT_IP"]) && @$loginizer['ip_method'] == 2){
44 - $ip = $_SERVER["HTTP_CLIENT_IP"];
45 - }
46 -
47 - if(@$loginizer['ip_method'] == 3 && isset($_SERVER[@$loginizer['custom_ip_method']])){
48 - $ip = $_SERVER[@$loginizer['custom_ip_method']];
49 - }
50 -
51 - // Hacking fix for X-Forwarded-For
52 - if(!lz_valid_ip($ip)){
53 - return '';
54 - }
55 -
56 - return $ip;
57 -
58 -}
59 -
60 10 // Execute a select query and return an array
61 11 function lz_selectquery($query, $array = 0){
62 12 global $wpdb;
63 13
@@ -69,54 +19,8 @@
69 19 return $result;
70 20 }
71 21 }
72 22
73 -// Check if an IP is valid
74 -function lz_valid_ip($ip){
75 -
76 - // IPv6
77 - if(lz_valid_ipv6($ip)){
78 - return true;
79 - }
80 -
81 - // IPv4
82 - if(!ip2long($ip) || !lz_valid_ipv4($ip)){
83 - return false;
84 - }
85 -
86 - return true;
87 -}
88 -
89 -function lz_valid_ipv4($ip){
90 - if(!preg_match('/^(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}$/is', $ip) || substr_count($ip, '.') != 3){
91 - return false;
92 - }
93 -
94 - $r = explode('.', $ip);
95 -
96 - foreach($r as $v){
97 - $v = (int) $v;
98 - if($v > 255 || $v < 0){
99 - return false;
100 - }
101 - }
102 -
103 - return true;
104 -
105 -}
106 -
107 -function lz_valid_ipv6($ip){
108 -
109 - $pattern = '/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/';
110 -
111 - if(!preg_match($pattern, $ip)){
112 - return false;
113 - }
114 -
115 - return true;
116 -
117 -}
118 -
119 23 // Check if a field is posted via POST else return default value
120 24 function lz_optpost($name, $default = ''){
121 25
122 26 if(!empty($_POST[$name])){
@@ -240,9 +144,9 @@
240 144 if(empty($error)){
241 145 return true;
242 146 }
243 147
244 - $error_string = '<b>Please fix the below error(s) :</b> <br />';
148 + $error_string = '<b>'.__('Please fix the below error(s)', 'loginizer').' :</b> <br />';
245 149
246 150 foreach($error as $ek => $ev){
247 151 $error_string .= '* '.$ev.'<br />';
248 152 }
@@ -247,9 +151,9 @@
247 151 $error_string .= '* '.$ev.'<br />';
248 152 }
249 153
250 154 echo '<div id="message" class="error"><p>'
251 - . __($error_string, 'loginizer')
155 + . $error_string
252 156 . '</p></div>';
253 157 }
254 158
255 159 // Report a notice
@@ -267,9 +171,9 @@
267 171 }else{
268 172 $notice_class = 'updated';
269 173 }
270 174
271 - $notice_string = '<b>Please check the below notice(s) :</b> <br />';
175 + $notice_string = '<b>'.__('Please check the below notice(s)', 'loginizer').' :</b> <br />';
272 176
273 177 foreach($notice as $ek => $ev){
274 178 $notice_string .= '* '.$ev.'<br />';
275 179 }
@@ -274,9 +178,9 @@
274 178 $notice_string .= '* '.$ev.'<br />';
275 179 }
276 180
277 181 echo '<div id="message" class="'.$notice_class.'"><p>'
278 - . __($notice_string, 'loginizer')
182 + . $notice_string
279 183 . '</p></div>';
280 184 }
281 185
282 186 // Convert an objext to array
@@ -487,9 +391,9 @@
487 391 }
488 392
489 393 // ------ HTML STARTS HERE -------- //
490 394
491 - $style = 'full';
395 + $style = 'icon';
492 396 $shape = 'square';
493 397 $position = 'below';
494 398 if(!empty($loginizer['social_settings'])){
495 399 $social_settings = $loginizer['social_settings'];
@@ -494,10 +398,10 @@
494 398 if(!empty($loginizer['social_settings'])){
495 399 $social_settings = $loginizer['social_settings'];
496 400
497 401 // Setting Button Style
498 - if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'icon'){
499 - $style = 'icon';
402 + if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'full'){
403 + $style = 'full';
500 404 }
501 405
502 406 // Setting Button Shape
503 407 if(!empty($social_settings[$page_type]['button_shape']) && $social_settings[$page_type]['button_shape'] !== 'square'){
@@ -509,8 +413,11 @@
509 413 $position = $social_settings[$page_type]['button_position'];
510 414 }
511 415 }
512 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 +
513 420 // Shortcode style
514 421 if(!empty($short_atts['type'])){
515 422 $style = esc_html($short_atts['type']);
516 423 }
@@ -518,8 +425,18 @@
518 425 // Shortcode Shape square or circle
519 426 if(!empty($short_atts['shape'])){
520 427 $shape = esc_html($short_atts['shape']);
521 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 + }
522 439
523 440 // Setting divider position
524 441 $divider_pos = '';
525 442 if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){
@@ -538,9 +455,9 @@
538 455 'above' => 'bottom',
539 456 'below' => 'top'
540 457 ];
541 458
542 - $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' : '').'">';
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).';">';
543 460
544 461 // HTML of the divider in case the buttons are below the login fields
545 462 if(!empty($divider_pos) && $divider_pos == 'above'){
546 463 $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>';
@@ -575,9 +492,9 @@
575 492 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png';
576 493 }
577 494 }
578 495
579 - $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).'\')" 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;') .'">
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;') .'">
580 497 <div class="loginizer-social-btn-logo">
581 498 <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/>
582 499 </div>';
583 500
@@ -588,9 +505,9 @@
588 505 }
589 506
590 507 $social_buttons .= '</div>';
591 508 }
592 -
509 +
593 510 if(empty($social_buttons)){
594 511 $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer');
595 512 }
596 513
@@ -637,14 +554,24 @@
637 554
638 555 wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]);
639 556 wp_enqueue_script('loginizer-social-js');
640 557 wp_add_inline_script('loginizer-social-js', '
558 +
559 +
641 560
642 561 let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"),
643 562 lz_social_btns = document.querySelectorAll("#lz-social-login-btns"),
644 563 lz_target_window = "'.esc_html($target_window).'",
645 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>";
646 569
570 + jQuery("body").append(loader);
571 + }
572 +
573 +
647 574 lz_social_btns.forEach((btns) => {
648 575 btns.style.display="flex";
649 576 });
650 577
@@ -656,11 +583,28 @@
656 583 }
657 584 });
658 585 }
659 586
660 - function loginizer_auth_popup(provider) {
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 +
661 602 if(lz_target_window == "same"){
662 - window.location.href = "'.esc_url(wp_login_url()).'?social_security='.esc_html($social_nonce).'&lz_social_provider="+ provider +"&ref='.esc_url($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']).'";
603 + jQuery("#loginizer-social-loader-wrap").css("display", "flex");
604 +
605 + window.location.href = target_url;
606 +
663 607 return;
664 608 }
665 609
666 610 let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft,
@@ -682,9 +626,9 @@
682 626 attributes.push("left=" + left);
683 627 attributes.push("top=" + right);
684 628 attributes.push("scrollbars=1");
685 629
686 - var auth_window = window.open("'.esc_url(wp_login_url()).'?social_security='.esc_html($social_nonce).'&lz_social_provider=" + provider+lz_is_interim+"&ref='.esc_url($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']).'", "authWindow", attributes.join(","));
630 + var auth_window = window.open(target_url, "authWindow", attributes.join(","));
687 631
688 632 if(window.focus){
689 633 auth_window.focus();
690 634 }
@@ -725,5 +669,5 @@
725 669
726 670 // Cleaning the error data
727 671 delete_site_transient($error_identifier); // Deleting the data
728 672 //setcookie('lz_social_error', '', time() - 300, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); // have to delete
729 -}
673 +}