mirror of
https://github.com/friendica/friendica
synced 2025-04-28 03:10:11 +00:00
Access contact avatars by guid
This commit is contained in:
parent
fe68df8e6a
commit
d30dc52101
5 changed files with 68 additions and 39 deletions
|
@ -1726,15 +1726,18 @@ class Contact
|
|||
* @param string $updated Contact update date
|
||||
* @return string avatar link
|
||||
*/
|
||||
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = ''):string
|
||||
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
|
||||
{
|
||||
// We have to fetch the "updated" variable when it wasn't provided
|
||||
// The parameter can be provided to improve performance
|
||||
if (empty($updated)) {
|
||||
$contact = self::getById($cid, ['updated']);
|
||||
$updated = $contact['updated'] ?? '';
|
||||
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:
|
||||
|
@ -1753,7 +1756,7 @@ class Contact
|
|||
$url .= Proxy::PIXEL_LARGE . '/';
|
||||
break;
|
||||
}
|
||||
return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1780,15 +1783,18 @@ class Contact
|
|||
* @param string $updated Contact update date
|
||||
* @return string header link
|
||||
*/
|
||||
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = ''):string
|
||||
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
|
||||
{
|
||||
// We have to fetch the "updated" variable when it wasn't provided
|
||||
// The parameter can be provided to improve performance
|
||||
if (empty($updated)) {
|
||||
$contact = self::getById($cid, ['updated']);
|
||||
$updated = $contact['updated'] ?? '';
|
||||
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/header/';
|
||||
switch ($size) {
|
||||
case Proxy::SIZE_MICRO:
|
||||
|
@ -1808,7 +1814,7 @@ class Contact
|
|||
break;
|
||||
}
|
||||
|
||||
return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2184,7 +2190,7 @@ class Contact
|
|||
}
|
||||
|
||||
$update = false;
|
||||
$guid = $ret['guid'] ?? '';
|
||||
$guid = $ret['guid'] ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
|
||||
|
||||
// make sure to not overwrite existing values with blank entries except some technical fields
|
||||
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
||||
|
@ -2212,6 +2218,12 @@ class Contact
|
|||
self::updateAvatar($id, $ret['photo'], $update);
|
||||
}
|
||||
|
||||
if (empty($guid)) {
|
||||
$uriid = ItemURI::getIdByURI($ret['url']);
|
||||
} else {
|
||||
$uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
|
||||
}
|
||||
|
||||
if (!$update) {
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
|
||||
|
||||
|
@ -2230,12 +2242,7 @@ class Contact
|
|||
return true;
|
||||
}
|
||||
|
||||
if (empty($guid)) {
|
||||
$ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
|
||||
} else {
|
||||
$ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
|
||||
}
|
||||
|
||||
$ret['uri-id'] = $uriid;
|
||||
$ret['nurl'] = Strings::normaliseLink($ret['url']);
|
||||
$ret['updated'] = $updated;
|
||||
$ret['failed'] = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue