Advertisement
englishextra

lib_browser.inc

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