Commit | Line | Data |
---|---|---|
9544b6b4 MW |
1 | <?php |
2 | namespace wcf\page; | |
2e0bc870 | 3 | use wcf\data\conversation\label\ConversationLabel; |
9544b6b4 | 4 | use wcf\data\conversation\message\ConversationMessage; |
232cdc4b | 5 | use wcf\data\conversation\Conversation; |
9544b6b4 | 6 | use wcf\data\conversation\ConversationAction; |
530c5f83 | 7 | use wcf\data\conversation\ConversationParticipantList; |
2e0bc870 | 8 | use wcf\data\conversation\ViewableConversation; |
83e23d22 | 9 | use wcf\data\modification\log\ConversationLogModificationLogList; |
b2de9161 | 10 | use wcf\data\smiley\SmileyCache; |
41c23899 | 11 | use wcf\system\attachment\AttachmentHandler; |
a21c8732 | 12 | use wcf\system\bbcode\BBCodeHandler; |
9544b6b4 MW |
13 | use wcf\system\breadcrumb\Breadcrumb; |
14 | use wcf\system\exception\IllegalLinkException; | |
15 | use wcf\system\exception\PermissionDeniedException; | |
2d181735 | 16 | use wcf\system\message\quote\MessageQuoteManager; |
9544b6b4 MW |
17 | use wcf\system\request\LinkHandler; |
18 | use wcf\system\WCF; | |
19 | use wcf\util\HeaderUtil; | |
41c23899 | 20 | use wcf\util\StringUtil; |
9544b6b4 MW |
21 | |
22 | /** | |
23 | * Shows a conversation. | |
61f754e0 | 24 | * |
9544b6b4 | 25 | * @author Marcel Werk |
c7b2df3b | 26 | * @copyright 2001-2014 WoltLab GmbH |
9544b6b4 MW |
27 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
28 | * @package com.woltlab.wcf.conversation | |
29 | * @subpackage page | |
61f754e0 | 30 | * @category Community Framework |
9544b6b4 MW |
31 | */ |
32 | class ConversationPage extends MultipleLinkPage { | |
f2855298 | 33 | /** |
2270f7e9 | 34 | * @see \wcf\page\AbstractPage::$enableTracking |
f2855298 MW |
35 | */ |
36 | public $enableTracking = true; | |
37 | ||
9544b6b4 | 38 | /** |
2270f7e9 | 39 | * @see \wcf\page\MultipleLinkPage::$itemsPerPage |
9544b6b4 MW |
40 | */ |
41 | public $itemsPerPage = CONVERSATION_MESSAGES_PER_PAGE; | |
42 | ||
43 | /** | |
2270f7e9 | 44 | * @see \wcf\page\MultipleLinkPage::$sortOrder |
9544b6b4 MW |
45 | */ |
46 | public $sortOrder = 'ASC'; | |
47 | ||
48 | /** | |
2270f7e9 | 49 | * @see \wcf\page\MultipleLinkPage::$objectListClassName |
9544b6b4 MW |
50 | */ |
51 | public $objectListClassName = 'wcf\data\conversation\message\ViewableConversationMessageList'; | |
52 | ||
84e18f05 | 53 | /** |
2270f7e9 | 54 | * @see \wcf\page\AbstractPage::$loginRequired |
84e18f05 MS |
55 | */ |
56 | public $loginRequired = true; | |
57 | ||
c764783c | 58 | /** |
2270f7e9 | 59 | * @see \wcf\page\AbstractPage::$neededModules |
c764783c MW |
60 | */ |
61 | public $neededModules = array('MODULE_CONVERSATION'); | |
62 | ||
63 | /** | |
2270f7e9 | 64 | * @see \wcf\page\AbstractPage::$neededPermissions |
c764783c MW |
65 | */ |
66 | public $neededPermissions = array('user.conversation.canUseConversation'); | |
67 | ||
9544b6b4 MW |
68 | /** |
69 | * conversation id | |
61f754e0 | 70 | * @var integer |
9544b6b4 MW |
71 | */ |
72 | public $conversationID = 0; | |
73 | ||
74 | /** | |
a208d1f4 | 75 | * viewable conversation object |
2270f7e9 | 76 | * @var \wcf\data\conversation\ViewableConversation |
9544b6b4 MW |
77 | */ |
78 | public $conversation = null; | |
79 | ||
2e0bc870 AE |
80 | /** |
81 | * conversation label list | |
2270f7e9 | 82 | * @var \wcf\data\conversation\label\ConversationLabelList |
2e0bc870 AE |
83 | */ |
84 | public $labelList = null; | |
85 | ||
9544b6b4 MW |
86 | /** |
87 | * message id | |
61f754e0 | 88 | * @var integer |
9544b6b4 MW |
89 | */ |
90 | public $messageID = 0; | |
91 | ||
92 | /** | |
93 | * conversation message object | |
2270f7e9 | 94 | * @var \wcf\data\conversation\message\ConversationMessage |
9544b6b4 MW |
95 | */ |
96 | public $message = null; | |
97 | ||
a208d1f4 AE |
98 | /** |
99 | * modification log list object | |
2270f7e9 | 100 | * @var \wcf\data\wcf\data\modification\log\ConversationLogModificationLogList |
a208d1f4 AE |
101 | */ |
102 | public $modificationLogList = null; | |
103 | ||
530c5f83 MW |
104 | /** |
105 | * list of participants | |
2270f7e9 | 106 | * @var \wcf\data\conversation\ConversationParticipantList |
530c5f83 MW |
107 | */ |
108 | public $participantList = null; | |
109 | ||
9544b6b4 | 110 | /** |
2270f7e9 | 111 | * @see \wcf\page\IPage::readParameters() |
9544b6b4 MW |
112 | */ |
113 | public function readParameters() { | |
114 | parent::readParameters(); | |
115 | ||
116 | if (isset($_REQUEST['id'])) $this->conversationID = intval($_REQUEST['id']); | |
117 | if (isset($_REQUEST['messageID'])) $this->messageID = intval($_REQUEST['messageID']); | |
118 | if ($this->messageID) { | |
119 | $this->message = new ConversationMessage($this->messageID); | |
120 | if (!$this->message->messageID) { | |
121 | throw new IllegalLinkException(); | |
122 | } | |
c764783c | 123 | $this->conversationID = $this->message->conversationID; |
9544b6b4 MW |
124 | } |
125 | ||
126 | $this->conversation = Conversation::getUserConversation($this->conversationID, WCF::getUser()->userID); | |
127 | if ($this->conversation === null) { | |
128 | throw new IllegalLinkException(); | |
129 | } | |
130 | if (!$this->conversation->canRead()) { | |
131 | throw new PermissionDeniedException(); | |
132 | } | |
133 | ||
2e0bc870 AE |
134 | // load labels |
135 | $this->labelList = ConversationLabel::getLabelsByUser(); | |
136 | $this->conversation = ViewableConversation::getViewableConversation($this->conversation, $this->labelList); | |
137 | ||
9544b6b4 MW |
138 | // posts per page |
139 | if (WCF::getUser()->conversationMessagesPerPage) $this->itemsPerPage = WCF::getUser()->conversationMessagesPerPage; | |
140 | } | |
141 | ||
142 | /** | |
2270f7e9 | 143 | * @see \wcf\page\MultipleLinkPage::initObjectList() |
9544b6b4 MW |
144 | */ |
145 | protected function initObjectList() { | |
146 | parent::initObjectList(); | |
147 | ||
148 | $this->objectList->getConditionBuilder()->add('conversation_message.conversationID = ?', array($this->conversation->conversationID)); | |
28bd6cbd | 149 | $this->objectList->setConversation($this->conversation->getDecoratedObject()); |
9544b6b4 MW |
150 | |
151 | // handle jump to | |
152 | if ($this->action == 'lastPost') $this->goToLastPost(); | |
153 | if ($this->action == 'firstNew') $this->goToFirstNewPost(); | |
154 | if ($this->messageID) $this->goToPost(); | |
155 | } | |
156 | ||
157 | /** | |
2270f7e9 | 158 | * @see \wcf\page\IPage::readData() |
9544b6b4 MW |
159 | */ |
160 | public function readData() { | |
161 | parent::readData(); | |
162 | ||
163 | // add breadcrumbs | |
164 | WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.conversation.conversations'), LinkHandler::getInstance()->getLink('ConversationList'))); | |
f34884b9 MW |
165 | if ($this->conversation->isDraft) { |
166 | WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.conversation.folder.draft'), LinkHandler::getInstance()->getLink('ConversationList', array( | |
167 | 'filter' => 'draft' | |
168 | )))); | |
169 | } | |
9544b6b4 MW |
170 | |
171 | // update last visit time count | |
172 | if ($this->conversation->isNew() && $this->objectList->getMaxPostTime() > $this->conversation->lastVisitTime) { | |
c0dd7a12 MW |
173 | $visitTime = $this->objectList->getMaxPostTime(); |
174 | if ($visitTime == $this->conversation->lastPostTime) $visitTime = TIME_NOW; | |
175 | $conversationAction = new ConversationAction(array($this->conversation->getDecoratedObject()), 'markAsRead', array('visitTime' => $visitTime)); | |
9544b6b4 MW |
176 | $conversationAction->executeAction(); |
177 | } | |
530c5f83 MW |
178 | |
179 | // get participants | |
ee89a9db | 180 | $this->participantList = new ConversationParticipantList($this->conversationID, WCF::getUser()->userID, ($this->conversation->userID == WCF::getUser()->userID)); |
530c5f83 | 181 | $this->participantList->readObjects(); |
42335f61 AE |
182 | |
183 | // init quote objects | |
184 | $messageIDs = array(); | |
185 | foreach ($this->objectList as $message) { | |
186 | $messageIDs[] = $message->messageID; | |
187 | } | |
188 | MessageQuoteManager::getInstance()->initObjects('com.woltlab.wcf.conversation.message', $messageIDs); | |
f7b9b1f3 MW |
189 | |
190 | // set attachment permissions | |
191 | if ($this->objectList->getAttachmentList() !== null) { | |
192 | $this->objectList->getAttachmentList()->setPermissions(array( | |
193 | 'canDownload' => true, | |
a480521b | 194 | 'canViewPreview' => true |
f7b9b1f3 MW |
195 | )); |
196 | } | |
a208d1f4 AE |
197 | |
198 | // get timeframe for modifications | |
199 | $this->objectList->rewind(); | |
200 | $startTime = $this->objectList->current()->time; | |
201 | ||
202 | $count = count($this->objectList); | |
203 | if ($count == 1) { | |
204 | $endTime = $startTime; | |
205 | } | |
206 | else { | |
207 | $this->objectList->seek($count - 1); | |
208 | $endTime = $this->objectList->current()->time; | |
209 | } | |
210 | $this->objectList->rewind(); | |
211 | ||
212 | // load modification log entries | |
213 | $this->modificationLogList = new ConversationLogModificationLogList(); | |
214 | $this->modificationLogList->setConversation($this->conversation->getDecoratedObject()); | |
215 | $this->modificationLogList->getConditionBuilder()->add("modification_log.time BETWEEN ? AND ?", array($startTime, $endTime)); | |
216 | $this->modificationLogList->readObjects(); | |
9544b6b4 MW |
217 | } |
218 | ||
219 | /** | |
2270f7e9 | 220 | * @see \wcf\page\IPage::assignVariables() |
9544b6b4 MW |
221 | */ |
222 | public function assignVariables() { | |
223 | parent::assignVariables(); | |
224 | ||
2d181735 AE |
225 | MessageQuoteManager::getInstance()->assignVariables(); |
226 | ||
41c23899 AE |
227 | $tmpHash = StringUtil::getRandomID(); |
228 | $attachmentHandler = new AttachmentHandler('com.woltlab.wcf.conversation.message', 0, $tmpHash, 0); | |
229 | ||
9544b6b4 | 230 | WCF::getTPL()->assign(array( |
41c23899 AE |
231 | 'attachmentHandler' => $attachmentHandler, |
232 | 'attachmentObjectID' => 0, | |
233 | 'attachmentObjectType' => 'com.woltlab.wcf.conversation.message', | |
234 | 'attachmentParentObjectID' => 0, | |
235 | 'tmpHash' => $tmpHash, | |
9544b6b4 | 236 | 'attachmentList' => $this->objectList->getAttachmentList(), |
2e0bc870 | 237 | 'labelList' => $this->labelList, |
a208d1f4 | 238 | 'modificationLogList' => $this->modificationLogList, |
9544b6b4 MW |
239 | 'sortOrder' => $this->sortOrder, |
240 | 'conversation' => $this->conversation, | |
530c5f83 | 241 | 'conversationID' => $this->conversationID, |
52971287 | 242 | 'participants' => $this->participantList->getObjects(), |
a21c8732 MS |
243 | 'defaultSmilies' => SmileyCache::getInstance()->getCategorySmilies(), |
244 | 'permissionCanUseSmilies' => 'user.message.canUseSmilies' | |
9544b6b4 | 245 | )); |
a21c8732 MS |
246 | |
247 | BBCodeHandler::getInstance()->setAllowedBBCodes(explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))); | |
9544b6b4 MW |
248 | } |
249 | ||
250 | /** | |
251 | * Calculates the position of a specific post in this conversation. | |
252 | */ | |
253 | protected function goToPost() { | |
254 | $conditionBuilder = clone $this->objectList->getConditionBuilder(); | |
255 | $conditionBuilder->add('time '.($this->sortOrder == 'ASC' ? '<=' : '>=').' ?', array($this->message->time)); | |
256 | ||
257 | $sql = "SELECT COUNT(*) AS messages | |
a480521b | 258 | FROM wcf".WCF_N."_conversation_message conversation_message |
9544b6b4 | 259 | ".$conditionBuilder; |
a21c8732 MS |
260 | $statement = WCF::getDB()->prepareStatement($sql); |
261 | $statement->execute($conditionBuilder->getParameters()); | |
9544b6b4 MW |
262 | $row = $statement->fetchArray(); |
263 | $this->pageNo = intval(ceil($row['messages'] / $this->itemsPerPage)); | |
264 | } | |
265 | ||
266 | /** | |
267 | * Gets the id of the last post in this conversation and forwards the user to this post. | |
268 | */ | |
269 | protected function goToLastPost() { | |
4f13dcae | 270 | $sql = "SELECT conversation_message.messageID |
a480521b | 271 | FROM wcf".WCF_N."_conversation_message conversation_message |
9544b6b4 | 272 | ".$this->objectList->getConditionBuilder()." |
a480521b | 273 | ORDER BY time ".($this->sortOrder == 'ASC' ? 'DESC' : 'ASC'); |
9544b6b4 MW |
274 | $statement = WCF::getDB()->prepareStatement($sql, 1); |
275 | $statement->execute($this->objectList->getConditionBuilder()->getParameters()); | |
276 | $row = $statement->fetchArray(); | |
277 | HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Conversation', array( | |
278 | 'object' => $this->conversation, | |
279 | 'messageID' => $row['messageID'] | |
280 | )).'#message'.$row['messageID']); | |
281 | exit; | |
282 | } | |
283 | ||
284 | /** | |
285 | * Forwards the user to the first new message in this conversation. | |
286 | */ | |
287 | protected function goToFirstNewPost() { | |
288 | $conditionBuilder = clone $this->objectList->getConditionBuilder(); | |
289 | $conditionBuilder->add('time > ?', array($this->conversation->lastVisitTime)); | |
290 | ||
291 | $sql = "SELECT conversation_message.messageID | |
a480521b | 292 | FROM wcf".WCF_N."_conversation_message conversation_message |
9544b6b4 | 293 | ".$conditionBuilder." |
a480521b | 294 | ORDER BY time ASC"; |
a21c8732 MS |
295 | $statement = WCF::getDB()->prepareStatement($sql, 1); |
296 | $statement->execute($conditionBuilder->getParameters()); | |
9544b6b4 MW |
297 | $row = $statement->fetchArray(); |
298 | if ($row !== false) { | |
299 | HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Conversation', array( | |
300 | 'object' => $this->conversation, | |
301 | 'messageID' => $row['messageID'] | |
302 | )).'#message'.$row['messageID']); | |
303 | exit; | |
304 | } | |
305 | else { | |
306 | $this->goToLastPost(); | |
307 | } | |
308 | } | |
309 | ||
f2855298 | 310 | /** |
2270f7e9 | 311 | * @see \wcf\page\ITrackablePage::getObjectType() |
f2855298 MW |
312 | */ |
313 | public function getObjectType() { | |
314 | return 'com.woltlab.wcf.conversation'; | |
315 | } | |
316 | ||
317 | /** | |
2270f7e9 | 318 | * @see \wcf\page\ITrackablePage::getObjectID() |
f2855298 MW |
319 | */ |
320 | public function getObjectID() { | |
321 | return $this->conversationID; | |
322 | } | |
78fd78a7 | 323 | } |