PluginProbe
Loginizer / 1.3.2
Loginizer v1.3.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 1.3.2, at functions.php

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