PluginProbe
Loginizer / 1.4.9
Loginizer v1.4.9
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 +348 -219 1.01.4.9 View file →
@@ -1,219 +1,348 @@
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 -// Get the value of option from lz_options table
15 -function lz_get_option($option_name, $default = ''){
16 -
17 - global $wpdb;
18 -
19 - $result = lz_selectquery("SELECT `option_value` FROM `".$wpdb->prefix."lz_options` WHERE `option_name` = '".$option_name."';");
20 -
21 - if(!empty($result['option_value'])){
22 - return $result['option_value'];
23 - }
24 -
25 - return $default;
26 -}
27 -
28 -// Update the value of an option in lz_options table
29 -function lz_update_option($option_name, $value){
30 -
31 - global $wpdb;
32 -
33 - $result = $wpdb->query("INSERT INTO `".$wpdb->prefix."lz_options` SET `option_name` = '".$option_name."', `option_value` = '".$value."', `updated` = '".time()."' ON DUPLICATE KEY UPDATE `option_value` = '".$value."', `updated` = '".time()."';");
34 -
35 - if(empty($result)){
36 - return false;
37 - }
38 -
39 - return true;
40 -}
41 -
42 -// Execute a select query and return an array
43 -function lz_selectquery($query, $array = 0){
44 - global $wpdb;
45 -
46 - $result = $wpdb->get_results($query, 'ARRAY_A');
47 -
48 - if(empty($array)){
49 - return current($result);
50 - }else{
51 - return $result;
52 - }
53 -}
54 -
55 -// Check if an IP is valid
56 -function lz_valid_ip($ip){
57 -
58 - if(!ip2long($ip)){
59 - return false;
60 - }
61 - return true;
62 -}
63 -
64 -// Check if a field is posted via POST else return default value
65 -function lz_optpost($name, $default = ''){
66 -
67 - if(!empty($_POST[$name])){
68 - return lz_inputsec(lz_htmlizer(trim($_POST[$name])));
69 - }
70 -
71 - return $default;
72 -}
73 -
74 -// Check if a field is posted via GET else return default value
75 -function lz_optget($name, $default = ''){
76 -
77 - if(!empty($_GET[$name])){
78 - return lz_inputsec(lz_htmlizer(trim($_GET[$name])));
79 - }
80 -
81 - return $default;
82 -}
83 -
84 -// Check if a field is posted via GET or POST else return default value
85 -function lz_optreq($name, $default = ''){
86 -
87 - if(!empty($_REQUEST[$name])){
88 - return lz_inputsec(lz_htmlizer(trim($_REQUEST[$name])));
89 - }
90 -
91 - return $default;
92 -}
93 -
94 -function lz_inputsec($string){
95 -
96 - if(!get_magic_quotes_gpc()){
97 -
98 - $string = addslashes($string);
99 -
100 - }else{
101 -
102 - $string = stripslashes($string);
103 - $string = addslashes($string);
104 -
105 - }
106 -
107 - // This is to replace ` which can cause the command to be executed in exec()
108 - $string = str_replace('`', '\`', $string);
109 -
110 - return $string;
111 -
112 -}
113 -
114 -function lz_htmlizer($string){
115 -
116 - $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
117 -
118 - $string = preg_replace('/(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)/e', 'entity_check(\\2);', $string);
119 -
120 - return $string;
121 -
122 -}
123 -
124 -// Check if a checkbox is selected
125 -function lz_is_checked($post){
126 -
127 - if(!empty($_POST[$post])){
128 - return true;
129 - }
130 - return false;
131 -}
132 -
133 -// Reoort an error
134 -function lz_report_error($error = array()){
135 -
136 - if(empty($error)){
137 - return true;
138 - }
139 -
140 - $error_string = '<b>Please fix the below error(s) :</b> <br />';
141 -
142 - foreach($error as $ek => $ev){
143 - $error_string .= '* '.$ev.'<br />';
144 - }
145 -
146 - echo '<div id="message" class="error"><p>'
147 - . __($error_string, 'loginizer')
148 - . '</p></div>';
149 -}
150 -
151 -// Report a notice
152 -function lz_report_notice($notice = array()){
153 -
154 - global $wp_version;
155 -
156 - if(empty($notice)){
157 - return true;
158 - }
159 -
160 - // Which class do we have to use ?
161 - if(version_compare($wp_version, '3.8', '<')){
162 - $notice_class = 'updated';
163 - }else{
164 - $notice_class = 'updated';
165 - }
166 -
167 - $notice_string = '<b>Please check the below notice(s) :</b> <br />';
168 -
169 - foreach($notice as $ek => $ev){
170 - $notice_string .= '* '.$ev.'<br />';
171 - }
172 -
173 - echo '<div id="message" class="'.$notice_class.'"><p>'
174 - . __($notice_string, 'loginizer')
175 - . '</p></div>';
176 -}
177 -
178 -// Convert an objext to array
179 -function lz_objectToArray($d){
180 -
181 - if(is_object($d)){
182 - $d = get_object_vars($d);
183 - }
184 -
185 - if(is_array($d)){
186 - return array_map(__FUNCTION__, $d); // recursive
187 - }elseif(is_object($d)){
188 - return lz_objectToArray($d);
189 - }else{
190 - return $d;
191 - }
192 -}
193 -
194 -// Sanitize variables
195 -function lz_sanitize_variables($variables = array()){
196 -
197 - if(is_array($variables)){
198 - foreach($variables as $k => $v){
199 - $variables[$k] = trim($v);
200 - $variables[$k] = escapeshellcmd($v);
201 - }
202 - }else{
203 - $variables = escapeshellcmd(trim($variables));
204 - }
205 -
206 - return $variables;
207 -}
208 -
209 -// Is multisite ?
210 -function lz_is_multisite() {
211 -
212 - if(function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()){
213 - return true;
214 - }
215 -
216 - return false;
217 -}
218 -
219 -?>
1 +<?php
2 +
3 +include_once(LOGINIZER_DIR.'/IPv6/IPv6.php');
4 +
5 +// Get the client IP
6 +function _lz_getip(){
7 + if(isset($_SERVER["REMOTE_ADDR"])){
8 + return $_SERVER["REMOTE_ADDR"];
9 + }elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
10 + return $_SERVER["HTTP_X_FORWARDED_FOR"];
11 + }elseif(isset($_SERVER["HTTP_CLIENT_IP"])){
12 + return $_SERVER["HTTP_CLIENT_IP"];
13 + }
14 +}
15 +
16 +// Get the client IP
17 +function lz_getip(){
18 +
19 + global $loginizer;
20 +
21 + // Just so that we have something
22 + $ip = _lz_getip();
23 +
24 + $loginizer['ip_method'] = (int) @$loginizer['ip_method'];
25 +
26 + if(isset($_SERVER["REMOTE_ADDR"])){
27 + $ip = $_SERVER["REMOTE_ADDR"];
28 + }
29 +
30 + if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && @$loginizer['ip_method'] == 1){
31 + if(strpos($_SERVER["HTTP_X_FORWARDED_FOR"], ',')){
32 + $temp_ip = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);
33 + $ip = trim($temp_ip[0]);
34 + }else{
35 + $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
36 + }
37 + }
38 +
39 + if(isset($_SERVER["HTTP_CLIENT_IP"]) && @$loginizer['ip_method'] == 2){
40 + $ip = $_SERVER["HTTP_CLIENT_IP"];
41 + }
42 +
43 + if(@$loginizer['ip_method'] == 3 && isset($_SERVER[@$loginizer['custom_ip_method']])){
44 + $ip = $_SERVER[@$loginizer['custom_ip_method']];
45 + }
46 +
47 + // Hacking fix for X-Forwarded-For
48 + if(!lz_valid_ip($ip)){
49 + return '';
50 + }
51 +
52 + return $ip;
53 +
54 +}
55 +
56 +// Execute a select query and return an array
57 +function lz_selectquery($query, $array = 0){
58 + global $wpdb;
59 +
60 + $result = $wpdb->get_results($query, 'ARRAY_A');
61 +
62 + if(empty($array)){
63 + return current($result);
64 + }else{
65 + return $result;
66 + }
67 +}
68 +
69 +// Check if an IP is valid
70 +function lz_valid_ip($ip){
71 +
72 + // IPv6
73 + if(lz_valid_ipv6($ip)){
74 + return true;
75 + }
76 +
77 + // IPv4
78 + if(!ip2long($ip)){
79 + return false;
80 + }
81 +
82 + return true;
83 +}
84 +
85 +function lz_valid_ipv6($ip){
86 +
87 + $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}:))$/';
88 +
89 + if(!preg_match($pattern, $ip)){
90 + return false;
91 + }
92 +
93 + return true;
94 +
95 +}
96 +
97 +// Check if a field is posted via POST else return default value
98 +function lz_optpost($name, $default = ''){
99 +
100 + if(!empty($_POST[$name])){
101 + return lz_inputsec(lz_htmlizer(trim($_POST[$name])));
102 + }
103 +
104 + return $default;
105 +}
106 +
107 +// Check if a field is posted via GET else return default value
108 +function lz_optget($name, $default = ''){
109 +
110 + if(!empty($_GET[$name])){
111 + return lz_inputsec(lz_htmlizer(trim($_GET[$name])));
112 + }
113 +
114 + return $default;
115 +}
116 +
117 +// Check if a field is posted via GET or POST else return default value
118 +function lz_optreq($name, $default = ''){
119 +
120 + if(!empty($_REQUEST[$name])){
121 + return lz_inputsec(lz_htmlizer(trim($_REQUEST[$name])));
122 + }
123 +
124 + return $default;
125 +}
126 +
127 +// For filling in posted values
128 +function lz_POSTval($name, $default = ''){
129 +
130 + return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : $_POST[$name]) : $default);
131 +
132 +}
133 +
134 +function lz_POSTchecked($name, $default = false){
135 +
136 + return (!empty($_POST) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : ''));
137 +
138 +}
139 +
140 +function lz_POSTselect($name, $value, $default = false){
141 +
142 + if(empty($_POST)){
143 + if(!empty($default)){
144 + return 'selected="selected"';
145 + }
146 + }else{
147 + if(isset($_POST[$name])){
148 + if(trim($_POST[$name]) == $value){
149 + return 'selected="selected"';
150 + }
151 + }
152 + }
153 +
154 +}
155 +
156 +function lz_POSTradio($name, $val, $default = null){
157 +
158 + return (!empty($_POST) ? (@$_POST[$name] == $val ? 'checked="checked"' : '') : (!is_null($default) && $default == $val ? 'checked="checked"' : ''));
159 +
160 +}
161 +
162 +function lz_inputsec($string){
163 +
164 + $string = addslashes($string);
165 +
166 + // This is to replace ` which can cause the command to be executed in exec()
167 + $string = str_replace('`', '\`', $string);
168 +
169 + return $string;
170 +
171 +}
172 +
173 +function lz_htmlizer($string){
174 +
175 + $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
176 +
177 + preg_match_all('/(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)/', $string, $matches);//r_print($matches);
178 +
179 + foreach($matches[1] as $mk => $mv){
180 + $tmp_m = lz_entity_check($matches[2][$mk]);
181 + $string = str_replace($matches[1][$mk], $tmp_m, $string);
182 + }
183 +
184 + return $string;
185 +
186 +}
187 +
188 +function lz_entity_check($string){
189 +
190 + //Convert Hexadecimal to Decimal
191 + $num = ((substr($string, 0, 1) === 'x') ? hexdec(substr($string, 1)) : (int) $string);
192 +
193 + //Squares and Spaces - return nothing
194 + $string = (($num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num < 0x20) ? '' : '&#'.$num.';');
195 +
196 + return $string;
197 +
198 +}
199 +
200 +// Check if a checkbox is selected
201 +function lz_is_checked($post){
202 +
203 + if(!empty($_POST[$post])){
204 + return true;
205 + }
206 + return false;
207 +}
208 +
209 +// Reoort an error
210 +function lz_report_error($error = array()){
211 +
212 + if(empty($error)){
213 + return true;
214 + }
215 +
216 + $error_string = '<b>Please fix the below error(s) :</b> <br />';
217 +
218 + foreach($error as $ek => $ev){
219 + $error_string .= '* '.$ev.'<br />';
220 + }
221 +
222 + echo '<div id="message" class="error"><p>'
223 + . __($error_string, 'loginizer')
224 + . '</p></div>';
225 +}
226 +
227 +// Report a notice
228 +function lz_report_notice($notice = array()){
229 +
230 + global $wp_version;
231 +
232 + if(empty($notice)){
233 + return true;
234 + }
235 +
236 + // Which class do we have to use ?
237 + if(version_compare($wp_version, '3.8', '<')){
238 + $notice_class = 'updated';
239 + }else{
240 + $notice_class = 'updated';
241 + }
242 +
243 + $notice_string = '<b>Please check the below notice(s) :</b> <br />';
244 +
245 + foreach($notice as $ek => $ev){
246 + $notice_string .= '* '.$ev.'<br />';
247 + }
248 +
249 + echo '<div id="message" class="'.$notice_class.'"><p>'
250 + . __($notice_string, 'loginizer')
251 + . '</p></div>';
252 +}
253 +
254 +// Convert an objext to array
255 +function lz_objectToArray($d){
256 +
257 + if(is_object($d)){
258 + $d = get_object_vars($d);
259 + }
260 +
261 + if(is_array($d)){
262 + return array_map(__FUNCTION__, $d); // recursive
263 + }elseif(is_object($d)){
264 + return lz_objectToArray($d);
265 + }else{
266 + return $d;
267 + }
268 +}
269 +
270 +// Sanitize variables
271 +function lz_sanitize_variables($variables = array()){
272 +
273 + if(is_array($variables)){
274 + foreach($variables as $k => $v){
275 + $variables[$k] = trim($v);
276 + $variables[$k] = escapeshellcmd($v);
277 + }
278 + }else{
279 + $variables = escapeshellcmd(trim($variables));
280 + }
281 +
282 + return $variables;
283 +}
284 +
285 +// Is multisite ?
286 +function lz_is_multisite() {
287 +
288 + if(function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()){
289 + return true;
290 + }
291 +
292 + return false;
293 +}
294 +
295 +// Generate a random string
296 +function lz_RandomString($length = 10){
297 + $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
298 + $charactersLength = strlen($characters);
299 + $randomString = '';
300 + for($i = 0; $i < $length; $i++){
301 + $randomString .= $characters[rand(0, $charactersLength - 1)];
302 + }
303 + return $randomString;
304 +}
305 +
306 +function lz_print($array){
307 +
308 + echo '<pre>';
309 + print_r($array);
310 + echo '</pre>';
311 +
312 +}
313 +
314 +function lz_cleanpath($path){
315 + $path = str_replace('\\\\', '/', $path);
316 + $path = str_replace('\\', '/', $path);
317 + $path = str_replace('//', '/', $path);
318 + return rtrim($path, '/');
319 +}
320 +
321 +// Returns the Numeric Value of results Per Page
322 +function lz_get_page($get = 'page', $resperpage = 50){
323 +
324 + $resperpage = (!empty($_REQUEST['reslen']) && is_numeric($_REQUEST['reslen']) ? (int) lz_optreq('reslen') : $resperpage);
325 +
326 + if(lz_optget($get)){
327 + $pg = (int) lz_optget($get);
328 + $pg = $pg - 1;
329 + $page = ($pg * $resperpage);
330 + $page = ($page <= 0 ? 0 : $page);
331 + }else{
332 + $page = 0;
333 + }
334 + return $page;
335 +}
336 +
337 +// Replaces the Variables with the supplied ones
338 +function lz_lang_vars_name($str, $array){
339 +
340 + foreach($array as $k => $v){
341 +
342 + $str = str_replace('$'.$k, $v, $str);
343 +
344 + }
345 +
346 + return $str;
347 +
348 +}