]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Fix overly strict return value for revokeFollow methods
[friendica.git] / src / Model / User.php
index 4f63b381988e688c612baae21b491c822799d49b..e27a950adb57f609039f93e7ad5b5ff85f16d446 100644 (file)
@@ -234,7 +234,7 @@ class User
                $system['closeness'] = 0;
                $system['baseurl'] = DI::baseUrl();
                $system['gsid'] = GServer::getID($system['baseurl']);
-               DBA::insert('contact', $system);
+               Contact::insert($system);
        }
 
        /**
@@ -840,6 +840,52 @@ class User
                return false;
        }
 
+       /**
+        * Get avatar link for given user
+        *
+        * @param array  $user
+        * @param string $size One of the Proxy::SIZE_* constants
+        * @return string avatar link
+        * @throws Exception
+        */
+       public static function getAvatarUrl(array $user, string $size = ''):string
+       {
+               if (empty($user['nickname'])) {
+                       DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
+               }
+
+               $url = DI::baseUrl() . '/photo/';
+
+               switch ($size) {
+                       case Proxy::SIZE_MICRO:
+                               $url .= 'micro/';
+                               $scale = 6;
+                               break;
+                       case Proxy::SIZE_THUMB:
+                               $url .= 'avatar/';
+                               $scale = 5;
+                               break;
+                       default:
+                               $url .= 'profile/';
+                               $scale = 4;
+                               break;
+               }
+
+               $updated =  '';
+               $imagetype = IMAGETYPE_JPEG;
+
+               $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['uid'], 'profile' => true]);
+               if (!empty($photo)) {
+                       $updated = max($photo['created'], $photo['edited'], $photo['updated']);
+
+                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
+                               $imagetype = IMAGETYPE_PNG;
+                       }
+               }
+
+               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+       }
+
        /**
         * Catch-all user creation function
         *
@@ -1054,8 +1100,8 @@ class User
                $insert_result = DBA::insert('profile', [
                        'uid' => $uid,
                        'name' => $username,
-                       'photo' => DI::baseUrl() . "/photo/profile/{$uid}.jpg",
-                       'thumb' => DI::baseUrl() . "/photo/avatar/{$uid}.jpg",
+                       'photo' => self::getAvatarUrl($user),
+                       'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
                        'publish' => $publish,
                        'net-publish' => $netpublish,
                ]);
@@ -1585,8 +1631,8 @@ class User
        /**
         * Check if the given user id has delegations or is delegated
         *
-        * @param int $uid 
-        * @return bool 
+        * @param int $uid
+        * @return bool
         */
        public static function hasIdentities(int $uid):bool
        {