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