Browser_Detection
[ class tree: Browser_Detection ] [ index: Browser_Detection ] [ 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 Browser_Detection
  16.  * @version 2.4.0
  17.  * @last-modified August 2, 2016
  18.  * @author Alexandre Valiquette
  19.  * @copyright Copyright (c) 2016, 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->getName() == BrowserDetection::BROWSER_FIREFOX &&
  32.  *     $browser->compareVersions($browser->getVersion(), '5.0') >= 0) {
  33.  *     echo 'You are using FireFox version 5 or greater.';
  34.  * }
  35.  *
  36.  * The class is an updated version of Chris Schuld's Browser class version 1.9 which is unmaintained since August 20th,
  37.  * 2010. Chris' class was based on the original work from Gary White.
  38.  *
  39.  * Updates:
  40.  *
  41.  * 2016-08-02: Version 2.4.0
  42.  *  + Platform version and platform version name are now supported for Android.
  43.  *  + Added support for the Samsung Internet browser.
  44.  *  + Added support for the Vivaldi browser.
  45.  *  + Better support for legacy Windows versions.
  46.  *
  47.  * 2016-02-11: Version 2.3.0
  48.  *  + WARNING! Breaking change: public method getBrowser() is renamed to getName().
  49.  *  + WARNING! Breaking change: changed the compareVersions() return values to be more in line with other libraries.
  50.  *  + You can now get the exact platform version (name or version numbers) on which the browser is run on with
  51.  *    getPlatformVersion(). Only working with Windows operating systems at the moment.
  52.  *  + You can now determine if the browser is executed from a 64-bit platform with is64bitPlatform().
  53.  *  + Better detection of mobile platform for Googlebot.
  54.  *
  55.  * 2016-01-04: Version 2.2.0
  56.  *  + Added support for Microsoft Edge.
  57.  *
  58.  * 2014-12-30: Version 2.1.2
  59.  *  + Better detection of Opera.
  60.  *
  61.  * 2014-07-11: Version 2.1.1
  62.  *  + Better detection of mobile devices and platforms.
  63.  *
  64.  * 2014-06-04: Version 2.1.0
  65.  *  + Added support for IE 11+.
  66.  *
  67.  * 2013-05-27: Version 2.0.0 which is (almost) a complete rewrite based on Chris Schuld's Browser class version 1.9 plus
  68.  * changes below.
  69.  *  + Added support for Opera Mobile
  70.  *  + Added support for the Windows Phone (formerly Windows Mobile) platform
  71.  *  + Added support for BlackBerry Tablet OS and BlackBerry 10
  72.  *  + Added support for the Symbian platform
  73.  *  + Added support for Bingbot
  74.  *  + Added support for the Yahoo! Multimedia crawler
  75.  *  + Removed iPhone/iPad/iPod browsers since there are not browsers but platforms - test them with getPlatform()
  76.  *  + Removed support for Shiretoko (Firefox 3.5 alpha/beta) and MSN Browser
  77.  *  + Merged Nokia and Nokia S60
  78.  *  + Updated some deprecated browser names
  79.  *  + Many public methods are now protected
  80.  *  + Documentation updated
  81.  *
  82.  * 2010-07-04:
  83.  *  + Added detection of IE compatibility view - test with getIECompatibilityView()
  84.  *  + Added support for all (deprecated) Netscape versions
  85.  *  + Added support for Safari < 3.0
  86.  *  + Better Firefox version parsing
  87.  *  + Better Opera version parsing
  88.  *  + Better Mozilla detection
  89.  *
  90.  * @package Browser_Detection
  91.  * @version 2.4.0
  92.  * @last-modified August 2, 2016
  93.  * @author Alexandre Valiquette, Chris Schuld, Gary White
  94.  * @copyright Copyright (c) 2016, Wolfcast
  95.  * @license http://www.gnu.org/licenses/lgpl.html
  96.  * @link http://wolfcast.com/
  97.  * @link http://wolfcast.com/open-source/browser-detection/tutorial.php
  98.  * @link http://chrisschuld.com/
  99.  * @link http://www.apptools.com/phptools/browser/
  100.  */
  101. {
  102.  
  103.     /**#@+
  104.      * Constant for the name of the Web browser.
  105.      */
  106.     const BROWSER_AMAYA 'Amaya';
  107.     const BROWSER_ANDROID 'Android';
  108.     const BROWSER_BINGBOT 'Bingbot';
  109.     const BROWSER_BLACKBERRY 'BlackBerry';
  110.     const BROWSER_CHROME 'Chrome';
  111.     const BROWSER_EDGE 'Edge';
  112.     const BROWSER_FIREBIRD 'Firebird';
  113.     const BROWSER_FIREFOX 'Firefox';
  114.     const BROWSER_GALEON 'Galeon';
  115.     const BROWSER_GOOGLEBOT 'Googlebot';
  116.     const BROWSER_ICAB 'iCab';
  117.     const BROWSER_ICECAT 'GNU IceCat';
  118.     const BROWSER_ICEWEASEL 'GNU IceWeasel';
  119.     const BROWSER_IE 'Internet Explorer';
  120.     const BROWSER_IE_MOBILE 'Internet Explorer Mobile';
  121.     const BROWSER_KONQUEROR 'Konqueror';
  122.     const BROWSER_LYNX 'Lynx';
  123.     const BROWSER_MOZILLA 'Mozilla';
  124.     const BROWSER_MSNBOT 'MSNBot';
  125.     const BROWSER_MSNTV 'MSN TV';
  126.     const BROWSER_NETPOSITIVE 'NetPositive';
  127.     const BROWSER_NETSCAPE 'Netscape';
  128.     const BROWSER_NOKIA 'Nokia Browser';
  129.     const BROWSER_OMNIWEB 'OmniWeb';
  130.     const BROWSER_OPERA 'Opera';
  131.     const BROWSER_OPERA_MINI 'Opera Mini';
  132.     const BROWSER_OPERA_MOBILE 'Opera Mobile';
  133.     const BROWSER_PHOENIX 'Phoenix';
  134.     const BROWSER_SAFARI 'Safari';
  135.     const BROWSER_SAMSUNG 'Samsung Internet';
  136.     const BROWSER_SLURP 'Yahoo! Slurp';
  137.     const BROWSER_TABLET_OS 'BlackBerry Tablet OS';
  138.     const BROWSER_UNKNOWN 'unknown';
  139.     const BROWSER_VIVALDI 'Vivaldi';
  140.     const BROWSER_W3CVALIDATOR 'W3C Validator';
  141.     const BROWSER_YAHOO_MM 'Yahoo! Multimedia';
  142.     /**#@-*/
  143.  
  144.     /**#@+
  145.      * Constant for the name of the platform of the Web browser.
  146.      */
  147.     const PLATFORM_ANDROID 'Android';
  148.     const PLATFORM_BEOS 'BeOS';
  149.     const PLATFORM_BLACKBERRY 'BlackBerry';
  150.     const PLATFORM_FREEBSD 'FreeBSD';
  151.     const PLATFORM_IPAD 'iPad';
  152.     const PLATFORM_IPHONE 'iPhone';
  153.     const PLATFORM_IPOD 'iPod';
  154.     const PLATFORM_LINUX 'Linux';
  155.     const PLATFORM_MACINTOSH 'Macintosh';
  156.     const PLATFORM_NETBSD 'NetBSD';
  157.     const PLATFORM_NOKIA 'Nokia';
  158.     const PLATFORM_OPENBSD 'OpenBSD';
  159.     const PLATFORM_OPENSOLARIS 'OpenSolaris';
  160.     const PLATFORM_OS2 'OS/2';
  161.     const PLATFORM_SUNOS 'SunOS';
  162.     const PLATFORM_SYMBIAN 'Symbian';
  163.     const PLATFORM_UNKNOWN 'unknown';
  164.     const PLATFORM_VERSION_UNKNOWN 'unknown';
  165.     const PLATFORM_WINDOWS 'Windows';
  166.     const PLATFORM_WINDOWS_CE 'Windows CE';
  167.     const PLATFORM_WINDOWS_PHONE 'Windows Phone';
  168.     /**#@-*/
  169.  
  170.     /**
  171.      * Version unknown constant.
  172.      */
  173.     const VERSION_UNKNOWN 'unknown';
  174.  
  175.  
  176.     /**
  177.      * @var string 
  178.      * @access private
  179.      */
  180.     private $_agent = '';
  181.  
  182.     /**
  183.      * @var string 
  184.      * @access private
  185.      */
  186.     private $_aolVersion = '';
  187.  
  188.     /**
  189.      * @var string 
  190.      * @access private
  191.      */
  192.     private $_browserName = '';
  193.  
  194.     /**
  195.      * @var string 
  196.      * @access private
  197.      */
  198.     private $_compatibilityViewName = '';
  199.  
  200.     /**
  201.      * @var string 
  202.      * @access private
  203.      */
  204.     private $_compatibilityViewVer = '';
  205.  
  206.     /**
  207.      * @var boolean 
  208.      * @access private
  209.      */
  210.     private $_is64bit = false;
  211.  
  212.     /**
  213.      * @var boolean 
  214.      * @access private
  215.      */
  216.     private $_isAol = false;
  217.  
  218.     /**
  219.      * @var boolean 
  220.      * @access private
  221.      */
  222.     private $_isMobile = false;
  223.  
  224.     /**
  225.      * @var boolean 
  226.      * @access private
  227.      */
  228.     private $_isRobot = false;
  229.  
  230.     /**
  231.      * @var string 
  232.      * @access private
  233.      */
  234.     private $_platform = '';
  235.  
  236.     /**
  237.      * @var string 
  238.      * @access private
  239.      */
  240.     private $_platformVersion = '';
  241.  
  242.     /**
  243.      * @var string 
  244.      * @access private
  245.      */
  246.     private $_version = '';
  247.  
  248.  
  249.     //--- MAGIC METHODS ------------------------------------------------------------------------------------------------
  250.  
  251.  
  252.     /**
  253.      * BrowserDetection class constructor.
  254.      * @param string $useragent The user agent to work with. Leave empty for the current user agent (contained in
  255.      *  $_SERVER['HTTP_USER_AGENT']).
  256.      */
  257.     public function __construct($useragent '')
  258.     {
  259.         $this->setUserAgent($useragent);
  260.     }
  261.  
  262.     /**
  263.      * Determine how the class will react when it is treated like a string.
  264.      * @return string Returns an HTML formatted string with a summary of the browser informations.
  265.      */
  266.     public function __toString()
  267.     {
  268.         $result '';
  269.  
  270.         $values array();
  271.         $values[array('label' => 'User agent''value' => $this->getUserAgent());
  272.         $values[array('label' => 'Browser name''value' => $this->getName());
  273.         $values[array('label' => 'Browser version''value' => $this->getVersion());
  274.         $values[array('label' => 'Platform family''value' => $this->getPlatform());
  275.         $values[array('label' => 'Platform version''value' => $this->getPlatformVersion(true));
  276.         $values[array('label' => 'Platform version name''value' => $this->getPlatformVersion());
  277.         $values[array('label' => 'Platform is 64-bit''value' => $this->is64bitPlatform('true' 'false');
  278.         $values[array('label' => 'Is mobile''value' => $this->isMobile('true' 'false');
  279.         $values[array('label' => 'Is robot''value' => $this->isRobot('true' 'false');
  280.         $values[array('label' => 'IE is in compatibility view''value' => $this->isInIECompatibilityView('true' 'false');
  281.         $values[array('label' => 'Emulated IE version''value' => $this->isInIECompatibilityView($this->getIECompatibilityView('Not applicable');
  282.         $values[array('label' => 'Is Chrome Frame''value' => $this->isChromeFrame('true' 'false');
  283.         $values[array('label' => 'Is AOL optimized''value' => $this->isAol('true' 'false');
  284.         $values[array('label' => 'AOL version''value' => $this->isAol($this->getAolVersion('Not applicable');
  285.  
  286.         foreach ($values as $currVal{
  287.             $result .= '<strong>' htmlspecialchars($currVal['label']ENT_NOQUOTES':</strong> ' $currVal['value''<br />' PHP_EOL;
  288.         }
  289.  
  290.         return $result;
  291.     }
  292.  
  293.  
  294.     //--- PUBLIC MEMBERS -----------------------------------------------------------------------------------------------
  295.  
  296.  
  297.     /**
  298.      * Compare two version number strings.
  299.      * @param string $sourceVer The source version number.
  300.      * @param string $compareVer The version number to compare with the source version number.
  301.      * @return int Returns -1 if $sourceVer < $compareVer, 0 if $sourceVer == $compareVer or 1 if $sourceVer >
  302.      *  $compareVer.
  303.      */
  304.     public function compareVersions($sourceVer$compareVer)
  305.     {
  306.         $sourceVer explode('.'$sourceVer);
  307.         foreach ($sourceVer as $k => $v{
  308.             $sourceVer[$k$this->parseInt($v);
  309.         }
  310.  
  311.         $compareVer explode('.'$compareVer);
  312.         foreach ($compareVer as $k => $v{
  313.             $compareVer[$k$this->parseInt($v);
  314.         }
  315.  
  316.         if (count($sourceVer!= count($compareVer)) {
  317.             if (count($sourceVercount($compareVer)) {
  318.                 for ($i count($compareVer)$i count($sourceVer)$i++{
  319.                     $compareVer[$i0;
  320.                 }
  321.             else {
  322.                 for ($i count($sourceVer)$i count($compareVer)$i++{
  323.                     $sourceVer[$i0;
  324.                 }
  325.             }
  326.         }
  327.  
  328.         foreach ($sourceVer as $i => $srcVerPart{
  329.             if ($srcVerPart $compareVer[$i]{
  330.                 return 1;
  331.             else {
  332.                 if ($srcVerPart $compareVer[$i]{
  333.                     return -1;
  334.                 }
  335.             }
  336.         }
  337.  
  338.         return 0;
  339.     }
  340.  
  341.     /**
  342.      * Get the version of AOL (if any). AOL releases "optimized" Internet Explorer and Firefox versions. In the making
  343.      * they add their version number in the user agent string of these browsers.
  344.      * @return string Returns the version of AOL or an empty string if no AOL version was found.
  345.      */
  346.     public function getAolVersion()
  347.     {
  348.         return $this->_aolVersion;
  349.     }
  350.  
  351.     /**
  352.      * Get the name of the browser. All of the return values are class constants. You can compare them like this:
  353.      * $myBrowserInstance->getName() == BrowserDetection::BROWSER_FIREFOX.
  354.      * @return string Returns the name of the browser.
  355.      */
  356.     public function getName()
  357.     {
  358.         return $this->_browserName;
  359.     }
  360.  
  361.     /**
  362.      * Get the name and version of the browser emulated in the compatibility view mode (if any). Since Internet
  363.      * Explorer 8, IE can be put in compatibility mode to make websites that were created for older browsers, especially
  364.      * IE 6 and 7, look better in IE 8+ which renders web pages closer to the standards and thus differently from those
  365.      * older versions of IE.
  366.      * @param boolean $asArray Determines if the return value must be an array (true) or a string (false).
  367.      * @return mixed If a string was requested, the function returns the name and version of the browser emulated in the
  368.      *  compatibility view mode or an empty string if the browser is not in compatibility view mode. If an array was
  369.      *  requested, an array with the keys 'browser' and 'version' is returned.
  370.      */
  371.     public function getIECompatibilityView($asArray false)
  372.     {
  373.         if ($asArray{
  374.             return array('browser' => $this->_compatibilityViewName'version' => $this->_compatibilityViewVer);
  375.         else {
  376.             return trim($this->_compatibilityViewName . ' ' $this->_compatibilityViewVer);
  377.         }
  378.     }
  379.  
  380.     /**
  381.      * Get the name of the platform family on which the browser is run on (such as Windows, Apple, iPhone, etc.). All of
  382.      * the return values are class constants. You can compare them like this:
  383.      * $myBrowserInstance->getPlatform() == BrowserDetection::PLATFORM_ANDROID.
  384.      * @return string Returns the name of the platform or BrowserDetection::PLATFORM_UNKNOWN if unknown.
  385.      */
  386.     public function getPlatform()
  387.     {
  388.         return $this->_platform;
  389.     }
  390.  
  391.     /**
  392.      * Get the platform version on which the browser is run on. It can be returned as a string number like 'NT 6.3' or
  393.      * as a name like 'Windows 8.1'. When returning version string numbers for Windows NT OS families the number is
  394.      * prefixed by 'NT ' to differentiate from older Windows 3.x & 9x release. At the moment only the Windows and
  395.      * Android operating systems are supported.
  396.      * @param boolean $returnVersionNumbers Determines if the return value must be versions numbers as a string (true)
  397.      *  or the version name (false).
  398.      * @param boolean $returnServerFlavor Since some Windows NT versions have the same values, this flag determines if
  399.      *  the Server flavor is returned or not. For instance Windows 8.1 and Windows Server 2012 R2 both use version 6.3.
  400.      *  This parameter is only useful when testing for Windows.
  401.      * @return string Returns the version name/version numbers of the platform or the constant PLATFORM_VERSION_UNKNOWN
  402.      *  if unknown.
  403.      */
  404.     public function getPlatformVersion($returnVersionNumbers false$returnServerFlavor false)
  405.     {
  406.         if ($this->_platformVersion == self::PLATFORM_VERSION_UNKNOWN || $this->_platformVersion == ''{
  407.             return self::PLATFORM_VERSION_UNKNOWN;
  408.         }
  409.  
  410.         if ($returnVersionNumbers{
  411.             return $this->_platformVersion;
  412.         else {
  413.             switch ($this->getPlatform()) {
  414.                 case self::PLATFORM_WINDOWS:
  415.                     if (substr($this->_platformVersion03== 'NT '{
  416.                         return $this->windowsNTVerToStr(substr($this->_platformVersion3)$returnServerFlavor);
  417.                     else {
  418.                         return $this->windowsVerToStr($this->_platformVersion);
  419.                     }
  420.                 break;
  421.  
  422.                 case self::PLATFORM_ANDROID:
  423.                     return $this->androidVerToStr($this->_platformVersion);
  424.                 break;
  425.  
  426.                 defaultreturn self::PLATFORM_VERSION_UNKNOWN;
  427.             }
  428.         }
  429.     }
  430.  
  431.     /**
  432.      * Get the user agent value used by the class to determine the browser details.
  433.      * @return string The user agent string.
  434.      */
  435.     public function getUserAgent()
  436.     {
  437.         return $this->_agent;
  438.     }
  439.  
  440.     /**
  441.      * Get the version of the browser.
  442.      * @return string Returns the version of the browser or BrowserDetection::VERSION_UNKNOWN if unknown.
  443.      */
  444.     public function getVersion()
  445.     {
  446.         return $this->_version;
  447.     }
  448.  
  449.     /**
  450.      * Determine if the browser is executed from a 64-bit platform. Keep in mind that not all platforms/browsers report
  451.      * this and the result may not always be accurate.
  452.      * @return boolean Returns true if the browser is executed from a 64-bit platform.
  453.      */
  454.     public function is64bitPlatform()
  455.     {
  456.         return $this->_is64bit;
  457.     }
  458.  
  459.     /**
  460.      * Determine if the browser is from AOL. AOL releases "optimized" Internet Explorer and Firefox versions. In the
  461.      * making they add their details in the user agent string of these browsers.
  462.      * @return boolean Returns true if the browser is from AOL, false otherwise.
  463.      */
  464.     public function isAol()
  465.     {
  466.         return $this->_isAol;
  467.     }
  468.  
  469.     /**
  470.      * Determine if the browser runs Google Chrome Frame (it's a plug-in designed for Internet Explorer 6+ based on the
  471.      * open-source Chromium project - it's like a Chrome browser within IE).
  472.      * @return boolean Returns true if the browser is using Google Chrome Frame, false otherwise.
  473.      */
  474.     public function isChromeFrame()
  475.     {
  476.         return stripos($this->_agent'chromeframe'!== false;
  477.     }
  478.  
  479.     /**
  480.      * Determine if the browser is in compatibility view or not. Since Internet Explorer 8, IE can be put in
  481.      * compatibility mode to make websites that were created for older browsers, especially IE 6 and 7, look better in
  482.      * IE 8+ which renders web pages closer to the standards and thus differently from those older versions of IE.
  483.      * @return boolean Returns true if the browser is in compatibility view, false otherwise.
  484.      */
  485.     public function isInIECompatibilityView()
  486.     {
  487.         return ($this->_compatibilityViewName != ''|| ($this->_compatibilityViewVer != '');
  488.     }
  489.  
  490.     /**
  491.      * Determine if the browser is from a mobile device or not.
  492.      * @return boolean Returns true if the browser is from a mobile device, false otherwise.
  493.      */
  494.     public function isMobile()
  495.     {
  496.         return $this->_isMobile;
  497.     }
  498.  
  499.     /**
  500.      * Determine if the browser is a robot (Googlebot, Bingbot, Yahoo! Slurp...) or not.
  501.      * @return boolean Returns true if the browser is a robot, false otherwise.
  502.      */
  503.     public function isRobot()
  504.     {
  505.         return $this->_isRobot;
  506.     }
  507.  
  508.     /**
  509.      * Set the user agent to use with the class.
  510.      * @param string $agentString The value of the user agent. If an empty string is sent (default),
  511.      *  $_SERVER['HTTP_USER_AGENT'] will be used.
  512.      */
  513.     public function setUserAgent($agentString '')
  514.     {
  515.         if (!is_string($agentString|| trim($agentString== ''{
  516.             if (array_key_exists('HTTP_USER_AGENT'$_SERVER&& is_string($_SERVER['HTTP_USER_AGENT'])) {
  517.                 $agentString $_SERVER['HTTP_USER_AGENT'];
  518.             else {
  519.                 $agentString '';
  520.             }
  521.         }
  522.  
  523.         $this->reset();
  524.         $this->_agent = $agentString;
  525.         $this->detect();
  526.     }
  527.  
  528.  
  529.     //--- PROTECTED MEMBERS --------------------------------------------------------------------------------------------
  530.  
  531.  
  532.     /**
  533.      * Convert the Android version numbers to the operating system name. For instance '1.6' returns 'Donut'.
  534.      * @access protected
  535.      * @param string $androidVer The Android version numbers as a string.
  536.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  537.      *  numbers.
  538.      */
  539.     protected function androidVerToStr($androidVer)
  540.     {
  541.         //https://en.wikipedia.org/wiki/Android_version_history
  542.  
  543.         if ($this->compareVersions($androidVer'7'>= && $this->compareVersions($androidVer'8'0{
  544.             return 'Nougat';
  545.         else if ($this->compareVersions($androidVer'6'>= && $this->compareVersions($androidVer'7'0{
  546.             return 'Marshmallow';
  547.         else if ($this->compareVersions($androidVer'5'>= && $this->compareVersions($androidVer'6'0{
  548.             return 'Lollipop';
  549.         else if ($this->compareVersions($androidVer'4.4'>= || $this->compareVersions($androidVer'5'0{
  550.             return 'KitKat';
  551.         else if ($this->compareVersions($androidVer'4.1'>= || $this->compareVersions($androidVer'4.4'0{
  552.             return 'Jelly Bean';
  553.         else if ($this->compareVersions($androidVer'4'>= || $this->compareVersions($androidVer'4.1'0{
  554.             return 'Ice Cream Sandwich';
  555.         else if ($this->compareVersions($androidVer'3'>= || $this->compareVersions($androidVer'4'0{
  556.             return 'Honeycomb';
  557.         else if ($this->compareVersions($androidVer'2.3'>= || $this->compareVersions($androidVer'3'0{
  558.             return 'Gingerbread';
  559.         else if ($this->compareVersions($androidVer'2.2'>= || $this->compareVersions($androidVer'2.3'0{
  560.             return 'Froyo';
  561.         else if ($this->compareVersions($androidVer'2'>= || $this->compareVersions($androidVer'2.2'0{
  562.             return 'Eclair';
  563.         else if ($this->compareVersions($androidVer'1.6'>= || $this->compareVersions($androidVer'2'0{
  564.             return 'Donut';
  565.         else if ($this->compareVersions($androidVer'1.5'>= || $this->compareVersions($androidVer'1.6'0{
  566.             return 'Cupcake';
  567.         else {
  568.             return self::PLATFORM_VERSION_UNKNOWN//Unknown/unnamed Android version
  569.         }
  570.     }
  571.  
  572.     /**
  573.      * Determine if the browser is the Amaya Web editor or not.
  574.      * @access protected
  575.      * @link http://www.w3.org/Amaya/
  576.      * @return boolean Returns true if the browser is Amaya, false otherwise.
  577.      */
  578.     protected function checkBrowserAmaya()
  579.     {
  580.         return $this->checkSimpleBrowserUA('amaya'$this->_agentself::BROWSER_AMAYA);
  581.     }
  582.  
  583.     /**
  584.      * Determine if the browser is the Android browser (based on the WebKit layout engine and coupled with Chrome's
  585.      * JavaScript engine) or not.
  586.      * @access protected
  587.      * @return boolean Returns true if the browser is the Android browser, false otherwise.
  588.      */
  589.     protected function checkBrowserAndroid()
  590.     {
  591.         //Android don't use the standard "Android/1.0", it uses "Android 1.0;" instead
  592.         return $this->checkSimpleBrowserUA('Android'$this->_agentself::BROWSER_ANDROIDtrue);
  593.     }
  594.  
  595.     /**
  596.      * Determine if the browser is the Bingbot crawler or not.
  597.      * @access protected
  598.      * @link http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0
  599.      * @return boolean Returns true if the browser is Bingbot, false otherwise.
  600.      */
  601.     protected function checkBrowserBingbot()
  602.     {
  603.         return $this->checkSimpleBrowserUA('bingbot'$this->_agentself::BROWSER_BINGBOTfalsetrue);
  604.     }
  605.  
  606.     /**
  607.      * Determine if the browser is the BlackBerry browser or not.
  608.      * @access protected
  609.      * @link http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862
  610.      * @return boolean Returns true if the browser is the BlackBerry browser, false otherwise.
  611.      */
  612.     protected function checkBrowserBlackBerry()
  613.     {
  614.         $found false;
  615.  
  616.         //Tablet OS check
  617.         if ($this->checkSimpleBrowserUA('RIM Tablet OS'$this->_agentself::BROWSER_TABLET_OStrue)) {
  618.             return true;
  619.         }
  620.  
  621.         //Version 6, 7 & 10 check (versions 8 & 9 does not exists)
  622.         if ($this->checkBrowserUAWithVersion(array('BlackBerry''BB10')$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  623.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  624.                 $found true;
  625.             else {
  626.                 return true;
  627.             }
  628.         }
  629.  
  630.         //Version 4.2 to 5.0 check
  631.         if ($this->checkSimpleBrowserUA('BlackBerry'$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  632.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  633.                 $found true;
  634.             else {
  635.                 return true;
  636.             }
  637.         }
  638.  
  639.         return $found;
  640.     }
  641.  
  642.     /**
  643.      * Determine if the browser is Chrome or not.
  644.      * @access protected
  645.      * @link http://www.google.com/chrome/
  646.      * @return boolean Returns true if the browser is Chrome, false otherwise.
  647.      */
  648.     protected function checkBrowserChrome()
  649.     {
  650.         return $this->checkSimpleBrowserUA('Chrome'$this->_agentself::BROWSER_CHROME);
  651.     }
  652.  
  653.     /**
  654.      * Determine if the browser is Edge or not.
  655.      * @access protected
  656.      * @return boolean Returns true if the browser is Edge, false otherwise.
  657.      */
  658.     protected function checkBrowserEdge()
  659.     {
  660.         return $this->checkSimpleBrowserUA('Edge'$this->_agentself::BROWSER_EDGE);
  661.     }
  662.  
  663.     /**
  664.      * Determine if the browser is Firebird or not. Firebird was the name of Firefox from version 0.6 to 0.7.1.
  665.      * @access protected
  666.      * @return boolean Returns true if the browser is Firebird, false otherwise.
  667.      */
  668.     protected function checkBrowserFirebird()
  669.     {
  670.         return $this->checkSimpleBrowserUA('Firebird'$this->_agentself::BROWSER_FIREBIRD);
  671.     }
  672.  
  673.     /**
  674.      * Determine if the browser is Firefox or not.
  675.      * @access protected
  676.      * @link http://www.mozilla.org/en-US/firefox/new/
  677.      * @return boolean Returns true if the browser is Firefox, false otherwise.
  678.      */
  679.     protected function checkBrowserFirefox()
  680.     {
  681.         //Safari heavily matches with Firefox, ensure that Safari is filtered out...
  682.         if (preg_match('/.*Firefox[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches&&
  683.                 stripos($this->_agent'Safari'=== false{
  684.             $this->setBrowser(self::BROWSER_FIREFOX);
  685.             $this->setVersion($matches[1]);
  686.             $this->setMobile(false);
  687.             $this->setRobot(false);
  688.  
  689.             return true;
  690.         }
  691.  
  692.         return false;
  693.     }
  694.  
  695.     /**
  696.      * Determine if the browser is Galeon or not. The browser was discontinued on September 27, 2008.
  697.      * @access protected
  698.      * @link http://en.wikipedia.org/wiki/Galeon
  699.      * @return boolean Returns true if the browser is Galeon, false otherwise.
  700.      */
  701.     protected function checkBrowserGaleon()
  702.     {
  703.         return $this->checkSimpleBrowserUA('Galeon'$this->_agentself::BROWSER_GALEON);
  704.     }
  705.  
  706.     /**
  707.      * Determine if the browser is the Googlebot crawler or not.
  708.      * @access protected
  709.      * @return boolean Returns true if the browser is Googlebot, false otherwise.
  710.      */
  711.     protected function checkBrowserGooglebot()
  712.     {
  713.         if ($this->checkSimpleBrowserUA('Googlebot'$this->_agentself::BROWSER_GOOGLEBOTfalsetrue)) {
  714.             if (strpos(strtolower($this->_agent)'googlebot-mobile'!== false{
  715.                 $this->setMobile(true);
  716.             }
  717.  
  718.             return true;
  719.         }
  720.  
  721.         return false;
  722.     }
  723.  
  724.     /**
  725.      * Determine if the browser is iCab or not.
  726.      * @access protected
  727.      * @link http://www.icab.de/
  728.      * @return boolean Returns true if the browser is iCab, false otherwise.
  729.      */
  730.     protected function checkBrowserIcab()
  731.     {
  732.         //Some (early) iCab versions don't use the standard "iCab/1.0", they uses "iCab 1.0;" instead
  733.         return $this->checkSimpleBrowserUA('iCab'$this->_agentself::BROWSER_ICAB);
  734.     }
  735.  
  736.     /**
  737.      * Determine if the browser is GNU IceCat (formerly known as GNU IceWeasel) or not.
  738.      * @access protected
  739.      * @link http://www.gnu.org/software/gnuzilla/
  740.      * @return boolean Returns true if the browser is GNU IceCat, false otherwise.
  741.      */
  742.     protected function checkBrowserIceCat()
  743.     {
  744.         return $this->checkSimpleBrowserUA('IceCat'$this->_agentself::BROWSER_ICECAT);
  745.     }
  746.  
  747.     /**
  748.      * Determine if the browser is GNU IceWeasel (now know as GNU IceCat) or not.
  749.      * @access protected
  750.      * @see checkBrowserIceCat()
  751.      * @return boolean Returns true if the browser is GNU IceWeasel, false otherwise.
  752.      */
  753.     protected function checkBrowserIceWeasel()
  754.     {
  755.         return $this->checkSimpleBrowserUA('Iceweasel'$this->_agentself::BROWSER_ICEWEASEL);
  756.     }
  757.  
  758.     /**
  759.      * Determine if the browser is Internet Explorer or not.
  760.      * @access protected
  761.      * @link http://www.microsoft.com/ie/
  762.      * @link http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  763.      * @return boolean Returns true if the browser is Internet Explorer, false otherwise.
  764.      */
  765.     protected function checkBrowserInternetExplorer()
  766.     {
  767.         //Test for Internet Explorer Mobile (formerly Pocket Internet Explorer)
  768.         if ($this->checkSimpleBrowserUA(array('IEMobile''MSPIE')$this->_agentself::BROWSER_IE_MOBILEtrue)) {
  769.             return true;
  770.         }
  771.  
  772.         //Several browsers uses IE compatibility UAs filter these browsers out (but after testing for IE Mobile)
  773.         if (stripos($this->_agent'Opera'!== false ||
  774.                 stripos($this->_agent'BlackBerry'!== false ||
  775.                 stripos($this->_agent'Nokia'!== false{
  776.             return false;
  777.         }
  778.  
  779.         //Test for Internet Explorer 1
  780.         if ($this->checkSimpleBrowserUA('Microsoft Internet Explorer'$this->_agentself::BROWSER_IE)) {
  781.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  782.                 if (preg_match('/308|425|426|474|0b1/i'$this->_agent)) {
  783.                     $this->setVersion('1.5');
  784.                 else {
  785.                     $this->setVersion('1.0');
  786.                 }
  787.             }
  788.             return true;
  789.         }
  790.  
  791.         //Test for Internet Explorer 2+
  792.         if (stripos($this->_agent'MSIE'!== false || stripos($this->_agent'Trident'!== false{
  793.             $version '';
  794.  
  795.             if (stripos($this->_agent'Trident'!== false{
  796.                 //Test for Internet Explorer 11+ (check the rv: string)
  797.                 if (stripos($this->_agent'rv:'!== false{
  798.                     if ($this->checkSimpleBrowserUA('Trident'$this->_agentself::BROWSER_IEfalsefalse'rv:')) {
  799.                         return true;
  800.                     }
  801.                 else {
  802.                     //Test for Internet Explorer 8, 9 & 10 (check the Trident string)
  803.                     if (preg_match('/Trident\/([\d]+)/i'$this->_agent$foundVersion)) {
  804.                         //Trident started with version 4.0 on IE 8
  805.                         $verFromTrident $this->parseInt($foundVersion[1]4;
  806.                         if ($verFromTrident >= 8{
  807.                             $version $verFromTrident '.0';
  808.                         }
  809.                     }
  810.                 }
  811.  
  812.                 //If we have the IE version from Trident, we can check for the compatibility view mode
  813.                 if ($version != ''{
  814.                     $emulatedVer '';
  815.                     preg_match_all('/MSIE\s*([^\s;$]+)/i'$this->_agent$foundVersions);
  816.                     foreach ($foundVersions[1as $currVer{
  817.                         //Keep the lowest MSIE version for the emulated version (in compatibility view mode)
  818.                         if ($emulatedVer == '' || $this->compareVersions($emulatedVer$currVer== 1{
  819.                             $emulatedVer $currVer;
  820.                         }
  821.                     }
  822.                     //Set the compatibility view mode if $version != $emulatedVer
  823.                     if ($this->compareVersions($version$emulatedVer!= 0{
  824.                         $this->_compatibilityViewName = self::BROWSER_IE;
  825.                         $this->_compatibilityViewVer = $this->cleanVersion($emulatedVer);
  826.                     }
  827.                 }
  828.             }
  829.  
  830.             //Test for Internet Explorer 2-7 versions if needed
  831.             if ($version == ''{
  832.                 preg_match_all('/MSIE\s+([^\s;$]+)/i'$this->_agent$foundVersions);
  833.                 foreach ($foundVersions[1as $currVer{
  834.                     //Keep the highest MSIE version
  835.                     if ($version == '' || $this->compareVersions($version$currVer== -1{
  836.                         $version $currVer;
  837.                     }
  838.                 }
  839.             }
  840.  
  841.             $this->setBrowser(self::BROWSER_IE);
  842.             $this->setVersion($version);
  843.             $this->setMobile(false);
  844.             $this->setRobot(false);
  845.  
  846.             return true;
  847.         }
  848.  
  849.         return false;
  850.     }
  851.  
  852.     /**
  853.      * Determine if the browser is Konqueror or not.
  854.      * @access protected
  855.      * @link http://www.konqueror.org/
  856.      * @return boolean Returns true if the browser is Konqueror, false otherwise.
  857.      */
  858.     protected function checkBrowserKonqueror()
  859.     {
  860.         return $this->checkSimpleBrowserUA('Konqueror'$this->_agentself::BROWSER_KONQUEROR);
  861.     }
  862.  
  863.     /**
  864.      * Determine if the browser is Lynx or not. It is the oldest web browser currently in general use and development.
  865.      * It is a text-based only Web browser.
  866.      * @access protected
  867.      * @link http://en.wikipedia.org/wiki/Lynx
  868.      * @return boolean Returns true if the browser is Lynx, false otherwise.
  869.      */
  870.     protected function checkBrowserLynx()
  871.     {
  872.         return $this->checkSimpleBrowserUA('Lynx'$this->_agentself::BROWSER_LYNX);
  873.     }
  874.  
  875.     /**
  876.      * Determine if the browser is Mozilla or not.
  877.      * @access protected
  878.      * @return boolean Returns true if the browser is Mozilla, false otherwise.
  879.      */
  880.     protected function checkBrowserMozilla()
  881.     {
  882.         return $this->checkSimpleBrowserUA('Mozilla'$this->_agentself::BROWSER_MOZILLAfalsefalse'rv:');
  883.     }
  884.  
  885.     /**
  886.      * Determine if the browser is the MSNBot crawler or not. In October 2010 it was replaced by the Bingbot robot.
  887.      * @access protected
  888.      * @see checkBrowserBingbot()
  889.      * @return boolean Returns true if the browser is MSNBot, false otherwise.
  890.      */
  891.     protected function checkBrowserMsnBot()
  892.     {
  893.         return $this->checkSimpleBrowserUA('msnbot'$this->_agentself::BROWSER_MSNBOTfalsetrue);
  894.     }
  895.  
  896.     /**
  897.      * Determine if the browser is MSN TV (formerly WebTV) or not.
  898.      * @access protected
  899.      * @link http://en.wikipedia.org/wiki/MSN_TV
  900.      * @return boolean Returns true if the browser is WebTv, false otherwise.
  901.      */
  902.     protected function checkBrowserMsnTv()
  903.     {
  904.         return $this->checkSimpleBrowserUA('webtv'$this->_agentself::BROWSER_MSNTV);
  905.     }
  906.  
  907.     /**
  908.      * Determine if the browser is NetPositive or not. The browser is discontinued since November 2001.
  909.      * @access protected
  910.      * @link http://en.wikipedia.org/wiki/NetPositive
  911.      * @return boolean Returns true if the browser is NetPositive, false otherwise.
  912.      */
  913.     protected function checkBrowserNetPositive()
  914.     {
  915.         return $this->checkSimpleBrowserUA('NetPositive'$this->_agentself::BROWSER_NETPOSITIVE);
  916.     }
  917.  
  918.     /**
  919.      * Determine if the browser is Netscape or not. Official support for this browser ended on March 1st, 2008.
  920.      * @access protected
  921.      * @link http://en.wikipedia.org/wiki/Netscape
  922.      * @return boolean Returns true if the browser is Netscape, false otherwise.
  923.      */
  924.     protected function checkBrowserNetscape()
  925.     {
  926.         //BlackBerry & Nokia UAs can conflict with Netscape UAs
  927.         if (stripos($this->_agent'BlackBerry'!== false || stripos($this->_agent'Nokia'!== false{
  928.             return false;
  929.         }
  930.  
  931.         //Netscape v6 to v9 check
  932.         if ($this->checkSimpleBrowserUA(array('Netscape''Navigator''Netscape6')$this->_agentself::BROWSER_NETSCAPE)) {
  933.             return true;
  934.         }
  935.  
  936.         //Netscape v1-4 (v5 don't exists)
  937.         $found false;
  938.         if (stripos($this->_agent'Mozilla'!== false && stripos($this->_agent'rv:'=== false{
  939.             $version '';
  940.             $verParts explode('/'stristr($this->_agent'Mozilla'));
  941.             if (count($verParts1{
  942.                 $verParts explode(' '$verParts[1]);
  943.                 $verParts explode('.'$verParts[0]);
  944.  
  945.                 $majorVer $this->parseInt($verParts[0]);
  946.                 if ($majorVer && $majorVer 5{
  947.                     $version implode('.'$verParts);
  948.                     $found true;
  949.  
  950.                     if (strtolower(substr($version-4)) == '-sgi'{
  951.                         $version substr($version0-4);
  952.                     else {
  953.                         if (strtolower(substr($version-4)) == 'gold'{
  954.                             $version substr($version0-4' Gold'//Doubles spaces (if any) will be normalized by setVersion()
  955.                         }
  956.                     }
  957.                 }
  958.             }
  959.         }
  960.  
  961.         if ($found{
  962.             $this->setBrowser(self::BROWSER_NETSCAPE);
  963.             $this->setVersion($version);
  964.             $this->setMobile(false);
  965.             $this->setRobot(false);
  966.         }
  967.  
  968.         return $found;
  969.     }
  970.  
  971.     /**
  972.      * Determine if the browser is a Nokia browser or not.
  973.      * @access protected
  974.      * @link http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
  975.      * @return boolean Returns true if the browser is a Nokia browser, false otherwise.
  976.      */
  977.     protected function checkBrowserNokia()
  978.     {
  979.         if (stripos($this->_agent'Nokia5800'!== false || stripos($this->_agent'Nokia5530'!== false || stripos($this->_agent'Nokia5230'!== false{
  980.             $this->setBrowser(self::BROWSER_NOKIA);
  981.             $this->setVersion('7.0');
  982.             $this->setMobile(true);
  983.             $this->setRobot(false);
  984.  
  985.             return true;
  986.         }
  987.  
  988.         if ($this->checkSimpleBrowserUA(array('NokiaBrowser''BrowserNG''Series60''S60''S40OviBrowser')$this->_agentself::BROWSER_NOKIAtrue)) {
  989.             return true;
  990.         }
  991.  
  992.         return false;
  993.     }
  994.  
  995.     /**
  996.      * Determine if the browser is OmniWeb or not.
  997.      * @access protected
  998.      * @link http://www.omnigroup.com/products/omniweb/
  999.      * @return boolean Returns true if the browser is OmniWeb, false otherwise.
  1000.      */
  1001.     protected function checkBrowserOmniWeb()
  1002.     {
  1003.         if ($this->checkSimpleBrowserUA('OmniWeb'$this->_agentself::BROWSER_OMNIWEB)) {
  1004.             //Some versions of OmniWeb prefix the version number with "v"
  1005.             if ($this->getVersion(!= self::VERSION_UNKNOWN && strtolower(substr($this->getVersion()01)) == 'v'{
  1006.                 $this->setVersion(substr($this->getVersion()1));
  1007.             }
  1008.             return true;
  1009.         }
  1010.  
  1011.         return false;
  1012.     }
  1013.  
  1014.     /**
  1015.      * Determine if the browser is Opera or not.
  1016.      * @access protected
  1017.      * @link http://www.opera.com/
  1018.      * @link http://www.opera.com/mini/
  1019.      * @link http://www.opera.com/mobile/
  1020.      * @link http://my.opera.com/community/openweb/idopera/
  1021.      * @return boolean Returns true if the browser is Opera, false otherwise.
  1022.      */
  1023.     protected function checkBrowserOpera()
  1024.     {
  1025.         if ($this->checkBrowserUAWithVersion('Opera Mobi'$this->_agentself::BROWSER_OPERA_MOBILEtrue)) {
  1026.             return true;
  1027.         }
  1028.  
  1029.         if ($this->checkSimpleBrowserUA('Opera Mini'$this->_agentself::BROWSER_OPERA_MINItrue)) {
  1030.             return true;
  1031.         }
  1032.  
  1033.         $version '';
  1034.         $found $this->checkBrowserUAWithVersion('Opera'$this->_agentself::BROWSER_OPERA);
  1035.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  1036.             $version $this->getVersion();
  1037.         }
  1038.  
  1039.         if (!$found || $version == ''{
  1040.             if ($this->checkSimpleBrowserUA('Opera'$this->_agentself::BROWSER_OPERA)) {
  1041.                 return true;
  1042.             }
  1043.         }
  1044.  
  1045.         if (!$found && $this->checkSimpleBrowserUA('Chrome'$this->_agentself::BROWSER_CHROME) ) {
  1046.             if ($this->checkSimpleBrowserUA('OPR/'$this->_agentself::BROWSER_OPERA)) {
  1047.                 return true;
  1048.             }
  1049.         }
  1050.  
  1051.         return $found;
  1052.     }
  1053.  
  1054.     /**
  1055.      * Determine if the browser is Phoenix or not. Phoenix was the name of Firefox from version 0.1 to 0.5.
  1056.      * @access protected
  1057.      * @return boolean Returns true if the browser is Phoenix, false otherwise.
  1058.      */
  1059.     protected function checkBrowserPhoenix()
  1060.     {
  1061.         return $this->checkSimpleBrowserUA('Phoenix'$this->_agentself::BROWSER_PHOENIX);
  1062.     }
  1063.  
  1064.     /**
  1065.      * Determine what is the browser used by the user.
  1066.      * @access protected
  1067.      * @return boolean Returns true if the browser has been identified, false otherwise.
  1068.      */
  1069.     protected function checkBrowsers()
  1070.     {
  1071.         //Changing the check order can break the class detection results!
  1072.         return
  1073.                /* Major browsers and browsers that need to be detected in a special order */
  1074.                $this->checkBrowserMsnTv(||            /* MSN TV is based on IE so we must check for MSN TV before IE */
  1075.                $this->checkBrowserInternetExplorer(||
  1076.                $this->checkBrowserOpera(||            /* Opera must be checked before Firefox, Netscape and Chrome to avoid conflicts */
  1077.                $this->checkBrowserEdge(||             /* Edge must be checked before Firefox, Safari and Chrome to avoid conflicts */
  1078.                $this->checkBrowserVivaldi(||          /* Vivaldi must be checked before Chrome and Safari to avoid conflicts */
  1079.                $this->checkBrowserSamsung(||          /* Samsung Internet browser must be checked before Chrome and Safari to avoid conflicts */
  1080.                $this->checkBrowserChrome(||           /* Chrome must be checked before Netscaoe and Mozilla to avoid conflicts */
  1081.                $this->checkBrowserOmniWeb(||          /* OmniWeb must be checked before Safari (on which it's based on) and Netscape (since it have Mozilla UAs) */
  1082.                $this->checkBrowserIcab(||             /* Check iCab before Netscape since iCab have Mozilla UAs */
  1083.                $this->checkBrowserNetPositive(||      /* Check NetPositive before Netscape since NetPositive have Mozilla UAs */
  1084.                $this->checkBrowserNetscape(||         /* Must be checked before Firefox since Netscape 8-9 are based on Firefox */
  1085.                $this->checkBrowserIceCat(||           /* Check IceCat and IceWeasel before Firefox since they are GNU builds of Firefox */
  1086.                $this->checkBrowserIceWeasel(||
  1087.                $this->checkBrowserGaleon(||           /* Galeon is based on Firefox and needs to be tested before Firefox is tested */
  1088.                $this->checkBrowserFirefox(||
  1089.                /* Current browsers that don't need to be detected in any special order */
  1090.                $this->checkBrowserKonqueror(||
  1091.                $this->checkBrowserLynx(||
  1092.                $this->checkBrowserAmaya(||
  1093.                /* Mobile */
  1094.                $this->checkBrowserAndroid(||
  1095.                $this->checkBrowserBlackBerry(||
  1096.                $this->checkBrowserNokia(||
  1097.                /* Bots */
  1098.                $this->checkBrowserGooglebot(||
  1099.                $this->checkBrowserBingbot(||
  1100.                $this->checkBrowserMsnBot(||
  1101.                $this->checkBrowserSlurp(||
  1102.                $this->checkBrowserYahooMultimedia(||
  1103.                $this->checkBrowserW3CValidator(||
  1104.                /* WebKit base check (after most other checks) */
  1105.                $this->checkBrowserSafari(||
  1106.                /* Deprecated browsers that don't need to be detected in any special order */
  1107.                $this->checkBrowserFirebird(||
  1108.                $this->checkBrowserPhoenix(||
  1109.                /* Mozilla is such an open standard that it must be checked last */
  1110.                $this->checkBrowserMozilla();
  1111.     }
  1112.  
  1113.     /**
  1114.      * Determine if the browser is Safari or not.
  1115.      * @access protected
  1116.      * @link http://www.apple.com/safari/
  1117.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1118.      * @link http://en.wikipedia.org/wiki/Safari_version_history#Release_history
  1119.      * @return boolean Returns true if the browser is Safari, false otherwise.
  1120.      */
  1121.     protected function checkBrowserSafari()
  1122.     {
  1123.         $version '';
  1124.  
  1125.         //Check for current versions of Safari
  1126.         $found $this->checkBrowserUAWithVersion(array('Safari''AppleWebKit')$this->_agentself::BROWSER_SAFARI);
  1127.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  1128.             $version $this->getVersion();
  1129.         }
  1130.  
  1131.         //Safari 1-2 didn't had a "Version" string in the UA, only a WebKit build and/or Safari build, extract version from these...
  1132.         if (!$found || $version == ''{
  1133.             if (preg_match('/.*Safari[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  1134.                 $version $this->safariBuildToSafariVer($matches[1]);
  1135.                 $found true;
  1136.             }
  1137.         }
  1138.         if (!$found || $version == ''{
  1139.             if (preg_match('/.*AppleWebKit[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  1140.                 $version $this->webKitBuildToSafariVer($matches[1]);
  1141.                 $found true;
  1142.             }
  1143.         }
  1144.  
  1145.         if ($found{
  1146.             $this->setBrowser(self::BROWSER_SAFARI);
  1147.             $this->setVersion($version);
  1148.             $this->setMobile(false);
  1149.             $this->setRobot(false);
  1150.         }
  1151.  
  1152.         return $found;
  1153.     }
  1154.  
  1155.     /**
  1156.      * Determine if the browser is the Samsung Internet browser or not.
  1157.      * @access protected
  1158.      * @return boolean Returns true if the browser is the the Samsung Internet browser, false otherwise.
  1159.      */
  1160.     protected function checkBrowserSamsung()
  1161.     {
  1162.         return $this->checkSimpleBrowserUA('SamsungBrowser'$this->_agentself::BROWSER_SAMSUNGtrue);
  1163.     }
  1164.  
  1165.     /**
  1166.      * Determine if the browser is the Yahoo! Slurp crawler or not.
  1167.      * @access protected
  1168.      * @return boolean Returns true if the browser is Yahoo! Slurp, false otherwise.
  1169.      */
  1170.     protected function checkBrowserSlurp()
  1171.     {
  1172.         return $this->checkSimpleBrowserUA('Yahoo! Slurp'$this->_agentself::BROWSER_SLURPfalsetrue);
  1173.     }
  1174.  
  1175.     /**
  1176.      * Test the user agent for a specific browser that use a "Version" string (like Safari and Opera). The user agent
  1177.      * should look like: "Version/1.0 Browser name/123.456" or "Browser name/123.456 Version/1.0".
  1178.      * @access protected
  1179.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  1180.      *  agent.
  1181.      * @param string $userAgent The user agent string to work with.
  1182.      * @param string $browserName The literal browser name. Always use a class constant!
  1183.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  1184.      * @param boolean $isRobot Determines if the browser is a robot or not.
  1185.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  1186.      */
  1187.     protected function checkBrowserUAWithVersion($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false)
  1188.     {
  1189.         if (!is_array($uaNameToLookFor)) {
  1190.             $uaNameToLookFor array($uaNameToLookFor);
  1191.         }
  1192.  
  1193.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  1194.             if (stripos($userAgent$currUANameToLookFor!== false{
  1195.                 $version '';
  1196.                 $verParts explode('/'stristr($this->_agent'Version'));
  1197.                 if (count($verParts1{
  1198.                     $verParts explode(' '$verParts[1]);
  1199.                     $version $verParts[0];
  1200.                 }
  1201.  
  1202.                 $this->setBrowser($browserName);
  1203.                 $this->setVersion($version);
  1204.  
  1205.                 $this->setMobile($isMobile);
  1206.                 $this->setRobot($isRobot);
  1207.  
  1208.                 return true;
  1209.             }
  1210.         }
  1211.  
  1212.         return false;
  1213.     }
  1214.  
  1215.     /**
  1216.      * Determine if the browser is Vivaldi or not.
  1217.      * @access protected
  1218.      * @return boolean Returns true if the browser is Vivaldi, false otherwise.
  1219.      */
  1220.     protected function checkBrowserVivaldi()
  1221.     {
  1222.         return $this->checkSimpleBrowserUA('Vivaldi'$this->_agentself::BROWSER_VIVALDI);
  1223.     }
  1224.  
  1225.     /**
  1226.      * Determine if the browser is the W3C Validator or not.
  1227.      * @access protected
  1228.      * @link http://validator.w3.org/
  1229.      * @return boolean Returns true if the browser is the W3C Validator, false otherwise.
  1230.      */
  1231.     protected function checkBrowserW3CValidator()
  1232.     {
  1233.         //Since the W3C validates pages with different robots we will prefix our versions with the part validated on the page...
  1234.  
  1235.         //W3C Link Checker (prefixed with "Link-")
  1236.         if ($this->checkSimpleBrowserUA('W3C-checklink'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1237.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1238.                 $this->setVersion('Link-' $this->getVersion());
  1239.             }
  1240.             return true;
  1241.         }
  1242.  
  1243.         //W3C CSS Validation Service (prefixed with "CSS-")
  1244.         if ($this->checkSimpleBrowserUA('Jigsaw'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1245.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1246.                 $this->setVersion('CSS-' $this->getVersion());
  1247.             }
  1248.             return true;
  1249.         }
  1250.  
  1251.         //W3C mobileOK Checker (prefixed with "mobileOK-")
  1252.         if ($this->checkSimpleBrowserUA('W3C-mobileOK'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1253.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1254.                 $this->setVersion('mobileOK-' $this->getVersion());
  1255.             }
  1256.             return true;
  1257.         }
  1258.  
  1259.         //W3C Markup Validation Service (no prefix)
  1260.         return $this->checkSimpleBrowserUA('W3C_Validator'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue);
  1261.     }
  1262.  
  1263.     /**
  1264.      * Determine if the browser is the Yahoo! multimedia crawler or not.
  1265.      * @access protected
  1266.      * @return boolean Returns true if the browser is the Yahoo! multimedia crawler, false otherwise.
  1267.      */
  1268.     protected function checkBrowserYahooMultimedia()
  1269.     {
  1270.         return $this->checkSimpleBrowserUA('Yahoo-MMCrawler'$this->_agentself::BROWSER_YAHOO_MMfalsetrue);
  1271.     }
  1272.  
  1273.     /**
  1274.      * Determine if the user is using an AOL "optimized" browser or not.
  1275.      * @access protected
  1276.      * @return boolean Returns true if the browser is AOL optimized, false otherwise.
  1277.      */
  1278.     protected function checkForAol()
  1279.     {
  1280.         //AOL UAs don't use the "AOL/1.0" format, they uses "AOL 1.0; AOLBuild 100.00;"
  1281.         if (stripos($this->_agent'AOL '!== false{
  1282.             $version '';
  1283.             $verParts explode('AOL 'stristr($this->_agent'AOL '));
  1284.             if (count($verParts1{
  1285.                 $verParts explode(' '$verParts[1]);
  1286.                 $version $verParts[0];
  1287.             }
  1288.  
  1289.             $this->setAol(true);
  1290.             $this->setAolVersion($version);
  1291.  
  1292.             return true;
  1293.         else {
  1294.             $this->setAol(false);
  1295.             $this->setAolVersion('');
  1296.  
  1297.             return false;
  1298.         }
  1299.     }
  1300.  
  1301.     /**
  1302.      * Determine the user's platform.
  1303.      * @access protected
  1304.      */
  1305.     protected function checkPlatform()
  1306.     {
  1307.         /* Mobile platforms */
  1308.         if (stripos($this->_agent'Windows Phone'!== false ||     /* Check Windows Phone (formerly Windows Mobile) before Windows */
  1309.                 stripos($this->_agent'IEMobile'!== false{
  1310.             $this->setPlatform(self::PLATFORM_WINDOWS_PHONE);
  1311.             $this->setMobile(true);
  1312.         else if (stripos($this->_agent'Windows CE'!== false/* Check Windows CE before Windows */
  1313.             $this->setPlatform(self::PLATFORM_WINDOWS_CE);
  1314.             $this->setMobile(true);
  1315.         else if (stripos($this->_agent'iPhone'!== false{     /* Check iPad/iPod/iPhone before Macintosh */
  1316.             $this->setPlatform(self::PLATFORM_IPHONE);
  1317.             $this->setMobile(true);
  1318.         else if (stripos($this->_agent'iPad'!== false{
  1319.             $this->setPlatform(self::PLATFORM_IPAD);
  1320.             $this->setMobile(true);
  1321.         else if (stripos($this->_agent'iPod'!== false{
  1322.             $this->setPlatform(self::PLATFORM_IPOD);
  1323.             $this->setMobile(true);
  1324.         else if (stripos($this->_agent'Android'!== false{
  1325.             $this->setPlatform(self::PLATFORM_ANDROID);
  1326.             $this->setMobile(true);
  1327.         else if (stripos($this->_agent'Symbian'!== false{
  1328.             $this->setPlatform(self::PLATFORM_SYMBIAN);
  1329.             $this->setMobile(true);
  1330.         else if (stripos($this->_agent'BlackBerry'!== false ||
  1331.                 stripos($this->_agent'BB10'!== false ||
  1332.                 stripos($this->_agent'RIM Tablet OS'!== false{
  1333.             $this->setPlatform(self::PLATFORM_BLACKBERRY);
  1334.             $this->setMobile(true);
  1335.         else if (stripos($this->_agent'Nokia'!== false{
  1336.             $this->setPlatform(self::PLATFORM_NOKIA);
  1337.             $this->setMobile(true);
  1338.  
  1339.         /* Desktop platforms */
  1340.         else if (stripos($this->_agent'Windows'!== false{
  1341.             $this->setPlatform(self::PLATFORM_WINDOWS);
  1342.         else if (stripos($this->_agent'Macintosh'!== false{
  1343.             $this->setPlatform(self::PLATFORM_MACINTOSH);
  1344.         else if (stripos($this->_agent'Linux'!== false{
  1345.             $this->setPlatform(self::PLATFORM_LINUX);
  1346.         else if (stripos($this->_agent'FreeBSD'!== false{
  1347.             $this->setPlatform(self::PLATFORM_FREEBSD);
  1348.         else if (stripos($this->_agent'OpenBSD'!== false{
  1349.             $this->setPlatform(self::PLATFORM_OPENBSD);
  1350.         else if (stripos($this->_agent'NetBSD'!== false{
  1351.             $this->setPlatform(self::PLATFORM_NETBSD);
  1352.  
  1353.         /* Discontinued */
  1354.         else if (stripos($this->_agent'OpenSolaris'!== false{
  1355.             $this->setPlatform(self::PLATFORM_OPENSOLARIS);
  1356.         else if (stripos($this->_agent'OS/2'!== false{
  1357.             $this->setPlatform(self::PLATFORM_OS2);
  1358.         else if (stripos($this->_agent'BeOS'!== false{
  1359.             $this->setPlatform(self::PLATFORM_BEOS);
  1360.         else if (stripos($this->_agent'SunOS'!== false{
  1361.             $this->setPlatform(self::PLATFORM_SUNOS);
  1362.  
  1363.         /* Generic */
  1364.         else if (stripos($this->_agent'Win'!== false{
  1365.             $this->setPlatform(self::PLATFORM_WINDOWS);
  1366.         else if (stripos($this->_agent'Mac'!== false{
  1367.             $this->setPlatform(self::PLATFORM_MACINTOSH);
  1368.         }
  1369.  
  1370.         //Check if it's a 64-bit platform
  1371.         if (stripos($this->_agent'WOW64'!== false || stripos($this->_agent'Win64'!== false{
  1372.             $this->set64bit(true);
  1373.         }
  1374.  
  1375.         $this->checkPlatformVersion();
  1376.     }
  1377.  
  1378.     /**
  1379.      * Determine the user's platform version.
  1380.      * @access protected
  1381.      */
  1382.     protected function checkPlatformVersion()
  1383.     {
  1384.         //https://support.microsoft.com/en-us/kb/158238
  1385.  
  1386.         $result '';
  1387.  
  1388.         switch ($this->getPlatform()) {
  1389.             case self::PLATFORM_WINDOWS:
  1390.                 if (preg_match('/Windows NT\s*([^\s;\)$]+)/i'$this->_agent$foundVersion)) {
  1391.                     //Windows NT family
  1392.                     $result 'NT ' $foundVersion[1];
  1393.                 else {
  1394.                     //Windows 3.x / 9x family
  1395.                     if (stripos($this->_agent'Win 9x 4.90'!== false || stripos($this->_agent'Windows ME'!== false{
  1396.                         $result '4.90.3000'//Windows Me version range from 4.90.3000 to 4.90.3000A
  1397.                     else if (stripos($this->_agent'Windows 98'!== false{
  1398.                         $result '4.10'//Windows 98 version range from 4.10.1998 to 4.10.2222B
  1399.                     else if (stripos($this->_agent'Windows 95'!== false{
  1400.                         $result '4.00'//Windows 95 version range from 4.00.950 to 4.03.1214
  1401.                     else if (preg_match('/Windows 3\.([^\s;\)$]+)/i'$this->_agent$foundVersion)) {
  1402.                         $result '3.' $foundVersion[1];
  1403.                     else if (stripos($this->_agent'Win16'!== false{
  1404.                         $result '3.1';
  1405.                     }
  1406.                 }
  1407.             break;
  1408.  
  1409.             case self::PLATFORM_ANDROID:
  1410.                 if (preg_match('/Android\s+([^\s;$]+)/i'$this->_agent$foundVersion)) {
  1411.                     $result $foundVersion[1];
  1412.                 }
  1413.             break;
  1414.         }
  1415.  
  1416.         if (trim($result== ''{
  1417.             $result self::PLATFORM_VERSION_UNKNOWN;
  1418.         }
  1419.         $this->setPlatformVersion($result);
  1420.     }
  1421.  
  1422.     /**
  1423.      * Test the user agent for a specific browser where the browser name is immediately followed by the version number.
  1424.      * The user agent should look like: "Browser name/1.0" or "Browser 1.0;".
  1425.      * @access protected
  1426.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  1427.      *  agent.
  1428.      * @param string $userAgent The user agent string to work with.
  1429.      * @param string $browserName The literal browser name. Always use a class constant!
  1430.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  1431.      * @param boolean $isRobot Determines if the browser is a robot or not.
  1432.      * @param string $separator The separator string used to split the browser name and the version number in the user
  1433.      *  agent.
  1434.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  1435.      */
  1436.     protected function checkSimpleBrowserUA($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false$separator '/')
  1437.     {
  1438.         if (!is_array($uaNameToLookFor)) {
  1439.             $uaNameToLookFor array($uaNameToLookFor);
  1440.         }
  1441.  
  1442.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  1443.             if (stripos($userAgent$currUANameToLookFor!== false{
  1444.                 //Many browsers don't use the standard "Browser/1.0" format, they uses "Browser 1.0;" instead
  1445.                 if (stripos($userAgent$currUANameToLookFor $separator=== false{
  1446.                     $userAgent str_ireplace($currUANameToLookFor ' '$currUANameToLookFor $separator$this->_agent);
  1447.                 }
  1448.  
  1449.                 $version '';
  1450.                 $verParts explode($separatorstristr($userAgent$currUANameToLookFor));
  1451.                 if (count($verParts1{
  1452.                     $verParts explode(' '$verParts[1]);
  1453.                     $version $verParts[0];
  1454.                 }
  1455.  
  1456.                 $this->setBrowser($browserName);
  1457.                 $this->setVersion($version);
  1458.  
  1459.                 $this->setMobile($isMobile);
  1460.                 $this->setRobot($isRobot);
  1461.  
  1462.                 return true;
  1463.             }
  1464.         }
  1465.  
  1466.         return false;
  1467.     }
  1468.  
  1469.     /**
  1470.      * Detect the user environment from the details in the user agent string.
  1471.      * @access protected
  1472.      */
  1473.     protected function detect()
  1474.     {
  1475.         $this->checkBrowsers();
  1476.         $this->checkPlatform()//Check the platform after the browser since some platforms can change the mobile value
  1477.         $this->checkForAol();
  1478.     }
  1479.  
  1480.     /**
  1481.      * Clean a version string from unwanted characters.
  1482.      * @access protected
  1483.      * @param string $version The version string to clean.
  1484.      * @return string Returns the cleaned version number string.
  1485.      */
  1486.     protected function cleanVersion($version)
  1487.     {
  1488.         //Clear anything that is in parentheses (and the parentheses themselves) - will clear started but unclosed ones too
  1489.         $cleanVer preg_replace('/\([^)]+\)?/'''$version);
  1490.         //Replace with a space any character which is NOT an alphanumeric, dot (.), hyphen (-), underscore (_) or space
  1491.         $cleanVer preg_replace('/[^0-9.a-zA-Z_ -]/'' '$cleanVer);
  1492.         //Remove trailing and leading spaces
  1493.         $cleanVer trim($cleanVer);
  1494.         //Remove double spaces if any
  1495.         while (strpos($cleanVer'  '!== false{
  1496.             $cleanVer str_replace('  '' '$cleanVer);
  1497.         }
  1498.  
  1499.         return $cleanVer;
  1500.     }
  1501.  
  1502.     /**
  1503.      * Get the integer value of a string variable.
  1504.      * @access protected
  1505.      * @param string $intStr The scalar value being converted to an integer.
  1506.      * @return int The integer value of $intStr on success, or 0 on failure.
  1507.      */
  1508.     protected function parseInt($intStr)
  1509.     {
  1510.         return intval($intStr10);
  1511.     }
  1512.  
  1513.     /**
  1514.      * Reset all the properties of the class.
  1515.      * @access protected
  1516.      */
  1517.     protected function reset()
  1518.     {
  1519.         $this->_agent = '';
  1520.         $this->_aolVersion = '';
  1521.         $this->_browserName = self::BROWSER_UNKNOWN;
  1522.         $this->_compatibilityViewName = '';
  1523.         $this->_compatibilityViewVer = '';
  1524.         $this->_is64bit = false;
  1525.         $this->_isAol = false;
  1526.         $this->_isMobile = false;
  1527.         $this->_isRobot = false;
  1528.         $this->_platform = self::PLATFORM_UNKNOWN;
  1529.         $this->_platformVersion = self::PLATFORM_VERSION_UNKNOWN;
  1530.         $this->_version = self::VERSION_UNKNOWN;
  1531.     }
  1532.  
  1533.     /**
  1534.      * Convert a Safari build number to a Safari version number.
  1535.      * @access protected
  1536.      * @param string $version A string representing the version number.
  1537.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1538.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1539.      *  returned.
  1540.      */
  1541.     protected function safariBuildToSafariVer($version)
  1542.     {
  1543.         $verParts explode('.'$version);
  1544.  
  1545.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1546.         while (count($verParts3{
  1547.             $verParts[0;
  1548.         }
  1549.         foreach ($verParts as $i => $currPart{
  1550.             $verParts[$i$this->parseInt($currPart);
  1551.         }
  1552.  
  1553.         switch ($verParts[0]{
  1554.             case 419$result '2.0.4';
  1555.                 break;
  1556.             case 417$result '2.0.3';
  1557.                 break;
  1558.             case 416$result '2.0.2';
  1559.                 break;
  1560.  
  1561.             case 412:
  1562.                 if ($verParts[1>= 5{
  1563.                     $result '2.0.1';
  1564.                 else {
  1565.                     $result '2.0';
  1566.                 }
  1567.                 break;
  1568.  
  1569.             case 312:
  1570.                 if ($verParts[1>= 5{
  1571.                     $result '1.3.2';
  1572.                 else {
  1573.                     if ($verParts[1>= 3{
  1574.                         $result '1.3.1';
  1575.                     else {
  1576.                         $result '1.3';
  1577.                     }
  1578.                 }
  1579.                 break;
  1580.  
  1581.             case 125:
  1582.                 if ($verParts[1>= 11{
  1583.                     $result '1.2.4';
  1584.                 else {
  1585.                     if ($verParts[1>= 9{
  1586.                         $result '1.2.3';
  1587.                     else {
  1588.                         if ($verParts[1>= 7{
  1589.                             $result '1.2.2';
  1590.                         else {
  1591.                             $result '1.2';
  1592.                         }
  1593.                     }
  1594.                 }
  1595.                 break;
  1596.  
  1597.             case 100:
  1598.                 if ($verParts[1>= 1{
  1599.                     $result '1.1.1';
  1600.                 else {
  1601.                     $result '1.1';
  1602.                 }
  1603.                 break;
  1604.  
  1605.             case 85:
  1606.                 if ($verParts[1>= 8{
  1607.                     $result '1.0.3';
  1608.                 else {
  1609.                     if ($verParts[1>= 7{
  1610.                         $result '1.0.2';
  1611.                     else {
  1612.                         $result '1.0';
  1613.                     }
  1614.                 }
  1615.                 break;
  1616.  
  1617.             case 73$result '0.9';
  1618.                 break;
  1619.             case 51$result '0.8.1';
  1620.                 break;
  1621.             case 48$result '0.8';
  1622.                 break;
  1623.  
  1624.             default$result '';
  1625.         }
  1626.  
  1627.         return $result;
  1628.     }
  1629.  
  1630.     /**
  1631.      * Set if the browser is executed from a 64-bit platform.
  1632.      * @access protected
  1633.      * @param boolean $is64bit Value that tells if the browser is executed from a 64-bit platform.
  1634.      */
  1635.     protected function set64bit($is64bit)
  1636.     {
  1637.         $this->_is64bit = $is64bit == true;
  1638.     }
  1639.  
  1640.     /**
  1641.      * Set the browser to be from AOL or not.
  1642.      * @access protected
  1643.      * @param boolean $isAol Value that tells if the browser is AOL or not.
  1644.      */
  1645.     protected function setAol($isAol)
  1646.     {
  1647.         $this->_isAol = $isAol == true;
  1648.     }
  1649.  
  1650.     /**
  1651.      * Set the version of AOL.
  1652.      * @access protected
  1653.      * @param string $version The version of AOL (will be cleaned).
  1654.      */
  1655.     protected function setAolVersion($version)
  1656.     {
  1657.         $cleanVer $this->cleanVersion($version);
  1658.  
  1659.         $this->_aolVersion = $cleanVer;
  1660.     }
  1661.  
  1662.     /**
  1663.      * Set the name of the browser.
  1664.      * @access protected
  1665.      * @param string $browserName The name of the browser.
  1666.      */
  1667.     protected function setBrowser($browserName)
  1668.     {
  1669.         $this->_browserName = $browserName;
  1670.     }
  1671.  
  1672.     /**
  1673.      * Set the browser to be from a mobile device or not.
  1674.      * @access protected
  1675.      * @param boolean $isMobile Value that tells if the browser is on a mobile device or not.
  1676.      */
  1677.     protected function setMobile($isMobile true)
  1678.     {
  1679.         $this->_isMobile = $isMobile == true;
  1680.     }
  1681.  
  1682.     /**
  1683.      * Set the platform on which the browser is on.
  1684.      * @access protected
  1685.      * @param string $platform The name of the platform.
  1686.      */
  1687.     protected function setPlatform($platform)
  1688.     {
  1689.         $this->_platform = $platform;
  1690.     }
  1691.  
  1692.     /**
  1693.      * Set the platform version on which the browser is on.
  1694.      * @access protected
  1695.      * @param string $platformVer The version numbers of the platform.
  1696.      */
  1697.     protected function setPlatformVersion($platformVer)
  1698.     {
  1699.         $this->_platformVersion = $platformVer;
  1700.     }
  1701.  
  1702.     /**
  1703.      * Set the browser to be a robot (crawler) or not.
  1704.      * @access protected
  1705.      * @param boolean $isRobot Value that tells if the browser is a robot or not.
  1706.      */
  1707.     protected function setRobot($isRobot true)
  1708.     {
  1709.         $this->_isRobot = $isRobot == true;
  1710.     }
  1711.  
  1712.     /**
  1713.      * Set the version of the browser.
  1714.      * @access protected
  1715.      * @param string $version The version of the browser.
  1716.      */
  1717.     protected function setVersion($version)
  1718.     {
  1719.         $cleanVer $this->cleanVersion($version);
  1720.  
  1721.         if ($cleanVer == ''{
  1722.             $this->_version = self::VERSION_UNKNOWN;
  1723.         else {
  1724.             $this->_version = $cleanVer;
  1725.         }
  1726.     }
  1727.  
  1728.     /**
  1729.      * Convert a WebKit build number to a Safari version number.
  1730.      * @access protected
  1731.      * @param string $version A string representing the version number.
  1732.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1733.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1734.      *  returned.
  1735.      */
  1736.     protected function webKitBuildToSafariVer($version)
  1737.     {
  1738.         $verParts explode('.'$version);
  1739.  
  1740.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1741.         while (count($verParts3{
  1742.             $verParts[0;
  1743.         }
  1744.         foreach ($verParts as $i => $currPart{
  1745.             $verParts[$i$this->parseInt($currPart);
  1746.         }
  1747.  
  1748.         switch ($verParts[0]{
  1749.             case 419$result '2.0.4';
  1750.                 break;
  1751.  
  1752.             case 418:
  1753.                 if ($verParts[1>= 8{
  1754.                     $result '2.0.4';
  1755.                 else {
  1756.                     $result '2.0.3';
  1757.                 }
  1758.                 break;
  1759.  
  1760.             case 417$result '2.0.3';
  1761.                 break;
  1762.  
  1763.             case 416$result '2.0.2';
  1764.                 break;
  1765.  
  1766.             case 412:
  1767.                 if ($verParts[1>= 7{
  1768.                     $result '2.0.1';
  1769.                 else {
  1770.                     $result '2.0';
  1771.                 }
  1772.                 break;
  1773.  
  1774.             case 312:
  1775.                 if ($verParts[1>= 8{
  1776.                     $result '1.3.2';
  1777.                 else {
  1778.                     if ($verParts[1>= 5{
  1779.                         $result '1.3.1';
  1780.                     else {
  1781.                         $result '1.3';
  1782.                     }
  1783.                 }
  1784.                 break;
  1785.  
  1786.             case 125:
  1787.                 if ($this->compareVersions('5.4'$verParts[1'.' $verParts[2]== -1{
  1788.                     $result '1.2.4'//125.5.5+
  1789.                 else {
  1790.                     if ($verParts[1>= 4{
  1791.                         $result '1.2.3';
  1792.                     else {
  1793.                         if ($verParts[1>= 2{
  1794.                             $result '1.2.2';
  1795.                         else {
  1796.                             $result '1.2';
  1797.                         }
  1798.                     }
  1799.                 }
  1800.                 break;
  1801.  
  1802.             //WebKit 100 can be either Safari 1.1 (Safari build 100) or 1.1.1 (Safari build 100.1)
  1803.             //for this reason, check the Safari build before the WebKit build.
  1804.             case 100$result '1.1.1';
  1805.                 break;
  1806.  
  1807.             case 85:
  1808.                 if ($verParts[1>= 8{
  1809.                     $result '1.0.3';
  1810.                 else {
  1811.                     if ($verParts[1>= 7{
  1812.                         //WebKit 85.7 can be either Safari 1.0 (Safari build 85.5) or 1.0.2 (Safari build 85.7)
  1813.                         //for this reason, check the Safari build before the WebKit build.
  1814.                         $result '1.0.2';
  1815.                     else {
  1816.                         $result '1.0';
  1817.                     }
  1818.                 }
  1819.                 break;
  1820.  
  1821.             case 73$result '0.9';
  1822.                 break;
  1823.             case 51$result '0.8.1';
  1824.                 break;
  1825.             case 48$result '0.8';
  1826.                 break;
  1827.  
  1828.             default$result '';
  1829.         }
  1830.  
  1831.         return $result;
  1832.     }
  1833.  
  1834.     /**
  1835.      * Convert the Windows NT family version numbers to the operating system name. For instance '5.1' returns
  1836.      * 'Windows XP'.
  1837.      * @access protected
  1838.      * @param string $winVer The Windows NT family version numbers as a string.
  1839.      * @param boolean $returnServerFlavor Since some Windows NT versions have the same values, this flag determines if
  1840.      *  the Server flavor is returned or not. For instance Windows 8.1 and Windows Server 2012 R2 both use version 6.3.
  1841.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  1842.      *  numbers.
  1843.      */
  1844.     protected function windowsNTVerToStr($winVer$returnServerFlavor false)
  1845.     {
  1846.         //https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
  1847.  
  1848.         $cleanWinVer explode('.'$winVer);
  1849.         while (count($cleanWinVer2{
  1850.             array_pop($cleanWinVer);
  1851.         }
  1852.         $cleanWinVer implode('.'$cleanWinVer);
  1853.  
  1854.         if ($this->compareVersions($cleanWinVer'11'>= 0{
  1855.             //Future versions of Windows
  1856.             return self::PLATFORM_WINDOWS ' ' $winVer;
  1857.         else if ($this->compareVersions($cleanWinVer'10'>= 0{
  1858.             //Current version of Windows
  1859.             return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2016'(self::PLATFORM_WINDOWS ' 10');
  1860.         else if ($this->compareVersions($cleanWinVer'7'0{
  1861.             if ($this->compareVersions($cleanWinVer'6.3'== 0{
  1862.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2012 R2'(self::PLATFORM_WINDOWS ' 8.1');
  1863.             else if ($this->compareVersions($cleanWinVer'6.2'== 0{
  1864.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2012'(self::PLATFORM_WINDOWS ' 8');
  1865.             else if ($this->compareVersions($cleanWinVer'6.1'== 0{
  1866.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2008 R2'(self::PLATFORM_WINDOWS ' 7');
  1867.             else if ($this->compareVersions($cleanWinVer'6'== 0{
  1868.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2008'(self::PLATFORM_WINDOWS ' Vista');
  1869.             else if ($this->compareVersions($cleanWinVer'5.2'== 0{
  1870.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2003 / ' self::PLATFORM_WINDOWS ' Server 2003 R2'(self::PLATFORM_WINDOWS ' XP x64 Edition');
  1871.             else if ($this->compareVersions($cleanWinVer'5.1'== 0{
  1872.                 return self::PLATFORM_WINDOWS ' XP';
  1873.             else if ($this->compareVersions($cleanWinVer'5'== 0{
  1874.                 return self::PLATFORM_WINDOWS ' 2000';
  1875.             else if ($this->compareVersions($cleanWinVer'5'&& $this->compareVersions($cleanWinVer'3'>= 0{
  1876.                 return self::PLATFORM_WINDOWS ' NT ' $winVer;
  1877.             }
  1878.         }
  1879.  
  1880.         return self::PLATFORM_VERSION_UNKNOWN//Invalid Windows NT version
  1881.     }
  1882.  
  1883.     /**
  1884.      * Convert the Windows 3.x & 9x family version numbers to the operating system name. For instance '4.10.1998'
  1885.      * returns 'Windows 98'.
  1886.      * @access protected
  1887.      * @param string $winVer The Windows 3.x or 9x family version numbers as a string.
  1888.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  1889.      *  numbers.
  1890.      */
  1891.     protected function windowsVerToStr($winVer)
  1892.     {
  1893.         //https://support.microsoft.com/en-us/kb/158238
  1894.  
  1895.         if ($this->compareVersions($winVer'4.90'>= && $this->compareVersions($winVer'4.91'0{
  1896.             return self::PLATFORM_WINDOWS ' Me'//Normally range from 4.90.3000 to 4.90.3000A
  1897.         else if ($this->compareVersions($winVer'4.10'>= && $this->compareVersions($winVer'4.11'0{
  1898.             return self::PLATFORM_WINDOWS ' 98'//Normally range from 4.10.1998 to 4.10.2222B
  1899.         else if ($this->compareVersions($winVer'4'>= && $this->compareVersions($winVer'4.04'0{
  1900.             return self::PLATFORM_WINDOWS ' 95'//Normally range from 4.00.950 to 4.03.1214
  1901.         else if ($this->compareVersions($winVer'3.1'== || $this->compareVersions($winVer'3.11'== 0{
  1902.             return self::PLATFORM_WINDOWS ' ' $winVer;
  1903.         else if ($this->compareVersions($winVer'3.10'== 0{
  1904.             return self::PLATFORM_WINDOWS ' 3.1';
  1905.         else {
  1906.             return self::PLATFORM_VERSION_UNKNOWN//Invalid Windows version
  1907.         }
  1908.     }
  1909. }

Documentation generated on Wed, 03 Aug 2016 00:47:29 +0200 by phpDocumentor 1.4.3