Add helper methods for the session class
authorjoshuaruesweg <ruesweg@woltlab.com>
Fri, 30 Oct 2020 13:49:47 +0000 (14:49 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Mon, 2 Nov 2020 14:43:06 +0000 (15:43 +0100)
wcfsetup/install/files/lib/system/session/Session.class.php

index 0185efe3ba180b15e87b939d4667994c200fad32..7d031703a641387debf3cfa6869f765637977841 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\session;
+use wcf\util\UserUtil;
 
 /**
  * Represents a session.
@@ -57,4 +58,40 @@ final class Session {
        public function isAcpSession(): bool {
                return $this->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']);
+       }
 }