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