diff --git a/Source/UserAgentParser.php b/Source/UserAgentParser.php index 7633b65..55c8785 100644 --- a/Source/UserAgentParser.php +++ b/Source/UserAgentParser.php @@ -29,11 +29,11 @@ function parse_user_agent( $u_agent = null ) { if( preg_match('/\((.*?)\)/im', $u_agent, $parent_matches) ) { - preg_match_all('/(?PBB\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('/(?PBB\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']) ) { @@ -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('%(?PCamino|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[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[0-9A-Z.]+)|/(?:[A-Z]*))%ix', $u_agent, $result, PREG_PATTERN_ORDER); // If nothing matched, return null (to avoid undefined index errors) @@ -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]; diff --git a/Tests/user_agents.json b/Tests/user_agents.json index fee697f..b59fe59 100644 --- a/Tests/user_agents.json +++ b/Tests/user_agents.json @@ -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",