$attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
}
- $author_contact = Contact::getByURL($attributes['profile'], false, ['url', 'addr', 'name', 'micro']);
+ $author_contact = Contact::getByURL($attributes['profile'], false, ['id', 'url', 'addr', 'name', 'micro']);
$author_contact['url'] = ($author_contact['url'] ?? $attributes['profile']);
$author_contact['addr'] = ($author_contact['addr'] ?? '') ?: Protocol::getAddrFromProfileUrl($attributes['profile']);
$attributes['avatar'] = ($author_contact['micro'] ?? '') ?: $attributes['avatar'];
$attributes['profile'] = ($author_contact['url'] ?? '') ?: $attributes['profile'];
- if ($attributes['avatar']) {
+ if (!empty($author_contact['id'])) {
+ $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], ProxyUtils::SIZE_THUMB);
+ } elseif ($attributes['avatar']) {
$attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
}
$remote = $attachment['url'];
if ($type == 'image') {
- if (Proxy::isLocalImage($attachment['url'])) {
- $url = $attachment['url'];
- $preview = $attachment['preview'] ?? $url;
- $remote = '';
+ $url = Post\Media::getPreviewUrlForId($attachment['id']);
+ $preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
+ } else {
+ $url = Proxy::proxifyUrl($attachment['url']);
+
+ if (!empty($attachment['preview'])) {
+ $preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
} else {
- $url = Proxy::proxifyUrl($attachment['url']);
- $preview = Proxy::proxifyUrl($attachment['url'], false, Proxy::SIZE_SMALL);
+ $preview = '';
}
- } else {
- $url = Proxy::proxifyUrl($attachment['url']);
- $preview = Proxy::proxifyUrl($attachment['preview'] ?? '');
}
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
'madeby_zrl' => Contact::magicLink($notification['url']),
'madeby_addr' => $notification['addr'],
'contact_id' => $notification['contact-id'],
- 'photo' => (!empty($notification['fphoto']) ? Proxy::proxifyUrl($notification['fphoto'], false, Proxy::SIZE_SMALL) : Contact::DEFAULT_AVATAR_PHOTO),
+ 'photo' => Contact::getAvatarUrlForUrl($notification['furl'], 0, Proxy::SIZE_SMALL),
'name' => $notification['fname'],
'url' => $notification['furl'],
'zrl' => Contact::magicLink($notification['furl']),
use Friendica\Core\Protocol;
use Friendica\Core\Session\ISession;
use Friendica\Database\Database;
+use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Module\BaseNotifications;
use Friendica\Network\HTTPException\InternalServerErrorException;
$formattedNotifications[] = new \Friendica\Object\Notification\Notification([
'label' => 'notification',
'link' => $this->baseUrl->get(true) . '/notification/' . $notification->id,
- 'image' => Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
+ 'image' => Contact::getAvatarUrlForUrl($notification->url, $notification->uid, Proxy::SIZE_MICRO),
'url' => $notification->url,
'text' => strip_tags(BBCode::convert($notification->msg)),
'when' => DateTimeFormat::local($notification->date, 'r'),
$avatar = $contact['avatar'];
}
- if (empty($avatar)) {
- $avatar = self::getDefaultAvatar([], $size);
- }
-
- if (Proxy::isLocalImage($avatar)) {
+ if (!empty($avatar) && Proxy::isLocalImage($avatar)) {
return $avatar;
} else {
- return Proxy::proxifyUrl($avatar, false, $size);
+ return self::getAvatarUrlForId($contact['id'], $size);
}
}
/**
* Get avatar link for given contact id
*
- * @param integer $cid contact id
+ * @param integer $cid contact id
+ * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @return string avatar link
+ */
+ public static function getAvatarUrlForId(int $cid, string $size = ''):string
+ {
+ $url = DI::baseUrl() . '/photo/contact/';
+ switch ($size) {
+ case Proxy::SIZE_MICRO:
+ $url .= Proxy::PIXEL_MICRO . '/';
+ break;
+ case Proxy::SIZE_THUMB:
+ $url .= Proxy::PIXEL_THUMB . '/';
+ break;
+ case Proxy::SIZE_SMALL:
+ $url .= Proxy::PIXEL_SMALL . '/';
+ break;
+ case Proxy::SIZE_MEDIUM:
+ $url .= Proxy::PIXEL_MEDIUM . '/';
+ break;
+ case Proxy::SIZE_LARGE:
+ $url .= Proxy::PIXEL_LARGE . '/';
+ break;
+ }
+ return $url . $cid;
+ }
+
+ /**
+ * Get avatar link for given contact URL
+ *
+ * @param string $url contact url
+ * @param integer $uid user id
+ * @param string $size One of the ProxyUtils::SIZE_* constants
* @return string avatar link
*/
- public static function getAvatarUrlForId(int $cid):string
+ public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''):string
{
- return DI::baseUrl() . '/photo/contact/' . $cid;
+ $condition = ["`nurl` = ? AND ((`uid` = ? AND `network` IN (?, ?)) OR `uid` = ?)",
+ Strings::normaliseLink($url), $uid, Protocol::FEED, Protocol::MAIL, 0];
+ $contact = self::selectFirst(['id'], $condition);
+ return self::getAvatarUrlForId($contact['id'] ?? 0, $size);
}
/**
continue;
}
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
- $the_url = Contact::magicLinkByContact($author, $attachment['url']);
-
if (!empty($attachment['preview'])) {
- $preview_url = Proxy::proxifyUrl(Contact::magicLinkByContact($author, $attachment['preview']));
+ $preview_url = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_LARGE);
} else {
$preview_url = '';
}
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
'$video' => [
'id' => $attachment['id'],
- 'src' => $the_url,
+ 'src' => $attachment['url'],
'name' => $attachment['name'] ?: $attachment['url'],
'preview' => $preview_url,
'mime' => $attachment['mimetype'],
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
'$audio' => [
'id' => $attachment['id'],
- 'src' => $the_url,
- 'name' => $attachment['name'] ?: $attachment['url'],
+ 'src' => $attachment['url'],
+ 'name' => $attachment['name'] ?: $attachment['url'],
'mime' => $attachment['mimetype'],
],
]);
$trailing .= $media;
}
} elseif ($attachment['filetype'] == 'image') {
- if (empty($preview_url) && (max($attachment['width'], $attachment['height']) > 600)) {
- $preview_url = Proxy::proxifyUrl($the_url, false, ($attachment['width'] > $attachment['height']) ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE);
- }
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
- '$image' => [
- 'src' => Proxy::proxifyUrl($the_url),
- 'preview' => $preview_url,
- 'attachment' => $attachment,
+ '$image' => [
+ 'src' => Post\Media::getUrlForId($attachment['id']),
+ 'preview' => Post\Media::getPreviewUrlForId($attachment['id'], ($attachment['width'] > $attachment['height']) ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE),
+ 'attachment' => $attachment,
],
]);
// On Diaspora posts the attached pictures are leading
'type' => 'link',
'url' => $attachment['url']];
- if ($preview) {
+ if ($preview && !empty($attachment['preview'])) {
if ($attachment['preview-width'] >= 500) {
- $data['image'] = $attachment['preview'] ?? '';
+ $data['image'] = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_MEDIUM);
} else {
- $data['preview'] = $attachment['preview'] ?? '';
+ $data['preview'] = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_MEDIUM);
}
}
use Friendica\Model\Post;
use Friendica\Util\Images;
use Friendica\Util\ParseUrl;
+use Friendica\Util\Proxy;
use Friendica\Util\Strings;
/**
/**
* Split the attachment media in the three segments "visual", "link" and "additional"
- *
- * @param int $uri_id
+ *
+ * @param int $uri_id
* @param string $guid
- * @param array $links ist of links that shouldn't be added
+ * @param array $links ist of links that shouldn't be added
* @return array attachments
*/
public static function splitAttachments(int $uri_id, string $guid = '', array $links = [])
continue 2;
}
}
-
+
if (!empty($medium['preview'])) {
$previews[] = $medium['preview'];
}
return $body;
}
+
+ /**
+ * Get preview link for given media id
+ *
+ * @param integer $id media id
+ * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @return string preview link
+ */
+ public static function getPreviewUrlForId(int $id, string $size = ''):string
+ {
+ $url = DI::baseUrl() . '/photo/preview/';
+ switch ($size) {
+ case Proxy::SIZE_MICRO:
+ $url .= Proxy::PIXEL_MICRO . '/';
+ break;
+ case Proxy::SIZE_THUMB:
+ $url .= Proxy::PIXEL_THUMB . '/';
+ break;
+ case Proxy::SIZE_SMALL:
+ $url .= Proxy::PIXEL_SMALL . '/';
+ break;
+ case Proxy::SIZE_MEDIUM:
+ $url .= Proxy::PIXEL_MEDIUM . '/';
+ break;
+ case Proxy::SIZE_LARGE:
+ $url .= Proxy::PIXEL_LARGE . '/';
+ break;
+ }
+ return $url . $id;
+ }
+
+ /**
+ * Get media link for given media id
+ *
+ * @param integer $id media id
+ * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @return string media link
+ */
+ public static function getUrlForId(int $id, string $size = ''):string
+ {
+ $url = DI::baseUrl() . '/photo/media/';
+ switch ($size) {
+ case Proxy::SIZE_MICRO:
+ $url .= Proxy::PIXEL_MICRO . '/';
+ break;
+ case Proxy::SIZE_THUMB:
+ $url .= Proxy::PIXEL_THUMB . '/';
+ break;
+ case Proxy::SIZE_SMALL:
+ $url .= Proxy::PIXEL_SMALL . '/';
+ break;
+ case Proxy::SIZE_MEDIUM:
+ $url .= Proxy::PIXEL_MEDIUM . '/';
+ break;
+ case Proxy::SIZE_LARGE:
+ $url .= Proxy::PIXEL_LARGE . '/';
+ break;
+ }
+ return $url . $id;
+ }
}
// correct contact table entry for the logged-in user.
$profile_contact = [];
- if (!empty($profile['nurl'] ?? '')) {
- if (local_user() && ($profile['uid'] ?? '') != local_user()) {
- $profile_contact = Contact::getById(Contact::getIdForURL($profile['nurl'], local_user()));
+ if (!empty($profile['nurl'])) {
+ if (local_user() && ($profile['uid'] ?? 0) != local_user()) {
+ $profile_contact = Contact::getByURL($profile['nurl'], null, ['rel'], local_user());
}
if (!empty($profile['cid']) && self::getMyURL()) {
$profile_contact = Contact::selectFirst(['rel'], ['id' => $profile['cid']]);
$profile_url = DI::baseUrl()->get() . '/profile/' . $profile['nickname'];
}
+ if (!empty($profile['id'])) {
+ $cid = $profile['id'];
+ } else {
+ $cid = Contact::getIdForURL($profile_url, false);
+ }
+
$follow_link = null;
$unfollow_link = null;
$subscribe_feed_link = null;
$p['address'] = BBCode::convert($p['address']);
}
- if (isset($p['photo'])) {
- $p['photo'] = ProxyUtils::proxifyUrl($p['photo'], false, ProxyUtils::SIZE_SMALL);
- }
+ $p['photo'] = Contact::getAvatarUrlForId($cid);
- $p['url'] = Contact::magicLink(($p['url'] ?? '') ?: $profile_url);
+ $p['url'] = Contact::magicLink($profile_url);
$tpl = Renderer::getMarkupTemplate('profile/vcard.tpl');
$o .= Renderer::replaceMacros($tpl, [
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo as MPhoto;
+use Friendica\Model\Post;
use Friendica\Util\Proxy;
use Friendica\Object\Image;
if (!empty($parameters['customsize'])) {
$customsize = intval($parameters['customsize']);
$uid = MPhoto::stripExtension($parameters['name']);
- $photo = self::getAvatar($uid, $parameters['type']);
+ $photo = self::getAvatar($uid, $parameters['type'], $customsize);
} elseif (!empty($parameters['type'])) {
$uid = MPhoto::stripExtension($parameters['name']);
- $photo = self::getAvatar($uid, $parameters['type']);
+ $photo = self::getAvatar($uid, $parameters['type'], Proxy::PIXEL_SMALL);
} elseif (!empty($parameters['name'])) {
$photoid = MPhoto::stripExtension($parameters['name']);
$scale = 0;
exit();
}
- private static function getAvatar($uid, $type="avatar")
+ private static function getAvatar($uid, $type="avatar", $customsize)
{
switch($type) {
- case "contact":
- $contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo']);
+ case "preview":
+ $media = DBA::selectFirst('post-media', ['preview', 'url', 'type', 'uri-id'], ['id' => $uid]);
+ if (empty($media)) {
+ return false;
+ }
+ $url = $media['preview'];
+
+ if (empty($url) && ($media['type'] == Post\Media::IMAGE)) {
+ $url = $media['url'];
+ }
+
+ if (empty($url)) {
+ 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);
+ case "media":
+ $media = DBA::selectFirst('post-media', ['url'], ['id' => $uid, 'type' => Post\Media::IMAGE]);
+ if (empty($media['url'])) {
+ 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);
+ case "contact":
+ $contact = Contact::getById($uid, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) {
return false;
}
If (($contact['uid'] != 0) && empty($contact['photo']) && empty($contact['avatar'])) {
- $contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo']);
+ $contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']);
}
if (!empty($contact['photo'])) {
$url = $contact['photo'];
} 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 = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
+ $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
}
return MPhoto::createPhotoForExternalResource($url);
case "header":
default:
$default = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB);
}
-
+
$parts = parse_url($default);
if (!empty($parts['scheme']) || !empty($parts['host'])) {
$photo = MPhoto::createPhotoForExternalResource($default);
private static function getRequestInfo()
{
$a = DI::app();
- $size = 1024;
+ $size = ProxyUtils::PIXEL_LARGE;
$sizetype = '';
// Look for filename in the arguments
// thumb, small, medium and large.
if (substr($url, -6) == ':micro') {
- $size = 48;
+ $size = ProxyUtils::PIXEL_MICRO;
$sizetype = ':micro';
$url = substr($url, 0, -6);
} elseif (substr($url, -6) == ':thumb') {
- $size = 80;
+ $size = ProxyUtils::PIXEL_THUMB;
$sizetype = ':thumb';
$url = substr($url, 0, -6);
} elseif (substr($url, -6) == ':small') {
- $size = 300;
+ $size = ProxyUtils::PIXEL_SMALL;
$url = substr($url, 0, -6);
$sizetype = ':small';
} elseif (substr($url, -7) == ':medium') {
- $size = 600;
+ $size = ProxyUtils::PIXEL_MEDIUM;
$url = substr($url, 0, -7);
$sizetype = ':medium';
} elseif (substr($url, -6) == ':large') {
- $size = 1024;
+ $size = ProxyUtils::PIXEL_LARGE;
$url = substr($url, 0, -6);
$sizetype = ':large';
}
/**
* Sizes constants
*/
- const SIZE_MICRO = 'micro';
- const SIZE_THUMB = 'thumb';
- const SIZE_SMALL = 'small';
- const SIZE_MEDIUM = 'medium';
- const SIZE_LARGE = 'large';
+ const SIZE_MICRO = 'micro'; // 48
+ const SIZE_THUMB = 'thumb'; // 80
+ const SIZE_SMALL = 'small'; // 300
+ const SIZE_MEDIUM = 'medium'; // 600
+ const SIZE_LARGE = 'large'; // 1024
+
+ /**
+ * Pixel Sizes
+ */
+ const PIXEL_MICRO = 48;
+ const PIXEL_THUMB = 80;
+ const PIXEL_SMALL = 300;
+ const PIXEL_MEDIUM = 600;
+ const PIXEL_LARGE = 1024;
/**
* Accepted extensions