]> git.mxchange.org Git - friendica.git/commitdiff
Fetch photo fields, ensuring that they are filled
authorMichael <heluecht@pirati.ca>
Tue, 28 Jul 2020 12:58:19 +0000 (12:58 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 28 Jul 2020 12:58:19 +0000 (12:58 +0000)
12 files changed:
mod/common.php
mod/match.php
mod/network.php
mod/ping.php
src/Model/Contact.php
src/Module/AllFriends.php
src/Module/Contact.php
src/Module/Contact/Hovercard.php
src/Module/Directory.php
src/Module/Profile/Contacts.php
src/Module/Search/Acl.php
src/Util/Proxy.php

index 0ff523b3f77c0d0f38b8ba9d3ce5c960a597908e..b59b36ee7d79267be9cff33bd8ddd0c7404d188b 100644 (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'],
index 3b24c4097a482bc47d8643a200c64d0c12be2bfa..f50a454ba9da919c05bbd578fe16ecbff70f387d 100644 (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,
index a3eb169839427274879ab9cdb1a71745ccec55a9..d82072754c9bf140e7d0602e8c68f63ff0dfeb1b 100644 (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'],
                        ];
 
index 848f2f0ecffc882a9f98bcf0298a197d202ccd36..c6e32a9314c4544f701ecf89c4ac081bd4cda609 100644 (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']);
 
index 9e89fc30a5a195ab070e907f519a4b2368b5fc79..bb876405421e0e723457e2bb302cf3e786579937 100644 (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 = [];
index 0a95256172220c83a86a6b4e0faf2100661bd22f..1c254b209488d8e32323ed11dc4b4e3c284d0622 100644 (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'],
index 5a4d0b1e86281b6ab9e4eb3bb9400e3fbd260219..ed6fe728a11c16bab997ad039c5899e2338d580d 100644 (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,
index 750b856bc301dea0c05563a58153cc8082053b6e..1d2fe856768c18edad8fe7543095a851ec282d09 100644 (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'],
index 507da6b94292ef97e22da1735462ff2cd3789d6c..38be89b93c860d576f2f2ca4ead732ed5466836c 100644 (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,
index 4cd97b4097e914ea3e8ca24099e6e0c249be8ccc..e7931bdb027d661a54a5267fdbdb3d2448601deb 100644 (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'],
index 8a5c9faf589177c51d45cd825f383bd66dfb7ea1..2c0cc967c03f20cc0aad820712e6bf74d7483a8c 100644 (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'],
index e104073f0331e6f22cd9dfcdce9b829e39bb309a..87f7c983e1acb4498d08834e9c5f7a02ec2860c9 100644 (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;