PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.3.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.3.2
V3.3.2 3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 All 139 releases
← All changes | includes/Core/Util/IpTool.php +197 -151 2.0 → V3.3.2 View file →
@@ -5,9 +5,10 @@
5 5 */
6 6
7 7 namespace BitCode\BitForm\Core\Util;
8 8
9 -final class IpTool {
9 +final class IpTool
10 +{
10 11 /**
11 12 * Check ip address
12 13 *
13 14 * @return string IP address of current visitor
@@ -13,54 +14,92 @@
13 14 * @return string IP address of current visitor
14 15 */
15 16
16 17 /**
18 + * Stored form of an IP: IPv4 as unsigned number (existing rows), IPv6 as text (numeric form was lossy).
17 19 *
18 - ipaddress converted to number digit
19 - */
20 - private static function ip2Number($ipAdr) {
21 - $ipTobytes = @inet_pton($ipAdr);
20 + * @param mixed $ip IP address
21 + *
22 + * @return string '' when $ip is not a valid address
23 + */
24 + public static function storageValue($ip)
25 + {
26 + if (!is_string($ip) || false === filter_var($ip, FILTER_VALIDATE_IP)) {
27 + return '';
28 + }
29 + if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
30 + return sprintf('%u', ip2long($ip));
31 + }
32 + $packed = inet_pton($ip);
22 33
23 - if (!$ipTobytes) {
24 - return false;
34 + return false === $packed ? '' : (string) inet_ntop($packed);
35 + }
36 +
37 + /**
38 + * Readable IP for a stored user_ip value.
39 + *
40 + * @param mixed $stored Value from user_ip
41 + *
42 + * @return string IP address, or '' for empty/lossy pre-3.3.2 IPv6 values
43 + */
44 + public static function displayValue($stored)
45 + {
46 + $stored = trim((string) $stored);
47 + if ('' === $stored) {
48 + return '';
25 49 }
50 + if (ctype_digit($stored)) {
51 + return (strlen($stored) <= 10 && (float) $stored <= 4294967295) ? long2ip((int) $stored) : '';
52 + }
26 53
27 - $number = '';
28 - foreach (unpack('C*', $ipTobytes) as $byte) {
29 - $number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
54 + return false === filter_var($stored, FILTER_VALIDATE_IP) ? '' : $stored;
55 + }
56 +
57 + /**
58 + * First valid IP in a client-controlled header value; anything else is rejected (injection guard).
59 + *
60 + * @param mixed $value Raw header value
61 + *
62 + * @return string IP address, or ''
63 + */
64 + public static function extractValidIp($value)
65 + {
66 + if (!is_string($value) || '' === $value) {
67 + return '';
30 68 }
31 69
32 - return base_convert(ltrim($number, '0'), 2, 10);
33 - }
70 + $ipv4Pattern = '/(?<![\d.])(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}(?![\d.])/';
34 71
35 - private static function validateIpAddress($ip) {
36 - $ipv4Pattern = '/(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}/';
37 - $ipv6Pattern = '/([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})\:([A-Fa-f0-9]{1,4})/';
72 + foreach (preg_split('/[\s,;]+/', $value) as $part) {
73 + $part = trim(preg_replace('/^for=/i', '', $part), "\"'");
74 + if (preg_match('/^\[([^\]]+)\]/', $part, $bracketed)) {
75 + $part = $bracketed[1];
76 + }
38 77
39 - if (preg_match($ipv4Pattern, $ip, $patternMatchIp)) {
40 - $ip = $patternMatchIp[0];
41 - } elseif (preg_match($ipv6Pattern, $ip, $patternMatchIp)) {
42 - $ip = $patternMatchIp[0];
78 + if (false !== filter_var($part, FILTER_VALIDATE_IP)) {
79 + return $part;
80 + }
81 +
82 + // IPv4 with port, e.g. "203.0.113.7:8080"
83 + if (preg_match($ipv4Pattern, $part, $match) && false !== filter_var($match[0], FILTER_VALIDATE_IP)) {
84 + return $match[0];
85 + }
43 86 }
44 87
45 - return $ip;
88 + return '';
46 89 }
47 90
48 - private static function _checkIP() {
49 - if (getenv('HTTP_CLIENT_IP')) {
50 - $ip = getenv('HTTP_CLIENT_IP');
51 - } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
52 - $ip = getenv('HTTP_X_FORWARDED_FOR');
53 - } elseif (getenv('HTTP_X_FORWARDED')) {
54 - $ip = getenv('HTTP_X_FORWARDED');
55 - } elseif (getenv('HTTP_FORWARDED_FOR')) {
56 - $ip = getenv('HTTP_FORWARDED_FOR');
57 - } elseif (getenv('HTTP_FORWARDED')) {
58 - $ip = getenv('HTTP_FORWARDED');
59 - } else {
60 - $ip = $_SERVER['REMOTE_ADDR'];
91 + private static function _checkIP()
92 + {
93 + $headers = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED'];
94 + foreach ($headers as $header) {
95 + $ip = IpTool::extractValidIp(getenv($header));
96 + if ('' !== $ip) {
97 + return $ip;
98 + }
61 99 }
62 - return IpTool::validateIpAddress($ip);
100 +
101 + return IpTool::extractValidIp(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
63 102 }
64 103
65 104 /**
66 105 * Check device info
@@ -66,11 +105,12 @@
66 105 * Check device info
67 106 *
68 107 * @return void
69 108 */
70 - private static function _checkDevice() {
109 + private static function _checkDevice()
110 + {
71 111 if (isset($_SERVER, $_SERVER['HTTP_USER_AGENT'])) {
72 - $user_agent = $_SERVER['HTTP_USER_AGENT'];
112 + $user_agent = sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']));
73 113 } else {
74 114 $user_agent = '';
75 115 }
76 116 return IpTool::_getBrowserName($user_agent) . '|' . IpTool::_getOS($user_agent);
@@ -84,15 +124,16 @@
84 124 * @param string $user_agent $_SERVER['HTTP_USER_AGENT']
85 125 *
86 126 * @return void
87 127 */
88 - private static function _getBrowserName($user_agent) {
128 + private static function _getBrowserName($user_agent)
129 + {
89 130 // Make case insensitive.
90 131 $t = strtolower($user_agent);
91 132
92 133 // If the string *starts* with the string, strpos returns 0 (i.e., FALSE). Do a ghetto hack and start with a space.
93 134 // "[strpos()] may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE."
94 - // http://php.net/manual/en/function.strpos.php
135 + // http://php.net/manual/en/function.strpos.php
95 136 $t = ' ' . $t;
96 137
97 138 // Humans / Regular Users
98 139 if (strpos($t, 'opera') || strpos($t, 'opr/')) {
@@ -162,132 +203,134 @@
162 203 * @link https://stackoverflow.com/questions/18070154/get-operating-system-info
163 204 *
164 205 * @return void
165 206 */
166 - private static function _getOS($user_agent) {
167 - $ros[] = ['Windows XP', 'Windows XP'];
168 - $ros[] = ['Windows NT 5.1|Windows NT5.1', 'Windows XP'];
169 - $ros[] = ['Windows 2000', 'Windows 2000'];
170 - $ros[] = ['Windows NT 5.0', 'Windows 2000'];
171 - $ros[] = ['Windows NT 4.0|WinNT4.0', 'Windows NT'];
172 - $ros[] = ['Windows NT 5.2', 'Windows Server 2003'];
173 - $ros[] = ['Windows NT 6.0', 'Windows Vista'];
174 - $ros[] = ['Windows NT 7.0', 'Windows 7'];
175 - $ros[] = ['Windows CE', 'Windows CE'];
176 - $ros[] = [
177 - '(media center pc).([0-9]{1,2}\.[0-9]{1,2})',
178 - 'Windows Media Center',
179 - ];
180 - $ros[] = ['(win)([0-9]{1,2}\.[0-9x]{1,2})', 'Windows'];
181 - $ros[] = ['(win)([0-9]{2})', 'Windows'];
182 - $ros[] = ['(windows)([0-9x]{2})', 'Windows'];
207 + private static function _getOS($user_agent)
208 + {
209 + $ros[] = ['Windows XP', 'Windows XP', false];
210 + $ros[] = ['Windows NT 5.1|Windows NT5.1', 'Windows XP', true];
211 + $ros[] = ['Windows 2000', 'Windows 2000', false];
212 + $ros[] = ['Windows NT 5.0', 'Windows 2000', false];
213 + $ros[] = ['Windows NT 4.0|WinNT4.0', 'Windows NT', true];
214 + $ros[] = ['Windows NT 5.2', 'Windows Server 2003', false];
215 + $ros[] = ['Windows NT 6.0', 'Windows Vista', false];
216 + $ros[] = ['Windows NT 7.0', 'Windows 7', false];
217 + $ros[] = ['Windows CE', 'Windows CE', false];
218 + $ros[] = ['(media center pc).([0-9]{1,2}\.[0-9]{1,2})', 'Windows Media Center', true];
219 + $ros[] = ['(win)([0-9]{1,2}\.[0-9x]{1,2})', 'Windows', true];
220 + $ros[] = ['(win)([0-9]{2})', 'Windows', true];
221 + $ros[] = ['(windows)([0-9x]{2})', 'Windows', true];
183 222 // Doesn't seem like these are necessary...not totally sure though..
184 223 //$ros[] = array('(winnt)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'Windows NT');
185 224 //$ros[] = array('(windows nt)(([0-9]{1,2}\.[0-9]{1,2}){0,1})', 'Windows NT'); // fix by bg
186 - $ros[] = ['Windows ME', 'Windows ME'];
187 - $ros[] = ['Win 9x 4.90', 'Windows ME'];
188 - $ros[] = ['Windows 98|Win98', 'Windows 98'];
189 - $ros[] = ['Windows 95', 'Windows 95'];
190 - $ros[] = ['(windows)([0-9]{1,2}\.[0-9]{1,2})', 'Windows'];
191 - $ros[] = ['win32', 'Windows'];
192 - $ros[] = ['(java)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})', 'Java'];
193 - $ros[] = ['(Solaris)([0-9]{1,2}\.[0-9x]{1,2}){0,1}', 'Solaris'];
194 - $ros[] = ['dos x86', 'DOS'];
195 - $ros[] = ['unix', 'Unix'];
225 + $ros[] = ['Windows ME', 'Windows ME', false];
226 + $ros[] = ['Win 9x 4.90', 'Windows ME', false];
227 + $ros[] = ['Windows 98|Win98', 'Windows 98', true];
228 + $ros[] = ['Windows 95', 'Windows 95', false];
229 + $ros[] = ['(windows)([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
230 + $ros[] = ['win32', 'Windows', false];
231 + $ros[] = ['(java)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})', 'Java', true];
232 + $ros[] = ['(Solaris)([0-9]{1,2}\.[0-9x]{1,2}){0,1}', 'Solaris', true];
233 + $ros[] = ['dos x86', 'DOS', false];
234 + $ros[] = ['unix', 'Unix', false];
196 235 //Android
197 - $ros[] = ['SM', 'Samsung'];
198 - $ros[] = ['HTC', 'HTC'];
199 - $ros[] = ['LG', 'LG'];
200 - $ros[] = ['Microsoft', 'Microsoft'];
201 - $ros[] = ['Pixel', 'Pixel'];
202 - $ros[] = ['MI', 'Xiaomi'];
203 - $ros[] = ['Xiaomi', 'Xiaomi'];
204 - $ros[] = ['Android', 'Android'];
205 - $ros[] = ['android', 'Android'];
236 + $ros[] = ['SM', 'Samsung', false];
237 + $ros[] = ['HTC', 'HTC', false];
238 + $ros[] = ['LG', 'LG', false];
239 + $ros[] = ['Microsoft', 'Microsoft', false];
240 + $ros[] = ['Pixel', 'Pixel', false];
241 + $ros[] = ['MI', 'Xiaomi', false];
242 + $ros[] = ['Xiaomi', 'Xiaomi', false];
243 + $ros[] = ['Android', 'Android', false];
244 + $ros[] = ['android', 'Android', false];
206 245
207 246 //iPhone
208 - $ros[] = ['iPhone', 'iPhone'];
247 + $ros[] = ['iPhone', 'iPhone', false];
209 248
210 - $ros[] = ['Mac OS X', 'Mac OS X'];
211 - $ros[] = ['Mac OS X Puma', 'Mac OS X 10.1[^0-9]'];
212 - $ros[] = ['Mac_PowerPC', 'Macintosh PowerPC'];
213 - $ros[] = ['(mac|Macintosh)', 'Mac OS'];
214 - $ros[] = ['(sunos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'SunOS'];
215 - $ros[] = ['(beos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'BeOS'];
216 - $ros[] = ['(risc os)([0-9]{1,2}\.[0-9]{1,2})', 'RISC OS'];
217 - $ros[] = ['os\/2', 'OS/2'];
218 - $ros[] = ['freebsd', 'FreeBSD'];
219 - $ros[] = ['openbsd', 'OpenBSD'];
220 - $ros[] = ['netbsd', 'NetBSD'];
221 - $ros[] = ['irix', 'IRIX'];
222 - $ros[] = ['plan9', 'Plan9'];
223 - $ros[] = ['osf', 'OSF'];
224 - $ros[] = ['aix', 'AIX'];
225 - $ros[] = ['GNU Hurd', 'GNU Hurd'];
226 - $ros[] = ['(fedora)', 'Linux - Fedora'];
227 - $ros[] = ['(kubuntu)', 'Linux - Kubuntu'];
228 - $ros[] = ['(ubuntu)', 'Linux - Ubuntu'];
229 - $ros[] = ['(debian)', 'Linux - Debian'];
230 - $ros[] = ['(CentOS)', 'Linux - CentOS'];
231 - $ros[] = [
232 - '(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)',
233 - 'Linux - Mandriva',
234 - ];
235 - $ros[] = [
236 - '(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)',
237 - 'Linux - SUSE',
238 - ];
239 - $ros[] = ['(Dropline)', 'Linux - Slackware (Dropline GNOME)'];
240 - $ros[] = ['(ASPLinux)', 'Linux - ASPLinux'];
241 - $ros[] = ['(Red Hat)', 'Linux - Red Hat'];
249 + $ros[] = ['Mac OS X', 'Mac OS X', false];
250 + $ros[] = ['Mac OS X Puma', 'Mac OS X 10.1[^0-9]', true];
251 + $ros[] = ['Mac_PowerPC', 'Macintosh PowerPC', false];
252 + $ros[] = ['(mac|Macintosh)', 'Mac OS', true];
253 + $ros[] = ['(sunos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'SunOS', true];
254 + $ros[] = ['(beos)([0-9]{1,2}\.[0-9]{1,2}){0,1}', 'BeOS', true];
255 + $ros[] = ['(risc os)([0-9]{1,2}\.[0-9]{1,2})', 'RISC OS', true];
256 + $ros[] = ['os\/2', 'OS/2', true];
257 + $ros[] = ['freebsd', 'FreeBSD', false];
258 + $ros[] = ['openbsd', 'OpenBSD', false];
259 + $ros[] = ['netbsd', 'NetBSD', false];
260 + $ros[] = ['irix', 'IRIX', false];
261 + $ros[] = ['plan9', 'Plan9', false];
262 + $ros[] = ['osf', 'OSF', false];
263 + $ros[] = ['aix', 'AIX', false];
264 + $ros[] = ['GNU Hurd', 'GNU Hurd', false];
265 + $ros[] = ['(fedora)', 'Linux - Fedora', true];
266 + $ros[] = ['(kubuntu)', 'Linux - Kubuntu', true];
267 + $ros[] = ['(ubuntu)', 'Linux - Ubuntu', true];
268 + $ros[] = ['(debian)', 'Linux - Debian', true];
269 + $ros[] = ['(CentOS)', 'Linux - CentOS', true];
270 + $ros[] = ['(Mandriva).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - Mandriva', true];
271 + $ros[] = ['(SUSE).([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?)', 'Linux - SUSE', true];
272 + $ros[] = ['(Dropline)', 'Linux - Slackware (Dropline GNOME)', true];
273 + $ros[] = ['(ASPLinux)', 'Linux - ASPLinux', true];
274 + $ros[] = ['(Red Hat)', 'Linux - Red Hat', true];
242 275 // Loads of Linux machines will be detected as unix.
243 276 // Actually, all of the linux machines I've checked have the 'X11' in the User Agent.
244 277 //$ros[] = array('X11', 'Unix');
245 - $ros[] = ['(linux)', 'Linux'];
246 - $ros[] = ['(amigaos)([0-9]{1,2}\.[0-9]{1,2})', 'AmigaOS'];
247 - $ros[] = ['amiga-aweb', 'AmigaOS'];
248 - $ros[] = ['amiga', 'Amiga'];
249 - $ros[] = ['AvantGo', 'PalmOS'];
278 + $ros[] = ['(linux)', 'Linux', true];
279 + $ros[] = ['(amigaos)([0-9]{1,2}\.[0-9]{1,2})', 'AmigaOS', true];
280 + $ros[] = ['amiga-aweb', 'AmigaOS', false];
281 + $ros[] = ['amiga', 'Amiga', false];
282 + $ros[] = ['AvantGo', 'PalmOS', false];
250 283 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1}-([0-9]{1,2}) i([0-9]{1})86){1}', 'Linux');
251 284 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1} i([0-9]{1}86)){1}', 'Linux');
252 285 //$ros[] = array('(Linux)([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}(rel\.[0-9]{1,2}){0,1})', 'Linux');
253 - $ros[] = ['[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})', 'Linux'];
254 - $ros[] = ['(webtv)/([0-9]{1,2}\.[0-9]{1,2})', 'WebTV'];
255 - $ros[] = ['Dreamcast', 'Dreamcast OS'];
256 - $ros[] = ['GetRight', 'Windows'];
257 - $ros[] = ['go!zilla', 'Windows'];
258 - $ros[] = ['gozilla', 'Windows'];
259 - $ros[] = ['gulliver', 'Windows'];
260 - $ros[] = ['ia archiver', 'Windows'];
261 - $ros[] = ['NetPositive', 'Windows'];
262 - $ros[] = ['mass downloader', 'Windows'];
263 - $ros[] = ['microsoft', 'Windows'];
264 - $ros[] = ['offline explorer', 'Windows'];
265 - $ros[] = ['teleport', 'Windows'];
266 - $ros[] = ['web downloader', 'Windows'];
267 - $ros[] = ['webcapture', 'Windows'];
268 - $ros[] = ['webcollage', 'Windows'];
269 - $ros[] = ['webcopier', 'Windows'];
270 - $ros[] = ['webstripper', 'Windows'];
271 - $ros[] = ['webzip', 'Windows'];
272 - $ros[] = ['wget', 'Windows'];
273 - $ros[] = ['Java', 'Unknown'];
274 - $ros[] = ['flashget', 'Windows'];
286 + $ros[] = ['[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3}', 'Linux', true];
287 + $ros[] = ['(webtv)/([0-9]{1,2}\.[0-9]{1,2})', 'WebTV', true];
288 + $ros[] = ['Dreamcast', 'Dreamcast OS', false];
289 + $ros[] = ['GetRight', 'Windows', false];
290 + $ros[] = ['go!zilla', 'Windows', false];
291 + $ros[] = ['gozilla', 'Windows', false];
292 + $ros[] = ['gulliver', 'Windows', false];
293 + $ros[] = ['ia archiver', 'Windows', false];
294 + $ros[] = ['NetPositive', 'Windows', false];
295 + $ros[] = ['mass downloader', 'Windows', false];
296 + $ros[] = ['microsoft', 'Windows', false];
297 + $ros[] = ['offline explorer', 'Windows', false];
298 + $ros[] = ['teleport', 'Windows', false];
299 + $ros[] = ['web downloader', 'Windows', false];
300 + $ros[] = ['webcapture', 'Windows', false];
301 + $ros[] = ['webcollage', 'Windows', false];
302 + $ros[] = ['webcopier', 'Windows', false];
303 + $ros[] = ['webstripper', 'Windows', false];
304 + $ros[] = ['webzip', 'Windows', false];
305 + $ros[] = ['wget', 'Windows', false];
306 + $ros[] = ['Java', 'Unknown', false];
307 + $ros[] = ['flashget', 'Windows', false];
275 308 // delete next line if the script show not the right OS
276 309 //$ros[] = array('(PHP)/([0-9]{1,2}.[0-9]{1,2})', 'PHP');
277 - $ros[] = ['MS FrontPage', 'Windows'];
278 - $ros[] = ['(msproxy)/([0-9]{1,2}.[0-9]{1,2})', 'Windows'];
279 - $ros[] = ['(msie)([0-9]{1,2}.[0-9]{1,2})', 'Windows'];
280 - $ros[] = ['libwww-perl', 'Unix'];
281 - $ros[] = ['UP.Browser', 'Windows CE'];
282 - $ros[] = ['NetAnts', 'Windows'];
283 - $ros[] = ['Android', 'Android'];
310 + $ros[] = ['MS FrontPage', 'Windows', false];
311 + $ros[] = ['(msproxy)/([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
312 + $ros[] = ['(msie)([0-9]{1,2}\.[0-9]{1,2})', 'Windows', true];
313 + $ros[] = ['libwww-perl', 'Unix', false];
314 + $ros[] = ['UP.Browser', 'Windows CE', false];
315 + $ros[] = ['NetAnts', 'Windows', false];
316 + $ros[] = ['Android', 'Android', false];
284 317 $file = count($ros);
285 318 $os = '';
286 319 for ($n = 0; $n < $file; $n++) {
287 - if (@preg_match('/' . $ros[$n][0] . '/i', $user_agent)) {
288 - $os = @$ros[$n][1];
289 - break;
320 + $isRegex = isset($ros[$n][2]) && true === $ros[$n][2];
321 + $pattern = $ros[$n][0];
322 +
323 + if ($isRegex) {
324 + if (@preg_match('/' . $pattern . '/i', $user_agent)) {
325 + $os = $ros[$n][1];
326 + break;
327 + }
328 + } else {
329 + if (false !== stripos($user_agent, $pattern)) {
330 + $os = $ros[$n][1];
331 + break;
332 + }
290 333 }
291 334 }
292 335 return trim($os);
293 336 }
@@ -294,13 +337,14 @@
294 337
295 338 /**
296 339 * Set user details ip,cdevice, user_id, user's visited page, current mysql formatted time
297 340 *
298 - * @return Array of user details
341 + * @return array of user details
299 342 */
300 - private static function _setUserDetail() {
343 + private static function _setUserDetail()
344 + {
301 345 $referer = wp_get_referer();
302 - $user_details['ip'] = IpTool::ip2Number(IpTool::_checkIP());
346 + $user_details['ip'] = IpTool::storageValue(IpTool::_checkIP());
303 347 $user_details['device'] = IpTool::_checkDevice();
304 348 $user_details['id'] = get_current_user_id();
305 349 $user_details['page'] = $referer ? $referer : '';
306 350 $user_details['time'] = current_time('mysql');
@@ -310,11 +354,12 @@
310 354
311 355 /**
312 356 * Provide user details
313 357 *
314 - * @return _setUserDetail user details array
358 + * @return array user details array
315 359 */
316 - public static function getUserDetail() {
360 + public static function getUserDetail()
361 + {
317 362 return IpTool::_setUserDetail();
318 363 }
319 364
320 365 /**
@@ -319,10 +364,11 @@
319 364
320 365 /**
321 366 * Provide user IP address
322 367 *
323 - * @return ip
368 + * @return string IP address, or ''
324 369 */
325 - public static function getIP() {
370 + public static function getIP()
371 + {
326 372 return IpTool::_checkIP();
327 373 }
328 374 }