-
Notifications
You must be signed in to change notification settings - Fork 1
/
xbd.js
executable file
·194 lines (160 loc) · 5.13 KB
/
xbd.js
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
/*
$Id: v 1.0 2010// 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 array() {
return Array.prototype.slice.call(arguments);
}
function empty(mixed_var) {
var key;
if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'undefined') {
return true;
}
if (typeof mixed_var == 'object') {
for (key in mixed_var) {
return false;
}
return true;
}
return false;
}
function f(s) {
return !empty(s);
}
function w(a, d) {
if (!f(a) || !is_string(a)) return {};
e = a.split(' ');
if (d !== false) {
for (i in e) {
e[e[i]] = d
delete e[i]
}
}
return e;
}
var xbd = {
browser_list, browser_type, platforms, agent = '',
xbd: function() {
/*
If you want to add more browsers, be careful because 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 = {
mobile: 'nokia motorola samsung sonyericsson blackberry iphone fennec minimo htc',
console: 'wii playstation',
bot: 'googlebot googlebot-image feedfetcher-google gigabot msnbot bloglines'
};
this.platforms = {
linux: w('linux'),
mac: array('macintosh', 'mac platform x', 'mac os x'),
windows: w('windows win32')
}
this.agent = strtolower(this.v('HTTP_USER_AGENT'));
},
//_browser: function(a_browser = false, a_version = false, name = false, d_name = false, ret_ary = false)
_browser: function(a_browser, a_version, name, d_name, ret_ary) {
var user_browser = this.agent;
var 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_browser;
}
vw = w('user_browser a_browser a_version name d_name');
for (i in vw) {
row = vw[i];
vrow = row;
if (is_string(vrow)) {
row = strtolower(vrow);
}
}
browser_limit = user_browser.length;
wbl = w(browser_list);
for (i in wbl) {
row = wbl[i];
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 {browser: this_browser, version: this_version, platform: this_platform, type: this_type, useragent: user_browser};
}
}