c64117f38e8e3639fdf2912e797eefd9550f99f6
[php-utility-classes.git] / classes / useragent.php-class
1 <?php
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 class userAgent {
7   // userAgent PHP class
8   // get user agent and tell us what Browser is accessing
9   //
10   // function __construct([$ua_string])
11   //   CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables.
12   //
13   // private $uastring
14   //   the plain User Agent string
15   // private $brand
16   //   the User Agent brand name
17   // private $version
18   //   the User Agent version
19   // private $bot
20   //   bool: true if this agent is a bot
21   // private $mobile
22   //   bool: true if this agent is a mobile phone
23   // private $uadata
24   //   array of static user agent data (static vars in functions are set for all objects of this class!)
25   //
26   // public function getBrand()
27   //   returns the User Agent Brand Name
28   //
29   // public function getVersion()
30   //   returns the User Agent version
31   //
32   // public function getAcceptLanguages()
33   //   returns an associated array with the accepted languages of this UA
34   //     keys are language codes, values are q factors (weights)
35   //
36   // public function getUAString()
37   //   returns the full User Agent string
38   //
39   // public function getEngine()
40   //   returns a string telling the detected rendering engine, null if we can't detect
41   //     one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|unknown
42   //
43   // public function hasEngine($rnd_engine)
44   //   returns true if the given rendering engine was detected
45   //
46   // public function getEngineVersion()
47   //   returns a the version number for the rendering engine
48   //     this may be the same as getVersion() for many engines, or null if we don't know
49   //
50   // public function getOS()
51   //   returns a string telling the detected operating system, null if we can't detect
52   //     might be very verbose, uses no abbreviations for most names
53   //
54   // public function getPlatform()
55   //   returns a string telling the detected OS platform, null if we can't detect
56   //     one of windows|linux|mac|solaris|unknown
57   //
58   // public function getLanguage() {
59   //   returns a string telling the detected browser UI language, null if we can't detect
60   //     should be an ISO code
61   //
62   // public function isBot()
63   //   returns true if User Agent seems to be a bot
64   //
65   // public function isMobile()
66   //   returns true if User Agent seems to be a mobile phone
67   //
68   // *** functions that only return useable info for some agents ***
69   //
70   // public function getGeckoDate()
71   //   returns the Gecko date for Gecko-based browsers, null for others
72   //
73   // public function getGeckoTime()
74   //   returns the Gecko build date/time as a unix epoch time number for Gecko-based browsers, null for others
75   //
76   // *** functions for compat to older versions of this class ***
77   //
78   // public function isns()
79   //   returns true if User Agent seems to be Netscape brand, false if not
80   // public function isns4()
81   //   returns true if User Agent seems to be Netscape Communicator 4.x, false if not
82   // public function isie()
83   //   returns true if User Agent seems to be a version of Internet Exploder, false if not
84   // public function geckobased()
85   //   returns true if User Agent seems to be a Gecko-based browser, false if not
86   // public function geckodate()
87   //   returns the Gecko date when it's a Gecko-based browser, 0 if not
88   // public function khtmlbased()
89   //   returns true if User Agent seems to be a KHTML-based browser, false if not
90
91   // collection of some known User Agent Strings:
92   // *** see testbed/ua_list_raw.txt ***
93   // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
94
95   private $uastring;
96   private $brand;
97   private $version;
98   private $bot = false;
99   private $mobile = false;
100   private $uadata = [];
101
102   function __construct($ua_string = '') {
103     // *** constructor ***
104     if (strlen($ua_string)) {
105       $this->uastring = $ua_string;
106     }
107     else {
108       // read raw UA string
109       $this->uastring = ($_SERVER['HTTP_USER_AGENT'] ?? '');
110     }
111
112     // get UA brand and version
113     $this->brand = 'Unknown';
114     $this->version = null;
115     // find reasonable defaults
116     if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/(\d[0-9a-zA-Z\._+-]*)|', $this->uastring, $regs)) {
117       $this->brand = trim($regs[1]);
118       $this->version = $regs[2];
119     }
120     elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?(\d[0-9a-zA-Z\.+]*)|', $this->uastring, $regs)) {
121       $this->brand = trim($regs[1]);
122       $this->version = $regs[2];
123     }
124     elseif (preg_match('|^([0-9a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
125       $this->brand = trim($regs[1]);
126       $this->version = null;
127     }
128     $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
129                  || (strpos(strtolower($this->brand), 'crawler') !== false)
130                  || (strpos(strtolower($this->brand), 'spider') !== false)
131                  || (strpos(strtolower($this->brand), 'search') !== false)
132                  || (strpos(strtolower($this->brand), 'seek') !== false);
133
134     // search for any real and/or special UAs
135     if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
136       $this->brand = 'Netscape';
137       $this->version = $regs[1];
138       $this->bot = false;
139     }
140     elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
141       $this->brand = 'Netscape';
142       $this->version = $regs[1];
143       $this->bot = false;
144     }
145     elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
146       $this->brand = 'Netscape';
147       $this->version = $regs[1];
148       $this->bot = false;
149     }
150     elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
151       $this->brand = 'Chimera';
152       $this->version = $regs[1];
153       $this->bot = false;
154     }
155     elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
156       $this->brand = 'Camino';
157       $this->version = $regs[1];
158       $this->bot = false;
159     }
160     elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
161       $this->brand = 'Phoenix';
162       $this->version = $regs[1];
163       $this->bot = false;
164     }
165     elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
166       $this->brand = 'Mozilla Firebird';
167       $this->version = $regs[1];
168       $this->bot = false;
169     }
170     elseif (preg_match('|Flock/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
171       $this->brand = 'Flock';
172       $this->version = $regs[1];
173       $this->bot = false;
174     }
175     elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
176       $this->brand = 'SeaMonkey';
177       $this->version = $regs[1];
178       $this->bot = false;
179     }
180     elseif (preg_match('|Iceape/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
181       $this->brand = 'IceApe'; // Debian-rebranded SeaMonkey
182       $this->version = $regs[1];
183       $this->bot = false;
184     }
185     elseif (preg_match('|Iceweasel/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
186       $this->brand = 'IceWeasel'; // Debian-rebranded Firefox
187       $this->version = $regs[1];
188       $this->bot = false;
189     }
190     elseif (preg_match('|Icedove/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
191       $this->brand = 'IceDove'; // Debian-rebranded Thunderbird
192       $this->version = $regs[1];
193       $this->bot = false;
194     }
195     elseif (preg_match('|BonEcho/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
196       $this->brand = 'Bon Echo'; // Firefox 2.0 code name
197       $this->version = $regs[1];
198       $this->bot = false;
199     }
200     elseif (preg_match('|GranParadiso/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
201       $this->brand = 'Gran Paradiso'; // Firefox 3.0 code name
202       $this->version = $regs[1];
203       $this->bot = false;
204     }
205     elseif (preg_match('|Shiretoko/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
206       $this->brand = 'Shiretoko'; // Firefox 3.5 code name
207       $this->version = $regs[1];
208       $this->bot = false;
209     }
210     elseif (preg_match('|Namoroka/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
211       $this->brand = 'Namoroka'; // Firefox 3.6 code name
212       $this->version = $regs[1];
213       $this->bot = false;
214     }
215     elseif (preg_match('|Lorentz/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
216       $this->brand = 'Lorentz'; // Firefox 3.6 (with OOPP) code name
217       $this->version = $regs[1];
218       $this->bot = false;
219     }
220     elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
221       $this->brand = 'Minefield'; // Firefox development nightly code name
222       $this->version = $regs[1];
223       $this->bot = false;
224     }
225     elseif (preg_match('|PmWFx/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
226       $this->brand = 'PmW-Firefox';
227       $this->version = $regs[1];
228       $this->bot = false;
229     }
230     elseif (preg_match('|BeZillaBrowser/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
231       $this->brand = 'BeZillaBrowser';
232       $this->version = $regs[1];
233       $this->bot = false;
234     }
235     elseif (preg_match('|Songbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
236       $this->brand = 'Songbird';
237       $this->version = $regs[1];
238       $this->bot = false;
239     }
240     elseif (preg_match('|Lanikai/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
241       $this->brand = 'Lanikai'; // Thunderbird 3.1 code name
242       $this->version = $regs[1];
243       $this->bot = false;
244     }
245     elseif (preg_match('|Shredder/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
246       $this->brand = 'Shredder'; // Thunderbird development nightly code name
247       $this->version = $regs[1];
248       $this->bot = false;
249     }
250     elseif (preg_match('|prism/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
251       $this->brand = 'Prism';
252       $this->version = $regs[1];
253       $this->bot = false;
254     }
255     elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
256       $this->brand = 'Minimo';
257       $this->version = $regs[1];
258       $this->bot = false;
259       $this->mobile = true;
260     }
261     elseif (preg_match('|Fennec/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
262       $this->brand = 'Fennec'; // Firefox mobile code name
263       $this->version = $regs[1];
264       $this->bot = false;
265       $this->mobile = true;
266     }
267     elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
268       $this->brand = 'Galeon';
269       $this->version = $regs[1];
270       $this->bot = false;
271     }
272     elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
273       $this->brand = 'Epiphany';
274       $this->version = $regs[1];
275       $this->bot = false;
276     }
277     elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
278       $this->brand = 'K-Meleon';
279       $this->version = $regs[1];
280       $this->bot = false;
281     }
282     elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
283       $this->brand = 'AOL';
284       $this->version = $regs[1];
285       $this->bot = false;
286     }
287     elseif (preg_match('|Tablet browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
288       $this->brand = 'microB';
289       $this->version = $regs[1];
290       $this->bot = false;
291       $this->mobile = true;
292     }
293     elseif (preg_match('|Maemo Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
294       $this->brand = 'microB';
295       $this->version = $regs[1];
296       $this->bot = false;
297       $this->mobile = true;
298     }
299     elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
300       $this->brand = 'Opera Mini';
301       $this->version = $regs[1];
302       $this->bot = false;
303       $this->mobile = true;
304     }
305     elseif (preg_match('/Opera\/[^\(]+ \(.*; Opera Mini\/([^;]+); /i', $this->uastring, $regs)) {
306       $this->brand = 'Opera Mini';
307       $this->version = $regs[1];
308       $this->bot = false;
309       $this->mobile = true;
310     }
311     elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
312       $this->brand = 'Opera';
313       $this->version = $regs[1];
314       $this->bot = false;
315     }
316     elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
317       $this->brand = 'OmniWeb';
318       $this->version = $regs[1];
319       $this->bot = false;
320     }
321     elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
322       $this->brand = 'Konqueror';
323       $this->version = $regs[1];
324       $this->bot = false;
325     }
326     elseif (preg_match('|Shiira/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
327       $this->brand = 'Shiira';
328       $this->version = $regs[1];
329       $this->bot = false;
330     }
331     elseif (preg_match('|Edge/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
332       $this->brand = 'Edge';
333       $this->version = $regs[1];
334       $this->bot = false;
335       $this->mobile = preg_match('| Mobile |', $this->uastring);
336     }
337     elseif (preg_match('|Chromium/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
338       $this->brand = 'Chromium';
339       $this->version = $regs[1];
340       $this->bot = false;
341     }
342     elseif (preg_match('|Chrome/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
343       $this->brand = 'Chrome';
344       $this->version = $regs[1];
345       $this->bot = false;
346     }
347     elseif (preg_match('|NokiaBrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
348       $this->brand = 'NokiaBrowser';
349       $this->version = $regs[1];
350       $this->bot = false;
351     }
352     elseif (preg_match('|wOSBrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
353       $this->brand = 'webOS Browser';
354       $this->version = $regs[1];
355       $this->bot = false;
356     }
357     elseif (preg_match('|Silk/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
358       $this->brand = 'Silk';
359       $this->version = $regs[1];
360       $this->bot = false;
361     }
362     elseif (preg_match('|Kindle/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
363       $this->brand = 'Kindle';
364       $this->version = $regs[1];
365       $this->bot = false;
366     }
367     elseif (preg_match('|Pre/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
368       $this->brand = 'Pre';
369       $this->version = $regs[1];
370       $this->bot = false;
371     }
372     elseif (preg_match('|BOLT/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
373       $this->brand = 'BOLT';
374       $this->version = $regs[1];
375       $this->bot = false;
376     }
377     elseif (preg_match('|Googlebot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Webkit! */
378       $this->brand = 'Googlebot-Mobile';
379       $this->version = $regs[1];
380       $this->bot = true;
381       $this->mobile = true;
382     }
383     elseif (preg_match('|FxiOS/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
384       $this->brand = 'Firefox for iOS';
385       $this->version = $regs[1];
386       $this->bot = false;
387       $this->mobile = true;
388     }
389     elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
390       if (preg_match('| Mobile(/[0-9a-zA-Z\.+]+)? ?Safari/|', $this->uastring)) {
391         $this->brand = 'Mobile Safari';
392         $this->mobile = true;
393       }
394       else {
395         $this->brand = 'Safari';
396       }
397       if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
398         $this->version = $vregs[1];
399       }
400       else {
401         $this->version = '('.$regs[1].')';
402       }
403       $this->bot = false;
404     }
405     elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
406       $this->brand = 'AppleWebKit';
407       $this->version = $regs[1];
408       $this->bot = false;
409     }
410     elseif (preg_match('|Spinn3r ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
411       $this->brand = 'Spinn3r';
412       $this->version = $regs[1];
413       $this->bot = true;
414     }
415     elseif (preg_match('|Butterfly/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
416       $this->brand = 'Butterfly';
417       $this->version = $regs[1];
418       $this->bot = true;
419     }
420     elseif (preg_match('|Googlebot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
421       $this->brand = 'Googlebot';
422       $this->version = $regs[1];
423       $this->bot = true;
424     }
425     elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
426       $this->brand = 'Firefox';
427       $this->version = $regs[1];
428       $this->bot = false;
429     }
430     elseif (preg_match('|Thunderbird/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
431       $this->brand = 'Thunderbird';
432       $this->version = $regs[1];
433       $this->bot = false;
434     }
435     elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
436             strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
437       $this->brand = 'Mozilla';
438       $this->version = $regs[1];
439       $this->bot = false;
440     }
441     elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
442             strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
443       $this->brand = 'Mozilla';
444       $this->version = 'M'.$regs[1];
445       $this->bot = false;
446     }
447     elseif (preg_match('|Baiduspider|i', $this->uastring)) {
448       $this->brand = 'BaiDuSpider';
449       $this->version = null;
450       $this->bot = true;
451     }
452     elseif (preg_match('|YodaoBot-Mobile/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
453       $this->brand = 'YodaoBot-Mobile';
454       $this->version = $regs[1];
455       $this->bot = true;
456       $this->mobile = true;
457     }
458     elseif (preg_match('|FASTMobileCrawl/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) { /* looks like Gecko! */
459       $this->brand = 'FASTMobileCrawl';
460       $this->version = $regs[1];
461       $this->bot = true;
462       $this->mobile = true;
463     }
464     elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
465       $this->brand = 'Microsoft FrontPage';
466       $this->version = $regs[1];
467       $this->bot = false;
468     }
469     elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
470       $this->brand = 'iCab';
471       $this->version = $regs[1];
472       $this->bot = false;
473     }
474     elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
475       $this->brand = 'IBrowse';
476       $this->version = $regs[1];
477       $this->bot = false;
478     }
479     elseif (preg_match('|ICEbrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
480       $this->brand = 'ICEbrowser';
481       $this->version = $regs[1];
482       $this->bot = false;
483     }
484     elseif (preg_match('|ICE Browser/v([0-9a-zA-Z\._+]+)|', $this->uastring, $regs)) {
485       $this->brand = 'ICEbrowser';
486       $this->version = str_replace('_', '.', $regs[1]);
487       $this->bot = false;
488     }
489     elseif (preg_match('|NetPositive/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
490       $this->brand = 'NetPositive';
491       $this->version = $regs[1];
492       $this->bot = false;
493     }
494     elseif (preg_match('|WebPro/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
495       $this->brand = 'WebPro (Novarra)';
496       $this->version = $regs[1];
497       $this->bot = false;
498     }
499     elseif (preg_match('|; OffByOne;|', $this->uastring, $regs)) {
500       $this->brand = 'Off By One';
501       $this->version = null;
502       $this->bot = false;
503     }
504     elseif (preg_match('|PSP \(PlayStation Portable\); ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
505       $this->brand = 'PlayStation Portable';
506       $this->version = $regs[1];
507       $this->bot = false;
508       $this->mobile = true;
509     }
510     elseif (preg_match('|PLAYSTATION 3; ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
511       $this->brand = 'PlayStation 3';
512       $this->version = $regs[1];
513       $this->bot = false;
514     }
515     elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
516       $this->brand = 'NetFront';
517       $this->version = $regs[1];
518       $this->bot = false;
519       $this->mobile = true;
520     }
521     elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
522       $this->brand = 'UP.Browser';
523       $this->version = $regs[1];
524       $this->bot = false;
525       $this->mobile = true;
526     }
527     elseif (preg_match('|UP.Link/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
528       $this->brand = 'UP.Link';
529       $this->version = $regs[1];
530       $this->bot = false;
531       $this->mobile = true;
532     }
533     elseif (preg_match('|AU-MIC-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
534       $this->brand = 'Obigo';
535       $this->version = $regs[1];
536       $this->bot = false;
537       $this->mobile = true;
538     }
539     elseif (preg_match('|Browser/Obigo-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
540       $this->brand = 'Obigo';
541       $this->version = $regs[1];
542       $this->bot = false;
543       $this->mobile = true;
544     }
545     elseif (preg_match('|Nokia([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
546       $this->brand = 'Nokia';
547       $this->version = $regs[1];
548       $this->bot = false;
549       $this->mobile = true;
550     }
551     elseif (preg_match('|SonyEricsson([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
552       $this->brand = 'SonyEricsson';
553       $this->version = $regs[1];
554       $this->bot = false;
555       $this->mobile = true;
556     }
557     elseif (preg_match('|SIE-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
558       $this->brand = 'Siemens';
559       $this->version = $regs[1];
560       $this->bot = false;
561       $this->mobile = true;
562     }
563     elseif (preg_match('|MOT-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
564       $this->brand = 'Motorola';
565       $this->version = $regs[1];
566       $this->bot = false;
567       $this->mobile = true;
568     }
569     elseif (preg_match('|IXI/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
570       $this->brand = 'IXI';
571       $this->version = $regs[1];
572       $this->bot = false;
573       $this->mobile = true;
574     }
575     elseif (preg_match('|NewsFox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
576       $this->brand = 'NewsFox';
577       $this->version = $regs[1];
578       $this->bot = false;
579     }
580     elseif (preg_match('|rdfbot/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
581       $this->brand = 'rdfbot';
582       $this->version = $regs[1];
583       $this->bot = false;
584     }
585     elseif (preg_match('|IBM-WebExplorer-DLL/v([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
586       $this->brand = 'WebExplorer';
587       $this->version = $regs[1];
588       $this->bot = false;
589     }
590     elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
591       $this->brand = 'ELinks';
592       $this->version = $regs[1];
593       $this->bot = false;
594     }
595     elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
596       $this->brand = 'Links';
597       $this->version = $regs[1];
598       $this->bot = false;
599     }
600     elseif (preg_match('|WinHttp.WinHttpRequest.([0-9\.]+)|i', $this->uastring, $regs)) {
601       $this->brand = 'WinHttpRequest';
602       $this->version = $regs[1];
603       $this->bot = false;
604     }
605     elseif (preg_match('|alpha[/ ]06; AmigaOS|i', $this->uastring, $regs)) {
606       $this->brand = 'Alpha 06';
607       $this->version = null;
608       $this->bot = false;
609     }
610     elseif (preg_match('|; arexx[\);]|i', $this->uastring, $regs)) {
611       $this->brand = 'ARexx';
612       $this->version = null;
613       $this->bot = false;
614     }
615     elseif (preg_match('|; Voyager; AmigaOS[\);]|i', $this->uastring, $regs)) {
616       $this->brand = 'AmigaVoyager';
617       $this->version = null;
618       $this->bot = false;
619     }
620     elseif (preg_match('|AWEB ([0-9a-zA-Z\.+ ]+)|', $this->uastring, $regs)) {
621       $this->brand = 'AWEB';
622       $this->version = $regs[1];
623       $this->bot = false;
624     }
625     elseif (preg_match('|X ([0-9a-zA-Z\.+ ]+); Commodore 64|', $this->uastring, $regs)) {
626       $this->brand = 'X';
627       $this->version = $regs[1];
628       $this->bot = false;
629     }
630     elseif (preg_match('|DB Browse ([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
631       $this->brand = 'DB Browse';
632       $this->version = $regs[1];
633       $this->bot = false;
634     }
635     elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
636       $this->brand = 'ZyBorg';
637       $this->version = $regs[1];
638       $this->bot = true;
639     }
640     elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
641       $this->brand = 'Ask Jeeves';
642       $this->version = $regs[1];
643       $this->bot = true;
644     }
645     elseif (preg_match('|heritrix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
646       $this->brand = 'Heritrix';
647       $this->version = $regs[1];
648       $this->bot = true;
649     }
650     elseif (preg_match('|heritrix([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
651       $this->brand = 'Heritrix';
652       $this->version = str_replace('-', '.', $regs[1]);
653       $this->bot = true;
654     }
655     elseif (preg_match('|SBSearch/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
656       $this->brand = 'SBSearch';
657       $this->version = $regs[1];
658       $this->bot = true;
659     }
660     elseif (preg_match('|Powermarks/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
661       $this->brand = 'Powermarks';
662       $this->version = $regs[1];
663       $this->bot = true;
664     }
665     elseif (preg_match('|TopBlogsInfo/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
666       $this->brand = 'TopBlogsInfo';
667       $this->version = $regs[1];
668       $this->bot = true;
669     }
670     elseif (preg_match('|picmole/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
671       $this->brand = 'picmole';
672       $this->version = $regs[1];
673       $this->bot = true;
674     }
675     elseif (preg_match('|([0-9a-zA-Z\._+-]+bot)/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
676       $this->brand = $regs[1];
677       $this->version = $regs[2];
678       $this->bot = true;
679     }
680     elseif (preg_match('|VoilaBot ((BETA )?[0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
681       $this->brand = 'VoilaBot';
682       $this->version = $regs[1];
683       $this->bot = true;
684     }
685     elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
686       $this->brand = 'Slurp';
687       $this->version = null;
688       $this->bot = true;
689     }
690     elseif (preg_match('|Check&amp;Get ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
691       $this->brand = 'Check&Get';
692       $this->version = $regs[1];
693       $this->bot = true;
694     }
695     elseif (preg_match('|WebCapture ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
696       $this->brand = 'WebCapture';
697       $this->version = $regs[1];
698       $this->bot = true;
699     }
700     elseif (preg_match('|WebMon ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
701       $this->brand = 'WebMon';
702       $this->version = $regs[1];
703       $this->bot = true;
704     }
705     elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
706       $this->brand = 'Gulper Web Bot';
707       $this->version = $regs[1];
708       $this->bot = true;
709     }
710     elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
711       $this->brand = 'HTTrack';
712       $this->version = $regs[1];
713       $this->bot = true;
714     }
715     elseif (preg_match('|Advista Crawler ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
716       $this->brand = 'HTTrack';
717       $this->version = $regs[1];
718       $this->bot = true;
719     }
720     elseif (preg_match('|Seznam screenshot-generator ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
721       $this->brand = 'Seznam screenshot-generator';
722       $this->version = $regs[1];
723       $this->bot = true;
724     }
725     elseif (preg_match('|Yahoo! SearchMonkey ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
726       $this->brand = 'Yahoo! SearchMonkey';
727       $this->version = $regs[1];
728       $this->bot = true;
729     }
730     elseif (preg_match('|Yahoo Pipes ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
731       $this->brand = 'Yahoo! Pipes';
732       $this->version = $regs[1];
733       $this->bot = true;
734     }
735     elseif (preg_match('|Firebat ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
736       $this->brand = 'Firebat';
737       $this->version = $regs[1];
738       $this->bot = true;
739     }
740     elseif (preg_match('|Twiceler-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
741       $this->brand = 'Twiceler';
742       $this->version = $regs[1];
743       $this->bot = true;
744     }
745     elseif (preg_match('|Nu_?tch-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
746       $this->brand = 'Nutch';
747       $this->version = $regs[1];
748       $this->bot = true;
749     }
750     elseif (preg_match('|Microsoft URL Control - ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
751       $this->brand = 'Microsoft URL Control';
752       $this->version = $regs[1];
753       $this->bot = true;
754     }
755     elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
756       $this->brand = 'AC-Plug';
757       $this->version = $regs[1];
758       $this->bot = true;
759     }
760     elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
761       $this->brand = 'Unknown bot (IE5.5)';
762       $this->version = null;
763       $this->bot = true;
764     }
765     elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
766       $this->brand = 'Unknown bot (Mozilla)';
767       $this->version = null;
768       $this->bot = true;
769     }
770     elseif (preg_match('|ICCrawler|i', $this->uastring, $regs)) {
771       $this->brand = 'ICCrawler';
772       $this->version = null;
773       $this->bot = true;
774     }
775     elseif (preg_match('|KaloogaBot|', $this->uastring, $regs)) {
776       $this->brand = 'KaloogaBot';
777       $this->version = null;
778       $this->bot = true;
779     }
780     elseif (preg_match('|ScoutJet|', $this->uastring, $regs)) {
781       $this->brand = 'ScoutJet';
782       $this->version = null;
783       $this->bot = true;
784     }
785     elseif (preg_match('|http://www.livedir.net|', $this->uastring, $regs)) {
786       $this->brand = 'livedir.net';
787       $this->version = null;
788       $this->bot = true;
789     }
790     elseif (preg_match('|WebClipping.com|', $this->uastring, $regs)) {
791       $this->brand = 'WebClipping.com';
792       $this->version = null;
793       $this->bot = true;
794     }
795     elseif (preg_match('|newstin.com|', $this->uastring, $regs)) {
796       $this->brand = 'newstin.com';
797       $this->version = null;
798       $this->bot = true;
799     }
800     elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
801       $this->brand = 'almaden crawler';
802       $this->version = null;
803       $this->bot = true;
804     }
805     elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) ||
806             preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
807       $this->brand = 'BlitzBOT';
808       $this->version = null;
809       $this->bot = true;
810     }
811     elseif (preg_match('|Really Gmane.org\'s favicon grabber|', $this->uastring)) {
812       $this->brand = 'Really Gmane.org\'s favicon grabber';
813       $this->version = null;
814       $this->bot = true;
815     }
816     elseif (preg_match('|Girafabot|', $this->uastring)) {
817       $this->brand = 'Girafabot';
818       $this->version = null;
819       $this->bot = true;
820     }
821     elseif (preg_match('|Arachmo|', $this->uastring)) {
822       $this->brand = 'Arachmo';
823       $this->version = null;
824       $this->bot = true;
825     }
826     elseif (preg_match('|OsO|', $this->uastring)) {
827       $this->brand = 'OsO';
828       $this->version = null;
829       $this->bot = true;
830     }
831     elseif (preg_match('|Yoono|', $this->uastring)) {
832       $this->brand = 'Yoono';
833       $this->version = null;
834       $this->bot = true;
835     }
836     elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
837       $this->brand = 'efp';
838       $this->version = null;
839       $this->bot = true;
840     }
841     elseif (preg_match('|Indy Library|', $this->uastring)) {
842       $this->brand = 'Indy Library';
843       $this->version = null;
844       $this->bot = true;
845     }
846     elseif (preg_match('|Linkman|', $this->uastring)) {
847       $this->brand = 'Linkman';
848       $this->version = null;
849       $this->bot = true;
850     }
851     elseif (preg_match('|Sage|', $this->uastring, $regs)) {
852       $this->brand = 'Sage';
853       $this->version = null;
854       $this->bot = true;
855     }
856     elseif (preg_match('|Google Desktop|', $this->uastring)) {
857       $this->brand = 'Google Desktop';
858       $this->version = null;
859       $this->bot = true;
860     }
861     elseif (preg_match('|^Firefly|', $this->uastring)) {
862       // comes here with correct value but would be detected as MSIE
863     }
864     elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
865       $this->brand = 'Steganos Internet Anonym';
866       $this->version = $regs[1];
867       $this->bot = false;
868     }
869     elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
870       $this->brand = 'Steganos Internet Anonym';
871       $this->version = $regs[1];
872       $this->bot = false;
873     }
874     elseif (preg_match('|BorderManager ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
875       $this->brand = 'BorderManager';
876       $this->version = $regs[1];
877       $this->bot = false;
878     }
879     elseif (preg_match('|WebWasher ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
880       $this->brand = 'WebWasher';
881       $this->version = $regs[1];
882       $this->bot = false;
883     }
884     elseif (preg_match('|SaferSurf|', $this->uastring, $regs)) {
885       $this->brand = 'SaferSurf';
886       $this->version = null;
887       $this->bot = false;
888     }
889     elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
890       $this->brand = 'Avant Browser';
891       $this->version = null;
892       $this->bot = false;
893     }
894     elseif (preg_match('|Browser[^/]+(http://www.avantbrowser.com)|', $this->uastring)) {
895       $this->brand = 'Avant Browser';
896       $this->version = null;
897       $this->bot = false;
898     }
899     elseif (preg_match('|Maxthon|', $this->uastring)) {
900       $this->brand = 'Maxthon';
901       $this->version = null;
902       $this->bot = false;
903     }
904     elseif (preg_match('|MyIE2|', $this->uastring)) {
905       $this->brand = 'MyIE2';
906       $this->version = null;
907       $this->bot = false;
908     }
909     elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
910       $this->brand = 'Crazy Browser';
911       $this->version = $regs[1];
912       $this->bot = false;
913     }
914     elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
915       $this->brand = 'AvantGo';
916       $this->version = $regs[1];
917       $this->bot = false;
918     }
919     elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
920       $this->brand = 'MSN';
921       $this->version = $regs[1];
922       $this->bot = false;
923     }
924     elseif (preg_match('|America Online Browser [0-9a-zA-Z\.+]+; rev([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
925       $this->brand = 'AOL Browser';
926       $this->version = $regs[1];
927       $this->bot = false;
928     }
929     elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
930       $this->brand = 'Microsoft FrontPage';
931       $this->version = $regs[1];
932       $this->bot = false;
933     }
934     elseif (preg_match('|Microsoft Internet Explorer/4.0b1|', $this->uastring, $regs)) {
935       $this->brand = 'Microsoft Internet Explorer';
936       $this->version = '1.0';
937       $this->bot = false;
938     }
939     elseif (preg_match('|MSIE 7\.0.+Trident/4.0|', $this->uastring, $regs)) {
940       $this->brand = 'Microsoft Internet Explorer';
941       $this->version = "8.0";
942       $this->bot = false;
943     }
944     elseif (preg_match('|MSIE 7\.0.+Trident/5.0|', $this->uastring, $regs)) {
945       $this->brand = 'Microsoft Internet Explorer';
946       $this->version = "9.0";
947       $this->bot = false;
948     }
949     elseif (preg_match('|MSIE 7\.0.+Trident/6.0|', $this->uastring, $regs)) {
950       $this->brand = 'Microsoft Internet Explorer';
951       $this->version = "10.0";
952       $this->bot = false;
953     }
954     elseif (preg_match('|Trident\/[0-9a-zA-Z\.+]+; ([^\)]+; )?rv:([0-9\.+]+)|', $this->uastring, $regs)) {
955       $this->brand = 'Microsoft Internet Explorer';
956       $this->version = $regs[2];
957       $this->bot = false;
958     }
959     elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
960       $this->brand = 'Microsoft Internet Explorer';
961       $this->version = $regs[1];
962       $this->bot = false;
963     }
964     elseif (preg_match('|MSPIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
965       $this->brand = 'Microsoft Pocket Internet Explorer';
966       $this->version = $regs[1];
967       $this->bot = false;
968       $this->mobile = true;
969     }
970     elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
971             (strpos($this->uastring, 'compatible') === false) && (strpos($this->uastring, 'Gecko/') === false) &&
972             (intval($regs[1]) < 5)) {
973       $this->brand = 'Netscape';
974       $this->version = $regs[1];
975       if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
976       $this->bot = false;
977     }
978     elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
979       $this->brand = (strpos($this->uastring, 'compatible') !== false)?'Mozilla-compatible (unknown)':'Mozilla (unknown)';
980       $this->version = null;
981       $this->bot = false;
982     }
983
984     $botArray = [
985       'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL',
986       'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', 'ichiro',
987       'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', 'appie', 'larbin',
988       'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', 'FavOrg', 'findlinks', 'DataCha0s',
989       'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', 'Yandex', 'Yeti', 'SEO Scanner', 'Feedbin feed-id',
990       'Austronaut-URL-Checker', 'check_ssl_cert', 'check_http', 'vdirsyncer', 'FreshRSS', 'UniversalFeedParser',
991       'Cloudflare Custom Hostname Verification', 'Scoop.it',
992     ];
993
994     if (in_array($this->brand, $botArray)) {
995       $this->bot = true;
996     }
997
998     if (($this->brand == 'Microsoft Pocket Internet Explorer') ||
999         (strpos($this->brand, 'BlackBerry') !== false)) {
1000       $this->mobile = true;
1001     }
1002   }
1003
1004   public function getBrand() {
1005     return $this->brand;
1006   }
1007
1008   public function getVersion() {
1009     return $this->version;
1010   }
1011
1012   public function getAcceptLanguages() {
1013     if (!isset($this->uadata['accept-languages'])) {
1014       $headers = getAllHeaders();
1015       $accLcomp = explode(',', ($headers['Accept-Language'] ?? ''));
1016       $accLang = [];
1017       foreach ($accLcomp as $lcomp) {
1018         if (strlen($lcomp)) {
1019           $ldef = explode(';', $lcomp);
1020           if (count($ldef) > 1 && strpos($ldef[1], 'q=') === 0) {
1021             $accLang[$ldef[0]] = substr($ldef[1], 2);
1022           }
1023           else {
1024             $accLang[$ldef[0]] = 1;
1025           }
1026         }
1027       }
1028       $this->uadata['accept-languages'] = $accLang;
1029     }
1030     return $this->uadata['accept-languages'];
1031   }
1032
1033   public function getUAString() {
1034     return $this->uastring;
1035   }
1036
1037   public function getEngine() {
1038     // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
1039     if (!isset($this->uadata['engine'])) {
1040       $this->uadata['engine'] = 'unknown';
1041       $this->uadata['geckodate'] = null;
1042       if (!$this->bot) {
1043         if (preg_match('|Gecko/([0-9\.]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
1044           $this->uadata['engine'] = 'gecko';
1045           // If it looks like a version number, i.e. shorter than 4 chars or has a . in it, it's no date.
1046           if ((strlen($regs[1]) > 4) && (strpos($regs[1], '.') === false)) {
1047             $this->uadata['geckodate'] = $regs[1];
1048           }
1049           else {
1050             $this->uadata['geckodate'] = null;
1051             $this->uadata['eng_version'] = $regs[1];
1052           }
1053         }
1054         elseif (preg_match('|Edge/([0-9\.]+)|', $this->uastring, $regs)) {
1055           $this->uadata['engine'] = 'edgehtml';
1056           $this->uadata['eng_version'] = $regs[1];
1057         }
1058         elseif ((strpos($this->brand, 'Internet Explorer') !== false) ||  (strpos($this->brand, 'FrontPage') !== false)) {
1059           if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
1060             $this->uadata['engine'] = 'tasman';
1061           }
1062           else {
1063             $this->uadata['engine'] = 'trident';
1064           }
1065         }
1066         elseif (preg_match('|WebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1067           $this->uadata['engine'] = 'webkit';
1068           $this->uadata['eng_version'] = $regs[1];
1069         }
1070         elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
1071           $this->uadata['engine'] = 'khtml';
1072         }
1073         elseif (strpos($this->brand, 'Netscape') !== false) {
1074           // non-Gecko Netscape browsers
1075           if (intval($this->version) <= 4) {
1076             $this->uadata['engine'] = 'nscp';
1077           }
1078           elseif (strpos($this->uastring, 'MSIE') !== false) {
1079             $this->uadata['engine'] = 'trident';
1080           }
1081         }
1082         elseif (strpos($this->brand, 'Opera') !== false) {
1083           $this->uadata['engine'] = 'presto';
1084         }
1085         elseif ((strpos($this->brand, 'iTunes') !== false) || (strpos($this->brand, 'nook browser') !== false)) {
1086           $this->uadata['engine'] = 'webkit';
1087         }
1088         elseif (strpos($this->brand, 'Dillo') !== false) {
1089           $this->uadata['engine'] = 'gzilla';
1090         }
1091         elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
1092           $this->uadata['engine'] = 'links';
1093         }
1094         elseif ((strpos($this->brand, 'Lynx') !== false)) {
1095           $this->uadata['engine'] = 'lynx';
1096         }
1097         elseif ((strpos($this->brand, 'ICEbrowser') !== false) || (strpos($this->brand, 'ICE Browser') !== false)) {
1098           $this->uadata['engine'] = 'icestorm';
1099         }
1100         elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
1101           $this->uadata['engine'] = 'netfront';
1102           $this->uadata['eng_version'] = $regs[1];
1103         }
1104         elseif ((strpos($this->brand, 'PlayStation') !== false) || (strpos($this->brand, 'NetFront') !== false)) {
1105           $this->uadata['engine'] = 'netfront';
1106         }
1107         elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
1108                 (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
1109                 (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
1110           $this->uadata['engine'] = 'trident';
1111         }
1112         elseif (strpos($this->brand, 'Galeon') !== false) {
1113           $this->uadata['engine'] = 'gecko';
1114         }
1115         elseif (strpos($this->brand, 'WebPro') !== false) {
1116           $this->uadata['engine'] = 'nscp';
1117         }
1118       }
1119     }
1120     return $this->uadata['engine'];
1121   }
1122
1123   public function hasEngine($rnd_engine) {
1124     return ($this->getEngine() == $rnd_engine);
1125   }
1126
1127   public function getEngineVersion() {
1128     if (!isset($this->uadata['eng_version'])) {
1129       $this->uadata['eng_version'] = null;
1130       // getOS() should get the date for us
1131       $this->getOS();
1132     }
1133     return $this->uadata['eng_version'];
1134   }
1135
1136   public function getOS() {
1137     if (!isset($this->uadata['os'])) {
1138       $this->uadata['os'] = null;
1139       if (!$this->bot) {
1140         if ($this->hasEngine('gecko')) {
1141           if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1142             $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1143             $this->uadata['lang'] = (strpos($regs[4],'chrome://')===false)?$regs[4]:null;
1144             $this->uadata['eng_version'] = $regs[5];
1145           }
1146           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1147             $this->uadata['os'] = $regs[2];
1148             $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1149             $this->uadata['eng_version'] = $regs[4];
1150           }
1151           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1152             $this->uadata['os'] = $regs[2];
1153             $this->uadata['lang'] = null;
1154             $this->uadata['eng_version'] = $regs[3];
1155           }
1156           elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); x64; rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1157             $this->uadata['os'] =  $regs[1].' ('.$regs[2].')';
1158             $this->uadata['lang'] = null;
1159             $this->uadata['eng_version'] = $regs[3];
1160           }
1161           elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
1162             $this->uadata['os'] = $regs[2];
1163             $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
1164             $this->uadata['eng_version'] = $regs[4];
1165           }
1166           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1167             $this->uadata['os'] = $regs[2];
1168             $this->uadata['lang'] = $regs[3];
1169             $this->uadata['eng_version'] = 'M'.$regs[4];
1170           }
1171           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
1172             $this->uadata['os'] = $regs[1];
1173             $this->uadata['lang'] = $regs[2];
1174             $this->uadata['eng_version'] = 'M'.$regs[3];
1175           }
1176           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1177             $this->uadata['os'] = $regs[2];
1178             $this->uadata['lang'] = $regs[3];
1179             $this->uadata['eng_version'] = null;
1180           }
1181           elseif (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Mobile|Tablet); rv:([^\);]+)\)#', $this->uastring, $regs)) {
1182             $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1183             $this->uadata['lang'] = null;
1184             $this->uadata['eng_version'] = $regs[3];
1185             $this->mobile = ($regs[2] == 'Mobile');
1186           }
1187           elseif (preg_match('#Mozilla/5.0 \((Mobile|Tablet); [^;]+; rv:([^\);]+)\)#', $this->uastring, $regs)) {
1188             $this->uadata['os'] = 'Firefox OS ('.$regs[1].')';
1189             $this->uadata['lang'] = null;
1190             $this->uadata['eng_version'] = $regs[2];
1191             $this->mobile = ($regs[1] == 'Mobile');
1192           }
1193           elseif (preg_match('#Mozilla/5.0 \(([^;]+); Viera; rv:([^\);]+)\)#', $this->uastring, $regs)) {
1194             $this->uadata['os'] = 'Firefox OS (TV, '.$regs[1].')';
1195             $this->uadata['lang'] = null;
1196             $this->uadata['eng_version'] = $regs[2];
1197           }
1198           elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1199             if ((strpos($regs[2], 'Linux') !== false) && ($regs[1] != 'X11')) {
1200               $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1201             }
1202             else {
1203               $this->uadata['os'] = $regs[2];
1204             }
1205             $this->uadata['lang'] = null;
1206             $this->uadata['eng_version'] = $regs[3];
1207           }
1208           elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
1209             $this->uadata['os'] = $regs[2];
1210             $this->uadata['lang'] = null;
1211             $this->uadata['eng_version'] = null;
1212           }
1213           elseif (preg_match('#Mozilla/5.0 \((Mobile|Tablet); rv:([^\);]+)\)#', $this->uastring, $regs)) {
1214             $this->uadata['os'] = 'Firefox OS ('.$regs[1].')';
1215             $this->uadata['lang'] = null;
1216             $this->uadata['eng_version'] = $regs[2];
1217             $this->mobile = ($regs[1] == 'Mobile');
1218           }
1219           elseif (preg_match('|Mozilla/5.0 \(([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
1220             $this->uadata['os'] = $regs[1];
1221             $this->uadata['lang'] = null;
1222             $this->uadata['eng_version'] = $regs[2];
1223           }
1224           elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
1225             $this->uadata['os'] = $regs[2];
1226             $this->uadata['lang'] = null;
1227             $this->uadata['eng_version'] = null;
1228           }
1229           elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
1230             $this->uadata['os'] = 'Debian Linux';
1231             $this->uadata['lang'] = null;
1232             $this->uadata['eng_version'] = null;
1233           }
1234           if (($this->brand == 'Firefox') && (intval($this->version) >= 110)) {
1235             $this->uadata['eng_version'] = $this->version;
1236           }
1237         }
1238         elseif ($this->hasEngine('edgehtml')) {
1239           if (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Win64); ([^\);]+)\)#', $this->uastring, $regs)) {
1240             $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1241           }
1242           elseif (preg_match('#Mozilla/5.0 \(([^;]+Phone[^;]+); [^\)]+\)#i', $this->uastring, $regs)) {
1243             $this->uadata['os'] = $regs[1];
1244           }
1245         }
1246         elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
1247           if (preg_match('/Mozilla\/[^\(]+ \((IE [^;]+[^\)]*; )?((?:Mac|Win)[^;]+); ?(Win64|WOW64); ?Trident\/([^;\)]+);/i', $this->uastring, $regs)) {
1248             $this->uadata['eng_version'] = $regs[4];
1249             $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1250             $this->uadata['lang'] = null;
1251           }
1252           elseif (preg_match('/Mozilla\/[^\(]+ \((IE [^;]+[^\)]*; )?((?:Mac|Win)[^;]+); ?Trident\/([^;\)]+);/i', $this->uastring, $regs)) {
1253             $this->uadata['eng_version'] = $regs[3];
1254             $this->uadata['os'] = $regs[2];
1255             $this->uadata['lang'] = null;
1256           }
1257           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1258             $this->uadata['eng_version'] = $regs[3];
1259             $this->uadata['os'] = $regs[1].' ('.$regs[2].')';
1260             $this->uadata['lang'] = null;
1261           }
1262           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE [^;]+[^\)]*; ?((?:Mac|Win)[^;]+); ?[^\)]*Trident\/([^;\)]+)[^\)]*\)/i', $this->uastring, $regs)) {
1263             $this->uadata['eng_version'] = $regs[2];
1264             $this->uadata['os'] = $regs[1];
1265             $this->uadata['lang'] = null;
1266           }
1267           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+); ?(Win64|WOW64)[^\)]*\)/i', $this->uastring, $regs)) {
1268             $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1269             $this->uadata['os'] = $regs[2].' ('.$regs[3].')';
1270             $this->uadata['lang'] = null;
1271             $this->mobile = (strpos($this->uastring,'MSPIE') !== false);
1272           }
1273           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1274             $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:"ie".$regs[1];
1275             $this->uadata['os'] = $regs[2];
1276             $this->uadata['lang'] = null;
1277             $this->mobile = (strpos($this->uastring,'MSPIE') !== false);
1278           }
1279           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
1280             $this->uadata['eng_version'] = "ie".$regs[1];
1281             $this->uadata['os'] = null;
1282             $this->uadata['lang'] = null;
1283           }
1284           elseif (preg_match('/Microsoft Internet Explorer\/[^\s]+ \(((?:Mac|Win)[^;\)]+)\)/i', $this->uastring, $regs)) {
1285             $this->uadata['eng_version'] = "ie".$this->getVersion();
1286             $this->uadata['os'] = $regs[1];
1287             $this->uadata['lang'] = null;
1288           }
1289           elseif (preg_match('/Microsoft Pocket Internet Explorer\/[^\s]+/i', $this->uastring, $regs)) {
1290             $this->uadata['eng_version'] = null;
1291             $this->uadata['os'] = 'Windows CE';
1292             $this->uadata['lang'] = null;
1293           }
1294         }
1295         elseif ($this->hasEngine('khtml')) {
1296           if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1297             $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
1298             $this->uadata['os'] = $regs[2];
1299             $this->uadata['lang'] = $regs[5];
1300           }
1301           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
1302             $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
1303             $this->uadata['os'] = $regs[2];
1304             $this->uadata['lang'] = null;
1305           }
1306           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
1307             $this->uadata['os'] = $regs[1];
1308             $this->uadata['lang'] = null;
1309             $this->uadata['eng_version'] = null;
1310           }
1311         }
1312         elseif ($this->hasEngine('webkit')) {
1313           if (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+); ([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1314             $this->uadata['os'] = $regs[2];
1315             $this->uadata['lang'] = $regs[3];
1316           }
1317           elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1318             if (strpos($regs[3], '/') !== false) {
1319               $this->uadata['os'] = $regs[1];
1320               $this->uadata['lang'] = null;
1321             }
1322             else {
1323               $this->uadata['os'] = $regs[2];
1324               $this->uadata['lang'] = $regs[3];
1325             }
1326           }
1327           elseif (preg_match('|Mozilla/5.0 \(([^;]+); Linux; ([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
1328             $this->uadata['os'] = $regs[2];
1329             $this->uadata['lang'] = $regs[3];
1330           }
1331           elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
1332             $this->uadata['os'] = $regs[1];
1333             $this->uadata['lang'] = $regs[2];
1334           }
1335           elseif (preg_match('|Mozilla/5.0 \(Linux; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1336             // (Chrome for) Android - $regs[2] is device
1337             $this->uadata['os'] = $regs[1];
1338             $this->uadata['lang'] = null;
1339           }
1340           elseif (preg_match('|Mozilla/5.0 \(([^\);]+); ([^\);]+)\)|', $this->uastring, $regs)) {
1341             if (($regs[1] == 'X11') || ($regs[1] == 'Macintosh') || ($regs[1] == 'iPhone')) {
1342               $this->uadata['os'] = $regs[2];
1343             }
1344             else {
1345               $this->uadata['os'] = $regs[1];
1346               if ($regs[2] == 'NokiaN9') {
1347                  $this->uadata['os'] .= ' Harmattan';
1348               }
1349             }
1350             $this->uadata['lang'] = null;
1351           }
1352           elseif (preg_match('|Mozilla/5.0 \(([^\);]+)\)|', $this->uastring, $regs)) {
1353             $this->uadata['os'] = $regs[1];
1354             $this->uadata['lang'] = null;
1355           }
1356           elseif (preg_match('|Midori/[^\(]+ \((?:X11; )?([^;]+); U; ([^\)]+)\)|i', $this->uastring, $regs)) {
1357             $this->uadata['os'] = $regs[1];
1358             $this->uadata['lang'] = $regs[2];
1359           }
1360           if ($this->brand == 'Silk') {
1361             // For some reason, Amazon spoofs us and tells us it's on MacOS X!
1362             $this->uadata['os'] = 'Android';
1363           }
1364           if (preg_match('| Mobile |', $this->uastring)) {
1365             $this->mobile = true;
1366           }
1367         }
1368         elseif ($this->hasEngine('presto')) {
1369           // Opera < 8
1370           if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1371             $this->uadata['eng_version'] = $this->getVersion();
1372             $this->uadata['os'] = $regs[1];
1373             $this->uadata['lang'] = $regs[2];
1374           }
1375           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1376             $this->uadata['eng_version'] = $this->getVersion();
1377             $this->uadata['os'] = $regs[1];
1378             $this->uadata['lang'] = $regs[2];
1379           }
1380           elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+\s+\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
1381             $this->uadata['eng_version'] = $this->getVersion();
1382             $this->uadata['os'] = $regs[1];
1383             $this->uadata['lang'] = $regs[2];
1384           }
1385           // Opera mini
1386           elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini; ([a-z_-]+); /i', $this->uastring, $regs)) {
1387             $this->uadata['eng_version'] = null;
1388             $this->uadata['os'] = $regs[2];
1389             $this->uadata['lang'] = $regs[3];
1390           }
1391           elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini\/[^;]+; ([a-z_-]+); /i', $this->uastring, $regs)) {
1392             $this->uadata['eng_version'] = $regs[1];
1393             $this->uadata['os'] = $regs[2];
1394             $this->uadata['lang'] = $regs[3];
1395           }
1396           // Opera >= 8
1397           elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
1398             $this->uadata['eng_version'] = $this->getVersion();
1399             $this->uadata['os'] = $regs[1];
1400             $this->uadata['lang'] = $regs[2];
1401           }
1402           elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1403             $this->uadata['eng_version'] = $this->getVersion();
1404             $this->uadata['os'] = $regs[1];
1405             $this->uadata['lang'] = $regs[2];
1406           }
1407           elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
1408             $this->uadata['eng_version'] = $this->getVersion();
1409             $this->uadata['os'] = $regs[1];
1410             $this->uadata['lang'] = $regs[2];
1411           }
1412           // Opera 9 Firefox-spoofing
1413           elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
1414             $this->uadata['eng_version'] = $this->getVersion();
1415             $this->uadata['os'] = $regs[1];
1416             $this->uadata['lang'] = $regs[2];
1417           }
1418           if (preg_match('| Mobi|', $this->uastring)) {
1419             $this->mobile = true;
1420           }
1421         }
1422         elseif ($this->hasEngine('nscp')) {
1423           if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1424             $this->uadata['eng_version'] = $regs[1];
1425             $this->uadata['os'] = $regs[3];
1426             $this->uadata['lang'] = $regs[2];
1427           }
1428           elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1429             $this->uadata['eng_version'] = $regs[1];
1430             $this->uadata['os'] = $regs[3];
1431             $this->uadata['lang'] = $regs[2];
1432           }
1433           elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+)[^\(]+\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
1434             $this->uadata['eng_version'] = $regs[1];
1435             $this->uadata['os'] = $regs[2];
1436             $this->uadata['lang'] = null;
1437           }
1438         }
1439         elseif ($this->hasEngine('gzilla')) {
1440           $this->uadata['eng_version'] = $this->getVersion();
1441           $this->uadata['os'] = null;
1442           $this->uadata['lang'] = null;
1443         }
1444         elseif ($this->hasEngine('links')) {
1445           if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
1446             $this->uadata['eng_version'] = null;
1447             $this->uadata['os'] = $regs[1];
1448             $this->uadata['lang'] = null;
1449           }
1450         }
1451         elseif ($this->hasEngine('lynx')) {
1452           $this->uadata['eng_version'] = $this->getVersion();
1453           $this->uadata['os'] = null;
1454           $this->uadata['lang'] = null;
1455         }
1456         elseif ($this->hasEngine('icestorm')) {
1457           if (preg_match('/ICE Browser\/v?([0-9a-zA-Z\._+]+) \(Java [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
1458             $this->uadata['eng_version'] = str_replace('_', '.', $regs[1]);
1459             $this->uadata['os'] = $regs[2];
1460             $this->uadata['lang'] = null;
1461           }
1462           elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\).* ICEbrowser\/([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) {
1463             $this->uadata['eng_version'] = $regs[3];
1464             $this->uadata['os'] = $regs[1];
1465             $this->uadata['lang'] = $regs[2];
1466           }
1467         }
1468         else {
1469           $this->uadata['eng_version'] = null;
1470           $this->uadata['lang'] = null;
1471           if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
1472             $this->uadata['os'] = 'AmigaOS';
1473           }
1474           if (preg_match('/Commodore 64/i', $this->uastring, $regs)) {
1475             $this->uadata['os'] = 'Commodore 64';
1476           }
1477           elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
1478             $this->uadata['os'] = $regs[1];
1479           }
1480           elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
1481             $this->uadata['os'] = trim($regs[1]);
1482           }
1483           elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
1484             $this->uadata['os'] = trim($regs[1]);
1485           }
1486           elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
1487             $this->uadata['os'] = 'SymbianOS '.$regs[1];
1488           }
1489         }
1490         if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
1491         elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows NT 4.0'; }
1492         elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
1493         elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
1494         elseif ($this->uadata['os'] == 'Windows NT 5.1 (Win64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1495         elseif ($this->uadata['os'] == 'Windows NT 5.1 (WOW64)') { $this->uadata['os'] = 'Windows XP (64bit)'; }
1496         elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
1497         elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1498         elseif ($this->uadata['os'] == 'Windows NT 5.2 (Win64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1499         elseif ($this->uadata['os'] == 'Windows NT 5.2 (WOW64)') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1500         elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
1501         elseif ($this->uadata['os'] == 'Windows NT 6.0 (Win64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1502         elseif ($this->uadata['os'] == 'Windows NT 6.0 (WOW64)') { $this->uadata['os'] = 'Windows Vista (64bit)'; }
1503         elseif ($this->uadata['os'] == 'Windows NT 6.1') { $this->uadata['os'] = 'Windows 7'; }
1504         elseif ($this->uadata['os'] == 'Windows NT 6.1 (Win64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1505         elseif ($this->uadata['os'] == 'Windows NT 6.1 (WOW64)') { $this->uadata['os'] = 'Windows 7 (64bit)'; }
1506         elseif ($this->uadata['os'] == 'Windows NT 6.2') { $this->uadata['os'] = 'Windows 8'; }
1507         elseif ($this->uadata['os'] == 'Windows NT 6.2 (Win64)') { $this->uadata['os'] = 'Windows 8 (64bit)'; }
1508         elseif ($this->uadata['os'] == 'Windows NT 6.2 (WOW64)') { $this->uadata['os'] = 'Windows 8 (64bit)'; }
1509         elseif ($this->uadata['os'] == 'Windows NT 6.3') { $this->uadata['os'] = 'Windows 8.1'; }
1510         elseif ($this->uadata['os'] == 'Windows NT 6.3 (Win64)') { $this->uadata['os'] = 'Windows 8.1 (64bit)'; }
1511         elseif ($this->uadata['os'] == 'Windows NT 6.3 (WOW64)') { $this->uadata['os'] = 'Windows 8.1 (64bit)'; }
1512         elseif ($this->uadata['os'] == 'Windows NT 6.4') { $this->uadata['os'] = 'Windows 10'; }
1513         elseif ($this->uadata['os'] == 'Windows NT 6.4 (Win64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1514         elseif ($this->uadata['os'] == 'Windows NT 6.4 (WOW64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1515         elseif ($this->uadata['os'] == 'Windows NT 10.0') { $this->uadata['os'] = 'Windows 10'; }
1516         elseif ($this->uadata['os'] == 'Windows NT 10.0 (Win64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1517         elseif ($this->uadata['os'] == 'Windows NT 10.0 (WOW64)') { $this->uadata['os'] = 'Windows 10 (64bit)'; }
1518         elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
1519         elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
1520         elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
1521         elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
1522         elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
1523         elseif (preg_match('/iPhone OS ([\d_]+)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
1524         elseif (preg_match('/Mac ?OS ?X/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'MacOS X'; }
1525         elseif (preg_match('/Mac_P(ower|)PC/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'MacOS'; }
1526         elseif (strpos($this->uadata['os'] ?? '', 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1527         elseif (strpos($this->uadata['os'] ?? '', 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
1528         elseif (strpos($this->uadata['os'] ?? '', 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
1529         elseif (strpos($this->uadata['os'] ?? '', 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
1530         elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; }
1531         elseif (preg_match('/Android \(Linux (.+)\)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
1532         elseif (strpos($this->uadata['os'] ?? '', 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
1533         elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; }
1534         elseif (preg_match('/Symbian ?OS/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'SymbianOS'; }
1535
1536         if (strpos($this->uadata['os'] ?? '', 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
1537         elseif (strpos($this->uadata['os'] ?? '', 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1538         elseif (strpos($this->uadata['os'] ?? '', 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1539         elseif (strpos($this->uadata['os'] ?? '', 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
1540         elseif (strpos($this->uadata['os'] ?? '', 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
1541         elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
1542         elseif (strpos($this->uadata['os'] ?? '', 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
1543         elseif (strpos($this->uadata['os'] ?? '', 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
1544         elseif (strpos($this->uadata['os'] ?? '', 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
1545         elseif (strpos($this->uadata['os'] ?? '', 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
1546         elseif (strpos($this->uadata['os'] ?? '', 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
1547         elseif (strpos($this->uadata['os'] ?? '', 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
1548         elseif (strpos($this->uadata['os'] ?? '', 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
1549         elseif (strpos($this->uadata['os'] ?? '', 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
1550         elseif (strpos($this->uadata['os'] ?? '', 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
1551         elseif (strpos($this->uadata['os'] ?? '', 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
1552         elseif (strpos($this->uadata['os'] ?? '', 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
1553         elseif (strpos($this->uadata['os'] ?? '', 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
1554         elseif (strpos($this->uadata['os'] ?? '', 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
1555         elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
1556         elseif (strpos($this->uadata['os'] ?? '', 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
1557         elseif (strpos($this->uadata['os'] ?? '', 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
1558         elseif (strpos($this->uadata['os'] ?? '', 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
1559         elseif (strpos($this->uadata['os'] ?? '', 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
1560         elseif (strpos($this->uadata['os'] ?? '', 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
1561         elseif (strpos($this->uadata['os'] ?? '', 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
1562         elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1563         elseif (strpos($this->uadata['os'] ?? '', 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1564         elseif (strpos($this->uadata['os'] ?? '', 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
1565         elseif (strpos($this->uadata['os'] ?? '', 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
1566         elseif (strpos($this->uadata['os'] ?? '', 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
1567         elseif (strpos($this->uadata['os'] ?? '', 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
1568         else { $this->uadata['platform'] = $this->uadata['os']; }
1569
1570         if (strpos($this->uadata['os'] ?? '', 'Windows Phone OS') !== false) { $this->mobile = true; }
1571         elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->mobile = true; }
1572
1573         $this->uadata['lang'] = str_replace('_', '-', ($this->uadata['lang'] ?? ''));
1574       }
1575     }
1576     return $this->uadata['os'];
1577   }
1578
1579   public function getPlatform() {
1580     if (!isset($this->uadata['platform'])) {
1581       $this->uadata['platform'] = null;
1582       // getOS() should get the date for us
1583       $this->getOS();
1584     }
1585     return $this->uadata['platform'];
1586   }
1587
1588   public function getLanguage() {
1589     if (!isset($this->uadata['lang'])) {
1590       $this->uadata['lang'] = null;
1591       // getOS() should get the date for us
1592       $this->getOS();
1593     }
1594     return $this->uadata['lang'];
1595   }
1596
1597   public function getGeckoDate() {
1598     if (!isset($this->uadata['geckodate'])) {
1599       $this->uadata['geckodate'] = null;
1600       // getEngine() should get the date for us
1601       $this->getEngine();
1602     }
1603     return $this->uadata['geckodate'];
1604   }
1605
1606   public function getGeckoTime() {
1607     if (!isset($this->uadata['geckotime'])) {
1608       $this->uadata['geckotime'] = null;
1609       if (!is_null($this->getGeckoDate())) {
1610         $use_time = (strlen($this->getGeckoDate()) > 8);
1611         $gd_str = substr($this->getGeckoDate(),0,4).'-'.substr($this->getGeckoDate(),4,2).'-'.substr($this->getGeckoDate(),6,2);
1612         if ($use_time) {
1613           $gd_str .= substr($this->getGeckoDate(),8,2).':00';
1614           $old_tz = date_default_timezone_get();
1615           date_default_timezone_set("America/Los_Angeles");
1616         }
1617         $this->uadata['geckotime'] = strtotime($gd_str);
1618         if ($use_time) { date_default_timezone_set($old_tz); }
1619       }
1620     }
1621     return $this->uadata['geckotime'];
1622   }
1623
1624   public function isBot() {
1625     return $this->bot;
1626   }
1627
1628   public function isMobile() {
1629     if (!isset($this->uadata['os'])) {
1630       // getOS() makes sure that also the mobile tag is set correctly
1631       $this->getOS();
1632     }
1633     return $this->mobile;
1634   }
1635
1636   public function isns() {
1637     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1638     return (strpos($this->brand, 'Netscape') !== false);
1639   }
1640   public function isns4() {
1641     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1642     return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4));
1643   }
1644   public function isie() {
1645     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1646     return $this->hasEngine('trident');
1647   }
1648   public function geckodate() {
1649     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1650     return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0);
1651   }
1652   public function geckobased() {
1653     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1654     return $this->hasEngine('gecko');
1655   }
1656   public function khtmlbased() {
1657     trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1658     return $this->hasEngine('khtml');
1659   }
1660 }
1661 ?>