home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Net / UserAgent / Detect.php
Encoding:
PHP Script  |  2008-07-02  |  41.2 KB  |  968 lines

  1. <?php
  2. // {{{ license
  3.  
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4.2                                                      |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2007 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 2.0 of the PHP license,       |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/2_02.txt.                                 |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Dan Allen <dan@mojavelinux.com>                             |
  18. // |          Jason Rust <jrust@php.net>                                  |
  19. // +----------------------------------------------------------------------+
  20.  
  21. // $Id: Detect.php,v 1.26 2007/09/19 21:31:54 jrust Exp $
  22.  
  23. // }}}
  24. // {{{ constants
  25.  
  26. define('NET_USERAGENT_DETECT_BROWSER',  'browser');
  27. define('NET_USERAGENT_DETECT_OS',       'os');
  28. define('NET_USERAGENT_DETECT_FEATURES', 'features');
  29. define('NET_USERAGENT_DETECT_QUIRKS',   'quirks');
  30. define('NET_USERAGENT_DETECT_ACCEPT',   'accept');
  31. define('NET_USERAGENT_DETECT_ALL',      'all');
  32.  
  33. // }}}
  34. // {{{ class Net_UserAgent_Detect
  35.  
  36. /**
  37.  * The Net_UserAgent_Detect object does a number of tests on an HTTP user
  38.  * agent string.  The results of these tests are available via methods of
  39.  * the object.  Note that all methods in this class can be called
  40.  * statically.  The constructor and singleton methods are only retained
  41.  * for BC.
  42.  *
  43.  * This module is based upon the JavaScript browser detection code
  44.  * available at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
  45.  * This module had many influences from the lib/Browser.php code in
  46.  * version 1.3 of Horde.
  47.  *
  48.  * @author   Jason Rust <jrust@php.net>
  49.  * @author   Dan Allen <dan@mojavelinux.com>
  50.  * @author   Chuck Hagenbuch <chuck@horde.org>
  51.  * @author   Jon Parise <jon@horde.org>
  52.  * @package  Net_UserAgent
  53.  */
  54.  
  55. // }}}
  56. class Net_UserAgent_Detect {
  57.     // {{{ constructor
  58.  
  59.     function Net_UserAgent_Detect($in_userAgent = null, $in_detect = null)
  60.     {
  61.         $this->detect($in_userAgent, $in_detect);
  62.     }
  63.  
  64.     // }}}
  65.     // {{{ singleton
  66.  
  67.     /**
  68.      * To be used in place of the contructor to return only open instance.
  69.      *
  70.      * @access public 
  71.      * @return object Net_UserAgent_Detect instance
  72.      */
  73.     function &singleton($in_userAgent = null, $in_detect = null) 
  74.     {
  75.         static $instance;
  76.        
  77.         if (!isset($instance)) { 
  78.             $instance = new Net_UserAgent_Detect($in_userAgent, $in_detect); 
  79.         }
  80.         
  81.         return $instance; 
  82.     }
  83.  
  84.     // }}}
  85.     // {{{ detect()
  86.  
  87.     /**
  88.      * Detect the user agent and prepare flags, features and quirks
  89.      * based on what is found
  90.      *
  91.      * This is the core of the Net_UserAgent_Detect class.  It moves its
  92.      * way through the user agent string setting up the flags based on
  93.      * the vendors and versions of the browsers, determining the OS and
  94.      * setting up the features and quirks owned by each of the relevant
  95.      * clients.  Note that if you are going to be calling methods of
  96.      * this class statically then set all the parameters using th
  97.      * setOption()
  98.      *
  99.      * @param  string $in_userAgent (optional) User agent override.  
  100.      * @param  mixed $in_detect (optional) The level of checking to do. 
  101.      *
  102.      * @access public
  103.      * @return void
  104.      */
  105.     function detect($in_userAgent = null, $in_detect = null)
  106.     {
  107.         static $hasRun;
  108.         $options = &Net_UserAgent_Detect::_getStaticProperty('options');
  109.         if (!empty($hasRun) && empty($options['re-evaluate'])) {
  110.             return;
  111.         }
  112.  
  113.         $hasRun = true;
  114.         // {{{ set up static properties
  115.  
  116.         $in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : $in_userAgent;
  117.         $in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : $in_detect;
  118.  
  119.         // User agent string that is being analyzed
  120.         $userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent');
  121.  
  122.         // Array that stores all of the flags for the vendor and version
  123.         // of the different browsers
  124.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  125.         $browser = array_flip(array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'belowns6', 'ns6up', 'firefox', 'firefox0.x', 'firefox1.x', 'firefox1.5', 'firefox2.x', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'belowie6', 'ie6up', 'ie7', 'ie7up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera6', 'opera7', 'opera8', 'opera9', 'opera5up', 'opera6up', 'opera7up', 'belowopera8', 'opera8up', 'opera9up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'aol8', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up', 'konq', 'safari', 'netgem', 'webdav', 'icab'));
  126.         
  127.         // Array that stores all of the flags for the operating systems,
  128.         // and in some cases the versions of those operating systems (windows)
  129.         $os = &Net_UserAgent_Detect::_getStaticProperty('os');
  130.         $os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd'));
  131.  
  132.         // Array which stores known issues with the given client that can
  133.         // be used for on the fly tweaking so that the client may recieve
  134.         // the proper handling of this quirk.
  135.         $quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
  136.         $quirks = array(
  137.                 'must_cache_forms'         => false,
  138.                 'popups_disabled'          => false,
  139.                 'empty_file_input_value'   => false,
  140.                 'cache_ssl_downloads'      => false,
  141.                 'scrollbar_in_way'         => false,
  142.                 'break_disposition_header' => false,
  143.                 'nested_table_render_bug'  => false);
  144.  
  145.         // Array that stores credentials for each of the browser/os
  146.         // combinations.  These allow quick access to determine if the
  147.         // current client has a feature that is going to be implemented
  148.         // in the script.
  149.         $features = &Net_UserAgent_Detect::_getStaticProperty('features');
  150.         $features = array(
  151.                 'javascript'   => false,
  152.                 'dhtml'        => false,
  153.                 'dom'          => false,
  154.                 'sidebar'      => false,
  155.                 'gecko'        => false,
  156.                 'svg'          => false,
  157.                 'css2'         => false,
  158.                 'ajax'         => false);
  159.  
  160.         // The leading identifier is the very first term in the user
  161.         // agent string, which is used to identify clients which are not
  162.         // Mosaic-based browsers.
  163.         $leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier');
  164.  
  165.         // The full version of the client as supplied by the very first
  166.         // numbers in the user agent
  167.         $version = &Net_UserAgent_Detect::_getStaticProperty('version');
  168.         $version = 0;
  169.  
  170.         // The major part of the client version, which is the integer
  171.         // value of the version.
  172.         $majorVersion = &Net_UserAgent_Detect::_getStaticProperty('majorVersion');
  173.         $majorVersion = 0;
  174.  
  175.         // The minor part of the client version, which is the decimal
  176.         // parts of the version
  177.         $subVersion = &Net_UserAgent_Detect::_getStaticProperty('subVersion');
  178.         $subVersion = 0;
  179.  
  180.         // }}}
  181.         // detemine what user agent we are using
  182.         if (is_null($in_userAgent)) {
  183.             if (isset($_SERVER['HTTP_USER_AGENT'])) {
  184.                 $userAgent = $_SERVER['HTTP_USER_AGENT'];
  185.             }
  186.             elseif (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'])) {
  187.                 $userAgent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
  188.             }
  189.             else {
  190.                 $userAgent = '';
  191.             }
  192.         }
  193.         else {
  194.             $userAgent = $in_userAgent;
  195.         }
  196.  
  197.         // get the lowercase version for case-insensitive searching
  198.         $agt = strtolower($userAgent);
  199.  
  200.         // figure out what we need to look for
  201.         $detectOptions = array(NET_USERAGENT_DETECT_BROWSER,
  202.                 NET_USERAGENT_DETECT_OS, NET_USERAGENT_DETECT_FEATURES,
  203.                 NET_USERAGENT_DETECT_QUIRKS, NET_USERAGENT_DETECT_ACCEPT, 
  204.                 NET_USERAGENT_DETECT_ALL);
  205.         $detect = is_null($in_detect) ? NET_USERAGENT_DETECT_ALL : $in_detect;
  206.         settype($detect, 'array');
  207.         foreach($detectOptions as $option) {
  208.             if (in_array($option, $detect)) {
  209.                 $detectFlags[$option] = true; 
  210.             }
  211.             else {
  212.                 $detectFlags[$option] = false;
  213.             }
  214.         }
  215.  
  216.         // initialize the arrays of browsers and operating systems
  217.  
  218.         // Get the type and version of the client
  219.         if (preg_match(";^([[:alnum:]]+)[ /\(]*[[:alpha:]]*([\d]*)(\.[\d\.]*);", $agt, $matches)) {
  220.             list(, $leadingIdentifier, $majorVersion, $subVersion) = $matches;
  221.         }
  222.  
  223.         if (empty($leadingIdentifier)) {
  224.             $leadingIdentifier = 'Unknown';
  225.         }
  226.  
  227.         $version = $majorVersion . $subVersion;
  228.     
  229.         // Browser type
  230.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_BROWSER]) {
  231.             $browser['webdav']  = ($agt == 'microsoft data access internet publishing provider dav' || $agt == 'microsoft data access internet publishing provider protocol discovery');
  232.             $browser['konq']    = $browser['safari'] = (strpos($agt, 'konqueror') !== false || strpos($agt, 'safari') !== false);
  233.             $browser['text']    = strpos($agt, 'links') !== false || strpos($agt, 'lynx') !== false || strpos($agt, 'w3m') !== false;
  234.             $browser['ns']      = strpos($agt, 'mozilla') !== false && !(strpos($agt, 'spoofer') !== false) && !(strpos($agt, 'compatible') !== false) && !(strpos($agt, 'hotjava') !== false) && !(strpos($agt, 'opera') !== false) && !(strpos($agt, 'webtv') !== false) ? 1 : 0;
  235.             $browser['netgem']  = strpos($agt, 'netgem') !== false;
  236.             $browser['icab']    = strpos($agt, 'icab') !== false;
  237.             $browser['ns2']     = $browser['ns'] && $majorVersion == 2;
  238.             $browser['ns3']     = $browser['ns'] && $majorVersion == 3;
  239.             $browser['ns4']     = $browser['ns'] && $majorVersion == 4;
  240.             $browser['ns4up']   = $browser['ns'] && $majorVersion >= 4;
  241.             // determine if this is a Netscape Navigator
  242.             $browser['nav'] = $browser['belowns6'] = $browser['ns'] && $majorVersion < 5;
  243.             $browser['ns6']     = !$browser['konq'] && $browser['ns'] && $majorVersion == 5;
  244.             $browser['ns6up']   = $browser['ns6'] && $majorVersion >= 5;
  245.             $browser['gecko']   = strpos($agt, 'gecko') !== false && !$browser['konq'];
  246.             $browser['firefox'] = $browser['gecko'] && strpos($agt, 'firefox') !== false;
  247.             $browser['firefox0.x'] = $browser['firefox'] && strpos($agt, 'firefox/0.') !== false;
  248.             $browser['firefox1.x'] = $browser['firefox'] && strpos($agt, 'firefox/1.') !== false;
  249.             $browser['firefox1.5'] = $browser['firefox'] && strpos($agt, 'firefox/1.5') !== false;
  250.             $browser['firefox2.x'] = $browser['firefox'] && strpos($agt, 'firefox/2.') !== false;
  251.             $browser['ie']      = strpos($agt, 'msie') !== false && !(strpos($agt, 'opera') !== false);
  252.             $browser['ie3']     = $browser['ie'] && $majorVersion < 4;
  253.             $browser['ie4']     = $browser['ie'] && $majorVersion == 4 && (strpos($agt, 'msie 4') !== false);
  254.             $browser['ie4up']   = $browser['ie'] && !$browser['ie3'];
  255.             $browser['ie5']     = $browser['ie4up'] && (strpos($agt, 'msie 5') !== false);
  256.             $browser['ie5_5']   = $browser['ie4up'] && (strpos($agt, 'msie 5.5') !== false);
  257.             $browser['ie5up']   = $browser['ie4up'] && !$browser['ie3'] && !$browser['ie4'];
  258.             $browser['ie5_5up'] = $browser['ie5up'] && !$browser['ie5'];
  259.             $browser['ie6']     = strpos($agt, 'msie 6') !== false;
  260.             $browser['ie6up']   = $browser['ie5up'] && !$browser['ie5'] && !$browser['ie5_5'];
  261.             $browser['ie7']     = strpos($agt, 'msie 7') !== false;
  262.             $browser['ie7up']   = $browser['ie6up'] && !$browser['ie6'];
  263.             $browser['belowie6']= $browser['ie'] && !$browser['ie6up'];
  264.             $browser['opera']   = strpos($agt, 'opera') !== false;
  265.             $browser['opera2']  = strpos($agt, 'opera 2') !== false || strpos($agt, 'opera/2') !== false;
  266.             $browser['opera3']  = strpos($agt, 'opera 3') !== false || strpos($agt, 'opera/3') !== false;
  267.             $browser['opera4']  = strpos($agt, 'opera 4') !== false || strpos($agt, 'opera/4') !== false;
  268.             $browser['opera5']  = strpos($agt, 'opera 5') !== false || strpos($agt, 'opera/5') !== false;
  269.             $browser['opera6']  = strpos($agt, 'opera 6') !== false || strpos($agt, 'opera/6') !== false;
  270.             $browser['opera7']  = strpos($agt, 'opera 7') !== false || strpos($agt, 'opera/7') !== false;
  271.             $browser['opera8']  = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/8') !== false;
  272.             $browser['opera9']  = strpos($agt, 'opera 9') !== false || strpos($agt, 'opera/9') !== false;
  273.             $browser['opera5up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'];
  274.             $browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'];
  275.             $browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'];
  276.             $browser['opera8up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'] && !$browser['opera7'];
  277.             $browser['opera9up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'] && !$browser['opera7'] && !$browser['opera8'];
  278.             $browser['belowopera8'] = $browser['opera'] && !$browser['opera8up'];
  279.             $browser['aol']   = strpos($agt, 'aol') !== false;
  280.             $browser['aol3']  = $browser['aol'] && $browser['ie3'];
  281.             $browser['aol4']  = $browser['aol'] && $browser['ie4'];
  282.             $browser['aol5']  = strpos($agt, 'aol 5') !== false;
  283.             $browser['aol6']  = strpos($agt, 'aol 6') !== false;
  284.             $browser['aol7']  = strpos($agt, 'aol 7') !== false || strpos($agt, 'aol7') !== false;
  285.             $browser['aol8']  = strpos($agt, 'aol 8') !== false || strpos($agt, 'aol8') !== false;
  286.             $browser['webtv'] = strpos($agt, 'webtv') !== false; 
  287.             $browser['aoltv'] = $browser['tvnavigator'] = strpos($agt, 'navio') !== false || strpos($agt, 'navio_aoltv') !== false; 
  288.             $browser['hotjava'] = strpos($agt, 'hotjava') !== false;
  289.             $browser['hotjava3'] = $browser['hotjava'] && $majorVersion == 3;
  290.             $browser['hotjava3up'] = $browser['hotjava'] && $majorVersion >= 3;
  291.             $browser['iemobile'] = strpos($agt, 'iemobile') !== false || strpos($agt, 'windows ce') !== false && (strpos($agt, 'ppc') !== false || strpos($agt, 'smartphone') !== false);
  292.         }
  293.  
  294.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || 
  295.             ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) {
  296.             // Javascript Check
  297.             if ($browser['ns2'] || $browser['ie3']) {
  298.                 Net_UserAgent_Detect::setFeature('javascript', 1.0);
  299.             }
  300.             elseif ($browser['iemobile']) {
  301.               // no javascript
  302.             }
  303.             elseif ($browser['opera5up']) {
  304.                 Net_UserAgent_Detect::setFeature('javascript', 1.3);
  305.             }
  306.             elseif ($browser['opera'] || $browser['ns3']) {
  307.                 Net_UserAgent_Detect::setFeature('javascript', 1.1);
  308.             }
  309.             elseif (($browser['ns4'] && ($version <= 4.05)) || $browser['ie4']) {
  310.                 Net_UserAgent_Detect::setFeature('javascript', 1.2);
  311.             }
  312.             elseif (($browser['ie5up'] && strpos($agt, 'mac') !== false) || $browser['konq']) {
  313.                 Net_UserAgent_Detect::setFeature('javascript', 1.4);
  314.             }
  315.             // I can't believe IE6 still has javascript 1.3, what a shitty browser
  316.             elseif (($browser['ns4'] && ($version > 4.05)) || $browser['ie5up'] || $browser['hotjava3up']) {
  317.                 Net_UserAgent_Detect::setFeature('javascript', 1.3);
  318.             }
  319.             elseif ($browser['ns6up'] || $browser['gecko'] || $browser['netgem']) {
  320.                 Net_UserAgent_Detect::setFeature('javascript', 1.5);
  321.             }
  322.         }
  323.         
  324.         /** OS Check **/
  325.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_OS]) {
  326.             $os['win']   = strpos($agt, 'win') !== false || strpos($agt, '16bit') !== false;
  327.             $os['win95'] = strpos($agt, 'win95') !== false || strpos($agt, 'windows 95') !== false;
  328.             $os['win16'] = strpos($agt, 'win16') !== false || strpos($agt, '16bit') !== false || strpos($agt, 'windows 3.1') !== false || strpos($agt, 'windows 16-bit') !== false;  
  329.             $os['win31'] = strpos($agt, 'windows 3.1') !== false || strpos($agt, 'win16') !== false || strpos($agt, 'windows 16-bit') !== false;
  330.             $os['winme'] = strpos($agt, 'win 9x 4.90') !== false;
  331.             $os['wince'] = strpos($agt, 'windows ce') !== false;
  332.             $os['win2k'] = strpos($agt, 'windows nt 5.0') !== false;
  333.             $os['winxp'] = strpos($agt, 'windows nt 5.1') !== false;
  334.             $os['win2003'] = strpos($agt, 'windows nt 5.2') !== false;
  335.             $os['win98'] = strpos($agt, 'win98') !== false || strpos($agt, 'windows 98') !== false;
  336.             $os['win9x'] = $os['win95'] || $os['win98'];
  337.             $os['winnt'] = (strpos($agt, 'winnt') !== false || strpos($agt, 'windows nt') !== false) && strpos($agt, 'windows nt 5') === false;
  338.             $os['win32'] = $os['win95'] || $os['winnt'] || $os['win98'] || $majorVersion >= 4 && strpos($agt, 'win32') !== false || strpos($agt, '32bit') !== false;
  339.             $os['os2']   = strpos($agt, 'os/2') !== false || strpos($agt, 'ibm-webexplorer') !== false;
  340.             $os['mac']   = strpos($agt, 'mac') !== false;
  341.             $os['mac68k']   = $os['mac'] && (strpos($agt, '68k') !== false || strpos($agt, '68000') !== false);
  342.             $os['macppc']   = $os['mac'] && (strpos($agt, 'ppc') !== false || strpos($agt, 'powerpc') !== false);
  343.             $os['sun']      = strpos($agt, 'sunos') !== false;
  344.             $os['sun4']     = strpos($agt, 'sunos 4') !== false;
  345.             $os['sun5']     = strpos($agt, 'sunos 5') !== false;
  346.             $os['suni86']   = $os['sun'] && strpos($agt, 'i86') !== false;
  347.             $os['irix']     = strpos($agt, 'irix') !== false;
  348.             $os['irix5']    = strpos($agt, 'irix 5') !== false;
  349.             $os['irix6']    = strpos($agt, 'irix 6') !== false || strpos($agt, 'irix6') !== false;
  350.             $os['hpux']     = strpos($agt, 'hp-ux') !== false;
  351.             $os['hpux9']    = $os['hpux'] && strpos($agt, '09.') !== false;
  352.             $os['hpux10']   = $os['hpux'] && strpos($agt, '10.') !== false;
  353.             $os['aix']      = strpos($agt, 'aix') !== false;
  354.             $os['aix1']     = strpos($agt, 'aix 1') !== false;
  355.             $os['aix2']     = strpos($agt, 'aix 2') !== false;
  356.             $os['aix3']     = strpos($agt, 'aix 3') !== false;
  357.             $os['aix4']     = strpos($agt, 'aix 4') !== false;
  358.             $os['linux']    = strpos($agt, 'inux') !== false;
  359.             $os['sco']      = strpos($agt, 'sco') !== false || strpos($agt, 'unix_sv') !== false;
  360.             $os['unixware'] = strpos($agt, 'unix_system_v') !== false; 
  361.             $os['mpras']    = strpos($agt, 'ncr') !== false; 
  362.             $os['reliant']  = strpos($agt, 'reliant') !== false;
  363.             $os['dec']      = strpos($agt, 'dec') !== false || strpos($agt, 'osf1') !== false || strpos($agt, 'dec_alpha') !== false || strpos($agt, 'alphaserver') !== false || strpos($agt, 'ultrix') !== false || strpos($agt, 'alphastation') !== false;
  364.             $os['sinix']    = strpos($agt, 'sinix') !== false;
  365.             $os['freebsd']  = strpos($agt, 'freebsd') !== false;
  366.             $os['bsd']      = strpos($agt, 'bsd') !== false;
  367.             $os['unix']     = strpos($agt, 'x11') !== false || strpos($agt, 'unix') !== false || $os['sun'] || $os['irix'] || $os['hpux'] || $os['sco'] || $os['unixware'] || $os['mpras'] || $os['reliant'] || $os['dec'] || $os['sinix'] || $os['aix'] || $os['linux'] || $os['bsd'] || $os['freebsd'];
  368.             $os['vms']      = strpos($agt, 'vax') !== false || strpos($agt, 'openvms') !== false;
  369.         }
  370.  
  371.         // Setup the quirks
  372.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || 
  373.             ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_QUIRKS])) {
  374.             if ($browser['konq']) {
  375.                 Net_UserAgent_Detect::setQuirk('empty_file_input_value');
  376.             }
  377.  
  378.             if ($browser['ie']) {
  379.                 Net_UserAgent_Detect::setQuirk('cache_ssl_downloads');
  380.             }
  381.  
  382.             if ($browser['ie6']) {
  383.                 Net_UserAgent_Detect::setQuirk('scrollbar_in_way');
  384.             }
  385.  
  386.             if ($browser['ie5']) {
  387.                 Net_UserAgent_Detect::setQuirk('break_disposition_header');
  388.             }
  389.  
  390.             if ($browser['ie7']) {
  391.                 Net_UserAgent_Detect::setQuirk('popups_disabled');
  392.             }
  393.  
  394.             if ($browser['ns6']) {
  395.                 Net_UserAgent_Detect::setQuirk('popups_disabled');
  396.                 Net_UserAgent_Detect::setQuirk('must_cache_forms');
  397.             }
  398.             
  399.             if ($browser['nav'] && $subVersion < .79) {
  400.                 Net_UserAgent_Detect::setQuirk('nested_table_render_bug');
  401.             }
  402.         }
  403.             
  404.         // Set features
  405.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || 
  406.             ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) {
  407.             if ($browser['gecko']) {
  408.                 preg_match(';gecko/([\d]+)\b;i', $agt, $matches);
  409.                 Net_UserAgent_Detect::setFeature('gecko', $matches[1]);
  410.             }
  411.  
  412.             if ($browser['gecko'] || ($browser['ie5up'] && !$browser['iemobile']) || $browser['konq'] || $browser['opera8up'] && !$os['wince']) {
  413.                 Net_UserAgent_Detect::setFeature('ajax');
  414.             }
  415.  
  416.             if ($browser['ns6up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) {
  417.                 Net_UserAgent_Detect::setFeature('dom');
  418.             }
  419.  
  420.             if ($browser['ie4up'] || $browser['ns4up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) {
  421.                 Net_UserAgent_Detect::setFeature('dhtml');
  422.             }
  423.  
  424.             if ($browser['firefox1.5'] || $browser['firefox2.x'] || $browser['opera9up']) {
  425.                 Net_UserAgent_Detect::setFeature('svg');
  426.             }
  427.  
  428.             if ($browser['gecko'] || $browser['ns6up'] || $browser['ie5up'] || $browser['konq'] || $browser['opera7up']) {
  429.                 Net_UserAgent_Detect::setFeature('css2');
  430.             }
  431.         }
  432.  
  433.         if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_ACCEPT]) {
  434.             $mimetypes = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT'), 0, strpos(getenv('HTTP_ACCEPT') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
  435.             Net_UserAgent_Detect::setAcceptType((array) $mimetypes, 'mimetype');
  436.  
  437.             $languages = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, strpos(getenv('HTTP_ACCEPT_LANGUAGE') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
  438.             if (empty($languages)) {
  439.                 $languages = 'en';
  440.             }
  441.  
  442.             Net_UserAgent_Detect::setAcceptType((array) $languages, 'language');
  443.  
  444.             $encodings = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_ENCODING'), 0, strpos(getenv('HTTP_ACCEPT_ENCODING') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
  445.             Net_UserAgent_Detect::setAcceptType((array) $encodings, 'encoding');
  446.             
  447.             $charsets = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_CHARSET'), 0, strpos(getenv('HTTP_ACCEPT_CHARSET') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
  448.             Net_UserAgent_Detect::setAcceptType((array) $charsets, 'charset');
  449.         }
  450.     }
  451.     
  452.     // }}}
  453.     // {{{ setOption()
  454.  
  455.     /**
  456.      * Sets a class option.  The available settings are:
  457.      * o 'userAgent' => The user agent string to detect (useful for
  458.      * checking a string manually).
  459.      * o 'detectOptions' => The level of checking to do.  A single level
  460.      * or an array of options.  Default is NET_USERAGENT_DETECT_ALL.
  461.      *
  462.      * @param string $in_field The option field (userAgent or detectOptions)
  463.      * @param mixed $in_value The value for the field
  464.      */
  465.     function setOption($in_field, $in_value)
  466.     {
  467.         $options = &Net_UserAgent_Detect::_getStaticProperty('options');
  468.         $options[$in_field] = $in_value;
  469.     }
  470.  
  471.     // }}}
  472.     // {{{ isBrowser()
  473.  
  474.     /**
  475.      * Look up the provide browser flag and return a boolean value
  476.      *
  477.      * Given one of the flags listed in the properties, this function will return
  478.      * the value associated with that flag.
  479.      *
  480.      * @param  string $in_match flag to lookup
  481.      *
  482.      * @access public
  483.      * @return boolean whether or not the browser satisfies this flag
  484.      */
  485.     function isBrowser($in_match)
  486.     {
  487.         Net_UserAgent_Detect::detect();
  488.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  489.         return isset($browser[strtolower($in_match)]) ? $browser[strtolower($in_match)] : false;
  490.     }
  491.  
  492.     // }}}
  493.     // {{{ getBrowser()
  494.  
  495.     /**
  496.      * Since simply returning the "browser" is somewhat ambiguous since there
  497.      * are different ways to classify the browser, this function works by taking
  498.      * an expect list and returning the string of the first match, so put the important
  499.      * ones first in the array.
  500.      *
  501.      * @param  array $in_expectList the browser flags to search for
  502.      *
  503.      * @access public
  504.      * @return string first flag that matches
  505.      */
  506.     function getBrowser($in_expectList)
  507.     {
  508.         Net_UserAgent_Detect::detect();
  509.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  510.         foreach((array) $in_expectList as $brwsr) {
  511.             if (!empty($browser[strtolower($brwsr)])) {
  512.                 return $brwsr;
  513.             }
  514.         }
  515.     }
  516.  
  517.     // }}}
  518.     // {{{ getBrowserString()
  519.  
  520.     /**
  521.      * This function returns the vendor string corresponding to the flag.
  522.      *
  523.      * Either use the default matches or pass in an associative array of
  524.      * flags and corresponding vendor strings.  This function will find
  525.      * the highest version flag and return the vendor string corresponding
  526.      * to the appropriate flag.  Be sure to pass in the flags in ascending order
  527.      * if you want a basic matches first, followed by more detailed matches.
  528.      *
  529.      * @param  array $in_vendorStrings (optional) array of flags matched with vendor strings
  530.      *
  531.      * @access public
  532.      * @return string vendor string matches appropriate flag
  533.      */
  534.     function getBrowserString($in_vendorStrings = null)
  535.     {
  536.         if (is_null($in_vendorStrings)) {
  537.             $in_vendorStrings = array (
  538.                     'ie'       => 'Microsoft Internet Explorer',
  539.                     'ie4up'    => 'Microsoft Internet Explorer 4.x',
  540.                     'ie5up'    => 'Microsoft Internet Explorer 5.x',
  541.                     'ie6up'    => 'Microsoft Internet Explorer 6.x',
  542.                     'ie7up'    => 'Microsoft Internet Explorer 7.x',
  543.                     'opera4'   => 'Opera 4.x',
  544.                     'opera5up' => 'Opera 5.x',
  545.                     'nav'      => 'Netscape Navigator',
  546.                     'ns4'      => 'Netscape 4.x',
  547.                     'ns6up'    => 'Mozilla/Netscape 6.x',
  548.                     'firefox0.x' => 'Firefox 0.x',
  549.                     'firefox1.x' => 'Firefox 1.x',
  550.                     'firefox1.5' => 'Firefox 1.5',
  551.                     'firefox2.x' => 'Firefox 2.x',
  552.                     'konq'     => 'Konqueror/Safari',
  553.                     'netgem'   => 'Netgem/iPlayer');
  554.         }
  555.  
  556.         Net_UserAgent_Detect::detect();
  557.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  558.         foreach((array) $in_vendorStrings as $flag => $string) {
  559.             if (!empty($browser[$flag])) {
  560.                 $vendorString = $string;
  561.             }
  562.         }
  563.  
  564.         // if there are no matches just use the user agent leading idendifier (usually Mozilla)
  565.         if (!isset($vendorString)) {
  566.             $leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier');
  567.             $vendorString = $leadingIdentifier;
  568.         }
  569.         
  570.         return $vendorString;
  571.     }
  572.  
  573.     // }}}
  574.     // {{{ isIE()
  575.  
  576.     /**
  577.      * Determine if the browser is an Internet Explorer browser
  578.      *
  579.      * @access public
  580.      * @return bool whether or not this browser is an ie browser
  581.      */
  582.     function isIE()
  583.     {
  584.         Net_UserAgent_Detect::detect();
  585.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  586.         return !empty($browser['ie']);
  587.     }
  588.  
  589.     // }}}
  590.     // {{{ isNavigator()
  591.  
  592.     /**
  593.      * Determine if the browser is a Netscape Navigator browser
  594.      *
  595.      * @access public
  596.      * @return bool whether or not this browser is a Netscape Navigator browser
  597.      */
  598.     function isNavigator()
  599.     {
  600.         Net_UserAgent_Detect::detect();
  601.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  602.         return !empty($browser['nav']);
  603.     }
  604.  
  605.     // }}}
  606.     // {{{ isNetscape()
  607.  
  608.     /**
  609.      * Determine if the browser is a Netscape or Mozilla browser
  610.      *
  611.      * Note that this function is not the same as isNavigator, since the
  612.      * new Mozilla browsers are still sponsered by Netscape, and hence are
  613.      * Netscape products, but not the original Navigators
  614.      *
  615.      * @access public
  616.      * @return bool whether or not this browser is a Netscape product
  617.      */
  618.     function isNetscape()
  619.     {
  620.         Net_UserAgent_Detect::detect();
  621.         $browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
  622.         return !empty($browser['ns4up']);
  623.     }
  624.     
  625.     // }}}
  626.     // {{{ isOS()
  627.  
  628.     /**
  629.      * Look up the provide OS flag and return a boolean value
  630.      *
  631.      * Given one of the flags listed in the properties, this function will return
  632.      * the value associated with that flag for the operating system.
  633.      *
  634.      * @param  string $in_match flag to lookup
  635.      *
  636.      * @access public
  637.      * @return boolean whether or not the OS satisfies this flag
  638.      */
  639.     function isOS($in_match)
  640.     {
  641.         Net_UserAgent_Detect::detect();
  642.         $os = &Net_UserAgent_Detect::_getStaticProperty('os');
  643.         return isset($os[strtolower($in_match)]) ? $os[strtolower($in_match)] : false;
  644.     }
  645.  
  646.     // }}}
  647.     // {{{ getOS()
  648.  
  649.     /**
  650.      * Since simply returning the "os" is somewhat ambiguous since there
  651.      * are different ways to classify the browser, this function works by taking
  652.      * an expect list and returning the string of the first match, so put the important
  653.      * ones first in the array.
  654.      *
  655.      * @access public
  656.      * @return string first flag that matches
  657.      */
  658.     function getOS($in_expectList)
  659.     {
  660.         Net_UserAgent_Detect::detect();
  661.         $os = &Net_UserAgent_Detect::_getStaticProperty('os');
  662.         foreach((array) $in_expectList as $expectOs) {
  663.             if (!empty($os[strtolower($expectOs)])) {
  664.                 return $expectOs;
  665.             }
  666.         }
  667.     }
  668.  
  669.     // }}}
  670.     // {{{ getOSString()
  671.  
  672.     /**
  673.      * This function returns the os string corresponding to the flag.
  674.      *
  675.      * Either use the default matches or pass in an associative array of
  676.      * flags and corresponding os strings.  This function will find
  677.      * the highest version flag and return the os string corresponding
  678.      * to the appropriate flag.  Be sure to pass in the flags in ascending order
  679.      * if you want a basic matches first, followed by more detailed matches.
  680.      *
  681.      * @param  array $in_osStrings (optional) array of flags matched with os strings
  682.      *
  683.      * @access public
  684.      * @return string os string matches appropriate flag
  685.      */
  686.     function getOSString($in_osStrings = null)
  687.     {
  688.         if (is_null($in_osStrings)) {
  689.             $in_osStrings = array(
  690.                    'win'   => 'Microsoft Windows',
  691.                    'wince' => 'Microsoft Windows CE',
  692.                    'win9x' => 'Microsoft Windows 9x',
  693.                    'winme' => 'Microsoft Windows Millenium',
  694.                    'win2k' => 'Microsoft Windows 2000',
  695.                    'winnt' => 'Microsoft Windows NT',
  696.                    'winxp' => 'Microsoft Windows XP',
  697.                    'win2003' => 'Microsoft Windows 2003',
  698.                    'mac'   => 'Macintosh',
  699.                    'unix'  => 'Linux/Unix');
  700.         }
  701.  
  702.         Net_UserAgent_Detect::detect();
  703.         $osString = 'Unknown';
  704.  
  705.         $os = &Net_UserAgent_Detect::_getStaticProperty('os');
  706.         foreach((array) $in_osStrings as $flag => $string) {
  707.             if (!empty($os[$flag])) {
  708.                 $osString = $string;
  709.             }
  710.         }
  711.  
  712.         return $osString;
  713.     }
  714.  
  715.     // }}}
  716.     // {{{ setQuirk()
  717.  
  718.     /**
  719.      * Set a unique behavior for the current browser.
  720.      *
  721.      * Many client browsers do some really funky things, and this
  722.      * mechanism allows the coder to determine if an excepetion must
  723.      * be made with the current client.
  724.      *
  725.      * @param string $in_quirk The quirk to set
  726.      * @param string $in_hasQuirk (optional) Does the browser have the quirk?
  727.      *
  728.      * @access public
  729.      * @return void
  730.      */
  731.     function setQuirk($in_quirk, $in_hasQuirk = true)
  732.     {
  733.         $quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
  734.         $hasQuirk = !empty($in_hasQuirk); 
  735.         $quirks[strtolower($in_quirk)] = $hasQuirk;
  736.     }
  737.  
  738.     // }}}
  739.     // {{{ hasQuirk()
  740.  
  741.     /**
  742.      * Check a unique behavior for the current browser.
  743.      *
  744.      * Many client browsers do some really funky things, and this
  745.      * mechanism allows the coder to determine if an excepetion must
  746.      * be made with the current client.
  747.      *
  748.      * @param string $in_quirk The quirk to detect
  749.      *
  750.      * @access public
  751.      * @return bool whether or not browser has this quirk
  752.      */
  753.     function hasQuirk($in_quirk)
  754.     {
  755.         return (bool) Net_UserAgent_Detect::getQuirk($in_quirk);
  756.     }
  757.     
  758.     // }}}
  759.     // {{{ getQuirk()
  760.  
  761.     /**
  762.      * Get the unique behavior for the current browser.
  763.      *
  764.      * Many client browsers do some really funky things, and this
  765.      * mechanism allows the coder to determine if an excepetion must
  766.      * be made with the current client.
  767.      *
  768.      * @param string $in_quirk The quirk to detect
  769.      *
  770.      * @access public
  771.      * @return string value of the quirk, in this case usually a boolean
  772.      */
  773.     function getQuirk($in_quirk)
  774.     {
  775.         Net_UserAgent_Detect::detect();
  776.         $quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
  777.         return isset($quirks[strtolower($in_quirk)]) ? $quirks[strtolower($in_quirk)] : null; 
  778.     }
  779.  
  780.     // }}}
  781.     // {{{ setFeature()
  782.  
  783.     /**
  784.      * Set capabilities for the current browser.
  785.      *
  786.      * Since the capabilities of client browsers vary widly, this interface
  787.      * helps keep track of the core features of a client, such as if the client
  788.      * supports dhtml, dom, javascript, etc.
  789.      *
  790.      * @param string $in_feature The feature to set
  791.      * @param string $in_hasFeature (optional) Does the browser have the feature?
  792.      *
  793.      * @access public
  794.      * @return void
  795.      */
  796.     function setFeature($in_feature, $in_hasFeature = true)
  797.     {
  798.         $features = &Net_UserAgent_Detect::_getStaticProperty('features');
  799.         $features[strtolower($in_feature)] = $in_hasFeature;
  800.     }
  801.  
  802.     // }}}
  803.     // {{{ hasFeature()
  804.  
  805.     /**
  806.      * Check the capabilities for the current browser.
  807.      *
  808.      * Since the capabilities of client browsers vary widly, this interface
  809.      * helps keep track of the core features of a client, such as if the client
  810.      * supports dhtml, dom, javascript, etc.
  811.      *
  812.      * @param string $in_feature The feature to detect
  813.      *
  814.      * @access public
  815.      * @return bool whether or not the current client has this feature
  816.      */
  817.     function hasFeature($in_feature)
  818.     {
  819.         return (bool) Net_UserAgent_Detect::getFeature($in_feature);
  820.     }
  821.     
  822.     // }}}
  823.     // {{{ getFeature()
  824.  
  825.     /**
  826.      * Get the capabilities for the current browser.
  827.      *
  828.      * Since the capabilities of client browsers vary widly, this interface
  829.      * helps keep track of the core features of a client, such as if the client
  830.      * supports dhtml, dom, javascript, etc.
  831.      *
  832.      * @param string $in_feature The feature to detect
  833.      *
  834.      * @access public
  835.      * @return string value of the feature requested
  836.      */
  837.     function getFeature($in_feature)
  838.     {
  839.         Net_UserAgent_Detect::detect();
  840.         $features = &Net_UserAgent_Detect::_getStaticProperty('features');
  841.         return isset($features[strtolower($in_feature)]) ? $features[strtolower($in_feature)] : null; 
  842.     }
  843.  
  844.     // }}}
  845.     // {{{ getAcceptType()
  846.  
  847.     /**
  848.      * Retrive the accept type for the current browser.
  849.      *
  850.      * To keep track of the mime-types, languages, charsets and encodings
  851.      * that each browser accepts we use associative arrays for each type.
  852.      * This function works like getBrowser() as it takes an expect list
  853.      * and returns the first match.  For instance, to find the language
  854.      * you would pass in your allowed languages and see if any of the
  855.      * languages set in the browser match.
  856.      *
  857.      * @param  string $in_expectList values to check
  858.      * @param  string $in_type type of accept
  859.      *
  860.      * @access public
  861.      * @return string the first matched value
  862.      */
  863.     function getAcceptType($in_expectList, $in_type)
  864.     {
  865.         Net_UserAgent_Detect::detect();
  866.         $type = strtolower($in_type);
  867.  
  868.         if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') {
  869.             $typeArray = &Net_UserAgent_Detect::_getStaticProperty($type);
  870.             foreach((array) $in_expectList as $match) {
  871.                 if (!empty($typeArray[$match])) {
  872.                     return $match;
  873.                 }
  874.             }
  875.         }
  876.  
  877.         return null;
  878.     }
  879.  
  880.     // }}}
  881.     // {{{ setAcceptType()
  882.  
  883.     /**
  884.      * Set the accept types for the current browser.
  885.      *
  886.      * To keep track of the mime-types, languages, charsets and encodings
  887.      * that each browser accepts we use associative arrays for each type.
  888.      * This function takes and array of accepted values for the type and
  889.      * records them for retrieval.
  890.      *
  891.      * @param  array $in_values values of the accept type
  892.      * @param  string $in_type type of accept
  893.      *
  894.      * @access public
  895.      * @return void
  896.      */
  897.     function setAcceptType($in_values, $in_type)
  898.     {
  899.         $type = strtolower($in_type);
  900.  
  901.         if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') {
  902.             $typeArray = &Net_UserAgent_Detect::_getStaticProperty($type);
  903.             foreach((array) $in_values as $value) {
  904.                 $typeArray[$value] = true;
  905.             }
  906.         }
  907.     }
  908.  
  909.     // }}}
  910.     // {{{ hasAcceptType()
  911.  
  912.     /**
  913.      * Check the accept types for the current browser.
  914.      *
  915.      * To keep track of the mime-types, languages, charsets and encodings
  916.      * that each browser accepts we use associative arrays for each type.
  917.      * This function checks the array for the given type and determines if
  918.      * the browser accepts it.
  919.      *
  920.      * @param  string $in_value values to check
  921.      * @param  string $in_type type of accept
  922.      *
  923.      * @access public
  924.      * @return bool whether or not the value is accept for this type
  925.      */
  926.     function hasAcceptType($in_value, $in_type)
  927.     {
  928.         return (bool) Net_UserAgent_Detect::getAcceptType((array) $in_value, $in_type);
  929.     }
  930.  
  931.     // }}}
  932.     // {{{ getUserAgent()
  933.  
  934.     /**
  935.      * Return the user agent string that is being worked on
  936.      *
  937.      * @access public
  938.      * @return string user agent
  939.      */
  940.     function getUserAgent()
  941.     {
  942.         Net_UserAgent_Detect::detect();
  943.         $userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent');
  944.         return $userAgent;
  945.     }
  946.  
  947.     // }}}
  948.     // {{{ _getStaticProperty()
  949.  
  950.     /**
  951.      * Copy of getStaticProperty() from PEAR.php to avoid having to
  952.      * include PEAR.php
  953.      *
  954.      * @access private
  955.      * @param  string $var    The variable to retrieve.
  956.      * @return mixed   A reference to the variable. If not set it will be
  957.      *                 auto initialised to NULL.
  958.      */
  959.     function &_getStaticProperty($var)
  960.     {
  961.         static $properties;
  962.         return $properties[$var];
  963.     }
  964.  
  965.     // }}}
  966. }
  967. ?>
  968.