From 4e8a4f61f24a23b5dcb5bce7e222f4694b8d57e1 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 7 Nov 2024 12:46:22 +0100 Subject: [PATCH] Remove old `AvatarEditForm` --- com.woltlab.wcf/fileDelete.xml | 1 + com.woltlab.wcf/templateDelete.xml | 1 + com.woltlab.wcf/templates/avatarEdit.tpl | 82 ---------- .../files/lib/form/AvatarEditForm.class.php | 148 ------------------ .../system/user/command/SetAvatar.class.php | 11 ++ 5 files changed, 13 insertions(+), 230 deletions(-) delete mode 100644 com.woltlab.wcf/templates/avatarEdit.tpl delete mode 100644 wcfsetup/install/files/lib/form/AvatarEditForm.class.php diff --git a/com.woltlab.wcf/fileDelete.xml b/com.woltlab.wcf/fileDelete.xml index 37f95956d5..2e2a46e686 100644 --- a/com.woltlab.wcf/fileDelete.xml +++ b/com.woltlab.wcf/fileDelete.xml @@ -1678,6 +1678,7 @@ lib/data/user/option/IUserOptionOutput.class.php lib/data/user/option/UserOptionOutput.class.php lib/form/AbstractSecureForm.class.php + lib/form/AvatarEditForm.class.php lib/form/Form.class.php lib/form/MailForm.class.php lib/form/MultifactorAuthenticationAbortForm.class.php diff --git a/com.woltlab.wcf/templateDelete.xml b/com.woltlab.wcf/templateDelete.xml index 054f501b38..cdc842f64d 100644 --- a/com.woltlab.wcf/templateDelete.xml +++ b/com.woltlab.wcf/templateDelete.xml @@ -116,5 +116,6 @@ + diff --git a/com.woltlab.wcf/templates/avatarEdit.tpl b/com.woltlab.wcf/templates/avatarEdit.tpl deleted file mode 100644 index 45fc6bd46e..0000000000 --- a/com.woltlab.wcf/templates/avatarEdit.tpl +++ /dev/null @@ -1,82 +0,0 @@ -{include file='userMenuSidebar'} - -{include file='header' __disableAds=true __sidebarLeftHasMenu=true} - -{if $__wcf->user->disableAvatar} - {lang}wcf.user.avatar.error.disabled{/lang} -{/if} - -{include file='shared_formError'} - -{if $success|isset} - {lang}wcf.global.success.edit{/lang} -{/if} - -
-
-
-
-
- - {lang}wcf.user.avatar.type.none.description{/lang} -
-
- - {if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar')} -
-
- {if $avatarType == 'custom'} - {@$__wcf->getUserProfileHandler()->getAvatar()->getImageTag(96)} - {else} - - {/if} -
-
- - {lang}wcf.user.avatar.type.custom.description{/lang} - - {* placeholder for upload button: *} -
- - {if $errorField == 'custom'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} -
-
- {/if} - - {event name='avatarFields'} -
- - {event name='sections'} - - {if !$__wcf->user->disableAvatar} -
- - {csrfToken} -
- {/if} -
- -{if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar')} - -{/if} - -{include file='footer'} diff --git a/wcfsetup/install/files/lib/form/AvatarEditForm.class.php b/wcfsetup/install/files/lib/form/AvatarEditForm.class.php deleted file mode 100644 index c458b6eea7..0000000000 --- a/wcfsetup/install/files/lib/form/AvatarEditForm.class.php +++ /dev/null @@ -1,148 +0,0 @@ - - */ -class AvatarEditForm extends AbstractForm -{ - /** - * @inheritDoc - */ - public $loginRequired = true; - - /** - * @inheritDoc - */ - public $templateName = 'avatarEdit'; - - /** - * avatar type - * @var string - */ - public $avatarType = 'none'; - - /** - * @inheritDoc - */ - public function readFormParameters() - { - parent::readFormParameters(); - - if (isset($_POST['avatarType'])) { - $this->avatarType = $_POST['avatarType']; - } - } - - /** - * @inheritDoc - */ - public function validate() - { - parent::validate(); - - if (WCF::getUser()->disableAvatar) { - throw new PermissionDeniedException(); - } - - if ($this->avatarType != 'custom') { - $this->avatarType = 'none'; - } - - switch ($this->avatarType) { - case 'custom': - if (!WCF::getUser()->avatarID) { - throw new UserInputException('custom'); - } - break; - } - } - - /** - * @inheritDoc - */ - public function save() - { - parent::save(); - - if ($this->avatarType != 'custom') { - // delete custom avatar - if (WCF::getUser()->avatarID) { - $action = new UserAvatarAction([WCF::getUser()->avatarID], 'delete'); - $action->executeAction(); - } - } - - // update user - $data = []; - if ($this->avatarType === 'none') { - $data = [ - 'avatarID' => null, - ]; - } - $this->objectAction = new UserAction([WCF::getUser()], 'update', [ - 'data' => \array_merge($this->additionalFields, $data), - ]); - $this->objectAction->executeAction(); - - // check if the user will be automatically added to new user groups - // because of the changed avatar - UserGroupAssignmentHandler::getInstance()->checkUsers([WCF::getUser()->userID]); - - UserProfileHandler::getInstance()->reloadUserProfile(); - - $this->saved(); - WCF::getTPL()->assign('success', true); - } - - /** - * @inheritDoc - */ - public function readData() - { - parent::readData(); - - if (empty($_POST)) { - if (WCF::getUser()->avatarID) { - $this->avatarType = 'custom'; - } - } - } - - /** - * @inheritDoc - */ - public function assignVariables() - { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'avatarType' => $this->avatarType, - ]); - } - - /** - * @inheritDoc - */ - public function show() - { - // set active tab - UserMenu::getInstance()->setActiveMenuItem('wcf.user.menu.profile.avatar'); - - parent::show(); - } -} diff --git a/wcfsetup/install/files/lib/system/user/command/SetAvatar.class.php b/wcfsetup/install/files/lib/system/user/command/SetAvatar.class.php index f1b4ae5e8a..04801ad8ff 100644 --- a/wcfsetup/install/files/lib/system/user/command/SetAvatar.class.php +++ b/wcfsetup/install/files/lib/system/user/command/SetAvatar.class.php @@ -7,7 +7,10 @@ use wcf\data\file\FileAction; use wcf\data\user\avatar\UserAvatarAction; use wcf\data\user\User; use wcf\data\user\UserEditor; +use wcf\system\user\group\assignment\UserGroupAssignmentHandler; use wcf\system\user\storage\UserStorageHandler; +use wcf\system\user\UserProfileHandler; +use wcf\system\WCF; final class SetAvatar { @@ -34,5 +37,13 @@ final class SetAvatar ]); UserStorageHandler::getInstance()->reset([$this->user->userID], 'avatar'); + + // check if the user will be automatically added to new user groups + // because of the changed avatar + UserGroupAssignmentHandler::getInstance()->checkUsers([$this->user->userID]); + + if ($this->user->userID === WCF::getUser()->userID) { + UserProfileHandler::getInstance()->reloadUserProfile(); + } } } -- 2.20.1