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;
/**
$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"]);
header_remove("Expires");
header_remove("Cache-Control");
}
- exit;
+ throw new NotModifiedException();
}
Profile::addVisitorCookieForHTTPSigner();
}
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();
$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'])) {
$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)) {