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