+ // We have to fetch the "updated" variable when it wasn't provided
+ // The parameter can be provided to improve performance
+ if (empty($updated) || empty($guid)) {
+ $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
+ $updated = $account['updated'] ?? '';
+ $guid = $account['guid'] ?? '';
+ }
+
+ $guid = urlencode($guid);
+
+ $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 . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
+ }
+
+ /**
+ * Get avatar link for given contact URL
+ *
+ * @param string $url contact url
+ * @param integer $uid user id
+ * @param string $size One of the Proxy::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', 'updated'], $condition, ['order' => ['uid' => true]]);
+ return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated'] ?? '');