Add updated_at column to accounts
[gamestick-pjgsapi.git] / src / Profile.php
index ca204ac7909fb45fb92192754b322c4643df4803..bf6ddb96010f68317bde3d8bfb08947368e5dcd8 100644 (file)
@@ -4,6 +4,8 @@
  */
 class Profile
 {
+    protected string $avatarDir;
+
     public int $id;
     public string $hwId;
     public string $sessionId;
@@ -15,6 +17,12 @@ class Profile
     public ?string $avatar;
 
     public string $created_at;
+    public string $updated_at;
+
+    public function __construct()
+    {
+        $this->avatarDir = dirname(__FILE__) . '/../www/resources/avatars/';
+    }
 
     public function complete(): bool
     {
@@ -26,8 +34,15 @@ class Profile
         if (strpos($this->avatar, '://')) {
             return $this->avatar;
         }
+
+        if (file_exists($this->avatarDir . $this->avatar . '.large.jpg')) {
+            $ext = 'jpg';
+        } else {
+            $ext = 'png';
+        }
+
         return 'http://l2.gamestickservices.net/resources/avatars/'
-            . $this->avatar . '.large.jpg';
+            . $this->avatar . '.large.' . $ext;
     }
 
     public function getAvatarSmallUrl(): string
@@ -35,7 +50,14 @@ class Profile
         if (strpos($this->avatar, '://')) {
             return $this->avatar;
         }
+
+        if (file_exists($this->avatarDir . $this->avatar . '.small.jpg')) {
+            $ext = 'jpg';
+        } else {
+            $ext = 'png';
+        }
+
         return 'http://l2.gamestickservices.net/resources/avatars/'
-            . $this->avatar . '.small.jpg';
+            . $this->avatar . '.small.' . $ext;
     }
 }