From 385d3f5883a945ffef2c9cd3c10f817930cc9433 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Wed, 28 Aug 2024 17:01:15 -0500 Subject: [PATCH] Roughs in Mastodon support --- src/UserAgent/Browsers.php | 1 + src/UserAgentParser.php | 4 ++-- tests/user_agents.dist.json | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/UserAgent/Browsers.php b/src/UserAgent/Browsers.php index 55a4894..990ed7b 100644 --- a/src/UserAgent/Browsers.php +++ b/src/UserAgent/Browsers.php @@ -31,6 +31,7 @@ interface Browsers { const IMESSAGEBOT = 'iMessageBot'; const KINDLE = 'Kindle'; const LYNX = 'Lynx'; + const MASTODON = 'Mastodon'; const MIDORI = 'Midori'; const MIUIBROWSER = 'MiuiBrowser'; const MSIE = 'MSIE'; diff --git a/src/UserAgentParser.php b/src/UserAgentParser.php index 3a144f3..1da2734 100644 --- a/src/UserAgentParser.php +++ b/src/UserAgentParser.php @@ -100,7 +100,7 @@ function parse_user_agent( $u_agent = null ) { TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|(?-i:Edge)|EdgA?|CriOS|UCBrowser|Puffin| OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi/MiuiBrowser|YaApp_Android| Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|ChatGPT-User|GPTBot|OAI-SearchBot| -Valve\ Steam\ Tenfoot| +Valve\ Steam\ Tenfoot|Mastodon| NintendoBrowser|PLAYSTATION\ (?:\d|Vita)+) \)?;? (?:[:/ ](?P[0-9A-Z.]+)|/[A-Z]*) @@ -188,7 +188,7 @@ function parse_user_agent( $u_agent = null ) { } } } - } elseif( $find([ 'Applebot', 'IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome', 'SailfishBrowser' ], $key, $browser) ) { + } elseif( $find([ 'Googlebot', 'Applebot', 'IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome', 'SailfishBrowser' ], $key, $browser) ) { $version = $result[BROWSER_VERSION][$key]; } elseif( $rv_result && $find('Trident') ) { $browser = 'MSIE'; diff --git a/tests/user_agents.dist.json b/tests/user_agents.dist.json index a22053b..ef8e155 100644 --- a/tests/user_agents.dist.json +++ b/tests/user_agents.dist.json @@ -744,6 +744,11 @@ "browser": "Firefox", "version": "84.0" }, + "Mozilla\/5.0 (Linux; Android 6.0.1; Nexus 5X Build\/MMB29P) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/90.0.4430.97 Mobile Safari\/537.36 (compatible; Googlebot\/2.1; +http:\/\/www.google.com\/bot.html)": { + "platform": "Android", + "browser": "Googlebot", + "version": "2.1" + }, "Mozilla\/5.0 (Linux; U; Android 8.1.0; en-gb; Redmi Note 5 Build\/OPM1.171019.011)\nAppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/61.0.3163.128 Mobile\nSafari\/537.36 XiaoMi\/MiuiBrowser\/10.1.2": { "platform": "Android", "browser": "MiuiBrowser", @@ -1429,6 +1434,11 @@ "browser": "Googlebot", "version": "1.3" }, + "Chrome\/90.0.4430.97 Mobile Safari\/537.36 (compatible; Googlebot\/2.1; +http:\/\/www.google.com\/bot.html)": { + "platform": null, + "browser": "Googlebot", + "version": "2.1" + }, "Mozilla\/5.0 (compatible; Googlebot\/2.1; +http:\/\/www.google.com\/bot.html)": { "platform": null, "browser": "Googlebot", @@ -1454,6 +1464,16 @@ "browser": "Lynx", "version": "2.8.6rel.4" }, + "http.rb\/5.1.1 (Mastodon\/4.2.5; +https:\/\/m.t-8.me\/)": { + "platform": null, + "browser": "Mastodon", + "version": "4.2.5" + }, + "http.rb\/5.2.0 (Mastodon\/4.3.0-alpha.3; +https:\/\/mstdn.social\/)": { + "platform": null, + "browser": "Mastodon", + "version": "4.3.0" + }, "msnbot-media\/1.1 (+http:\/\/search.msn.com\/msnbot.htm)": { "platform": null, "browser": "msnbot-media",