Merge pull request #8938 from annando/get-avatar
Fetch photo fields, ensuring that they are filled
This commit is contained in:
commit
418c2edb50
|
@ -26,8 +26,8 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Module;
|
use Friendica\Module;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
function common_content(App $a)
|
function common_content(App $a)
|
||||||
|
@ -136,7 +136,7 @@ function common_content(App $a)
|
||||||
'url' => Model\Contact::magicLink($common_friend['url']),
|
'url' => Model\Contact::magicLink($common_friend['url']),
|
||||||
'itemurl' => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
|
'itemurl' => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
|
||||||
'name' => $contact_details['name'],
|
'name' => $contact_details['name'],
|
||||||
'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact_details),
|
||||||
'img_hover' => $contact_details['name'],
|
'img_hover' => $contact_details['name'],
|
||||||
'details' => $contact_details['location'],
|
'details' => $contact_details['location'],
|
||||||
'tags' => $contact_details['keywords'],
|
'tags' => $contact_details['keywords'],
|
||||||
|
|
|
@ -27,7 +27,6 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for /match.
|
* Controller for /match.
|
||||||
|
@ -111,7 +110,7 @@ function match_content(App $a)
|
||||||
'tags' => $contact_details['keywords'] ?? '',
|
'tags' => $contact_details['keywords'] ?? '',
|
||||||
'about' => $contact_details['about'] ?? '',
|
'about' => $contact_details['about'] ?? '',
|
||||||
'account_type' => Contact::getAccountType($contact_details),
|
'account_type' => Contact::getAccountType($contact_details),
|
||||||
'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact_details, $profile->photo),
|
||||||
'conntxt' => DI::l10n()->t('Connect'),
|
'conntxt' => DI::l10n()->t('Connect'),
|
||||||
'connlnk' => $connlnk,
|
'connlnk' => $connlnk,
|
||||||
'img_hover' => $profile->tags,
|
'img_hover' => $profile->tags,
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Content\Feature;
|
|
||||||
use Friendica\Content\ForumManager;
|
use Friendica\Content\ForumManager;
|
||||||
use Friendica\Content\Nav;
|
use Friendica\Content\Nav;
|
||||||
use Friendica\Content\Pager;
|
use Friendica\Content\Pager;
|
||||||
|
@ -29,9 +28,7 @@ use Friendica\Content\Text\HTML;
|
||||||
use Friendica\Core\ACL;
|
use Friendica\Core\ACL;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Protocol;
|
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session;
|
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
@ -41,7 +38,6 @@ use Friendica\Model\Post\Category;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Module\Security\Login;
|
use Friendica\Module\Security\Login;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
function network_init(App $a)
|
function network_init(App $a)
|
||||||
|
@ -587,7 +583,7 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
'id' => 'network',
|
'id' => 'network',
|
||||||
'name' => $contact['name'],
|
'name' => $contact['name'],
|
||||||
'itemurl' => ($contact['addr'] ?? '') ?: $contact['nurl'],
|
'itemurl' => ($contact['addr'] ?? '') ?: $contact['nurl'],
|
||||||
'thumb' => ProxyUtils::proxifyUrl($contact['thumb'], false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact),
|
||||||
'details' => $contact['location'],
|
'details' => $contact['location'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ use Friendica\Model\Verb;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -329,11 +328,7 @@ function ping_init(App $a)
|
||||||
if (DBA::isResult($notifs)) {
|
if (DBA::isResult($notifs)) {
|
||||||
foreach ($notifs as $notif) {
|
foreach ($notifs as $notif) {
|
||||||
$contact = Contact::getByURL($notif['url'], false, ['micro']);
|
$contact = Contact::getByURL($notif['url'], false, ['micro']);
|
||||||
if (isset($contact['micro'])) {
|
$notif['photo'] = Contact::getMicro($contact, $notif['photo']);
|
||||||
$notif['photo'] = ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO);
|
|
||||||
} else {
|
|
||||||
$notif['photo'] = ProxyUtils::proxifyUrl($notif['photo'], false, ProxyUtils::SIZE_MICRO);
|
|
||||||
}
|
|
||||||
|
|
||||||
$local_time = DateTimeFormat::local($notif['date']);
|
$local_time = DateTimeFormat::local($notif['date']);
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ use Friendica\Protocol\Salmon;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Images;
|
use Friendica\Util\Images;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
use Friendica\Util\Proxy;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1787,13 +1788,79 @@ class Contact
|
||||||
self::updateAvatar($cid, $contact['avatar'], true);
|
self::updateAvatar($cid, $contact['avatar'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the photo path for a given contact array in the given size
|
||||||
|
*
|
||||||
|
* @param array $contact contact array
|
||||||
|
* @param string $field Fieldname of the photo in the contact array
|
||||||
|
* @param string $default Default path when no picture had been found
|
||||||
|
* @param string $size Size of the avatar picture
|
||||||
|
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||||
|
* @return string photo path
|
||||||
|
*/
|
||||||
|
private static function getAvatarPath(array $contact, string $field, string $default, string $size, string $avatar)
|
||||||
|
{
|
||||||
|
if (!empty($contact)) {
|
||||||
|
$contact = self::checkAvatarCacheByArray($contact);
|
||||||
|
if (!empty($contact[$field])) {
|
||||||
|
$avatar = $contact[$field];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($avatar)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Proxy::isLocalImage($avatar)) {
|
||||||
|
return $avatar;
|
||||||
|
} else {
|
||||||
|
return Proxy::proxifyUrl($avatar, false, $size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the photo path for a given contact array
|
||||||
|
*
|
||||||
|
* @param array $contact Contact array
|
||||||
|
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||||
|
* @return string photo path
|
||||||
|
*/
|
||||||
|
public static function getPhoto(array $contact, string $avatar = '')
|
||||||
|
{
|
||||||
|
return self::getAvatarPath($contact, 'photo', DI::baseUrl() . '/images/person-300.jpg', Proxy::SIZE_SMALL, $avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the photo path (thumb size) for a given contact array
|
||||||
|
*
|
||||||
|
* @param array $contact Contact array
|
||||||
|
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||||
|
* @return string photo path
|
||||||
|
*/
|
||||||
|
public static function getThumb(array $contact, string $avatar = '')
|
||||||
|
{
|
||||||
|
return self::getAvatarPath($contact, 'thumb', DI::baseUrl() . '/images/person-80.jpg', Proxy::SIZE_THUMB, $avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the photo path (micro size) for a given contact array
|
||||||
|
*
|
||||||
|
* @param array $contact Contact array
|
||||||
|
* @param string $avatar Avatar path that is displayed when no photo had been found
|
||||||
|
* @return string photo path
|
||||||
|
*/
|
||||||
|
public static function getMicro(array $contact, string $avatar = '')
|
||||||
|
{
|
||||||
|
return self::getAvatarPath($contact, 'micro', DI::baseUrl() . '/images/person-48.jpg', Proxy::SIZE_MICRO, $avatar);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the given contact array for avatar cache fields
|
* Check the given contact array for avatar cache fields
|
||||||
*
|
*
|
||||||
* @param array $contact
|
* @param array $contact
|
||||||
* @return array contact array with avatar cache fields
|
* @return array contact array with avatar cache fields
|
||||||
*/
|
*/
|
||||||
public static function checkAvatarCacheByArray(array $contact)
|
private static function checkAvatarCacheByArray(array $contact)
|
||||||
{
|
{
|
||||||
$update = false;
|
$update = false;
|
||||||
$contact_fields = [];
|
$contact_fields = [];
|
||||||
|
|
|
@ -28,7 +28,6 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module shows all public friends of the selected contact
|
* This module shows all public friends of the selected contact
|
||||||
|
@ -99,7 +98,7 @@ class AllFriends extends BaseModule
|
||||||
'url' => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
|
'url' => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
|
||||||
'itemurl' => ($contactDetails['addr'] ?? '') ?: $friend['url'],
|
'itemurl' => ($contactDetails['addr'] ?? '') ?: $friend['url'],
|
||||||
'name' => $contactDetails['name'],
|
'name' => $contactDetails['name'],
|
||||||
'thumb' => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Model\Contact::getThumb($contactDetails),
|
||||||
'img_hover' => $contactDetails['name'],
|
'img_hover' => $contactDetails['name'],
|
||||||
'details' => $contactDetails['location'],
|
'details' => $contactDetails['location'],
|
||||||
'tags' => $contactDetails['keywords'],
|
'tags' => $contactDetails['keywords'],
|
||||||
|
|
|
@ -36,7 +36,6 @@ use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
use Friendica\Model\Contact as ModelContact;
|
|
||||||
use Friendica\Module\Security\Login;
|
use Friendica\Module\Security\Login;
|
||||||
use Friendica\Network\HTTPException\BadRequestException;
|
use Friendica\Network\HTTPException\BadRequestException;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
@ -279,8 +278,6 @@ class Contact extends BaseModule
|
||||||
if ($contact['network'] == Protocol::PHANTOM) {
|
if ($contact['network'] == Protocol::PHANTOM) {
|
||||||
$contact = false;
|
$contact = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = ModelContact::checkAvatarCacheByArray($contact);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBA::isResult($contact)) {
|
if (DBA::isResult($contact)) {
|
||||||
|
@ -318,7 +315,7 @@ class Contact extends BaseModule
|
||||||
|
|
||||||
$vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
|
$vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
|
||||||
'$name' => $contact['name'],
|
'$name' => $contact['name'],
|
||||||
'$photo' => $contact['photo'],
|
'$photo' => Model\Contact::getPhoto($contact),
|
||||||
'$url' => Model\Contact::magicLinkByContact($contact, $contact['url']),
|
'$url' => Model\Contact::magicLinkByContact($contact, $contact['url']),
|
||||||
'$addr' => $contact['addr'] ?? '',
|
'$addr' => $contact['addr'] ?? '',
|
||||||
'$network_link' => $network_link,
|
'$network_link' => $network_link,
|
||||||
|
@ -614,7 +611,7 @@ class Contact extends BaseModule
|
||||||
'$notify' => ['notify', DI::l10n()->t('Notification for new posts'), ($contact['notify_new_posts'] == 1), DI::l10n()->t('Send a notification of every new post of this contact')],
|
'$notify' => ['notify', DI::l10n()->t('Notification for new posts'), ($contact['notify_new_posts'] == 1), DI::l10n()->t('Send a notification of every new post of this contact')],
|
||||||
'$fetch_further_information' => $fetch_further_information,
|
'$fetch_further_information' => $fetch_further_information,
|
||||||
'$ffi_keyword_denylist' => ['ffi_keyword_denylist', DI::l10n()->t('Keyword Deny List'), $contact['ffi_keyword_denylist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
|
'$ffi_keyword_denylist' => ['ffi_keyword_denylist', DI::l10n()->t('Keyword Deny List'), $contact['ffi_keyword_denylist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
|
||||||
'$photo' => $contact['photo'],
|
'$photo' => Model\Contact::getPhoto($contact),
|
||||||
'$name' => $contact['name'],
|
'$name' => $contact['name'],
|
||||||
'$dir_icon' => $dir_icon,
|
'$dir_icon' => $dir_icon,
|
||||||
'$sparkle' => $sparkle,
|
'$sparkle' => $sparkle,
|
||||||
|
|
|
@ -27,10 +27,8 @@ use Friendica\Core\Session;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\GContact;
|
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\Proxy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronous HTML fragment provider for frio contact hovercards
|
* Asynchronous HTML fragment provider for frio contact hovercards
|
||||||
|
@ -88,7 +86,7 @@ class Hovercard extends BaseModule
|
||||||
'name' => $contact['name'],
|
'name' => $contact['name'],
|
||||||
'nick' => $contact['nick'],
|
'nick' => $contact['nick'],
|
||||||
'addr' => $contact['addr'] ?: $contact['url'],
|
'addr' => $contact['addr'] ?: $contact['url'],
|
||||||
'thumb' => Proxy::proxifyUrl($contact['thumb'], false, Proxy::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact),
|
||||||
'url' => Contact::magicLink($contact['url']),
|
'url' => Contact::magicLink($contact['url']),
|
||||||
'nurl' => $contact['nurl'],
|
'nurl' => $contact['nurl'],
|
||||||
'location' => $contact['location'],
|
'location' => $contact['location'],
|
||||||
|
|
|
@ -32,7 +32,6 @@ use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,7 +167,7 @@ class Directory extends BaseModule
|
||||||
'id' => $contact['id'],
|
'id' => $contact['id'],
|
||||||
'url' => Contact::magicLink($profile_link),
|
'url' => Contact::magicLink($profile_link),
|
||||||
'itemurl' => $itemurl,
|
'itemurl' => $itemurl,
|
||||||
'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact),
|
||||||
'img_hover' => $contact['name'],
|
'img_hover' => $contact['name'],
|
||||||
'name' => $contact['name'],
|
'name' => $contact['name'],
|
||||||
'details' => $details,
|
'details' => $details,
|
||||||
|
|
|
@ -32,7 +32,6 @@ use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Module\BaseProfile;
|
use Friendica\Module\BaseProfile;
|
||||||
use Friendica\Util\Proxy as ProxyUtils;
|
|
||||||
|
|
||||||
class Contacts extends BaseProfile
|
class Contacts extends BaseProfile
|
||||||
{
|
{
|
||||||
|
@ -109,7 +108,7 @@ class Contacts extends BaseProfile
|
||||||
'id' => $contact['id'],
|
'id' => $contact['id'],
|
||||||
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
|
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
|
||||||
'photo_menu' => Contact::photoMenu($contact),
|
'photo_menu' => Contact::photoMenu($contact),
|
||||||
'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
|
'thumb' => Contact::getThumb($contact_details),
|
||||||
'name' => substr($contact_details['name'], 0, 20),
|
'name' => substr($contact_details['name'], 0, 20),
|
||||||
'username' => $contact_details['name'],
|
'username' => $contact_details['name'],
|
||||||
'details' => $contact_details['location'],
|
'details' => $contact_details['location'],
|
||||||
|
|
|
@ -294,7 +294,7 @@ class Acl extends BaseModule
|
||||||
foreach ($r as $g) {
|
foreach ($r as $g) {
|
||||||
$entry = [
|
$entry = [
|
||||||
'type' => 'c',
|
'type' => 'c',
|
||||||
'photo' => ProxyUtils::proxifyUrl($g['micro'], false, ProxyUtils::SIZE_MICRO),
|
'photo' => Contact::getMicro($g),
|
||||||
'name' => htmlspecialchars($g['name']),
|
'name' => htmlspecialchars($g['name']),
|
||||||
'id' => intval($g['id']),
|
'id' => intval($g['id']),
|
||||||
'network' => $g['network'],
|
'network' => $g['network'],
|
||||||
|
@ -355,7 +355,7 @@ class Acl extends BaseModule
|
||||||
if (count($contact) > 0) {
|
if (count($contact) > 0) {
|
||||||
$unknown_contacts[] = [
|
$unknown_contacts[] = [
|
||||||
'type' => 'c',
|
'type' => 'c',
|
||||||
'photo' => ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO),
|
'photo' => Contact::getMicro($contact),
|
||||||
'name' => htmlspecialchars($contact['name']),
|
'name' => htmlspecialchars($contact['name']),
|
||||||
'id' => intval($contact['cid']),
|
'id' => intval($contact['cid']),
|
||||||
'network' => $contact['network'],
|
'network' => $contact['network'],
|
||||||
|
|
|
@ -170,7 +170,7 @@ class Proxy
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
private static function isLocalImage($url)
|
public static function isLocalImage($url)
|
||||||
{
|
{
|
||||||
if (substr($url, 0, 1) == '/') {
|
if (substr($url, 0, 1) == '/') {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user