From a8eec778dfe6e74b5dd7b559a20a16035c05af75 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 5 Jun 2023 15:28:59 +0700 Subject: [PATCH] [ACP] Added showing user device type in online info (#772) --- admin/index.php | 6 ++-- composer.json | 1 + composer.lock | 60 +++++++++++++++++++++++++++++++- library/includes/functions.php | 22 ++++++++++++ library/language/source/main.php | 6 ++++ styles/templates/admin/index.tpl | 50 ++++++++++++++------------ 6 files changed, 119 insertions(+), 26 deletions(-) diff --git a/admin/index.php b/admin/index.php index 8bd9c2963..6faf6e472 100644 --- a/admin/index.php +++ b/admin/index.php @@ -125,7 +125,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { )); // Get users online information. - $sql = 'SELECT u.user_id, u.username, u.user_rank, s.session_time AS user_session_time, u.user_opt, s.session_logged_in, s.session_ip, s.session_start + $sql = 'SELECT u.user_id, u.username, u.user_rank, s.session_time AS user_session_time, u.user_opt, s.session_logged_in, s.session_ip, s.session_agent, s.session_start FROM ' . BB_USERS . ' u, ' . BB_SESSIONS . ' s WHERE s.session_logged_in = 1 AND u.user_id = s.session_user_id @@ -138,7 +138,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $onlinerow_reg = DB()->sql_fetchrowset($result); // Get guests online information. - $sql = 'SELECT session_logged_in, session_time, session_ip, session_start + $sql = 'SELECT session_logged_in, session_time, session_ip, session_agent, session_start FROM ' . BB_SESSIONS . ' WHERE session_logged_in = 0 AND session_time >= ' . (TIMENOW - 300) . ' @@ -164,6 +164,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'H:i', false), 'IP_ADDRESS' => $reg_ip, 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $reg_ip, + 'USER_DEVICE' => get_user_device($onlinerow_reg[$i]['session_agent']), )); } } @@ -183,6 +184,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'H:i', false), 'IP_ADDRESS' => $guest_ip, 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $guest_ip, + 'USER_DEVICE' => get_user_device($onlinerow_guest[$i]['session_agent']), )); } } diff --git a/composer.json b/composer.json index 1c1d6db6c..adf29929c 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "guzzlehttp/guzzle": "^7.5", "guzzlehttp/psr7": "^2.4", "longman/ip-tools": "1.2.1", + "mobiledetect/mobiledetectlib": "^3.74", "monolog/monolog": "^2.9", "rych/bencode": "v1.0.0", "samdark/sitemap": "2.4.0", diff --git a/composer.lock b/composer.lock index 9e1ccc5a9..218cdd918 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "37120ee700fdd2297989239da1026e46", + "content-hash": "b219ffca9c988e2666f5fd1b963cd675", "packages": [ { "name": "bugsnag/bugsnag", @@ -962,6 +962,64 @@ }, "time": "2016-10-23T20:08:46+00:00" }, + { + "name": "mobiledetect/mobiledetectlib", + "version": "3.74.0", + "source": { + "type": "git", + "url": "https://github.com/serbanghita/Mobile-Detect.git", + "reference": "812a4aa4605c63fc33d7fe32ca82f29275940b9d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/812a4aa4605c63fc33d7fe32ca82f29275940b9d", + "reference": "812a4aa4605c63fc33d7fe32ca82f29275940b9d", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "v2.19.3", + "phpunit/phpunit": "^7.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Detection\\": "src/" + }, + "classmap": [ + "src/MobileDetect.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Serban Ghita", + "email": "serbanghita@gmail.com", + "homepage": "http://mobiledetect.net", + "role": "Developer" + } + ], + "description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.", + "homepage": "https://github.com/serbanghita/Mobile-Detect", + "keywords": [ + "detect mobile devices", + "mobile", + "mobile detect", + "mobile detector", + "php mobile detect" + ], + "support": { + "issues": "https://github.com/serbanghita/Mobile-Detect/issues", + "source": "https://github.com/serbanghita/Mobile-Detect/tree/3.74.0" + }, + "time": "2022-12-04T15:37:32+00:00" + }, { "name": "monolog/monolog", "version": "2.9.1", diff --git a/library/includes/functions.php b/library/includes/functions.php index 0a2ce55b6..1d33da2ca 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2058,3 +2058,25 @@ function user_birthday_icon($user_birthday, $user_id): string return ($bb_cfg['birthday_enabled'] && $current_date == $user_birthday) ? '' : ''; } + +/** + * Get user device type (PC, Tablet, Phone) by USER_AGENT + * + * @param string $user_agent + * @return string + */ +function get_user_device($user_agent = USER_AGENT): string +{ + global $lang; + + $detect = new \Detection\MobileDetect(); + $detect->setUserAgent($user_agent); + + if ($detect->isMobile()) { + return $lang['DEVICE_MOBILE']; + } else if ($detect->isTablet()) { + return $lang['DEVICE_TABLET']; + } else { + return $lang['DEVICE_PC']; + } +} diff --git a/library/language/source/main.php b/library/language/source/main.php index 0dc401b27..544d973b6 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -2832,3 +2832,9 @@ $lang['EMAILER_SUBJECT'] = [ 'USER_WELCOME' => 'Welcome to the site %s', 'USER_WELCOME_INACTIVE' => 'Welcome to the site %s', ]; + +// Devices +$lang['DEVICE'] = 'Device'; +$lang['DEVICE_MOBILE'] = 'Phone'; +$lang['DEVICE_TABLET'] = 'Tablet'; +$lang['DEVICE_PC'] = 'PC'; diff --git a/styles/templates/admin/index.tpl b/styles/templates/admin/index.tpl index 4d4a97fe9..f62031925 100644 --- a/styles/templates/admin/index.tpl +++ b/styles/templates/admin/index.tpl @@ -196,29 +196,33 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +
{L_USERNAME}{L_LOGIN} / {L_LAST_UPDATED}{L_IP_ADDRESS}
{reg_user_row.USER}{reg_user_row.STARTED}-{reg_user_row.LASTUPDATE}{reg_user_row.IP_ADDRESS} -
.
{L_GUEST}{guest_user_row.STARTED}-{guest_user_row.LASTUPDATE}{guest_user_row.IP_ADDRESS}
{L_USERNAME}{L_LOGIN} / {L_LAST_UPDATED}{L_IP_ADDRESS}{L_DEVICE}
{reg_user_row.USER}{reg_user_row.STARTED}-{reg_user_row.LASTUPDATE}{reg_user_row.IP_ADDRESS} + {reg_user_row.USER_DEVICE}
.
{L_GUEST}{guest_user_row.STARTED}-{guest_user_row.LASTUPDATE}{guest_user_row.IP_ADDRESS}{guest_user_row.USER_DEVICE}
{L_SHOW_ONLINE_USERLIST}