diff --git a/src/Model/User.php b/src/Model/User.php index 3355695f2..8f69aa87c 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -879,7 +879,7 @@ class User } } - return $url . $user['uid'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : ''); + return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : ''); } /** diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 406bbb2f3..32403a5d1 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -75,16 +75,31 @@ class Photo extends BaseModule $square_resize = true; $scale = null; $stamp = microtime(true); - if (!empty($parameters['customsize'])) { - $customsize = intval($parameters['customsize']); - $uid = pathinfo($parameters['name'], PATHINFO_FILENAME); - $photo = self::getAvatar($uid, $parameters['type'], $customsize); - $square_resize = !in_array($parameters['type'], ['media', 'preview']); - } elseif (!empty($parameters['type'])) { - $uid = pathinfo($parameters['name'], PATHINFO_FILENAME); - $photo = self::getAvatar($uid, $parameters['type'], Proxy::PIXEL_SMALL); - } elseif (!empty($parameters['name'])) { - $photoid = pathinfo($parameters['name'], PATHINFO_FILENAME); + // User avatar + if (!empty($parameters['type'])) { + if (!empty($parameters['customsize'])) { + $customsize = intval($parameters['customsize']); + $square_resize = !in_array($parameters['type'], ['media', 'preview']); + } + + if (!empty($parameters['nickname_ext'])) { + $nickname = pathinfo($parameters['nickname_ext'], PATHINFO_FILENAME); + $user = User::getByNickname($nickname, ['uid']); + if (empty($user)) { + throw new HTTPException\NotFoundException(); + } + + $uid = $user['uid']; + } + + // User Id Fallback, to remove after version 2021.12 + if (!empty($parameters['uid_ext'])) { + $uid = intval(pathinfo($parameters['uid_ext'], PATHINFO_FILENAME)); + } + + $photo = self::getAvatar($uid, $parameters['type'], $customsize ?: Proxy::PIXEL_SMALL); + } else { + $photoid = MPhoto::stripExtension($parameters['name']); $scale = 0; if (substr($photoid, -2, 1) == "-") { $scale = intval(substr($photoid, -1, 1)); diff --git a/static/routes.config.php b/static/routes.config.php index 2c9765b3c..a76b19d88 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -371,9 +371,13 @@ return [ '/permission/tooltip/{type}/{id:\d+}' => [Module\PermissionTooltip::class, [R::GET]], '/photo' => [ - '/{name}' => [Module\Photo::class, [R::GET]], - '/{type}/{name}' => [Module\Photo::class, [R::GET]], - '/{type}/{customsize}/{name}' => [Module\Photo::class, [R::GET]], + '/{name}' => [Module\Photo::class, [R::GET]], + // User Id Fallback, to remove after version 2021.12 + '/{type}/{uid_ext:\d+}' => [Module\Photo::class, [R::GET]], + '/{type}/{nickname_ext}' => [Module\Photo::class, [R::GET]], + // User Id Fallback, to remove after version 2021.12 + '/{type}/{customsize}/{uid_ext:\d+}' => [Module\Photo::class, [R::GET]], + '/{type}/{customsize}/{nickname_ext}' => [Module\Photo::class, [R::GET]], ], '/pretheme' => [Module\ThemeDetails::class, [R::GET]],