Fetch photo fields, ensuring that they are filled

This commit is contained in:
Michael 2020-07-28 12:58:19 +00:00
parent 74bc3de472
commit b79bb0d2cb
12 changed files with 82 additions and 32 deletions

View File

@ -26,8 +26,8 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model;
use Friendica\Model\Contact;
use Friendica\Module;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
function common_content(App $a)
@ -136,7 +136,7 @@ function common_content(App $a)
'url' => Model\Contact::magicLink($common_friend['url']),
'itemurl' => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
'name' => $contact_details['name'],
'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
'thumb' => Contact::getThumb($contact_details),
'img_hover' => $contact_details['name'],
'details' => $contact_details['location'],
'tags' => $contact_details['keywords'],

View File

@ -27,7 +27,6 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\Proxy as ProxyUtils;
/**
* Controller for /match.
@ -111,7 +110,7 @@ function match_content(App $a)
'tags' => $contact_details['keywords'] ?? '',
'about' => $contact_details['about'] ?? '',
'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'),
'connlnk' => $connlnk,
'img_hover' => $profile->tags,

View File

@ -20,7 +20,6 @@
*/
use Friendica\App;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
@ -29,9 +28,7 @@ use Friendica\Content\Text\HTML;
use Friendica\Core\ACL;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -41,7 +38,6 @@ use Friendica\Model\Post\Category;
use Friendica\Model\Profile;
use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
function network_init(App $a)
@ -587,7 +583,7 @@ function networkThreadedView(App $a, $update, $parent)
'id' => 'network',
'name' => $contact['name'],
'itemurl' => ($contact['addr'] ?? '') ?: $contact['nurl'],
'thumb' => ProxyUtils::proxifyUrl($contact['thumb'], false, ProxyUtils::SIZE_THUMB),
'thumb' => Contact::getThumb($contact),
'details' => $contact['location'],
];

View File

@ -34,7 +34,6 @@ use Friendica\Model\Verb;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\XML;
/**
@ -329,11 +328,7 @@ function ping_init(App $a)
if (DBA::isResult($notifs)) {
foreach ($notifs as $notif) {
$contact = Contact::getByURL($notif['url'], false, ['micro']);
if (isset($contact['micro'])) {
$notif['photo'] = ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO);
} else {
$notif['photo'] = ProxyUtils::proxifyUrl($notif['photo'], false, ProxyUtils::SIZE_MICRO);
}
$notif['photo'] = Contact::getMicro($contact, $notif['photo']);
$local_time = DateTimeFormat::local($notif['date']);

View File

@ -43,6 +43,7 @@ use Friendica\Protocol\Salmon;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
/**
@ -1787,13 +1788,79 @@ class Contact
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
*
* @param array $contact
* @return array contact array with avatar cache fields
*/
public static function checkAvatarCacheByArray(array $contact)
private static function checkAvatarCacheByArray(array $contact)
{
$update = false;
$contact_fields = [];

View File

@ -28,7 +28,6 @@ use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model;
use Friendica\Network\HTTPException;
use Friendica\Util\Proxy as ProxyUtils;
/**
* 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']),
'itemurl' => ($contactDetails['addr'] ?? '') ?: $friend['url'],
'name' => $contactDetails['name'],
'thumb' => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB),
'thumb' => Model\Contact::getThumb($contactDetails),
'img_hover' => $contactDetails['name'],
'details' => $contactDetails['location'],
'tags' => $contactDetails['keywords'],

View File

@ -279,8 +279,6 @@ class Contact extends BaseModule
if ($contact['network'] == Protocol::PHANTOM) {
$contact = false;
}
$contact = ModelContact::checkAvatarCacheByArray($contact);
}
if (DBA::isResult($contact)) {
@ -318,7 +316,7 @@ class Contact extends BaseModule
$vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
'$name' => $contact['name'],
'$photo' => $contact['photo'],
'$photo' => Model\Contact::getPhoto($contact),
'$url' => Model\Contact::magicLinkByContact($contact, $contact['url']),
'$addr' => $contact['addr'] ?? '',
'$network_link' => $network_link,
@ -614,7 +612,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')],
'$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')],
'$photo' => $contact['photo'],
'$photo' => Model\Contact::getPhoto($contact),
'$name' => $contact['name'],
'$dir_icon' => $dir_icon,
'$sparkle' => $sparkle,

View File

@ -27,10 +27,8 @@ use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
use Friendica\Util\Proxy;
/**
* Asynchronous HTML fragment provider for frio contact hovercards
@ -88,7 +86,7 @@ class Hovercard extends BaseModule
'name' => $contact['name'],
'nick' => $contact['nick'],
'addr' => $contact['addr'] ?: $contact['url'],
'thumb' => Proxy::proxifyUrl($contact['thumb'], false, Proxy::SIZE_THUMB),
'thumb' => Contact::getThumb($contact),
'url' => Contact::magicLink($contact['url']),
'nurl' => $contact['nurl'],
'location' => $contact['location'],

View File

@ -32,7 +32,6 @@ use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Network\HTTPException;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
/**
@ -168,7 +167,7 @@ class Directory extends BaseModule
'id' => $contact['id'],
'url' => Contact::magicLink($profile_link),
'itemurl' => $itemurl,
'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
'thumb' => Contact::getThumb($contact),
'img_hover' => $contact['name'],
'name' => $contact['name'],
'details' => $details,

View File

@ -32,7 +32,6 @@ use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
use Friendica\Util\Proxy as ProxyUtils;
class Contacts extends BaseProfile
{
@ -109,7 +108,7 @@ class Contacts extends BaseProfile
'id' => $contact['id'],
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
'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),
'username' => $contact_details['name'],
'details' => $contact_details['location'],

View File

@ -294,7 +294,7 @@ class Acl extends BaseModule
foreach ($r as $g) {
$entry = [
'type' => 'c',
'photo' => ProxyUtils::proxifyUrl($g['micro'], false, ProxyUtils::SIZE_MICRO),
'photo' => Contact::getMicro($g),
'name' => htmlspecialchars($g['name']),
'id' => intval($g['id']),
'network' => $g['network'],
@ -355,7 +355,7 @@ class Acl extends BaseModule
if (count($contact) > 0) {
$unknown_contacts[] = [
'type' => 'c',
'photo' => ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO),
'photo' => Contact::getMicro($contact),
'name' => htmlspecialchars($contact['name']),
'id' => intval($contact['cid']),
'network' => $contact['network'],

View File

@ -170,7 +170,7 @@ class Proxy
* @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function isLocalImage($url)
public static function isLocalImage($url)
{
if (substr($url, 0, 1) == '/') {
return true;