BrowserDetection
[ class tree: BrowserDetection ] [ index: BrowserDetection ] [ all elements ]

Source for file BrowserDetection.php

Documentation is available at BrowserDetection.php

  1. <?php
  2.  
  3. /**
  4.  * Browser detection class file.
  5.  * This file contains everything required to use the BrowserDetection class.
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
  8.  * Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any
  9.  * later version (if any).
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12.  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13.  * details at: http://www.gnu.org/licenses/lgpl.html
  14.  *
  15.  * @package BrowserDetection
  16.  * @version 2.1
  17.  * @last-modified June 5, 2014
  18.  * @author Alexandre Valiquette
  19.  * @copyright Copyright (c) 2014, Wolfcast
  20.  * @link http://wolfcast.com/
  21.  */
  22.  
  23.  
  24. /**
  25.  * The BrowserDetection class facilitates the identification of the user's environment such as Web browser, version,
  26.  * platform or if it's a mobile device.
  27.  *
  28.  * Typical usage:
  29.  *
  30.  * $browser = new BrowserDetection();
  31.  * if ($browser->getBrowser() == BrowserDetection::BROWSER_FIREFOX && $browser->getVersion() >= 5) {
  32.  *     echo 'You have FireFox version 5 or greater.';
  33.  * }
  34.  *
  35.  * The class is an updated version of Chris Schuld's Browser class version 1.9 which is unmaintaned since August 20th,
  36.  * 2010. Chris' class was based on the original work from Gary White.
  37.  *
  38.  * Updates:
  39.  *
  40.  * 2014-06-04:
  41.  *  + Version 2.1. Added IE 11+ support.
  42.  *
  43.  * 2013-05-27:
  44.  *  + Version 2.0 is (almost) a complete rewrite based on Chris Schuld's Browser class version 1.9 plus changes below
  45.  *  + Added support for Opera Mobile
  46.  *  + Added support for the Windows Phone (formerly Windows Mobile) platform
  47.  *  + Added support for BlackBerry Tablet OS and BlackBerry 10
  48.  *  + Added support for the Symbian platform
  49.  *  + Added support for Bingbot
  50.  *  + Added support for the Yahoo! Multimedia crawler
  51.  *  + Removed iPhone/iPad/iPod browsers since there are not browsers but platforms - test them with getPlatform()
  52.  *  + Removed support for Shiretoko (Firefox 3.5 alpha/beta) and MSN Browser
  53.  *  + Merged Nokia and Nokia S60
  54.  *  + Updated some deprecated browser names
  55.  *  + Many public methods are now protected
  56.  *  + Documentation updated
  57.  *
  58.  * 2010-07-04:
  59.  *  + Added detection of IE compatibility view - test with getIECompatibilityView()
  60.  *  + Added support for all (deprecated) Netscape versions
  61.  *  + Added support for Safari < 3.0
  62.  *  + Better Firefox version parsing
  63.  *  + Better Opera version parsing
  64.  *  + Better Mozilla detection
  65.  *
  66.  * @package BrowserDetection
  67.  * @version 2.1
  68.  * @last-modified June 5, 2014
  69.  * @author Alexandre Valiquette, Chris Schuld, Gary White
  70.  * @copyright Copyright (c) 2014, Wolfcast
  71.  * @license http://www.gnu.org/licenses/lgpl.html
  72.  * @link http://wolfcast.com/
  73.  * @link http://chrisschuld.com/
  74.  * @link http://www.apptools.com/phptools/browser/
  75.  */
  76. {
  77.     const BROWSER_AMAYA 'Amaya';
  78.     const BROWSER_ANDROID 'Android';
  79.     const BROWSER_BINGBOT 'Bingbot';
  80.     const BROWSER_BLACKBERRY 'BlackBerry';
  81.     const BROWSER_CHROME 'Chrome';
  82.     const BROWSER_FIREBIRD 'Firebird';
  83.     const BROWSER_FIREFOX 'Firefox';
  84.     const BROWSER_GALEON 'Galeon';
  85.     const BROWSER_GOOGLEBOT 'Googlebot';
  86.     const BROWSER_ICAB 'iCab';
  87.     const BROWSER_ICECAT 'GNU IceCat';
  88.     const BROWSER_ICEWEASEL 'GNU IceWeasel';
  89.     const BROWSER_IE 'Internet Explorer';
  90.     const BROWSER_IE_MOBILE 'Internet Explorer Mobile';
  91.     const BROWSER_KONQUEROR 'Konqueror';
  92.     const BROWSER_LYNX 'Lynx';
  93.     const BROWSER_MOZILLA 'Mozilla';
  94.     const BROWSER_MSNBOT 'MSNBot';
  95.     const BROWSER_MSNTV 'MSN TV';
  96.     const BROWSER_NETPOSITIVE 'NetPositive';
  97.     const BROWSER_NETSCAPE 'Netscape';
  98.     const BROWSER_NOKIA 'Nokia Browser';
  99.     const BROWSER_OMNIWEB 'OmniWeb';
  100.     const BROWSER_OPERA 'Opera';
  101.     const BROWSER_OPERA_MINI 'Opera Mini';
  102.     const BROWSER_OPERA_MOBILE 'Opera Mobile';
  103.     const BROWSER_PHOENIX 'Phoenix';
  104.     const BROWSER_SAFARI 'Safari';
  105.     const BROWSER_SLURP 'Yahoo! Slurp';
  106.     const BROWSER_TABLET_OS 'BlackBerry Tablet OS';
  107.     const BROWSER_UNKNOWN 'unknown';
  108.     const BROWSER_W3CVALIDATOR 'W3C Validator';
  109.     const BROWSER_YAHOO_MM 'Yahoo! Multimedia';
  110.     const PLATFORM_ANDROID 'Android';
  111.     const PLATFORM_BEOS 'BeOS';
  112.     const PLATFORM_BLACKBERRY 'BlackBerry';
  113.     const PLATFORM_FREEBSD 'FreeBSD';
  114.     const PLATFORM_IPAD 'iPad';
  115.     const PLATFORM_IPHONE 'iPhone';
  116.     const PLATFORM_IPOD 'iPod';
  117.     const PLATFORM_LINUX 'Linux';
  118.     const PLATFORM_MACINTOSH 'Macintosh';
  119.     const PLATFORM_NETBSD 'NetBSD';
  120.     const PLATFORM_NOKIA 'Nokia';
  121.     const PLATFORM_OPENBSD 'OpenBSD';
  122.     const PLATFORM_OPENSOLARIS 'OpenSolaris';
  123.     const PLATFORM_OS2 'OS/2';
  124.     const PLATFORM_SUNOS 'SunOS';
  125.     const PLATFORM_SYMBIAN 'Symbian';
  126.     const PLATFORM_UNKNOWN 'unknown';
  127.     const PLATFORM_WINDOWS 'Windows';
  128.     const PLATFORM_WINDOWS_CE 'Windows CE';
  129.     const PLATFORM_WINDOWS_PHONE 'Windows Phone';
  130.     const VERSION_UNKNOWN 'unknown';
  131.  
  132.     private $_agent = '';
  133.     private $_aolVersion = '';
  134.     private $_browserName = '';
  135.     private $_compatibilityViewName = '';
  136.     private $_compatibilityViewVer = '';
  137.     private $_isAol = false;
  138.     private $_isMobile = false;
  139.     private $_isRobot = false;
  140.     private $_platform = '';
  141.     private $_version = '';
  142.  
  143.  
  144.     //--- MAGIC METHODS ------------------------------------------------------------------------------------------------
  145.  
  146.  
  147.     /**
  148.      * BrowserDetection class constructor.
  149.      * @param string $useragent The user agent to work with. Leave empty for the current user agent (contained in
  150.      *  $_SERVER['HTTP_USER_AGENT']).
  151.      */
  152.     public function __construct($useragent '')
  153.     {
  154.         $this->setUserAgent($useragent);
  155.     }
  156.  
  157.     /**
  158.      * Determine how the class will react when it is treated like a string.
  159.      * @return string Returns an HTML formatted string with a summary of the browser informations.
  160.      */
  161.     public function __toString()
  162.     {
  163.         $result '<strong>Browser name:</strong> ' $this->getBrowser('<br />' PHP_EOL .
  164.                   '<strong>Browser version:</strong> ' $this->getVersion('<br />' PHP_EOL;
  165.  
  166.         if ($this->isInIECompatibilityView()) {
  167.             $result .= '<strong>Compatibility view mode:</strong> ' $this->getIECompatibilityView('<br />' PHP_EOL;
  168.         }
  169.         if ($this->isAol()) {
  170.             $result .= '<strong>AOL version:</strong> ' $this->getAolVersion('<br />' PHP_EOL;
  171.         }
  172.         if ($this->isChromeFrame()) {
  173.             $result .= '<strong>Is Google Chrome Frame:</strong> Yes<br />' PHP_EOL;
  174.         }
  175.  
  176.         $result .= '<strong>Platform:</strong> ' $this->getPlatform('<br />' PHP_EOL;
  177.  
  178.         if ($this->isRobot()) {
  179.             $result .= '<strong>Is a robot:</strong> Yes<br />' PHP_EOL;
  180.         }
  181.         if ($this->isMobile()) {
  182.             $result .= '<strong>Is on a mobile device:</strong> Yes<br />' PHP_EOL;
  183.         }
  184.  
  185.         $result .= '<strong>Browser user agent:</strong> ' $this->getUserAgent('<br />' PHP_EOL;
  186.  
  187.         return $result;
  188.     }
  189.  
  190.  
  191.     //--- PUBLIC MEMBERS -----------------------------------------------------------------------------------------------
  192.  
  193.  
  194.     /**
  195.      * Compare two version number strings.
  196.      * @param string $sourceVer The source version number.
  197.      * @param string $compareVer The version number to compare with the source version number.
  198.      * @return int Returns 1 if $sourceVer < $compareVer, 0 if $sourceVer == $compareVer or -1 if $sourceVer > $compareVer.
  199.      */
  200.     public function compareVersions($sourceVer$compareVer)
  201.     {
  202.         $sourceVer explode('.'$sourceVer);
  203.         foreach ($sourceVer as $k => $v{
  204.             $sourceVer[$k$this->parseInt($v);
  205.         }
  206.  
  207.         $compareVer explode('.'$compareVer);
  208.         foreach ($compareVer as $k => $v{
  209.             $compareVer[$k$this->parseInt($v);
  210.         }
  211.  
  212.         if (count($sourceVer!= count($compareVer)) {
  213.             if (count($sourceVercount($compareVer)) {
  214.                 for ($i count($compareVer)$i count($sourceVer)$i++{
  215.                     $compareVer[$i0;
  216.                 }
  217.             else {
  218.                 for ($i count($sourceVer)$i count($compareVer)$i++{
  219.                     $sourceVer[$i0;
  220.                 }
  221.             }
  222.         }
  223.  
  224.         foreach ($sourceVer as $i => $srcVerPart{
  225.             if ($srcVerPart $compareVer[$i]{
  226.                 return -1;
  227.             else {
  228.                 if ($srcVerPart $compareVer[$i]{
  229.                     return 1;
  230.                 }
  231.             }
  232.         }
  233.  
  234.         return 0;
  235.     }
  236.  
  237.     /**
  238.      * Get the version of AOL (if any). AOL releases "optimized" Internet Explorer and Firefox versions. In the making
  239.      * they add their version number in the user agent string of these browsers.
  240.      * @return string Returns the version of AOL or an empty string if no AOL version was found.
  241.      */
  242.     public function getAolVersion()
  243.     {
  244.         return $this->_aolVersion;
  245.     }
  246.  
  247.     /**
  248.      * Get the name of the browser. All of the return values are class constants. You can compare them like this:
  249.      * $myBrowserInstance->getBrowser() == BrowserDetection::BROWSER_FIREFOX.
  250.      * @return string Returns the name of the browser.
  251.      */
  252.     public function getBrowser()
  253.     {
  254.         return $this->_browserName;
  255.     }
  256.  
  257.     /**
  258.      * Get the name and version of the browser emulated in the compatibility view mode (if any). Since Internet
  259.      * Explorer 8, IE can be put in compatibility mode to make websites that were created for older browsers, especially
  260.      * IE 6 and 7, look better in IE 8+ which renders web pages closer to the standards and thus differently from those
  261.      * older versions of IE.
  262.      * @param bool $asArray Determines if the return value must be an array (true) or a string (false).
  263.      * @return mixed If a string was requested, the function returns the name and version of the browser emulated in the
  264.      *  compatibility view mode or an empty string if the browser is not in compatibility view mode. If an array was
  265.      *  requested, an array with the keys 'browser' and 'version' is returned.
  266.      */
  267.     public function getIECompatibilityView($asArray false)
  268.     {
  269.         if ($asArray{
  270.             return array('browser' => $this->_compatibilityViewName'version' => $this->_compatibilityViewVer);
  271.         else {
  272.             return trim($this->_compatibilityViewName . ' ' $this->_compatibilityViewVer);
  273.         }
  274.     }
  275.  
  276.     /**
  277.      * Get the name of the platform on which the browser is runned on (such as Windows, Apple, iPhone, etc.). All of the
  278.      * return values are class constants. You can compare them like this:
  279.      * $myBrowserInstance->getPlatform() == BrowserDetection::PLATFORM_ANDROID.
  280.      * @return string Returns the name of the platform or BrowserDetection::PLATFORM_UNKNOWN if unknown.
  281.      */
  282.     public function getPlatform()
  283.     {
  284.         return $this->_platform;
  285.     }
  286.  
  287.     /**
  288.      * Get the user agent value used by the class to determine the browser details.
  289.      * @return string The user agent string.
  290.      */
  291.     public function getUserAgent()
  292.     {
  293.         return $this->_agent;
  294.     }
  295.  
  296.     /**
  297.      * Get the version of the browser.
  298.      * @return string Returns the version of the browser or BrowserDetection::VERSION_UNKNOWN if unknown.
  299.      */
  300.     public function getVersion()
  301.     {
  302.         return $this->_version;
  303.     }
  304.  
  305.     /**
  306.      * Determine if the browser is from AOL. AOL releases "optimized" Internet Explorer and Firefox versions. In the
  307.      * making they add their details in the user agent string of these browsers.
  308.      * @return boolean Returns true if the browser is from AOL, false otherwise.
  309.      */
  310.     public function isAol()
  311.     {
  312.         return $this->_isAol;
  313.     }
  314.  
  315.     /**
  316.      * Determine if the browser runs Google Chrome Frame (it's a plug-in designed for Internet Explorer 6+ based on the
  317.      * open-source Chromium project - it's like a Chrome browser within IE).
  318.      * @return boolean Returns true if the browser is using Google Chrome Frame, false otherwise.
  319.      */
  320.     public function isChromeFrame()
  321.     {
  322.         return stripos($this->_agent'chromeframe'!== false;
  323.     }
  324.  
  325.     /**
  326.      * Determine if the browser is in compatibility view or not. Since Internet Explorer 8, IE can be put in
  327.      * compatibility mode to make websites that were created for older browsers, especially IE 6 and 7, look better in
  328.      * IE 8+ which renders web pages closer to the standards and thus differently from those older versions of IE.
  329.      * @return boolean Returns true if the browser is in compatibility view, false otherwise.
  330.      */
  331.     public function isInIECompatibilityView()
  332.     {
  333.         return ($this->_compatibilityViewName != ''|| ($this->_compatibilityViewVer != '');
  334.     }
  335.  
  336.     /**
  337.      * Determine if the browser is from a mobile device or not.
  338.      * @return boolean Returns true if the browser is from a mobile device, false otherwise.
  339.      */
  340.     public function isMobile()
  341.     {
  342.         return $this->_isMobile;
  343.     }
  344.  
  345.     /**
  346.      * Determine if the browser is a robot (Googlebot, Bingbot, Yahoo! Slurp...) or not.
  347.      * @return boolean Returns true if the browser is a robot, false otherwise.
  348.      */
  349.     public function isRobot()
  350.     {
  351.         return $this->_isRobot;
  352.     }
  353.  
  354.     /**
  355.      * Set the user agent to use with the class.
  356.      * @param string $agentString The value of the user agent. If an empty string is sent (default),
  357.      *  $_SERVER['HTTP_USER_AGENT'] will be used.
  358.      */
  359.     public function setUserAgent($agentString '')
  360.     {
  361.         if (!is_string($agentString|| trim($agentString== ''{
  362.             if (array_key_exists('HTTP_USER_AGENT'$_SERVER&& is_string($_SERVER['HTTP_USER_AGENT'])) {
  363.                 $agentString $_SERVER['HTTP_USER_AGENT'];
  364.             else {
  365.                 $agentString '';
  366.             }
  367.         }
  368.  
  369.         $this->reset();
  370.         $this->_agent = $agentString;
  371.         $this->detect();
  372.     }
  373.  
  374.  
  375.     //--- PROTECTED MEMBERS --------------------------------------------------------------------------------------------
  376.  
  377.  
  378.     /**
  379.      * Determine if the browser is the Amaya Web editor or not.
  380.      * @access protected
  381.      * @link http://www.w3.org/Amaya/
  382.      * @return boolean Returns true if the browser is Amaya, false otherwise.
  383.      */
  384.     protected function checkBrowserAmaya()
  385.     {
  386.         return $this->checkSimpleBrowserUA('amaya'$this->_agentself::BROWSER_AMAYA);
  387.     }
  388.  
  389.     /**
  390.      * Determine if the browser is the Android browser (based on the WebKit layout engine and coupled with Chrome's
  391.      * JavaScript engine) or not.
  392.      * @access protected
  393.      * @return boolean Returns true if the browser is the Android browser, false otherwise.
  394.      */
  395.     protected function checkBrowserAndroid()
  396.     {
  397.         //Android don't use the standard "Android/1.0", it uses "Android 1.0;" instead
  398.         return $this->checkSimpleBrowserUA('Android'$this->_agentself::BROWSER_ANDROIDtrue);
  399.     }
  400.  
  401.     /**
  402.      * Determine if the browser is the Bingbot crawler or not.
  403.      * @access protected
  404.      * @link http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0
  405.      * @return boolean Returns true if the browser is Bingbot, false otherwise.
  406.      */
  407.     protected function checkBrowserBingbot()
  408.     {
  409.         return $this->checkSimpleBrowserUA('bingbot'$this->_agentself::BROWSER_BINGBOTfalsetrue);
  410.     }
  411.  
  412.     /**
  413.      * Determine if the browser is the BlackBerry browser or not.
  414.      * @access protected
  415.      * @link http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862
  416.      * @return boolean Returns true if the browser is the BlackBerry browser, false otherwise.
  417.      */
  418.     protected function checkBrowserBlackBerry()
  419.     {
  420.         $found false;
  421.  
  422.         //Tablet OS check
  423.         if ($this->checkSimpleBrowserUA('RIM Tablet OS'$this->_agentself::BROWSER_TABLET_OStrue)) {
  424.             return true;
  425.         }
  426.  
  427.         //Version 6, 7 & 10 check (versions 8 & 9 does not exists)
  428.         if ($this->checkBrowserUAWithVersion(array('BlackBerry''BB10')$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  429.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  430.                 $found true;
  431.             else {
  432.                 return true;
  433.             }
  434.         }
  435.  
  436.         //Version 4.2 to 5.0 check
  437.         if ($this->checkSimpleBrowserUA('BlackBerry'$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  438.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  439.                 $found true;
  440.             else {
  441.                 return true;
  442.             }
  443.         }
  444.  
  445.         return $found;
  446.     }
  447.  
  448.     /**
  449.      * Determine if the browser is Chrome or not.
  450.      * @access protected
  451.      * @link http://www.google.com/chrome/
  452.      * @return boolean Returns true if the browser is Chrome, false otherwise.
  453.      */
  454.     protected function checkBrowserChrome()
  455.     {
  456.         return $this->checkSimpleBrowserUA('Chrome'$this->_agentself::BROWSER_CHROME);
  457.     }
  458.  
  459.     /**
  460.      * Determine if the browser is Firebird or not. Firebird was the name of Firefox from version 0.6 to 0.7.1.
  461.      * @access protected
  462.      * @return boolean Returns true if the browser is Firebird, false otherwise.
  463.      */
  464.     protected function checkBrowserFirebird()
  465.     {
  466.         return $this->checkSimpleBrowserUA('Firebird'$this->_agentself::BROWSER_FIREBIRD);
  467.     }
  468.  
  469.     /**
  470.      * Determine if the browser is Firefox or not.
  471.      * @access protected
  472.      * @link http://www.mozilla.org/en-US/firefox/new/
  473.      * @return boolean Returns true if the browser is Firefox, false otherwise.
  474.      */
  475.     protected function checkBrowserFirefox()
  476.     {
  477.         //Safari heavily matches with Firefox, ensure that Safari is filtered out...
  478.         if (preg_match('/.*Firefox[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches&&
  479.             stripos($this->_agent'Safari'=== false{
  480.             $this->setBrowser(self::BROWSER_FIREFOX);
  481.             $this->setVersion($matches[1]);
  482.             $this->setMobile(false);
  483.             $this->setRobot(false);
  484.  
  485.             return true;
  486.         }
  487.  
  488.         return false;
  489.     }
  490.  
  491.     /**
  492.      * Determine if the browser is Galeon or not. The browser was discontinued on September 27, 2008.
  493.      * @access protected
  494.      * @link http://en.wikipedia.org/wiki/Galeon
  495.      * @return boolean Returns true if the browser is Galeon, false otherwise.
  496.      */
  497.     protected function checkBrowserGaleon()
  498.     {
  499.         return $this->checkSimpleBrowserUA('Galeon'$this->_agentself::BROWSER_GALEON);
  500.     }
  501.  
  502.     /**
  503.      * Determine if the browser is the Googlebot crawler or not.
  504.      * @access protected
  505.      * @return boolean Returns true if the browser is Googlebot, false otherwise.
  506.      */
  507.     protected function checkBrowserGooglebot()
  508.     {
  509.         return $this->checkSimpleBrowserUA('Googlebot'$this->_agentself::BROWSER_GOOGLEBOTfalsetrue);
  510.     }
  511.  
  512.     /**
  513.      * Determine if the browser is iCab or not.
  514.      * @access protected
  515.      * @link http://www.icab.de/
  516.      * @return boolean Returns true if the browser is iCab, false otherwise.
  517.      */
  518.     protected function checkBrowserIcab()
  519.     {
  520.         //Some (early) iCab versions don't use the standard "iCab/1.0", they uses "iCab 1.0;" instead
  521.         return $this->checkSimpleBrowserUA('iCab'$this->_agentself::BROWSER_ICAB);
  522.     }
  523.  
  524.     /**
  525.      * Determine if the browser is GNU IceCat (formerly known as GNU IceWeasel) or not.
  526.      * @access protected
  527.      * @link http://www.gnu.org/software/gnuzilla/
  528.      * @return boolean Returns true if the browser is GNU IceCat, false otherwise.
  529.      */
  530.     protected function checkBrowserIceCat()
  531.     {
  532.         return $this->checkSimpleBrowserUA('IceCat'$this->_agentself::BROWSER_ICECAT);
  533.     }
  534.  
  535.     /**
  536.      * Determine if the browser is GNU IceWeasel (now know as GNU IceCat) or not.
  537.      * @access protected
  538.      * @see checkBrowserIceCat()
  539.      * @return boolean Returns true if the browser is GNU IceWeasel, false otherwise.
  540.      */
  541.     protected function checkBrowserIceWeasel()
  542.     {
  543.         return $this->checkSimpleBrowserUA('Iceweasel'$this->_agentself::BROWSER_ICEWEASEL);
  544.     }
  545.  
  546.     /**
  547.      * Determine if the browser is Internet Explorer or not.
  548.      * @access protected
  549.      * @link http://www.microsoft.com/ie/
  550.      * @link http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  551.      * @return boolean Returns true if the browser is Internet Explorer, false otherwise.
  552.      */
  553.     protected function checkBrowserInternetExplorer()
  554.     {
  555.         //Test for Internet Explorer Mobile (formerly Pocket Internet Explorer)
  556.         if ($this->checkSimpleBrowserUA(array('IEMobile''MSPIE')$this->_agentself::BROWSER_IE_MOBILEtrue)) {
  557.             return true;
  558.         }
  559.  
  560.         //Several browsers uses IE compatibility UAs filter these browsers out (but after testing for IE Mobile)
  561.         if (stripos($this->_agent'Opera'!== false ||
  562.             stripos($this->_agent'BlackBerry'!== false ||
  563.             stripos($this->_agent'Nokia'!== false{
  564.             return false;
  565.         }
  566.  
  567.         //Test for Internet Explorer 1
  568.         if ($this->checkSimpleBrowserUA('Microsoft Internet Explorer'$this->_agentself::BROWSER_IE)) {
  569.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  570.                 if (preg_match('/308|425|426|474|0b1/i'$this->_agent)) {
  571.                     $this->setVersion('1.5');
  572.                 else {
  573.                     $this->setVersion('1.0');
  574.                 }
  575.             }
  576.             return true;
  577.         }
  578.  
  579.         //Test for Internet Explorer 2+
  580.         if (stripos($this->_agent'MSIE'!== false || stripos($this->_agent'Trident'!== false{
  581.             $version '';
  582.  
  583.             if (stripos($this->_agent'Trident'!== false{
  584.                 //Test for Internet Explorer 11+ (check the rv: string)
  585.                 if (stripos($this->_agent'rv:'!== false{
  586.                     if ($this->checkSimpleBrowserUA('Trident'$this->_agentself::BROWSER_IEfalsefalse'rv:')) {
  587.                         return true;
  588.                     }
  589.                 else {
  590.                     //Test for Internet Explorer 8, 9 & 10 (check the Trident string)
  591.                     if (preg_match('/Trident\/([\d]+)/i'$this->_agent$foundVersion)) {
  592.                         //Trident started with version 4.0 on IE 8
  593.                         $verFromTrident $this->parseInt($foundVersion[1]4;
  594.                         if ($verFromTrident >= 8{
  595.                             $version $verFromTrident '.0';
  596.                         }
  597.                     }
  598.                 }
  599.  
  600.                 //If we have the IE version from Trident, we can check for the compatibility view mode
  601.                 if ($version != ''{
  602.                     $emulatedVer '';
  603.                     preg_match_all('/MSIE\s*([^\s;$]+)/i'$this->_agent$foundVersions);
  604.                     foreach ($foundVersions[1as $currVer{
  605.                         //Keep the lowest MSIE version for the emulated version (in compatibility view mode)
  606.                         if ($emulatedVer == '' || $this->compareVersions($emulatedVer$currVer== -1{
  607.                             $emulatedVer $currVer;
  608.                         }
  609.                     }
  610.                     //Set the compatibility view mode if $version != $emulatedVer
  611.                     if ($this->compareVersions($version$emulatedVer!= 0{
  612.                         $this->_compatibilityViewName = self::BROWSER_IE;
  613.                         $this->_compatibilityViewVer = $this->cleanVersion($emulatedVer);
  614.                     }
  615.                 }
  616.             }
  617.  
  618.             //Test for Internet Explorer 2-7 versions if needed
  619.             if ($version == ''{
  620.                 preg_match_all('/MSIE\s+([^\s;$]+)/i'$this->_agent$foundVersions);
  621.                 foreach ($foundVersions[1as $currVer{
  622.                     //Keep the highest MSIE version
  623.                     if ($version == '' || $this->compareVersions($version$currVer== 1{
  624.                         $version $currVer;
  625.                     }
  626.                 }
  627.             }
  628.  
  629.             $this->setBrowser(self::BROWSER_IE);
  630.             $this->setVersion($version);
  631.             $this->setMobile(false);
  632.             $this->setRobot(false);
  633.  
  634.             return true;
  635.         }
  636.  
  637.         return false;
  638.     }
  639.  
  640.     /**
  641.      * Determine if the browser is Konqueror or not.
  642.      * @access protected
  643.      * @link http://www.konqueror.org/
  644.      * @return boolean Returns true if the browser is Konqueror, false otherwise.
  645.      */
  646.     protected function checkBrowserKonqueror()
  647.     {
  648.         return $this->checkSimpleBrowserUA('Konqueror'$this->_agentself::BROWSER_KONQUEROR);
  649.     }
  650.  
  651.     /**
  652.      * Determine if the browser is Lynx or not. It is the oldest web browser currently in general use and development.
  653.      * It is a text-based only Web browser.
  654.      * @access protected
  655.      * @link http://en.wikipedia.org/wiki/Lynx
  656.      * @return boolean Returns true if the browser is Lynx, false otherwise.
  657.      */
  658.     protected function checkBrowserLynx()
  659.     {
  660.         return $this->checkSimpleBrowserUA('Lynx'$this->_agentself::BROWSER_LYNX);
  661.     }
  662.  
  663.     /**
  664.      * Determine if the browser is Mozilla or not.
  665.      * @access protected
  666.      * @return boolean Returns true if the browser is Mozilla, false otherwise.
  667.      */
  668.     protected function checkBrowserMozilla()
  669.     {
  670.         return $this->checkSimpleBrowserUA('Mozilla'$this->_agentself::BROWSER_MOZILLAfalsefalse'rv:');
  671.     }
  672.  
  673.     /**
  674.      * Determine if the browser is the MSNBot crawler or not. In October 2010 it was replaced by the Bingbot robot.
  675.      * @access protected
  676.      * @see checkBrowserBingbot()
  677.      * @return boolean Returns true if the browser is MSNBot, false otherwise.
  678.      */
  679.     protected function checkBrowserMsnBot()
  680.     {
  681.         return $this->checkSimpleBrowserUA('msnbot'$this->_agentself::BROWSER_MSNBOTfalsetrue);
  682.     }
  683.  
  684.     /**
  685.      * Determine if the browser is MSN TV (formerly WebTV) or not.
  686.      * @access protected
  687.      * @link http://en.wikipedia.org/wiki/MSN_TV
  688.      * @return boolean Returns true if the browser is WebTv, false otherwise.
  689.      */
  690.     protected function checkBrowserMsnTv()
  691.     {
  692.         return $this->checkSimpleBrowserUA('webtv'$this->_agentself::BROWSER_MSNTV);
  693.     }
  694.  
  695.     /**
  696.      * Determine if the browser is NetPositive or not. The browser is discontinued since November 2001.
  697.      * @access protected
  698.      * @link http://en.wikipedia.org/wiki/NetPositive
  699.      * @return boolean Returns true if the browser is NetPositive, false otherwise.
  700.      */
  701.     protected function checkBrowserNetPositive()
  702.     {
  703.         return $this->checkSimpleBrowserUA('NetPositive'$this->_agentself::BROWSER_NETPOSITIVE);
  704.     }
  705.  
  706.     /**
  707.      * Determine if the browser is Netscape or not. Official support for this browser ended on March 1st, 2008.
  708.      * @access protected
  709.      * @link http://en.wikipedia.org/wiki/Netscape
  710.      * @return boolean Returns true if the browser is Netscape, false otherwise.
  711.      */
  712.     protected function checkBrowserNetscape()
  713.     {
  714.         //BlackBerry & Nokia UAs can confilict with Netscape UAs
  715.         if (stripos($this->_agent'BlackBerry'!== false || stripos($this->_agent'Nokia'!== false{
  716.             return false;
  717.         }
  718.  
  719.         //Netscape v6 to v9 check
  720.         if ($this->checkSimpleBrowserUA(array('Netscape''Navigator''Netscape6')$this->_agentself::BROWSER_NETSCAPE)) {
  721.             return true;
  722.         }
  723.  
  724.         //Netscape v1-4 (v5 don't exists)
  725.         $found false;
  726.         if (stripos($this->_agent'Mozilla'!== false && stripos($this->_agent'rv:'=== false{
  727.             $version '';
  728.             $verParts explode('/'stristr($this->_agent'Mozilla'));
  729.             if (count($verParts1{
  730.                 $verParts explode(' '$verParts[1]);
  731.                 $verParts explode('.'$verParts[0]);
  732.  
  733.                 $majorVer $this->parseInt($verParts[0]);
  734.                 if ($majorVer && $majorVer 5{
  735.                     $version implode('.'$verParts);
  736.                     $found true;
  737.  
  738.                     if (strtolower(substr($version-4)) == '-sgi'{
  739.                         $version substr($version0-4);
  740.                     else if (strtolower(substr($version-4)) == 'gold'{
  741.                         $version substr($version0-4' Gold'//Doubles spaces (if any) will be normalized by setVersion()
  742.                     }
  743.                 }
  744.             }
  745.         }
  746.  
  747.         if ($found{
  748.             $this->setBrowser(self::BROWSER_NETSCAPE);
  749.             $this->setVersion($version);
  750.             $this->setMobile(false);
  751.             $this->setRobot(false);
  752.         }
  753.  
  754.         return $found;
  755.     }
  756.  
  757.     /**
  758.      * Determine if the browser is a Nokia browser or not.
  759.      * @access protected
  760.      * @link http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
  761.      * @return boolean Returns true if the browser is a Nokia browser, false otherwise.
  762.      */
  763.     protected function checkBrowserNokia()
  764.     {
  765.         if (stripos($this->_agent'Nokia5800'!== false || stripos($this->_agent'Nokia5530'!== false || stripos($this->_agent'Nokia5230'!== false{
  766.             $this->setBrowser(self::BROWSER_NOKIA);
  767.             $this->setVersion('7.0');
  768.             $this->setMobile(true);
  769.             $this->setRobot(false);
  770.  
  771.             return true;
  772.         }
  773.  
  774.         if ($this->checkSimpleBrowserUA(array('NokiaBrowser''BrowserNG''Series60''S60''S40OviBrowser')$this->_agentself::BROWSER_NOKIAtrue)) {
  775.             return true;
  776.         }
  777.  
  778.         return false;
  779.     }
  780.  
  781.     /**
  782.      * Determine if the browser is OmniWeb or not.
  783.      * @access protected
  784.      * @link http://www.omnigroup.com/products/omniweb/
  785.      * @return boolean Returns true if the browser is OmniWeb, false otherwise.
  786.      */
  787.     protected function checkBrowserOmniWeb()
  788.     {
  789.         if ($this->checkSimpleBrowserUA('OmniWeb'$this->_agentself::BROWSER_OMNIWEB)) {
  790.             //Some versions of OmniWeb prefix the version number with "v"
  791.             if ($this->getVersion(!= self::VERSION_UNKNOWN && strtolower(substr($this->getVersion()01)) == 'v'{
  792.                 $this->setVersion(substr($this->getVersion()1));
  793.             }
  794.             return true;
  795.         }
  796.  
  797.         return false;
  798.     }
  799.  
  800.     /**
  801.      * Determine if the browser is Opera or not.
  802.      * @access protected
  803.      * @link http://www.opera.com/
  804.      * @link http://www.opera.com/mini/
  805.      * @link http://www.opera.com/mobile/
  806.      * @link http://my.opera.com/community/openweb/idopera/
  807.      * @return boolean Returns true if the browser is Opera, false otherwise.
  808.      */
  809.     protected function checkBrowserOpera()
  810.     {
  811.         if ($this->checkBrowserUAWithVersion('Opera Mobi'$this->_agentself::BROWSER_OPERA_MOBILEtrue)) {
  812.             return true;
  813.         }
  814.  
  815.         if ($this->checkSimpleBrowserUA('Opera Mini'$this->_agentself::BROWSER_OPERA_MINItrue)) {
  816.             return true;
  817.         }
  818.  
  819.         $version '';
  820.         $found $this->checkBrowserUAWithVersion('Opera'$this->_agentself::BROWSER_OPERA);
  821.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  822.             $version $this->getVersion();
  823.         }
  824.  
  825.         if (!$found || $version == ''{
  826.             if ($this->checkSimpleBrowserUA('Opera'$this->_agentself::BROWSER_OPERA)) {
  827.                 return true;
  828.             }
  829.         }
  830.  
  831.         return $found;
  832.     }
  833.  
  834.     /**
  835.      * Determine if the browser is Phoenix or not. Phoenix was the name of Firefox from version 0.1 to 0.5.
  836.      * @access protected
  837.      * @return boolean Returns true if the browser is Phoenix, false otherwise.
  838.      */
  839.     protected function checkBrowserPhoenix()
  840.     {
  841.         return $this->checkSimpleBrowserUA('Phoenix'$this->_agentself::BROWSER_PHOENIX);
  842.     }
  843.  
  844.     /**
  845.      * Determine what is the browser used by the user.
  846.      * @access protected
  847.      */
  848.     protected function checkBrowsers()
  849.     {
  850.         //Changing the check order can break the class detection results!
  851.         return
  852.                /* Major browsers and browsers that need to be detected in a special order */
  853.                $this->checkBrowserMsnTv(||            /* MSN TV is based on IE so we must check for MSN TV before IE */
  854.                $this->checkBrowserInternetExplorer(||
  855.                $this->checkBrowserChrome(||           /* Chrome must be checked before Netscaoe and Mozilla to avoid conflicts */
  856.                $this->checkBrowserOpera(||            /* Opera be checked before Firefox and Netscape to avoid conflicts */
  857.                $this->checkBrowserOmniWeb(||          /* OmniWeb must be checked before Safari (on which it's based on) and Netscape (since it have Mozilla UAs) */
  858.                $this->checkBrowserIcab(||             /* Check iCab before Netscape since iCab have Mozilla UAs */
  859.                $this->checkBrowserNetPositive(||      /* Check NetPositive before Netscape since NetPositive have Mozilla UAs */
  860.                $this->checkBrowserNetscape(||         /* Must be checked before Firefox since Netscape 8-9 are based on Firefox */
  861.                $this->checkBrowserIceCat(||           /* Check IceCat and IceWeasel before Firefox since they are GNU builds of Firefox */
  862.                $this->checkBrowserIceWeasel(||
  863.                $this->checkBrowserGaleon(||           /* Galeon is based on Firefox and needs to be tested before Firefox is tested */
  864.                $this->checkBrowserFirefox(||
  865.                /* Current browsers that don't need to be tetected in any special order */
  866.                $this->checkBrowserKonqueror(||
  867.                $this->checkBrowserLynx(||
  868.                $this->checkBrowserAmaya(||
  869.                /* Mobile */
  870.                $this->checkBrowserAndroid(||
  871.                $this->checkBrowserBlackBerry(||
  872.                $this->checkBrowserNokia(||
  873.                /* Bots */
  874.                $this->checkBrowserGooglebot(||
  875.                $this->checkBrowserBingbot(||
  876.                $this->checkBrowserMsnBot(||
  877.                $this->checkBrowserSlurp(||
  878.                $this->checkBrowserYahooMultimedia(||
  879.                $this->checkBrowserW3CValidator(||
  880.                /* WebKit base check (after most other checks) */
  881.                $this->checkBrowserSafari(||
  882.                /* Deprecated browsers that don't need to be tetected in any special order */
  883.                $this->checkBrowserFirebird(||
  884.                $this->checkBrowserPhoenix(||
  885.                /* Mozilla is such an open standard that it must be checked last */
  886.                $this->checkBrowserMozilla();
  887.     }
  888.  
  889.     /**
  890.      * Determine if the browser is Safari or not.
  891.      * @access protected
  892.      * @link http://www.apple.com/safari/
  893.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  894.      * @link http://en.wikipedia.org/wiki/Safari_version_history#Release_history
  895.      * @return boolean Returns true if the browser is Safari, false otherwise.
  896.      */
  897.     protected function checkBrowserSafari()
  898.     {
  899.         $version '';
  900.  
  901.         //Check for current versions of Safari
  902.         $found $this->checkBrowserUAWithVersion(array('Safari''AppleWebKit')$this->_agentself::BROWSER_SAFARI);
  903.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  904.             $version $this->getVersion();
  905.         }
  906.  
  907.         //Safari 1-2 didn't had a "Version" string in the UA, only a WebKit build and/or Safari build, extract version from these...
  908.         if (!$found || $version == ''{
  909.             if (preg_match('/.*Safari[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  910.                 $version $this->safariBuildToSafariVer($matches[1]);
  911.                 $found true;
  912.             }
  913.         }
  914.         if (!$found || $version == ''{
  915.             if (preg_match('/.*AppleWebKit[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  916.                 $version $this->webKitBuildToSafariVer($matches[1]);
  917.                 $found true;
  918.             }
  919.         }
  920.  
  921.         if ($found{
  922.             $this->setBrowser(self::BROWSER_SAFARI);
  923.             $this->setVersion($version);
  924.             $this->setMobile(false);
  925.             $this->setRobot(false);
  926.         }
  927.  
  928.         return $found;
  929.     }
  930.  
  931.     /**
  932.      * Determine if the browser is the Yahoo! Slurp crawler or not.
  933.      * @access protected
  934.      * @return boolean Returns true if the browser is Yahoo! Slurp, false otherwise.
  935.      */
  936.     protected function checkBrowserSlurp()
  937.     {
  938.         return $this->checkSimpleBrowserUA('Yahoo! Slurp'$this->_agentself::BROWSER_SLURPfalsetrue);
  939.     }
  940.  
  941.     /**
  942.      * Test the user agent for a specific browser that use a "Version" string (like Safari and Opera). The user agent
  943.      * should look like: "Version/1.0 Browser name/123.456" or "Browser name/123.456 Version/1.0".
  944.      * @access protected
  945.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  946.      *  agent.
  947.      * @param string $userAgent The user agent string to work with.
  948.      * @param string $browserName The litteral browser name. Always use a class constant!
  949.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  950.      * @param boolean $isRobot Determines if the browser is a robot or not.
  951.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  952.      */
  953.     protected function checkBrowserUAWithVersion($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false)
  954.     {
  955.         if (!is_array($uaNameToLookFor)) {
  956.             $uaNameToLookFor array($uaNameToLookFor);
  957.         }
  958.  
  959.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  960.             if (stripos($userAgent$currUANameToLookFor!== false{
  961.                 $version '';
  962.                 $verParts explode('/'stristr($this->_agent'Version'));
  963.                 if (count($verParts1{
  964.                     $verParts explode(' '$verParts[1]);
  965.                     $version $verParts[0];
  966.                 }
  967.  
  968.                 $this->setBrowser($browserName);
  969.                 $this->setVersion($version);
  970.  
  971.                 $this->setMobile($isMobile);
  972.                 $this->setRobot($isRobot);
  973.  
  974.                 return true;
  975.             }
  976.         }
  977.  
  978.         return false;
  979.     }
  980.  
  981.     /**
  982.      * Determine if the browser is the W3C Validator or not.
  983.      * @access protected
  984.      * @link http://validator.w3.org/
  985.      * @return boolean Returns true if the browser is the W3C Validator, false otherwise.
  986.      */
  987.     protected function checkBrowserW3CValidator()
  988.     {
  989.         //Since the W3C validates pages with different robots we will prefix our versions with the part validated on the page...
  990.  
  991.         //W3C Link Checker (prefixed with "Link-")
  992.         if ($this->checkSimpleBrowserUA('W3C-checklink'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  993.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  994.                 $this->setVersion('Link-' $this->getVersion());
  995.             }
  996.             return true;
  997.         }
  998.  
  999.         //W3C CSS Validation Service (prefixed with "CSS-")
  1000.         if ($this->checkSimpleBrowserUA('Jigsaw'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1001.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1002.                 $this->setVersion('CSS-' $this->getVersion());
  1003.             }
  1004.             return true;
  1005.         }
  1006.  
  1007.         //W3C mobileOK Checker (prefixed with "mobileOK-")
  1008.         if ($this->checkSimpleBrowserUA('W3C-mobileOK'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1009.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1010.                 $this->setVersion('mobileOK-' $this->getVersion());
  1011.             }
  1012.             return true;
  1013.         }
  1014.  
  1015.         //W3C Markup Validation Service (no prefix)
  1016.         return $this->checkSimpleBrowserUA('W3C_Validator'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue);
  1017.     }
  1018.  
  1019.     /**
  1020.      * Determine if the browser is the Yahoo! multimedia crawler or not.
  1021.      * @access protected
  1022.      * @return boolean Returns true if the browser is the Yahoo! multimedia crawler, false otherwise.
  1023.      */
  1024.     protected function checkBrowserYahooMultimedia()
  1025.     {
  1026.         return $this->checkSimpleBrowserUA('Yahoo-MMCrawler'$this->_agentself::BROWSER_YAHOO_MMfalsetrue);
  1027.     }
  1028.  
  1029.     /**
  1030.      * Determine if the user is using an AOL "optimized" browser or not.
  1031.      * @access protected
  1032.      * @return boolean Returns true if the browser is AOL optimized, false otherwise.
  1033.      */
  1034.     protected function checkForAol()
  1035.     {
  1036.         //AOL UAs don't use the "AOL/1.0" format, they uses "AOL 1.0; AOLBuild 100.00;"
  1037.         if (stripos($this->_agent'AOL '!== false{
  1038.             $version '';
  1039.             $verParts explode('AOL 'stristr($this->_agent'AOL '));
  1040.             if (count($verParts1{
  1041.                 $verParts explode(' '$verParts[1]);
  1042.                 $version $verParts[0];
  1043.             }
  1044.  
  1045.             $this->setAol(true);
  1046.             $this->setAolVersion($version);
  1047.  
  1048.             return true;
  1049.         else {
  1050.             $this->setAol(false);
  1051.             $this->setAolVersion('');
  1052.  
  1053.             return false;
  1054.         }
  1055.     }
  1056.  
  1057.     /**
  1058.      * Determine the user's platform.
  1059.      * @access protected
  1060.      */
  1061.     protected function checkPlatform()
  1062.     {
  1063.         /* Desktop platforms */
  1064.         if (stripos($this->_agent'Windows Phone'!== false ||      /* Check Windows Phone (formerly Windows Mobile) before Windows */
  1065.             stripos($this->_agent'IEMobile'!== false{
  1066.             $this->_platform = self::PLATFORM_WINDOWS_PHONE;
  1067.             $this->setMobile(true);
  1068.         else if (stripos($this->_agent'Windows CE'!== false{  /* Check Windows CE before Windows */
  1069.             $this->_platform = self::PLATFORM_WINDOWS_CE;
  1070.             $this->setMobile(true);
  1071.         else if (stripos($this->_agent'Windows'!== false{
  1072.             $this->_platform = self::PLATFORM_WINDOWS;
  1073.         else if (stripos($this->_agent'iPhone'!== false{      /* Check iPad/iPod/iPhone before Macintosh */
  1074.             $this->_platform = self::PLATFORM_IPHONE;
  1075.             $this->setMobile(true);
  1076.         else if (stripos($this->_agent'iPad'!== false{
  1077.             $this->_platform = self::PLATFORM_IPAD;
  1078.             $this->setMobile(true);
  1079.         else if (stripos($this->_agent'iPod'!== false{
  1080.             $this->_platform = self::PLATFORM_IPOD;
  1081.             $this->setMobile(true);
  1082.         else if (stripos($this->_agent'Macintosh'!== false{
  1083.             $this->_platform = self::PLATFORM_MACINTOSH;
  1084.         else if (stripos($this->_agent'Linux'!== false{
  1085.             $this->_platform = self::PLATFORM_LINUX;
  1086.         else if (stripos($this->_agent'FreeBSD'!== false{
  1087.             $this->_platform = self::PLATFORM_FREEBSD;
  1088.         else if (stripos($this->_agent'OpenBSD'!== false{
  1089.             $this->_platform = self::PLATFORM_OPENBSD;
  1090.         else if (stripos($this->_agent'NetBSD'!== false{
  1091.             $this->_platform = self::PLATFORM_NETBSD;
  1092.  
  1093.         /* Mobile platforms */
  1094.         else if (stripos($this->_agent'Android'!== false{
  1095.             $this->_platform = self::PLATFORM_ANDROID;
  1096.             $this->setMobile(true);
  1097.         else if (stripos($this->_agent'Symbian'!== false{
  1098.             $this->_platform = self::PLATFORM_SYMBIAN;
  1099.             $this->setMobile(true);
  1100.         else if (stripos($this->_agent'BlackBerry'!== false ||
  1101.                    stripos($this->_agent'BB10'!== false ||
  1102.                    stripos($this->_agent'RIM Tablet OS'!== false{
  1103.             $this->_platform = self::PLATFORM_BLACKBERRY;
  1104.             $this->setMobile(true);
  1105.         else if (stripos($this->_agent'Nokia'!== false{
  1106.             $this->_platform = self::PLATFORM_NOKIA;
  1107.             $this->setMobile(true);
  1108.  
  1109.         /* Discontinued */
  1110.         else if (stripos($this->_agent'OpenSolaris'!== false{
  1111.             $this->_platform = self::PLATFORM_OPENSOLARIS;
  1112.         else if (stripos($this->_agent'OS/2'!== false{
  1113.             $this->_platform = self::PLATFORM_OS2;
  1114.         else if (stripos($this->_agent'BeOS'!== false{
  1115.             $this->_platform = self::PLATFORM_BEOS;
  1116.         else if (stripos($this->_agent'SunOS'!== false{
  1117.             $this->_platform = self::PLATFORM_SUNOS;
  1118.  
  1119.         /* Generic */
  1120.         else if (stripos($this->_agent'Win'!== false{
  1121.             $this->_platform = self::PLATFORM_WINDOWS;
  1122.         else if (stripos($this->_agent'Mac'!== false{
  1123.             $this->_platform = self::PLATFORM_MACINTOSH;
  1124.         }
  1125.     }
  1126.  
  1127.     /**
  1128.      * Test the user agent for a specific browser where the browser name is immediately followed by the version number.
  1129.      * The user agent should look like: "Browser name/1.0" or "Browser 1.0;".
  1130.      * @access protected
  1131.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  1132.      *  agent.
  1133.      * @param string $userAgent The user agent string to work with.
  1134.      * @param string $browserName The litteral browser name. Always use a class constant!
  1135.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  1136.      * @param boolean $isRobot Determines if the browser is a robot or not.
  1137.      * @param string $separator The separator string used to split the browser name and the version number in the user
  1138.      *  agent.
  1139.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  1140.      */
  1141.     protected function checkSimpleBrowserUA($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false$separator '/')
  1142.     {
  1143.         if (!is_array($uaNameToLookFor)) {
  1144.             $uaNameToLookFor array($uaNameToLookFor);
  1145.         }
  1146.  
  1147.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  1148.             if (stripos($userAgent$currUANameToLookFor!== false{
  1149.                 //Many browsers don't use the standard "Browser/1.0" format, they uses "Browser 1.0;" instead
  1150.                 if (stripos($userAgent$currUANameToLookFor $separator=== false{
  1151.                     $userAgent str_ireplace($currUANameToLookFor ' '$currUANameToLookFor $separator$this->_agent);
  1152.                 }
  1153.  
  1154.                 $version '';
  1155.                 $verParts explode($separatorstristr($userAgent$currUANameToLookFor));
  1156.                 if (count($verParts1{
  1157.                     $verParts explode(' '$verParts[1]);
  1158.                     $version $verParts[0];
  1159.                 }
  1160.  
  1161.                 $this->setBrowser($browserName);
  1162.                 $this->setVersion($version);
  1163.  
  1164.                 $this->setMobile($isMobile);
  1165.                 $this->setRobot($isRobot);
  1166.  
  1167.                 return true;
  1168.             }
  1169.         }
  1170.  
  1171.         return false;
  1172.     }
  1173.  
  1174.     /**
  1175.      * Detect the user environment from the details in the user agent string.
  1176.      * @access protected
  1177.      */
  1178.     protected function detect()
  1179.     {
  1180.         $this->checkBrowsers();
  1181.         $this->checkPlatform()//Check the platform after the browser since some platforms can change the mobile value
  1182.         $this->checkForAol();
  1183.     }
  1184.  
  1185.     /**
  1186.      * Clean a version string from unwanted characters.
  1187.      * @access protected
  1188.      * @param string $version The version string to clean.
  1189.      * @return string Returns the cleaned version number string.
  1190.      */
  1191.     protected function cleanVersion($version)
  1192.     {
  1193.         //Clear anything that is in parentheses (and the parentheses themselves) - will clear started but unclosed ones too
  1194.         $cleanVer preg_replace('/\([^)]+\)?/'''$version);
  1195.         //Replace with a space any character which is NOT an alphanumeric, dot (.), hyphen (-), underscore (_) or space
  1196.         $cleanVer preg_replace('/[^0-9.a-zA-Z_ -]/'' '$cleanVer);
  1197.         //Remove trailing and leading spaces
  1198.         $cleanVer trim($cleanVer);
  1199.         //Remove double spaces if any
  1200.         while (strpos($cleanVer'  '!== false{
  1201.             $cleanVer str_replace('  '' '$cleanVer);
  1202.         }
  1203.  
  1204.         return $cleanVer;
  1205.     }
  1206.  
  1207.     /**
  1208.      * Get the integer value of a string variable.
  1209.      * @access protected
  1210.      * @param string $intStr The scalar value being converted to an integer.
  1211.      * @return int The integer value of $intStr on success, or 0 on failure.
  1212.      */
  1213.     protected function parseInt($intStr)
  1214.     {
  1215.         return intval($intStr10);
  1216.     }
  1217.  
  1218.     /**
  1219.      * Reset all the properties of the class.
  1220.      * @access protected
  1221.      */
  1222.     protected function reset()
  1223.     {
  1224.         $this->_agent = '';
  1225.         $this->_aolVersion = '';
  1226.         $this->_browserName = self::BROWSER_UNKNOWN;
  1227.         $this->_compatibilityViewName = '';
  1228.         $this->_compatibilityViewVer = '';
  1229.         $this->_isAol = false;
  1230.         $this->_isMobile = false;
  1231.         $this->_isRobot = false;
  1232.         $this->_platform = self::PLATFORM_UNKNOWN;
  1233.         $this->_version = self::VERSION_UNKNOWN;
  1234.     }
  1235.  
  1236.     /**
  1237.      * Convert a Safari build number to a Safari version number.
  1238.      * @access protected
  1239.      * @param string $version A string representing the version number.
  1240.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1241.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1242.      *  returned.
  1243.      */
  1244.     protected function safariBuildToSafariVer($version)
  1245.     {
  1246.         $verParts explode('.'$version);
  1247.  
  1248.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1249.         while (count($verParts3{
  1250.             $verParts[0;
  1251.         }
  1252.         foreach ($verParts as $i => $currPart{
  1253.             $verParts[$i$this->parseInt($currPart);
  1254.         }
  1255.  
  1256.         switch ($verParts[0]{
  1257.             case 419$result '2.0.4';
  1258.             break;
  1259.             case 417$result '2.0.3';
  1260.             break;
  1261.             case 416$result '2.0.2';
  1262.             break;
  1263.  
  1264.             case 412if ($verParts[1>= 5{
  1265.                           $result '2.0.1';
  1266.                       else {
  1267.                           $result '2.0';
  1268.                       }
  1269.             break;
  1270.  
  1271.             case 312if ($verParts[1>= 5{
  1272.                          $result '1.3.2';
  1273.                      else if ($verParts[1>= 3{
  1274.                          $result '1.3.1';
  1275.                      else {
  1276.                          $result '1.3';
  1277.                      }
  1278.             break;
  1279.  
  1280.             case 125if ($verParts[1>= 11{
  1281.                          $result '1.2.4';
  1282.                      else if ($verParts[1>= 9{
  1283.                          $result '1.2.3';
  1284.                      else if ($verParts[1>= 7{
  1285.                          $result '1.2.2';
  1286.                      else {
  1287.                          $result '1.2';
  1288.                      }
  1289.             break;
  1290.  
  1291.             case 100if ($verParts[1>= 1{
  1292.                           $result '1.1.1';
  1293.                       else {
  1294.                           $result '1.1';
  1295.                       }
  1296.             break;
  1297.  
  1298.             case 85if ($verParts[1>= 8{
  1299.                          $result '1.0.3';
  1300.                      else if ($verParts[1>= 7{
  1301.                          $result '1.0.2';
  1302.                      else {
  1303.                          $result '1.0';
  1304.                      }
  1305.             break;
  1306.  
  1307.             case 73$result '0.9';
  1308.             break;
  1309.             case 51$result '0.8.1';
  1310.             break;
  1311.             case 48$result '0.8';
  1312.             break;
  1313.  
  1314.             default$result '';
  1315.         }
  1316.  
  1317.         return $result;
  1318.     }
  1319.  
  1320.     /**
  1321.      * Set the browser to be from AOL or not.
  1322.      * @access protected
  1323.      * @param boolean $isAol Value that tells if the browser is AOL or not.
  1324.      */
  1325.     protected function setAol($isAol)
  1326.     {
  1327.         $this->_isAol = $isAol == true;
  1328.     }
  1329.  
  1330.     /**
  1331.      * Set the version of AOL.
  1332.      * @access protected
  1333.      * @param string $version The version of AOL (will be cleaned).
  1334.      */
  1335.     protected function setAolVersion($version)
  1336.     {
  1337.         $cleanVer $this->cleanVersion($version);
  1338.  
  1339.         $this->_aolVersion = $cleanVer;
  1340.     }
  1341.  
  1342.     /**
  1343.      * Set the name of the browser.
  1344.      * @access protected
  1345.      * @param string $browserName The name of the browser.
  1346.      */
  1347.     protected function setBrowser($browserName)
  1348.     {
  1349.         return $this->_browserName = $browserName;
  1350.     }
  1351.  
  1352.     /**
  1353.      * Set the browser to be from a mobile device or not.
  1354.      * @access protected
  1355.      * @param boolean $isMobile Value that tells if the browser is on a mobile device or not.
  1356.      */
  1357.     protected function setMobile($isMobile true)
  1358.     {
  1359.         $this->_isMobile = $isMobile == true;
  1360.     }
  1361.  
  1362.     /**
  1363.      * Set the platform on which the browser is on.
  1364.      * @access protected
  1365.      * @param string $platform The name of the platform.
  1366.      */
  1367.     protected function setPlatform($platform)
  1368.     {
  1369.         return $this->_platform = $platform;
  1370.     }
  1371.  
  1372.     /**
  1373.      * Set the browser to be a robot (crawler) or not.
  1374.      * @access protected
  1375.      * @param boolean $isRobot Value that tells if the browser is a robot or not.
  1376.      */
  1377.     protected function setRobot($isRobot true)
  1378.     {
  1379.         $this->_isRobot = $isRobot == true;
  1380.     }
  1381.  
  1382.     /**
  1383.      * Set the version of the browser.
  1384.      * @access protected
  1385.      * @param string $version The version of the browser.
  1386.      */
  1387.     protected function setVersion($version)
  1388.     {
  1389.         $cleanVer $this->cleanVersion($version);
  1390.  
  1391.         if ($cleanVer == ''{
  1392.             $this->_version = self::VERSION_UNKNOWN;
  1393.         else {
  1394.             $this->_version = $cleanVer;
  1395.         }
  1396.     }
  1397.  
  1398.     /**
  1399.      * Convert a WebKit build number to a Safari version number.
  1400.      * @access protected
  1401.      * @param string $version A string representing the version number.
  1402.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1403.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1404.      *  returned.
  1405.      */
  1406.     protected function webKitBuildToSafariVer($version)
  1407.     {
  1408.         $verParts explode('.'$version);
  1409.  
  1410.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1411.         while (count($verParts3{
  1412.             $verParts[0;
  1413.         }
  1414.         foreach ($verParts as $i => $currPart{
  1415.             $verParts[$i$this->parseInt($currPart);
  1416.         }
  1417.  
  1418.         switch ($verParts[0]{
  1419.             case 419$result '2.0.4';
  1420.             break;
  1421.  
  1422.             case 418if ($verParts[1>= 8{
  1423.                           $result '2.0.4';
  1424.                       else {
  1425.                           $result '2.0.3';
  1426.                       }
  1427.             break;
  1428.  
  1429.             case 417$result '2.0.3';
  1430.             break;
  1431.  
  1432.             case 416$result '2.0.2';
  1433.             break;
  1434.  
  1435.             case 412if ($verParts[1>= 7{
  1436.                           $result '2.0.1';
  1437.                       else {
  1438.                           $result '2.0';
  1439.                       }
  1440.             break;
  1441.  
  1442.             case 312if ($verParts[1>= 8{
  1443.                           $result '1.3.2';
  1444.                       else if ($verParts[1>= 5{
  1445.                           $result '1.3.1';
  1446.                       else {
  1447.                           $result '1.3';
  1448.                       }
  1449.             break;
  1450.  
  1451.             case 125if ($this->compareVersions('5.4'$verParts[1'.' $verParts[2]=== 1{
  1452.                           $result '1.2.4'//125.5.5+
  1453.                       else if ($verParts[1>= 4{
  1454.                           $result '1.2.3';
  1455.                       else if ($verParts[1>= 2{
  1456.                           $result '1.2.2';
  1457.                       else {
  1458.                           $result '1.2';
  1459.                       }
  1460.             break;
  1461.  
  1462.                       //WebKit 100 can be either Safari 1.1 (Safari build 100) or 1.1.1 (Safari build 100.1)
  1463.                       //for this reason, check the Safari build before the WebKit build.
  1464.             case 100$result '1.1.1';
  1465.             break;
  1466.  
  1467.             case 85if ($verParts[1>= 8{
  1468.                          $result '1.0.3';
  1469.                      else if ($verParts[1>= 7{
  1470.                          //WebKit 85.7 can be either Safari 1.0 (Safari build 85.5) or 1.0.2 (Safari build 85.7)
  1471.                          //for this reason, check the Safari build before the WebKit build.
  1472.                          $result '1.0.2';
  1473.                      else {
  1474.                          $result '1.0';
  1475.                      }
  1476.             break;
  1477.  
  1478.             case 73$result '0.9';
  1479.             break;
  1480.             case 51$result '0.8.1';
  1481.             break;
  1482.             case 48$result '0.8';
  1483.             break;
  1484.  
  1485.             default$result '';
  1486.         }
  1487.  
  1488.         return $result;
  1489.     }
  1490. }
  1491.  
  1492. ?>

Documentation generated on Thu, 05 Jun 2014 13:32:52 -0400 by phpDocumentor 1.4.3