]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Photo.php
Some more API functions moved
[friendica.git] / src / Module / Photo.php
index 9ee737d3829db17036c481002e99f40913f12234..399313e3f5c428816d89404b1dbc47837376343c 100644 (file)
@@ -29,13 +29,15 @@ use Friendica\Model\Contact;
 use Friendica\Model\Photo as MPhoto;
 use Friendica\Model\Post;
 use Friendica\Model\Profile;
-use Friendica\Model\Storage\ExternalResource;
-use Friendica\Model\Storage\SystemResource;
+use Friendica\Core\Storage\Type\ExternalResource;
+use Friendica\Core\Storage\Type\SystemResource;
 use Friendica\Model\User;
 use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPException\NotModifiedException;
 use Friendica\Object\Image;
 use Friendica\Util\Images;
 use Friendica\Util\Network;
+use Friendica\Util\ParseUrl;
 use Friendica\Util\Proxy;
 
 /**
@@ -54,7 +56,6 @@ class Photo extends BaseModule
                $totalstamp = microtime(true);
 
                if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
-                       header("HTTP/1.1 304 Not Modified");
                        header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
                        if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) {
                                header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]);
@@ -66,7 +67,7 @@ class Photo extends BaseModule
                                header_remove("Expires");
                                header_remove("Cache-Control");
                        }
-                       exit;
+                       throw new NotModifiedException();
                }
 
                Profile::addVisitorCookieForHTTPSigner();
@@ -83,7 +84,7 @@ class Photo extends BaseModule
                        }
 
                        if (!empty($parameters['guid'])) {
-                               $guid = pathinfo($parameters['guid'], PATHINFO_FILENAME);
+                               $guid = $parameters['guid'];
                                $account = DBA::selectFirst('account-user-view', ['id'], ['guid' => $guid], ['order' => ['uid' => true]]);
                                if (empty($account)) {
                                        throw new HTTPException\NotFoundException();
@@ -92,8 +93,9 @@ class Photo extends BaseModule
                                $id = $account['id'];
                        }
 
-                       if (!empty($parameters['contact_id'])) {
-                               $id = intval(pathinfo($parameters['contact_id'], PATHINFO_FILENAME));
+                       // Contact Id Fallback, to remove after version 2021.12
+                       if (isset($parameters['contact_id'])) {
+                               $id = intval($parameters['contact_id']);
                        }
 
                        if (!empty($parameters['nickname_ext'])) {
@@ -283,14 +285,30 @@ class Photo extends BaseModule
                                        $url = $contact['avatar'];
                                } elseif (!empty($contact['avatar'])) {
                                        $url = $contact['avatar'];
-                               } elseif ($customsize <= Proxy::PIXEL_MICRO) {
-                                       $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO);
-                               } elseif ($customsize <= Proxy::PIXEL_THUMB) {
-                                       $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB);
-                               } else {
-                                       $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
                                }
-                               return MPhoto::createPhotoForExternalResource($url);
+                               $mimetext = '';
+                               if (!empty($url)) {
+                                       $mime = ParseUrl::getContentType($url);
+                                       if (!empty($mime)) {
+                                               $mimetext = $mime[0] . '/' . $mime[1];
+                                       } else {
+                                               Logger::info('Invalid file', ['url' => $url]);
+                                       }
+                                       if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) {
+                                               Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]);
+                                               $mimetext = '';
+                                       }
+                               }
+                               if (empty($mimetext)) {
+                                       if ($customsize <= Proxy::PIXEL_MICRO) {
+                                               $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO);
+                                       } elseif ($customsize <= Proxy::PIXEL_THUMB) {
+                                               $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB);
+                                       } else {
+                                               $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
+                                       }
+                               }
+                               return MPhoto::createPhotoForExternalResource($url, 0, $mimetext);
                        case "header":
                                $contact = Contact::getById($id, ['uid', 'url', 'header']);
                                if (empty($contact)) {