Merge pull request #10925 from annando/invalid-url

Handle invalid avatar pictures
This commit is contained in:
Hypolite Petovan 2021-10-24 22:39:33 -04:00 committed by GitHub
commit 40666d3585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ use Friendica\Network\HTTPException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
/** /**
@ -284,14 +285,26 @@ class Photo extends BaseModule
$url = $contact['avatar']; $url = $contact['avatar'];
} elseif (!empty($contact['avatar'])) { } elseif (!empty($contact['avatar'])) {
$url = $contact['avatar']; $url = $contact['avatar'];
} elseif ($customsize <= Proxy::PIXEL_MICRO) { }
$mimetext = '';
if (!empty($url)) {
$mime = ParseUrl::getContentType($url);
if (empty($mime) || ($mime[0] != 'image')) {
$url = '';
} else {
$mimetext = $mime[0] . '/' . $mime[1];
}
}
if (empty($url)) {
if ($customsize <= Proxy::PIXEL_MICRO) {
$url = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO); $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO);
} elseif ($customsize <= Proxy::PIXEL_THUMB) { } elseif ($customsize <= Proxy::PIXEL_THUMB) {
$url = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB); $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB);
} else { } else {
$url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL); $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
} }
return MPhoto::createPhotoForExternalResource($url); }
return MPhoto::createPhotoForExternalResource($url, 0, $mimetext);
case "header": case "header":
$contact = Contact::getById($id, ['uid', 'url', 'header']); $contact = Contact::getById($id, ['uid', 'url', 'header']);
if (empty($contact)) { if (empty($contact)) {