]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Fix jpeg ending
[friendica.git] / src / Model / User.php
index c43209b22552afcd494a223d4740ff6214a256d7..93538bce641d684ba3601767fdffcc1a67f7288d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -481,13 +481,12 @@ class User
        /**
         * Returns the default group for a given user and network
         *
-        * @param int    $uid     User id
-        * @param string $network network name
+        * @param int $uid User id
         *
         * @return int group id
         * @throws Exception
         */
-       public static function getDefaultGroup($uid, $network = '')
+       public static function getDefaultGroup($uid)
        {
                $user = DBA::selectFirst('user', ['def_gid'], ['uid' => $uid]);
                if (DBA::isResult($user)) {
@@ -851,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) : '');
        }
 
        /**