/**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // add edit note
     $postData = array();
     if (!$this->board->getPermission('canHideEditNote') && (WCF::getUser()->userID != $this->post->userID || $this->post->time <= TIME_NOW - POST_EDIT_HIDE_EDIT_NOTE_PERIOD * 60)) {
         $postData['editor'] = WCF::getUser()->username;
         $postData['editorID'] = WCF::getUser()->userID;
         $postData['lastEditTime'] = TIME_NOW;
         $postData['editCount'] = $this->post->editCount + 1;
         $postData['editReason'] = '';
     }
     // update message
     $this->post->updateMessage($this->text, $postData);
     if ($this->thread->firstPostID == $this->post->postID) {
         // update first post preview
         $this->post->updateFirstPostPreview($this->post->threadID, $this->post->postID, $this->text, array('enableSmilies' => $this->post->enableSmilies, 'enableHtml' => $this->post->enableHtml, 'enableBBCodes' => $this->post->enableBBCodes));
     }
     $this->executed();
     // get new formatted message and return it
     $postList = new PostList();
     $postList->sqlConditions = 'post.postID = ' . $this->postID;
     $postList->readPosts();
     $post = reset($postList->posts);
     HeaderUtil::sendHeaders();
     echo $post->getFormattedMessage();
 }
 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // add cache resources
     WCF::getCache()->addResource('bbcodes', WCF_DIR . 'cache/cache.bbcodes.php', WCF_DIR . 'lib/system/cache/CacheBuilderBBCodes.class.php');
     WCF::getCache()->addResource('smileys', WCF_DIR . 'cache/cache.smileys.php', WCF_DIR . 'lib/system/cache/CacheBuilderSmileys.class.php');
     // count threads
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twbb" . WBB_N . "_thread";
     $row = WCF::getDB()->getFirstRow($sql);
     $count = $row['count'];
     // get thread ids
     $threadIDs = '';
     $sql = "SELECT\t\tthreadID\n\t\t\tFROM\t\twbb" . WBB_N . "_thread\n\t\t\tORDER BY\tthreadID";
     $result = WCF::getDB()->sendQuery($sql, $this->limit, $this->limit * $this->loop);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $threadIDs .= ',' . $row['threadID'];
     }
     if (empty($threadIDs)) {
         $this->calcProgress();
         $this->finish();
     }
     // get data
     $sql = "SELECT\t\tthread.threadID,\n\t\t\t\t\tpost.postID, post.message, post.enableSmilies, post.enableHtml, post.enableBBCodes\n\t\t\tFROM\t\twbb" . WBB_N . "_thread thread\n\t\t\tLEFT JOIN\twbb" . WBB_N . "_post post\n\t\t\tON\t\t(post.postID = thread.firstPostID)\n\t\t\tWHERE\t\tthread.threadID IN (0" . $threadIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if ($row['postID']) {
             PostEditor::updateFirstPostPreview($row['threadID'], $row['postID'], $row['message'], $row);
         }
     }
     $this->executed();
     $this->calcProgress($this->limit * $this->loop, $count);
     $this->nextLoop();
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     // get post, thread and board
     $this->post = new PostEditor($this->postID);
     $this->thread = new Thread($this->post->threadID);
     $this->board = Board::getBoard($this->thread->boardID);
     // get ip addresses of the author
     $this->authorIpAddresses = PostEditor::getIpAddressByAuthor($this->post->userID, $this->post->username, $this->post->ipAddress);
     // get hostnames
     $this->loadHostnames();
     // get other users of this ip address
     if ($this->post->ipAddress) {
         $this->otherUsers = PostEditor::getAuthorByIpAddress($this->post->ipAddress, $this->post->userID, $this->post->username);
     }
 }
 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // check permissions
     $boardIDs = Board::getModeratedBoards('canDeletePostCompletely');
     if (empty($boardIDs)) {
         throw new PermissionDeniedException();
     }
     // delete posts
     $postIDArray = array();
     $sql = "SELECT\tpostID\n\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\tWHERE\tisDeleted = 1\n\t\t\t\tAND threadID IN (\n\t\t\t\t\tSELECT\tthreadID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\tWHERE\tboardID IN (" . $boardIDs . ")\n\t\t\t\t\t\tAND isDeleted = 0\n\t\t\t\t)";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $postIDArray[] = $row['postID'];
     }
     if (count($postIDArray)) {
         PostEditor::deleteAllCompletely(implode(',', $postIDArray));
     }
     $this->executed();
     // forward
     HeaderUtil::redirect('index.php?page=ModerationDeletedPosts' . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     if (THREAD_ENABLE_RECYCLE_BIN && THREAD_EMPTY_RECYCLE_BIN_CYCLE > 0) {
         // delete threads first
         $sql = "SELECT\tthreadID\n\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\tWHERE\tisDeleted = 1\n\t\t\t\t\tAND deleteTime < " . (TIME_NOW - THREAD_EMPTY_RECYCLE_BIN_CYCLE * 86400);
         $result = WCF::getDB()->sendQuery($sql);
         if (WCF::getDB()->countRows($result) > 0) {
             require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
             $threadIDs = '';
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($threadIDs)) {
                     $threadIDs .= ',';
                 }
                 $threadIDs .= $row['threadID'];
             }
             ThreadEditor::deleteAllCompletely($threadIDs);
         }
         // delete posts
         $sql = "SELECT\tpostID\n\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\tWHERE\tisDeleted = 1\n\t\t\t\t\tAND deleteTime < " . (TIME_NOW - THREAD_EMPTY_RECYCLE_BIN_CYCLE * 86400);
         $result = WCF::getDB()->sendQuery($sql);
         if (WCF::getDB()->countRows($result) > 0) {
             require_once WBB_DIR . 'lib/data/post/PostEditor.class.php';
             $postIDs = '';
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($postIDs)) {
                     $postIDs .= ',';
                 }
                 $postIDs .= $row['postID'];
             }
             PostEditor::deleteAllCompletely($postIDs);
         }
     }
     if (THREAD_DELETE_LINK_CYCLE > 0) {
         $sql = "DELETE FROM\twbb" . WBB_N . "_thread\n\t\t\t\tWHERE\t\tmovedTime > 0\n\t\t\t\t\t\tAND movedTime < " . (TIME_NOW - THREAD_DELETE_LINK_CYCLE * 86400);
         WCF::getDB()->sendQuery($sql);
     }
 }
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (MODULE_USER_NOTIFICATION) {
         if ($className === 'PostActionPage') {
             $markedPostIDs = WCF::getSession()->getVar('markedPosts');
             if ($eventObj->post !== null && $eventObj->post->userID != WCF::getUser()->userID) {
                 if ($eventObj->action === 'trash') {
                     if (!THREAD_ENABLE_RECYCLE_BIN || !$eventObj->board->getModeratorPermission('canDeletePost') || $eventObj->post->isDeleted) {
                         return;
                     }
                     NotificationHandler::fireEvent('trashed', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->reason, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                     return true;
                 } else {
                     if ($eventObj->action === 'delete') {
                         if (!$eventObj->board->getModeratorPermission('canDeletePostCompletely')) {
                             return;
                         }
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post->postID);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                         return true;
                     } else {
                         if ($eventObj->action === 'recover') {
                             if (!$eventObj->board->getModeratorPermission('canDeletePostCompletely') || !$eventObj->post->isDeleted) {
                                 return;
                             }
                             NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post);
                             return true;
                         }
                     }
                 }
             }
             if ($markedPostIDs !== null && count($markedPostIDs)) {
                 if ($eventObj->action === 'deleteAll') {
                     $trashPosts = array();
                     $trashPostsThreadIDs = array();
                     $deletePosts = array();
                     $deletePostsThreadIDs = array();
                     $sql = "SELECT\t\tpost.*, thread.threadID, thread.topic\n\t\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_post post\n\t\t\t\t\t\t\tLEFT JOIN\twbb" . WBB_N . "_thread thread\n\t\t\t\t\t\t\tON\t\t(post.threadID = thread.threadID)\n\t\t\t\t\t\t\tWHERE\t\tpost.postID IN (" . implode(',', $markedPostIDs) . ")";
                     $result = WCF::getDB()->sendQuery($sql);
                     while ($row = WCF::getDB()->fetchArray($result)) {
                         if ($row['userID'] != WCF::getUser()->userID) {
                             if ($row['isDeleted'] || !THREAD_ENABLE_RECYCLE_BIN) {
                                 $deletePosts[$row['postID']] = new PostDeleteNotificationObject(null, $row);
                                 $deletePostsThreadIDs[] = $row['threadID'];
                             } else {
                                 $trashPosts[$row['postID']] = new PostDeleteNotificationObject(null, $row);
                                 $trashPostsThreadIDs[] = $row['threadID'];
                             }
                         }
                     }
                     list($trashPostsBoards, $trashPostsBoardIDs) = ThreadEditor::getBoards(implode(',', $trashPostsThreadIDs));
                     list($deletePostsBoards, $deletePostsBoardIDs) = ThreadEditor::getBoards(implode(',', $deletePostsThreadIDs));
                     foreach ($trashPostsBoards as $trashPostsBoard) {
                         $trashPostsBoard->checkModeratorPermission('canDeletePost');
                     }
                     foreach ($deletePostsBoards as $deletePostsBoard) {
                         $deletePostsBoard->checkModeratorPermission('canDeletePostCompletely');
                     }
                     unset($trashPostsThreadIDs, $deletePostsThreadIDs, $trashPostsBoards, $deletePostsBoards, $trashPostsBoardIDs, $deletePostsBoardIDs);
                     foreach ($trashPosts as $trashPost) {
                         NotificationHandler::fireEvent('trashed', 'postDelete', $trashPost, $trashPost->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->reason, 'threadID' => $trashPost->threadID, 'threadTopic' => $trashPost->topic));
                     }
                     foreach ($deletePosts as $deletePost) {
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $deletePost);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $deletePost, $deletePost->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $deletePost->threadID, 'threadTopic' => $deletePost->topic));
                     }
                     return true;
                 } else {
                     if ($eventObj->action === 'recoverAll') {
                         $threadIDs = PostEditor::getThreadIDs(implode(',', $markedPostIDs));
                         $notificationObjectObjects = NotificationHandler::getNotificationObjectTypeObject('postDelete')->getObjects($markedPostIDs);
                         list($boards, $boardIDs) = ThreadEditor::getBoards($threadIDs);
                         foreach ($boards as $board) {
                             $board->checkModeratorPermission('canDeletePostCompletely');
                         }
                         unset($threadIDs, $boards, $boardIDs);
                         foreach ($notificationObjectObjects as $notificationObjectObject) {
                             NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $notificationObjectObject);
                         }
                         return true;
                     }
                 }
             }
         } else {
             if ($className === 'ThreadPage') {
                 $posts = $eventObj->postList->posts;
                 $postIDs = array();
                 $user = new NotificationUser(null, WCF::getUser(), false);
                 $packageID = NotificationHandler::getNotificationObjectTypeObject('postDelete')->getPackageID();
                 foreach ($posts as $post) {
                     if ($post->isDeleted && $post->userID == $user->userID) {
                         $postIDs[] = $post->postID;
                     }
                 }
                 unset($posts);
                 if (isset($user->notificationFlags[$packageID]) && $user->notificationFlags[$packageID] > 0) {
                     $count = NotificationEditor::markConfirmedByObjectVisit($user->userID, array('trashed'), 'postDelete', $postIDs);
                     $user->removeOutstandingNotification($packageID, $count);
                 }
             } else {
                 if ($className === 'PostEditForm' && $eventObj->post->userID != WCF::getUser()->userID && isset($_POST['deletePost']) && isset($_POST['sure'])) {
                     if ((!THREAD_ENABLE_RECYCLE_BIN || THREAD_ENABLE_RECYCLE_BIN && $eventObj->post->isDeleted) && $eventObj->board->getModeratorPermission('canDeletePostCompletely')) {
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post->postID);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                     } else {
                         if (!$eventObj->post->isDeleted && THREAD_ENABLE_RECYCLE_BIN && $eventObj->board->getModeratorPermission('canDeletePost')) {
                             NotificationHandler::fireEvent('trashed', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->deleteReason, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Creates a new thread.
  */
 public static function createFromPosts($postIDs, $boardID)
 {
     // get post
     $sql = "SELECT \t\tpost.*, thread.languageID\n\t\t\tFROM \t\twbb" . WBB_N . "_post post\n\t\t\tLEFT JOIN\twbb" . WBB_N . "_thread thread\n\t\t\tON\t\t(thread.threadID = post.threadID)\n\t\t\tWHERE \t\tpost.postID IN (" . $postIDs . ")\n\t\t\tORDER BY \tpost.time ASC";
     $row = WCF::getDB()->getFirstRow($sql);
     $post = new Post(null, $row);
     $sql = "INSERT INTO \twbb" . WBB_N . "_thread\n\t\t\t\t\t(boardID, topic, firstPostID, time, userID, username, languageID)\n\t\t\tVALUES\t\t(" . $boardID . ",\n\t\t\t\t\t'" . escapeString($post->subject ? $post->subject : substr($post->message, 0, 255)) . "',\n\t\t\t\t\t" . $post->postID . ",\n\t\t\t\t\t" . $post->time . ",\n\t\t\t\t\t" . $post->userID . ",\n\t\t\t\t\t'" . escapeString($post->username) . "',\n\t\t\t\t\t" . intval($row['languageID']) . ")";
     WCF::getDB()->sendQuery($sql);
     $threadID = WCF::getDB()->getInsertID();
     // update user posts & activity points
     self::updateUserStats($threadID, 'copy', $boardID);
     // update first post preview
     PostEditor::updateFirstPostPreview($threadID, $post->postID, $post->message, array('enableSmilies' => $post->enableSmilies, 'enableHtml' => $post->enableHtml, 'enableBBCodes' => $post->enableBBCodes));
     return new ThreadEditor($threadID);
 }
 /**
  * Copies and inserts the marked posts in a new thread.
  */
 public function copyAndInsert()
 {
     if ($this->board == null) {
         throw new IllegalLinkException();
     }
     $this->board->checkModeratorPermission('canCopyPost');
     // create new thread
     $thread = ThreadEditor::createFromPosts($this->postIDs, $this->board->boardID);
     // move posts
     PostEditor::copyAll($this->postIDs, $thread->threadID, null, $this->board->boardID);
     PostEditor::unmarkAll();
     // check thread
     $thread->checkVisibility();
     // refresh
     $thread->refresh();
     // set last post
     $this->board->refresh();
     $this->board->setLastPosts();
     self::resetCache();
     HeaderUtil::redirect($this->url);
     exit;
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     // set the language temporarily to the thread language
     if ($this->languageID && $this->languageID != WCF::getLanguage()->getLanguageID()) {
         $this->setLanguage($this->languageID);
     }
     parent::save();
     // search for double posts
     if ($postID = PostEditor::test($this->subject, $this->text, WCF::getUser()->userID, $this->username)) {
         HeaderUtil::redirect('index.php?page=Thread&postID=' . $postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $postID);
         exit;
     }
     // save poll
     if ($this->showPoll) {
         $this->pollEditor->save();
     }
     // save thread in database
     $this->newThread = ThreadEditor::create($this->board->boardID, $this->languageID, $this->prefix, $this->subject, $this->text, WCF::getUser()->userID, $this->username, intval($this->isImportant == 1), intval($this->isImportant == 2), $this->closeThread, $this->getOptions(), $this->subscription, $this->attachmentListEditor, $this->pollEditor, intval($this->disableThread || !$this->board->getPermission('canStartThreadWithoutModeration')));
     if ($this->isImportant == 2) {
         $this->newThread->assignBoards($this->boardIDs);
     }
     // save tags
     if (MODULE_TAGGING && THREAD_ENABLE_TAGS && $this->board->getPermission('canSetTags')) {
         $tagArray = TaggingUtil::splitString($this->tags);
         if (count($tagArray)) {
             $this->newThread->updateTags($tagArray);
         }
     }
     // reset language
     if ($this->userInterfaceLanguageID !== null) {
         $this->setLanguage($this->userInterfaceLanguageID, true);
     }
     if (!$this->disableThread && $this->board->getPermission('canStartThreadWithoutModeration')) {
         // update user posts
         if (WCF::getUser()->userID && $this->board->countUserPosts) {
             require_once WBB_DIR . 'lib/data/user/WBBUser.class.php';
             WBBUser::updateUserPosts(WCF::getUser()->userID, 1);
             if (ACTIVITY_POINTS_PER_THREAD) {
                 require_once WCF_DIR . 'lib/data/user/rank/UserRank.class.php';
                 UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_THREAD);
             }
         }
         // refresh counter and last post
         $this->board->addThreads();
         $this->board->setLastPost($this->newThread);
         // reset stat cache
         WCF::getCache()->clearResource('stat');
         WCF::getCache()->clearResource('boardData');
         // send notifications
         $this->newThread->sendNotification(new Post(null, array('postID' => $this->newThread->firstPostID, 'message' => $this->text, 'enableSmilies' => $this->enableSmilies, 'enableHtml' => $this->enableHtml, 'enableBBCodes' => $this->enableBBCodes)), $this->attachmentListEditor);
         $this->saved();
         // forward to post
         HeaderUtil::redirect('index.php?page=Thread&threadID=' . $this->newThread->threadID . SID_ARG_2ND_NOT_ENCODED);
     } else {
         $this->saved();
         if ($this->disableThread) {
             // forward to post
             HeaderUtil::redirect('index.php?page=Thread&threadID=' . $this->newThread->threadID . SID_ARG_2ND_NOT_ENCODED);
         } else {
             WCF::getTPL()->assign(array('url' => 'index.php?page=Board&boardID=' . $this->boardID . SID_ARG_2ND_NOT_ENCODED, 'message' => WCF::getLanguage()->get('wbb.threadAdd.moderation.redirect'), 'wait' => 5));
             WCF::getTPL()->display('redirect');
         }
     }
     exit;
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     // set the language temporarily to the thread language
     if ($this->thread->languageID && $this->thread->languageID != WCF::getLanguage()->getLanguageID()) {
         $this->setLanguage($this->thread->languageID);
     }
     MessageForm::save();
     if ($this->thread->isDisabled) {
         $this->disablePost = 1;
     }
     // search for double posts
     if ($postID = PostEditor::test($this->subject, $this->text, WCF::getUser()->userID, $this->username, $this->threadID)) {
         HeaderUtil::redirect('index.php?page=Thread&postID=' . $postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $postID);
         exit;
     }
     // save poll
     if ($this->showPoll) {
         $this->pollEditor->save();
     }
     // save post in database
     $this->newPost = PostEditor::create($this->thread->threadID, $this->subject, $this->text, WCF::getUser()->userID, $this->username, $this->getOptions(), $this->attachmentListEditor, $this->pollEditor, null, intval($this->disablePost || !$this->board->getPermission('canReplyThreadWithoutModeration')));
     // reset language
     if ($this->userInterfaceLanguageID !== null) {
         $this->setLanguage($this->userInterfaceLanguageID, true);
     }
     // remove quotes
     $sessionVars = WCF::getSession()->getVars();
     if (isset($sessionVars['quotes'][$this->threadID])) {
         unset($sessionVars['quotes'][$this->threadID]);
         WCF::getSession()->register('quotes', $sessionVars['quotes']);
     }
     if (!$this->disablePost && $this->board->getPermission('canReplyThreadWithoutModeration')) {
         // refresh thread
         $this->thread->addPost($this->newPost, $this->closeThread);
         // update subscription
         $this->thread->setSubscription($this->subscription);
         // update user posts
         if (WCF::getUser()->userID && $this->board->countUserPosts) {
             WBBUser::updateUserPosts(WCF::getUser()->userID, 1);
             if (ACTIVITY_POINTS_PER_POST) {
                 require_once WCF_DIR . 'lib/data/user/rank/UserRank.class.php';
                 UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_POST);
             }
         }
         // refresh counter and last post
         $this->board->addPosts();
         $this->board->setLastPost($this->thread);
         // close / open thread
         if (!$this->thread->isClosed && $this->closeThread) {
             $this->thread->close();
         } else {
             if ($this->thread->isClosed && !$this->closeThread) {
                 $this->thread->open();
             }
         }
         // mark as done
         if ($this->markAsDone == 1) {
             $this->thread->markAsDone();
         } else {
             if (MODULE_THREAD_MARKING_AS_DONE && $this->board->enableMarkingAsDone && $this->thread->isDone && WCF::getUser()->userID && WCF::getUser()->userID == $this->thread->userID) {
                 $this->thread->markAsUndone();
             }
         }
         // reset stat cache
         WCF::getCache()->clearResource('stat');
         WCF::getCache()->clearResource('boardData');
         // send notifications
         $this->newPost->sendNotification($this->thread, $this->board, $this->attachmentListEditor);
         $this->saved();
         // forward to post
         $url = 'index.php?page=Thread&postID=' . $this->newPost->postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $this->newPost->postID;
         HeaderUtil::redirect($url);
     } else {
         $this->saved();
         if ($this->disablePost) {
             HeaderUtil::redirect('index.php?page=Thread&postID=' . $this->newPost->postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $this->newPost->postID);
         } else {
             WCF::getTPL()->assign(array('url' => 'index.php?page=Thread&threadID=' . $this->threadID . SID_ARG_2ND_NOT_ENCODED, 'message' => WCF::getLanguage()->get('wbb.postAdd.moderation.redirect'), 'wait' => 5));
             WCF::getTPL()->display('redirect');
         }
     }
     exit;
 }
 /**
  * Copies all SQL data of the posts with the given posts ids. 
  */
 public static function copyAll($postIDs, $threadID, $threadMapping = null, $boardID = 0, $updateUserStats = true)
 {
     if (empty($postIDs)) {
         return;
     }
     // copy 'post' data
     $postMapping = array();
     $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $post = new PostEditor(null, $row);
         $postMapping[$post->postID] = $post->copy($threadID ? $threadID : $threadMapping[$row['threadID']]);
     }
     // refresh first post ids
     require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
     ThreadEditor::refreshFirstPostIDAll($threadID ? $threadID : implode(',', $threadMapping));
     // update user posts and activity points
     if ($updateUserStats) {
         self::updateUserStats(implode(',', $postMapping), 'copy', $boardID);
     }
     // copy 'post_cache' data
     $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post_cache\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $sql = "INSERT INTO \twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\t(postID, threadID, messageCache)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . ($threadID ? $threadID : $threadMapping[$row['threadID']]) . ",\n\t\t\t\t\t\t'" . escapeString($row['messageCache']) . "')";
         WCF::getDB()->sendQuery($sql);
     }
     // copy 'post_report' data
     $sql = "SELECT \t*\n\t\t\tFROM \twbb" . WBB_N . "_post_report\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $sql = "INSERT INTO \twbb" . WBB_N . "_post_report\n\t\t\t\t\t\t(postID, userID, report, reportTime)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . $row['userID'] . ",\n\t\t\t\t\t\t'" . escapeString($row['report']) . "',\n\t\t\t\t\t\t" . $row['reportTime'] . ")";
         WCF::getDB()->sendQuery($sql);
     }
     // copy polls
     require_once WCF_DIR . 'lib/data/message/poll/PollEditor.class.php';
     $pollMapping = PollEditor::copyAll($postIDs, $postMapping);
     if (is_array($pollMapping)) {
         foreach ($pollMapping as $oldPollID => $newPollID) {
             $sql = "UPDATE\t\twbb" . WBB_N . "_post\n\t\t\t\t\tSET \t\tpollID = " . $newPollID . "\n\t\t\t\t\tWHERE \t\tpollID = " . $oldPollID . "\n\t\t\t\t\t\t\tAND postID NOT IN (SELECT messageID FROM wcf" . WCF_N . "_poll WHERE pollID = " . $oldPollID . ")";
             WCF::getDB()->sendQuery($sql);
         }
     }
     // copy attachments
     require_once WCF_DIR . 'lib/data/message/attachment/AttachmentsEditor.class.php';
     $attachment = new AttachmentsEditor($postIDs);
     $attachmentMapping = $attachment->copyAll($postMapping);
     // update inline attachments
     if (count($attachmentMapping) > 0) {
         $sql = "SELECT\tpostID, message\n\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\tWHERE\tpostID IN (" . implode(',', array_keys($attachmentMapping)) . ")\n\t\t\t\t\tAND message LIKE '%[attach%'";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $messageChanged = false;
             foreach ($attachmentMapping[$row['postID']] as $oldAttachmentID => $newAttachmentID) {
                 $row['message'] = StringUtil::replaceIgnoreCase('[attach=' . $oldAttachmentID . ']', '[attach=' . $newAttachmentID . ']', $row['message']);
                 $row['message'] = StringUtil::replaceIgnoreCase('[attach]' . $oldAttachmentID . '[/attach]', '[attach]' . $newAttachmentID . '[/attach]', $row['message']);
                 $messageChanged = true;
             }
             if ($messageChanged) {
                 // update message
                 $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\t\tSET\tmessage = '" . escapeString($row['message']) . "'\n\t\t\t\t\t\tWHERE\tpostID = " . $row['postID'];
                 WCF::getDB()->sendQuery($sql);
                 // delete post cache
                 $sql = "DELETE FROM\twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\tWHERE\t\tpostID = " . $row['postID'];
                 WCF::getDB()->sendQuery($sql);
             }
         }
     }
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     // build conditions
     $this->conditions = new ConditionBuilder();
     parent::save();
     // boardIDs
     if (count($this->boardIDs)) {
         $this->conditions->add("threadID IN (SELECT threadID FROM wbb" . WBB_N . "_thread WHERE boardID IN (" . implode(',', $this->boardIDs) . "))");
     }
     // time
     if ($this->timeAfterDay && $this->timeAfterMonth && $this->timeAfterYear) {
         $time = @gmmktime(0, 0, 0, $this->timeAfterMonth, $this->timeAfterDay, $this->timeAfterYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("time > " . $time);
         }
     }
     if ($this->timeBeforeDay && $this->timeBeforeMonth && $this->timeBeforeYear) {
         $time = @gmmktime(0, 0, 0, $this->timeBeforeMonth, $this->timeBeforeDay, $this->timeBeforeYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("time < " . $time);
         }
     }
     // username
     if ($this->createdBy != '') {
         $users = preg_split('/\\s*,\\s*/', $this->createdBy, -1, PREG_SPLIT_NO_EMPTY);
         $users = array_map('escapeString', $users);
         $this->conditions->add("username IN ('" . implode("','", $users) . "')");
     }
     // status
     if ($this->deleted) {
         $this->conditions->add("isDeleted = 1");
     }
     if ($this->notDeleted) {
         $this->conditions->add("isDeleted = 0");
     }
     if ($this->disabled) {
         $this->conditions->add("isDisabled = 1");
     }
     if ($this->notDisabled) {
         $this->conditions->add("isDisabled = 0");
     }
     if ($this->closed) {
         $this->conditions->add("isClosed = 1");
     }
     if ($this->open) {
         $this->conditions->add("isClosed = 0");
     }
     // execute action
     $conditions = $this->conditions->get();
     switch ($this->action) {
         case 'delete':
             $postIDs = '';
             $sql = "SELECT\tpostID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\t\t" . $conditions;
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($postIDs)) {
                     $postIDs .= ',';
                 }
                 $postIDs .= $row['postID'];
                 $this->affectedPosts++;
             }
             // get thread ids
             $threadIDs = PostEditor::getThreadIDs($postIDs);
             // delete posts
             PostEditor::deleteAllCompletely($postIDs);
             // check threads
             ThreadEditor::checkVisibilityAll($threadIDs);
             break;
         case 'trash':
         case 'restore':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisDeleted = " . ($this->action == 'trash' ? 1 : 0) . "\n\t\t\t\t\t\t" . ($this->action == 'trash' ? ",deleteTime = " . TIME_NOW . ", deletedBy = '" . escapeString(WCF::getUser()->username) . "', deletedByID = " . WCF::getUser()->userID : '') . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
         case 'disable':
         case 'enable':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisDisabled = " . ($this->action == 'disable' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
         case 'close':
         case 'open':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisClosed = " . ($this->action == 'close' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedPosts', $this->affectedPosts);
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     if (!$this->canEditPost()) {
         throw new PermissionDeniedException();
     }
     // set the language temporarily to the thread language
     if ($this->thread->languageID && $this->thread->languageID != WCF::getLanguage()->getLanguageID()) {
         $this->setLanguage($this->thread->languageID);
     }
     MessageForm::save();
     // update subscription
     $this->thread->setSubscription($this->subscription);
     // save poll
     if ($this->showPoll) {
         $this->pollEditor->save();
     }
     // add edit note
     $postData = array();
     if (!$this->hideEditNote && (WCF::getUser()->userID != $this->post->userID || $this->post->time <= TIME_NOW - POST_EDIT_HIDE_EDIT_NOTE_PERIOD * 60)) {
         $postData['editor'] = WCF::getUser()->username;
         $postData['editorID'] = WCF::getUser()->userID;
         $postData['lastEditTime'] = TIME_NOW;
         $postData['editCount'] = $this->post->editCount + 1;
         $postData['editReason'] = $this->editReason;
     } else {
         if (!empty($this->editReason)) {
             $postData['editReason'] = $this->editReason;
         }
     }
     // update database entry
     $this->post->update($this->subject, $this->text, $this->getOptions(), $this->attachmentListEditor, $this->pollEditor, $postData);
     // reset language
     if ($this->userInterfaceLanguageID !== null) {
         $this->setLanguage($this->userInterfaceLanguageID, true);
     }
     $threadData = array();
     if ($this->thread->firstPostID == $this->post->postID) {
         // update thread topic
         if (!empty($this->subject)) {
             $threadData['topic'] = $this->subject;
         }
         // update thread prefix
         if ($this->board->getPermission('canUsePrefix')) {
             $threadData['prefix'] = $this->prefix;
         }
         // save tags
         if (MODULE_TAGGING && THREAD_ENABLE_TAGS && $this->board->getPermission('canSetTags')) {
             $this->thread->updateTags(TaggingUtil::splitString($this->tags));
         }
         // announcement
         if ($this->board->getModeratorPermission('canStartAnnouncement')) {
             if ($this->thread->isAnnouncement) {
                 $this->thread->removeAssignedBoards();
             }
             if ($this->isImportant == 2) {
                 $this->thread->assignBoards($this->boardIDs);
             }
             $threadData['isAnnouncement'] = intval($this->isImportant == 2);
         }
         // pin thread
         if ($this->board->getModeratorPermission('canPinThread')) {
             $threadData['isSticky'] = intval($this->isImportant == 1);
         }
         // set language
         if ($this->languageID != $this->thread->languageID) {
             $threadData['languageID'] = $this->languageID;
         }
     }
     // close / open thread
     if ($this->board->getModeratorPermission('canCloseThread')) {
         if (!$this->thread->isClosed && $this->closeThread) {
             $threadData['isClosed'] = 1;
         } else {
             if ($this->thread->isClosed && !$this->closeThread) {
                 $threadData['isClosed'] = 0;
             }
         }
     }
     // update thread
     $this->thread->update($threadData);
     // update last posts
     if ($this->thread->firstPostID == $this->post->postID && $this->languageID != $this->thread->languageID) {
         $this->board->setLastPosts();
         WCF::getCache()->clearResource('boardData');
     }
     $this->saved();
     // forward to post
     $url = 'index.php?page=Thread&postID=' . $this->postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $this->postID;
     HeaderUtil::redirect($url);
     exit;
 }