break too long lines, correct RRDtool links
[php-utility-classes.git] / include / classes / useragent.php-class
CommitLineData
31733e08 1<?php
a5813ca3 2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is KaiRo's userAgent detection.
16 *
17 * The Initial Developer of the Original Code is
18 * KaiRo - Robert Kaiser.
c863ed1e 19 * Portions created by the Initial Developer are Copyright (C) 2003-2007
a5813ca3 20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s): Robert Kaiser <kairo@kairo.at>
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
31733e08 38class userAgent {
39 // userAgent PHP class
40 // get user agent and tell us what Browser is accessing
41 //
3077a4f6 42 // function __construct([$ua_string])
1defa974 43 // CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables.
31733e08 44 //
3077a4f6 45 // private $uastring
31733e08 46 // the plain User Agent string
3077a4f6 47 // private $brand
bf78d3ed 48 // the User Agent brand name
3077a4f6 49 // private $version
31733e08 50 // the User Agent version
3077a4f6 51 // private $bot
a8464009 52 // bool: true if this agent is a bot
3077a4f6 53 // private $uadata
f983aa36 54 // array of static user agent data (static vars in functions are set for all objects of this class!)
31733e08 55 //
3077a4f6 56 // public function getBrand()
23585ba2 57 // returns the User Agent Brand Name
bf78d3ed 58 //
3077a4f6 59 // public function getVersion()
23585ba2 60 // returns the User Agent version
61 //
3077a4f6 62 // public function getAcceptLanguages()
4210e7b0 63 // returns an associated array with the accepted languages of this UA
64 // keys are language codes, values are q factors (weights)
65 //
3077a4f6 66 // public function getUAString()
f983aa36 67 // returns the full User Agent string
68 //
3077a4f6 69 // public function getEngine()
bf78d3ed 70 // returns a string telling the detected rendering engine, null if we can't detect
c18a4476 71 // one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|unknown
bf78d3ed 72 //
3077a4f6 73 // public function hasEngine($rnd_engine)
bf78d3ed 74 // returns true if the given rendering engine was detected
75 //
3077a4f6 76 // public function getEngineVersion()
bf78d3ed 77 // returns a the version number for the rendering engine
78 // this may be the same as getVersion() for many engines, or null if we don't know
79 //
3077a4f6 80 // public function getOS()
bf78d3ed 81 // returns a string telling the detected operating system, null if we can't detect
82 // might be very verbose, uses no abbreviations for most names
83 //
3077a4f6 84 // public function getPlatform()
bf78d3ed 85 // returns a string telling the detected OS platform, null if we can't detect
ac9220c2 86 // one of windows|linux|mac|solaris|unknown
bf78d3ed 87 //
3077a4f6 88 // public function getLanguage() {
bf78d3ed 89 // returns a string telling the detected browser UI language, null if we can't detect
90 // should be an ISO code
91 //
3077a4f6 92 // public function isBot()
a8464009 93 // returns true if User Agent seems to be a bot
bf78d3ed 94 //
95 // *** functions that only return useable info for some agents ***
96 //
3077a4f6 97 // public function getGeckoDate()
bf78d3ed 98 // returns the Gecko date for Gecko-based browsers, null for others
99 //
100 // *** functions for compat to older versions of this class ***
101 //
3077a4f6 102 // public function isns()
31733e08 103 // returns true if User Agent seems to be Netscape brand, false if not
3077a4f6 104 // public function isns4()
31733e08 105 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
3077a4f6 106 // public function isie()
31733e08 107 // returns true if User Agent seems to be a version of Internet Exploder, false if not
3077a4f6 108 // public function geckobased()
31733e08 109 // returns true if User Agent seems to be a Gecko-based browser, false if not
3077a4f6 110 // public function geckodate()
31733e08 111 // returns the Gecko date when it's a Gecko-based browser, 0 if not
3077a4f6 112 // public function khtmlbased()
1defa974 113 // returns true if User Agent seems to be a KHTML-based browser, false if not
114
115 // collection of some known User Agent Strings:
bf78d3ed 116 // *** see testbed/ua_list_raw.txt ***
117 // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
31733e08 118
3077a4f6 119 private $uastring;
120 private $brand;
121 private $version;
122 private $bot = false;
123 private $uadata = array();
31733e08 124
3077a4f6 125 function __construct($ua_string = '') {
31733e08 126 // *** constructor ***
1defa974 127 if (strlen($ua_string)) {
128 $this->uastring = $ua_string;
129 }
130 else {
131 // read raw UA string
4210e7b0 132 $this->uastring = $_SERVER['HTTP_USER_AGENT'];
1defa974 133 }
31733e08 134
135 // get UA brand and version
bf78d3ed 136 $this->brand = 'Unknown'; $this->version = null;
137 // find reasonable defaults
06c9b824 138 if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/(\d[0-9a-zA-Z\._+-]*)|', $this->uastring, $regs)) {
bf78d3ed 139 $this->brand = trim($regs[1]);
140 $this->version = $regs[2];
141 }
06c9b824 142 elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?(\d[0-9a-zA-Z\.+]*)|', $this->uastring, $regs)) {
bf78d3ed 143 $this->brand = trim($regs[1]);
144 $this->version = $regs[2];
145 }
06c9b824 146 elseif (preg_match('|^([0-9a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
bf78d3ed 147 $this->brand = trim($regs[1]);
148 $this->version = null;
149 }
81e72a3e 150 $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
151 || (strpos(strtolower($this->brand), 'crawler') !== false)
06c9b824
RK
152 || (strpos(strtolower($this->brand), 'spider') !== false)
153 || (strpos(strtolower($this->brand), 'search') !== false)
154 || (strpos(strtolower($this->brand), 'seek') !== false);
81e72a3e 155
bf78d3ed 156 // search for any real and/or special UAs
157 if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
158 $this->brand = 'Netscape';
31733e08 159 $this->version = $regs[1];
81e72a3e 160 $this->bot = false;
31733e08 161 }
bf78d3ed 162 elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
163 $this->brand = 'Netscape';
31733e08 164 $this->version = $regs[1];
81e72a3e 165 $this->bot = false;
31733e08 166 }
208cf837
RK
167 elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
168 $this->brand = 'Netscape';
169 $this->version = $regs[1];
170 $this->bot = false;
171 }
bf78d3ed 172 elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
173 $this->brand = 'Chimera';
1defa974 174 $this->version = $regs[1];
81e72a3e 175 $this->bot = false;
1defa974 176 }
bf78d3ed 177 elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
178 $this->brand = 'Camino';
a5813ca3 179 $this->version = $regs[1];
81e72a3e 180 $this->bot = false;
a5813ca3 181 }
bf78d3ed 182 elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
183 $this->brand = 'Phoenix';
1defa974 184 $this->version = $regs[1];
81e72a3e 185 $this->bot = false;
1defa974 186 }
bf78d3ed 187 elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
188 $this->brand = 'Mozilla Firebird';
23585ba2 189 $this->version = $regs[1];
81e72a3e 190 $this->bot = false;
23585ba2 191 }
c18a4476 192 elseif (preg_match('|Flock/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
193 $this->brand = 'Flock';
194 $this->version = $regs[1];
195 $this->bot = false;
196 }
b24eb888 197 elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
198 $this->brand = 'SeaMonkey';
199 $this->version = $regs[1];
81e72a3e 200 $this->bot = false;
b24eb888 201 }
c18a4476 202 elseif (preg_match('|Iceape/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
203 $this->brand = 'IceApe';
204 $this->version = $regs[1];
205 $this->bot = false;
206 }
207 elseif (preg_match('|Iceweasel/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
208 $this->brand = 'IceWeasel';
209 $this->version = $regs[1];
210 $this->bot = false;
211 }
208cf837
RK
212 elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
213 $this->brand = 'Minefield';
214 $this->version = $regs[1];
215 $this->bot = false;
216 }
217 elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
218 $this->brand = 'Minimo';
219 $this->version = $regs[1];
220 $this->bot = false;
221 }
bf78d3ed 222 elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
223 $this->brand = 'Galeon';
31733e08 224 $this->version = $regs[1];
81e72a3e 225 $this->bot = false;
31733e08 226 }
6e783db6 227 elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
228 $this->brand = 'Epiphany';
229 $this->version = $regs[1];
81e72a3e 230 $this->bot = false;
6e783db6 231 }
232 elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
233 $this->brand = 'K-Meleon';
234 $this->version = $regs[1];
81e72a3e 235 $this->bot = false;
6e783db6 236 }
237 elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
238 $this->brand = 'AOL';
239 $this->version = $regs[1];
81e72a3e 240 $this->bot = false;
6e783db6 241 }
c18a4476 242 elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
243 $this->brand = 'Opera Mini';
244 $this->version = $regs[1];
245 $this->bot = false;
246 }
247 elseif (preg_match('/Opera\/[^\(]+ \(.*; Opera Mini\/([^;]+); /i', $this->uastring, $regs)) {
248 $this->brand = 'Opera Mini';
249 $this->version = $regs[1];
250 $this->bot = false;
251 }
bf78d3ed 252 elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
253 $this->brand = 'Opera';
31733e08 254 $this->version = $regs[1];
81e72a3e 255 $this->bot = false;
31733e08 256 }
c18a4476 257 elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
bf78d3ed 258 $this->brand = 'OmniWeb';
1defa974 259 $this->version = $regs[1];
81e72a3e 260 $this->bot = false;
1defa974 261 }
bf78d3ed 262 elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
263 $this->brand = 'Konqueror';
31733e08 264 $this->version = $regs[1];
81e72a3e 265 $this->bot = false;
31733e08 266 }
c18a4476 267 elseif (preg_match('|Shiira/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
268 $this->brand = 'Shiira';
269 $this->version = $regs[1];
270 $this->bot = false;
271 }
bf78d3ed 272 elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
273 $this->brand = 'Safari';
588763e6
RK
274 if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
275 $this->version = $vregs[1];
276 }
277 else {
278 $this->version = '('.$regs[1].')';
279 }
81e72a3e 280 $this->bot = false;
1defa974 281 }
bf78d3ed 282 elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
283 $this->brand = 'AppleWebKit';
1defa974 284 $this->version = $regs[1];
81e72a3e 285 $this->bot = false;
1defa974 286 }
208cf837
RK
287 elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
288 $this->brand = 'Firefox';
289 $this->version = $regs[1];
290 $this->bot = false;
291 }
292 elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
293 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
294 $this->brand = 'Mozilla';
295 $this->version = $regs[1];
296 $this->bot = false;
297 }
298 elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
299 strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
300 $this->brand = 'Mozilla';
301 $this->version = 'M'.$regs[1];
302 $this->bot = false;
303 }
bf78d3ed 304 elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
305 $this->brand = 'Microsoft FrontPage';
f983aa36 306 $this->version = $regs[1];
81e72a3e 307 $this->bot = false;
f983aa36 308 }
bf78d3ed 309 elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
310 $this->brand = 'iCab';
a8464009 311 $this->version = $regs[1];
81e72a3e 312 $this->bot = false;
a8464009 313 }
bf78d3ed 314 elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
315 $this->brand = 'IBrowse';
a8464009 316 $this->version = $regs[1];
81e72a3e 317 $this->bot = false;
a8464009 318 }
c18a4476 319 elseif (preg_match('|ICEbrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
320 $this->brand = 'ICEbrowser';
321 $this->version = $regs[1];
322 $this->bot = false;
323 }
324 elseif (preg_match('|ICE Browser/v([0-9a-zA-Z\._+]+)|', $this->uastring, $regs)) {
325 $this->brand = 'ICEbrowser';
326 $this->version = str_replace('_', '.', $regs[1]);
327 $this->bot = false;
328 }
329 elseif (preg_match('|NetPositive/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
330 $this->brand = 'NetPositive';
331 $this->version = $regs[1];
332 $this->bot = false;
333 }
334 elseif (preg_match('|WebPro/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
335 $this->brand = 'WebPro (Novarra)';
336 $this->version = $regs[1];
337 $this->bot = false;
338 }
339 elseif (preg_match('|; OffByOne;|', $this->uastring, $regs)) {
340 $this->brand = 'Off By One';
341 $this->version = null;
342 $this->bot = false;
343 }
344 elseif (preg_match('|PSP \(PlayStation Portable\); ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
345 $this->brand = 'PlayStation Portable';
346 $this->version = $regs[1];
347 $this->bot = false;
348 }
b50f91ef 349 elseif (preg_match('|PLAYSTATION 3; ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
350 $this->brand = 'PlayStation 3';
351 $this->version = $regs[1];
352 $this->bot = false;
353 }
c18a4476 354 elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
355 $this->brand = 'NetFront';
a8464009 356 $this->version = $regs[1];
81e72a3e 357 $this->bot = false;
a8464009 358 }
6e783db6 359 elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
360 $this->brand = 'UP.Browser';
361 $this->version = $regs[1];
81e72a3e 362 $this->bot = false;
6e783db6 363 }
c18a4476 364 elseif (preg_match('|UP.Link/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
365 $this->brand = 'UP.Link';
366 $this->version = $regs[1];
367 $this->bot = false;
368 }
369 elseif (preg_match('|AU-MIC-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
370 $this->brand = 'Obigo';
371 $this->version = $regs[1];
372 $this->bot = false;
373 }
374 elseif (preg_match('|Nokia([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
375 $this->brand = 'Nokia';
376 $this->version = $regs[1];
377 $this->bot = false;
378 }
379 elseif (preg_match('|SonyEricsson([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
380 $this->brand = 'SonyEricsson';
381 $this->version = $regs[1];
382 $this->bot = false;
383 }
384 elseif (preg_match('|SIE-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
385 $this->brand = 'Siemens';
386 $this->version = $regs[1];
387 $this->bot = false;
388 }
389 elseif (preg_match('|MOT-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
390 $this->brand = 'Motorola';
391 $this->version = $regs[1];
392 $this->bot = false;
393 }
b50f91ef 394 elseif (preg_match('|IXI/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
395 $this->brand = 'IXI';
396 $this->version = $regs[1];
397 $this->bot = false;
398 }
c18a4476 399 elseif (preg_match('|IBM-WebExplorer-DLL/v([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
400 $this->brand = 'WebExplorer';
401 $this->version = $regs[1];
402 $this->bot = false;
403 }
bf78d3ed 404 elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
405 $this->brand = 'ELinks';
a8464009 406 $this->version = $regs[1];
81e72a3e 407 $this->bot = false;
a8464009 408 }
6e783db6 409 elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
410 $this->brand = 'Links';
411 $this->version = $regs[1];
81e72a3e 412 $this->bot = false;
6e783db6 413 }
b50f91ef 414 elseif (preg_match('|WinHttp.WinHttpRequest.([0-9\.]+)|i', $this->uastring, $regs)) {
415 $this->brand = 'WinHttpRequest';
416 $this->version = $regs[1];
417 $this->bot = false;
418 }
419 elseif (preg_match('|alpha[/ ]06; AmigaOS|i', $this->uastring, $regs)) {
420 $this->brand = 'Alpha 06';
421 $this->version = null;
422 $this->bot = false;
423 }
424 elseif (preg_match('|; arexx[\);]|i', $this->uastring, $regs)) {
c18a4476 425 $this->brand = 'ARexx';
426 $this->version = null;
427 $this->bot = false;
428 }
b50f91ef 429 elseif (preg_match('|; Voyager; AmigaOS[\);]|i', $this->uastring, $regs)) {
430 $this->brand = 'AmigaVoyager';
431 $this->version = null;
432 $this->bot = false;
433 }
434 elseif (preg_match('|AWEB ([0-9a-zA-Z\.+ ]+)|', $this->uastring, $regs)) {
435 $this->brand = 'AWEB';
436 $this->version = $regs[1];
437 $this->bot = false;
438 }
439 elseif (preg_match('|X ([0-9a-zA-Z\.+ ]+); Commodore 64|', $this->uastring, $regs)) {
440 $this->brand = 'X';
441 $this->version = $regs[1];
442 $this->bot = false;
443 }
444 elseif (preg_match('|DB Browse ([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
445 $this->brand = 'DB Browse';
446 $this->version = $regs[1];
447 $this->bot = false;
448 }
bf78d3ed 449 elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
450 $this->brand = 'ZyBorg';
a8464009 451 $this->version = $regs[1];
452 $this->bot = true;
453 }
bf78d3ed 454 elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
455 $this->brand = 'Ask Jeeves';
a8464009 456 $this->version = $regs[1];
457 $this->bot = true;
458 }
4e8c44da 459 elseif (preg_match('|heritrix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
460 $this->brand = 'Heritrix';
461 $this->version = $regs[1];
462 $this->bot = true;
463 }
b50f91ef 464 elseif (preg_match('|([0-9a-zA-Z\.+]+bot)/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
465 $this->brand = $regs[1];
466 $this->version = $regs[2];
467 $this->bot = true;
468 }
469 elseif (preg_match('|VoilaBot ((BETA )?[0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
470 $this->brand = 'VoilaBot';
471 $this->version = $regs[1];
472 $this->bot = true;
473 }
c51ab9a2 474 elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
bf78d3ed 475 $this->brand = 'Slurp';
c51ab9a2 476 $this->version = null;
a8464009 477 $this->bot = true;
478 }
b50f91ef 479 elseif (preg_match('|Check&amp;Get ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
480 $this->brand = 'Check&Get';
481 $this->version = $regs[1];
482 $this->bot = true;
483 }
484 elseif (preg_match('|WebCapture ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
485 $this->brand = 'WebCapture';
486 $this->version = $regs[1];
487 $this->bot = true;
488 }
489 elseif (preg_match('|WebMon ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
490 $this->brand = 'WebMon';
491 $this->version = $regs[1];
492 $this->bot = true;
493 }
494 elseif (preg_match('|Powermarks/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
495 $this->brand = 'Powermarks';
496 $this->version = $regs[1];
497 $this->bot = true;
498 }
bf78d3ed 499 elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
500 $this->brand = 'Gulper Web Bot';
a8464009 501 $this->version = $regs[1];
502 $this->bot = true;
503 }
bf78d3ed 504 elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
505 $this->brand = 'HTTrack';
a8464009 506 $this->version = $regs[1];
507 $this->bot = true;
508 }
b50f91ef 509 elseif (preg_match('|Twiceler-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
510 $this->brand = 'Twiceler';
511 $this->version = $regs[1];
512 $this->bot = true;
513 }
5b8eba2a 514 elseif (preg_match('|Microsoft URL Control - ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
515 $this->brand = 'Microsoft URL Control';
516 $this->version = $regs[1];
517 $this->bot = true;
518 }
81e72a3e 519 elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
520 $this->brand = 'AC-Plug';
521 $this->version = $regs[1];
522 $this->bot = true;
523 }
bf78d3ed 524 elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
525 $this->brand = 'Unknown bot (IE5.5)';
526 $this->version = null;
a8464009 527 $this->bot = true;
528 }
bf78d3ed 529 elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
530 $this->brand = 'Unknown bot (Mozilla)';
531 $this->version = null;
a8464009 532 $this->bot = true;
533 }
b50f91ef 534 elseif (preg_match('|http://www.livedir.net|', $this->uastring, $regs)) {
535 $this->brand = 'livedir.net';
536 $this->version = null;
537 $this->bot = true;
538 }
539 elseif (preg_match('|WebClipping.com|', $this->uastring, $regs)) {
540 $this->brand = 'WebClipping.com';
541 $this->version = null;
542 $this->bot = true;
543 }
bf78d3ed 544 elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
545 $this->brand = 'almaden crawler';
546 $this->version = null;
a8464009 547 $this->bot = true;
548 }
b50f91ef 549 elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) ||
550 preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
bf78d3ed 551 $this->brand = 'BlitzBOT';
552 $this->version = null;
a8464009 553 $this->bot = true;
554 }
b50f91ef 555 elseif (preg_match('|Really Gmane.org\'s favicon grabber|', $this->uastring)) {
556 $this->brand = 'Really Gmane.org\'s favicon grabber';
557 $this->version = null;
558 $this->bot = true;
559 }
bf78d3ed 560 elseif (preg_match('|Girafabot|', $this->uastring)) {
561 $this->brand = 'Girafabot';
562 $this->version = null;
a8464009 563 $this->bot = true;
564 }
b50f91ef 565 elseif (preg_match('|Arachmo|', $this->uastring)) {
566 $this->brand = 'Arachmo';
567 $this->version = null;
568 $this->bot = true;
569 }
570 elseif (preg_match('|OsO|', $this->uastring)) {
571 $this->brand = 'OsO';
572 $this->version = null;
573 $this->bot = true;
574 }
575 elseif (preg_match('|Yoono|', $this->uastring)) {
576 $this->brand = 'Yoono';
577 $this->version = null;
578 $this->bot = true;
579 }
bf78d3ed 580 elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
581 $this->brand = 'efp';
582 $this->version = null;
a8464009 583 $this->bot = true;
584 }
81e72a3e 585 elseif (preg_match('|Baiduspider|i', $this->uastring)) {
586 $this->brand = 'BaiDuSpider';
587 $this->version = null;
588 $this->bot = true;
589 }
590 elseif (preg_match('|Indy Library|', $this->uastring)) {
591 $this->brand = 'Indy Library';
592 $this->version = null;
593 $this->bot = true;
594 }
b50f91ef 595 elseif (preg_match('|Linkman|', $this->uastring)) {
596 $this->brand = 'Linkman';
597 $this->version = null;
598 $this->bot = true;
599 }
600 elseif (preg_match('|Sage|', $this->uastring, $regs)) {
601 $this->brand = 'Sage';
602 $this->version = null;
603 $this->bot = true;
604 }
605 elseif (preg_match('|Google Desktop|', $this->uastring)) {
606 $this->brand = 'Google Desktop';
607 $this->version = null;
608 $this->bot = true;
609 }
bf78d3ed 610 elseif (preg_match('|^Firefly|', $this->uastring)) {
611 // comes here with correct value but would be detected as MSIE
a8464009 612 }
81e72a3e 613 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
614 $this->brand = 'Steganos Internet Anonym';
615 $this->version = $regs[1];
616 $this->bot = false;
617 }
b50f91ef 618 elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
619 $this->brand = 'Steganos Internet Anonym';
620 $this->version = $regs[1];
621 $this->bot = false;
622 }
623 elseif (preg_match('|BorderManager ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
624 $this->brand = 'BorderManager';
625 $this->version = $regs[1];
626 $this->bot = false;
627 }
628 elseif (preg_match('|WebWasher ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
629 $this->brand = 'WebWasher';
630 $this->version = $regs[1];
631 $this->bot = false;
632 }
633 elseif (preg_match('|SaferSurf|', $this->uastring, $regs)) {
634 $this->brand = 'SaferSurf';
635 $this->version = null;
636 $this->bot = false;
637 }
bf78d3ed 638 elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
639 $this->brand = 'Avant Browser';
640 $this->version = null;
81e72a3e 641 $this->bot = false;
a8464009 642 }
c18a4476 643 elseif (preg_match('|Browser[^/]+(http://www.avantbrowser.com)|', $this->uastring)) {
644 $this->brand = 'Avant Browser';
645 $this->version = null;
646 $this->bot = false;
647 }
6e783db6 648 elseif (preg_match('|Maxthon|', $this->uastring)) {
649 $this->brand = 'Maxthon';
650 $this->version = null;
81e72a3e 651 $this->bot = false;
6e783db6 652 }
653 elseif (preg_match('|MyIE2|', $this->uastring)) {
654 $this->brand = 'MyIE2';
655 $this->version = null;
81e72a3e 656 $this->bot = false;
6e783db6 657 }
bf78d3ed 658 elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
659 $this->brand = 'Crazy Browser';
660 $this->version = $regs[1];
81e72a3e 661 $this->bot = false;
662 }
663 elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
664 $this->brand = 'AvantGo';
665 $this->version = $regs[1];
666 $this->bot = false;
a8464009 667 }
bf78d3ed 668 elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
669 $this->brand = 'MSN';
670 $this->version = $regs[1];
81e72a3e 671 $this->bot = false;
a8464009 672 }
c18a4476 673 elseif (preg_match('|America Online Browser [0-9a-zA-Z\.+]+; rev([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
674 $this->brand = 'AOL Browser';
675 $this->version = $regs[1];
676 $this->bot = false;
677 }
bf78d3ed 678 elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
679 $this->brand = 'Microsoft FrontPage';
680 $this->version = $regs[1];
81e72a3e 681 $this->bot = false;
a8464009 682 }
c18a4476 683 elseif (preg_match('|Microsoft Internet Explorer/4.0b1|', $this->uastring, $regs)) {
684 $this->brand = 'Microsoft Internet Explorer';
685 $this->version = '1.0';
686 $this->bot = false;
687 }
bf78d3ed 688 elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
689 $this->brand = 'Microsoft Internet Explorer';
31733e08 690 $this->version = $regs[1];
81e72a3e 691 $this->bot = false;
31733e08 692 }
c18a4476 693 elseif (preg_match('|MSPIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
694 $this->brand = 'Microsoft Pocket Internet Explorer';
695 $this->version = $regs[1];
696 $this->bot = false;
697 }
b50f91ef 698 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
699 (strpos($this->uastring, 'compatible') === false) && (strpos($this->uastring, 'Gecko/') === false) &&
700 (intval($regs[1]) < 5)) {
bf78d3ed 701 $this->brand = 'Netscape';
1defa974 702 $this->version = $regs[1];
bf78d3ed 703 if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
81e72a3e 704 $this->bot = false;
705 }
b50f91ef 706 elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
707 $this->brand = (strpos($this->uastring, 'compatible') !== false)?'Mozilla-compatible (unknown)':'Mozilla (unknown)';
81e72a3e 708 $this->version = null;
709 $this->bot = false;
1defa974 710 }
a8464009 711
06c9b824 712 $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
81e72a3e 713 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
714 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
06c9b824
RK
715 'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
716 'FavOrg','findlinks','DataCha0s','ichiro','Francis','','','','','');
a8464009 717
718 if (in_array($this->brand, $botArray)) {
719 $this->bot = true;
720 }
31733e08 721 }
722
3077a4f6 723 public function getBrand() { return $this->brand; }
724 public function getVersion() { return $this->version; }
4210e7b0 725
3077a4f6 726 public function getAcceptLanguages() {
4210e7b0 727 if (!isset($this->uadata['accept-languages'])) {
728 $headers = getAllHeaders();
729 $accLcomp = explode(',', $headers['Accept-Language']);
730 $accLang = array();
731 foreach ($accLcomp as $lcomp) {
732 if (strlen($lcomp)) {
733 $ldef = explode(';', $lcomp);
437e1c91 734 $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
4210e7b0 735 }
736 }
737 $this->uadata['accept-languages'] = $accLang;
738 }
739 return $this->uadata['accept-languages'];
740 }
741
3077a4f6 742 public function getUAString() { return $this->uastring; }
23585ba2 743
3077a4f6 744 public function getEngine() {
b50f91ef 745 // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
bf78d3ed 746 if (!isset($this->uadata['engine'])) {
ac9220c2 747 $this->uadata['engine'] = 'unknown';
bf78d3ed 748 $this->uadata['geckodate'] = null;
c863ed1e 749 if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
bf78d3ed 750 $this->uadata['engine'] = 'gecko';
751 $this->uadata['geckodate'] = $regs[1];
752 }
753 elseif ((strpos($this->brand, 'Internet Explorer') !== false) || (strpos($this->brand, 'FrontPage') !== false)) {
6e783db6 754 if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
bf78d3ed 755 $this->uadata['engine'] = 'tasman';
756 }
757 else {
758 $this->uadata['engine'] = 'trident';
759 }
760 }
c18a4476 761 elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'Safari') !== false) ||
762 (strpos($this->brand, 'Shiira') !== false) ||
763 (strpos($this->brand, 'AppleWebKit') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
bf78d3ed 764 $this->uadata['engine'] = 'khtml';
765 }
81e72a3e 766 elseif (strpos($this->brand, 'Netscape') !== false) {
767 // non-Gecko Netscape browsers
768 if (intval($this->version) <= 4) {
769 $this->uadata['engine'] = 'nscp';
770 }
771 elseif (strpos($this->uastring, 'MSIE') !== false) {
772 $this->uadata['engine'] = 'trident';
773 }
bf78d3ed 774 }
775 elseif (strpos($this->brand, 'Opera') !== false) {
776 $this->uadata['engine'] = 'presto';
777 }
778 elseif (strpos($this->brand, 'Dillo') !== false) {
779 $this->uadata['engine'] = 'gzilla';
780 }
781 elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
782 $this->uadata['engine'] = 'links';
783 }
c18a4476 784 elseif ((strpos($this->brand, 'ICEbrowser') !== false) || (strpos($this->brand, 'ICE Browser') !== false)) {
785 $this->uadata['engine'] = 'icestorm';
786 }
b50f91ef 787 elseif ((strpos($this->brand, 'PlayStation') !== false) || (strpos($this->brand, 'NetFront') !== false)) {
788 $this->uadata['engine'] = 'netfront';
789 }
6e783db6 790 elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
791 (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
792 (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
bf78d3ed 793 $this->uadata['engine'] = 'trident';
794 }
795 elseif (strpos($this->brand, 'Galeon') !== false) {
796 $this->uadata['engine'] = 'gecko';
31733e08 797 }
c18a4476 798 elseif (strpos($this->brand, 'WebPro') !== false) {
799 $this->uadata['engine'] = 'nscp';
800 }
31733e08 801 }
bf78d3ed 802 return $this->uadata['engine'];
31733e08 803 }
804
3077a4f6 805 public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
bf78d3ed 806
3077a4f6 807 public function getEngineVersion() {
bf78d3ed 808 if (!isset($this->uadata['eng_version'])) {
809 $this->uadata['eng_version'] = null;
810 // getOS() should get the date for us
811 $this->getOS();
31733e08 812 }
bf78d3ed 813 return $this->uadata['eng_version'];
31733e08 814 }
815
3077a4f6 816 public function getOS() {
bf78d3ed 817 if (!isset($this->uadata['os'])) {
818 $this->uadata['os'] = null;
819 if ($this->hasEngine('gecko')) {
81e72a3e 820 if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
bf78d3ed 821 $this->uadata['os'] = $regs[2];
f9a0c27d 822 $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
bf78d3ed 823 $this->uadata['eng_version'] = $regs[4];
824 }
81e72a3e 825 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
826 $this->uadata['os'] = $regs[2];
827 $this->uadata['lang'] = null;
828 $this->uadata['eng_version'] = $regs[3];
829 }
6e783db6 830 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
bf78d3ed 831 $this->uadata['os'] = $regs[2];
832 $this->uadata['lang'] = $regs[3];
833 $this->uadata['eng_version'] = 'M'.$regs[4];
834 }
09cd2756 835 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
836 $this->uadata['os'] = $regs[1];
837 $this->uadata['lang'] = $regs[2];
838 $this->uadata['eng_version'] = 'M'.$regs[3];
839 }
6e783db6 840 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
841 $this->uadata['os'] = $regs[2];
842 $this->uadata['lang'] = $regs[3];
843 $this->uadata['eng_version'] = null;
844 }
f9a0c27d 845 elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
846 $this->uadata['os'] = $regs[2];
847 $this->uadata['lang'] = null;
848 $this->uadata['eng_version'] = $regs[3];
849 }
6e783db6 850 elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
bf78d3ed 851 $this->uadata['os'] = $regs[2];
852 $this->uadata['lang'] = null;
853 $this->uadata['eng_version'] = null;
854 }
855 elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
856 $this->uadata['os'] = $regs[2];
857 $this->uadata['lang'] = null;
858 $this->uadata['eng_version'] = null;
859 }
860 elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
861 $this->uadata['os'] = 'Debian Linux';
862 $this->uadata['lang'] = null;
863 $this->uadata['eng_version'] = null;
864 }
865 }
6e783db6 866 elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
c18a4476 867 if (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
868 $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:$regs[1];
bf78d3ed 869 $this->uadata['os'] = $regs[2];
870 $this->uadata['lang'] = null;
871 }
81e72a3e 872 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
bf78d3ed 873 $this->uadata['eng_version'] = $regs[1];
874 $this->uadata['os'] = null;
875 $this->uadata['lang'] = null;
876 }
c18a4476 877 elseif (preg_match('/Microsoft Internet Explorer\/[^\s]+ \(((?:Mac|Win)[^;\)]+)\)/i', $this->uastring, $regs)) {
878 $this->uadata['eng_version'] = $this->getVersion();
879 $this->uadata['os'] = $regs[1];
880 $this->uadata['lang'] = null;
881 }
882 elseif (preg_match('/Microsoft Pocket Internet Explorer\/[^\s]+/i', $this->uastring, $regs)) {
883 $this->uadata['eng_version'] = null;
884 $this->uadata['os'] = 'Windows CE';
885 $this->uadata['lang'] = null;
886 }
31733e08 887 }
bf78d3ed 888 elseif ($this->hasEngine('khtml')) {
6e783db6 889 if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
890 $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
bf78d3ed 891 $this->uadata['os'] = $regs[2];
892 $this->uadata['lang'] = $regs[5];
893 }
6e783db6 894 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
895 $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
bf78d3ed 896 $this->uadata['os'] = $regs[2];
897 $this->uadata['lang'] = null;
898 }
899 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
900 $this->uadata['os'] = $regs[2];
901 $this->uadata['lang'] = $regs[3];
902 $this->uadata['eng_version'] = null;
903 }
c18a4476 904 elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
905 $this->uadata['os'] = $regs[1];
906 $this->uadata['lang'] = $regs[2];
907 $this->uadata['eng_version'] = null;
908 }
bf78d3ed 909 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
910 $this->uadata['os'] = $regs[1];
911 $this->uadata['lang'] = null;
912 $this->uadata['eng_version'] = null;
913 }
914 }
915 elseif ($this->hasEngine('presto')) {
c18a4476 916 // Opera < 8
f9a0c27d 917 if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
bf78d3ed 918 $this->uadata['eng_version'] = $this->getVersion();
919 $this->uadata['os'] = $regs[1];
920 $this->uadata['lang'] = $regs[2];
921 }
f9a0c27d 922 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+ +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
6e783db6 923 $this->uadata['eng_version'] = $this->getVersion();
924 $this->uadata['os'] = $regs[1];
925 $this->uadata['lang'] = $regs[2];
926 }
f9a0c27d 927 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) {
6e783db6 928 $this->uadata['eng_version'] = $this->getVersion();
929 $this->uadata['os'] = $regs[1];
930 $this->uadata['lang'] = $regs[2];
931 }
c18a4476 932 // Opera mini
933 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini; ([a-z_-]+); /i', $this->uastring, $regs)) {
934 $this->uadata['eng_version'] = null;
935 $this->uadata['os'] = $regs[2];
936 $this->uadata['lang'] = $regs[3];
937 }
938 elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini\/[^;]+; ([a-z_-]+); /i', $this->uastring, $regs)) {
939 $this->uadata['eng_version'] = $regs[1];
940 $this->uadata['os'] = $regs[2];
941 $this->uadata['lang'] = $regs[3];
942 }
943 // Opera >= 8
f9a0c27d 944 elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
bf78d3ed 945 $this->uadata['eng_version'] = $this->getVersion();
946 $this->uadata['os'] = $regs[1];
947 $this->uadata['lang'] = $regs[2];
948 }
f9a0c27d 949 elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
6e783db6 950 $this->uadata['eng_version'] = $this->getVersion();
951 $this->uadata['os'] = $regs[1];
952 $this->uadata['lang'] = $regs[2];
953 }
f9a0c27d 954 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
bf78d3ed 955 $this->uadata['eng_version'] = $this->getVersion();
956 $this->uadata['os'] = $regs[1];
957 $this->uadata['lang'] = $regs[2];
958 }
c863ed1e
RK
959 // Opera 9 Firefox-spoofing
960 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
961 $this->uadata['eng_version'] = $this->getVersion();
962 $this->uadata['os'] = $regs[1];
963 $this->uadata['lang'] = $regs[2];
964 }
bf78d3ed 965 }
966 elseif ($this->hasEngine('nscp')) {
f9a0c27d 967 if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
968 $this->uadata['eng_version'] = $regs[1];
969 $this->uadata['os'] = $regs[3];
970 $this->uadata['lang'] = $regs[2];
971 }
972 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
bf78d3ed 973 $this->uadata['eng_version'] = $regs[1];
974 $this->uadata['os'] = $regs[3];
975 $this->uadata['lang'] = $regs[2];
976 }
c18a4476 977 elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+)[^\(]+\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
978 $this->uadata['eng_version'] = $regs[1];
979 $this->uadata['os'] = $regs[2];
980 $this->uadata['lang'] = null;
981 }
bf78d3ed 982 }
983 elseif ($this->hasEngine('gzilla')) {
984 $this->uadata['eng_version'] = $this->getVersion();
985 $this->uadata['os'] = null;
986 $this->uadata['lang'] = null;
987 }
988 elseif ($this->hasEngine('links')) {
6e783db6 989 if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
bf78d3ed 990 $this->uadata['eng_version'] = null;
991 $this->uadata['os'] = $regs[1];
992 $this->uadata['lang'] = null;
993 }
994 }
c18a4476 995 elseif ($this->hasEngine('icestorm')) {
996 if (preg_match('/ICE Browser\/v?([0-9a-zA-Z\._+]+) \(Java [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
997 $this->uadata['eng_version'] = str_replace('_', '.', $regs[1]);
998 $this->uadata['os'] = $regs[2];
999 $this->uadata['lang'] = null;
1000 }
1001 elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\).* ICEbrowser\/([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) {
1002 $this->uadata['eng_version'] = $regs[3];
1003 $this->uadata['os'] = $regs[1];
1004 $this->uadata['lang'] = $regs[2];
1005 }
1006 }
bf78d3ed 1007 else {
1008 $this->uadata['eng_version'] = null;
1009 $this->uadata['lang'] = null;
1010 if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
1011 $this->uadata['os'] = 'AmigaOS';
1012 }
b50f91ef 1013 if (preg_match('/Commodore 64/i', $this->uastring, $regs)) {
1014 $this->uadata['os'] = 'Commodore 64';
1015 }
bf78d3ed 1016 elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
1017 $this->uadata['os'] = $regs[1];
1018 }
6e783db6 1019 elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
1020 $this->uadata['os'] = trim($regs[1]);
1021 }
1022 elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
1023 $this->uadata['os'] = trim($regs[1]);
1024 }
c51ab9a2 1025 elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
1026 $this->uadata['os'] = 'SymbianOS '.$regs[1];
1027 }
bf78d3ed 1028 }
1029 if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
804fe4f1 1030 elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows NT 4.0'; }
bf78d3ed 1031 elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
1032 elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
1033 elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
55020829 1034 elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
1035 elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
bf78d3ed 1036 elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
1037 elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
55020829 1038 elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
1039 elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
1040 elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
bf78d3ed 1041 elseif (preg_match('/Mac ?OS ?X/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
1042 elseif (preg_match('/Mac_P(ower|)PC/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
1043 elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
6e783db6 1044 elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
bf78d3ed 1045 elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
6e783db6 1046 elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
bf78d3ed 1047 elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
588763e6 1048 elseif (preg_match('/Symbian ?OS/i',$this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
bf78d3ed 1049
6e783db6 1050 if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
1051 elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
1052 elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
1053 elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
1054 elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
1055 elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
1056 elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
1057 elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
1058 elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
1059 elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
1060 elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
1061 elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
1062 elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
b50f91ef 1063 elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
6e783db6 1064 elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
1065 elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
c51ab9a2 1066 elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
6e783db6 1067 elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
1068 else { $this->uadata['platform'] = $this->uadata['os']; }
bf78d3ed 1069
1070 $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']);
31733e08 1071 }
bf78d3ed 1072 return $this->uadata['os'];
31733e08 1073 }
1074
3077a4f6 1075 public function getPlatform() {
bf78d3ed 1076 if (!isset($this->uadata['platform'])) {
1077 $this->uadata['platform'] = null;
1078 // getOS() should get the date for us
1079 $this->getOS();
31733e08 1080 }
bf78d3ed 1081 return $this->uadata['platform'];
31733e08 1082 }
1083
3077a4f6 1084 public function getLanguage() {
bf78d3ed 1085 if (!isset($this->uadata['lang'])) {
1086 $this->uadata['lang'] = null;
1087 // getOS() should get the date for us
1088 $this->getOS();
31733e08 1089 }
bf78d3ed 1090 return $this->uadata['lang'];
31733e08 1091 }
1defa974 1092
3077a4f6 1093 public function getGeckoDate() {
bf78d3ed 1094 if (!isset($this->uadata['geckodate'])) {
1095 $this->uadata['geckodate'] = null;
1096 // getEngine() should get the date for us
1097 $this->getEngine();
1defa974 1098 }
bf78d3ed 1099 return $this->uadata['geckodate'];
1defa974 1100 }
bf78d3ed 1101
3077a4f6 1102 public function isBot() { return $this->bot; }
1103
1104 public function isns() {
1105 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1106 return (strpos($this->brand, 'Netscape') !== false);
1107 }
1108 public function isns4() {
1109 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1110 return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4));
1111 }
1112 public function isie() {
1113 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1114 return $this->hasEngine('trident');
1115 }
1116 public function geckodate() {
1117 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1118 return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0);
1119 }
1120 public function geckobased() {
1121 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1122 return $this->hasEngine('gecko');
1123 }
1124 public function khtmlbased() {
1125 trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
1126 return $this->hasEngine('khtml');
1127 }
31733e08 1128}
23585ba2 1129?>