From 04c6d582f2afc83dd1bca6b0e761497df0272fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 25 Jan 2023 00:16:10 +0100 Subject: [PATCH] Make small user pictures hoverable to show larger version of profile picture. --- src/DataTables/LogDataTable.php | 3 ++- src/Services/UserSystem/UserAvatarHelper.php | 21 ++++++++++++++++++++ templates/helper.twig | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 1cb77e3d..5d105035 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -234,8 +234,9 @@ class LogDataTable implements DataTableTypeInterface $img_url = $this->userAvatarHelper->getAvatarSmURL($user); return sprintf( - ' %s', + ' %s', $img_url, + $this->userAvatarHelper->getAvatarMdURL($user), $this->urlGenerator->generate('user_info', ['id' => $user->getID()]), htmlentities($user->getFullName(true)) ); diff --git a/src/Services/UserSystem/UserAvatarHelper.php b/src/Services/UserSystem/UserAvatarHelper.php index 80ad5d00..95b94dca 100644 --- a/src/Services/UserSystem/UserAvatarHelper.php +++ b/src/Services/UserSystem/UserAvatarHelper.php @@ -94,6 +94,27 @@ class UserAvatarHelper } } + public function getAvatarMdURL(User $user): string + { + //Check if the user has a master attachment defined (meaning he has explicitly defined a profile picture) + if ($user->getMasterPictureAttachment() !== null) { + return $this->attachmentURLGenerator->getThumbnailURL($user->getMasterPictureAttachment(), 'thumbnail_sm'); + } + + //If not check if gravatar is enabled (then use gravatar URL) + if ($this->use_gravatar) { + return $this->getGravatar($user, 150); + } + + try { + //Otherwise we can serve the relative path via Asset component + return $this->filterService->getUrlOfFilteredImage('/img/default_avatar.png', 'thumbnail_xs'); + } catch (\Imagine\Exception\RuntimeException $e) { + //If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning + return $this->packages->getUrl('/img/default_avatar.png'); + } + } + /** * Get either a Gravatar URL or complete image tag for a specified email address. diff --git a/templates/helper.twig b/templates/helper.twig index 8aa78be3..f7a259bc 100644 --- a/templates/helper.twig +++ b/templates/helper.twig @@ -169,7 +169,7 @@ {% endmacro %} {% macro user_icon(user) %} - User avatar + User avatar {% endmacro %} {% macro parameters_table(parameters) %}