Refactor User::getAvatarUrlForId into getAvatarUrl

- Use user/owner array as parameter instead of uid
- Rename $profile variables to $owner when it's the result of User::getOwnerDataByNick
- Replace Module\Photo::stripExtension with native pathinfo() calls
This commit is contained in:
Hypolite Petovan 2021-10-02 17:28:29 -04:00
parent 810699b454
commit 7cdd2d1336
14 changed files with 78 additions and 107 deletions

View file

@ -841,13 +841,14 @@ class User
}
/**
* Get avatar link for given user id
* Get avatar link for given user
*
* @param integer $uid user id
* @param string $size One of the ProxyUtils::SIZE_* constants
* @param array $user
* @param string $size One of the ProxyUtils::SIZE_* constants
* @return string avatar link
* @throws Exception
*/
public static function getAvatarUrlForId(int $uid, string $size = ''):string
public static function getAvatarUrl(array $user, string $size = ''):string
{
$url = DI::baseUrl() . '/photo/';
@ -869,26 +870,16 @@ class User
$updated = '';
$imagetype = IMAGETYPE_JPEG;
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['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;
if (in_array($photo['type'], ['image/png', 'image/gif'])) {
$imagetype = IMAGETYPE_PNG;
}
}
return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
return $url . $user['uid'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
@ -1105,8 +1096,8 @@ class User
$insert_result = DBA::insert('profile', [
'uid' => $uid,
'name' => $username,
'photo' => self::getAvatarUrlForId($uid),
'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
'photo' => self::getAvatarUrl($user),
'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
'publish' => $publish,
'net-publish' => $netpublish,
]);