-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxbd_object.php
executable file
·201 lines (165 loc) · 5.13 KB
/
xbd_object.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/*
$Id: v 1.4 2009/12/08 11:22:00 $
<XBD, Extended Browser Detection.>
Copyright (C) <2009> <Guillermo Azurdia, www.nopticon.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function _print($name, $ret) {
echo $name . '<br />';
if (!f($ret)) {
$ret = 'false';
} elseif ($ret == '1') {
$ret = 'true';
}
echo '<blockquote><pre>';
print_r($ret);
echo '</pre></blockquote>';
return;
}
function f($s) {
return !empty($s);
}
function w($a = '', $d = false) {
if (!f($a) || !is_string($a)) return array();
$e = explode(' ', $a);
if ($d !== false) {
foreach ($e as $i => $v) {
$e[$v] = $d;
unset($e[$i]);
}
}
return $e;
}
class xbd {
private $browser_list, $browser_type, $platforms, $agent, $http;
public function __construct() {
/*
If you want to add more browsers, do it but be careful... order matters.
*/
$this->browser_list = 'nokia motorola samsung sonyericsson blackberry iphone htc ';
$this->browser_list .= 'flock firefox konqueror lobo msie netscape navigator mosaic netsurf lynx amaya omniweb ';
$this->browser_list .= 'googlebot googlebot-image feedfetcher-google gigabot msnbot thunderbird fennec minimo ';
$this->browser_list .= 'minefield chrome wget cheshire safari avant camino seamonkey aol bloglines ';
$this->browser_list .= 'wii playstation netfront opera mozilla gecko ubuntu';
$this->browser_type = array(
'mobile' => 'nokia motorola samsung sonyericsson blackberry iphone fennec minimo htc',
'console' => 'wii playstation',
'bot' => 'googlebot googlebot-image feedfetcher-google gigabot msnbot bloglines'
);
$this->platforms = array(
'linux' => w('linux'),
'mac' => array('macintosh', 'mac platform x', 'mac os x'),
'windows' => w('windows win32')
);
$this->agent = strtolower($this->v('HTTP_USER_AGENT'));
return;
}
private function v($a) {
if (!isset($this->http[$a])) {
$this->http[$a] = (isset($_SERVER[$a])) ? $_SERVER[$a] : '';
}
return $this->http[$a];
}
public function _browser($a_browser = false, $a_version = false, $name = false, $d_name = false, $ret_ary = false) {
$user_browser = $this->agent;
$this_version = $this_browser = $this_platform = '';
if ($a_browser == '*') {
$a_browser = $a_version = $name = false;
$d_name = true;
}
if ($a_browser === false && $a_version === false && $name === false && $d_name !== false) {
return $user_agent;
}
foreach (w('user_browser a_browser a_version name d_name') as $row) {
$vrow = ${$row};
if (is_string($vrow)) {
${$row} = strtolower($vrow);
}
}
$browser_limit = strlen($user_browser);
foreach (w($browser_list) as $row) {
$row = ($a_browser !== false) ? $a_browser : $row;
$n = stristr($user_browser, $row);
if (!$n || f($this_browser)) continue;
$this_browser = $row;
$j = strpos($user_browser, $row) + strlen($row);
$j2 = substr($user_browser, $j, 1);
if (preg_match('#[\/\_\-\ ]#', $j2)) {
$j += 1;
}
for (; $j <= $browser_limit; $j++) {
$s = trim(substr($user_browser, $j, 1));
if (!preg_match('/[\w\.\-]/', $s)) break;
$this_version .= $s;
}
}
if ($a_browser !== false && ($d_name === false || $name === true) && $ret_ary === false) {
$ret = false;
if (strtolower($a_browser) == $this_browser) {
$ret = true;
if ($a_version !== false) {
if (f($this_version)) {
$a_sign = explode(' ', $a_version);
if (version_compare($this_version, $a_sign[1], $a_sign[0]) === false) {
$ret = false;
$vf = true;
}
} else {
$ret = false;
}
}
}
if ($name !== true) {
return $ret;
}
}
foreach ($platforms as $os => $match) {
foreach ($match as $os_name) {
if (strpos($user_browser, $os_name) !== false) {
$this_platform = $os;
break 2;
}
}
}
$this_type = '';
if (f($this_browser)) {
foreach ($browser_type as $type => $browsers) {
foreach (w($browsers) as $row) {
if (strpos($this_browser, $row) !== false) {
$this_type = $type;
break 2;
}
}
}
if (!$this_type) $this_type = 'desktop';
}
if ($name !== false && $ret_ary === false) {
if ($a_browser !== false && $a_version !== false && $ret === false) {
return false;
}
$s_browser = '';
$s_data = array($this_type, $this_platform, $this_browser, $this_version);
foreach ($s_data as $row) {
if (f($row)) $s_browser .= (($s_browser != '') ? ' ' : '') . $row;
}
return $s_browser;
}
return array(
'browser' => $this_browser,
'version' => $this_version,
'platform' => $this_platform,
'type' => $this_type,
'useragent' => $user_browser
);
}
}