From 717f125396545a6cfe0c9e74c8ebd0bb92aecd20 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Fri, 30 Oct 2020 14:49:47 +0100 Subject: [PATCH] Add helper methods for the session class --- .../lib/system/session/Session.class.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/wcfsetup/install/files/lib/system/session/Session.class.php b/wcfsetup/install/files/lib/system/session/Session.class.php index 0185efe3ba..7d031703a6 100644 --- a/wcfsetup/install/files/lib/system/session/Session.class.php +++ b/wcfsetup/install/files/lib/system/session/Session.class.php @@ -1,5 +1,6 @@ isAcpSession; } + + /** + * Returns true, if the current object is the active session of the user. + */ + public function isCurrentSession(): bool { + return $this->getSessionID() === SessionHandler::getInstance()->sessionID; + } + + /** + * Returns a font awesome device icon. + */ + public function getDeviceIcon(): string { + if (UserUtil::isTablet($this->data['userAgent'])) { + return 'tablet'; + } + + if (UserUtil::isMobileBrowser($this->data['userAgent'])) { + return 'mobile'; + } + + return 'laptop'; + } + + /** + * Returns the converted ip address of the session. + */ + public function getIpAddress(): string { + return UserUtil::convertIPv6To4($this->data['ipAddress']); + } + + /** + * Returns the used browser. + */ + public function getBrowser(): string { + return UserUtil::getBrowser($this->data['userAgent']); + } } -- 2.20.1