mirror of
https://github.com/friendica/friendica
synced 2025-04-24 11:10:18 +00:00
Merge pull request #10721 from annando/issue-10720-avatar
Issue 10720: Use different path scheme for user avatars
This commit is contained in:
commit
24ecf5954c
12 changed files with 84 additions and 34 deletions
|
@ -627,9 +627,9 @@ class Contact
|
|||
'nick' => $user['nickname'],
|
||||
'pubkey' => $user['pubkey'],
|
||||
'prvkey' => $user['prvkey'],
|
||||
'photo' => DI::baseUrl() . '/photo/profile/' . $user['uid'] . '.jpg',
|
||||
'thumb' => DI::baseUrl() . '/photo/avatar/' . $user['uid'] . '.jpg',
|
||||
'micro' => DI::baseUrl() . '/photo/micro/' . $user['uid'] . '.jpg',
|
||||
'photo' => User::getAvatarUrlForId($user['uid']),
|
||||
'thumb' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_THUMB),
|
||||
'micro' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_MICRO),
|
||||
'blocked' => 0,
|
||||
'pending' => 0,
|
||||
'url' => DI::baseUrl() . '/profile/' . $user['nickname'],
|
||||
|
@ -742,7 +742,7 @@ class Contact
|
|||
$fields['micro'] = self::getDefaultAvatar($fields, Proxy::SIZE_MICRO);
|
||||
}
|
||||
|
||||
$fields['avatar'] = DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix;
|
||||
$fields['avatar'] = User::getAvatarUrlForId($uid);
|
||||
$fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
||||
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
|
||||
$fields['unsearchable'] = !$profile['net-publish'];
|
||||
|
@ -768,8 +768,11 @@ class Contact
|
|||
DBA::update('contact', $fields, ['uid' => 0, 'nurl' => $self['nurl']]);
|
||||
|
||||
// Update the profile
|
||||
$fields = ['photo' => DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix,
|
||||
'thumb' => DI::baseUrl() . '/photo/avatar/' . $uid .'.' . $file_suffix];
|
||||
$fields = [
|
||||
'photo' => User::getAvatarUrlForId($uid),
|
||||
'thumb' => User::getAvatarUrlForId($uid, Proxy::SIZE_THUMB)
|
||||
];
|
||||
|
||||
DBA::update('profile', $fields, ['uid' => $uid]);
|
||||
}
|
||||
|
||||
|
@ -2355,7 +2358,7 @@ class Contact
|
|||
$probed = false;
|
||||
$ret = $arr['contact'];
|
||||
} else {
|
||||
$probed = true;
|
||||
$probed = true;
|
||||
$ret = Probe::uri($url, $network, $uid);
|
||||
}
|
||||
|
||||
|
|
|
@ -840,6 +840,57 @@ class User
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get avatar link for given user id
|
||||
*
|
||||
* @param integer $uid user id
|
||||
* @param string $size One of the ProxyUtils::SIZE_* constants
|
||||
* @return string avatar link
|
||||
*/
|
||||
public static function getAvatarUrlForId(int $uid, string $size = ''):string
|
||||
{
|
||||
$url = DI::baseUrl() . '/photo/';
|
||||
|
||||
switch ($size) {
|
||||
case Proxy::SIZE_MICRO:
|
||||
$url .= 'micro/';
|
||||
$scale = 6;
|
||||
break;
|
||||
case Proxy::SIZE_THUMB:
|
||||
$url .= 'avatar/';
|
||||
$scale = 5;
|
||||
break;
|
||||
default:
|
||||
$url .= 'profile/';
|
||||
$scale = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
$updated = '';
|
||||
$imagetype = IMAGETYPE_JPEG;
|
||||
|
||||
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
|
||||
if (!empty($photo)) {
|
||||
$updated = max($photo['created'], $photo['edited'], $photo['updated']);
|
||||
|
||||
switch ($photo['type']) {
|
||||
case 'image/png':
|
||||
$imagetype = IMAGETYPE_PNG;
|
||||
break;
|
||||
|
||||
case 'image/gif':
|
||||
$imagetype = IMAGETYPE_PNG;
|
||||
break;
|
||||
|
||||
default:
|
||||
$imagetype = IMAGETYPE_JPEG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch-all user creation function
|
||||
*
|
||||
|
@ -1054,8 +1105,8 @@ class User
|
|||
$insert_result = DBA::insert('profile', [
|
||||
'uid' => $uid,
|
||||
'name' => $username,
|
||||
'photo' => DI::baseUrl() . "/photo/profile/{$uid}.jpg",
|
||||
'thumb' => DI::baseUrl() . "/photo/avatar/{$uid}.jpg",
|
||||
'photo' => self::getAvatarUrlForId($uid),
|
||||
'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
|
||||
'publish' => $publish,
|
||||
'net-publish' => $netpublish,
|
||||
]);
|
||||
|
@ -1585,8 +1636,8 @@ class User
|
|||
/**
|
||||
* Check if the given user id has delegations or is delegated
|
||||
*
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasIdentities(int $uid):bool
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue