PluginProbe
Loginizer / 2.0.0
Loginizer v2.0.0
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
loginizer / functions.php

functions.php in Loginizer 2.0.0, at functions.php

733 lines 21.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!defined('ABSPATH')){
4 die('HACKING ATTEMPT!');
5 }
6
7 include_once(LOGINIZER_DIR.'/lib/IPv6/IPv6.php');
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
60 // Execute a select query and return an array
61 function lz_selectquery($query, $array = 0){
62 global $wpdb;
63
64 $result = $wpdb->get_results($query, 'ARRAY_A');
65
66 if(empty($array)){
67 return current($result);
68 }else{
69 return $result;
70 }
71 }
72
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 // Check if a field is posted via POST else return default value
124 function lz_optpost($name, $default = ''){
125
126 if(!empty($_POST[$name])){
127 return lz_inputsec(lz_htmlizer(trim($_POST[$name])));
128 }
129
130 return $default;
131 }
132
133 // Check if a field is posted via GET else return default value
134 function lz_optget($name, $default = ''){
135
136 if(!empty($_GET[$name])){
137 return lz_inputsec(lz_htmlizer(trim($_GET[$name])));
138 }
139
140 return $default;
141 }
142
143 // Check if a field is posted via GET or POST else return default value
144 function lz_optreq($name, $default = ''){
145
146 if(!empty($_REQUEST[$name])){
147 return lz_inputsec(lz_htmlizer(trim($_REQUEST[$name])));
148 }
149
150 return $default;
151 }
152
153 // For filling in posted values
154 function lz_POSTval($name, $default = ''){
155
156 return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : esc_html($_POST[$name])) : $default);
157
158 }
159
160 function lz_POSTchecked($name, $default = false, $submit_name = ''){
161
162 if(!empty($submit_name)){
163 $post_to_check = isset($_POST[$submit_name]) ? $_POST[$submit_name] : '';
164 }else{
165 $post_to_check = $_POST;
166 }
167
168 return (!empty($post_to_check) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : ''));
169
170 }
171
172 function lz_POSTselect($name, $value, $default = false){
173
174 if(empty($_POST)){
175 if(!empty($default)){
176 return 'selected="selected"';
177 }
178 }else{
179 if(isset($_POST[$name])){
180 if(trim($_POST[$name]) == $value){
181 return 'selected="selected"';
182 }
183 }
184 }
185
186 }
187
188 function lz_POSTradio($name, $val, $default = null){
189
190 return (!empty($_POST) ? (@$_POST[$name] == $val ? 'checked="checked"' : '') : (!is_null($default) && $default == $val ? 'checked="checked"' : ''));
191
192 }
193
194 function lz_inputsec($string){
195
196 $string = addslashes($string);
197
198 // This is to replace ` which can cause the command to be executed in exec()
199 $string = str_replace('`', '\`', $string);
200
201 return $string;
202
203 }
204
205 function lz_htmlizer($string){
206
207 $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
208
209 preg_match_all('/(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)/', $string, $matches);//r_print($matches);
210
211 foreach($matches[1] as $mk => $mv){
212 $tmp_m = lz_entity_check($matches[2][$mk]);
213 $string = str_replace($matches[1][$mk], $tmp_m, $string);
214 }
215
216 return $string;
217
218 }
219
220 function lz_entity_check($string){
221
222 //Convert Hexadecimal to Decimal
223 $num = ((substr($string, 0, 1) === 'x') ? hexdec(substr($string, 1)) : (int) $string);
224
225 //Squares and Spaces - return nothing
226 $string = (($num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num < 0x20) ? '' : '&#'.$num.';');
227
228 return $string;
229
230 }
231
232 // Check if a checkbox is selected
233 function lz_is_checked($post){
234
235 if(!empty($_POST[$post])){
236 return true;
237 }
238 return false;
239 }
240
241 // Reoort an error
242 function lz_report_error($error = array()){
243
244 if(empty($error)){
245 return true;
246 }
247
248 $error_string = '<b>Please fix the below error(s) :</b> <br />';
249
250 foreach($error as $ek => $ev){
251 $error_string .= '* '.$ev.'<br />';
252 }
253
254 echo '<div id="message" class="error"><p>'
255 . __($error_string, 'loginizer')
256 . '</p></div>';
257 }
258
259 // Report a notice
260 function lz_report_notice($notice = array()){
261
262 global $wp_version;
263
264 if(empty($notice)){
265 return true;
266 }
267
268 // Which class do we have to use ?
269 if(version_compare($wp_version, '3.8', '<')){
270 $notice_class = 'updated';
271 }else{
272 $notice_class = 'updated';
273 }
274
275 $notice_string = '<b>Please check the below notice(s) :</b> <br />';
276
277 foreach($notice as $ek => $ev){
278 $notice_string .= '* '.$ev.'<br />';
279 }
280
281 echo '<div id="message" class="'.$notice_class.'"><p>'
282 . __($notice_string, 'loginizer')
283 . '</p></div>';
284 }
285
286 // Convert an objext to array
287 function lz_objectToArray($d){
288
289 if(is_object($d)){
290 $d = get_object_vars($d);
291 }
292
293 if(is_array($d)){
294 return array_map(__FUNCTION__, $d); // recursive
295 }elseif(is_object($d)){
296 return lz_objectToArray($d);
297 }else{
298 return $d;
299 }
300 }
301
302 // Sanitize variables
303 function lz_sanitize_variables($variables = array()){
304
305 if(is_array($variables)){
306 foreach($variables as $k => $v){
307 $variables[$k] = trim($v);
308 $variables[$k] = escapeshellcmd($v);
309 }
310 }else{
311 $variables = escapeshellcmd(trim($variables));
312 }
313
314 return $variables;
315 }
316
317 // Is multisite ?
318 function lz_is_multisite() {
319
320 if(function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()){
321 return true;
322 }
323
324 return false;
325 }
326
327 // Generate a random string
328 function lz_RandomString($length = 10){
329 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
330 $charactersLength = strlen($characters);
331 $randomString = '';
332 for($i = 0; $i < $length; $i++){
333 $randomString .= $characters[rand(0, $charactersLength - 1)];
334 }
335 return $randomString;
336 }
337
338 function lz_print($array){
339
340 echo '<pre>';
341 print_r($array);
342 echo '</pre>';
343
344 }
345
346 function lz_cleanpath($path){
347 $path = str_replace('\\\\', '/', $path);
348 $path = str_replace('\\', '/', $path);
349 $path = str_replace('//', '/', $path);
350 return rtrim($path, '/');
351 }
352
353 // Returns the Numeric Value of results Per Page
354 function lz_get_page($get = 'page', $resperpage = 50){
355
356 $resperpage = (!empty($_REQUEST['reslen']) && is_numeric($_REQUEST['reslen']) ? (int) lz_optreq('reslen') : $resperpage);
357
358 if(lz_optget($get)){
359 $pg = (int) lz_optget($get);
360 $pg = $pg - 1;
361 $page = ($pg * $resperpage);
362 $page = ($page <= 0 ? 0 : $page);
363 }else{
364 $page = 0;
365 }
366 return $page;
367 }
368
369 // Replaces the Variables with the supplied ones
370 function lz_lang_vars_name($str, $array){
371
372 foreach($array as $k => $v){
373
374 $str = str_replace('$'.$k, $v, $str);
375
376 }
377
378 return $str;
379
380 }
381
382 // Check if Loginizer is premium
383 function loginizer_is_premium(){
384 return defined('LOGINIZER_PREMIUM');
385 }
386
387 function loginizer_feature_available($feature = '', $return = 0){
388
389 if(loginizer_is_premium()){
390 return true;
391 }
392
393 $msg = '';
394
395 if(!empty($feature)){
396 $msg .= '<b>'.$feature.'</b> is available in the Pro version of Loginizer. ';
397 }
398
399 $msg .= '<a href="'.LOGINIZER_PRICING_URL.'" target="_blank" style="text-decoration:none; color:green;"><b>Upgrade to Pro</b></a>';
400
401 if(!empty($return)){
402 return $msg;
403 }else{
404 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>';
405 }
406
407 }
408
409 // Checks if the email is valid
410 function lz_valid_email($email){
411
412 return filter_var($email, FILTER_VALIDATE_EMAIL);
413
414 }
415
416 function loginizer_blocked_page($lz_error){
417
418 // We are checking if this is a login page or not
419 if(false === stripos(wp_login_url(), $_SERVER['REQUEST_URI'])){
420 return;
421 }
422
423 echo '<!DOCTYPE html><html><head>
424 <meta name="robots" content="noindex, noarchive">
425 <meta name="referrer" content="strict-origin-when-cross-origin">
426 <meta name="viewport" content="width=device-width, initial-scale=1.0">
427 <title>'.__('You can not access this page', 'loginizer').'</title>
428 <style>html,body{height:100%}
429 .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>
430 </head>
431 <body style="font-family:sans-serif; font-size:calc(15px + 0.390625vw);margin:0;">
432 <div class="loginizer-blocked-wrapper">
433 <div style="margin-top:10em;">
434 <h1 align="center">'.__('You can not access this page', 'loginizer').'</h1>
435 <p align="center">'.wp_kses_post(implode('', $lz_error)).'</p>
436 </div>
437 <footer>';
438 if(!defined('LOGINIZER_PREMIUM')){
439 echo '<p>Powered by Loginizer</p>';
440 } else {
441 echo '<p>Powered by ' . esc_html(get_bloginfo('name')) . '</p>';
442 }
443
444 echo '</footer></div></body></html>';
445 die();
446 }
447
448 function loginizer_social_css($position = 'below'){
449 global $loginizer;
450
451 // Starting the CSS
452 $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}';
453
454 // CSS for the divider with the text OR in the middle
455 if(!empty($loginizer['social_settings']) && ($position === 'below' || $position === 'above')){
456 $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}';
457 }
458
459 wp_register_style('loginizer-social', '', [], LOGINIZER_VERSION);
460 wp_enqueue_style('loginizer-social');
461 wp_add_inline_style('loginizer-social', $css);
462 }
463
464 // Echos the HTML of the Social button
465 function loginizer_social_btn($return = false, $page_type = 'login', $short_atts = []){
466 global $loginizer, $loginizer_login_providers;
467
468 // We don't want to give social login option to blacklisted IP's
469 if(loginizer_is_blacklisted() || !loginizer_can_login()){
470 return;
471 }
472
473 $provider_settings = get_option('loginizer_provider_settings', []);
474 $provider_order = get_option('loginizer_social_order', []); // in what order the icons are to be shown
475
476 $providers = [];
477
478 // Sorting according to the saved order of the providers.
479 if(!empty($provider_order)){
480 foreach($provider_order as $key => $num){
481 if(!empty($provider_settings[$key])){
482 $providers[$key] = $provider_settings[$key];
483 }
484 }
485 } else {
486 $providers = $provider_settings;
487 }
488
489 if(empty($providers)){
490 return;
491 }
492
493 // ------ HTML STARTS HERE -------- //
494
495 $style = 'full';
496 $shape = 'square';
497 $position = 'below';
498 if(!empty($loginizer['social_settings'])){
499 $social_settings = $loginizer['social_settings'];
500
501 // Setting Button Style
502 if(!empty($social_settings[$page_type]['button_style']) && $social_settings[$page_type]['button_style'] === 'icon'){
503 $style = 'icon';
504 }
505
506 // Setting Button Shape
507 if(!empty($social_settings[$page_type]['button_shape']) && $social_settings[$page_type]['button_shape'] !== 'square'){
508 $shape = $social_settings[$page_type]['button_shape'];
509 }
510
511 // Setting position
512 if(!empty($social_settings[$page_type]['button_position']) && $social_settings[$page_type]['button_position'] !== 'below'){
513 $position = $social_settings[$page_type]['button_position'];
514 }
515 }
516
517 // Shortcode style
518 if(!empty($short_atts['type'])){
519 $style = esc_html($short_atts['type']);
520 }
521
522 // Shortcode Shape square or circle
523 if(!empty($short_atts['shape'])){
524 $shape = esc_html($short_atts['shape']);
525 }
526
527 // Setting divider position
528 $divider_pos = '';
529 if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){
530 $divider_pos = 'above';
531 }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'below_plus'){
532 $divider_pos = 'above';
533 }elseif(!empty($short_atts['divider']) && $short_atts['divider'] == 'below'){
534 $divider_pos = 'below';
535 }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'above_plus'){
536 $divider_pos = 'below';
537 }
538
539 loginizer_social_css($divider_pos);
540
541 $padding = [
542 'above' => 'bottom',
543 'below' => 'top'
544 ];
545
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' : '').'">';
547
548 // HTML of the divider in case the buttons are below the login fields
549 if(!empty($divider_pos) && $divider_pos == 'above'){
550 $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>';
551 }
552
553 include_once LOGINIZER_DIR . '/main/login-providers.php';
554
555 foreach($providers as $provider => $settings){
556 if(empty($settings['enabled']) || empty($settings['tested'])){
557 continue;
558 }
559
560 // Filters Pro Only Auth
561 if(!empty($loginizer_login_providers[$provider]['premium']) && !defined('LOGINIZER_PREMIUM')){
562 continue;
563 }
564
565 $name = $loginizer_login_providers[$provider]['name'];
566 $color = $loginizer_login_providers[$provider]['color'];
567
568 $btn_style = 'default';
569 if(!empty($provider_settings[$provider]['button_style'])){
570 $btn_style = $provider_settings[$provider]['button_style'];
571 }
572
573 // TODO:: Improve the comment here
574 // The image is named based on button style as Facebook has different images for different style
575 // And if some more social options are added they could have the same behaviour too.
576 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'.png';
577 if('default' !== $btn_style){
578 if(file_exists(LOGINIZER_DIR .'/assets/images/social/'.$provider.'-'.$btn_style.'.png')){
579 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png';
580 }
581 }
582
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;') .'">
584 <div class="loginizer-social-btn-logo">
585 <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/>
586 </div>';
587
588 // Button text in case of full button
589 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>
591 </div>';
592 }
593
594 $social_buttons .= '</div>';
595 }
596
597 if(empty($social_buttons)){
598 $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer');
599 }
600
601 // HTML of the divider in case the buttons are above the login fields
602 if(!empty($divider_pos) && $divider_pos == 'below'){
603 $social_buttons .= '<br><div class="loginizer-social-divider">OR</div>';
604 }
605
606 $social_buttons .= '</div>';
607 loginizer_add_social_js($page_type);
608
609 if($return){
610 return $social_buttons;
611 }
612
613 echo wp_kses($social_buttons, [
614 'div' => ['class' => true, 'id' => true, 'style' => true, 'onclick' => true],
615 'img' => ['src' => true, 'height' => true, 'alt' => true, 'width' => true],
616 'strong' => true,
617 ]);
618 }
619
620 function loginizer_add_social_js($page_type){
621 global $loginizer;
622
623 if(wp_script_is('loginizer-social-js') || loginizer_is_blacklisted() || !empty($loginizer['social_script_added'])){
624 return;
625 }
626
627 $loginizer['social_script_added'] = false;
628 $func = 'append';
629 if(!empty($loginizer['social_settings']) && !empty($loginizer['social_settings'][$page_type]['button_position']) && strpos($loginizer['social_settings'][$page_type]['button_position'], 'above') !== FALSE){
630 $func = 'prepend';
631 }
632
633 $target_window = 'same';
634 if(isset($_GET['interim-login']) && $_GET['interim-login'] == 1){
635 $target_window = 'popup';
636 } elseif(!empty($loginizer['social_settings']['general']['target_window'])){
637 $target_window = $loginizer['social_settings']['general']['target_window'];
638 }
639
640 $social_nonce = wp_create_nonce('loginizer_social_check');
641
642 wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]);
643 wp_enqueue_script('loginizer-social-js');
644 wp_add_inline_script('loginizer-social-js', '
645
646 let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"),
647 lz_social_btns = document.querySelectorAll("#lz-social-login-btns"),
648 lz_target_window = "'.esc_html($target_window).'",
649 lz_is_interim = "'.(!empty($_GET['interim-login']) ? '&interim-login=0' : '').'"; // as for interim it should only open a popup
650
651 lz_social_btns.forEach((btns) => {
652 btns.style.display="flex";
653 });
654
655 if(lz_form.length > 0){
656 lz_form.forEach((form, index) => {
657 if (lz_social_btns[index]) {
658 lz_social_btns[index].style.display="flex";
659 form.'.esc_html($func).'(lz_social_btns[index]);
660 }
661 });
662 }
663
664 function loginizer_auth_popup(provider) {
665 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']).'";
667 return;
668 }
669
670 let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft,
671 screen_y = window.screenY !== undefined ? window.screenY : window.screenTop,
672 outer_width = window.outerWidth !== undefined ? window.outerWidth : document.documentElement.clientWidth,
673 outer_height = window.outerHeight !== undefined ? window.outerHeight : document.documentElement.clientHeight - 22,
674 target_width = 600,
675 target_height = 600,
676 right = parseInt(screen_y + (outerHeight - target_height) / 2.5, 10),
677 left = parseInt(screen_x + (outerWidth - target_width) / 2, 10),
678 attributes = [];
679
680 if(target_width !== null){
681 attributes.push("width=" + target_width);
682 }
683 if(target_height !== null){
684 attributes.push("height=" + target_height);
685 }
686 attributes.push("left=" + left);
687 attributes.push("top=" + right);
688 attributes.push("scrollbars=1");
689
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(","));
691
692 if(window.focus){
693 auth_window.focus();
694 }
695 return false;
696 }'
697 );
698
699 $loginizer['social_script_added'] = true;
700
701 }
702
703 function loginizer_social_btn_login($return = false, $id = ''){
704 loginizer_social_btn($return, 'login');
705 }
706
707 function loginizer_get_social_error(){
708 global $loginizer;
709
710 // If we already have the error set
711 if(!empty($loginizer['social_errors'])){
712 return;
713 }
714
715 if(empty($_COOKIE) || empty($_COOKIE['lz_social_error'])){
716 return;
717 }
718
719 $error_identifier = sanitize_text_field(wp_unslash($_COOKIE['lz_social_error']));
720 $social_errors = get_site_transient($error_identifier);
721
722 if(empty($social_errors['errors'])){
723 return;
724 }
725
726 // Setting error data
727 $loginizer['retries_left'] = $social_errors['retries_left'];
728 $loginizer['social_errors'] = $social_errors['errors'];
729
730 // Cleaning the error data
731 delete_site_transient($error_identifier); // Deleting the data
732 //setcookie('lz_social_error', '', time() - 300, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); // have to delete
733 }