/**
  * Updates the data of this post.
  * 
  * @param	string				$subject		new subject of this post
  * @param	string				$message		new text of this post
  * @param	array				$options		new options of this post
  * @param	AttachmentsEditor		$attachments		
  * @param	PollEditor			$poll
  */
 public function update($subject, $message, $options, $attachments = null, $poll = null, $additionalData = array())
 {
     $updateSubject = $updateText = '';
     $attachmentsAmount = $attachments != null ? count($attachments->getAttachments($this->postID)) : 0;
     // save subject
     if ($subject != $this->subject) {
         $updateSubject = "subject = '" . escapeString($subject) . "',";
     }
     // save message
     $updateText = "message = '" . escapeString($message) . "',";
     // assign attachments
     if ($attachments != null) {
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachments->getSortedAttachments());
     }
     // update post cache
     require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
     $parser = MessageParser::getInstance();
     $parser->setOutputType('text/html');
     $sql = "UPDATE\twbb" . WBB_N . "_post_cache\n\t\t\tSET\tmessageCache = '" . escapeString($parser->parse($message, $options['enableSmilies'], $options['enableHtml'], $options['enableBBCodes'], false)) . "'\n\t\t\tWHERE\tpostID = " . $this->postID;
     WCF::getDB()->registerShutdownUpdate($sql);
     $additionalSql = '';
     foreach ($additionalData as $key => $value) {
         $additionalSql .= ',' . $key . "='" . escapeString($value) . "'";
     }
     // save post in database
     $sql = "UPDATE \twbb" . WBB_N . "_post\n\t\t\tSET\t{$updateSubject}\n\t\t\t\t{$updateText}\n\t\t\t\tattachments = " . $attachmentsAmount . ",\n\t\t\t\t" . ($poll != null ? "pollID = " . intval($poll->pollID) . "," : '') . "\n\t\t\t\tenableSmilies = " . $options['enableSmilies'] . ",\n\t\t\t\tenableHtml = " . $options['enableHtml'] . ",\n\t\t\t\tenableBBCodes = " . $options['enableBBCodes'] . ",\n\t\t\t\tshowSignature = " . $options['showSignature'] . "\n\t\t\t\t" . $additionalSql . "\n\t\t\tWHERE \tpostID = " . $this->postID;
     WCF::getDB()->sendQuery($sql);
     // update attachments
     if ($attachments != null) {
         $attachments->findEmbeddedAttachments($message);
     }
     // update poll
     if ($poll != null) {
         $poll->updateMessageID($this->postID);
     }
     // update first post preview
     $this->updateFirstPostPreview($this->threadID, $this->postID, $message, $options);
     // refresh thread data
     require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
     ThreadEditor::refreshAll($this->threadID, false);
 }
 /**
  * Merges posts.
  */
 public function merge()
 {
     if ($this->post === null || empty($this->postIDs)) {
         throw new IllegalLinkException();
     }
     // remove target post from source
     $postIDArray = explode(',', $this->postIDs);
     if (($key = array_search($this->post->postID, $postIDArray)) !== false) {
         unset($postIDArray[$key]);
         $this->postIDs = implode(',', $postIDArray);
     }
     // get thread ids
     $threadIDs = PostEditor::getThreadIDs($this->postIDs);
     // get boards
     list($boards, $boardIDs) = ThreadEditor::getBoards($threadIDs);
     // check permissions
     $this->board->checkModeratorPermission('canMergePost');
     foreach ($boards as $board) {
         $board->checkModeratorPermission('canMergePost');
     }
     // remove user stats
     ThreadEditor::updateUserStats($threadIDs, 'delete');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'delete');
     // merge posts
     PostEditor::mergeAll($this->postIDs, $this->post->postID);
     PostEditor::unmarkAll();
     // handle threads (check for empty, deleted and hidden threads)
     ThreadEditor::checkVisibilityAll($threadIDs);
     // refresh last post, replies, attachments, polls in threads
     ThreadEditor::refreshAll($threadIDs);
     // re-add user stats
     ThreadEditor::updateUserStats($threadIDs, 'enable');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'enable');
     // refresh counts
     BoardEditor::refreshAll($boardIDs);
     // refresh last post in boards
     $this->board->setLastPosts();
     foreach ($boards as $board) {
         $board->setLastPosts();
     }
     HeaderUtil::redirect($this->url);
     exit;
 }
 /**
  * Moves and inserts the marked posts in a new thread.
  */
 public function moveAndInsert()
 {
     if ($this->board == null) {
         throw new IllegalLinkException();
     }
     // check permission
     $this->board->checkModeratorPermission('canMovePost');
     // get threadids
     $threadIDs = PostEditor::getThreadIDs($this->postIDs);
     // get boards
     list($boards, $boardIDs) = ThreadEditor::getBoards($threadIDs);
     // check permissions
     foreach ($boards as $board) {
         $board->checkModeratorPermission('canMovePost');
     }
     // remove user stats
     ThreadEditor::updateUserStats($threadIDs, 'delete');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'delete');
     // create new thread
     $thread = ThreadEditor::createFromPosts($this->postIDs, $this->board->boardID);
     // move posts
     PostEditor::moveAll($this->postIDs, $thread->threadID, $thread->boardID);
     PostEditor::unmarkAll();
     // check threads
     ThreadEditor::checkVisibilityAll($threadIDs . ',' . $thread->threadID);
     // refresh
     ThreadEditor::refreshAll($threadIDs . ',' . $thread->threadID);
     // re-add user stats
     ThreadEditor::updateUserStats($threadIDs, 'enable');
     PostEditor::updateUserStats($this->postIDs, 'enable');
     PostEditor::updateUserStats(ThreadEditor::getAllPostIDs($threadIDs), 'enable');
     // refresh counts
     BoardEditor::refreshAll($boardIDs . ',' . $this->board->boardID);
     // set last post
     $this->board->setLastPosts();
     foreach ($boards as $board) {
         $board->setLastPosts();
     }
     self::resetCache();
     HeaderUtil::redirect($this->url);
     exit;
 }