Add a new user menu item to manage the avatar
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 6 Nov 2024 12:12:17 +0000 (13:12 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 6 Nov 2024 12:12:17 +0000 (13:12 +0100)
com.woltlab.wcf/page.xml
com.woltlab.wcf/templates/pageHeaderUser.tpl
com.woltlab.wcf/userMenu.xml
wcfsetup/install/files/lib/system/file/processor/UserAvatarFileProcessor.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 59b2f271b068e839bcfa5ea4b9981c56680ad5c6..856395a425cee23c3b4b08d3896e061a3ff4556e 100644 (file)
                                <title>Benutzerkonto-Sicherheit</title>
                        </content>
                </page>
-               <page identifier="com.woltlab.wcf.AvatarEdit">
-                       <pageType>system</pageType>
-                       <controller>wcf\form\AvatarEditForm</controller>
-                       <name language="de">Avatar-Verwaltung</name>
-                       <name language="en">Avatar Management</name>
-                       <hasFixedParent>1</hasFixedParent>
-                       <parent>com.woltlab.wcf.AccountManagement</parent>
-                       <content language="en">
-                               <title>Avatar Management</title>
-                       </content>
-                       <content language="de">
-                               <title>Avatar-Verwaltung</title>
-                       </content>
-               </page>
                <page identifier="com.woltlab.wcf.EmailActivation">
                        <pageType>system</pageType>
                        <controller>wcf\form\EmailActivationForm</controller>
@@ -888,6 +874,7 @@ E-Mail: [E-Mail-Adresse der verantwortlichen Stelle]</p><p>Verantwortliche Stell
                </page>
        </import>
        <delete>
+               <page identifier="com.woltlab.wcf.AvatarEdit"/>
                <!-- The notification list is no longer part of the user menu. -->
                <page identifier="com.woltlab.wcf.NotificationList"/>
        </delete>
index 2038b6d5b3f46f8d09745626e33457e057daffe8..b2a4490bb021724275f62fe295cd5ffa0296c164 100644 (file)
                                                                                </div>
                                                                        </div>
                                                                {/if}
+                                                               {if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar') && !$__wcf->getUserProfileHandler()->disableAvatar}
+                                                                       <div class="userMenuItem userMenuItemNarrow userMenuItemSingleLine">
+                                                                               <div class="userMenuItemImage">
+                                                                                       {icon size=16 name='user-pen'}
+                                                                               </div>
+                                                                               <div class="userMenuItemContent">
+                                                                                       <button type="button" class="userMenuItemLink userAvatarManagement">
+                                                                                               {lang}wcf.user.avatarManagement{/lang}
+                                                                                       </button>
+                                                                               </div>
+                                                                       </div>
+                                                               {/if}
                                                                {if $__wcf->session->getPermission('admin.general.canUseAcp')}
                                                                        <div class="userMenuItem userMenuItemNarrow userMenuItemSingleLine">
                                                                                <div class="userMenuItemImage">
index 1d8ccefe15f8349b1ca0d192cbe2e6cf09d76b07..6cea9f70df56cd1b12b01bffb3bb83c55d9e47ba 100644 (file)
                        <parent>wcf.user.menu.profile</parent>
                        <showorder>2</showorder>
                </usermenuitem>
-               <usermenuitem name="wcf.user.menu.profile.avatar">
-                       <controller>wcf\form\AvatarEditForm</controller>
-                       <parent>wcf.user.menu.profile</parent>
-                       <showorder>3</showorder>
-               </usermenuitem>
                <usermenuitem name="wcf.user.menu.profile.signature">
                        <controller>wcf\form\SignatureEditForm</controller>
                        <parent>wcf.user.menu.profile</parent>
@@ -63,5 +58,6 @@
        </import>
        <delete>
                <usermenuitem name="wcf.user.menu.community.notification"/>
+               <usermenuitem name="wcf.user.menu.profile.avatar"/>
        </delete>
 </data>
index 5140d0af57a4762293b06fab756a9eb096f15e1e..a2d194a1a737f09641a2ef1666cd0bf8c003bdae 100644 (file)
@@ -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;
index 91ae548c7b79ecf99e406254e1df020539f62d0a..b3d23e11b80f906644afff33e8dde2197cff8f74 100644 (file)
@@ -4868,6 +4868,7 @@ sich{/if} nicht bei uns registriert {if LANGUAGE_USE_INFORMAL_VARIANT}hast{else}
                <item name="wcf.user.ignore.type.hideMessages"><![CDATA[Direkten Kontakt blockieren und erstellte Inhalte ausblenden]]></item>
                <item name="wcf.user.ignore.error.cannotBeIgnored"><![CDATA[Der Benutzer kann nicht blockiert werden.]]></item>
                <item name="wcf.user.reactionsReceived"><![CDATA[Reaktionen]]></item>
+               <item name="wcf.user.avatarManagement"><![CDATA[Avatar-Verwaltung]]></item>
        </category>
        <category name="wcf.user.menu">
                <item name="wcf.user.menu.community"><![CDATA[Community]]></item>
index f8b67dcfda200e7225e2433197d04e9ff978163e..b64fa8fd76ab947364db007fa45d206c89d97e54 100644 (file)
@@ -4870,6 +4870,7 @@ not register with us.]]></item>
                <item name="wcf.user.ignore.type.hideMessages"><![CDATA[Block Direct Contact and Hide Created Messages]]></item>
                <item name="wcf.user.ignore.error.cannotBeIgnored"><![CDATA[The user cannot be blocked.]]></item>
                <item name="wcf.user.reactionsReceived"><![CDATA[Reactions]]></item>
+               <item name="wcf.user.avatarManagement"><![CDATA[Avatar Management]]></item>
        </category>
        <category name="wcf.user.menu">
                <item name="wcf.user.menu.community"><![CDATA[Community]]></item>