31733e08 |
1 | <?php |
a5813ca3 |
2 | /* ***** BEGIN LICENSE BLOCK ***** |
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 | * |
5 | * The contents of this file are subject to the Mozilla Public License Version |
6 | * 1.1 (the "License"); you may not use this file except in compliance with |
7 | * the License. You may obtain a copy of the License at |
8 | * http://www.mozilla.org/MPL/ |
9 | * |
10 | * Software distributed under the License is distributed on an "AS IS" basis, |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
12 | * for the specific language governing rights and limitations under the |
13 | * License. |
14 | * |
15 | * The Original Code is KaiRo's userAgent detection. |
16 | * |
17 | * The Initial Developer of the Original Code is |
18 | * KaiRo - Robert Kaiser. |
19 | * Portions created by the Initial Developer are Copyright (C) 2003 |
20 | * the Initial Developer. All Rights Reserved. |
21 | * |
22 | * Contributor(s): Robert Kaiser <kairo@kairo.at> |
23 | * |
24 | * Alternatively, the contents of this file may be used under the terms of |
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
27 | * in which case the provisions of the GPL or the LGPL are applicable instead |
28 | * of those above. If you wish to allow use of your version of this file only |
29 | * under the terms of either the GPL or the LGPL, and not to allow others to |
30 | * use your version of this file under the terms of the MPL, indicate your |
31 | * decision by deleting the provisions above and replace them with the notice |
32 | * and other provisions required by the GPL or the LGPL. If you do not delete |
33 | * the provisions above, a recipient may use your version of this file under |
34 | * the terms of any one of the MPL, the GPL or the LGPL. |
35 | * |
36 | * ***** END LICENSE BLOCK ***** */ |
37 | |
31733e08 |
38 | class userAgent { |
39 | // userAgent PHP class |
40 | // get user agent and tell us what Browser is accessing |
41 | // |
1defa974 |
42 | // function userAgent([$ua_string]) |
43 | // CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables. |
31733e08 |
44 | // |
45 | // var $uastring |
46 | // the plain User Agent string |
47 | // var $brand |
bf78d3ed |
48 | // the User Agent brand name |
31733e08 |
49 | // var $version |
50 | // the User Agent version |
a8464009 |
51 | // var $bot |
52 | // bool: true if this agent is a bot |
f983aa36 |
53 | // var $uadata |
54 | // array of static user agent data (static vars in functions are set for all objects of this class!) |
31733e08 |
55 | // |
23585ba2 |
56 | // function getBrand() |
57 | // returns the User Agent Brand Name |
bf78d3ed |
58 | // |
23585ba2 |
59 | // function getVersion() |
60 | // returns the User Agent version |
61 | // |
4210e7b0 |
62 | // function getAcceptLanguages() |
63 | // returns an associated array with the accepted languages of this UA |
64 | // keys are language codes, values are q factors (weights) |
65 | // |
f983aa36 |
66 | // function getUAString() |
67 | // returns the full User Agent string |
68 | // |
bf78d3ed |
69 | // function getEngine() |
70 | // returns a string telling the detected rendering engine, null if we can't detect |
71 | // one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|unkown |
72 | // |
73 | // function hasEngine($rnd_engine) |
74 | // returns true if the given rendering engine was detected |
75 | // |
76 | // function getEngineVersion() |
77 | // returns a the version number for the rendering engine |
78 | // this may be the same as getVersion() for many engines, or null if we don't know |
79 | // |
80 | // function getOS() |
81 | // returns a string telling the detected operating system, null if we can't detect |
82 | // might be very verbose, uses no abbreviations for most names |
83 | // |
84 | // function getPlatform() |
85 | // returns a string telling the detected OS platform, null if we can't detect |
86 | // one of windows|linux|mac|solaris|unkown |
87 | // |
88 | // function getLanguage() { |
89 | // returns a string telling the detected browser UI language, null if we can't detect |
90 | // should be an ISO code |
91 | // |
92 | // function isBot() |
a8464009 |
93 | // returns true if User Agent seems to be a bot |
bf78d3ed |
94 | // |
95 | // *** functions that only return useable info for some agents *** |
96 | // |
97 | // function getGeckoDate() |
98 | // returns the Gecko date for Gecko-based browsers, null for others |
99 | // |
100 | // *** functions for compat to older versions of this class *** |
101 | // |
31733e08 |
102 | // function isns() |
103 | // returns true if User Agent seems to be Netscape brand, false if not |
104 | // function isns4() |
105 | // returns true if User Agent seems to be Netscape Communicator 4.x, false if not |
106 | // function isie() |
107 | // returns true if User Agent seems to be a version of Internet Exploder, false if not |
108 | // function geckobased() |
109 | // returns true if User Agent seems to be a Gecko-based browser, false if not |
110 | // function geckodate() |
111 | // returns the Gecko date when it's a Gecko-based browser, 0 if not |
1defa974 |
112 | // function khtmlbased() |
113 | // returns true if User Agent seems to be a KHTML-based browser, false if not |
114 | |
115 | // collection of some known User Agent Strings: |
bf78d3ed |
116 | // *** see testbed/ua_list_raw.txt *** |
117 | // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html *** |
31733e08 |
118 | |
31733e08 |
119 | var $uastring; |
120 | var $brand; |
121 | var $version; |
a8464009 |
122 | var $bot = false; |
f983aa36 |
123 | var $uadata = array(); |
31733e08 |
124 | |
4210e7b0 |
125 | function userAgent($ua_string = '') { |
31733e08 |
126 | // *** constructor *** |
1defa974 |
127 | if (strlen($ua_string)) { |
128 | $this->uastring = $ua_string; |
129 | } |
130 | else { |
131 | // read raw UA string |
4210e7b0 |
132 | $this->uastring = $_SERVER['HTTP_USER_AGENT']; |
1defa974 |
133 | } |
31733e08 |
134 | |
135 | // get UA brand and version |
bf78d3ed |
136 | $this->brand = 'Unknown'; $this->version = null; |
137 | // find reasonable defaults |
6e783db6 |
138 | if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/([0-9a-zA-Z\._+-]+)|', $this->uastring, $regs)) { |
bf78d3ed |
139 | $this->brand = trim($regs[1]); |
140 | $this->version = $regs[2]; |
141 | } |
142 | elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?([0-9][0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
143 | $this->brand = trim($regs[1]); |
144 | $this->version = $regs[2]; |
145 | } |
146 | elseif (preg_match('|^([a-zA-Z\._ -]+)|', $this->uastring, $regs)) { |
147 | $this->brand = trim($regs[1]); |
148 | $this->version = null; |
149 | } |
150 | // search for any real and/or special UAs |
151 | if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
152 | $this->brand = 'Netscape'; |
31733e08 |
153 | $this->version = $regs[1]; |
31733e08 |
154 | } |
bf78d3ed |
155 | elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
156 | $this->brand = 'Netscape'; |
31733e08 |
157 | $this->version = $regs[1]; |
158 | } |
bf78d3ed |
159 | elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
160 | $this->brand = 'Chimera'; |
1defa974 |
161 | $this->version = $regs[1]; |
162 | } |
bf78d3ed |
163 | elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
164 | $this->brand = 'Camino'; |
a5813ca3 |
165 | $this->version = $regs[1]; |
166 | } |
bf78d3ed |
167 | elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
168 | $this->brand = 'Phoenix'; |
1defa974 |
169 | $this->version = $regs[1]; |
170 | } |
bf78d3ed |
171 | elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
172 | $this->brand = 'Mozilla Firebird'; |
23585ba2 |
173 | $this->version = $regs[1]; |
174 | } |
bf78d3ed |
175 | elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
176 | $this->brand = 'Firefox'; |
a5813ca3 |
177 | $this->version = $regs[1]; |
178 | } |
b24eb888 |
179 | elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
180 | $this->brand = 'SeaMonkey'; |
181 | $this->version = $regs[1]; |
182 | } |
bf78d3ed |
183 | elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
184 | $this->brand = 'Galeon'; |
31733e08 |
185 | $this->version = $regs[1]; |
186 | } |
6e783db6 |
187 | elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
188 | $this->brand = 'Epiphany'; |
189 | $this->version = $regs[1]; |
190 | } |
191 | elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
192 | $this->brand = 'K-Meleon'; |
193 | $this->version = $regs[1]; |
194 | } |
195 | elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
196 | $this->brand = 'AOL'; |
197 | $this->version = $regs[1]; |
198 | } |
bf78d3ed |
199 | elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) { |
200 | $this->brand = 'Mozilla'; |
31733e08 |
201 | $this->version = $regs[1]; |
202 | } |
bf78d3ed |
203 | elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
204 | $this->brand = 'Opera'; |
31733e08 |
205 | $this->version = $regs[1]; |
206 | } |
bf78d3ed |
207 | elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
208 | $this->brand = 'OmniWeb'; |
1defa974 |
209 | $this->version = $regs[1]; |
210 | } |
bf78d3ed |
211 | elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
212 | $this->brand = 'Konqueror'; |
31733e08 |
213 | $this->version = $regs[1]; |
214 | } |
bf78d3ed |
215 | elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
216 | $this->brand = 'Safari'; |
1defa974 |
217 | $this->version = $regs[1]; |
218 | } |
bf78d3ed |
219 | elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
220 | $this->brand = 'AppleWebKit'; |
1defa974 |
221 | $this->version = $regs[1]; |
222 | } |
bf78d3ed |
223 | elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
224 | $this->brand = 'Microsoft FrontPage'; |
f983aa36 |
225 | $this->version = $regs[1]; |
f983aa36 |
226 | } |
bf78d3ed |
227 | elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
228 | $this->brand = 'iCab'; |
a8464009 |
229 | $this->version = $regs[1]; |
a8464009 |
230 | } |
bf78d3ed |
231 | elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
232 | $this->brand = 'IBrowse'; |
a8464009 |
233 | $this->version = $regs[1]; |
a8464009 |
234 | } |
bf78d3ed |
235 | elseif (preg_match('|Configuration/CLDC-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
236 | $this->brand = 'CLDC'; |
a8464009 |
237 | $this->version = $regs[1]; |
a8464009 |
238 | } |
6e783db6 |
239 | elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
240 | $this->brand = 'UP.Browser'; |
241 | $this->version = $regs[1]; |
242 | } |
bf78d3ed |
243 | elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) { |
244 | $this->brand = 'ELinks'; |
a8464009 |
245 | $this->version = $regs[1]; |
a8464009 |
246 | } |
6e783db6 |
247 | elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) { |
248 | $this->brand = 'Links'; |
249 | $this->version = $regs[1]; |
250 | } |
251 | elseif (preg_match('|wget[/ ]([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) { |
252 | $this->brand = 'wget'; |
253 | $this->version = $regs[1]; |
254 | } |
bf78d3ed |
255 | elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
256 | $this->brand = 'ZyBorg'; |
a8464009 |
257 | $this->version = $regs[1]; |
258 | $this->bot = true; |
259 | } |
bf78d3ed |
260 | elseif (preg_match('|Googlebot/?([0-9a-zA-Z\.+]+)?|', $this->uastring, $regs)) { |
261 | $this->brand = 'Googlebot'; |
a8464009 |
262 | $this->version = $regs[1]; |
263 | $this->bot = true; |
264 | } |
bf78d3ed |
265 | elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
266 | $this->brand = 'Ask Jeeves'; |
a8464009 |
267 | $this->version = $regs[1]; |
268 | $this->bot = true; |
269 | } |
c51ab9a2 |
270 | elseif (preg_match('|Slurp|', $this->uastring, $regs)) { |
bf78d3ed |
271 | $this->brand = 'Slurp'; |
c51ab9a2 |
272 | $this->version = null; |
a8464009 |
273 | $this->bot = true; |
274 | } |
bf78d3ed |
275 | elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
276 | $this->brand = 'Gulper Web Bot'; |
a8464009 |
277 | $this->version = $regs[1]; |
278 | $this->bot = true; |
279 | } |
bf78d3ed |
280 | elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
281 | $this->brand = 'HTTrack'; |
a8464009 |
282 | $this->version = $regs[1]; |
283 | $this->bot = true; |
284 | } |
bf78d3ed |
285 | elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) { |
286 | $this->brand = 'Unknown bot (IE5.5)'; |
287 | $this->version = null; |
a8464009 |
288 | $this->bot = true; |
289 | } |
bf78d3ed |
290 | elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) { |
291 | $this->brand = 'Unknown bot (Mozilla)'; |
292 | $this->version = null; |
a8464009 |
293 | $this->bot = true; |
294 | } |
bf78d3ed |
295 | elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) { |
296 | $this->brand = 'almaden crawler'; |
297 | $this->version = null; |
a8464009 |
298 | $this->bot = true; |
299 | } |
bf78d3ed |
300 | elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) || preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) { |
301 | $this->brand = 'BlitzBOT'; |
302 | $this->version = null; |
a8464009 |
303 | $this->bot = true; |
304 | } |
bf78d3ed |
305 | elseif (preg_match('|sitecheck.internetseer.com|', $this->uastring)) { |
306 | $this->brand = 'internetseer'; |
307 | $this->version = null; |
a8464009 |
308 | $this->bot = true; |
309 | } |
bf78d3ed |
310 | elseif (preg_match('|Girafabot|', $this->uastring)) { |
311 | $this->brand = 'Girafabot'; |
312 | $this->version = null; |
a8464009 |
313 | $this->bot = true; |
314 | } |
bf78d3ed |
315 | elseif (preg_match('|efp@gmx.net|', $this->uastring)) { |
316 | $this->brand = 'efp'; |
317 | $this->version = null; |
a8464009 |
318 | $this->bot = true; |
319 | } |
bf78d3ed |
320 | elseif (preg_match('|^Firefly|', $this->uastring)) { |
321 | // comes here with correct value but would be detected as MSIE |
a8464009 |
322 | } |
bf78d3ed |
323 | elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) { |
324 | $this->brand = 'Avant Browser'; |
325 | $this->version = null; |
a8464009 |
326 | } |
6e783db6 |
327 | elseif (preg_match('|Maxthon|', $this->uastring)) { |
328 | $this->brand = 'Maxthon'; |
329 | $this->version = null; |
330 | } |
331 | elseif (preg_match('|MyIE2|', $this->uastring)) { |
332 | $this->brand = 'MyIE2'; |
333 | $this->version = null; |
334 | } |
bf78d3ed |
335 | elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
336 | $this->brand = 'Crazy Browser'; |
337 | $this->version = $regs[1]; |
a8464009 |
338 | } |
bf78d3ed |
339 | elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
340 | $this->brand = 'MSN'; |
341 | $this->version = $regs[1]; |
a8464009 |
342 | } |
bf78d3ed |
343 | elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
344 | $this->brand = 'Microsoft FrontPage'; |
345 | $this->version = $regs[1]; |
a8464009 |
346 | } |
bf78d3ed |
347 | elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { |
348 | $this->brand = 'Microsoft Internet Explorer'; |
31733e08 |
349 | $this->version = $regs[1]; |
350 | } |
bf78d3ed |
351 | elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) { |
352 | $this->brand = 'Netscape'; |
1defa974 |
353 | $this->version = $regs[1]; |
bf78d3ed |
354 | if (intval($this->version) == 4) { $this->brand .= ' Communicator'; } |
1defa974 |
355 | } |
a8464009 |
356 | |
4210e7b0 |
357 | $botArray = array('Scooter','Spinne','Vagabondo','TurnitinBot','FAST-WebCrawler','Firefly','Googlebot', |
358 | 'Scrubby','psbot','NG','URL_Spider_Pro','Pompos','Szukacz','ASPseek','NPBot-1', |
bf78d3ed |
359 | 'dloader(NaverRobot)','NetResearchServer','HeinrichderMiragoRobot','LinkWalker', |
360 | 'Openbot','W3C_Validator','ZyBorg','Ask Jeeves','dumbBot','BaiDuSpider','ia_archiver', |
361 | 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','OWR_Crawler', |
c51ab9a2 |
362 | 'search.ch','WebFilter Robot','appie','larbin','NutchCVS','ObjectsSearch','Webchat', |
363 | 'msnbot','','','','','',''); |
a8464009 |
364 | |
365 | if (in_array($this->brand, $botArray)) { |
366 | $this->bot = true; |
367 | } |
31733e08 |
368 | } |
369 | |
23585ba2 |
370 | function getBrand() { return $this->brand; } |
371 | function getVersion() { return $this->version; } |
4210e7b0 |
372 | |
373 | function getAcceptLanguages() { |
374 | if (!isset($this->uadata['accept-languages'])) { |
375 | $headers = getAllHeaders(); |
376 | $accLcomp = explode(',', $headers['Accept-Language']); |
377 | $accLang = array(); |
378 | foreach ($accLcomp as $lcomp) { |
379 | if (strlen($lcomp)) { |
380 | $ldef = explode(';', $lcomp); |
381 | $accLang[$ldef[0]] = (float)((strpos($ldef[1],'q=')===0)?substr($ldef[1],2):1); |
382 | } |
383 | } |
384 | $this->uadata['accept-languages'] = $accLang; |
385 | } |
386 | return $this->uadata['accept-languages']; |
387 | } |
388 | |
f983aa36 |
389 | function getUAString() { return $this->uastring; } |
23585ba2 |
390 | |
bf78d3ed |
391 | function getEngine() { |
392 | // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|unkown |
393 | if (!isset($this->uadata['engine'])) { |
394 | $this->uadata['engine'] = 'unkown'; |
395 | $this->uadata['geckodate'] = null; |
396 | if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs)) { |
397 | $this->uadata['engine'] = 'gecko'; |
398 | $this->uadata['geckodate'] = $regs[1]; |
399 | } |
400 | elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) { |
6e783db6 |
401 | if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) { |
bf78d3ed |
402 | $this->uadata['engine'] = 'tasman'; |
403 | } |
404 | else { |
405 | $this->uadata['engine'] = 'trident'; |
406 | } |
407 | } |
408 | elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'Safari') !== false) || (strpos($this->brand, 'AppleWebKit') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) { |
409 | $this->uadata['engine'] = 'khtml'; |
410 | } |
411 | elseif ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) <= 4)) { |
412 | $this->uadata['engine'] = 'nscp'; |
413 | } |
414 | elseif (strpos($this->brand, 'Opera') !== false) { |
415 | $this->uadata['engine'] = 'presto'; |
416 | } |
417 | elseif (strpos($this->brand, 'Dillo') !== false) { |
418 | $this->uadata['engine'] = 'gzilla'; |
419 | } |
420 | elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) { |
421 | $this->uadata['engine'] = 'links'; |
422 | } |
6e783db6 |
423 | elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) || |
424 | (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) || |
425 | (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) { |
bf78d3ed |
426 | $this->uadata['engine'] = 'trident'; |
427 | } |
428 | elseif (strpos($this->brand, 'Galeon') !== false) { |
429 | $this->uadata['engine'] = 'gecko'; |
31733e08 |
430 | } |
431 | } |
bf78d3ed |
432 | return $this->uadata['engine']; |
31733e08 |
433 | } |
434 | |
bf78d3ed |
435 | function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); } |
436 | |
437 | function getEngineVersion() { |
438 | if (!isset($this->uadata['eng_version'])) { |
439 | $this->uadata['eng_version'] = null; |
440 | // getOS() should get the date for us |
441 | $this->getOS(); |
31733e08 |
442 | } |
bf78d3ed |
443 | return $this->uadata['eng_version']; |
31733e08 |
444 | } |
445 | |
bf78d3ed |
446 | function getOS() { |
447 | if (!isset($this->uadata['os'])) { |
448 | $this->uadata['os'] = null; |
449 | if ($this->hasEngine('gecko')) { |
6e783db6 |
450 | if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) { |
bf78d3ed |
451 | $this->uadata['os'] = $regs[2]; |
452 | $this->uadata['lang'] = $regs[3]; |
453 | $this->uadata['eng_version'] = $regs[4]; |
454 | } |
6e783db6 |
455 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) { |
bf78d3ed |
456 | $this->uadata['os'] = $regs[2]; |
457 | $this->uadata['lang'] = $regs[3]; |
458 | $this->uadata['eng_version'] = 'M'.$regs[4]; |
459 | } |
6e783db6 |
460 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) { |
461 | $this->uadata['os'] = $regs[2]; |
462 | $this->uadata['lang'] = $regs[3]; |
463 | $this->uadata['eng_version'] = null; |
464 | } |
465 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) { |
bf78d3ed |
466 | $this->uadata['os'] = $regs[2]; |
467 | $this->uadata['lang'] = null; |
468 | $this->uadata['eng_version'] = null; |
469 | } |
470 | elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) { |
471 | $this->uadata['os'] = $regs[2]; |
472 | $this->uadata['lang'] = null; |
473 | $this->uadata['eng_version'] = null; |
474 | } |
475 | elseif (preg_match('|Debian/|', $this->uastring, $regs)) { |
476 | $this->uadata['os'] = 'Debian Linux'; |
477 | $this->uadata['lang'] = null; |
478 | $this->uadata['eng_version'] = null; |
479 | } |
480 | } |
6e783db6 |
481 | elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) { |
482 | if (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) { |
bf78d3ed |
483 | $this->uadata['eng_version'] = $regs[1]; |
484 | $this->uadata['os'] = $regs[2]; |
485 | $this->uadata['lang'] = null; |
486 | } |
487 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) { |
488 | $this->uadata['eng_version'] = $regs[1]; |
489 | $this->uadata['os'] = null; |
490 | $this->uadata['lang'] = null; |
491 | } |
31733e08 |
492 | } |
bf78d3ed |
493 | elseif ($this->hasEngine('khtml')) { |
6e783db6 |
494 | if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) { |
495 | $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1]; |
bf78d3ed |
496 | $this->uadata['os'] = $regs[2]; |
497 | $this->uadata['lang'] = $regs[5]; |
498 | } |
6e783db6 |
499 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) { |
500 | $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1]; |
bf78d3ed |
501 | $this->uadata['os'] = $regs[2]; |
502 | $this->uadata['lang'] = null; |
503 | } |
504 | elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) { |
505 | $this->uadata['os'] = $regs[2]; |
506 | $this->uadata['lang'] = $regs[3]; |
507 | $this->uadata['eng_version'] = null; |
508 | } |
509 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) { |
510 | $this->uadata['os'] = $regs[1]; |
511 | $this->uadata['lang'] = null; |
512 | $this->uadata['eng_version'] = null; |
513 | } |
514 | } |
515 | elseif ($this->hasEngine('presto')) { |
516 | if (preg_match('/Opera\/[^\(]+ \(([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
517 | $this->uadata['eng_version'] = $this->getVersion(); |
518 | $this->uadata['os'] = $regs[1]; |
519 | $this->uadata['lang'] = $regs[2]; |
520 | } |
6e783db6 |
521 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; .+; ([^;]+)\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
522 | $this->uadata['eng_version'] = $this->getVersion(); |
523 | $this->uadata['os'] = $regs[1]; |
524 | $this->uadata['lang'] = $regs[2]; |
525 | } |
526 | elseif (preg_match('/Mozilla\/[^\(]+ \(([^;]+);.+\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) { |
527 | $this->uadata['eng_version'] = $this->getVersion(); |
528 | $this->uadata['os'] = $regs[1]; |
529 | $this->uadata['lang'] = $regs[2]; |
530 | } |
531 | // Opera 8 |
bf78d3ed |
532 | elseif (preg_match('/Opera\/[^\(]+ \(([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) { |
533 | $this->uadata['eng_version'] = $this->getVersion(); |
534 | $this->uadata['os'] = $regs[1]; |
535 | $this->uadata['lang'] = $regs[2]; |
536 | } |
6e783db6 |
537 | elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; .+; ([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) { |
538 | $this->uadata['eng_version'] = $this->getVersion(); |
539 | $this->uadata['os'] = $regs[1]; |
540 | $this->uadata['lang'] = $regs[2]; |
541 | } |
542 | elseif (preg_match('/Mozilla\/[^\(]+ \(([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) { |
bf78d3ed |
543 | $this->uadata['eng_version'] = $this->getVersion(); |
544 | $this->uadata['os'] = $regs[1]; |
545 | $this->uadata['lang'] = $regs[2]; |
546 | } |
547 | } |
548 | elseif ($this->hasEngine('nscp')) { |
6e783db6 |
549 | if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) { |
bf78d3ed |
550 | $this->uadata['eng_version'] = $regs[1]; |
551 | $this->uadata['os'] = $regs[3]; |
552 | $this->uadata['lang'] = $regs[2]; |
553 | } |
554 | } |
555 | elseif ($this->hasEngine('gzilla')) { |
556 | $this->uadata['eng_version'] = $this->getVersion(); |
557 | $this->uadata['os'] = null; |
558 | $this->uadata['lang'] = null; |
559 | } |
560 | elseif ($this->hasEngine('links')) { |
6e783db6 |
561 | if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) { |
bf78d3ed |
562 | $this->uadata['eng_version'] = null; |
563 | $this->uadata['os'] = $regs[1]; |
564 | $this->uadata['lang'] = null; |
565 | } |
566 | } |
567 | else { |
568 | $this->uadata['eng_version'] = null; |
569 | $this->uadata['lang'] = null; |
570 | if (preg_match('/AmigaOS/i', $this->uastring, $regs)) { |
571 | $this->uadata['os'] = 'AmigaOS'; |
572 | } |
573 | elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) { |
574 | $this->uadata['os'] = $regs[1]; |
575 | } |
6e783db6 |
576 | elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) { |
577 | $this->uadata['os'] = trim($regs[1]); |
578 | } |
579 | elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) { |
580 | $this->uadata['os'] = trim($regs[1]); |
581 | } |
c51ab9a2 |
582 | elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) { |
583 | $this->uadata['os'] = 'SymbianOS '.$regs[1]; |
584 | } |
bf78d3ed |
585 | } |
586 | if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; } |
587 | elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows ME'; } |
588 | elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; } |
589 | elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; } |
590 | elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; } |
591 | elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; } |
592 | elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; } |
593 | elseif (preg_match('/Mac ?OS ?X/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; } |
594 | elseif (preg_match('/Mac_P(ower|)PC/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; } |
595 | elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } |
6e783db6 |
596 | elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } |
bf78d3ed |
597 | elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; } |
6e783db6 |
598 | elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; } |
bf78d3ed |
599 | elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; } |
600 | |
6e783db6 |
601 | if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; } |
602 | elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; } |
603 | elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; } |
604 | elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; } |
605 | elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; } |
606 | elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; } |
607 | elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; } |
608 | elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; } |
609 | elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; } |
610 | elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; } |
611 | elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; } |
612 | elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; } |
613 | elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; } |
614 | elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; } |
615 | elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; } |
c51ab9a2 |
616 | elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; } |
6e783db6 |
617 | elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; } |
618 | else { $this->uadata['platform'] = $this->uadata['os']; } |
bf78d3ed |
619 | |
620 | $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']); |
31733e08 |
621 | } |
bf78d3ed |
622 | return $this->uadata['os']; |
31733e08 |
623 | } |
624 | |
bf78d3ed |
625 | function getPlatform() { |
626 | if (!isset($this->uadata['platform'])) { |
627 | $this->uadata['platform'] = null; |
628 | // getOS() should get the date for us |
629 | $this->getOS(); |
31733e08 |
630 | } |
bf78d3ed |
631 | return $this->uadata['platform']; |
31733e08 |
632 | } |
633 | |
bf78d3ed |
634 | function getLanguage() { |
635 | if (!isset($this->uadata['lang'])) { |
636 | $this->uadata['lang'] = null; |
637 | // getOS() should get the date for us |
638 | $this->getOS(); |
31733e08 |
639 | } |
bf78d3ed |
640 | return $this->uadata['lang']; |
31733e08 |
641 | } |
1defa974 |
642 | |
bf78d3ed |
643 | function getGeckoDate() { |
644 | if (!isset($this->uadata['geckodate'])) { |
645 | $this->uadata['geckodate'] = null; |
646 | // getEngine() should get the date for us |
647 | $this->getEngine(); |
1defa974 |
648 | } |
bf78d3ed |
649 | return $this->uadata['geckodate']; |
1defa974 |
650 | } |
bf78d3ed |
651 | |
652 | function isbot() { return $this->bot; } |
653 | function isns() { return (strpos($this->brand, 'Netscape') !== false); } |
654 | function isns4() { return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4)); } |
655 | function isie() { return $this->hasEngine('trident'); } |
656 | function geckodate() { return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0); } |
657 | function geckobased() { return $this->hasEngine('gecko'); } |
658 | function khtmlbased() { return $this->hasEngine('khtml'); } |
31733e08 |
659 | } |
23585ba2 |
660 | ?> |