Skip to content

Commit

Permalink
Adds support for "Valve Steam Tenfoot"
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Mar 7, 2016
1 parent e9016b4 commit b003927
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Source/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function parse_user_agent( $u_agent = null ) {

if( preg_match('/\((.*?)\)/im', $u_agent, $parent_matches) ) {

preg_match_all('/(?P<platform>BB\d+;|Android|CrOS|Tizen|iPhone|iPad|iPod|Linux|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|(New\ )?Nintendo\ (WiiU?|3?DS)|Xbox(\ One)?)
preg_match_all('/(?P<platform>BB\d+;|Android|CrOS|Tizen|iPhone|iPad|iPod|Linux|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(New\ )?Nintendo\ (WiiU?|3?DS)|Xbox(\ One)?)
(?:\ [^;]*)?
(?:;|$)/imx', $parent_matches[1], $result, PREG_PATTERN_ORDER);

$priority = array( 'Xbox One', 'Xbox', 'Windows Phone', 'Tizen', 'Android' );
$priority = array( 'Xbox One', 'Xbox', 'Windows Phone', 'Tizen', 'Android', 'CrOS', 'Linux', 'X11' );
$result['platform'] = array_unique($result['platform']);
if( count($result['platform']) > 1 ) {
if( $keys = array_intersect($priority, $result['platform']) ) {
Expand All @@ -46,18 +46,19 @@ function parse_user_agent( $u_agent = null ) {
}
}

if( $platform == 'linux-gnu' ) {
if( $platform == 'linux-gnu' || $platform == 'X11' ) {
$platform = 'Linux';
} elseif( $platform == 'CrOS' ) {
$platform = 'Chrome OS';
}

preg_match_all('%(?P<browser>Camino|Kindle(\ Fire)?|Firefox|Iceweasel|Safari|MSIE|Trident|AppleWebKit|TizenBrowser|Chrome|
Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|CriOS|
Baiduspider|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
NintendoBrowser|PLAYSTATION\ (\d|Vita)+)
(?:\)?;?)
(?:(?:[:/ ])(?P<version>[0-9A-Z.]+)|/(?:[A-Z]*))%ix',
Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|CriOS|
Baiduspider|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
Valve\ Steam\ Tenfoot|
NintendoBrowser|PLAYSTATION\ (\d|Vita)+)
(?:\)?;?)
(?:(?:[:/ ])(?P<version>[0-9A-Z.]+)|/(?:[A-Z]*))%ix',
$u_agent, $result, PREG_PATTERN_ORDER);

// If nothing matched, return null (to avoid undefined index errors)
Expand Down Expand Up @@ -136,6 +137,9 @@ function parse_user_agent( $u_agent = null ) {
} elseif( $find('Vivaldi', $key) ) {
$browser = 'Vivaldi';
$version = $result['version'][$key];
} elseif( $find('Valve Steam Tenfoot', $key) ) {
$browser = 'Valve Steam Tenfoot';
$version = $result['version'][$key];
} elseif( $find('Chrome', $key) || $find('CriOS', $key) ) {
$browser = 'Chrome';
$version = $result['version'][$key];
Expand Down
15 changes: 15 additions & 0 deletions Tests/user_agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@
"browser": "Safari",
"version": "5.0.4"
},
"Mozilla\/5.0 (X11; U; X11; en-US; Valve Steam Tenfoot\/1352503901; ) AppleWebKit\/535.15 (KHTML, like Gecko) Chrome\/18.0.989.0 Safari\/535.11": {
"platform": "Linux",
"browser": "Valve Steam Tenfoot",
"version": "1352503901"
},
"Mozilla\/5.0 (Macintosh; U; MacOS X 10_11_3; en-US; Valve Steam Tenfoot\/1456366706; ) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/47.0.2526.80 Safari\/537.36": {
"platform": "Macintosh",
"browser": "Valve Steam Tenfoot",
"version": "1456366706"
},
"Mozilla\/5.0 (Windows; U; Windows NT 6.2; en-US; Valve Steam Tenfoot\/1451690000; ) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/47.0.2526.49 Safari\/537.36": {
"platform": "Windows",
"browser": "Valve Steam Tenfoot",
"version": "1451690000"
},
"Mozilla\/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.0.18) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/40.0.2214.89 Vivaldi\/1.0.83.38 Safari\/537.36": {
"platform": "Macintosh",
"browser": "Vivaldi",
Expand Down

0 comments on commit b003927

Please sign in to comment.