Skip to content

Commit

Permalink
Improves support for UC Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Dec 29, 2020
1 parent d405147 commit 978e667
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Predefined helper constants from `donatj\UserAgent\Platforms`
| `Platforms::PLAYSTATION_3` | PlayStation 3 |
| `Platforms::PLAYSTATION_4` | PlayStation 4 |
| `Platforms::PLAYSTATION_VITA` | PlayStation Vita |
| `Platforms::SYMBIAN` | Symbian |
| `Platforms::TIZEN` | Tizen |
| `Platforms::WINDOWS_PHONE` | Windows Phone |
| `Platforms::XBOX` | Xbox |
Expand Down
1 change: 1 addition & 0 deletions src/UserAgent/Platforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Platforms {
const PLAYSTATION_3 = 'PlayStation 3';
const PLAYSTATION_4 = 'PlayStation 4';
const PLAYSTATION_VITA = 'PlayStation Vita';
const SYMBIAN = 'Symbian';
const TIZEN = 'Tizen';
const WINDOWS_PHONE = 'Windows Phone';
const XBOX = 'Xbox';
Expand Down
4 changes: 3 additions & 1 deletion src/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function parse_user_agent( $u_agent = null ) {

if( preg_match('/\((.*?)\)/m', $u_agent, $parent_matches) ) {
preg_match_all(<<<'REGEX'
/(?P<platform>BB\d+;|Android|CrOS|Tizen|iPhone|iPad|iPod|Linux|(Open|Net|Free)BSD|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(New\ )?Nintendo\ (WiiU?|3?DS|Switch)|Xbox(\ One)?)
/(?P<platform>BB\d+;|Android|Adr|Symbian|CrOS|Tizen|iPhone|iPad|iPod|Linux|(Open|Net|Free)BSD|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(New\ )?Nintendo\ (WiiU?|3?DS|Switch)|Xbox(\ One)?)
(?:\ [^;]*)?
(?:;|$)/imx
REGEX
Expand All @@ -86,6 +86,8 @@ function parse_user_agent( $u_agent = null ) {
$platform = 'Linux';
} elseif( $platform == 'CrOS' ) {
$platform = 'Chrome OS';
} elseif( $platform == 'Adr' ) {
$platform = 'Android';
}

preg_match_all(<<<'REGEX'
Expand Down
25 changes: 25 additions & 0 deletions tests/user_agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,16 +549,36 @@
"browser": "SamsungBrowser",
"version": "4.0"
},
"UCWEB\/2.0 (MIDP-2.0; U; Adr 4.4.2; en-US; E75) U2\/1.0.0 UCBrowser\/9.0.2.389 U2\/1.0.0 Mobile": {
"platform": "Android",
"browser": "UC Browser",
"version": "9.0.2.389"
},
"Mozilla\/5.0 (Linux; U; Android 4.4.2; en-US; LG-D325 Build\/KOT49I.A1411471607) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 UCBrowser\/10.2.0.535 U3\/0.8.0 Mobile Safari\/534.30": {
"platform": "Android",
"browser": "UC Browser",
"version": "10.2.0.535"
},
"UCWEB\/2.0 (MIDP-2.0; U; Adr 2.3.6; en-US; GT-S5830i) U2\/1.0.0 UCBrowser\/10.6.8.732 U2\/1.0.0 Mobile": {
"platform": "Android",
"browser": "UC Browser",
"version": "10.6.8.732"
},
"Mozilla\/5.0 (Linux; U; Android 5.1.1; en-US; SM-G925F Build\/LMY47X) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 UCBrowser\/10.7.5.658 U3\/0.8.0 Mobile Safari\/534.30": {
"platform": "Android",
"browser": "UC Browser",
"version": "10.7.5.658"
},
"Mozilla\/5.0 (Linux; U; Android 8.1.0; zh-CN; EML-AL00 Build\/HUAWEIEML-AL00) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/57.0.2987.108 baidu.sogo.uc.UCBrowser\/11.9.4.974 UWS\/2.13.1.48 Mobile Safari\/537.36 AliApp(DingTalk\/4.5.11) com.alibaba.android.rimet\/10487439 Channel\/227200 language\/zh-CN": {
"platform": "Android",
"browser": "UC Browser",
"version": "11.9.4.974"
},
"Mozilla\/5.0 (Linux; U; Android 10; en-US; RMX1851 Build\/QKQ1.190918.001) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/57.0.2987.108 UCBrowser\/13.0.5.1290 Mobile Safari\/537.36": {
"platform": "Android",
"browser": "UC Browser",
"version": "13.0.5.1290"
},
"Mozilla\/5.0 (Linux; U; Android 6.0; en-US; ZTE BLADE V7 Build\/MRA58K) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/57.0.2987.108 UCBrowser\/13.0.8.1291 Mobile Safari\/537.36": {
"platform": "Android",
"browser": "UC Browser",
Expand Down Expand Up @@ -894,6 +914,11 @@
"browser": "Browser",
"version": "1.69"
},
"UCWEB\/2.0 (Symbian; U; S60 V5; id; NokiaN8-00) U2\/1.0.0 UCBrowser\/9.2.0.336 U2\/1.0.0 Mobile": {
"platform": "Symbian",
"browser": "UC Browser",
"version": "9.2.0.336"
},
"Mozilla\/5.0 (Linux; Tizen 2.3; SAMSUNG SM-Z130H) AppleWebKit\/537.3 (KHTML, like Gecko) SamsungBrowser\/1.0 ": {
"platform": "Tizen",
"browser": "SamsungBrowser",
Expand Down

0 comments on commit 978e667

Please sign in to comment.