From 86805f9c5b077bd0e06676f7354ce33370c03b1d Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Wed, 6 Nov 2024 13:12:17 +0100 Subject: [PATCH] Add a new user menu item to manage the avatar --- com.woltlab.wcf/page.xml | 15 +--------- com.woltlab.wcf/templates/pageHeaderUser.tpl | 12 ++++++++ com.woltlab.wcf/userMenu.xml | 6 +--- .../UserAvatarFileProcessor.class.php | 28 +++++++++++++------ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index 59b2f271b0..856395a425 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -100,20 +100,6 @@ Benutzerkonto-Sicherheit - - system - wcf\form\AvatarEditForm - Avatar-Verwaltung - Avatar Management - 1 - com.woltlab.wcf.AccountManagement - - Avatar Management - - - Avatar-Verwaltung - - system wcf\form\EmailActivationForm @@ -888,6 +874,7 @@ E-Mail: [E-Mail-Adresse der verantwortlichen Stelle]

Verantwortliche Stell + diff --git a/com.woltlab.wcf/templates/pageHeaderUser.tpl b/com.woltlab.wcf/templates/pageHeaderUser.tpl index 2038b6d5b3..b2a4490bb0 100644 --- a/com.woltlab.wcf/templates/pageHeaderUser.tpl +++ b/com.woltlab.wcf/templates/pageHeaderUser.tpl @@ -54,6 +54,18 @@ {/if} + {if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar') && !$__wcf->getUserProfileHandler()->disableAvatar} +

+
+ {icon size=16 name='user-pen'} +
+
+ +
+
+ {/if} {if $__wcf->session->getPermission('admin.general.canUseAcp')}
diff --git a/com.woltlab.wcf/userMenu.xml b/com.woltlab.wcf/userMenu.xml index 1d8ccefe15..6cea9f70df 100644 --- a/com.woltlab.wcf/userMenu.xml +++ b/com.woltlab.wcf/userMenu.xml @@ -16,11 +16,6 @@ wcf.user.menu.profile 2 - - wcf\form\AvatarEditForm - wcf.user.menu.profile - 3 - wcf\form\SignatureEditForm wcf.user.menu.profile @@ -63,5 +58,6 @@ + diff --git a/wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php b/wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php index 5140d0af57..a2d194a1a7 100644 --- a/wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php +++ b/wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php @@ -4,9 +4,9 @@ namespace wcf\system\file\processor; use wcf\data\file\File; use wcf\data\user\avatar\UserAvatar; -use wcf\data\user\User; use wcf\data\user\UserEditor; -use wcf\system\cache\runtime\UserRuntimeCache; +use wcf\data\user\UserProfile; +use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\UserInputException; use wcf\system\user\storage\UserStorageHandler; @@ -130,7 +130,12 @@ final class UserAvatarFileProcessor extends AbstractFileProcessor #[\Override] public function canDownload(File $file): bool { - return true; + $user = $this->getUserByFile($file); + if ($user === null) { + return false; + } + + return $user->canSeeAvatar(); } #[\Override] @@ -202,28 +207,33 @@ final class UserAvatarFileProcessor extends AbstractFileProcessor ); } - private function getUser(array $context): ?User + private function getUser(array $context): ?UserProfile { $userID = $context['objectID'] ?? null; if ($userID === null) { return null; } - return UserRuntimeCache::getInstance()->getObject($userID); + return UserProfileRuntimeCache::getInstance()->getObject($userID); } - private function getUserByFile(File $file): ?User + private function getUserByFile(File $file): ?UserProfile { - $sql = "SELECT * + $sql = "SELECT userID FROM wcf1_user WHERE avatarFileID = ?"; $statement = WCF::getDB()->prepare($sql); $statement->execute([$file->fileID]); + $userID = $statement->fetchSingleColumn(); + + if ($userID === false) { + return null; + } - return $statement->fetchObject(User::class); + return UserProfileRuntimeCache::getInstance()->getObject($userID); } - private function canEditAvatar(User $user): bool + private function canEditAvatar(UserProfile $user): bool { if (WCF::getSession()->getPermission('admin.user.canEditUser')) { return true; diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 91ae548c7b..b3d23e11b8 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4868,6 +4868,7 @@ sich{/if} nicht bei uns registriert {if LANGUAGE_USE_INFORMAL_VARIANT}hast{else} + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index f8b67dcfda..b64fa8fd76 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4870,6 +4870,7 @@ not register with us.]]> + -- 2.20.1