1
0
Fork 0

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;
$square_resize = true;
$photo = false;
$scale = null;
$stamp = microtime(true);
@ -70,6 +71,7 @@ class Photo extends BaseModule
$customsize = intval($parameters['customsize']);
$uid = MPhoto::stripExtension($parameters['name']);
$photo = self::getAvatar($uid, $parameters['type'], $customsize);
$square_resize = !in_array($parameters['type'], ['media', 'preview']);
} elseif (!empty($parameters['type'])) {
$uid = MPhoto::stripExtension($parameters['name']);
$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 ($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->scaleToSquare($customsize);
$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")) {
@ -168,9 +174,6 @@ class Photo extends BaseModule
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());
case "media":
$media = DBA::selectFirst('post-media', ['url', 'uri-id'], ['id' => $uid, 'type' => Post\Media::IMAGE]);
@ -178,10 +181,7 @@ class Photo extends BaseModule
return false;
}
$author = Contact::selectFirst([], ["`id` IN (SELECT `author-id` FROM `post` WHERE `uri-id` = ?)", $media['uri-id']]);
$url = Contact::magicLinkByContact($author, $media['url']);
return MPhoto::createPhotoForExternalResource($url, (int)local_user());
return MPhoto::createPhotoForExternalResource($media['url'], (int)local_user());
case "contact":
$contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) {