Skip to content

Commit

Permalink
Adds support for TelegramBot, Twitterbot and iMessageBot
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Mar 16, 2021
1 parent 3b5aebb commit 246c1cf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
5 changes: 2 additions & 3 deletions .mddoc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
<badge-poser type="version"/>
<badge-poser type="downloads"/>
<badge-poser type="license"/>
<badge-travis name="donatj/phpUserAgent"/>
<badge-github-action name="donatj/phpUserAgent" workflow="CI"/>
<section title="What It Is">
<text><![CDATA[
A simple, streamlined PHP user-agent parser!
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php
]]></text>
</section>
<section title="Upgrading to `1.*`">
Expand Down Expand Up @@ -106,7 +105,7 @@ $ua->browserVersion();
<exec cmd="php .helpers/constants.php 'donatj\UserAgent\Browsers' 'Browser'"/>
</section>
<text><![CDATA[
More information is available at [Donat Studios](http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT).
More information is available at [Donat Studios](https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT).
]]></text>
</section>
</docpage>
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

A simple, streamlined PHP user-agent parser!

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php

## Upgrading to `1.*`

Expand Down Expand Up @@ -161,6 +161,7 @@ Predefined helper constants from `donatj\UserAgent\Browsers`
| `Browsers::GOOGLEBOT_VIDEO` | Googlebot-Video |
| `Browsers::HEADLESSCHROME` | HeadlessChrome |
| `Browsers::IEMOBILE` | IEMobile |
| `Browsers::IMESSAGEBOT` | iMessageBot |
| `Browsers::KINDLE` | Kindle |
| `Browsers::LYNX` | Lynx |
| `Browsers::MIDORI` | Midori |
Expand All @@ -176,7 +177,9 @@ Predefined helper constants from `donatj\UserAgent\Browsers`
| `Browsers::SAILFISHBROWSER` | SailfishBrowser |
| `Browsers::SAMSUNGBROWSER` | SamsungBrowser |
| `Browsers::SILK` | Silk |
| `Browsers::TELEGRAMBOT` | TelegramBot |
| `Browsers::TIZENBROWSER` | TizenBrowser |
| `Browsers::TWITTERBOT` | Twitterbot |
| `Browsers::UC_BROWSER` | UC Browser |
| `Browsers::VALVE_STEAM_TENFOOT` | Valve Steam Tenfoot |
| `Browsers::VIVALDI` | Vivaldi |
Expand All @@ -185,4 +188,4 @@ Predefined helper constants from `donatj\UserAgent\Browsers`
| `Browsers::YANDEX` | Yandex |
| `Browsers::YANDEXBOT` | YandexBot |

More information is available at [Donat Studios](http://donatstudios.com/PHP-Parser-HTTP_USER_AGENT).
More information is available at [Donat Studios](https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT).
3 changes: 3 additions & 0 deletions src/UserAgent/Browsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface Browsers {
const GOOGLEBOT_VIDEO = 'Googlebot-Video';
const HEADLESSCHROME = 'HeadlessChrome';
const IEMOBILE = 'IEMobile';
const IMESSAGEBOT = 'iMessageBot';
const KINDLE = 'Kindle';
const LYNX = 'Lynx';
const MIDORI = 'Midori';
Expand All @@ -41,7 +42,9 @@ interface Browsers {
const SAILFISHBROWSER = 'SailfishBrowser';
const SAMSUNGBROWSER = 'SamsungBrowser';
const SILK = 'Silk';
const TELEGRAMBOT = 'TelegramBot';
const TIZENBROWSER = 'TizenBrowser';
const TWITTERBOT = 'Twitterbot';
const UC_BROWSER = 'UC Browser';
const VALVE_STEAM_TENFOOT = 'Valve Steam Tenfoot';
const VIVALDI = 'Vivaldi';
Expand Down
6 changes: 3 additions & 3 deletions src/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function parse_user_agent( $u_agent = null ) {
%(?P<browser>Camino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|
TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin|
OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi/MiuiBrowser|
Baiduspider|Applebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
Valve\ Steam\ Tenfoot|
NintendoBrowser|PLAYSTATION\ (\d|Vita)+)
(?:\)?;?)
Expand Down Expand Up @@ -149,8 +149,8 @@ function parse_user_agent( $u_agent = null ) {

$key = 0;
$val = '';
if( $findT(array( 'OPR' => 'Opera', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser' ), $key, $browser) ) {
$version = $result[BROWSER_VERSION][$key];
if( $findT(array( 'OPR' => 'Opera', 'Facebot' => 'iMessageBot', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser' ), $key, $browser) ) {
$version = is_numeric(substr($result[BROWSER_VERSION][$key], 0, 1)) ? $result[BROWSER_VERSION][$key] : null;
} elseif( $find('Playstation Vita', $key, $platform) ) {
$platform = 'PlayStation Vita';
$browser = 'Browser';
Expand Down
20 changes: 20 additions & 0 deletions tests/user_agents.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
"browser": "HeadlessChrome",
"version": "69.0.3452.0"
},
"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit\/601.2.4 (KHTML, like Gecko) Version\/9.0.1 Safari\/601.2.4 facebookexternalhit\/1.1 Facebot Twitterbot\/1.0": {
"platform": "Macintosh",
"browser": "iMessageBot",
"version": null
},
"Mozilla\/5.0 (X11; U; Linux i686; de-DE; rv:1.8.1.9) Gecko\/20071103 Midori\/0.0.10": {
"platform": "Linux",
"browser": "Midori",
Expand Down Expand Up @@ -1094,6 +1099,11 @@
"browser": "curl",
"version": "7.19.7"
},
"facebookexternalhit\/1.1": {
"platform": null,
"browser": "facebookexternalhit",
"version": "1.1"
},
"facebookexternalhit\/1.1 (+http:\/\/www.facebook.com\/externalhit_uatext.php)": {
"platform": null,
"browser": "facebookexternalhit",
Expand Down Expand Up @@ -1134,6 +1144,16 @@
"browser": "msnbot-media",
"version": "1.1"
},
"TelegramBot (like TwitterBot)": {
"platform": null,
"browser": "TelegramBot",
"version": null
},
"Twitterbot\/1.0": {
"platform": null,
"browser": "Twitterbot",
"version": "1.0"
},
"WordPress\/3.7.1; http:\/\/wordpress.com": {
"platform": null,
"browser": "WordPress",
Expand Down

0 comments on commit 246c1cf

Please sign in to comment.