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