/**
  * add forum topic
  *
  * @param  $oMbqEtForumTopic
  */
 public function addMbqEtForumTopic($oMbqEtForumTopic)
 {
     $oMbqRdEtForum = MbqMain::$oClk->newObj('MbqRdEtForum');
     $objsMbqEtForum = $oMbqRdEtForum->getObjsMbqEtForum(array($oMbqEtForumTopic->forumId->oriValue), array('case' => 'byForumIds'));
     if ($oMbqEtForum = $objsMbqEtForum[0]) {
         $oBoard = $oMbqEtForum->mbqBind['oDetailedBoardNode']->getBoard();
     } else {
         MbqError::alert('', "Need valid forum.", '', MBQ_ERR_APP);
     }
     //ref wcf\form\MessageForm,wbb\form\ThreadAddForm
     $oMbqEtForumTopic->topicTitle->setOriValue(StringUtil::trim($oMbqEtForumTopic->topicTitle->oriValue));
     $oMbqEtForumTopic->topicContent->setOriValue(MessageUtil::stripCrap(StringUtil::trim($oMbqEtForumTopic->topicContent->oriValue)));
     $attachmentObjectType = 'com.woltlab.wbb.post';
     $attachmentObjectID = 0;
     $tmpHash = $oMbqEtForumTopic->groupId->oriValue ? $oMbqEtForumTopic->groupId->oriValue : StringUtil::getRandomID();
     $attachmentParentObjectID = $oBoard->boardID;
     //settings
     $preParse = $enableSmilies = $enableBBCodes = $showSignature = $subscribeThread = $enableHtml = 0;
     $preParse = 1;
     if (WCF::getSession()->getPermission('user.message.canUseSmilies')) {
         $enableSmilies = 1;
     }
     //if (WCF::getSession()->getPermission('user.message.canUseHtml')) $enableHtml = 1;
     if (WCF::getSession()->getPermission('user.message.canUseBBCodes')) {
         $enableBBCodes = 1;
     }
     $showSignature = 1;
     $subscribeThread = 1;
     $type = Thread::TYPE_DEFAULT;
     // get max text length
     $maxTextLength = WCF::getSession()->getPermission('user.board.maxPostLength');
     $minCharLength = WBB_THREAD_MIN_CHAR_LENGTH;
     $minWordCount = WBB_THREAD_MIN_WORD_COUNT;
     //begin validate
     $allowedBBCodesPermission = 'user.message.allowedBBCodes';
     //validateSubject
     if (empty($oMbqEtForumTopic->topicTitle->oriValue)) {
         MbqError::alert('', "Need topic title.", '', MBQ_ERR_APP);
     }
     if (StringUtil::length($oMbqEtForumTopic->topicTitle->oriValue) > 255) {
         MbqError::alert('', "Topic title is too long.", '', MBQ_ERR_APP);
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtForumTopic->topicTitle->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in topic title.", '', MBQ_ERR_APP);
         }
     }
     //validateText
     if (empty($oMbqEtForumTopic->topicContent->oriValue)) {
         MbqError::alert('', "Need topic content.", '', MBQ_ERR_APP);
     }
     // check text length
     if ($maxTextLength != 0 && StringUtil::length($oMbqEtForumTopic->topicContent->oriValue) > $maxTextLength) {
         MbqError::alert('', "Topic content is too long.", '', MBQ_ERR_APP);
     }
     if ($enableBBCodes && $allowedBBCodesPermission) {
         $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($oMbqEtForumTopic->topicContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission))));
         if (!empty($disallowedBBCodes)) {
             MbqError::alert('', "Topic content included disallowed bbcodes.", '', MBQ_ERR_APP);
         }
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtForumTopic->topicContent->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in topic content.", '', MBQ_ERR_APP);
         }
     }
     if ($minCharLength && StringUtil::length($oMbqEtForumTopic->topicContent->oriValue) < $minCharLength) {
         MbqError::alert('', "Topic content is too short.", '', MBQ_ERR_APP);
     }
     if ($minWordCount && count(explode(' ', $oMbqEtForumTopic->topicContent->oriValue)) < $minWordCount) {
         MbqError::alert('', "Need more words in topic content", '', MBQ_ERR_APP);
     }
     //language
     //$languageID = LanguageFactory::getInstance()->getUserLanguage()->languageID;
     $languageID = NULL;
     //attachment
     if (MODULE_ATTACHMENT && $attachmentObjectType) {
         $attachmentHandler = new AttachmentHandler($attachmentObjectType, $attachmentObjectID, $tmpHash, $attachmentParentObjectID);
     }
     //save
     if ($preParse) {
         // BBCodes are enabled
         if ($enableBBCodes) {
             if ($allowedBBCodesPermission) {
                 $oMbqEtForumTopic->topicContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumTopic->topicContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission)))));
             } else {
                 $oMbqEtForumTopic->topicContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumTopic->topicContent->oriValue));
             }
         } else {
             $oMbqEtForumTopic->topicContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumTopic->topicContent->oriValue, array()));
         }
     }
     // save thread
     $data = array('boardID' => $oMbqEtForumTopic->forumId->oriValue, 'languageID' => $languageID, 'topic' => $oMbqEtForumTopic->topicTitle->oriValue, 'time' => TIME_NOW, 'userID' => MbqMain::$oCurMbqEtUser->userId->oriValue, 'username' => MbqMain::$oCurMbqEtUser->loginName->oriValue, 'hasLabels' => 0);
     $data['isClosed'] = 0;
     if (!$oBoard->getPermission('canStartThreadWithoutModeration')) {
         $data['isDisabled'] = 1;
     }
     $threadData = array('data' => $data, 'board' => $oBoard, 'attachmentHandler' => $attachmentHandler, 'postData' => array('message' => $oMbqEtForumTopic->topicContent->oriValue, 'enableBBCodes' => $enableBBCodes, 'enableHtml' => $enableHtml, 'enableSmilies' => $enableSmilies, 'showSignature' => $showSignature), 'tags' => array(), 'subscribeThread' => $subscribeThread);
     $oThreadAction = new ThreadAction(array(), 'create', $threadData);
     $resultValues = $oThreadAction->executeAction();
     if ($resultValues['returnValues']->threadID) {
         $oMbqEtForumTopic->topicId->setOriValue($resultValues['returnValues']->threadID);
         $oMbqRdEtForumTopic = MbqMain::$oClk->newObj('MbqRdEtForumTopic');
         $oMbqEtForumTopic = $oMbqRdEtForumTopic->initOMbqEtForumTopic($oMbqEtForumTopic->topicId->oriValue, array('case' => 'byTopicId'));
         //for get state
         /* mark forum topic read */
         $this->markForumTopicRead($oMbqEtForumTopic);
     } else {
         MbqError::alert('', "Can not create topic.", '', MBQ_ERR_APP);
     }
 }
 /**
  * modify forum post
  *
  * @param $oMbqEtForumPost
  */
 public function mdfMbqEtForumPost($oMbqEtForumPost, $mbqOpt)
 {
     $oBoard = $oMbqEtForumPost->oMbqEtForumTopic->oMbqEtForum->mbqBind['oDetailedBoardNode']->getBoard();
     $oThread = $oMbqEtForumPost->oMbqEtForumTopic->mbqBind['oViewableThread']->getDecoratedObject();
     $oPost = $oMbqEtForumPost->mbqBind['oViewablePost']->getDecoratedObject();
     //ref wbb\form\PostEditForm,wcf\form\MessageForm,wbb\form\ThreadAddForm
     $oMbqEtForumPost->postTitle->setOriValue(StringUtil::trim($oMbqEtForumPost->postTitle->oriValue));
     $oMbqEtForumPost->postContent->setOriValue(MessageUtil::stripCrap(StringUtil::trim($oMbqEtForumPost->postContent->oriValue)));
     $editReason = '';
     $attachmentObjectType = 'com.woltlab.wbb.post';
     $attachmentObjectID = $oMbqEtForumPost->postId->oriValue;
     if ($oThread->firstPostID == $oMbqEtForumPost->postId->oriValue) {
         $enableMultilingualism = true;
         $isFirstPost = true;
     }
     $tmpHash = StringUtil::getRandomID();
     $attachmentParentObjectID = $oBoard->boardID;
     //$attachmentParentObjectID = 0;
     //settings
     $preParse = $enableSmilies = $enableBBCodes = $showSignature = $subscribeThread = $enableHtml = 0;
     $preParse = 1;
     if (WCF::getSession()->getPermission('user.message.canUseSmilies')) {
         $enableSmilies = 1;
     }
     //if (WCF::getSession()->getPermission('user.message.canUseHtml')) $enableHtml = 1;
     if (WCF::getSession()->getPermission('user.message.canUseBBCodes')) {
         $enableBBCodes = 1;
     }
     $showSignature = 1;
     $subscribeThread = 1;
     $type = Thread::TYPE_DEFAULT;
     if ($oThread->isSticky) {
         $type = Thread::TYPE_STICKY;
     } elseif ($oThread->isAnnouncement) {
         MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . 'Sorry,do not support announcement type.');
     }
     if ($oBoard->getPermission('canHideEditNote')) {
         $hideEditNote = true;
     } else {
         $hideEditNote = false;
     }
     // get max text length
     $maxTextLength = WCF::getSession()->getPermission('user.board.maxPostLength');
     $minCharLength = WBB_POST_MIN_CHAR_LENGTH;
     $minWordCount = WBB_POST_MIN_WORD_COUNT;
     //begin validate
     $allowedBBCodesPermission = 'user.message.allowedBBCodes';
     //validateSubject
     if (StringUtil::length($oMbqEtForumPost->postTitle->oriValue) > 255) {
         MbqError::alert('', "Post title is too long.", '', MBQ_ERR_APP);
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtForumPost->postTitle->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in post title.", '', MBQ_ERR_APP);
         }
     }
     //validateText
     if (empty($oMbqEtForumPost->postContent->oriValue)) {
         MbqError::alert('', "Need post content.", '', MBQ_ERR_APP);
     }
     // check text length
     if ($maxTextLength != 0 && StringUtil::length($oMbqEtForumPost->postContent->oriValue) > $maxTextLength) {
         MbqError::alert('', "Post content is too long.", '', MBQ_ERR_APP);
     }
     if ($enableBBCodes && $allowedBBCodesPermission) {
         $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($oMbqEtForumPost->postContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission))));
         if (!empty($disallowedBBCodes)) {
             MbqError::alert('', "Post content included disallowed bbcodes.", '', MBQ_ERR_APP);
         }
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtForumPost->postContent->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in post content.", '', MBQ_ERR_APP);
         }
     }
     if ($minCharLength && StringUtil::length($oMbqEtForumPost->postContent->oriValue) < $minCharLength) {
         MbqError::alert('', "Post content is too short.", '', MBQ_ERR_APP);
     }
     if ($minWordCount && count(explode(' ', $oMbqEtForumPost->postContent->oriValue)) < $minWordCount) {
         MbqError::alert('', "Need more words in Post content", '', MBQ_ERR_APP);
     }
     //attachment
     if (MODULE_ATTACHMENT && $attachmentObjectType) {
         $attachmentHandler = new AttachmentHandler($attachmentObjectType, $attachmentObjectID, $tmpHash, $attachmentParentObjectID);
     }
     //save
     if ($preParse) {
         // BBCodes are enabled
         if ($enableBBCodes) {
             if ($allowedBBCodesPermission) {
                 $oMbqEtForumPost->postContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumPost->postContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission)))));
             } else {
                 $oMbqEtForumPost->postContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumPost->postContent->oriValue));
             }
         } else {
             $oMbqEtForumPost->postContent->setOriValue(PreParser::getInstance()->parse($oMbqEtForumPost->postContent->oriValue, array()));
         }
     }
     // save post
     $data = array('subject' => $oMbqEtForumPost->postTitle->oriValue, 'message' => $oMbqEtForumPost->postContent->oriValue, 'enableBBCodes' => $enableBBCodes, 'enableHtml' => $enableHtml, 'enableSmilies' => $enableSmilies, 'showSignature' => $showSignature);
     if (!$hideEditNote && (WCF::getUser()->userID != $oPost->userID || $oPost->time <= TIME_NOW - WBB_POST_EDIT_HIDE_EDIT_NOTE_PERIOD * 60)) {
         $data['editCount'] = $oPost->editCount + 1;
         $data['editReason'] = $editReason;
         $data['editor'] = WCF::getUser()->username;
         $data['editorID'] = WCF::getUser()->userID;
         $data['lastEditTime'] = TIME_NOW;
     }
     $oPostAction = new PostAction(array($oPost), 'update', array('attachmentHandler' => $attachmentHandler, 'data' => $data, 'isEdit' => true));
     $oPostAction->executeAction();
     $threadData = array();
     if (isset($isFirstPost) && $isFirstPost) {
         // update title
         if ($oMbqEtForumPost->postTitle->oriValue != $oMbqEtForumPost->oMbqEtForumTopic->topicTitle->oriValue) {
             $threadData['topic'] = $oMbqEtForumPost->postTitle->oriValue;
         }
         // handle thread type
         switch ($type) {
             case Thread::TYPE_DEFAULT:
                 $threadData['isSticky'] = 0;
                 $threadData['isAnnouncement'] = 0;
                 break;
             case Thread::TYPE_STICKY:
                 $threadData['isSticky'] = 1;
                 $threadData['isAnnouncement'] = 0;
                 break;
             case Thread::TYPE_ANNOUNCEMENT:
                 $threadData['isSticky'] = 0;
                 $threadData['isAnnouncement'] = 1;
                 break;
         }
     }
     if (isset($isFirstPost) && $isFirstPost || !empty($threadData)) {
         $threadData = array('data' => $threadData);
         if ($isFirstPost) {
             $threadData['announcementBoardIDs'] = array();
         }
         //!!!
         $threadAction = new ThreadAction(array($oThread), 'update', $threadData);
         $threadAction->executeAction();
     }
     // save subscription
     if (WCF::getUser()->userID) {
         if ($subscribeThread && !$oThread->isSubscribed()) {
             $action = new UserObjectWatchAction(array(), 'subscribe', array('data' => array('objectID' => $oPost->threadID, 'objectType' => 'com.woltlab.wbb.thread'), 'enableNotification' => UserNotificationHandler::getInstance()->getEventSetting('com.woltlab.wbb.post', 'post') !== false ? 1 : 0));
             $action->executeAction();
         } else {
             if (!$subscribeThread && $oThread->isSubscribed()) {
                 $action = new UserObjectWatchAction(array(), 'unsubscribe', array('data' => array('objectID' => $oPost->threadID, 'objectType' => 'com.woltlab.wbb.thread')));
                 $action->executeAction();
             }
         }
     }
     return $oMbqEtForumPost;
 }