]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #10845 from MrPetovan/bug/10844-unfollow-errors
[friendica.git] / src / Model / User.php
index f3f837eb2e6854a592587059c44d2fd5f027fdc7..e27a950adb57f609039f93e7ad5b5ff85f16d446 100644 (file)
@@ -841,14 +841,19 @@ class User
        }
 
        /**
-        * Get avatar link for given user id
+        * Get avatar link for given user
         *
-        * @param integer $uid     user id
-        * @param string  $size    One of the ProxyUtils::SIZE_* constants
+        * @param array  $user
+        * @param string $size One of the Proxy::SIZE_* constants
         * @return string avatar link
+        * @throws Exception
         */
-       public static function getAvatarUrlForId(int $uid, string $size = ''):string
+       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) {
@@ -869,26 +874,16 @@ class User
                $updated =  '';
                $imagetype = IMAGETYPE_JPEG;
 
-               $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
+               $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']);
 
-                       switch ($photo['type']) {
-                               case 'image/png':
-                                       $imagetype = IMAGETYPE_PNG;
-                                       break;
-
-                               case 'image/gif':
-                                       $imagetype = IMAGETYPE_PNG;
-                                       break;
-
-                               default:
-                                       $imagetype = IMAGETYPE_JPEG;
-                                       break;
+                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
+                               $imagetype = IMAGETYPE_PNG;
                        }
                }
 
-               return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
        }
 
        /**
@@ -1105,8 +1100,8 @@ class User
                $insert_result = DBA::insert('profile', [
                        'uid' => $uid,
                        'name' => $username,
-                       'photo' => self::getAvatarUrlForId($uid),
-                       'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
+                       'photo' => self::getAvatarUrl($user),
+                       'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
                        'publish' => $publish,
                        'net-publish' => $netpublish,
                ]);