Commit | Line | Data |
---|---|---|
9544b6b4 MW |
1 | <?php |
2 | namespace wcf\data\conversation\message; | |
3 | use wcf\data\conversation\Conversation; | |
3b34d39f | 4 | use wcf\data\conversation\ConversationAction; |
9544b6b4 | 5 | use wcf\data\conversation\ConversationEditor; |
b2de9161 | 6 | use wcf\data\smiley\SmileyCache; |
9544b6b4 | 7 | use wcf\data\AbstractDatabaseObjectAction; |
52971287 | 8 | use wcf\data\DatabaseObject; |
4a2ee5bb AE |
9 | use wcf\data\IExtendedMessageQuickReplyAction; |
10 | use wcf\data\IMessageInlineEditorAction; | |
5fa9d104 | 11 | use wcf\data\IMessageQuoteAction; |
5d7f0df0 | 12 | use wcf\system\attachment\AttachmentHandler; |
a21c8732 | 13 | use wcf\system\bbcode\BBCodeHandler; |
027c57f4 | 14 | use wcf\system\bbcode\BBCodeParser; |
0a0e61bb | 15 | use wcf\system\bbcode\PreParser; |
5e52978f AE |
16 | use wcf\system\exception\PermissionDeniedException; |
17 | use wcf\system\exception\UserInputException; | |
d8671029 | 18 | use wcf\system\message\censorship\Censorship; |
a0c1a541 | 19 | use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; |
5fa9d104 | 20 | use wcf\system\message\quote\MessageQuoteManager; |
5e52978f | 21 | use wcf\system\message\QuickReplyManager; |
3b37e024 | 22 | use wcf\system\moderation\queue\ModerationQueueManager; |
5e52978f | 23 | use wcf\system\request\LinkHandler; |
80a0761e | 24 | use wcf\system\search\SearchIndexManager; |
b5ffaf76 AE |
25 | use wcf\system\user\notification\object\ConversationMessageUserNotificationObject; |
26 | use wcf\system\user\notification\UserNotificationHandler; | |
df8f8628 | 27 | use wcf\system\user\storage\UserStorageHandler; |
9544b6b4 | 28 | use wcf\system\WCF; |
e4124bfc | 29 | use wcf\util\MessageUtil; |
5e00d333 | 30 | use wcf\util\StringUtil; |
9544b6b4 MW |
31 | |
32 | /** | |
3b37e024 | 33 | * Executes conversation message-related actions. |
9544b6b4 MW |
34 | * |
35 | * @author Marcel Werk | |
c7b2df3b | 36 | * @copyright 2001-2014 WoltLab GmbH |
9544b6b4 MW |
37 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
38 | * @package com.woltlab.wcf.conversation | |
39 | * @subpackage data.conversation.message | |
61f754e0 | 40 | * @category Community Framework |
9544b6b4 | 41 | */ |
5fa9d104 | 42 | class ConversationMessageAction extends AbstractDatabaseObjectAction implements IExtendedMessageQuickReplyAction, IMessageInlineEditorAction, IMessageQuoteAction { |
9544b6b4 | 43 | /** |
2270f7e9 | 44 | * @see \wcf\data\AbstractDatabaseObjectAction::$className |
9544b6b4 MW |
45 | */ |
46 | protected $className = 'wcf\data\conversation\message\ConversationMessageEditor'; | |
47 | ||
5e52978f AE |
48 | /** |
49 | * conversation object | |
2270f7e9 | 50 | * @var \wcf\data\conversation\Conversation |
5e52978f AE |
51 | */ |
52 | public $conversation = null; | |
53 | ||
a5bacc02 AE |
54 | /** |
55 | * conversation message object | |
2270f7e9 | 56 | * @var \wcf\data\conversation\message\ConversationMessage |
a5bacc02 AE |
57 | */ |
58 | public $message = null; | |
59 | ||
9544b6b4 | 60 | /** |
2270f7e9 | 61 | * @see \wcf\data\AbstractDatabaseObjectAction::create() |
9544b6b4 MW |
62 | */ |
63 | public function create() { | |
64 | // count attachments | |
65 | if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { | |
66 | $this->parameters['data']['attachments'] = count($this->parameters['attachmentHandler']); | |
67 | } | |
68 | ||
69 | if (LOG_IP_ADDRESS) { | |
70 | // add ip address | |
71 | if (!isset($this->parameters['data']['ipAddress'])) { | |
72 | $this->parameters['data']['ipAddress'] = WCF::getSession()->ipAddress; | |
73 | } | |
74 | } | |
75 | else { | |
76 | // do not track ip address | |
77 | if (isset($this->parameters['data']['ipAddress'])) { | |
78 | unset($this->parameters['data']['ipAddress']); | |
79 | } | |
80 | } | |
81 | ||
82 | // create message | |
83 | $message = parent::create(); | |
a0c1a541 | 84 | $messageEditor = new ConversationMessageEditor($message); |
9544b6b4 | 85 | |
fcf27f27 | 86 | // get conversation |
6f1cd040 MW |
87 | $conversation = (isset($this->parameters['converation']) ? $this->parameters['converation'] : new Conversation($message->conversationID)); |
88 | $conversationEditor = new ConversationEditor($conversation); | |
61f754e0 | 89 | |
4b541146 | 90 | if (empty($this->parameters['isFirstPost'])) { |
9544b6b4 MW |
91 | // update last message |
92 | $conversationEditor->addMessage($message); | |
64ac54a1 MW |
93 | |
94 | // fire notification event | |
6f1cd040 | 95 | if (!$conversation->isDraft) { |
0ff992a3 | 96 | $notificationRecipients = array_diff($conversation->getParticipantIDs(true), array($message->userID)); // don't notify message author |
566eb43f MW |
97 | if (!empty($notificationRecipients)) { |
98 | UserNotificationHandler::getInstance()->fireEvent('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', new ConversationMessageUserNotificationObject($message), $notificationRecipients); | |
99 | } | |
5fa9d104 | 100 | } |
fcf27f27 | 101 | |
ad478273 MW |
102 | $userConversation = Conversation::getUserConversation($conversation->conversationID, $message->userID); |
103 | if ($userConversation !== null && $userConversation->isInvisible) { | |
104 | // make invisible participant visible | |
105 | $sql = "UPDATE wcf".WCF_N."_conversation_to_user | |
106 | SET isInvisible = 0 | |
107 | WHERE participantID = ? | |
108 | AND conversationID = ?"; | |
109 | $statement = WCF::getDB()->prepareStatement($sql); | |
110 | $statement->execute(array($message->userID, $conversation->conversationID)); | |
111 | ||
112 | $conversationEditor->updateParticipantSummary(); | |
113 | $conversationEditor->updateParticipantCount(); | |
114 | } | |
0ff992a3 AE |
115 | |
116 | // reset visibility if it was hidden but not left | |
117 | $sql = "UPDATE wcf".WCF_N."_conversation_to_user | |
118 | SET hideConversation = ? | |
119 | WHERE conversationID = ? | |
120 | AND hideConversation = ?"; | |
121 | $statement = WCF::getDB()->prepareStatement($sql); | |
122 | $statement->execute(array( | |
06695793 | 123 | Conversation::STATE_DEFAULT, |
0ff992a3 | 124 | $conversation->conversationID, |
06695793 | 125 | Conversation::STATE_HIDDEN |
0ff992a3 | 126 | )); |
9544b6b4 MW |
127 | } |
128 | ||
df8f8628 | 129 | // reset storage |
462d532a | 130 | UserStorageHandler::getInstance()->reset($conversation->getParticipantIDs(), 'unreadConversationCount'); |
9544b6b4 | 131 | |
80a0761e | 132 | // update search index |
6f1cd040 | 133 | SearchIndexManager::getInstance()->add('com.woltlab.wcf.conversation.message', $message->messageID, $message->message, (!empty($this->parameters['isFirstPost']) ? $conversation->subject : ''), $message->time, $message->userID, $message->username); |
9544b6b4 | 134 | |
a0c1a541 MW |
135 | // save embedded objects |
136 | if (MessageEmbeddedObjectManager::getInstance()->registerObjects('com.woltlab.wcf.conversation.message', $message->messageID, $message->message)) { | |
137 | $messageEditor->update(array( | |
138 | 'hasEmbeddedObjects' => 1 | |
139 | )); | |
140 | } | |
141 | ||
9544b6b4 MW |
142 | // update attachments |
143 | if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { | |
144 | $this->parameters['attachmentHandler']->updateObjectID($message->messageID); | |
145 | } | |
146 | ||
5fa9d104 | 147 | // clear quotes |
f1781bd0 AE |
148 | if (isset($this->parameters['removeQuoteIDs']) && !empty($this->parameters['removeQuoteIDs'])) { |
149 | MessageQuoteManager::getInstance()->markQuotesForRemoval($this->parameters['removeQuoteIDs']); | |
150 | } | |
5fa9d104 AE |
151 | MessageQuoteManager::getInstance()->removeMarkedQuotes(); |
152 | ||
9544b6b4 MW |
153 | // return new message |
154 | return $message; | |
155 | } | |
c764783c MW |
156 | |
157 | /** | |
2270f7e9 | 158 | * @see \wcf\data\AbstractDatabaseObjectAction::update() |
c764783c MW |
159 | */ |
160 | public function update() { | |
161 | // count attachments | |
162 | if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { | |
163 | $this->parameters['data']['attachments'] = count($this->parameters['attachmentHandler']); | |
164 | } | |
165 | ||
166 | parent::update(); | |
80a0761e | 167 | |
a0c1a541 | 168 | // update search index / embedded objects |
28bd6cbd MW |
169 | if (isset($this->parameters['data']) && isset($this->parameters['data']['message'])) { |
170 | foreach ($this->objects as $message) { | |
171 | $conversation = $message->getConversation(); | |
172 | SearchIndexManager::getInstance()->update('com.woltlab.wcf.conversation.message', $message->messageID, $this->parameters['data']['message'], ($conversation->firstMessageID == $message->messageID ? $conversation->subject : ''), $message->time, $message->userID, $message->username); | |
173 | ||
174 | if ($message->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects('com.woltlab.wcf.conversation.message', $message->messageID, $this->parameters['data']['message'])) { | |
175 | $message->update(array( | |
176 | 'hasEmbeddedObjects' => ($message->hasEmbeddedObjects ? 0 : 1) | |
177 | )); | |
178 | } | |
a0c1a541 | 179 | } |
fcf27f27 | 180 | } |
c764783c | 181 | } |
5e52978f | 182 | |
db07cb2d | 183 | /** |
2270f7e9 | 184 | * @see \wcf\data\AbstractDatabaseObjectAction::delete() |
db07cb2d AE |
185 | */ |
186 | public function delete() { | |
187 | $count = parent::delete(); | |
188 | ||
3b34d39f | 189 | $attachmentMessageIDs = $conversationIDs = array(); |
5d7f0df0 | 190 | foreach ($this->objects as $message) { |
3b34d39f MS |
191 | if (!in_array($message->conversationID, $conversationIDs)) { |
192 | $conversationIDs[] = $message->conversationID; | |
193 | } | |
194 | ||
5d7f0df0 MW |
195 | if ($message->attachments) { |
196 | $attachmentMessageIDs[] = $message->messageID; | |
db07cb2d AE |
197 | } |
198 | } | |
199 | ||
3b34d39f MS |
200 | // rebuild conversations |
201 | if (!empty($conversationIDs)) { | |
202 | $conversationAction = new ConversationAction($conversationIDs, 'rebuild'); | |
203 | $conversationAction->executeAction(); | |
204 | } | |
205 | ||
5d7f0df0 MW |
206 | if (!empty($this->objectIDs)) { |
207 | // delete notifications | |
208 | UserNotificationHandler::getInstance()->deleteNotifications('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', array(), $this->objectIDs); | |
3b34d39f | 209 | |
5d7f0df0 MW |
210 | // update search index |
211 | SearchIndexManager::getInstance()->delete('com.woltlab.wcf.conversation.message', $this->objectIDs); | |
3b37e024 | 212 | |
a0c1a541 MW |
213 | // update embedded objects |
214 | MessageEmbeddedObjectManager::getInstance()->removeObjects('com.woltlab.wcf.conversation.message', $this->objectIDs); | |
215 | ||
3b37e024 AE |
216 | // remove moderation queues |
217 | ModerationQueueManager::getInstance()->removeQueues('com.woltlab.wcf.conversation.message', $this->objectIDs); | |
5d7f0df0 MW |
218 | } |
219 | ||
220 | // remove attachments | |
221 | if (!empty($attachmentMessageIDs)) { | |
222 | AttachmentHandler::removeAttachments('com.woltlab.wcf.conversation.message', $attachmentMessageIDs); | |
223 | } | |
224 | ||
db07cb2d AE |
225 | return $count; |
226 | } | |
227 | ||
5e52978f | 228 | /** |
2270f7e9 | 229 | * @see \wcf\data\IMessageQuickReply::validateQuickReply() |
5e52978f AE |
230 | */ |
231 | public function validateQuickReply() { | |
0a0e61bb | 232 | QuickReplyManager::getInstance()->setAllowedBBCodes(explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))); |
5e52978f AE |
233 | QuickReplyManager::getInstance()->validateParameters($this, $this->parameters, 'wcf\data\conversation\Conversation'); |
234 | } | |
235 | ||
236 | /** | |
2270f7e9 | 237 | * @see \wcf\data\IMessageQuickReply::quickReply() |
5e52978f AE |
238 | */ |
239 | public function quickReply() { | |
240 | return QuickReplyManager::getInstance()->createMessage( | |
241 | $this, | |
242 | $this->parameters, | |
243 | 'wcf\data\conversation\ConversationAction', | |
9353cd87 AE |
244 | CONVERSATION_LIST_DEFAULT_SORT_ORDER, |
245 | 'conversationMessageList' | |
5e52978f AE |
246 | ); |
247 | } | |
248 | ||
a5bacc02 | 249 | /** |
2270f7e9 | 250 | * @see \wcf\data\IExtendedMessageQuickReplyAction::validateJumpToExtended() |
a5bacc02 AE |
251 | */ |
252 | public function validateJumpToExtended() { | |
c2b8907c AE |
253 | $this->readInteger('containerID'); |
254 | $this->readString('message', true); | |
a5bacc02 | 255 | |
c2b8907c AE |
256 | $this->conversation = new Conversation($this->parameters['containerID']); |
257 | if (!$this->conversation->conversationID) { | |
86a5431b | 258 | throw new UserInputException('containerID'); |
a5bacc02 | 259 | } |
c2b8907c AE |
260 | else if ($this->conversation->isClosed || !Conversation::isParticipant(array($this->conversation->conversationID))) { |
261 | throw new PermissionDeniedException(); | |
a5bacc02 AE |
262 | } |
263 | ||
264 | // editing existing message | |
265 | if (isset($this->parameters['messageID'])) { | |
266 | $this->message = new ConversationMessage(intval($this->parameters['messageID'])); | |
267 | if (!$this->message->messageID || ($this->message->conversationID != $this->conversation->conversationID)) { | |
268 | throw new UserInputException('messageID'); | |
269 | } | |
61f754e0 | 270 | |
a5bacc02 AE |
271 | if (!$this->message->canEdit()) { |
272 | throw new PermissionDeniedException(); | |
273 | } | |
274 | } | |
275 | } | |
276 | ||
277 | /** | |
2270f7e9 | 278 | * @see \wcf\data\IExtendedMessageQuickReplyAction::jumpToExtended() |
a5bacc02 AE |
279 | */ |
280 | public function jumpToExtended() { | |
281 | // quick reply | |
282 | if ($this->message === null) { | |
283 | QuickReplyManager::getInstance()->setMessage('conversation', $this->conversation->conversationID, $this->parameters['message']); | |
284 | $url = LinkHandler::getInstance()->getLink('ConversationMessageAdd', array('id' => $this->conversation->conversationID)); | |
285 | } | |
286 | else { | |
287 | // editing message | |
288 | QuickReplyManager::getInstance()->setMessage('conversationMessage', $this->message->messageID, $this->parameters['message']); | |
289 | $url = LinkHandler::getInstance()->getLink('ConversationMessageEdit', array('id' => $this->message->messageID)); | |
290 | } | |
291 | ||
292 | // redirect | |
293 | return array( | |
294 | 'url' => $url | |
295 | ); | |
296 | } | |
297 | ||
b5ffaf76 | 298 | /** |
2270f7e9 | 299 | * @see \wcf\data\IMessageInlineEditorAction::validateBeginEdit() |
b5ffaf76 AE |
300 | */ |
301 | public function validateBeginEdit() { | |
c2b8907c AE |
302 | $this->readInteger('containerID'); |
303 | $this->readInteger('objectID'); | |
304 | ||
305 | $this->conversation = new Conversation($this->parameters['containerID']); | |
306 | if (!$this->conversation->conversationID) { | |
b5ffaf76 AE |
307 | throw new UserInputException('containerID'); |
308 | } | |
c2b8907c AE |
309 | |
310 | if ($this->conversation->isClosed || !Conversation::isParticipant(array($this->conversation->conversationID))) { | |
311 | throw new PermissionDeniedException(); | |
b5ffaf76 AE |
312 | } |
313 | ||
c2b8907c AE |
314 | $this->message = new ConversationMessage($this->parameters['objectID']); |
315 | if (!$this->message->messageID) { | |
b5ffaf76 AE |
316 | throw new UserInputException('objectID'); |
317 | } | |
c2b8907c AE |
318 | |
319 | if (!$this->message->canEdit()) { | |
320 | throw new PermissionDeniedException(); | |
b5ffaf76 AE |
321 | } |
322 | } | |
323 | ||
324 | /** | |
2270f7e9 | 325 | * @see \wcf\data\IMessageInlineEditorAction::beginEdit() |
b5ffaf76 AE |
326 | */ |
327 | public function beginEdit() { | |
a21c8732 MS |
328 | BBCodeHandler::getInstance()->setAllowedBBCodes(explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))); |
329 | ||
b5ffaf76 | 330 | WCF::getTPL()->assign(array( |
b2de9161 | 331 | 'defaultSmilies' => SmileyCache::getInstance()->getCategorySmilies(), |
b5ffaf76 | 332 | 'message' => $this->message, |
a21c8732 | 333 | 'permissionCanUseSmilies' => 'user.message.canUseSmilies', |
b5ffaf76 AE |
334 | 'wysiwygSelector' => 'messageEditor'.$this->message->messageID |
335 | )); | |
336 | ||
5e00d333 MW |
337 | if (MODULE_ATTACHMENT) { |
338 | $tmpHash = StringUtil::getRandomID(); | |
339 | $attachmentHandler = new AttachmentHandler('com.woltlab.wcf.conversation.message', $this->message->messageID, $tmpHash); | |
340 | $attachmentList = $attachmentHandler->getAttachmentList(); | |
341 | ||
342 | WCF::getTPL()->assign(array( | |
343 | 'attachmentHandler' => $attachmentHandler, | |
344 | 'attachmentList' => $attachmentList->getObjects(), | |
345 | 'attachmentObjectID' => $this->message->messageID, | |
346 | 'attachmentObjectType' => 'com.woltlab.wcf.conversation.message', | |
347 | 'attachmentParentObjectID' => 0, | |
348 | 'tmpHash' => $tmpHash | |
349 | )); | |
350 | } | |
351 | ||
b5ffaf76 AE |
352 | return array( |
353 | 'actionName' => 'beginEdit', | |
354 | 'template' => WCF::getTPL()->fetch('conversationMessageInlineEditor') | |
355 | ); | |
356 | } | |
357 | ||
358 | /** | |
2270f7e9 | 359 | * @see \wcf\data\IMessageInlineEditorAction::validateSave() |
b5ffaf76 AE |
360 | */ |
361 | public function validateSave() { | |
9101781c MS |
362 | $this->readString('message', true, 'data'); |
363 | ||
364 | if (empty($this->parameters['data']['message'])) { | |
365 | throw new UserInputException('message', WCF::getLanguage()->get('wcf.global.form.error.empty')); | |
366 | } | |
b5ffaf76 AE |
367 | |
368 | $this->validateBeginEdit(); | |
271c06ce | 369 | $this->validateMessage($this->conversation, $this->parameters['data']['message']); |
b5ffaf76 AE |
370 | } |
371 | ||
372 | /** | |
2270f7e9 | 373 | * @see \wcf\data\IMessageInlineEditorAction::save() |
b5ffaf76 AE |
374 | */ |
375 | public function save() { | |
e7ed68e5 | 376 | $data = array( |
e4124bfc | 377 | 'message' => PreParser::getInstance()->parse(MessageUtil::stripCrap($this->parameters['data']['message']), explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))) |
e7ed68e5 MW |
378 | ); |
379 | if (!$this->message->getConversation()->isDraft) { | |
380 | $data['lastEditTime'] = TIME_NOW; | |
381 | $data['editCount'] = $this->message->editCount + 1; | |
382 | } | |
28bd6cbd MW |
383 | // execute update action |
384 | $action = new ConversationMessageAction(array($this->message), 'update', array('data' => $data)); | |
385 | $action->executeAction(); | |
b5ffaf76 AE |
386 | |
387 | // load new message | |
388 | $this->message = new ConversationMessage($this->message->messageID); | |
f7b9b1f3 | 389 | $this->message->getAttachments(); |
b5ffaf76 | 390 | |
5e00d333 MW |
391 | if (MODULE_ATTACHMENT) { |
392 | $attachmentList = $this->message->getAttachments(); | |
393 | if ($attachmentList !== null) { | |
394 | // set permisions | |
395 | $attachmentList->setPermissions(array( | |
396 | 'canDownload' => true, | |
397 | 'canViewPreview' => true | |
398 | )); | |
399 | } | |
400 | } | |
401 | ||
402 | // load embedded objects | |
403 | MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.conversation.message', array($this->message->messageID)); | |
404 | ||
405 | $data = array( | |
b5ffaf76 AE |
406 | 'actionName' => 'save', |
407 | 'message' => $this->message->getFormattedMessage() | |
408 | ); | |
5e00d333 MW |
409 | |
410 | if (MODULE_ATTACHMENT) { | |
411 | WCF::getTPL()->assign(array( | |
412 | 'attachmentList' => $attachmentList, | |
413 | 'objectID' => $this->message->messageID | |
414 | )); | |
415 | $data['attachmentList'] = WCF::getTPL()->fetch('attachments'); | |
416 | } | |
417 | ||
418 | return $data; | |
b5ffaf76 AE |
419 | } |
420 | ||
5e52978f | 421 | /** |
2270f7e9 | 422 | * @see \wcf\data\IMessageQuickReply::validateContainer() |
5e52978f | 423 | */ |
52971287 | 424 | public function validateContainer(DatabaseObject $conversation) { |
5e52978f AE |
425 | if (!$conversation->conversationID) { |
426 | throw new UserInputException('objectID'); | |
427 | } | |
428 | else if ($conversation->isClosed || !Conversation::isParticipant(array($conversation->conversationID))) { | |
429 | throw new PermissionDeniedException(); | |
430 | } | |
431 | } | |
432 | ||
b6c2b36c | 433 | /** |
2270f7e9 | 434 | * @see \wcf\data\IMessageQuickReplyAction::validateMessage() |
b6c2b36c | 435 | */ |
d8671029 | 436 | public function validateMessage(DatabaseObject $container, $message) { |
e4124bfc AE |
437 | $message = MessageUtil::stripCrap($message); |
438 | ||
d5702630 | 439 | if (mb_strlen($message) > WCF::getSession()->getPermission('user.conversation.maxLength')) { |
84cebd68 MW |
440 | throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', array('maxTextLength' => WCF::getSession()->getPermission('user.conversation.maxLength')))); |
441 | } | |
442 | ||
027c57f4 MS |
443 | // search for disallowed bbcodes |
444 | $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($message, explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))); | |
445 | if (!empty($disallowedBBCodes)) { | |
446 | throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', array('disallowedBBCodes' => $disallowedBBCodes))); | |
447 | } | |
448 | ||
d8671029 MW |
449 | // search for censored words |
450 | if (ENABLE_CENSORSHIP) { | |
451 | $result = Censorship::getInstance()->test($message); | |
452 | if ($result) { | |
e86562df | 453 | throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', array('censoredWords' => $result))); |
d8671029 MW |
454 | } |
455 | } | |
456 | } | |
b6c2b36c | 457 | |
9353cd87 | 458 | /** |
2270f7e9 | 459 | * @see \wcf\data\IMessageQuickReplyAction::getMessageList() |
9353cd87 AE |
460 | */ |
461 | public function getMessageList(DatabaseObject $conversation, $lastMessageTime) { | |
648456e0 | 462 | $messageList = new ViewableConversationMessageList(); |
a0c1a541 | 463 | $messageList->setConversation($conversation); |
9353cd87 AE |
464 | $messageList->getConditionBuilder()->add("conversation_message.conversationID = ?", array($conversation->conversationID)); |
465 | $messageList->getConditionBuilder()->add("conversation_message.time > ?", array($lastMessageTime)); | |
466 | $messageList->sqlOrderBy = "conversation_message.time ".CONVERSATION_LIST_DEFAULT_SORT_ORDER; | |
467 | $messageList->readObjects(); | |
a480521b | 468 | |
9353cd87 AE |
469 | return $messageList; |
470 | } | |
471 | ||
5e52978f | 472 | /** |
2270f7e9 | 473 | * @see \wcf\data\IMessageQuickReply::getPageNo() |
5e52978f | 474 | */ |
52971287 | 475 | public function getPageNo(DatabaseObject $conversation) { |
5e52978f AE |
476 | $sql = "SELECT COUNT(*) AS count |
477 | FROM wcf".WCF_N."_conversation_message | |
478 | WHERE conversationID = ?"; | |
479 | $statement = WCF::getDB()->prepareStatement($sql); | |
480 | $statement->execute(array($conversation->conversationID)); | |
481 | $count = $statement->fetchArray(); | |
482 | ||
a3157f71 | 483 | return array(intval(ceil($count['count'] / CONVERSATION_MESSAGES_PER_PAGE)), $count['count']); |
5e52978f AE |
484 | } |
485 | ||
486 | /** | |
2270f7e9 | 487 | * @see \wcf\data\IMessageQuickReply::getRedirectUrl() |
5e52978f | 488 | */ |
52971287 | 489 | public function getRedirectUrl(DatabaseObject $conversation, DatabaseObject $message) { |
5e52978f AE |
490 | return LinkHandler::getInstance()->getLink('Conversation', array( |
491 | 'object' => $conversation, | |
492 | 'messageID' => $message->messageID | |
493 | )).'#message'.$message->messageID; | |
494 | } | |
5fa9d104 | 495 | |
42335f61 | 496 | /** |
2270f7e9 | 497 | * @see \wcf\data\IMessageQuoteAction::validateSaveFullQuote() |
42335f61 | 498 | */ |
09f53f03 | 499 | public function validateSaveFullQuote() { |
c2b8907c | 500 | $this->message = $this->getSingleObject(); |
61f754e0 | 501 | |
42335f61 AE |
502 | if (!Conversation::isParticipant(array($this->message->conversationID))) { |
503 | throw new PermissionDeniedException(); | |
504 | } | |
505 | } | |
506 | ||
507 | /** | |
2270f7e9 | 508 | * @see \wcf\data\IMessageQuoteAction::saveFullQuote() |
42335f61 AE |
509 | */ |
510 | public function saveFullQuote() { | |
af6dfd11 | 511 | if (!MessageQuoteManager::getInstance()->addQuote('com.woltlab.wcf.conversation.message', $this->message->conversationID, $this->message->messageID, $this->message->getExcerpt(), $this->message->getMessage())) { |
626fa1ff | 512 | $quoteID = MessageQuoteManager::getInstance()->getQuoteID('com.woltlab.wcf.conversation.message', $this->message->conversationID, $this->message->messageID, $this->message->getExcerpt(), $this->message->getMessage()); |
42335f61 AE |
513 | MessageQuoteManager::getInstance()->removeQuote($quoteID); |
514 | } | |
db864366 | 515 | |
42335f61 | 516 | return array( |
ce6fa919 AE |
517 | 'count' => MessageQuoteManager::getInstance()->countQuotes(), |
518 | 'fullQuoteMessageIDs' => MessageQuoteManager::getInstance()->getFullQuoteObjectIDs(array('com.woltlab.wcf.conversation.message')) | |
42335f61 AE |
519 | ); |
520 | } | |
521 | ||
5fa9d104 | 522 | /** |
2270f7e9 | 523 | * @see \wcf\data\IMessageQuoteAction::validateSaveQuote() |
5fa9d104 AE |
524 | */ |
525 | public function validateSaveQuote() { | |
c2b8907c AE |
526 | $this->readString('message'); |
527 | $this->message = $this->getSingleObject(); | |
5fa9d104 | 528 | |
5fa9d104 AE |
529 | if (!Conversation::isParticipant(array($this->message->conversationID))) { |
530 | throw new PermissionDeniedException(); | |
531 | } | |
532 | } | |
533 | ||
534 | /** | |
2270f7e9 | 535 | * @see \wcf\data\IMessageQuoteAction::saveQuote() |
5fa9d104 AE |
536 | */ |
537 | public function saveQuote() { | |
626fa1ff | 538 | MessageQuoteManager::getInstance()->addQuote('com.woltlab.wcf.conversation.message', $this->message->conversationID, $this->message->messageID, $this->parameters['message']); |
5fa9d104 AE |
539 | |
540 | return array( | |
ce6fa919 AE |
541 | 'count' => MessageQuoteManager::getInstance()->countQuotes(), |
542 | 'fullQuoteMessageIDs' => MessageQuoteManager::getInstance()->getFullQuoteObjectIDs(array('com.woltlab.wcf.conversation.message')) | |
5fa9d104 AE |
543 | ); |
544 | } | |
1ffd7648 AE |
545 | |
546 | /** | |
2270f7e9 | 547 | * @see \wcf\data\IMessageQuoteAction::validateGetRenderedQuotes() |
1ffd7648 AE |
548 | */ |
549 | public function validateGetRenderedQuotes() { | |
550 | $this->readInteger('parentObjectID'); | |
551 | ||
552 | $this->conversation = new Conversation($this->parameters['parentObjectID']); | |
553 | if (!$this->conversation->conversationID) { | |
554 | throw new UserInputException('parentObjectID'); | |
555 | } | |
556 | } | |
557 | ||
558 | /** | |
2270f7e9 | 559 | * @see \wcf\data\IMessageQuoteAction::getRenderedQuotes() |
1ffd7648 AE |
560 | */ |
561 | public function getRenderedQuotes() { | |
3c427544 | 562 | $quotes = MessageQuoteManager::getInstance()->getQuotesByParentObjectID('com.woltlab.wcf.conversation.message', $this->conversation->conversationID); |
ba1ab5e5 | 563 | |
1ffd7648 AE |
564 | return array( |
565 | 'template' => implode("\n\n", $quotes) | |
566 | ); | |
567 | } | |
9544b6b4 | 568 | } |