/** * add private conversation message * * @param Object $oMbqEtPcMsg * @param Object $oMbqEtPc */ public function addMbqEtPcMsg($oMbqEtPcMsg, $oMbqEtPc) { $oConversation = $oMbqEtPc->mbqBind['oViewableConversation']->getDecoratedObject(); //ref wcf\form\MessageForm,wcf\form\ConversationMessageAddForm $oMbqEtPcMsg->msgContent->setOriValue(MessageUtil::stripCrap(StringUtil::trim($oMbqEtPcMsg->msgContent->oriValue))); $attachmentObjectType = 'com.woltlab.wcf.conversation.message'; $attachmentObjectID = 0; $tmpHash = StringUtil::getRandomID(); $attachmentParentObjectID = 0; //settings $preParse = $enableSmilies = $enableBBCodes = $showSignature = $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; // get max text length $maxTextLength = WCF::getSession()->getPermission('user.conversation.maxLength'); //!!! use this,is better than 0 //begin validate $allowedBBCodesPermission = 'user.message.allowedBBCodes'; //validateText if (empty($oMbqEtPcMsg->msgContent->oriValue)) { MbqError::alert('', "Need message content.", '', MBQ_ERR_APP); } // check text length if ($maxTextLength != 0 && StringUtil::length($oMbqEtPcMsg->msgContent->oriValue) > $maxTextLength) { MbqError::alert('', "Message content is too long.", '', MBQ_ERR_APP); } if ($enableBBCodes && $allowedBBCodesPermission) { $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($oMbqEtPcMsg->msgContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission)))); if (!empty($disallowedBBCodes)) { MbqError::alert('', "Message content included disallowed bbcodes.", '', MBQ_ERR_APP); } } // search for censored words if (ENABLE_CENSORSHIP) { $result = Censorship::getInstance()->test($oMbqEtPcMsg->msgContent->oriValue); if ($result) { MbqError::alert('', "Found censored words in message content.", '', MBQ_ERR_APP); } } //language $languageID = NULL; //attachment if (MODULE_ATTACHMENT && $attachmentObjectType) { $attachmentHandler = new AttachmentHandler($attachmentObjectType, $attachmentObjectID, $tmpHash, $attachmentParentObjectID); } //save if ($preParse) { // BBCodes are enabled if ($enableBBCodes) { if ($allowedBBCodesPermission) { $oMbqEtPcMsg->msgContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPcMsg->msgContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission))))); } else { $oMbqEtPcMsg->msgContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPcMsg->msgContent->oriValue)); } } else { $oMbqEtPcMsg->msgContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPcMsg->msgContent->oriValue, array())); } } // save message $data = array('conversationID' => $oConversation->conversationID, 'message' => $oMbqEtPcMsg->msgContent->oriValue, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, 'enableBBCodes' => $enableBBCodes, 'enableHtml' => $enableHtml, 'enableSmilies' => $enableSmilies, 'showSignature' => $showSignature); $messageData = array('data' => $data, 'attachmentHandler' => $attachmentHandler); $objectAction = new ConversationMessageAction(array(), 'create', $messageData); $resultValues = $objectAction->executeAction(); if ($resultValues['returnValues']->messageID) { $oMbqEtPcMsg->msgId->setOriValue($resultValues['returnValues']->messageID); } else { MbqError::alert('', "Can not create topic.", '', MBQ_ERR_APP); } return $oMbqEtPcMsg; }
/** * @see \wcf\data\IMessageInlineEditorAction::save() */ public function save() { $data = array('message' => PreParser::getInstance()->parse(MessageUtil::stripCrap($this->parameters['data']['message']), explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes')))); if (!$this->message->getConversation()->isDraft) { $data['lastEditTime'] = TIME_NOW; $data['editCount'] = $this->message->editCount + 1; } // execute update action $action = new ConversationMessageAction(array($this->message), 'update', array('data' => $data)); $action->executeAction(); // load new message $this->message = new ConversationMessage($this->message->messageID); $this->message->getAttachments(); if (MODULE_ATTACHMENT) { $attachmentList = $this->message->getAttachments(true); $count = 0; if ($attachmentList !== null) { // set permisions $attachmentList->setPermissions(array('canDownload' => true, 'canViewPreview' => true)); $count = count($attachmentList); } // update count to reflect number of attachments after edit if ($count != $this->message->attachments) { $messageEditor = new ConversationMessageEditor($this->message); $messageEditor->update(array('attachments' => $count)); } } // load embedded objects MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.conversation.message', array($this->message->messageID)); $data = array('actionName' => 'save', 'message' => $this->message->getFormattedMessage()); if (MODULE_ATTACHMENT) { WCF::getTPL()->assign(array('attachmentList' => $attachmentList, 'objectID' => $this->message->messageID)); $data['attachmentList'] = WCF::getTPL()->fetch('attachments'); } return $data; }
/** * @see \wcf\data\IDeleteAction::delete() */ public function delete() { // deletes messages $messageList = new ConversationMessageList(); $messageList->getConditionBuilder()->add('conversation_message.conversationID IN (?)', array($this->objectIDs)); $messageList->readObjectIDs(); $action = new ConversationMessageAction($messageList->getObjectIDs(), 'delete'); $action->executeAction(); // delete conversations parent::delete(); if (!empty($this->objectIDs)) { // delete notifications UserNotificationHandler::getInstance()->deleteNotifications('conversation', 'com.woltlab.wcf.conversation.notification', array(), $this->objectIDs); // remove modification logs ConversationModificationLogHandler::getInstance()->remove($this->objectIDs); } }
/** * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent() */ public function removeContent(ModerationQueue $queue, $message) { if ($this->isValid($queue->objectID)) { $messageAction = new ConversationMessageAction(array($this->getMessage($queue->objectID)), 'delete'); $messageAction->executeAction(); } }