Permalink
Browse files

* Adding new "browsers" that make it easier to exclude old browsers: …

…belowie6, belowns6, and belowopera8

* Adding new "feature" which tells if a browser is AJAX enabled: ajax


git-svn-id: http://svn.php.net/repository/pear/packages/Net_UserAgent/trunk@211706 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 01c487d commit e836a204ed7663c7c142c62df8678060fd816f01 Jason Rust committed Apr 19, 2006
Showing with 12 additions and 3 deletions.
  1. +10 −3 Detect.php
  2. +2 −0 tests/example.php
View
@@ -122,7 +122,7 @@ function detect($in_userAgent = null, $in_detect = null)
// 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', 'ie7', 'ie7up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera6', 'opera7', 'opera8', 'opera5up', 'opera6up', 'opera7up', 'opera8up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'aol8', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up', 'konq', 'safari', 'netgem', 'webdav', 'icab'));
+ $browser = array_flip(array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'belowns6', 'ns6up', 'firefox', 'firefox0.x', 'firefox1.x', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'belowie6', 'ie6up', 'ie7', 'ie7up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera6', 'opera7', 'opera8', 'opera5up', 'opera6up', 'opera7up', 'belowopera8', 'opera8up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'aol8', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up', 'konq', 'safari', 'netgem', 'webdav', 'icab'));
// Array that stores all of the flags for the operating systems,
// and in some cases the versions of those operating systems (windows)
@@ -152,7 +152,8 @@ function detect($in_userAgent = null, $in_detect = null)
'dhtml' => false,
'dom' => false,
'sidebar' => false,
- 'gecko' => false);
+ 'gecko' => false,
+ 'ajax' => false);
// The leading identifier is the very first term in the user
// agent string, which is used to identify clients which are not
@@ -236,7 +237,7 @@ function detect($in_userAgent = null, $in_detect = null)
$browser['ns4'] = $browser['ns'] && $majorVersion == 4;
$browser['ns4up'] = $browser['ns'] && $majorVersion >= 4;
// determine if this is a Netscape Navigator
- $browser['nav'] = $browser['ns'] && $majorVersion < 5;
+ $browser['nav'] = $browser['belowns6'] = $browser['ns'] && $majorVersion < 5;
$browser['ns6'] = !$browser['konq'] && $browser['ns'] && $majorVersion == 5;
$browser['ns6up'] = $browser['ns6'] && $majorVersion >= 5;
$browser['gecko'] = strpos($agt, 'gecko') !== false && !$browser['konq'];
@@ -255,6 +256,7 @@ function detect($in_userAgent = null, $in_detect = null)
$browser['ie6up'] = $browser['ie5up'] && !$browser['ie5'] && !$browser['ie5_5'];
$browser['ie7'] = strpos($agt, 'msie 7') !== false;
$browser['ie7up'] = $browser['ie6up'] && !$browser['ie6'];
+ $browser['belowie6']= $browser['ie'] && !$browser['ie6up'];
$browser['opera'] = strpos($agt, 'opera') !== false;
$browser['opera2'] = strpos($agt, 'opera 2') !== false || strpos($agt, 'opera/2') !== false;
$browser['opera3'] = strpos($agt, 'opera 3') !== false || strpos($agt, 'opera/3') !== false;
@@ -267,6 +269,7 @@ function detect($in_userAgent = null, $in_detect = null)
$browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'];
$browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'];
$browser['opera8up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'] && !$browser['opera7'];
+ $browser['belowopera8'] = $browser['opera'] && !$browser['opera8up'];
$browser['aol'] = strpos($agt, 'aol') !== false;
$browser['aol3'] = $browser['aol'] && $browser['ie3'];
$browser['aol4'] = $browser['aol'] && $browser['ie4'];
@@ -391,6 +394,10 @@ function detect($in_userAgent = null, $in_detect = null)
Net_UserAgent_Detect::setFeature('gecko', $matches[1]);
}
+ if ($browser['gecko'] || $browser['ie5up'] || $browser['konq'] || $browser['opera8up']) {
+ Net_UserAgent_Detect::setFeature('ajax');
+ }
+
if ($browser['ns6up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) {
Net_UserAgent_Detect::setFeature('dom');
}
View
@@ -23,6 +23,7 @@ function println($in_string) {
// }}}
if (in_array(php_sapi_name(), array('cli', 'cgi')) && empty($_SERVER['REMOTE_ADDR'])) {
+ // List of user agent strings: http://www.scanmybrowser.com/ua_strings.html
Net_UserAgent_Detect::setOption('re-evaluate', true);
foreach (array('en-us' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417',
'fr' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)') as $lang => $brwsr) {
@@ -46,6 +47,7 @@ function print_info()
println('Browser flag: ' . Net_UserAgent_Detect::getBrowser($browserSearch));
println('Has "popups disabled" quirk: ' . (Net_UserAgent_Detect::hasQuirk('popups_disabled') ? 'Yes' : 'No'));
println('Has "dom" feature: ' . (Net_UserAgent_Detect::hasFeature('dom') ? 'Yes' : 'No'));
+ println('Has "ajax" feature: ' . (Net_UserAgent_Detect::hasFeature('ajax') ? 'Yes' : 'No'));
println('Javascript version: ' . Net_UserAgent_Detect::getFeature('javascript'));
$languages = array('fr', 'de', 'en-us');
println('Accept Language: ' . Net_UserAgent_Detect::getAcceptType($languages, 'language'));

0 comments on commit e836a20

Please sign in to comment.