| version 1.1, 2005/06/05 12:14:37 |
version 1.2, 2005/11/07 20:37:55 |
|
|
| // | license@php.net so we can mail you a copy immediately. | |
// | license@php.net so we can mail you a copy immediately. | |
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| // | Authors: Dan Allen <dan@mojavelinux.com> | |
// | Authors: Dan Allen <dan@mojavelinux.com> | |
| |
// | Jason Rust <jrust@php.net> | |
| // +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| |
|
| // $Id$ |
// $Id$ |
| |
|
| // }}} |
// }}} |
| // {{{ description |
|
| |
|
| // Net_UserAgent_Detect Determine the Web browser, version, and platform from an HTTP user agent string |
|
| |
|
| // }}} |
|
| // {{{ constants |
// {{{ constants |
| |
|
| define('NET_USERAGENT_DETECT_BROWSER', 'browser'); |
define('NET_USERAGENT_DETECT_BROWSER', 'browser'); |
| Line 35 define('NET_USERAGENT_DETECT_ACCEPT', |
|
| Line 31 define('NET_USERAGENT_DETECT_ACCEPT', |
|
| define('NET_USERAGENT_DETECT_ALL', 'all'); |
define('NET_USERAGENT_DETECT_ALL', 'all'); |
| |
|
| // }}} |
// }}} |
| |
|
| // {{{ class Net_UserAgent_Detect |
// {{{ class Net_UserAgent_Detect |
| |
|
| /** |
/** |
| * The Net_UserAgent_Detect object does a number of tests on an HTTP user |
* The Net_UserAgent_Detect object does a number of tests on an HTTP user |
| * agent string. The results of these tests are available via methods of |
* agent string. The results of these tests are available via methods of |
| * the object. |
* the object. Note that all methods in this class can be called |
| |
* statically. The constructor and singleton methods are only retained |
| |
* for BC. |
| * |
* |
| * This module is based upon the JavaScript browser detection code |
* This module is based upon the JavaScript browser detection code |
| * available at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html. |
* available at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html. |
| * This module had many influences from the lib/Browser.php code in |
* This module had many influences from the lib/Browser.php code in |
| * version 1.3 of Horde. |
* version 1.3 of Horde. |
| * |
* |
| * @version Revision: 0.1 |
* @author Jason Rust <jrust@php.net> |
| * @author Dan Allen <dan@mojavelinux.com> |
* @author Dan Allen <dan@mojavelinux.com> |
| * @author Chuck Hagenbuch <chuck@horde.org> |
* @author Chuck Hagenbuch <chuck@horde.org> |
| * @author Jon Parise <jon@horde.org> |
* @author Jon Parise <jon@horde.org> |
| * @access public |
|
| * @since PHP 4.1 |
|
| * @package Net_UserAgent |
* @package Net_UserAgent |
| */ |
*/ |
| |
|
| // }}} |
// }}} |
| class Net_UserAgent_Detect { |
class Net_UserAgent_Detect { |
| // {{{ properties |
// {{{ constructor |
| |
|
| /** |
|
| * User agent string that is being analyzed |
|
| * @var string $userAgent |
|
| */ |
|
| var $userAgent = ''; |
|
| |
|
| /** |
|
| * Array that stores all of the flags for the vendor and version of |
|
| * the different browsers. The flags key values are show in the array. |
|
| * @var array $browser |
|
| */ |
|
| var $browser = array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'ns6up', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'ie6up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera5up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up'); |
|
| |
|
| /** |
|
| * Array that stores all of the flags for the operating systems, and in some cases |
|
| * the versions of those operating systems (windows) |
|
| * @var array $os |
|
| */ |
|
| var $os = array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'winme', 'win2k', 'winxp', 'winnt', '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'); |
|
| |
|
| /** |
|
| * Array that stores credentials for each of the browser/os combinations. These allow |
|
| * quick access to determine if the current client has a feature that is going to be |
|
| * implemented in the script. |
|
| * @var array $features |
|
| */ |
|
| var $features = array( |
|
| 'javascript' => false, |
|
| 'dhtml' => false, |
|
| 'dom' => false, |
|
| 'sidebar' => false, |
|
| 'gecko' => false, |
|
| ); |
|
| |
|
| /** |
|
| * Array which stores known issues with the given client that can be used for on the |
|
| * fly tweaking so that the client may recieve the proper handling of this quirk. |
|
| * @var array $quirks |
|
| */ |
|
| var $quirks = array( |
|
| 'must_cache_forms' => false, |
|
| 'popups_disabled' => false, |
|
| 'empty_file_input_value' => false, |
|
| 'cache_ssl_downloads' => false, |
|
| 'scrollbar_in_way' => false, |
|
| 'break_disposition_header' => false, |
|
| 'nested_table_render_bug' => false, |
|
| ); |
|
| |
|
| /** |
|
| * The leading identifier is the very first term in the user agent string, which is |
|
| * used to identify clients which are not Mosaic-based browsers. |
|
| * @var string $leadingIdentifier |
|
| */ |
|
| var $leadingIdentifier = ''; |
|
| |
|
| /** |
|
| * The full version of the client as supplied by the very first numbers in the user agent |
|
| * @var float $version |
|
| */ |
|
| var $version = 0; |
|
| |
|
| /** |
|
| * The major part of the client version, which is the integer value of the version. |
|
| * @var integer $majorVersion |
|
| */ |
|
| var $majorVersion = 0; |
|
| |
|
| /** |
|
| * The minor part of the client version, which is the decimal parts of the version |
|
| * @var float $subVersion |
|
| */ |
|
| var $subVersion = 0; |
|
| |
|
| /** |
|
| * This level determins how much checking we do. When time is of the essences, filtering |
|
| * the AOL versions might seem like overkill. There are three levels, normal|detailed|basic |
|
| * @var string $level |
|
| */ |
|
| var $detectOptions = array(NET_USERAGENT_DETECT_BROWSER, NET_USERAGENT_DETECT_OS, NET_USERAGENT_DETECT_FEATURES, NET_USERAGENT_DETECT_QUIRKS, NET_USERAGENT_DETECT_ACCEPT, NET_USERAGENT_DETECT_ALL); |
|
| |
|
| var $mimetype = array(); |
|
| |
|
| var $language = array(); |
|
| |
|
| var $charset = array(); |
|
| |
|
| var $encoding = array(); |
function Net_UserAgent_Detect($in_userAgent = null, $in_detect = null) |
| |
{ |
| |
$this->detect($in_userAgent, $in_detect); |
| |
} |
| |
|
| // }}} |
// }}} |
| // {{{ singleton |
// {{{ singleton |
| |
|
| /** |
/** |
| * To be used in place of the contructor to return any open instance. |
* To be used in place of the contructor to return only open instance. |
| * |
|
| * Most of the time we want to evaluate the client's user agent string, |
|
| * so we want to make sure that we only have to run the detect() function |
|
| * once. Therefore, all of the all of the properties and methods must map |
|
| * to a single state. Therefore, this function is used in place of the |
|
| * contructor to return any open instances of the client object, and if none |
|
| * are open will create a new instance and cache it using a static |
|
| * variable. |
|
| * |
* |
| * @access public |
* @access public |
| * @return object Net_UserAgent_Detect instance |
* @return object Net_UserAgent_Detect instance |
| Line 172 class Net_UserAgent_Detect { |
|
| Line 75 class Net_UserAgent_Detect { |
|
| static $instance; |
static $instance; |
| |
|
| if (!isset($instance)) { |
if (!isset($instance)) { |
| $instance = new Net_UserAgent_Detect($in_userAgent); |
$instance = new Net_UserAgent_Detect($in_userAgent, $in_detect); |
| } |
} |
| |
|
| return $instance; |
return $instance; |
| } |
} |
| |
|
| // }}} |
// }}} |
| // {{{ constructor |
|
| |
|
| function Net_UserAgent_Detect($in_userAgent = null, $in_detect = null) |
|
| { |
|
| $this->detect($in_userAgent, $in_detect); |
|
| } |
|
| |
|
| // }}} |
|
| // {{{ detect() |
// {{{ detect() |
| |
|
| /** |
/** |
| * Detect the user agent and prepare flags, features and quirks based on what is found |
* Detect the user agent and prepare flags, features and quirks |
| |
* based on what is found |
| * |
* |
| * This is the core of the Net_UserAgent_Detect class. It moves its way through the user agent |
* This is the core of the Net_UserAgent_Detect class. It moves its |
| * string setting up the flags based on the vendors and versions of the browsers, determining |
* way through the user agent string setting up the flags based on |
| * the OS and setting up the features and quirks owned by each of the relevant clients. |
* the vendors and versions of the browsers, determining the OS and |
| |
* setting up the features and quirks owned by each of the relevant |
| |
* clients. Note that if you are going to be calling methods of |
| |
* this class statically then set all the parameters using th |
| |
* setOption() |
| * |
* |
| * @param string (optional) user agent override |
* @param string $in_userAgent (optional) User agent override. |
| |
* @param mixed $in_detect (optional) The level of checking to do. |
| * |
* |
| * @access public |
* @access public |
| * @return void |
* @return void |
| */ |
*/ |
| function detect($in_userAgent = null, $in_detect = null) |
function detect($in_userAgent = null, $in_detect = null) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
static $hasRun; |
| $this =& Net_UserAgent_Detect::singleton(); |
$options = &Net_UserAgent_Detect::_getStaticProperty('options'); |
| |
if (!empty($hasRun) && empty($options['re-evaluate'])) { |
| |
return; |
| } |
} |
| |
|
| |
$hasRun = true; |
| |
// {{{ set up static properties |
| |
|
| |
$in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : null; |
| |
$in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : null; |
| |
|
| |
// User agent string that is being analyzed |
| |
$userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent'); |
| |
|
| |
// Array that stores all of the flags for the vendor and version |
| |
// of the different browsers |
| |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| |
$browser = array_flip(array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'ns6up', 'firefox', 'firefox0.x', 'firefox1.x', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'ie6up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera6', 'opera7', 'opera5up', 'opera6up', 'opera7up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'aol8', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up', 'konq', 'safari', 'netgem', 'webdav')); |
| |
|
| |
// Array that stores all of the flags for the operating systems, |
| |
// and in some cases the versions of those operating systems (windows) |
| |
$os = &Net_UserAgent_Detect::_getStaticProperty('os'); |
| |
$os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', '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')); |
| |
|
| |
// Array which stores known issues with the given client that can |
| |
// be used for on the fly tweaking so that the client may recieve |
| |
// the proper handling of this quirk. |
| |
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks'); |
| |
$quirks = array( |
| |
'must_cache_forms' => false, |
| |
'popups_disabled' => false, |
| |
'empty_file_input_value' => false, |
| |
'cache_ssl_downloads' => false, |
| |
'scrollbar_in_way' => false, |
| |
'break_disposition_header' => false, |
| |
'nested_table_render_bug' => false); |
| |
|
| |
// Array that stores credentials for each of the browser/os |
| |
// combinations. These allow quick access to determine if the |
| |
// current client has a feature that is going to be implemented |
| |
// in the script. |
| |
$features = &Net_UserAgent_Detect::_getStaticProperty('features'); |
| |
$features = array( |
| |
'javascript' => false, |
| |
'dhtml' => false, |
| |
'dom' => false, |
| |
'sidebar' => false, |
| |
'gecko' => false); |
| |
|
| |
// The leading identifier is the very first term in the user |
| |
// agent string, which is used to identify clients which are not |
| |
// Mosaic-based browsers. |
| |
$leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'); |
| |
|
| |
// The full version of the client as supplied by the very first |
| |
// numbers in the user agent |
| |
$version = &Net_UserAgent_Detect::_getStaticProperty('version'); |
| |
$version = 0; |
| |
|
| |
// The major part of the client version, which is the integer |
| |
// value of the version. |
| |
$majorVersion = &Net_UserAgent_Detect::_getStaticProperty('majorVersion'); |
| |
$majorVersion = 0; |
| |
|
| |
// The minor part of the client version, which is the decimal |
| |
// parts of the version |
| |
$subVersion = &Net_UserAgent_Detect::_getStaticProperty('subVersion'); |
| |
$subVersion = 0; |
| |
|
| |
// }}} |
| // detemine what user agent we are using |
// detemine what user agent we are using |
| if (is_null($in_userAgent)) { |
if (is_null($in_userAgent)) { |
| if (isset($_SERVER['HTTP_USER_AGENT'])) { |
if (isset($_SERVER['HTTP_USER_AGENT'])) { |
| $this->userAgent = $_SERVER['HTTP_USER_AGENT']; |
$userAgent = $_SERVER['HTTP_USER_AGENT']; |
| } |
} |
| elseif (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'])) { |
elseif (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'])) { |
| $this->userAgent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']; |
$userAgent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']; |
| } |
} |
| // fallback on a default one for testing from commandline |
|
| else { |
else { |
| $this->userAgent = ''; |
$userAgent = ''; |
| } |
} |
| } |
} |
| else { |
else { |
| $this->userAgent = $in_userAgent; |
$userAgent = $in_userAgent; |
| } |
} |
| |
|
| // get the lowercase version for case-insensitive searching |
// get the lowercase version for case-insensitive searching |
| $agt = strtolower($this->userAgent); |
$agt = strtolower($userAgent); |
| |
|
| // figure out what we need to look for |
// figure out what we need to look for |
| |
$detectOptions = array(NET_USERAGENT_DETECT_BROWSER, |
| |
NET_USERAGENT_DETECT_OS, NET_USERAGENT_DETECT_FEATURES, |
| |
NET_USERAGENT_DETECT_QUIRKS, NET_USERAGENT_DETECT_ACCEPT, |
| |
NET_USERAGENT_DETECT_ALL); |
| $detect = is_null($in_detect) ? NET_USERAGENT_DETECT_ALL : $in_detect; |
$detect = is_null($in_detect) ? NET_USERAGENT_DETECT_ALL : $in_detect; |
| settype($detect, 'array'); |
settype($detect, 'array'); |
| foreach($this->detectOptions as $option) { |
foreach($detectOptions as $option) { |
| if (in_array($option, $detect)) { |
if (in_array($option, $detect)) { |
| $detectFlags[$option] = true; |
$detectFlags[$option] = true; |
| } |
} |
| Line 239 class Net_UserAgent_Detect { |
|
| Line 210 class Net_UserAgent_Detect { |
|
| } |
} |
| } |
} |
| |
|
| // initialize the flag arrays |
// initialize the arrays of browsers and operating systems |
| $brwsr =& $this->browser; |
|
| $brwsr = array_flip($brwsr); |
|
| $os =& $this->os; |
|
| $os = array_flip($os); |
|
| |
|
| // Get the type and version of the client |
// Get the type and version of the client |
| if (preg_match(";^([[:alnum:]]+)[ /\(]*[[:alpha:]]*([\d]*)(\.[\d\.]*);", $agt, $matches)) { |
if (preg_match(";^([[:alnum:]]+)[ /\(]*[[:alpha:]]*([\d]*)(\.[\d\.]*);", $agt, $matches)) { |
| list(, $this->leadingIdentifier, $this->majorVersion, $this->subVersion) = $matches; |
list(, $leadingIdentifier, $majorVersion, $subVersion) = $matches; |
| } |
} |
| |
|
| if (empty($this->leadingIdentifier)) { |
if (empty($leadingIdentifier)) { |
| $this->leadingIdentifier = 'Unknown'; |
$leadingIdentifier = 'Unknown'; |
| } |
} |
| |
|
| $this->version = $this->majorVersion . $this->subVersion; |
$version = $majorVersion . $subVersion; |
| |
|
| // Browser type |
// Browser type |
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_BROWSER]) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_BROWSER]) { |
| $brwsr['konq'] = (strpos($agt, 'konqueror') !== false || strpos($agt, 'safari') !== false); |
$browser['webdav'] = ($agt == 'microsoft data access internet publishing provider dav' || $agt == 'microsoft data access internet publishing provider protocol discovery'); |
| $brwsr['text'] = (strpos($agt, 'links') !== false) || (strpos($agt, 'lynx') !== false) || (strpos($agt, 'w3m') !== false); |
$browser['konq'] = $browser['safari'] = (strpos($agt, 'konqueror') !== false || strpos($agt, 'safari') !== false); |
| $brwsr['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; |
$browser['text'] = strpos($agt, 'links') !== false || strpos($agt, 'lynx') !== false || strpos($agt, 'w3m') !== false; |
| $brwsr['ns2'] = $brwsr['ns'] && $this->majorVersion == 2; |
$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; |
| $brwsr['ns3'] = $brwsr['ns'] && $this->majorVersion == 3; |
$browser['netgem'] = strpos($agt, 'netgem') !== false; |
| $brwsr['ns4'] = $brwsr['ns'] && $this->majorVersion == 4; |
$browser['ns2'] = $browser['ns'] && $majorVersion == 2; |
| $brwsr['ns4up'] = $brwsr['ns'] && $this->majorVersion >= 4; |
$browser['ns3'] = $browser['ns'] && $majorVersion == 3; |
| |
$browser['ns4'] = $browser['ns'] && $majorVersion == 4; |
| |
$browser['ns4up'] = $browser['ns'] && $majorVersion >= 4; |
| // determine if this is a Netscape Navigator |
// determine if this is a Netscape Navigator |
| $brwsr['nav'] = $brwsr['ns'] && $this->majorVersion < 5; |
$browser['nav'] = $browser['ns'] && $majorVersion < 5; |
| $brwsr['ns6'] = !$brwsr['konq'] && $brwsr['ns'] && $this->majorVersion == 5; |
$browser['ns6'] = !$browser['konq'] && $browser['ns'] && $majorVersion == 5; |
| $brwsr['ns6up'] = $brwsr['ns6'] && $this->majorVersion >= 5; |
$browser['ns6up'] = $browser['ns6'] && $majorVersion >= 5; |
| $brwsr['gecko'] = (strpos($agt, 'gecko') !== false && !$brwsr['konq']); |
$browser['gecko'] = strpos($agt, 'gecko') !== false && !$browser['konq']; |
| $brwsr['ie'] = (strpos($agt, 'msie') !== false) && !(strpos($agt, 'opera') !== false); |
$browser['firefox'] = $browser['gecko'] && strpos($agt, 'firefox') !== false; |
| $brwsr['ie3'] = $brwsr['ie'] && $this->majorVersion < 4; |
$browser['firefox0.x'] = $browser['firefox'] && strpos($agt, 'firefox/0.') !== false; |
| $brwsr['ie4'] = $brwsr['ie'] && $this->majorVersion == 4 && (strpos($agt, 'msie 4') !== false); |
$browser['firefox1.x'] = $browser['firefox'] && strpos($agt, 'firefox/1.') !== false; |
| $brwsr['ie4up'] = $brwsr['ie'] && !$brwsr['ie3']; |
$browser['ie'] = strpos($agt, 'msie') !== false && !(strpos($agt, 'opera') !== false); |
| $brwsr['ie5'] = $brwsr['ie4up'] && (strpos($agt, 'msie 5.0') !== false); |
$browser['ie3'] = $browser['ie'] && $majorVersion < 4; |
| $brwsr['ie5_5'] = $brwsr['ie4up'] && (strpos($agt, 'msie 5.5') !== false); |
$browser['ie4'] = $browser['ie'] && $majorVersion == 4 && (strpos($agt, 'msie 4') !== false); |
| $brwsr['ie5up'] = $brwsr['ie4up'] && !$brwsr['ie3'] && !$brwsr['ie4']; |
$browser['ie4up'] = $browser['ie'] && !$browser['ie3']; |
| $brwsr['ie5_5up'] = $brwsr['ie5up'] && !$brwsr['ie5']; |
$browser['ie5'] = $browser['ie4up'] && (strpos($agt, 'msie 5.0') !== false); |
| $brwsr['ie6'] = (strpos($agt, 'msie 6') !== false); |
$browser['ie5_5'] = $browser['ie4up'] && (strpos($agt, 'msie 5.5') !== false); |
| $brwsr['ie6up'] = $brwsr['ie5up'] && !$brwsr['ie5'] && !$brwsr['ie5_5']; |
$browser['ie5up'] = $browser['ie4up'] && !$browser['ie3'] && !$browser['ie4']; |
| $brwsr['opera'] = (strpos($agt, 'opera') !== false); |
$browser['ie5_5up'] = $browser['ie5up'] && !$browser['ie5']; |
| $brwsr['opera2'] = (strpos($agt, 'opera 2') !== false) || (strpos($agt, 'opera/2') !== false); |
$browser['ie6'] = strpos($agt, 'msie 6') !== false; |
| $brwsr['opera3'] = (strpos($agt, 'opera 3') !== false) || (strpos($agt, 'opera/3') !== false); |
$browser['ie6up'] = $browser['ie5up'] && !$browser['ie5'] && !$browser['ie5_5']; |
| $brwsr['opera4'] = (strpos($agt, 'opera 4') !== false) || (strpos($agt, 'opera/4') !== false); |
$browser['opera'] = strpos($agt, 'opera') !== false; |
| $brwsr['opera5'] = (strpos($agt, 'opera 5') !== false) || (strpos($agt, 'opera/5') !== false); |
$browser['opera2'] = strpos($agt, 'opera 2') !== false || strpos($agt, 'opera/2') !== false; |
| $brwsr['opera5up'] = $brwsr['opera'] && !$brwsr['opera2'] && !$brwsr['opera3'] && !$brwsr['opera4']; |
$browser['opera3'] = strpos($agt, 'opera 3') !== false || strpos($agt, 'opera/3') !== false; |
| |
$browser['opera4'] = strpos($agt, 'opera 4') !== false || strpos($agt, 'opera/4') !== false; |
| $brwsr['aol'] = (strpos($agt, 'aol') !== false); |
$browser['opera5'] = strpos($agt, 'opera 5') !== false || strpos($agt, 'opera/5') !== false; |
| $brwsr['aol3'] = $brwsr['aol'] && $brwsr['ie3']; |
$browser['opera6'] = strpos($agt, 'opera 6') !== false || strpos($agt, 'opera/6') !== false; |
| $brwsr['aol4'] = $brwsr['aol'] && $brwsr['ie4']; |
$browser['opera7'] = strpos($agt, 'opera 7') !== false || strpos($agt, 'opera/7') !== false; |
| $brwsr['aol5'] = (strpos($agt, 'aol 5') !== false); |
$browser['opera5up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4']; |
| $brwsr['aol6'] = (strpos($agt, 'aol 6') !== false); |
$browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5']; |
| $brwsr['aol7'] = (strpos($agt, 'aol 7') !== false); |
$browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6']; |
| $brwsr['webtv'] = (strpos($agt, 'webtv') !== false); |
|
| $brwsr['aoltv'] = $brwsr['tvnavigator'] = (strpos($agt, 'navio') !== false) || (strpos($agt, 'navio_aoltv') !== false); |
$browser['aol'] = strpos($agt, 'aol') !== false; |
| $brwsr['hotjava'] = (strpos($agt, 'hotjava') !== false); |
$browser['aol3'] = $browser['aol'] && $browser['ie3']; |
| $brwsr['hotjava3'] = $brwsr['hotjava'] && $this->majorVersion == 3; |
$browser['aol4'] = $browser['aol'] && $browser['ie4']; |
| $brwsr['hotjava3up'] = $brwsr['hotjava'] && $this->majorVersion >= 3; |
$browser['aol5'] = strpos($agt, 'aol 5') !== false; |
| |
$browser['aol6'] = strpos($agt, 'aol 6') !== false; |
| |
$browser['aol7'] = strpos($agt, 'aol 7') !== false || strpos($agt, 'aol7') !== false; |
| |
$browser['aol8'] = strpos($agt, 'aol 8') !== false || strpos($agt, 'aol8') !== false; |
| |
$browser['webtv'] = strpos($agt, 'webtv') !== false; |
| |
$browser['aoltv'] = $browser['tvnavigator'] = strpos($agt, 'navio') !== false || strpos($agt, 'navio_aoltv') !== false; |
| |
$browser['hotjava'] = strpos($agt, 'hotjava') !== false; |
| |
$browser['hotjava3'] = $browser['hotjava'] && $majorVersion == 3; |
| |
$browser['hotjava3up'] = $browser['hotjava'] && $majorVersion >= 3; |
| } |
} |
| |
|
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || |
| |
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) { |
| // Javascript Check |
// Javascript Check |
| if ($brwsr['ns2'] || $brwsr['ie3']) { |
if ($browser['ns2'] || $browser['ie3']) { |
| $this->setFeature('javascript', 1.0); |
Net_UserAgent_Detect::setFeature('javascript', 1.0); |
| } |
} |
| elseif ($brwsr['opera5up']) { |
elseif ($browser['opera5up']) { |
| $this->setFeature('javascript', 1.3); |
Net_UserAgent_Detect::setFeature('javascript', 1.3); |
| } |
} |
| elseif ($brwsr['opera'] || $brwsr['ns3']) { |
elseif ($browser['opera'] || $browser['ns3']) { |
| $this->setFeature('javascript', 1.1); |
Net_UserAgent_Detect::setFeature('javascript', 1.1); |
| } |
} |
| elseif (($brwsr['ns4'] && ($this->version <= 4.05)) || $brwsr['ie4']) { |
elseif (($browser['ns4'] && ($version <= 4.05)) || $browser['ie4']) { |
| $this->setFeature('javascript', 1.2); |
Net_UserAgent_Detect::setFeature('javascript', 1.2); |
| } |
} |
| elseif (($brwsr['ie5up'] && strpos($agt, 'mac') !== false) || $brwsr['konq']) { |
elseif (($browser['ie5up'] && strpos($agt, 'mac') !== false) || $browser['konq']) { |
| $this->setFeature('javascript', 1.4); |
Net_UserAgent_Detect::setFeature('javascript', 1.4); |
| } |
} |
| // I can't believe IE6 still has javascript 1.3, what a shitty browser |
// I can't believe IE6 still has javascript 1.3, what a shitty browser |
| elseif (($brwsr['ns4'] && ($this->version > 4.05)) || $brwsr['ie5up'] || $brwsr['hotjava3up']) { |
elseif (($browser['ns4'] && ($version > 4.05)) || $browser['ie5up'] || $browser['hotjava3up']) { |
| $this->setFeature('javascript', 1.3); |
Net_UserAgent_Detect::setFeature('javascript', 1.3); |
| } |
} |
| elseif ($brwsr['ns6up'] || $brwsr['gecko']) { |
elseif ($browser['ns6up'] || $browser['gecko'] || $browser['netgem']) { |
| $this->setFeature('javascript', 1.5); |
Net_UserAgent_Detect::setFeature('javascript', 1.5); |
| } |
} |
| } |
} |
| |
|
| /** OS Check **/ |
/** OS Check **/ |
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_OS]) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_OS]) { |
| $os['win'] = (strpos($agt, 'win') !== false) || (strpos($agt, '16bit') !== false); |
$os['win'] = strpos($agt, 'win') !== false || strpos($agt, '16bit') !== false; |
| $os['win95'] = (strpos($agt, 'win95') !== false) || (strpos($agt, 'windows 95') !== false); |
$os['win95'] = strpos($agt, 'win95') !== false || strpos($agt, 'windows 95') !== false; |
| $os['win16'] = (strpos($agt, 'win16') !== false) || (strpos($agt, '16bit') !== false) || (strpos($agt, 'windows 3.1') !== false) || (strpos($agt, 'windows 16-bit') !== false); |
$os['win16'] = strpos($agt, 'win16') !== false || strpos($agt, '16bit') !== false || strpos($agt, 'windows 3.1') !== false || strpos($agt, 'windows 16-bit') !== false; |
| $os['win31'] = (strpos($agt, 'windows 3.1') !== false) || (strpos($agt, 'win16') !== false) || (strpos($agt, 'windows 16-bit') !== false); |
$os['win31'] = strpos($agt, 'windows 3.1') !== false || strpos($agt, 'win16') !== false || strpos($agt, 'windows 16-bit') !== false; |
| $os['winme'] = (strpos($agt, 'win 9x 4.90') !== false); |
$os['winme'] = strpos($agt, 'win 9x 4.90') !== false; |
| $os['win2k'] = (strpos($agt, 'windows nt 5.0') !== false); |
$os['win2k'] = strpos($agt, 'windows nt 5.0') !== false; |
| $os['winxp'] = (strpos($agt, 'windows nt 5.1') !== false); |
$os['winxp'] = strpos($agt, 'windows nt 5.1') !== false; |
| $os['win98'] = (strpos($agt, 'win98') !== false) || (strpos($agt, 'windows 98') !== false); |
$os['win2003'] = strpos($agt, 'windows nt 5.2') !== false; |
| |
$os['win98'] = strpos($agt, 'win98') !== false || strpos($agt, 'windows 98') !== false; |
| $os['win9x'] = $os['win95'] || $os['win98']; |
$os['win9x'] = $os['win95'] || $os['win98']; |
| $os['winnt'] = ((strpos($agt, 'winnt') !== false) || (strpos($agt, 'windows nt') !== false)) && (strpos($agt, 'windows nt 5') === false); |
$os['winnt'] = (strpos($agt, 'winnt') !== false || strpos($agt, 'windows nt') !== false) && strpos($agt, 'windows nt 5') === false; |
| $os['win32'] = $os['win95'] || $os['winnt'] || $os['win98'] || $this->majorVersion >= 4 && (strpos($agt, 'win32') !== false) || (strpos($agt, '32bit') !== false); |
$os['win32'] = $os['win95'] || $os['winnt'] || $os['win98'] || $majorVersion >= 4 && strpos($agt, 'win32') !== false || strpos($agt, '32bit') !== false; |
| $os['os2'] = (strpos($agt, 'os/2') !== false) || (strpos($agt, 'ibm-webexplorer') !== false); |
$os['os2'] = strpos($agt, 'os/2') !== false || strpos($agt, 'ibm-webexplorer') !== false; |
| $os['mac'] = (strpos($agt, 'mac') !== false); |
$os['mac'] = strpos($agt, 'mac') !== false; |
| $os['mac68k'] = $os['mac'] && ((strpos($agt, '68k') !== false) || (strpos($agt, '68000') !== false)); |
$os['mac68k'] = $os['mac'] && (strpos($agt, '68k') !== false || strpos($agt, '68000') !== false); |
| $os['macppc'] = $os['mac'] && ((strpos($agt, 'ppc') !== false) || (strpos($agt, 'powerpc') !== false)); |
$os['macppc'] = $os['mac'] && (strpos($agt, 'ppc') !== false || strpos($agt, 'powerpc') !== false); |
| $os['sun'] = (strpos($agt, 'sunos') !== false); |
$os['sun'] = strpos($agt, 'sunos') !== false; |
| $os['sun4'] = (strpos($agt, 'sunos 4') !== false); |
$os['sun4'] = strpos($agt, 'sunos 4') !== false; |
| $os['sun5'] = (strpos($agt, 'sunos 5') !== false); |
$os['sun5'] = strpos($agt, 'sunos 5') !== false; |
| $os['suni86'] = $os['sun'] && (strpos($agt, 'i86') !== false); |
$os['suni86'] = $os['sun'] && strpos($agt, 'i86') !== false; |
| $os['irix'] = (strpos($agt, 'irix') !== false); |
$os['irix'] = strpos($agt, 'irix') !== false; |
| $os['irix5'] = (strpos($agt, 'irix 5') !== false); |
$os['irix5'] = strpos($agt, 'irix 5') !== false; |
| $os['irix6'] = (strpos($agt, 'irix 6') !== false) || (strpos($agt, 'irix6') !== false); |
$os['irix6'] = strpos($agt, 'irix 6') !== false || strpos($agt, 'irix6') !== false; |
| $os['hpux'] = (strpos($agt, 'hp-ux') !== false); |
$os['hpux'] = strpos($agt, 'hp-ux') !== false; |
| $os['hpux9'] = $os['hpux'] && (strpos($agt, '09.') !== false); |
$os['hpux9'] = $os['hpux'] && strpos($agt, '09.') !== false; |
| $os['hpux10'] = $os['hpux'] && (strpos($agt, '10.') !== false); |
$os['hpux10'] = $os['hpux'] && strpos($agt, '10.') !== false; |
| $os['aix'] = (strpos($agt, 'aix') !== false); |
$os['aix'] = strpos($agt, 'aix') !== false; |
| $os['aix1'] = (strpos($agt, 'aix 1') !== false); |
$os['aix1'] = strpos($agt, 'aix 1') !== false; |
| $os['aix2'] = (strpos($agt, 'aix 2') !== false); |
$os['aix2'] = strpos($agt, 'aix 2') !== false; |
| $os['aix3'] = (strpos($agt, 'aix 3') !== false); |
$os['aix3'] = strpos($agt, 'aix 3') !== false; |
| $os['aix4'] = (strpos($agt, 'aix 4') !== false); |
$os['aix4'] = strpos($agt, 'aix 4') !== false; |
| $os['linux'] = (strpos($agt, 'inux') !== false); |
$os['linux'] = strpos($agt, 'inux') !== false; |
| $os['sco'] = (strpos($agt, 'sco') !== false) || (strpos($agt, 'unix_sv') !== false); |
$os['sco'] = strpos($agt, 'sco') !== false || strpos($agt, 'unix_sv') !== false; |
| $os['unixware'] = (strpos($agt, 'unix_system_v') !== false); |
$os['unixware'] = strpos($agt, 'unix_system_v') !== false; |
| $os['mpras'] = (strpos($agt, 'ncr') !== false); |
$os['mpras'] = strpos($agt, 'ncr') !== false; |
| $os['reliant'] = (strpos($agt, 'reliant') !== false); |
$os['reliant'] = strpos($agt, 'reliant') !== false; |
| $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); |
$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; |
| $os['sinix'] = (strpos($agt, 'sinix') !== false); |
$os['sinix'] = strpos($agt, 'sinix') !== false; |
| $os['freebsd'] = (strpos($agt, 'freebsd') !== false); |
$os['freebsd'] = strpos($agt, 'freebsd') !== false; |
| $os['bsd'] = (strpos($agt, 'bsd') !== false); |
$os['bsd'] = strpos($agt, 'bsd') !== false; |
| $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']; |
$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']; |
| $os['vms'] = (strpos($agt, 'vax') !== false) || (strpos($agt, 'openvms') !== false); |
$os['vms'] = strpos($agt, 'vax') !== false || strpos($agt, 'openvms') !== false; |
| } |
} |
| |
|
| // Setup the quirks |
// Setup the quirks |
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_QUIRKS])) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || |
| if ($brwsr['konq']) { |
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_QUIRKS])) { |
| $this->setQuirk('empty_file_input_value'); |
if ($browser['konq']) { |
| |
Net_UserAgent_Detect::setQuirk('empty_file_input_value'); |
| } |
} |
| |
|
| if ($brwsr['ie']) { |
if ($browser['ie']) { |
| $this->setQuirk('cache_ssl_downloads'); |
Net_UserAgent_Detect::setQuirk('cache_ssl_downloads'); |
| } |
} |
| |
|
| if ($brwsr['ie6']) { |
if ($browser['ie6']) { |
| $this->setQuirk('scrollbar_in_way'); |
Net_UserAgent_Detect::setQuirk('scrollbar_in_way'); |
| } |
} |
| |
|
| if ($brwsr['ie5']) { |
if ($browser['ie5']) { |
| $this->setQuirk('break_disposition_header'); |
Net_UserAgent_Detect::setQuirk('break_disposition_header'); |
| } |
} |
| |
|
| if ($brwsr['ns6']) { |
if ($browser['ns6']) { |
| $this->setQuirk('popups_disabled'); |
Net_UserAgent_Detect::setQuirk('popups_disabled'); |
| $this->setQuirk('must_cache_forms'); |
Net_UserAgent_Detect::setQuirk('must_cache_forms'); |
| } |
} |
| |
|
| if ($brwsr['nav'] && $this->subVersion < .79) { |
if ($browser['nav'] && $subVersion < .79) { |
| $this->setQuirk('nested_table_render_bug'); |
Net_UserAgent_Detect::setQuirk('nested_table_render_bug'); |
| } |
} |
| } |
} |
| |
|
| // Set features |
// Set features |
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || |
| if ($brwsr['gecko']) { |
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) { |
| |
if ($browser['gecko']) { |
| preg_match(';gecko/([\d]+)\b;i', $agt, $matches); |
preg_match(';gecko/([\d]+)\b;i', $agt, $matches); |
| $this->setFeature('gecko', $matches[1]); |
Net_UserAgent_Detect::setFeature('gecko', $matches[1]); |
| } |
} |
| |
|
| if ($brwsr['ns6up'] || $brwsr['opera5up'] || $brwsr['konq']) { |
if ($browser['ns6up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) { |
| $this->setFeature('dom'); |
Net_UserAgent_Detect::setFeature('dom'); |
| } |
} |
| |
|
| if ($brwsr['ie4up'] || $brwsr['ns4up'] || $brwsr['opera5up'] || $brwsr['konq']) { |
if ($browser['ie4up'] || $browser['ns4up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) { |
| $this->setFeature('dhtml'); |
Net_UserAgent_Detect::setFeature('dhtml'); |
| } |
} |
| } |
} |
| |
|
| if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_ACCEPT]) { |
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_ACCEPT]) { |
| $mimetypes = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT'), 0, strpos(getenv('HTTP_ACCEPT') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
$mimetypes = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT'), 0, strpos(getenv('HTTP_ACCEPT') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
| $this->setAcceptType((array) $mimetypes, 'mimetype'); |
Net_UserAgent_Detect::setAcceptType((array) $mimetypes, 'mimetype'); |
| |
|
| $languages = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, strpos(getenv('HTTP_ACCEPT_LANGUAGE') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
$languages = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, strpos(getenv('HTTP_ACCEPT_LANGUAGE') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
| if (empty($languages)) { |
if (empty($languages)) { |
| $languages = 'en'; |
$languages = 'en'; |
| } |
} |
| |
|
| $this->setAcceptType((array) $languages, 'language'); |
Net_UserAgent_Detect::setAcceptType((array) $languages, 'language'); |
| |
|
| $encodings = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_ENCODING'), 0, strpos(getenv('HTTP_ACCEPT_ENCODING') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
$encodings = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_ENCODING'), 0, strpos(getenv('HTTP_ACCEPT_ENCODING') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
| $this->setAcceptType((array) $encodings, 'encoding'); |
Net_UserAgent_Detect::setAcceptType((array) $encodings, 'encoding'); |
| |
|
| $charsets = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_CHARSET'), 0, strpos(getenv('HTTP_ACCEPT_CHARSET') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
$charsets = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_CHARSET'), 0, strpos(getenv('HTTP_ACCEPT_CHARSET') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); |
| |
Net_UserAgent_Detect::setAcceptType((array) $charsets, 'charset'); |
| $this->setAcceptType((array) $charsets, 'charset'); |
|
| } |
} |
| } |
} |
| |
|
| // }}} |
// }}} |
| |
// {{{ setOption() |
| |
|
| |
/** |
| |
* Sets a class option. The available settings are: |
| |
* o 'userAgent' => The user agent string to detect (useful for |
| |
* checking a string manually). |
| |
* o 'detectOptions' => The level of checking to do. A single level |
| |
* or an array of options. Default is NET_USERAGENT_DETECT_ALL. |
| |
* |
| |
* @param string $in_field The option field (userAgent or detectOptions) |
| |
* @param mixed $in_value The value for the field |
| |
*/ |
| |
function setOption($in_field, $in_value) |
| |
{ |
| |
$options = &Net_UserAgent_Detect::_getStaticProperty('options'); |
| |
$options[$in_field] = $in_value; |
| |
} |
| |
|
| |
// }}} |
| // {{{ isBrowser() |
// {{{ isBrowser() |
| |
|
| /** |
/** |
| Line 451 class Net_UserAgent_Detect { |
|
| Line 450 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function isBrowser($in_match) |
function isBrowser($in_match) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
return isset($browser[strtolower($in_match)]) ? $browser[strtolower($in_match)] : false; |
| |
|
| $match = strtolower($in_match); |
|
| return isset($this->browser[$match]) ? $this->browser[$match] : false; |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 475 class Net_UserAgent_Detect { |
|
| Line 471 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function getBrowser($in_expectList) |
function getBrowser($in_expectList) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
foreach((array) $in_expectList as $brwsr) { |
| |
if (!empty($browser[strtolower($brwsr)])) { |
| foreach((array) $in_expectList as $browser) { |
return $brwsr; |
| if (!empty($this->browser[strtolower($browser)])) { |
|
| return $browser; |
|
| } |
} |
| } |
} |
| } |
} |
| Line 513 class Net_UserAgent_Detect { |
|
| Line 507 class Net_UserAgent_Detect { |
|
| 'nav' => 'Netscape Navigator', |
'nav' => 'Netscape Navigator', |
| 'ns4' => 'Netscape 4.x', |
'ns4' => 'Netscape 4.x', |
| 'ns6up' => 'Mozilla/Netscape 6.x', |
'ns6up' => 'Mozilla/Netscape 6.x', |
| |
'firefox0.x' => 'Firefox 0.x', |
| |
'firefox1.x' => 'Firefox 1.x', |
| 'konq' => 'Konqueror/Safari', |
'konq' => 'Konqueror/Safari', |
| |
'netgem' => 'Netgem/iPlayer', |
| )) |
)) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
|
| |
|
| foreach((array) $in_vendorStrings as $flag => $string) { |
foreach((array) $in_vendorStrings as $flag => $string) { |
| if (!empty($this->browser[$flag])) { |
if (!empty($browser[$flag])) { |
| $vendorString = $string; |
$vendorString = $string; |
| } |
} |
| } |
} |
| |
|
| // if there are no matches just use the user agent leading idendifier (usually Mozilla) |
// if there are no matches just use the user agent leading idendifier (usually Mozilla) |
| if (!isset($vendorString)) { |
if (!isset($vendorString)) { |
| $vendorString = $this->leadingIdentifier; |
$leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'); |
| |
$vendorString = $leadingIdentifier; |
| } |
} |
| |
|
| return $vendorString; |
return $vendorString; |
| Line 545 class Net_UserAgent_Detect { |
|
| Line 541 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function isIE() |
function isIE() |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
return !empty($browser['ie']); |
| |
|
| return !empty($this->browser['ie']); |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 563 class Net_UserAgent_Detect { |
|
| Line 557 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function isNavigator() |
function isNavigator() |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
return !empty($browser['nav']); |
| |
|
| return !empty($this->browser['nav']); |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 585 class Net_UserAgent_Detect { |
|
| Line 577 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function isNetscape() |
function isNetscape() |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); |
| } |
return !empty($browser['ns4up']); |
| |
|
| return !empty($this->browser['ns4up']); |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 608 class Net_UserAgent_Detect { |
|
| Line 598 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function isOS($in_match) |
function isOS($in_match) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$os = &Net_UserAgent_Detect::_getStaticProperty('os'); |
| } |
return isset($os[strtolower($in_match)]) ? $os[strtolower($in_match)] : false; |
| |
|
| $match = strtolower($in_match); |
|
| return isset($this->os[$match]) ? $this->os[$match] : false; |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 630 class Net_UserAgent_Detect { |
|
| Line 617 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function getOS($in_expectList) |
function getOS($in_expectList) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$os = &Net_UserAgent_Detect::_getStaticProperty('os'); |
| } |
foreach((array) $in_expectList as $expectOs) { |
| |
if (!empty($os[strtolower($expectOs)])) { |
| foreach((array) $in_expectList as $os) { |
return $expectOs; |
| if (!empty($this->os[strtolower($os)])) { |
|
| return $os; |
|
| } |
} |
| } |
} |
| } |
} |
| Line 665 class Net_UserAgent_Detect { |
|
| Line 650 class Net_UserAgent_Detect { |
|
| 'win2k' => 'Microsoft Windows 2000', |
'win2k' => 'Microsoft Windows 2000', |
| 'winnt' => 'Microsoft Windows NT', |
'winnt' => 'Microsoft Windows NT', |
| 'winxp' => 'Microsoft Windows XP', |
'winxp' => 'Microsoft Windows XP', |
| |
'win2003' => 'Microsoft Windows 2003', |
| 'mac' => 'Macintosh', |
'mac' => 'Macintosh', |
| 'unix' => 'Linux/Unix', |
'unix' => 'Linux/Unix', |
| )) |
)) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| $osString = 'Unknown'; |
$osString = 'Unknown'; |
| |
|
| |
$os = &Net_UserAgent_Detect::_getStaticProperty('os'); |
| foreach((array) $in_osStrings as $flag => $string) { |
foreach((array) $in_osStrings as $flag => $string) { |
| if (!empty($this->os[$flag])) { |
if (!empty($os[$flag])) { |
| $osString = $string; |
$osString = $string; |
| } |
} |
| } |
} |
| Line 694 class Net_UserAgent_Detect { |
|
| Line 678 class Net_UserAgent_Detect { |
|
| * mechanism allows the coder to determine if an excepetion must |
* mechanism allows the coder to determine if an excepetion must |
| * be made with the current client. |
* be made with the current client. |
| * |
* |
| |
* @param string $in_quirk The quirk to set |
| |
* @param string $in_hasQuirk (optional) Does the browser have the quirk? |
| |
* |
| * @access public |
* @access public |
| * @return void |
* @return void |
| */ |
*/ |
| function setQuirk($in_quirk, $in_hasQuirk = true) |
function setQuirk($in_quirk, $in_hasQuirk = true) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks'); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| $hasQuirk = !empty($in_hasQuirk); |
$hasQuirk = !empty($in_hasQuirk); |
| $this->quirks[strtolower($in_quirk)] = $hasQuirk; |
$quirks[strtolower($in_quirk)] = $hasQuirk; |
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 717 class Net_UserAgent_Detect { |
|
| Line 701 class Net_UserAgent_Detect { |
|
| * mechanism allows the coder to determine if an excepetion must |
* mechanism allows the coder to determine if an excepetion must |
| * be made with the current client. |
* be made with the current client. |
| * |
* |
| |
* @param string $in_quirk The quirk to detect |
| |
* |
| * @access public |
* @access public |
| * @return bool whether or not browser has this quirk |
* @return bool whether or not browser has this quirk |
| */ |
*/ |
| function hasQuirk($in_quirk) |
function hasQuirk($in_quirk) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
return (bool) Net_UserAgent_Detect::getQuirk($in_quirk); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| return !empty($this->quirks[strtolower($in_quirk)]); |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 739 class Net_UserAgent_Detect { |
|
| Line 721 class Net_UserAgent_Detect { |
|
| * mechanism allows the coder to determine if an excepetion must |
* mechanism allows the coder to determine if an excepetion must |
| * be made with the current client. |
* be made with the current client. |
| * |
* |
| |
* @param string $in_quirk The quirk to detect |
| |
* |
| * @access public |
* @access public |
| * @return string value of the quirk, in this case usually a boolean |
* @return string value of the quirk, in this case usually a boolean |
| */ |
*/ |
| function getQuirk() |
function getQuirk($in_quirk) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks'); |
| } |
return isset($quirks[strtolower($in_quirk)]) ? $quirks[strtolower($in_quirk)] : null; |
| |
|
| return isset($this->quirks[strtolower($in_quirks)]) ? $this->quirks[strtolower($in_quirks)] : null; |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 761 class Net_UserAgent_Detect { |
|
| Line 743 class Net_UserAgent_Detect { |
|
| * helps keep track of the core features of a client, such as if the client |
* helps keep track of the core features of a client, such as if the client |
| * supports dhtml, dom, javascript, etc. |
* supports dhtml, dom, javascript, etc. |
| * |
* |
| |
* @param string $in_feature The feature to set |
| |
* @param string $in_hasFeature (optional) Does the browser have the feature? |
| |
* |
| * @access public |
* @access public |
| * @return void |
* @return void |
| */ |
*/ |
| function setFeature($in_feature, $in_hasFeature = true) |
function setFeature($in_feature, $in_hasFeature = true) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
$features = &Net_UserAgent_Detect::_getStaticProperty('features'); |
| $this =& Net_UserAgent_Detect::singleton(); |
$features[strtolower($in_feature)] = $in_hasFeature; |
| } |
|
| |
|
| $this->features[strtolower($in_feature)] = $in_hasFeature; |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 783 class Net_UserAgent_Detect { |
|
| Line 765 class Net_UserAgent_Detect { |
|
| * helps keep track of the core features of a client, such as if the client |
* helps keep track of the core features of a client, such as if the client |
| * supports dhtml, dom, javascript, etc. |
* supports dhtml, dom, javascript, etc. |
| * |
* |
| |
* @param string $in_feature The feature to detect |
| |
* |
| * @access public |
* @access public |
| * @return bool whether or not the current client has this feature |
* @return bool whether or not the current client has this feature |
| */ |
*/ |
| function hasFeature($in_feature) |
function hasFeature($in_feature) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
return (bool) Net_UserAgent_Detect::getFeature($in_feature); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| return !empty($this->features[strtolower($in_feature)]); |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 805 class Net_UserAgent_Detect { |
|
| Line 785 class Net_UserAgent_Detect { |
|
| * helps keep track of the core features of a client, such as if the client |
* helps keep track of the core features of a client, such as if the client |
| * supports dhtml, dom, javascript, etc. |
* supports dhtml, dom, javascript, etc. |
| * |
* |
| |
* @param string $in_feature The feature to detect |
| |
* |
| * @access public |
* @access public |
| * @return string value of the feature requested |
* @return string value of the feature requested |
| */ |
*/ |
| function getFeature($in_feature) |
function getFeature($in_feature) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$features = &Net_UserAgent_Detect::_getStaticProperty('features'); |
| } |
return isset($features[strtolower($in_feature)]) ? $features[strtolower($in_feature)] : null; |
| |
|
| return isset($this->features[strtolower($in_feature)]) ? $this->features[strtolower($in_feature)] : null; |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 838 class Net_UserAgent_Detect { |
|
| Line 818 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function getAcceptType($in_expectList, $in_type) |
function getAcceptType($in_expectList, $in_type) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| $type = strtolower($in_type); |
$type = strtolower($in_type); |
| |
|
| if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') { |
if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') { |
| $typeArray =& $this->$type; |
$typeArray = &Net_UserAgent_Detect::_getStaticProperty($type); |
| foreach((array) $in_expectList as $match) { |
foreach((array) $in_expectList as $match) { |
| if (!empty($typeArray[$match])) { |
if (!empty($typeArray[$match])) { |
| return $match; |
return $match; |
| Line 875 class Net_UserAgent_Detect { |
|
| Line 852 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function setAcceptType($in_values, $in_type) |
function setAcceptType($in_values, $in_type) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
|
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| $type = strtolower($in_type); |
$type = strtolower($in_type); |
| |
|
| if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') { |
if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') { |
| $typeArray =& $this->$type; |
$typeArray = &Net_UserAgent_Detect::_getStaticProperty($type); |
| foreach((array) $in_values as $value) { |
foreach((array) $in_values as $value) { |
| $typeArray[$value] = true; |
$typeArray[$value] = true; |
| } |
} |
| Line 908 class Net_UserAgent_Detect { |
|
| Line 881 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function hasAcceptType($in_value, $in_type) |
function hasAcceptType($in_value, $in_type) |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
return (bool) Net_UserAgent_Detect::getAcceptType((array) $in_value, $in_type); |
| $this =& Net_UserAgent_Detect::singleton(); |
|
| } |
|
| |
|
| $type = strtolower($in_type); |
|
| |
|
| if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') { |
|
| $typeArray =& $this->$type; |
|
| return !empty($typeArray[$in_value]); |
|
| } |
|
| else { |
|
| return false; |
|
| } |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| Line 934 class Net_UserAgent_Detect { |
|
| Line 895 class Net_UserAgent_Detect { |
|
| */ |
*/ |
| function getUserAgent() |
function getUserAgent() |
| { |
{ |
| if (!isset($this) || get_class($this) != 'net_useragent_detect') { |
Net_UserAgent_Detect::detect(); |
| $this =& Net_UserAgent_Detect::singleton(); |
$userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent'); |
| } |
return $userAgent; |
| |
} |
| |
|
| |
// }}} |
| |
// {{{ _getStaticProperty() |
| |
|
| return $this->userAgent; |
/** |
| |
* Copy of getStaticProperty() from PEAR.php to avoid having to |
| |
* include PEAR.php |
| |
* |
| |
* @access private |
| |
* @param string $var The variable to retrieve. |
| |
* @return mixed A reference to the variable. If not set it will be |
| |
* auto initialised to NULL. |
| |
*/ |
| |
function &_getStaticProperty($var) |
| |
{ |
| |
static $properties; |
| |
return $properties[$var]; |
| } |
} |
| |
|
| // }}} |
// }}} |