PluginProbe
Loginizer / 2.0.2
Loginizer v2.0.2
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.2, at functions.php

768 lines 23.2 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 = 'icon';
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'] === 'full'){
503 $style = 'full';
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 $container_alignment = isset($loginizer['social_settings'][$page_type]['alignment']) ? $loginizer['social_settings'][$page_type]['alignment'] : 'auto';
518 $button_alignment = isset($loginizer['social_settings'][$page_type]['button_alignment']) ? $loginizer['social_settings'][$page_type]['button_alignment'] : 'center';
519
520 // Shortcode style
521 if(!empty($short_atts['type'])){
522 $style = esc_html($short_atts['type']);
523 }
524
525 // Shortcode Shape square or circle
526 if(!empty($short_atts['shape'])){
527 $shape = esc_html($short_atts['shape']);
528 }
529
530 // Shortcode for Container alignment
531 if(!empty($short_atts['container_alignment'])){
532 $container_alignment = esc_html($short_atts['container_alignment']);
533 }
534
535 // Shortcode for Button alignment
536 if(!empty($short_atts['button_alignment'])){
537 $button_alignment = esc_html($short_atts['button_alignment']);
538 }
539
540 // Setting divider position
541 $divider_pos = '';
542 if(!empty($short_atts['divider']) && $short_atts['divider'] == 'above'){
543 $divider_pos = 'above';
544 }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'below_plus'){
545 $divider_pos = 'above';
546 }elseif(!empty($short_atts['divider']) && $short_atts['divider'] == 'below'){
547 $divider_pos = 'below';
548 }elseif(empty($short_atts) && !empty($loginizer['social_settings']) && $position === 'above_plus'){
549 $divider_pos = 'below';
550 }
551
552 loginizer_social_css($divider_pos);
553
554 $padding = [
555 'above' => 'bottom',
556 'below' => 'top'
557 ];
558
559 $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).';">';
560
561 // HTML of the divider in case the buttons are below the login fields
562 if(!empty($divider_pos) && $divider_pos == 'above'){
563 $social_buttons .= '<div class="loginizer-social-divider">OR</div><br>';
564 }
565
566 include_once LOGINIZER_DIR . '/main/login-providers.php';
567
568 foreach($providers as $provider => $settings){
569 if(empty($settings['enabled']) || empty($settings['tested'])){
570 continue;
571 }
572
573 // Filters Pro Only Auth
574 if(!empty($loginizer_login_providers[$provider]['premium']) && !defined('LOGINIZER_PREMIUM')){
575 continue;
576 }
577
578 $name = $loginizer_login_providers[$provider]['name'];
579 $color = $loginizer_login_providers[$provider]['color'];
580
581 $btn_style = 'default';
582 if(!empty($provider_settings[$provider]['button_style'])){
583 $btn_style = $provider_settings[$provider]['button_style'];
584 }
585
586 // TODO:: Improve the comment here
587 // The image is named based on button style as Facebook has different images for different style
588 // And if some more social options are added they could have the same behaviour too.
589 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'.png';
590 if('default' !== $btn_style){
591 if(file_exists(LOGINIZER_DIR .'/assets/images/social/'.$provider.'-'.$btn_style.'.png')){
592 $img_url = LOGINIZER_URL .'/assets/images/social/'.$provider.'-'.$btn_style.'.png';
593 }
594 }
595
596 $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;') .'">
597 <div class="loginizer-social-btn-logo">
598 <img src="'.esc_url($img_url).'" height="24" alt="'.esc_attr($name).' Icon"/>
599 </div>';
600
601 // Button text in case of full button
602 if(!empty($loginizer['social_settings']) && $style === 'full'){
603 $social_buttons .= '<div class="loginizer-social-btn-text">'.esc_html__('Login With', 'loginizer').' <strong>'.esc_html($name).'</strong>
604 </div>';
605 }
606
607 $social_buttons .= '</div>';
608 }
609
610 if(empty($social_buttons)){
611 $social_buttons .= esc_html__('No Auth Provider configured', 'loginizer');
612 }
613
614 // HTML of the divider in case the buttons are above the login fields
615 if(!empty($divider_pos) && $divider_pos == 'below'){
616 $social_buttons .= '<br><div class="loginizer-social-divider">OR</div>';
617 }
618
619 $social_buttons .= '</div>';
620 loginizer_add_social_js($page_type);
621
622 if($return){
623 return $social_buttons;
624 }
625
626 echo wp_kses($social_buttons, [
627 'div' => ['class' => true, 'id' => true, 'style' => true, 'onclick' => true],
628 'img' => ['src' => true, 'height' => true, 'alt' => true, 'width' => true],
629 'strong' => true,
630 ]);
631 }
632
633 function loginizer_add_social_js($page_type){
634 global $loginizer;
635
636 if(wp_script_is('loginizer-social-js') || loginizer_is_blacklisted() || !empty($loginizer['social_script_added'])){
637 return;
638 }
639
640 $loginizer['social_script_added'] = false;
641 $func = 'append';
642 if(!empty($loginizer['social_settings']) && !empty($loginizer['social_settings'][$page_type]['button_position']) && strpos($loginizer['social_settings'][$page_type]['button_position'], 'above') !== FALSE){
643 $func = 'prepend';
644 }
645
646 $target_window = 'same';
647 if(isset($_GET['interim-login']) && $_GET['interim-login'] == 1){
648 $target_window = 'popup';
649 } elseif(!empty($loginizer['social_settings']['general']['target_window'])){
650 $target_window = $loginizer['social_settings']['general']['target_window'];
651 }
652
653 $social_nonce = wp_create_nonce('loginizer_social_check');
654
655 wp_register_script('loginizer-social-js', '', ['jquery'], LOGINIZER_VERSION, ['strategy' => false, 'in_footer' => true]);
656 wp_enqueue_script('loginizer-social-js');
657 wp_add_inline_script('loginizer-social-js', '
658
659
660
661 let lz_form = document.querySelectorAll("#loginform, #registerform, .woocommerce-form-login, .woocommerce-form-register, #front-login-form, #setupform"),
662 lz_social_btns = document.querySelectorAll("#lz-social-login-btns"),
663 lz_target_window = "'.esc_html($target_window).'",
664 lz_is_interim = "'.(!empty($_GET['interim-login']) ? '&interim-login=0' : '').'"; // as for interim it should only open a popup
665
666 if(lz_target_window == "same"){
667 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>";
668 loader += "<div id=\"loginizer-social-loader-wrap\"><div class=\"loginizer-social-loader\"></div></div>";
669
670 jQuery("body").append(loader);
671 }
672
673
674 lz_social_btns.forEach((btns) => {
675 btns.style.display="flex";
676 });
677
678 if(lz_form.length > 0){
679 lz_form.forEach((form, index) => {
680 if (lz_social_btns[index]) {
681 lz_social_btns[index].style.display="flex";
682 form.'.esc_html($func).'(lz_social_btns[index]);
683 }
684 });
685 }
686
687 function loginizer_auth_popup(provider, isAPI) {
688 let target_url = "'.esc_url(wp_login_url()).'?social_security='.esc_html($social_nonce).'&lz_social_provider=" + provider+lz_is_interim;
689
690 if(isAPI){
691 target_url += "&lz_api=1";
692 }
693
694 target_url += "&ref='.esc_url((is_ssl() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']).'"
695
696 if(lz_target_window == "same"){
697 jQuery("#loginizer-social-loader-wrap").css("display", "flex");
698
699 window.location.href = target_url;
700
701 return;
702 }
703
704 let screen_x = window.screenX !== undefined ? window.screenX : window.screenLeft,
705 screen_y = window.screenY !== undefined ? window.screenY : window.screenTop,
706 outer_width = window.outerWidth !== undefined ? window.outerWidth : document.documentElement.clientWidth,
707 outer_height = window.outerHeight !== undefined ? window.outerHeight : document.documentElement.clientHeight - 22,
708 target_width = 600,
709 target_height = 600,
710 right = parseInt(screen_y + (outerHeight - target_height) / 2.5, 10),
711 left = parseInt(screen_x + (outerWidth - target_width) / 2, 10),
712 attributes = [];
713
714 if(target_width !== null){
715 attributes.push("width=" + target_width);
716 }
717 if(target_height !== null){
718 attributes.push("height=" + target_height);
719 }
720 attributes.push("left=" + left);
721 attributes.push("top=" + right);
722 attributes.push("scrollbars=1");
723
724 var auth_window = window.open(target_url, "authWindow", attributes.join(","));
725
726 if(window.focus){
727 auth_window.focus();
728 }
729 return false;
730 }'
731 );
732
733 $loginizer['social_script_added'] = true;
734
735 }
736
737 function loginizer_social_btn_login($return = false, $id = ''){
738 loginizer_social_btn($return, 'login');
739 }
740
741 function loginizer_get_social_error(){
742 global $loginizer;
743
744 // If we already have the error set
745 if(!empty($loginizer['social_errors'])){
746 return;
747 }
748
749 if(empty($_COOKIE) || empty($_COOKIE['lz_social_error'])){
750 return;
751 }
752
753 $error_identifier = sanitize_text_field(wp_unslash($_COOKIE['lz_social_error']));
754 $social_errors = get_site_transient($error_identifier);
755
756 if(empty($social_errors['errors'])){
757 return;
758 }
759
760 // Setting error data
761 $loginizer['retries_left'] = $social_errors['retries_left'];
762 $loginizer['social_errors'] = $social_errors['errors'];
763
764 // Cleaning the error data
765 delete_site_transient($error_identifier); // Deleting the data
766 //setcookie('lz_social_error', '', time() - 300, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); // have to delete
767 }
768