From 51adfd0254699e938cbc80c837722513d2cc9f65 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Wed, 19 Jun 2024 11:05:46 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B07565=20-=20Refactor=20way=20of=20retriev?= =?UTF-8?q?ing=20user's=20picture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/userrights.class.inc.php | 13 ++++++------- .../Base/Layout/NavigationMenu/NavigationMenu.php | 5 +---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 489b2bf3f..3c4ad349a 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -1264,19 +1264,13 @@ class UserRights { $sUserPicturesFolder = 'images/user-pictures/'; $sUserPicturePlaceholderPrefKey = 'user_picture_placeholder'; + $sPictureUrl = null; // First, check cache if (array_key_exists($sLogin, static::$m_aCacheContactPictureAbsUrl)) { return static::$m_aCacheContactPictureAbsUrl[$sLogin]; } - // Then, the default picture - if ($bAllowDefaultPicture === true) { - $sPictureUrl = utils::GetAbsoluteUrlAppRoot().$sUserPicturesFolder.'user-profile-default-256px.png'; - } else { - $sPictureUrl = null; - } - // Then check if the user has a contact attached and if it has an picture defined $sContactId = UserRights::GetContactId($sLogin); if (!empty($sContactId)) { @@ -1323,6 +1317,11 @@ class UserRights } // Else, no contact and no login, then it's for an unknown origin (system, extension, ...) + // Then, the default picture + if (utils::IsNullOrEmptyString($sPictureUrl) && $bAllowDefaultPicture === true) { + $sPictureUrl = utils::GetAbsoluteUrlAppRoot().$sUserPicturesFolder.'user-profile-default-256px.png'; + } + // Update cache static::$m_aCacheContactPictureAbsUrl[$sLogin] = $sPictureUrl; diff --git a/sources/Application/UI/Base/Layout/NavigationMenu/NavigationMenu.php b/sources/Application/UI/Base/Layout/NavigationMenu/NavigationMenu.php index b81e612da..714509b2f 100644 --- a/sources/Application/UI/Base/Layout/NavigationMenu/NavigationMenu.php +++ b/sources/Application/UI/Base/Layout/NavigationMenu/NavigationMenu.php @@ -454,10 +454,7 @@ JS; protected function ComputeUserData() { // Use a picture set in the preferences is there is none in the user's contact - $sPictureUrl = UserRights::GetUserPictureAbsUrl('', false); - if (empty($sPictureUrl)) { - $sPictureUrl = utils::GetAbsoluteUrlAppRoot().'images/user-pictures/'.appUserPreferences::GetPref('user_picture_placeholder', 'user-profile-default-256px.png'); - } + $sPictureUrl = UserRights::GetUserPictureAbsUrl(); // TODO 3.0.0 : what do we show if no contact is linked to the user ? $aData = [