Commit | Line | Data |
---|---|---|
320f4a6d | 1 | <?php |
a9229942 | 2 | |
320f4a6d | 3 | namespace wcf\form; |
a9229942 | 4 | |
320f4a6d MW |
5 | use wcf\data\user\User; |
6 | use wcf\data\user\UserAction; | |
320f4a6d | 7 | use wcf\system\exception\PermissionDeniedException; |
24ecd433 | 8 | use wcf\system\html\input\HtmlInputProcessor; |
320f4a6d | 9 | use wcf\system\menu\user\UserMenu; |
b0dc9618 | 10 | use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; |
320f4a6d MW |
11 | use wcf\system\user\signature\SignatureCache; |
12 | use wcf\system\WCF; | |
13 | ||
14 | /** | |
15 | * Shows the signature edit form. | |
a9229942 TD |
16 | * |
17 | * @author Alexander Ebert | |
18 | * @copyright 2001-2019 WoltLab GmbH | |
19 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
320f4a6d | 20 | */ |
a9229942 TD |
21 | class SignatureEditForm extends MessageForm |
22 | { | |
23 | /** | |
24 | * @inheritDoc | |
25 | */ | |
26 | public $disallowedBBCodesPermission = 'user.signature.disallowedBBCodes'; | |
27 | ||
28 | /** | |
29 | * @inheritDoc | |
30 | */ | |
31 | public $loginRequired = true; | |
32 | ||
33 | /** | |
34 | * @inheritDoc | |
35 | */ | |
36 | public $messageObjectType = 'com.woltlab.wcf.user.signature'; | |
37 | ||
38 | /** | |
39 | * @inheritDoc | |
40 | */ | |
41 | public $attachmentObjectType = 'com.woltlab.wcf.user.signature'; | |
42 | ||
43 | /** | |
44 | * @inheritDoc | |
45 | */ | |
46 | public $neededModules = ['MODULE_USER_SIGNATURE']; | |
47 | ||
48 | /** | |
49 | * @inheritDoc | |
50 | */ | |
51 | public $showSignatureSetting = false; | |
52 | ||
53 | /** | |
54 | * parsed signature cache | |
55 | * @var string | |
56 | */ | |
57 | public $signatureCache; | |
58 | ||
59 | /** | |
60 | * @inheritDoc | |
61 | */ | |
62 | public $templateName = 'signatureEdit'; | |
63 | ||
64 | /** | |
65 | * @inheritDoc | |
66 | */ | |
67 | public $neededPermissions = ['user.signature.canEditSignature']; | |
68 | ||
69 | /** | |
70 | * @inheritDoc | |
71 | */ | |
72 | public function readParameters() | |
73 | { | |
74 | parent::readParameters(); | |
75 | ||
76 | // get max text length | |
77 | $this->maxTextLength = WCF::getSession()->getPermission('user.signature.maxLength'); | |
78 | $this->attachmentObjectID = WCF::getUser()->userID; | |
79 | } | |
80 | ||
81 | /** | |
82 | * @inheritDoc | |
83 | */ | |
84 | public function validate() | |
85 | { | |
86 | if (WCF::getUser()->disableSignature) { | |
87 | throw new PermissionDeniedException(); | |
88 | } | |
89 | ||
90 | AbstractForm::validate(); | |
91 | ||
92 | if (!empty($this->text)) { | |
93 | $this->validateText(); | |
94 | } else { | |
95 | $this->htmlInputProcessor = new HtmlInputProcessor(); | |
96 | $this->htmlInputProcessor->process($this->text, $this->messageObjectType, WCF::getUser()->userID); | |
97 | } | |
98 | } | |
99 | ||
100 | /** | |
101 | * @inheritDoc | |
102 | */ | |
103 | public function readData() | |
104 | { | |
105 | parent::readData(); | |
106 | ||
107 | // default values | |
108 | if (empty($_POST)) { | |
109 | $this->text = WCF::getUser()->signature; | |
110 | } | |
111 | ||
112 | $this->signatureCache = SignatureCache::getInstance()->getSignature(WCF::getUser()); | |
113 | } | |
114 | ||
115 | /** | |
116 | * @inheritDoc | |
117 | */ | |
118 | public function assignVariables() | |
119 | { | |
120 | parent::assignVariables(); | |
121 | ||
122 | WCF::getTPL()->assign([ | |
123 | 'signatureCache' => $this->signatureCache, | |
124 | ]); | |
125 | } | |
126 | ||
127 | /** | |
128 | * @inheritDoc | |
129 | */ | |
130 | public function show() | |
131 | { | |
132 | // set active tab | |
133 | UserMenu::getInstance()->setActiveMenuItem('wcf.user.menu.profile.signature'); | |
134 | ||
135 | parent::show(); | |
136 | } | |
137 | ||
138 | /** | |
139 | * @inheritDoc | |
140 | */ | |
141 | public function save() | |
142 | { | |
143 | parent::save(); | |
144 | $this->htmlInputProcessor->setObjectID(WCF::getUser()->userID); | |
145 | MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor); | |
146 | ||
147 | $this->objectAction = new UserAction([WCF::getUser()], 'update', [ | |
148 | 'data' => \array_merge($this->additionalFields, [ | |
149 | 'signature' => $this->htmlInputProcessor->getHtml(), | |
150 | 'signatureEnableHtml' => 1, | |
151 | ]), | |
152 | 'signatureAttachmentHandler' => $this->attachmentHandler, | |
153 | ]); | |
154 | $this->objectAction->executeAction(); | |
155 | SignatureCache::getInstance()->getSignature(new User(WCF::getUser()->userID)); | |
156 | $this->saved(); | |
157 | ||
158 | // show success message | |
159 | WCF::getTPL()->assign('success', true); | |
160 | } | |
320f4a6d | 161 | } |