3 use wcf\data\conversation\label\ConversationLabel
;
4 use wcf\data\conversation\message\ConversationMessage
;
5 use wcf\data\conversation\Conversation
;
6 use wcf\data\conversation\ConversationAction
;
7 use wcf\data\conversation\ConversationParticipantList
;
8 use wcf\data\conversation\ViewableConversation
;
9 use wcf\data\modification\log\ConversationLogModificationLogList
;
10 use wcf\data\smiley\SmileyCache
;
11 use wcf\system\attachment\AttachmentHandler
;
12 use wcf\system\bbcode\BBCodeHandler
;
13 use wcf\system\breadcrumb\Breadcrumb
;
14 use wcf\system\exception\IllegalLinkException
;
15 use wcf\system\exception\PermissionDeniedException
;
16 use wcf\system\message\quote\MessageQuoteManager
;
17 use wcf\system\request\LinkHandler
;
19 use wcf\util\HeaderUtil
;
20 use wcf\util\StringUtil
;
23 * Shows a conversation.
26 * @copyright 2001-2014 WoltLab GmbH
27 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
28 * @package com.woltlab.wcf.conversation
30 * @category Community Framework
32 class ConversationPage
extends MultipleLinkPage
{
34 * @see \wcf\page\AbstractPage::$enableTracking
36 public $enableTracking = true;
39 * @see \wcf\page\MultipleLinkPage::$itemsPerPage
41 public $itemsPerPage = CONVERSATION_MESSAGES_PER_PAGE
;
44 * @see \wcf\page\MultipleLinkPage::$sortOrder
46 public $sortOrder = 'ASC';
49 * @see \wcf\page\MultipleLinkPage::$objectListClassName
51 public $objectListClassName = 'wcf\data\conversation\message\ViewableConversationMessageList';
54 * @see \wcf\page\AbstractPage::$loginRequired
56 public $loginRequired = true;
59 * @see \wcf\page\AbstractPage::$neededModules
61 public $neededModules = array('MODULE_CONVERSATION');
64 * @see \wcf\page\AbstractPage::$neededPermissions
66 public $neededPermissions = array('user.conversation.canUseConversation');
72 public $conversationID = 0;
75 * viewable conversation object
76 * @var \wcf\data\conversation\ViewableConversation
78 public $conversation = null;
81 * conversation label list
82 * @var \wcf\data\conversation\label\ConversationLabelList
84 public $labelList = null;
90 public $messageID = 0;
93 * conversation message object
94 * @var \wcf\data\conversation\message\ConversationMessage
96 public $message = null;
99 * modification log list object
100 * @var \wcf\data\wcf\data\modification\log\ConversationLogModificationLogList
102 public $modificationLogList = null;
105 * list of participants
106 * @var \wcf\data\conversation\ConversationParticipantList
108 public $participantList = null;
111 * @see \wcf\page\IPage::readParameters()
113 public function readParameters() {
114 parent
::readParameters();
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();
123 $this->conversationID
= $this->message
->conversationID
;
126 $this->conversation
= Conversation
::getUserConversation($this->conversationID
, WCF
::getUser()->userID
);
127 if ($this->conversation
=== null) {
128 throw new IllegalLinkException();
130 if (!$this->conversation
->canRead()) {
131 throw new PermissionDeniedException();
135 $this->labelList
= ConversationLabel
::getLabelsByUser();
136 $this->conversation
= ViewableConversation
::getViewableConversation($this->conversation
, $this->labelList
);
139 if (WCF
::getUser()->conversationMessagesPerPage
) $this->itemsPerPage
= WCF
::getUser()->conversationMessagesPerPage
;
143 * @see \wcf\page\MultipleLinkPage::initObjectList()
145 protected function initObjectList() {
146 parent
::initObjectList();
148 $this->objectList
->getConditionBuilder()->add('conversation_message.conversationID = ?', array($this->conversation
->conversationID
));
149 $this->objectList
->setConversation($this->conversation
->getDecoratedObject());
152 if ($this->action
== 'lastPost') $this->goToLastPost();
153 if ($this->action
== 'firstNew') $this->goToFirstNewPost();
154 if ($this->messageID
) $this->goToPost();
158 * @see \wcf\page\IPage::readData()
160 public function readData() {
164 WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.conversation.conversations'), LinkHandler
::getInstance()->getLink('ConversationList')));
165 if ($this->conversation
->isDraft
) {
166 WCF
::getBreadcrumbs()->add(new Breadcrumb(WCF
::getLanguage()->get('wcf.conversation.folder.draft'), LinkHandler
::getInstance()->getLink('ConversationList', array(
171 // update last visit time count
172 if ($this->conversation
->isNew() && $this->objectList
->getMaxPostTime() > $this->conversation
->lastVisitTime
) {
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));
176 $conversationAction->executeAction();
180 $this->participantList
= new ConversationParticipantList($this->conversationID
, WCF
::getUser()->userID
, ($this->conversation
->userID
== WCF
::getUser()->userID
));
181 $this->participantList
->readObjects();
183 // init quote objects
184 $messageIDs = array();
185 foreach ($this->objectList
as $message) {
186 $messageIDs[] = $message->messageID
;
188 MessageQuoteManager
::getInstance()->initObjects('com.woltlab.wcf.conversation.message', $messageIDs);
190 // set attachment permissions
191 if ($this->objectList
->getAttachmentList() !== null) {
192 $this->objectList
->getAttachmentList()->setPermissions(array(
193 'canDownload' => true,
194 'canViewPreview' => true
198 // get timeframe for modifications
199 $this->objectList
->rewind();
200 $startTime = $this->objectList
->current()->time
;
202 $count = count($this->objectList
);
204 $endTime = $startTime;
207 $this->objectList
->seek($count - 1);
208 $endTime = $this->objectList
->current()->time
;
210 $this->objectList
->rewind();
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();
220 * @see \wcf\page\IPage::assignVariables()
222 public function assignVariables() {
223 parent
::assignVariables();
225 MessageQuoteManager
::getInstance()->assignVariables();
227 $tmpHash = StringUtil
::getRandomID();
228 $attachmentHandler = new AttachmentHandler('com.woltlab.wcf.conversation.message', 0, $tmpHash, 0);
230 WCF
::getTPL()->assign(array(
231 'attachmentHandler' => $attachmentHandler,
232 'attachmentObjectID' => 0,
233 'attachmentObjectType' => 'com.woltlab.wcf.conversation.message',
234 'attachmentParentObjectID' => 0,
235 'tmpHash' => $tmpHash,
236 'attachmentList' => $this->objectList
->getAttachmentList(),
237 'labelList' => $this->labelList
,
238 'modificationLogList' => $this->modificationLogList
,
239 'sortOrder' => $this->sortOrder
,
240 'conversation' => $this->conversation
,
241 'conversationID' => $this->conversationID
,
242 'participants' => $this->participantList
->getObjects(),
243 'defaultSmilies' => SmileyCache
::getInstance()->getCategorySmilies(),
244 'permissionCanUseSmilies' => 'user.message.canUseSmilies'
247 BBCodeHandler
::getInstance()->setAllowedBBCodes(explode(',', WCF
::getSession()->getPermission('user.message.allowedBBCodes')));
251 * Calculates the position of a specific post in this conversation.
253 protected function goToPost() {
254 $conditionBuilder = clone $this->objectList
->getConditionBuilder();
255 $conditionBuilder->add('time '.($this->sortOrder
== 'ASC' ?
'<=' : '>=').' ?', array($this->message
->time
));
257 $sql = "SELECT COUNT(*) AS messages
258 FROM wcf".WCF_N
."_conversation_message conversation_message
260 $statement = WCF
::getDB()->prepareStatement($sql);
261 $statement->execute($conditionBuilder->getParameters());
262 $row = $statement->fetchArray();
263 $this->pageNo
= intval(ceil($row['messages'] / $this->itemsPerPage
));
267 * Gets the id of the last post in this conversation and forwards the user to this post.
269 protected function goToLastPost() {
270 $sql = "SELECT conversation_message.messageID
271 FROM wcf".WCF_N
."_conversation_message conversation_message
272 ".$this->objectList
->getConditionBuilder()."
273 ORDER BY time ".($this->sortOrder
== 'ASC' ?
'DESC' : 'ASC');
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']);
285 * Forwards the user to the first new message in this conversation.
287 protected function goToFirstNewPost() {
288 $conditionBuilder = clone $this->objectList
->getConditionBuilder();
289 $conditionBuilder->add('time > ?', array($this->conversation
->lastVisitTime
));
291 $sql = "SELECT conversation_message.messageID
292 FROM wcf".WCF_N
."_conversation_message conversation_message
293 ".$conditionBuilder."
295 $statement = WCF
::getDB()->prepareStatement($sql, 1);
296 $statement->execute($conditionBuilder->getParameters());
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']);
306 $this->goToLastPost();
311 * @see \wcf\page\ITrackablePage::getObjectType()
313 public function getObjectType() {
314 return 'com.woltlab.wcf.conversation';
318 * @see \wcf\page\ITrackablePage::getObjectID()
320 public function getObjectID() {
321 return $this->conversationID
;