/**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (WCF::getUser()->userID && $eventObj->board->countUserPosts && $eventObj->disablePost) {
         WBBUser::updateUserPosts(WCF::getUser()->userID, 1);
         if (ACTIVITY_POINTS_PER_POST) {
             UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_POST);
         }
     }
 }
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if ($eventObj->action == 'enable') {
         if ($eventObj->post->userID && $eventObj->board->countUserPosts && $eventObj->board->getModeratorPermission('canEnableThread') && !$eventObj->post->everEnabled) {
             WBBUser::updateUserPosts($eventObj->post->userID, -1);
             if (ACTIVITY_POINTS_PER_POST) {
                 UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_POST * -1, $eventObj->post->userID);
             }
         }
     }
 }
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if ($eventObj->action == 'enable') {
         if ($eventObj->thread->userID && $eventObj->board->countUserPosts && $eventObj->board->getModeratorPermission('canEnableThread') && !$eventObj->thread->everEnabled) {
             WBBUser::updateUserPosts($eventObj->thread->userID, -1);
             if (ACTIVITY_POINTS_PER_THREAD) {
                 UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_THREAD * -1, $eventObj->thread->userID);
             }
             $postIDs = explode(',', ThreadEditor::getAllPostIDs((string) $eventObj->thread->threadID));
             foreach ($postIDs as $postID) {
                 $post = new Post($postID);
                 if ($post->postID != $eventObj->thread->firstPostID && !$post->everEnabled) {
                     WBBUser::updateUserPosts($post->userID, -1);
                     if (ACTIVITY_POINTS_PER_POST) {
                         UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_POST * -1, $post->userID);
                     }
                 }
             }
         }
     }
 }
 /**
  * Updates the user stats (user posts, activity points & user rank).
  * 
  * @param	string		$threadIDs		changed threads
  * @param 	string		$mode			(enable|copy|move|delete)
  * @param 	integer		$destinationBoardID
  */
 public static function updateUserStats($threadIDs, $mode, $destinationBoardID = 0)
 {
     if (empty($threadIDs)) {
         return;
     }
     // get destination board
     $destinationBoard = null;
     if ($destinationBoardID) {
         $destinationBoard = Board::getBoard($destinationBoardID);
     }
     if ($mode == 'copy' && !$destinationBoard->countUserPosts) {
         return;
     }
     // update user posts, activity points
     $userPosts = array();
     $userActivityPoints = array();
     $sql = "SELECT\tboardID, userID\n\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\tWHERE\tthreadID IN (" . $threadIDs . ")\n\t\t\t\t" . ($mode != 'enable' ? "AND everEnabled = 1" : '') . "\n\t\t\t\tAND userID <> 0";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $board = Board::getBoard($row['boardID']);
         switch ($mode) {
             case 'enable':
                 if ($board->countUserPosts) {
                     // posts
                     if (!isset($userPosts[$row['userID']])) {
                         $userPosts[$row['userID']] = 0;
                     }
                     $userPosts[$row['userID']]++;
                     // activity points
                     if (!isset($userActivityPoints[$row['userID']])) {
                         $userActivityPoints[$row['userID']] = 0;
                     }
                     $userActivityPoints[$row['userID']] += ACTIVITY_POINTS_PER_THREAD;
                 }
                 break;
             case 'copy':
                 if ($destinationBoard->countUserPosts) {
                     // posts
                     if (!isset($userPosts[$row['userID']])) {
                         $userPosts[$row['userID']] = 0;
                     }
                     $userPosts[$row['userID']]++;
                     // activity points
                     if (!isset($userActivityPoints[$row['userID']])) {
                         $userActivityPoints[$row['userID']] = 0;
                     }
                     $userActivityPoints[$row['userID']] += ACTIVITY_POINTS_PER_THREAD;
                 }
                 break;
             case 'move':
                 if ($board->countUserPosts != $destinationBoard->countUserPosts) {
                     // posts
                     if (!isset($userPosts[$row['userID']])) {
                         $userPosts[$row['userID']] = 0;
                     }
                     $userPosts[$row['userID']] += $board->countUserPosts ? -1 : 1;
                     // activity points
                     if (!isset($userActivityPoints[$row['userID']])) {
                         $userActivityPoints[$row['userID']] = 0;
                     }
                     $userActivityPoints[$row['userID']] += $board->countUserPosts ? ACTIVITY_POINTS_PER_THREAD * -1 : ACTIVITY_POINTS_PER_THREAD;
                 }
                 break;
             case 'delete':
                 if ($board->countUserPosts) {
                     // posts
                     if (!isset($userPosts[$row['userID']])) {
                         $userPosts[$row['userID']] = 0;
                     }
                     $userPosts[$row['userID']]--;
                     // activity points
                     if (!isset($userActivityPoints[$row['userID']])) {
                         $userActivityPoints[$row['userID']] = 0;
                     }
                     $userActivityPoints[$row['userID']] -= ACTIVITY_POINTS_PER_THREAD;
                 }
                 break;
         }
     }
     // save posts
     if (count($userPosts)) {
         require_once WBB_DIR . 'lib/data/user/WBBUser.class.php';
         foreach ($userPosts as $userID => $posts) {
             WBBUser::updateUserPosts($userID, $posts);
         }
     }
     // save activity points
     if (count($userActivityPoints)) {
         require_once WCF_DIR . 'lib/data/user/rank/UserRank.class.php';
         foreach ($userActivityPoints as $userID => $points) {
             UserRank::updateActivityPoints($points, $userID);
         }
     }
 }
 /**
  * @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;
 }