]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #11278 from annando/receiver-name
[friendica.git] / src / Model / User.php
index c8e9a61f17339ce59a22248b08de62cbe9028cc8..93538bce641d684ba3601767fdffcc1a67f7288d 100644 (file)
@@ -850,19 +850,46 @@ class User
                                break;
                }
 
-               $updated =  '';
-               $imagetype = IMAGETYPE_JPEG;
+               $updated  =  '';
+               $mimetype = '';
 
                $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']);
+                       $updated  = max($photo['created'], $photo['edited'], $photo['updated']);
+                       $mimetype = $photo['type'];
+               }
 
-                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
-                               $imagetype = IMAGETYPE_PNG;
-                       }
+               return $url . $user['nickname'] . Images::getExtensionByMimeType($mimetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+       }
+
+       /**
+        * Get banner link for given user
+        *
+        * @param array  $user
+        * @return string banner link
+        * @throws Exception
+        */
+       public static function getBannerUrl(array $user):string
+       {
+               if (empty($user['nickname'])) {
+                       DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
+               }
+
+               $url = DI::baseUrl() . '/photo/banner/';
+
+               $updated  = '';
+               $mimetype = '';
+
+               $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => 3, 'uid' => $user['uid'], 'photo-type' => Photo::USER_BANNER]);
+               if (!empty($photo)) {
+                       $updated  = max($photo['created'], $photo['edited'], $photo['updated']);
+                       $mimetype = $photo['type'];
+               } else {
+                       // Only for the RC phase: Don't return an image link for the default picture
+                       return '';
                }
 
-               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+               return $url . $user['nickname'] . Images::getExtensionByMimeType($mimetype) . ($updated ? '?ts=' . strtotime($updated) : '');
        }
 
        /**