PluginProbe
Loginizer / 1.9.3
Loginizer v1.9.3
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 +116 -79 trunk1.9.3 View file →
@@ -4,10 +4,60 @@
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');
9 8
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 +
10 60 // Execute a select query and return an array
11 61 function lz_selectquery($query, $array = 0){
12 62 global $wpdb;
13 63
@@ -19,8 +69,54 @@
19 69 return $result;
20 70 }
21 71 }
22 72
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 +
23 119 // Check if a field is posted via POST else return default value
24 120 function lz_optpost($name, $default = ''){
25 121
26 122 if(!empty($_POST[$name])){
@@ -144,9 +240,9 @@
144 240 if(empty($error)){
145 241 return true;
146 242 }
147 243
148 - $error_string = '<b>'.__('Please fix the below error(s)', 'loginizer').' :</b> <br />';
244 + $error_string = '<b>Please fix the below error(s) :</b> <br />';
149 245
150 246 foreach($error as $ek => $ev){
151 247 $error_string .= '* '.$ev.'<br />';
152 248 }
@@ -151,9 +247,9 @@
151 247 $error_string .= '* '.$ev.'<br />';
152 248 }
153 249
154 250 echo '<div id="message" class="error"><p>'
155 - . $error_string
251 + . __($error_string, 'loginizer')
156 252 . '</p></div>';
157 253 }
158 254
159 255 // Report a notice
@@ -171,9 +267,9 @@
171 267 }else{
172 268 $notice_class = 'updated';
173 269 }
174 270
175 - $notice_string = '<b>'.__('Please check the below notice(s)', 'loginizer').' :</b> <br />';
271 + $notice_string = '<b>Please check the below notice(s) :</b> <br />';
176 272
177 273 foreach($notice as $ek => $ev){
178 274 $notice_string .= '* '.$ev.'<br />';
179 275 }
@@ -178,9 +274,9 @@
178 274 $notice_string .= '* '.$ev.'<br />';
179 275 }
180 276
181 277 echo '<div id="message" class="'.$notice_class.'"><p>'
182 - . $notice_string
278 + . __($notice_string, 'loginizer')
183 279 . '</p></div>';
184 280 }
185 281
186 282 // Convert an objext to array
@@ -391,9 +487,9 @@
391 487 }
392 488
393 489 // ------ HTML STARTS HERE -------- //
394 490
395 - $style = 'icon';
491 + $style = 'full';
396 492 $shape = 'square';
397 493 $position = 'below';
398 494 if(!empty($loginizer['social_settings'])){
399 495 $social_settings = $loginizer['social_settings'];
@@ -398,10 +494,10 @@
398 494 if(!empty($loginizer['social_settings'])){
399 495 $social_settings = $loginizer['social_settings'];
400 496
401 497 // Setting Button Style
402 - if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'full'){
403 - $style = 'full';
498 + if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'icon'){
499 + $style = 'icon';
404 500 }
405 501
406 502 // Setting Button Shape
407 503 if(!empty($social_settings[$page_type]['button_shape']) && $social_settings[$page_type]['button_shape'] !== 'square'){
@@ -413,11 +509,8 @@
413 509 $position = $social_settings[$page_type]['button_position'];
414 510 }
415 511 }
416 512
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 513 // Shortcode style
421 514 if(!empty($short_atts['type'])){
422 515 $style = esc_html($short_atts['type']);
423 516 }
@@ -425,18 +518,8 @@
425 518 // Shortcode Shape square or circle
426 519 if(!empty($short_atts['shape'])){
427 520 $shape = esc_html($short_atts['shape']);
428 521 }
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 522
440 523 // Setting divider position
441 524 $divider_pos = '';
442 525 if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){
@@ -455,23 +538,16 @@
455 538 'above' => 'bottom',
456 539 'below' => 'top'
457 540 ];
458 541
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).';">';
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' : '').'">';
460 543
461 - /* translators: %s: This OR is used as a separator for Either login through username OR use social login */
462 - $or_translated = __('OR', 'loginizer');
463 -
464 544 // HTML of the divider in case the buttons are below the login fields
465 545 if(!empty($divider_pos) && $divider_pos == 'above'){
466 - $social_buttons .= '<div class="loginizer-social-divider">'.esc_html($or_translated).'</div><br>';
546 + $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>';
467 547 }
468 548
469 549 include_once LOGINIZER_DIR . '/main/login-providers.php';
470 -
471 - // This is used to decide weather we will use Login with or Register with
472 - $current_hook = current_action();
473 - $register_hooks = ['register_form', 'woocommerce_register_form'];
474 550
475 551 foreach($providers as $provider => $settings){
476 552 if(empty($settings['enabled']) || empty($settings['tested'])){
477 553 continue;
@@ -499,30 +575,22 @@
499 575 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png';
500 576 }
501 577 }
502 578
503 - $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;') .'">
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;') .'">
504 580 <div class="loginizer-social-btn-logo">
505 581 <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/>
506 582 </div>';
507 -
508 - if(in_array($current_hook, $register_hooks)){
509 - /* translators: %s: This is for social login so the complete text would be Register With [Brand Name], eg Register With Google */
510 - $button_text = esc_html__('Register With', 'loginizer');
511 - } else {
512 - /* translators: %s: This is for social login so the complete text would be Login With [Brand Name], eg Login With Google */
513 - $button_text = esc_html__('Login With', 'loginizer');
514 - }
515 583
516 584 // Button text in case of full button
517 585 if(!empty($loginizer['social_settings']) && $style === 'full'){
518 - $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html($button_text).' <strong>'.esc_html($name).'</strong>
586 + $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html__('Login With', 'loginizer').' <strong>'.esc_html($name).'</strong>
519 587 </div>';
520 588 }
521 589
522 590 $social_buttons .= '</div>';
523 591 }
524 -
592 +
525 593 if(empty($social_buttons)){
526 594 $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer');
527 595 }
528 596
@@ -527,9 +595,9 @@
527 595 }
528 596
529 597 // HTML of the divider in case the buttons are above the login fields
530 598 if(!empty($divider_pos) && $divider_pos == 'below'){
531 - $social_buttons .= '<br><div class="loginizer-social-divider">'.esc_html($or_translated).'</div>';
599 + $social_buttons .= '<br><div class="loginizer-social-divider">OR</div>';
532 600 }
533 601
534 602 $social_buttons .= '</div>';
535 603 loginizer_add_social_js($page_type);
@@ -569,24 +637,14 @@
569 637
570 638 wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]);
571 639 wp_enqueue_script('loginizer-social-js');
572 640 wp_add_inline_script('loginizer-social-js', '
573 -
574 -
575 641
576 642 let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"),
577 643 lz_social_btns = document.querySelectorAll("#lz-social-login-btns"),
578 644 lz_target_window = "'.esc_html($target_window).'",
579 645 lz_is_interim = "'.(!empty($_GET['interim-login']) ? '&interim-login=0' : '').'"; // as for interim it should only open a popup
580 -
581 - if(lz_target_window == "same"){
582 - 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>";
583 - loader += "<div id=\"loginizer-social-loader-wrap\"><div class=\"loginizer-social-loader\"></div></div>";
584 646
585 - jQuery("body").append(loader);
586 - }
587 -
588 -
589 647 lz_social_btns.forEach((btns) => {
590 648 btns.style.display="flex";
591 649 });
592 650
@@ -591,35 +649,16 @@
591 649 });
592 650
593 651 if(lz_form.length > 0){
594 652 lz_form.forEach((form, index) => {
595 - if (lz_social_btns[index]) {
596 - lz_social_btns[index].style.display="flex";
597 - form.'.esc_html($func).'(lz_social_btns[index]);
598 - }
653 + lz_social_btns[index].style.display="flex";
654 + form.'.esc_html($func).'(lz_social_btns[index]);
599 655 });
600 656 }
601 657
602 - function loginizer_auth_popup(provider, isAPI) {
603 - let target_url = "'.esc_url(wp_login_url()).'?social_security='.esc_html($social_nonce).'&lz_social_provider=" + provider+lz_is_interim;
604 -
605 - if(isAPI){
606 - target_url += "&lz_api=1";
607 - }
608 -
609 - let redirect_to = "'.(!empty($_GET['redirect_to']) ? wp_validate_redirect(esc_url($_GET['redirect_to'])) : '') .'";
610 -
611 - if(redirect_to.length){
612 - target_url += "&ref="+redirect_to;
613 - } else {
614 - target_url += "&ref='.esc_url((is_ssl() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']).'"
615 - }
616 -
658 + function loginizer_auth_popup(provider) {
617 659 if(lz_target_window == "same"){
618 - jQuery("#loginizer-social-loader-wrap").css("display", "flex");
619 -
620 - window.location.href = target_url;
621 -
660 + 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']).'";
622 661 return;
623 662 }
624 663
625 664 let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft,
@@ -641,9 +680,9 @@
641 680 attributes.push("left=" + left);
642 681 attributes.push("top=" + right);
643 682 attributes.push("scrollbars=1");
644 683
645 - var auth_window = window.open(target_url, "authWindow", attributes.join(","));
684 + 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(","));
646 685
647 686 if(window.focus){
648 687 auth_window.focus();
649 688 }
@@ -655,11 +694,9 @@
655 694
656 695 }
657 696
658 697 function loginizer_social_btn_login($return = false, $id = ''){
659 - if(!loginizer_is_blacklisted()){
660 - loginizer_social_btn($return, 'login');
661 - }
698 + loginizer_social_btn($return, 'login');
662 699 }
663 700
664 701 function loginizer_get_social_error(){
665 702 global $loginizer;