From 8cb0bb5deb226aa32f6558666add75aa07b0c57b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 2 Oct 2021 18:42:14 -0400 Subject: [PATCH] Switch uid with nickname in user picture URLs - Keep previous URL scheme fallback as remote contact avatar URLs pointing to local user avatar URLs need to update --- src/Model/User.php | 2 +- src/Module/Photo.php | 35 +++++++++++++++++++++++++---------- static/routes.config.php | 10 +++++++--- 3 files changed, 33 insertions(+), 14 deletions(-) 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]],