]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #10437 from annando/reduce-proxy
[friendica.git] / src / Model / Contact.php
index f196f6f6a7682c8c79e23f821d0e8a2069183994..86f848da39d4008f17343aa12dee8c8620c27635 100644 (file)
@@ -1103,7 +1103,7 @@ class Contact
                if (($uid == 0) && (empty($data['network']) || ($data['network'] == Protocol::PHANTOM))) {
                        // Fetch data for the public contact via the first found personal contact
                        /// @todo Check if this case can happen at all (possibly with mail accounts?)
-                       $fields = ['name', 'nick', 'url', 'addr', 'alias', 'avatar', 'contact-type',
+                       $fields = ['name', 'nick', 'url', 'addr', 'alias', 'avatar', 'header', 'contact-type',
                                'keywords', 'location', 'about', 'unsearchable', 'batch', 'notify', 'poll',
                                'request', 'confirm', 'poco', 'subscribe', 'network', 'baseurl', 'gsid'];
 
@@ -1510,14 +1510,10 @@ class Contact
                        $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);
                }
        }
 
@@ -1614,7 +1610,7 @@ class Contact
         *
         * @param array $contact  contact array
         * @param string $size    Size of the avatar picture
-        * @return void
+        * @return string avatar URL
         */
        public static function getDefaultAvatar(array $contact, string $size)
        {
@@ -1662,6 +1658,63 @@ class Contact
                return DI::baseUrl() . $default;
        }
 
+       /**
+        * Get avatar link for given 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 getAvatarUrlForUrl(string $url, int $uid, string $size = ''):string
+       {
+               $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);
+       }
+
+       /**
+        * Get header link for given contact id
+        *
+        * @param integer $cid contact id
+        * @return string header link
+        */
+       public static function getHeaderUrlForId(int $cid):string
+       {
+               return DI::baseUrl() . '/photo/header/' . $cid;
+       }
+
        /**
         * Updates the avatar links in a contact only if needed
         *
@@ -1949,8 +2002,8 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe', 'manually-approve',
-                       'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
+               $fields = ['uid', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
+                       'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
                        'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
                if (!DBA::isResult($contact)) {