<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Core\Storage\Type\ExternalResource;
use Friendica\Core\Storage\Type\SystemResource;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image;
return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype']);
case "contact":
- $contact = Contact::getById($id, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
+ $contact = Contact::getById($id, ['uid', 'url', 'nurl', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) {
return false;
}
- If (($contact['uid'] != 0) && empty($contact['photo']) && empty($contact['avatar'])) {
+
+ // For local users directly use the photo record that is marked as the profile
+ if (Network::isLocalLink($contact['url'])) {
+ $contact = Contact::selectFirst(['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr'], ['nurl' => $contact['nurl'], 'self' => true]);
+ if (!empty($contact)) {
+ if ($customsize <= Proxy::PIXEL_MICRO) {
+ $scale = 6;
+ } elseif ($customsize <= Proxy::PIXEL_THUMB) {
+ $scale = 5;
+ } else {
+ $scale = 4;
+ }
+ $photo = MPhoto::selectFirst([], ["scale" => $scale, "uid" => $contact['uid'], "profile" => 1]);
+ if (!empty($photo)) {
+ return $photo;
+ }
+ }
+ }
+
+ if (!empty($contact['uid']) && empty($contact['photo']) && empty($contact['avatar'])) {
$contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']);
}
+
if (!empty($contact['photo']) && !empty($contact['avatar'])) {
// Fetch photo directly
$resourceid = MPhoto::ridFromURI($contact['photo']);
}
$mimetext = '';
if (!empty($url)) {
- $mime = ParseUrl::getContentType($url);
+ $mime = ParseUrl::getContentType($url, HttpClient::ACCEPT_IMAGE);
if (!empty($mime)) {
$mimetext = $mime[0] . '/' . $mime[1];
} else {
if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) {
Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]);
$mimetext = '';
+ } if (!empty($mimetext)) {
+ Logger::debug('Expected Content-Type', ['mime' => $mimetext, 'url' => $url]);
}
}
if (empty($mimetext)) {
}
return MPhoto::createPhotoForExternalResource($url, 0, $mimetext);
case "header":
- $contact = Contact::getById($id, ['uid', 'url', 'header']);
+ $fields = ['uid', 'url', 'header', 'network', 'gsid'];
+ $contact = Contact::getById($id, $fields);
if (empty($contact)) {
return false;
}
If (($contact['uid'] != 0) && empty($contact['header'])) {
- $contact = Contact::getByURL($contact['url'], false, ['header']);
+ $contact = Contact::getByURL($contact['url'], false, $fields);
}
if (!empty($contact['header'])) {
$url = $contact['header'];
} else {
- $url = DI::baseUrl() . '/images/blank.png';
+ $url = Contact::getDefaultHeader($contact);
}
return MPhoto::createPhotoForExternalResource($url);
+ case "banner":
+ $photo = MPhoto::selectFirst([], ["scale" => 3, 'uid' => $id, 'photo-type' => MPhoto::USER_BANNER]);
+ if (!empty($photo)) {
+ return $photo;
+ }
+ return MPhoto::createPhotoForExternalResource(DI::baseUrl() . '/images/friendica-banner.jpg');
case "profile":
case "custom":
$scale = 4;