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