Merge pull request #10444 from annando/issue-10443

Issue 10443: Fix requesting media content
This commit is contained in:
Hypolite Petovan 2021-06-28 18:41:58 -04:00 committed by GitHub
commit 97556aa69c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,6 +63,7 @@ class Photo extends BaseModule
} }
$customsize = 0; $customsize = 0;
$square_resize = true;
$photo = false; $photo = false;
$scale = null; $scale = null;
$stamp = microtime(true); $stamp = microtime(true);
@ -70,6 +71,7 @@ class Photo extends BaseModule
$customsize = intval($parameters['customsize']); $customsize = intval($parameters['customsize']);
$uid = MPhoto::stripExtension($parameters['name']); $uid = MPhoto::stripExtension($parameters['name']);
$photo = self::getAvatar($uid, $parameters['type'], $customsize); $photo = self::getAvatar($uid, $parameters['type'], $customsize);
$square_resize = !in_array($parameters['type'], ['media', 'preview']);
} elseif (!empty($parameters['type'])) { } elseif (!empty($parameters['type'])) {
$uid = MPhoto::stripExtension($parameters['name']); $uid = MPhoto::stripExtension($parameters['name']);
$photo = self::getAvatar($uid, $parameters['type'], Proxy::PIXEL_SMALL); $photo = self::getAvatar($uid, $parameters['type'], Proxy::PIXEL_SMALL);
@ -105,10 +107,14 @@ class Photo extends BaseModule
} }
// if customsize is set and image is not a gif, resize it // if customsize is set and image is not a gif, resize it
if ($photo['type'] !== "image/gif" && $customsize > 0 && $customsize < 501) { if ($photo['type'] !== "image/gif" && $customsize > 0 && $customsize <= Proxy::PIXEL_THUMB && $square_resize) {
$img = new Image($imgdata, $photo['type']); $img = new Image($imgdata, $photo['type']);
$img->scaleToSquare($customsize); $img->scaleToSquare($customsize);
$imgdata = $img->asString(); $imgdata = $img->asString();
} elseif ($photo['type'] !== "image/gif" && $customsize > 0) {
$img = new Image($imgdata, $photo['type']);
$img->scaleDown($customsize);
$imgdata = $img->asString();
} }
if (function_exists("header_remove")) { if (function_exists("header_remove")) {
@ -168,9 +174,6 @@ class Photo extends BaseModule
return false; return false;
} }
$author = Contact::selectFirst([], ["`id` IN (SELECT `author-id` FROM `post` WHERE `uri-id` = ?)", $media['uri-id']]);
$url = Contact::magicLinkByContact($author, $url);
return MPhoto::createPhotoForExternalResource($url, (int)local_user()); return MPhoto::createPhotoForExternalResource($url, (int)local_user());
case "media": case "media":
$media = DBA::selectFirst('post-media', ['url', 'uri-id'], ['id' => $uid, 'type' => Post\Media::IMAGE]); $media = DBA::selectFirst('post-media', ['url', 'uri-id'], ['id' => $uid, 'type' => Post\Media::IMAGE]);
@ -178,10 +181,7 @@ class Photo extends BaseModule
return false; return false;
} }
$author = Contact::selectFirst([], ["`id` IN (SELECT `author-id` FROM `post` WHERE `uri-id` = ?)", $media['uri-id']]); return MPhoto::createPhotoForExternalResource($media['url'], (int)local_user());
$url = Contact::magicLinkByContact($author, $media['url']);
return MPhoto::createPhotoForExternalResource($url, (int)local_user());
case "contact": case "contact":
$contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']); $contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) { if (empty($contact)) {