]> git.mxchange.org Git - friendica.git/commitdiff
Cleaned code for contact avatars
authorMichael <heluecht@pirati.ca>
Tue, 6 Jul 2021 10:36:00 +0000 (10:36 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 6 Jul 2021 10:36:00 +0000 (10:36 +0000)
mod/message.php
src/Model/Contact.php
src/Module/Contact.php
src/Module/Search/Acl.php

index 06542bbaf24708f507448f88f817cc9c6aa4c755..2705708ea6f206e43dc43cfbb2869f3feda1328d 100644 (file)
@@ -325,7 +325,7 @@ function message_content(App $a)
                        $to_name_e = $message['name'];
 
                        $contact = Contact::getByURL($message['from-url'], false, ['thumb', 'addr', 'id', 'avatar']);
-                       $from_photo = Contact::getThumb($contact, $message['from-photo']);
+                       $from_photo = Contact::getThumb($contact);
 
                        $mails[] = [
                                'id' => $message['id'],
@@ -457,7 +457,7 @@ function render_messages(array $msg, $t)
                }
 
                $contact = Contact::getByURL($rr['url'], false, ['thumb', 'addr', 'id', 'avatar']);
-               $from_photo = Contact::getThumb($contact, $rr['thumb'] ?: $rr['from-photo']);
+               $from_photo = Contact::getThumb($contact);
 
                $rslt .= Renderer::replaceMacros($tpl, [
                        '$id' => $rr['id'],
index 5fc234d609e1abe0ff409f5ff2fdab70e0d7792f..c65837bd971a13dfbdaceee79a2d97e4819fb792 100644 (file)
@@ -1497,67 +1497,46 @@ class Contact
         * @param bool  $no_update Don't perfom an update if no cached avatar was found
         * @return string photo path
         */
-       private static function getAvatarPath(array $contact, string $field, string $size, string $avatar, $no_update = false)
+       private static function getAvatarPath(array $contact, string $size, $no_update = false)
        {
-               if (!empty($contact)) {
-                       $contact = self::checkAvatarCacheByArray($contact, $no_update);
-                       if (!empty($contact['id'])) {
-                               return self::getAvatarUrlForId($contact['id'], $size, $contact['updated'] ?? '');
-                       } elseif (!empty($contact[$field])) {
-                               return $contact[$field];
-                       } elseif (!empty($contact['avatar'])) {
-                               $avatar = $contact['avatar'];
-                       }
-               }
-
-               if (empty($avatar)) {
-                       $avatar = self::getDefaultAvatar([], $size);
-               }
-
-               if (Proxy::isLocalImage($avatar)) {
-                       return $avatar;
-               } else {
-                       return Proxy::proxifyUrl($avatar, $size);
-               }
+               $contact = self::checkAvatarCacheByArray($contact, $no_update);
+               return self::getAvatarUrlForId($contact['id'], $size, $contact['updated'] ?? '');
        }
 
        /**
         * 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
         * @param bool   $no_update Don't perfom an update if no cached avatar was found
         * @return string photo path
         */
-       public static function getPhoto(array $contact, string $avatar = '', bool $no_update = false)
+       public static function getPhoto(array $contact, bool $no_update = false)
        {
-               return self::getAvatarPath($contact, 'photo', Proxy::SIZE_SMALL, $avatar, $no_update);
+               return self::getAvatarPath($contact, Proxy::SIZE_SMALL, $no_update);
        }
 
        /**
         * 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
         * @param bool   $no_update Don't perfom an update if no cached avatar was found
         * @return string photo path
         */
-       public static function getThumb(array $contact, string $avatar = '', bool $no_update = false)
+       public static function getThumb(array $contact, bool $no_update = false)
        {
-               return self::getAvatarPath($contact, 'thumb', Proxy::SIZE_THUMB, $avatar, $no_update);
+               return self::getAvatarPath($contact, Proxy::SIZE_THUMB, $no_update);
        }
 
        /**
         * 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
         * @param bool   $no_update Don't perfom an update if no cached avatar was found
         * @return string photo path
         */
-       public static function getMicro(array $contact, string $avatar = '', bool $no_update = false)
+       public static function getMicro(array $contact, bool $no_update = false)
        {
-               return self::getAvatarPath($contact, 'micro', Proxy::SIZE_MICRO, $avatar, $no_update);
+               return self::getAvatarPath($contact, Proxy::SIZE_MICRO, $no_update);
        }
 
        /**
index cc6cc7e055f9c9b38f9c6c49dc39bd880c9fd96b..a00b0c702f03b9d581c5578c5fb9f726216d0334 100644 (file)
@@ -1111,7 +1111,7 @@ class Contact extends BaseModule
                        'url'          => $url,
                        'img_hover'    => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
                        'photo_menu'   => Model\Contact::photoMenu($contact),
-                       'thumb'        => Model\Contact::getThumb($contact, '', true),
+                       'thumb'        => Model\Contact::getThumb($contact, true),
                        'alt_text'     => $alt_text,
                        'name'         => $contact['name'],
                        'nick'         => $contact['nick'],
index ab031f9cbb0b0e60d9e450854db0f8fb5ff841ec..aa5a0e36789a91607d9a6dc071348409a5113eb1 100644 (file)
@@ -78,7 +78,7 @@ class Acl extends BaseModule
                $contacts = [];
                foreach ($result as $contact) {
                        $contacts[] = [
-                               'photo'   => Contact::getMicro($contact, '', true),
+                               'photo'   => Contact::getMicro($contact, true),
                                'name'    => htmlspecialchars($contact['name']),
                                'nick'    => $contact['addr'] ?: $contact['url'],
                                'network' => $contact['network'],