]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
doc/themes.md,FAQ-admin: point to live friendica-themes.com mirror
[friendica.git] / src / Model / User.php
index d99588e05bb74246e779805291debec4c28b0140..497787d1c8b81abd3d23efcdd892ac43900e27b5 100644 (file)
@@ -34,6 +34,8 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
@@ -850,19 +852,16 @@ 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']);
-
-                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
-                               $imagetype = IMAGETYPE_PNG;
-                       }
+                       $updated  = max($photo['created'], $photo['edited'], $photo['updated']);
+                       $mimetype = $photo['type'];
                }
 
-               return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+               return $url . $user['nickname'] . Images::getExtensionByMimeType($mimetype) . ($updated ? '?ts=' . strtotime($updated) : '');
        }
 
        /**
@@ -880,22 +879,19 @@ class User
 
                $url = DI::baseUrl() . '/photo/banner/';
 
-               $updated  '';
-               $imagetype = IMAGETYPE_JPEG;
+               $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']);
-
-                       if (in_array($photo['type'], ['image/png', 'image/gif'])) {
-                               $imagetype = IMAGETYPE_PNG;
-                       }
+                       $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) : '');
        }
 
        /**
@@ -1156,8 +1152,9 @@ class User
                        $photo_failure = false;
 
                        $filename = basename($photo);
-                       $curlResult = DI::httpClient()->get($photo);
+                       $curlResult = DI::httpClient()->get($photo, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
                        if ($curlResult->isSuccess()) {
+                               Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
                                $img_str = $curlResult->getBody();
                                $type = $curlResult->getContentType();
                        } else {