PluginProbe
Loginizer / 2.1.1
Loginizer v2.1.1
2.1.1 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 All 75 releases
← All changes | functions.php +75 -118 1.9.9 → 2.1.1 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,58 +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 - if(empty($ip)){
77 - return false;
78 - }
79 -
80 - // IPv6
81 - if(lz_valid_ipv6($ip)){
82 - return true;
83 - }
84 -
85 - // IPv4
86 - if(!ip2long($ip) || !lz_valid_ipv4($ip)){
87 - return false;
88 - }
89 -
90 - return true;
91 -}
92 -
93 -function lz_valid_ipv4($ip){
94 - if(!preg_match('/^(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}$/is', $ip) || substr_count($ip, '.') != 3){
95 - return false;
96 - }
97 -
98 - $r = explode('.', $ip);
99 -
100 - foreach($r as $v){
101 - $v = (int) $v;
102 - if($v > 255 || $v < 0){
103 - return false;
104 - }
105 - }
106 -
107 - return true;
108 -
109 -}
110 -
111 -function lz_valid_ipv6($ip){
112 -
113 - $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}:))$/';
114 -
115 - if(!preg_match($pattern, $ip)){
116 - return false;
117 - }
118 -
119 - return true;
120 -
121 -}
122 -
123 23 // Check if a field is posted via POST else return default value
124 24 function lz_optpost($name, $default = ''){
125 25
126 26 if(!empty($_POST[$name])){
@@ -244,9 +144,9 @@
244 144 if(empty($error)){
245 145 return true;
246 146 }
247 147
248 - $error_string = '<b>Please fix the below error(s) :</b> <br />';
148 + $error_string = '<b>'.__('Please fix the below error(s)', 'loginizer').' :</b> <br />';
249 149
250 150 foreach($error as $ek => $ev){
251 151 $error_string .= '* '.$ev.'<br />';
252 152 }
@@ -251,9 +151,9 @@
251 151 $error_string .= '* '.$ev.'<br />';
252 152 }
253 153
254 154 echo '<div id="message" class="error"><p>'
255 - . __($error_string, 'loginizer')
155 + . $error_string
256 156 . '</p></div>';
257 157 }
258 158
259 159 // Report a notice
@@ -271,9 +171,9 @@
271 171 }else{
272 172 $notice_class = 'updated';
273 173 }
274 174
275 - $notice_string = '<b>Please check the below notice(s) :</b> <br />';
175 + $notice_string = '<b>'.__('Please check the below notice(s)', 'loginizer').' :</b> <br />';
276 176
277 177 foreach($notice as $ek => $ev){
278 178 $notice_string .= '* '.$ev.'<br />';
279 179 }
@@ -278,9 +178,9 @@
278 178 $notice_string .= '* '.$ev.'<br />';
279 179 }
280 180
281 181 echo '<div id="message" class="'.$notice_class.'"><p>'
282 - . __($notice_string, 'loginizer')
182 + . $notice_string
283 183 . '</p></div>';
284 184 }
285 185
286 186 // Convert an objext to array
@@ -491,9 +391,9 @@
491 391 }
492 392
493 393 // ------ HTML STARTS HERE -------- //
494 394
495 - $style = 'full';
395 + $style = 'icon';
496 396 $shape = 'square';
497 397 $position = 'below';
498 398 if(!empty($loginizer['social_settings'])){
499 399 $social_settings = $loginizer['social_settings'];
@@ -498,10 +398,10 @@
498 398 if(!empty($loginizer['social_settings'])){
499 399 $social_settings = $loginizer['social_settings'];
500 400
501 401 // Setting Button Style
502 - if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'icon'){
503 - $style = 'icon';
402 + if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'full'){
403 + $style = 'full';
504 404 }
505 405
506 406 // Setting Button Shape
507 407 if(!empty($social_settings[$page_type]['button_shape']) && $social_settings[$page_type]['button_shape'] !== 'square'){
@@ -513,8 +413,11 @@
513 413 $position = $social_settings[$page_type]['button_position'];
514 414 }
515 415 }
516 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 +
517 420 // Shortcode style
518 421 if(!empty($short_atts['type'])){
519 422 $style = esc_html($short_atts['type']);
520 423 }
@@ -522,8 +425,18 @@
522 425 // Shortcode Shape square or circle
523 426 if(!empty($short_atts['shape'])){
524 427 $shape = esc_html($short_atts['shape']);
525 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 + }
526 439
527 440 // Setting divider position
528 441 $divider_pos = '';
529 442 if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){
@@ -542,16 +455,23 @@
542 455 'above' => 'bottom',
543 456 'below' => 'top'
544 457 ];
545 458
546 - $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).';">';
547 460
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 +
548 464 // HTML of the divider in case the buttons are below the login fields
549 465 if(!empty($divider_pos) && $divider_pos == 'above'){
550 - $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>';
466 + $social_buttons .= '<div class="loginizer-social-divider">'.esc_html($or_translated).'</div><br>';
551 467 }
552 468
553 469 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'];
554 474
555 475 foreach($providers as $provider => $settings){
556 476 if(empty($settings['enabled']) || empty($settings['tested'])){
557 477 continue;
@@ -579,22 +499,30 @@
579 499 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png';
580 500 }
581 501 }
582 502
583 - $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;') .'">
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;') .'">
584 504 <div class="loginizer-social-btn-logo">
585 505 <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/>
586 506 </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 + }
587 515
588 516 // Button text in case of full button
589 517 if(!empty($loginizer['social_settings']) && $style === 'full'){
590 - $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html__('Login With', 'loginizer').' <strong>'.esc_html($name).'</strong>
518 + $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html($button_text).' <strong>'.esc_html($name).'</strong>
591 519 </div>';
592 520 }
593 521
594 522 $social_buttons .= '</div>';
595 523 }
596 -
524 +
597 525 if(empty($social_buttons)){
598 526 $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer');
599 527 }
600 528
@@ -599,9 +527,9 @@
599 527 }
600 528
601 529 // HTML of the divider in case the buttons are above the login fields
602 530 if(!empty($divider_pos) && $divider_pos == 'below'){
603 - $social_buttons .= '<br><div class="loginizer-social-divider">OR</div>';
531 + $social_buttons .= '<br><div class="loginizer-social-divider">'.esc_html($or_translated).'</div>';
604 532 }
605 533
606 534 $social_buttons .= '</div>';
607 535 loginizer_add_social_js($page_type);
@@ -641,14 +569,24 @@
641 569
642 570 wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]);
643 571 wp_enqueue_script('loginizer-social-js');
644 572 wp_add_inline_script('loginizer-social-js', '
573 +
574 +
645 575
646 576 let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"),
647 577 lz_social_btns = document.querySelectorAll("#lz-social-login-btns"),
648 578 lz_target_window = "'.esc_html($target_window).'",
649 579 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>";
650 584
585 + jQuery("body").append(loader);
586 + }
587 +
588 +
651 589 lz_social_btns.forEach((btns) => {
652 590 btns.style.display="flex";
653 591 });
654 592
@@ -660,11 +598,28 @@
660 598 }
661 599 });
662 600 }
663 601
664 - function loginizer_auth_popup(provider) {
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 +
665 617 if(lz_target_window == "same"){
666 - 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']).'";
618 + jQuery("#loginizer-social-loader-wrap").css("display", "flex");
619 +
620 + window.location.href = target_url;
621 +
667 622 return;
668 623 }
669 624
670 625 let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft,
@@ -686,9 +641,9 @@
686 641 attributes.push("left=" + left);
687 642 attributes.push("top=" + right);
688 643 attributes.push("scrollbars=1");
689 644
690 - 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(","));
645 + var auth_window = window.open(target_url, "authWindow", attributes.join(","));
691 646
692 647 if(window.focus){
693 648 auth_window.focus();
694 649 }
@@ -700,9 +655,11 @@
700 655
701 656 }
702 657
703 658 function loginizer_social_btn_login($return = false, $id = ''){
704 - loginizer_social_btn($return, 'login');
659 + if(!loginizer_is_blacklisted()){
660 + loginizer_social_btn($return, 'login');
661 + }
705 662 }
706 663
707 664 function loginizer_get_social_error(){
708 665 global $loginizer;