PluginProbe
QuadMenu – Mega Menu / 1.9.4
QuadMenu – Mega Menu v1.9.4
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / lib / ReduxCore / inc / browser.php

browser.php in QuadMenu – Mega Menu 1.9.4, at lib/ReduxCore/inc/browser.php

1,283 lines 44.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: Browser.php
5 * Author: Chris Schuld (http://chrisschuld.com/)
6 * Last Modified: July 4th, 2014
7 * @version 1.9
8 * @package PegasusPHP
9 *
10 * Copyright (C) 2008-2010 Chris Schuld (chris@chrisschuld.com)
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details at:
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 *
24 * Typical Usage:
25 *
26 * $browser = new Browser();
27 * if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
28 * echo 'You have FireFox version 2 or greater';
29 * }
30 *
31 * User Agents Sampled from: http://www.useragentstring.com/
32 *
33 * This implementation is based on the original work from Gary White
34 * http://apptools.com/phptools/browser/
35 *
36 */
37
38 class Browser
39 {
40 private $_agent = '';
41 private $_browser_name = '';
42 private $_version = '';
43 private $_platform = '';
44 private $_os = '';
45 private $_is_aol = false;
46 private $_is_mobile = false;
47 private $_is_tablet = false;
48 private $_is_robot = false;
49 private $_is_facebook = false;
50 private $_aol_version = '';
51
52 const BROWSER_UNKNOWN = 'unknown';
53 const VERSION_UNKNOWN = 'unknown';
54
55 const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
56 const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
57 const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
58 const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
59 const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
60 const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
61 const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
62 const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
63 const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
64 const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
65 const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
66 const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
67 const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
68 const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
69 const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
70 const BROWSER_SAFARI = 'Safari'; // http://apple.com
71 const BROWSER_IPHONE = 'iPhone'; // http://apple.com
72 const BROWSER_IPOD = 'iPod'; // http://apple.com
73 const BROWSER_IPAD = 'iPad'; // http://apple.com
74 const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
75 const BROWSER_ANDROID = 'Android'; // http://www.android.com/
76 const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
77 const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
78 const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
79 const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
80 const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
81 const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
82 const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
83 const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
84 const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
85 const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot
86
87 const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
88 const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
89 const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
90 const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
91
92 const PLATFORM_UNKNOWN = 'unknown';
93 const PLATFORM_WINDOWS = 'Windows';
94 const PLATFORM_WINDOWS_CE = 'Windows CE';
95 const PLATFORM_APPLE = 'Apple';
96 const PLATFORM_LINUX = 'Linux';
97 const PLATFORM_OS2 = 'OS/2';
98 const PLATFORM_BEOS = 'BeOS';
99 const PLATFORM_IPHONE = 'iPhone';
100 const PLATFORM_IPOD = 'iPod';
101 const PLATFORM_IPAD = 'iPad';
102 const PLATFORM_BLACKBERRY = 'BlackBerry';
103 const PLATFORM_NOKIA = 'Nokia';
104 const PLATFORM_FREEBSD = 'FreeBSD';
105 const PLATFORM_OPENBSD = 'OpenBSD';
106 const PLATFORM_NETBSD = 'NetBSD';
107 const PLATFORM_SUNOS = 'SunOS';
108 const PLATFORM_OPENSOLARIS = 'OpenSolaris';
109 const PLATFORM_ANDROID = 'Android';
110
111 const OPERATING_SYSTEM_UNKNOWN = 'unknown';
112
113 public function __construct($userAgent = "")
114 {
115 $this->reset();
116 if ($userAgent != "") {
117 $this->setUserAgent($userAgent);
118 } else {
119 $this->determine();
120 }
121 }
122
123 /**
124 * Reset all properties
125 */
126 public function reset()
127 {
128 $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
129 $this->_browser_name = self::BROWSER_UNKNOWN;
130 $this->_version = self::VERSION_UNKNOWN;
131 $this->_platform = self::PLATFORM_UNKNOWN;
132 $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
133 $this->_is_aol = false;
134 $this->_is_mobile = false;
135 $this->_is_tablet = false;
136 $this->_is_robot = false;
137 $this->_is_facebook = false;
138 $this->_aol_version = self::VERSION_UNKNOWN;
139 }
140
141 /**
142 * Check to see if the specific browser is valid
143 * @param string $browserName
144 * @return bool True if the browser is the specified browser
145 */
146 function isBrowser($browserName)
147 {
148 return (0 == strcasecmp($this->_browser_name, trim($browserName)));
149 }
150
151 /**
152 * The name of the browser. All return types are from the class contants
153 * @return string Name of the browser
154 */
155 public function getBrowser()
156 {
157 return $this->_browser_name;
158 }
159
160 /**
161 * Set the name of the browser
162 * @param $browser string The name of the Browser
163 */
164 public function setBrowser($browser)
165 {
166 $this->_browser_name = $browser;
167 }
168
169 /**
170 * The name of the platform. All return types are from the class contants
171 * @return string Name of the browser
172 */
173 public function getPlatform()
174 {
175 return $this->_platform;
176 }
177
178 /**
179 * Set the name of the platform
180 * @param string $platform The name of the Platform
181 */
182 public function setPlatform($platform)
183 {
184 $this->_platform = $platform;
185 }
186
187 /**
188 * The version of the browser.
189 * @return string Version of the browser (will only contain alpha-numeric characters and a period)
190 */
191 public function getVersion()
192 {
193 return $this->_version;
194 }
195
196 /**
197 * Set the version of the browser
198 * @param string $version The version of the Browser
199 */
200 public function setVersion($version)
201 {
202 $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version);
203 }
204
205 /**
206 * The version of AOL.
207 * @return string Version of AOL (will only contain alpha-numeric characters and a period)
208 */
209 public function getAolVersion()
210 {
211 return $this->_aol_version;
212 }
213
214 /**
215 * Set the version of AOL
216 * @param string $version The version of AOL
217 */
218 public function setAolVersion($version)
219 {
220 $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version);
221 }
222
223 /**
224 * Is the browser from AOL?
225 * @return boolean True if the browser is from AOL otherwise false
226 */
227 public function isAol()
228 {
229 return $this->_is_aol;
230 }
231
232 /**
233 * Is the browser from a mobile device?
234 * @return boolean True if the browser is from a mobile device otherwise false
235 */
236 public function isMobile()
237 {
238 return $this->_is_mobile;
239 }
240
241 /**
242 * Is the browser from a tablet device?
243 * @return boolean True if the browser is from a tablet device otherwise false
244 */
245 public function isTablet()
246 {
247 return $this->_is_tablet;
248 }
249
250 /**
251 * Is the browser from a robot (ex Slurp,GoogleBot)?
252 * @return boolean True if the browser is from a robot otherwise false
253 */
254 public function isRobot()
255 {
256 return $this->_is_robot;
257 }
258
259 /**
260 * Is the browser from facebook?
261 * @return boolean True if the browser is from facebook otherwise false
262 */
263 public function isFacebook()
264 {
265 return $this->_is_facebook;
266 }
267
268 /**
269 * Set the browser to be from AOL
270 * @param $isAol
271 */
272 public function setAol($isAol)
273 {
274 $this->_is_aol = $isAol;
275 }
276
277 /**
278 * Set the Browser to be mobile
279 * @param boolean $value is the browser a mobile browser or not
280 */
281 protected function setMobile($value = true)
282 {
283 $this->_is_mobile = $value;
284 }
285
286 /**
287 * Set the Browser to be tablet
288 * @param boolean $value is the browser a tablet browser or not
289 */
290 protected function setTablet($value = true)
291 {
292 $this->_is_tablet = $value;
293 }
294
295 /**
296 * Set the Browser to be a robot
297 * @param boolean $value is the browser a robot or not
298 */
299 protected function setRobot($value = true)
300 {
301 $this->_is_robot = $value;
302 }
303
304 /**
305 * Set the Browser to be a Facebook request
306 * @param boolean $value is the browser a robot or not
307 */
308 protected function setFacebook($value = true)
309 {
310 $this->_is_facebook = $value;
311 }
312
313 /**
314 * Get the user agent value in use to determine the browser
315 * @return string The user agent from the HTTP header
316 */
317 public function getUserAgent()
318 {
319 return $this->_agent;
320 }
321
322 /**
323 * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
324 * @param string $agent_string The value for the User Agent
325 */
326 public function setUserAgent($agent_string)
327 {
328 $this->reset();
329 $this->_agent = $agent_string;
330 $this->determine();
331 }
332
333 /**
334 * Used to determine if the browser is actually "chromeframe"
335 * @since 1.7
336 * @return boolean True if the browser is using chromeframe
337 */
338 public function isChromeFrame()
339 {
340 return (strpos($this->_agent, "chromeframe") !== false);
341 }
342
343 /**
344 * Returns a formatted string with a summary of the details of the browser.
345 * @return string formatted string with a summary of the browser
346 */
347 public function __toString()
348 {
349 return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" .
350 "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" .
351 "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
352 "<strong>Platform:</strong> {$this->getPlatform()}<br/>";
353 }
354
355 /**
356 * Protected routine to calculate and determine what the browser is in use (including platform)
357 */
358 protected function determine()
359 {
360 $this->checkPlatform();
361 $this->checkBrowsers();
362 $this->checkForAol();
363 }
364
365 /**
366 * Protected routine to determine the browser type
367 * @return boolean True if the browser was detected otherwise false
368 */
369 protected function checkBrowsers()
370 {
371 return (
372 // well-known, well-used
373 // Special Notes:
374 // (1) Opera must be checked before FireFox due to the odd
375 // user agents used in some older versions of Opera
376 // (2) WebTV is strapped onto Internet Explorer so we must
377 // check for WebTV before IE
378 // (3) (deprecated) Galeon is based on Firefox and needs to be
379 // tested before Firefox is tested
380 // (4) OmniWeb is based on Safari so OmniWeb check must occur
381 // before Safari
382 // (5) Netscape 9+ is based on Firefox so Netscape checks
383 // before FireFox are necessary
384 $this->checkBrowserWebTv() ||
385 $this->checkBrowserInternetExplorer() ||
386 $this->checkBrowserOpera() ||
387 $this->checkBrowserGaleon() ||
388 $this->checkBrowserNetscapeNavigator9Plus() ||
389 $this->checkBrowserFirefox() ||
390 $this->checkBrowserChrome() ||
391 $this->checkBrowserOmniWeb() ||
392
393 // common mobile
394 $this->checkBrowserAndroid() ||
395 $this->checkBrowseriPad() ||
396 $this->checkBrowseriPod() ||
397 $this->checkBrowseriPhone() ||
398 $this->checkBrowserBlackBerry() ||
399 $this->checkBrowserNokia() ||
400
401 // common bots
402 $this->checkBrowserGoogleBot() ||
403 $this->checkBrowserMSNBot() ||
404 $this->checkBrowserBingBot() ||
405 $this->checkBrowserSlurp() ||
406
407 // check for facebook external hit when loading URL
408 $this->checkFacebookExternalHit() ||
409
410 // WebKit base check (post mobile and others)
411 $this->checkBrowserSafari() ||
412
413 // everyone else
414 $this->checkBrowserNetPositive() ||
415 $this->checkBrowserFirebird() ||
416 $this->checkBrowserKonqueror() ||
417 $this->checkBrowserIcab() ||
418 $this->checkBrowserPhoenix() ||
419 $this->checkBrowserAmaya() ||
420 $this->checkBrowserLynx() ||
421 $this->checkBrowserShiretoko() ||
422 $this->checkBrowserIceCat() ||
423 $this->checkBrowserIceweasel() ||
424 $this->checkBrowserW3CValidator() ||
425 $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
426 );
427 }
428
429 /**
430 * Determine if the user is using a BlackBerry (last updated 1.7)
431 * @return boolean True if the browser is the BlackBerry browser otherwise false
432 */
433 protected function checkBrowserBlackBerry()
434 {
435 if (stripos($this->_agent, 'blackberry') !== false) {
436 $aresult = explode("/", stristr($this->_agent, "BlackBerry"));
437 if (isset($aresult[1])) {
438 $aversion = explode(' ', $aresult[1]);
439 $this->setVersion($aversion[0]);
440 $this->_browser_name = self::BROWSER_BLACKBERRY;
441 $this->setMobile(true);
442 return true;
443 }
444 }
445 return false;
446 }
447
448 /**
449 * Determine if the user is using an AOL User Agent (last updated 1.7)
450 * @return boolean True if the browser is from AOL otherwise false
451 */
452 protected function checkForAol()
453 {
454 $this->setAol(false);
455 $this->setAolVersion(self::VERSION_UNKNOWN);
456
457 if (stripos($this->_agent, 'aol') !== false) {
458 $aversion = explode(' ', stristr($this->_agent, 'AOL'));
459 if (isset($aversion[1])) {
460 $this->setAol(true);
461 $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
462 return true;
463 }
464 }
465 return false;
466 }
467
468 /**
469 * Determine if the browser is the GoogleBot or not (last updated 1.7)
470 * @return boolean True if the browser is the GoogletBot otherwise false
471 */
472 protected function checkBrowserGoogleBot()
473 {
474 if (stripos($this->_agent, 'googlebot') !== false) {
475 $aresult = explode('/', stristr($this->_agent, 'googlebot'));
476 if (isset($aresult[1])) {
477 $aversion = explode(' ', $aresult[1]);
478 $this->setVersion(str_replace(';', '', $aversion[0]));
479 $this->_browser_name = self::BROWSER_GOOGLEBOT;
480 $this->setRobot(true);
481 return true;
482 }
483 }
484 return false;
485 }
486
487 /**
488 * Determine if the browser is the MSNBot or not (last updated 1.9)
489 * @return boolean True if the browser is the MSNBot otherwise false
490 */
491 protected function checkBrowserMSNBot()
492 {
493 if (stripos($this->_agent, "msnbot") !== false) {
494 $aresult = explode("/", stristr($this->_agent, "msnbot"));
495 if (isset($aresult[1])) {
496 $aversion = explode(" ", $aresult[1]);
497 $this->setVersion(str_replace(";", "", $aversion[0]));
498 $this->_browser_name = self::BROWSER_MSNBOT;
499 $this->setRobot(true);
500 return true;
501 }
502 }
503 return false;
504 }
505
506 /**
507 * Determine if the browser is the BingBot or not (last updated 1.9)
508 * @return boolean True if the browser is the BingBot otherwise false
509 */
510 protected function checkBrowserBingBot()
511 {
512 if (stripos($this->_agent, "bingbot") !== false) {
513 $aresult = explode("/", stristr($this->_agent, "bingbot"));
514 if (isset($aresult[1])) {
515 $aversion = explode(" ", $aresult[1]);
516 $this->setVersion(str_replace(";", "", $aversion[0]));
517 $this->_browser_name = self::BROWSER_BINGBOT;
518 $this->setRobot(true);
519 return true;
520 }
521 }
522 return false;
523 }
524
525 /**
526 * Determine if the browser is the W3C Validator or not (last updated 1.7)
527 * @return boolean True if the browser is the W3C Validator otherwise false
528 */
529 protected function checkBrowserW3CValidator()
530 {
531 if (stripos($this->_agent, 'W3C-checklink') !== false) {
532 $aresult = explode('/', stristr($this->_agent, 'W3C-checklink'));
533 if (isset($aresult[1])) {
534 $aversion = explode(' ', $aresult[1]);
535 $this->setVersion($aversion[0]);
536 $this->_browser_name = self::BROWSER_W3CVALIDATOR;
537 return true;
538 }
539 } else if (stripos($this->_agent, 'W3C_Validator') !== false) {
540 // Some of the Validator versions do not delineate w/ a slash - add it back in
541 $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
542 $aresult = explode('/', stristr($ua, 'W3C_Validator'));
543 if (isset($aresult[1])) {
544 $aversion = explode(' ', $aresult[1]);
545 $this->setVersion($aversion[0]);
546 $this->_browser_name = self::BROWSER_W3CVALIDATOR;
547 return true;
548 }
549 } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) {
550 $this->_browser_name = self::BROWSER_W3CVALIDATOR;
551 $this->setMobile(true);
552 return true;
553 }
554 return false;
555 }
556
557 /**
558 * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
559 * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
560 */
561 protected function checkBrowserSlurp()
562 {
563 if (stripos($this->_agent, 'slurp') !== false) {
564 $aresult = explode('/', stristr($this->_agent, 'Slurp'));
565 if (isset($aresult[1])) {
566 $aversion = explode(' ', $aresult[1]);
567 $this->setVersion($aversion[0]);
568 $this->_browser_name = self::BROWSER_SLURP;
569 $this->setRobot(true);
570 $this->setMobile(false);
571 return true;
572 }
573 }
574 return false;
575 }
576
577 /**
578 * Determine if the browser is Internet Explorer or not (last updated 1.7)
579 * @return boolean True if the browser is Internet Explorer otherwise false
580 */
581 protected function checkBrowserInternetExplorer()
582 {
583 // Test for IE11
584 if( stripos($this->_agent,'Trident/7.0; rv:11.0') !== false ) {
585 $this->setBrowser(self::BROWSER_IE);
586 $this->setVersion('11.0');
587 return true;
588 }
589 // Test for v1 - v1.5 IE
590 else if (stripos($this->_agent, 'microsoft internet explorer') !== false) {
591 $this->setBrowser(self::BROWSER_IE);
592 $this->setVersion('1.0');
593 $aresult = stristr($this->_agent, '/');
594 if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
595 $this->setVersion('1.5');
596 }
597 return true;
598 } // Test for versions > 1.5
599 else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) {
600 // See if the browser is the odd MSN Explorer
601 if (stripos($this->_agent, 'msnb') !== false) {
602 $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN'));
603 if (isset($aresult[1])) {
604 $this->setBrowser(self::BROWSER_MSN);
605 $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
606 return true;
607 }
608 }
609 $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie'));
610 if (isset($aresult[1])) {
611 $this->setBrowser(self::BROWSER_IE);
612 $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
613 if(stripos($this->_agent, 'IEMobile') !== false) {
614 $this->setBrowser(self::BROWSER_POCKET_IE);
615 $this->setMobile(true);
616 }
617 return true;
618 }
619 } // Test for versions > IE 10
620 else if(stripos($this->_agent, 'trident') !== false) {
621 $this->setBrowser(self::BROWSER_IE);
622 $result = explode('rv:', $this->_agent);
623 if (isset($result[1])) {
624 $this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1]));
625 $this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent);
626 }
627 } // Test for Pocket IE
628 else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) {
629 $aresult = explode(' ', stristr($this->_agent, 'mspie'));
630 if (isset($aresult[1])) {
631 $this->setPlatform(self::PLATFORM_WINDOWS_CE);
632 $this->setBrowser(self::BROWSER_POCKET_IE);
633 $this->setMobile(true);
634
635 if (stripos($this->_agent, 'mspie') !== false) {
636 $this->setVersion($aresult[1]);
637 } else {
638 $aversion = explode('/', $this->_agent);
639 if (isset($aversion[1])) {
640 $this->setVersion($aversion[1]);
641 }
642 }
643 return true;
644 }
645 }
646 return false;
647 }
648
649 /**
650 * Determine if the browser is Opera or not (last updated 1.7)
651 * @return boolean True if the browser is Opera otherwise false
652 */
653 protected function checkBrowserOpera()
654 {
655 if (stripos($this->_agent, 'opera mini') !== false) {
656 $resultant = stristr($this->_agent, 'opera mini');
657 if (preg_match('/\//', $resultant)) {
658 $aresult = explode('/', $resultant);
659 if (isset($aresult[1])) {
660 $aversion = explode(' ', $aresult[1]);
661 $this->setVersion($aversion[0]);
662 }
663 } else {
664 $aversion = explode(' ', stristr($resultant, 'opera mini'));
665 if (isset($aversion[1])) {
666 $this->setVersion($aversion[1]);
667 }
668 }
669 $this->_browser_name = self::BROWSER_OPERA_MINI;
670 $this->setMobile(true);
671 return true;
672 } else if (stripos($this->_agent, 'opera') !== false) {
673 $resultant = stristr($this->_agent, 'opera');
674 if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) {
675 $this->setVersion($matches[1]);
676 } else if (preg_match('/\//', $resultant)) {
677 $aresult = explode('/', str_replace("(", " ", $resultant));
678 if (isset($aresult[1])) {
679 $aversion = explode(' ', $aresult[1]);
680 $this->setVersion($aversion[0]);
681 }
682 } else {
683 $aversion = explode(' ', stristr($resultant, 'opera'));
684 $this->setVersion(isset($aversion[1]) ? $aversion[1] : "");
685 }
686 if (stripos($this->_agent, 'Opera Mobi') !== false) {
687 $this->setMobile(true);
688 }
689 $this->_browser_name = self::BROWSER_OPERA;
690 return true;
691 } else if (stripos($this->_agent, 'OPR') !== false) {
692 $resultant = stristr($this->_agent, 'OPR');
693 if (preg_match('/\//', $resultant)) {
694 $aresult = explode('/', str_replace("(", " ", $resultant));
695 if (isset($aresult[1])) {
696 $aversion = explode(' ', $aresult[1]);
697 $this->setVersion($aversion[0]);
698 }
699 }
700 if (stripos($this->_agent, 'Mobile') !== false) {
701 $this->setMobile(true);
702 }
703 $this->_browser_name = self::BROWSER_OPERA;
704 return true;
705 }
706 return false;
707 }
708
709 /**
710 * Determine if the browser is Chrome or not (last updated 1.7)
711 * @return boolean True if the browser is Chrome otherwise false
712 */
713 protected function checkBrowserChrome()
714 {
715 if (stripos($this->_agent, 'Chrome') !== false) {
716 $aresult = explode('/', stristr($this->_agent, 'Chrome'));
717 if (isset($aresult[1])) {
718 $aversion = explode(' ', $aresult[1]);
719 $this->setVersion($aversion[0]);
720 $this->setBrowser(self::BROWSER_CHROME);
721 //Chrome on Android
722 if (stripos($this->_agent, 'Android') !== false) {
723 if (stripos($this->_agent, 'Mobile') !== false) {
724 $this->setMobile(true);
725 } else {
726 $this->setTablet(true);
727 }
728 }
729 return true;
730 }
731 }
732 return false;
733 }
734
735
736 /**
737 * Determine if the browser is WebTv or not (last updated 1.7)
738 * @return boolean True if the browser is WebTv otherwise false
739 */
740 protected function checkBrowserWebTv()
741 {
742 if (stripos($this->_agent, 'webtv') !== false) {
743 $aresult = explode('/', stristr($this->_agent, 'webtv'));
744 if (isset($aresult[1])) {
745 $aversion = explode(' ', $aresult[1]);
746 $this->setVersion($aversion[0]);
747 $this->setBrowser(self::BROWSER_WEBTV);
748 return true;
749 }
750 }
751 return false;
752 }
753
754 /**
755 * Determine if the browser is NetPositive or not (last updated 1.7)
756 * @return boolean True if the browser is NetPositive otherwise false
757 */
758 protected function checkBrowserNetPositive()
759 {
760 if (stripos($this->_agent, 'NetPositive') !== false) {
761 $aresult = explode('/', stristr($this->_agent, 'NetPositive'));
762 if (isset($aresult[1])) {
763 $aversion = explode(' ', $aresult[1]);
764 $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
765 $this->setBrowser(self::BROWSER_NETPOSITIVE);
766 return true;
767 }
768 }
769 return false;
770 }
771
772 /**
773 * Determine if the browser is Galeon or not (last updated 1.7)
774 * @return boolean True if the browser is Galeon otherwise false
775 */
776 protected function checkBrowserGaleon()
777 {
778 if (stripos($this->_agent, 'galeon') !== false) {
779 $aresult = explode(' ', stristr($this->_agent, 'galeon'));
780 $aversion = explode('/', $aresult[0]);
781 if (isset($aversion[1])) {
782 $this->setVersion($aversion[1]);
783 $this->setBrowser(self::BROWSER_GALEON);
784 return true;
785 }
786 }
787 return false;
788 }
789
790 /**
791 * Determine if the browser is Konqueror or not (last updated 1.7)
792 * @return boolean True if the browser is Konqueror otherwise false
793 */
794 protected function checkBrowserKonqueror()
795 {
796 if (stripos($this->_agent, 'Konqueror') !== false) {
797 $aresult = explode(' ', stristr($this->_agent, 'Konqueror'));
798 $aversion = explode('/', $aresult[0]);
799 if (isset($aversion[1])) {
800 $this->setVersion($aversion[1]);
801 $this->setBrowser(self::BROWSER_KONQUEROR);
802 return true;
803 }
804 }
805 return false;
806 }
807
808 /**
809 * Determine if the browser is iCab or not (last updated 1.7)
810 * @return boolean True if the browser is iCab otherwise false
811 */
812 protected function checkBrowserIcab()
813 {
814 if (stripos($this->_agent, 'icab') !== false) {
815 $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab'));
816 if (isset($aversion[1])) {
817 $this->setVersion($aversion[1]);
818 $this->setBrowser(self::BROWSER_ICAB);
819 return true;
820 }
821 }
822 return false;
823 }
824
825 /**
826 * Determine if the browser is OmniWeb or not (last updated 1.7)
827 * @return boolean True if the browser is OmniWeb otherwise false
828 */
829 protected function checkBrowserOmniWeb()
830 {
831 if (stripos($this->_agent, 'omniweb') !== false) {
832 $aresult = explode('/', stristr($this->_agent, 'omniweb'));
833 $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : "");
834 $this->setVersion($aversion[0]);
835 $this->setBrowser(self::BROWSER_OMNIWEB);
836 return true;
837 }
838 return false;
839 }
840
841 /**
842 * Determine if the browser is Phoenix or not (last updated 1.7)
843 * @return boolean True if the browser is Phoenix otherwise false
844 */
845 protected function checkBrowserPhoenix()
846 {
847 if (stripos($this->_agent, 'Phoenix') !== false) {
848 $aversion = explode('/', stristr($this->_agent, 'Phoenix'));
849 if (isset($aversion[1])) {
850 $this->setVersion($aversion[1]);
851 $this->setBrowser(self::BROWSER_PHOENIX);
852 return true;
853 }
854 }
855 return false;
856 }
857
858 /**
859 * Determine if the browser is Firebird or not (last updated 1.7)
860 * @return boolean True if the browser is Firebird otherwise false
861 */
862 protected function checkBrowserFirebird()
863 {
864 if (stripos($this->_agent, 'Firebird') !== false) {
865 $aversion = explode('/', stristr($this->_agent, 'Firebird'));
866 if (isset($aversion[1])) {
867 $this->setVersion($aversion[1]);
868 $this->setBrowser(self::BROWSER_FIREBIRD);
869 return true;
870 }
871 }
872 return false;
873 }
874
875 /**
876 * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
877 * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
878 * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
879 */
880 protected function checkBrowserNetscapeNavigator9Plus()
881 {
882 if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) {
883 $this->setVersion($matches[1]);
884 $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
885 return true;
886 } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) {
887 $this->setVersion($matches[1]);
888 $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
889 return true;
890 }
891 return false;
892 }
893
894 /**
895 * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
896 * @return boolean True if the browser is Shiretoko otherwise false
897 */
898 protected function checkBrowserShiretoko()
899 {
900 if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) {
901 $this->setVersion($matches[1]);
902 $this->setBrowser(self::BROWSER_SHIRETOKO);
903 return true;
904 }
905 return false;
906 }
907
908 /**
909 * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
910 * @return boolean True if the browser is Ice Cat otherwise false
911 */
912 protected function checkBrowserIceCat()
913 {
914 if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) {
915 $this->setVersion($matches[1]);
916 $this->setBrowser(self::BROWSER_ICECAT);
917 return true;
918 }
919 return false;
920 }
921
922 /**
923 * Determine if the browser is Nokia or not (last updated 1.7)
924 * @return boolean True if the browser is Nokia otherwise false
925 */
926 protected function checkBrowserNokia()
927 {
928 if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) {
929 $this->setVersion($matches[2]);
930 if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) {
931 $this->setBrowser(self::BROWSER_NOKIA_S60);
932 } else {
933 $this->setBrowser(self::BROWSER_NOKIA);
934 }
935 $this->setMobile(true);
936 return true;
937 }
938 return false;
939 }
940
941 /**
942 * Determine if the browser is Firefox or not (last updated 1.7)
943 * @return boolean True if the browser is Firefox otherwise false
944 */
945 protected function checkBrowserFirefox()
946 {
947 if (stripos($this->_agent, 'safari') === false) {
948 if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) {
949 $this->setVersion($matches[1]);
950 $this->setBrowser(self::BROWSER_FIREFOX);
951 //Firefox on Android
952 if (stripos($this->_agent, 'Android') !== false) {
953 if (stripos($this->_agent, 'Mobile') !== false) {
954 $this->setMobile(true);
955 } else {
956 $this->setTablet(true);
957 }
958 }
959 return true;
960 } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) {
961 $this->setVersion("");
962 $this->setBrowser(self::BROWSER_FIREFOX);
963 return true;
964 }
965 }
966 return false;
967 }
968
969 /**
970 * Determine if the browser is Firefox or not (last updated 1.7)
971 * @return boolean True if the browser is Firefox otherwise false
972 */
973 protected function checkBrowserIceweasel()
974 {
975 if (stripos($this->_agent, 'Iceweasel') !== false) {
976 $aresult = explode('/', stristr($this->_agent, 'Iceweasel'));
977 if (isset($aresult[1])) {
978 $aversion = explode(' ', $aresult[1]);
979 $this->setVersion($aversion[0]);
980 $this->setBrowser(self::BROWSER_ICEWEASEL);
981 return true;
982 }
983 }
984 return false;
985 }
986
987 /**
988 * Determine if the browser is Mozilla or not (last updated 1.7)
989 * @return boolean True if the browser is Mozilla otherwise false
990 */
991 protected function checkBrowserMozilla()
992 {
993 if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
994 $aversion = explode(' ', stristr($this->_agent, 'rv:'));
995 preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion);
996 $this->setVersion(str_replace('rv:', '', $aversion[0]));
997 $this->setBrowser(self::BROWSER_MOZILLA);
998 return true;
999 } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
1000 $aversion = explode('', stristr($this->_agent, 'rv:'));
1001 $this->setVersion(str_replace('rv:', '', $aversion[0]));
1002 $this->setBrowser(self::BROWSER_MOZILLA);
1003 return true;
1004 } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) {
1005 $this->setVersion($matches[1]);
1006 $this->setBrowser(self::BROWSER_MOZILLA);
1007 return true;
1008 }
1009 return false;
1010 }
1011
1012 /**
1013 * Determine if the browser is Lynx or not (last updated 1.7)
1014 * @return boolean True if the browser is Lynx otherwise false
1015 */
1016 protected function checkBrowserLynx()
1017 {
1018 if (stripos($this->_agent, 'lynx') !== false) {
1019 $aresult = explode('/', stristr($this->_agent, 'Lynx'));
1020 $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ""));
1021 $this->setVersion($aversion[0]);
1022 $this->setBrowser(self::BROWSER_LYNX);
1023 return true;
1024 }
1025 return false;
1026 }
1027
1028 /**
1029 * Determine if the browser is Amaya or not (last updated 1.7)
1030 * @return boolean True if the browser is Amaya otherwise false
1031 */
1032 protected function checkBrowserAmaya()
1033 {
1034 if (stripos($this->_agent, 'amaya') !== false) {
1035 $aresult = explode('/', stristr($this->_agent, 'Amaya'));
1036 if (isset($aresult[1])) {
1037 $aversion = explode(' ', $aresult[1]);
1038 $this->setVersion($aversion[0]);
1039 $this->setBrowser(self::BROWSER_AMAYA);
1040 return true;
1041 }
1042 }
1043 return false;
1044 }
1045
1046 /**
1047 * Determine if the browser is Safari or not (last updated 1.7)
1048 * @return boolean True if the browser is Safari otherwise false
1049 */
1050 protected function checkBrowserSafari()
1051 {
1052 if (stripos($this->_agent, 'Safari') !== false
1053 && stripos($this->_agent, 'iPhone') === false
1054 && stripos($this->_agent, 'iPod') === false) {
1055
1056 $aresult = explode('/', stristr($this->_agent, 'Version'));
1057 if (isset($aresult[1])) {
1058 $aversion = explode(' ', $aresult[1]);
1059 $this->setVersion($aversion[0]);
1060 } else {
1061 $this->setVersion(self::VERSION_UNKNOWN);
1062 }
1063 $this->setBrowser(self::BROWSER_SAFARI);
1064 return true;
1065 }
1066 return false;
1067 }
1068
1069 /**
1070 * Detect if URL is loaded from FacebookExternalHit
1071 * @return boolean True if it detects FacebookExternalHit otherwise false
1072 */
1073 protected function checkFacebookExternalHit()
1074 {
1075 if(stristr($this->_agent,'FacebookExternalHit'))
1076 {
1077 $this->setRobot(true);
1078 $this->setFacebook(true);
1079 return true;
1080 }
1081 return false;
1082 }
1083
1084 /**
1085 * Detect if URL is being loaded from internal Facebook browser
1086 * @return boolean True if it detects internal Facebook browser otherwise false
1087 */
1088 protected function checkForFacebookIos()
1089 {
1090 if(stristr($this->_agent,'FBIOS'))
1091 {
1092 $this->setFacebook(true);
1093 return true;
1094 }
1095 return false;
1096 }
1097
1098 /**
1099 * Detect Version for the Safari browser on iOS devices
1100 * @return boolean True if it detects the version correctly otherwise false
1101 */
1102 protected function getSafariVersionOnIos()
1103 {
1104 $aresult = explode('/',stristr($this->_agent,'Version'));
1105 if( isset($aresult[1]) )
1106 {
1107 $aversion = explode(' ',$aresult[1]);
1108 $this->setVersion($aversion[0]);
1109 return true;
1110 }
1111 return false;
1112 }
1113
1114 /**
1115 * Detect Version for the Chrome browser on iOS devices
1116 * @return boolean True if it detects the version correctly otherwise false
1117 */
1118 protected function getChromeVersionOnIos()
1119 {
1120 $aresult = explode('/',stristr($this->_agent,'CriOS'));
1121 if( isset($aresult[1]) )
1122 {
1123 $aversion = explode(' ',$aresult[1]);
1124 $this->setVersion($aversion[0]);
1125 $this->setBrowser(self::BROWSER_CHROME);
1126 return true;
1127 }
1128 return false;
1129 }
1130
1131 /**
1132 * Determine if the browser is iPhone or not (last updated 1.7)
1133 * @return boolean True if the browser is iPhone otherwise false
1134 */
1135 protected function checkBrowseriPhone() {
1136 if( stripos($this->_agent,'iPhone') !== false ) {
1137 $this->setVersion(self::VERSION_UNKNOWN);
1138 $this->setBrowser(self::BROWSER_IPHONE);
1139 $this->getSafariVersionOnIos();
1140 $this->getChromeVersionOnIos();
1141 $this->checkForFacebookIos();
1142 $this->setMobile(true);
1143 return true;
1144 }
1145 return false;
1146 }
1147
1148 /**
1149 * Determine if the browser is iPad or not (last updated 1.7)
1150 * @return boolean True if the browser is iPad otherwise false
1151 */
1152 protected function checkBrowseriPad() {
1153 if( stripos($this->_agent,'iPad') !== false ) {
1154 $this->setVersion(self::VERSION_UNKNOWN);
1155 $this->setBrowser(self::BROWSER_IPAD);
1156 $this->getSafariVersionOnIos();
1157 $this->getChromeVersionOnIos();
1158 $this->checkForFacebookIos();
1159 $this->setTablet(true);
1160 return true;
1161 }
1162 return false;
1163 }
1164
1165 /**
1166 * Determine if the browser is iPod or not (last updated 1.7)
1167 * @return boolean True if the browser is iPod otherwise false
1168 */
1169 protected function checkBrowseriPod() {
1170 if( stripos($this->_agent,'iPod') !== false ) {
1171 $this->setVersion(self::VERSION_UNKNOWN);
1172 $this->setBrowser(self::BROWSER_IPOD);
1173 $this->getSafariVersionOnIos();
1174 $this->getChromeVersionOnIos();
1175 $this->checkForFacebookIos();
1176 $this->setMobile(true);
1177 return true;
1178 }
1179 return false;
1180 }
1181
1182 /**
1183 * Determine if the browser is Android or not (last updated 1.7)
1184 * @return boolean True if the browser is Android otherwise false
1185 */
1186 protected function checkBrowserAndroid()
1187 {
1188 if (stripos($this->_agent, 'Android') !== false) {
1189 $aresult = explode(' ', stristr($this->_agent, 'Android'));
1190 if (isset($aresult[1])) {
1191 $aversion = explode(' ', $aresult[1]);
1192 $this->setVersion($aversion[0]);
1193 } else {
1194 $this->setVersion(self::VERSION_UNKNOWN);
1195 }
1196 if (stripos($this->_agent, 'Mobile') !== false) {
1197 $this->setMobile(true);
1198 } else {
1199 $this->setTablet(true);
1200 }
1201 $this->setBrowser(self::BROWSER_ANDROID);
1202 return true;
1203 }
1204 return false;
1205 }
1206
1207 /**
1208 * Determine the user's platform (last updated 1.7)
1209 */
1210 protected function checkPlatform()
1211 {
1212 if (stripos($this->_agent, 'windows') !== false)
1213 {
1214 $this->_platform = self::PLATFORM_WINDOWS;
1215 }
1216 else if (stripos($this->_agent, 'iPad') !== false)
1217 {
1218 $this->_platform = self::PLATFORM_IPAD;
1219 }
1220 else if (stripos($this->_agent, 'iPod') !== false)
1221 {
1222 $this->_platform = self::PLATFORM_IPOD;
1223 }
1224 else if (stripos($this->_agent, 'iPhone') !== false)
1225 {
1226 $this->_platform = self::PLATFORM_IPHONE;
1227 }
1228 elseif (stripos($this->_agent, 'mac') !== false)
1229 {
1230 $this->_platform = self::PLATFORM_APPLE;
1231 }
1232 elseif (stripos($this->_agent, 'android') !== false)
1233 {
1234 $this->_platform = self::PLATFORM_ANDROID;
1235 }
1236 elseif (stripos($this->_agent, 'linux') !== false)
1237 {
1238 $this->_platform = self::PLATFORM_LINUX;
1239 }
1240 else if (stripos($this->_agent, 'Nokia') !== false)
1241 {
1242 $this->_platform = self::PLATFORM_NOKIA;
1243 }
1244 else if (stripos($this->_agent, 'BlackBerry') !== false)
1245 {
1246 $this->_platform = self::PLATFORM_BLACKBERRY;
1247 }
1248 elseif (stripos($this->_agent, 'FreeBSD') !== false)
1249 {
1250 $this->_platform = self::PLATFORM_FREEBSD;
1251 }
1252 elseif (stripos($this->_agent, 'OpenBSD') !== false)
1253 {
1254 $this->_platform = self::PLATFORM_OPENBSD;
1255 }
1256 elseif (stripos($this->_agent, 'NetBSD') !== false)
1257 {
1258 $this->_platform = self::PLATFORM_NETBSD;
1259 }
1260 elseif (stripos($this->_agent, 'OpenSolaris') !== false)
1261 {
1262 $this->_platform = self::PLATFORM_OPENSOLARIS;
1263 }
1264 elseif (stripos($this->_agent, 'SunOS') !== false)
1265 {
1266 $this->_platform = self::PLATFORM_SUNOS;
1267 }
1268 elseif (stripos($this->_agent, 'OS\/2') !== false)
1269 {
1270 $this->_platform = self::PLATFORM_OS2;
1271 }
1272 elseif (stripos($this->_agent, 'BeOS') !== false)
1273 {
1274 $this->_platform = self::PLATFORM_BEOS;
1275 }
1276 elseif (stripos($this->_agent, 'win') !== false)
1277 {
1278 $this->_platform = self::PLATFORM_WINDOWS;
1279 }
1280
1281 }
1282 }
1283