/** * Returns the message text, truncated to given character length. * * @param integer $maxLength * @return string */ public function getFormattedExcerpt($maxLength = CMS_NEWS_EXCERPT_LENGTH) { $message = $this->message; // find position of [readmore] tag $position = mb_strpos($this->message, '[readmore]'); if ($position !== false) { $message = mb_substr($message, 0, $position); } // assign embedded objects MessageEmbeddedObjectManager::getInstance()->setActiveMessage('de.incendium.cms.news.entry', $this->entryID); // parse message MessageParser::getInstance()->setOutputType('text/html'); $message = MessageParser::getInstance()->parse($message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes); // truncate message return MessageUtil::truncateFormattedMessage($message, $maxLength); }
/** * @see \wcf\system\option\IOptionHandler::readUserInput() */ public function readUserInput(array &$source) { parent::readUserInput($source); // remove 4 byte utf-8 characters (e.g. emoji) foreach ($this->rawValues as &$value) { if (is_string($value)) { $value = MessageUtil::stripCrap($value); } } if ($this->searchMode) { $this->optionValues = $this->rawValues; } }
/** * Validates parameters for current request. * * @param \wcf\system\message\IMessageQuickReplyAction $object * @param array<array> $parameters * @param string $containerClassName * @param string $containerDecoratorClassName */ public function validateParameters(IMessageQuickReplyAction $object, array &$parameters, $containerClassName, $containerDecoratorClassName = '') { if (!isset($parameters['data']['message'])) { throw new UserInputException('message'); } $parameters['data']['message'] = StringUtil::trim(MessageUtil::stripCrap($parameters['data']['message'])); if (empty($parameters['data']['message'])) { throw new UserInputException('message', WCF::getLanguage()->get('wcf.global.form.error.empty')); } $parameters['lastPostTime'] = isset($parameters['lastPostTime']) ? intval($parameters['lastPostTime']) : 0; if (!$parameters['lastPostTime']) { throw new UserInputException('lastPostTime'); } $parameters['pageNo'] = isset($parameters['pageNo']) ? intval($parameters['pageNo']) : 0; if (!$parameters['pageNo']) { throw new UserInputException('pageNo'); } $parameters['objectID'] = isset($parameters['objectID']) ? intval($parameters['objectID']) : 0; if (!$parameters['objectID']) { throw new UserInputException('objectID'); } $this->container = new $containerClassName($parameters['objectID']); if (!empty($containerDecoratorClassName)) { if (!ClassUtil::isInstanceOf($containerDecoratorClassName, 'wcf\\data\\DatabaseObjectDecorator')) { throw new SystemException("'" . $containerDecoratorClassName . "' does not extend 'wcf\\data\\DatabaseObjectDecorator'"); } $this->container = new $containerDecoratorClassName($this->container); } $object->validateContainer($this->container); // validate message $object->validateMessage($this->container, $parameters['data']['message']); // check for message quote ids $parameters['removeQuoteIDs'] = isset($parameters['removeQuoteIDs']) && is_array($parameters['removeQuoteIDs']) ? ArrayUtil::trim($parameters['removeQuoteIDs']) : array(); // check for tmp hash (attachments) $parameters['tmpHash'] = ''; if (isset($parameters['data']['tmpHash'])) { $parameters['tmpHash'] = StringUtil::trim($parameters['data']['tmpHash']); unset($parameters['data']['tmpHash']); } // message settings $parameters['data'] = array_merge($parameters['data'], MessageFormSettingsHandler::getSettings($parameters)); $parameters['data']['enableHtml'] = 0; $parameters['data']['showSignature'] = WCF::getUser()->userID ? WCF::getUser()->showSignature : 0; EventHandler::getInstance()->fireAction($this, 'validateParameters', $parameters); }
private static function fixBBCodes($message) { // code bbcodes $message = preg_replace('~\\[(php|java|css|html|xml|tpl|js|c)\\]~', '[code=\\1]', $message); $message = preg_replace('~\\[(php|java|css|html|xml|tpl|js|c)=(\\d+)\\]~', '[code=\\1,\\2]', $message); $message = str_replace('[mysql]', '[code=sql]', $message); $message = preg_replace('~\\[mysql=(\\d+)\\]~', '[code=sql,\\1]', $message); $message = preg_replace('~\\[/(?:php|java|css|html|xml|tpl|js|c|mysql)\\]~', '[/code]', $message); // media bbcodes $message = preg_replace("~\\[(?:youtube|myvideo|myspace|googlevideo|clipfish|sevenload)(?:='?([^'\\],]+)'?)?(?:,[^\\]]+)?\\]~", '[media]\\1', $message); $message = preg_replace('~\\[/(?:youtube|myvideo|myspace|googlevideo|clipfish|sevenload)\\]~', '[/media]', $message); // remove crap $message = MessageUtil::stripCrap($message); return $message; }
/** * Saves changes to user profile. * * @return array */ public function save() { $userTitle = null; if (isset($this->parameters['values']['__userTitle'])) { $userTitle = StringUtil::trim(MessageUtil::stripCrap($this->parameters['values']['__userTitle'])); unset($this->parameters['values']['__userTitle']); } $optionHandler = $this->getOptionHandler($this->userProfile->getDecoratedObject()); $optionHandler->readUserInput($this->parameters); $errors = $optionHandler->validate(); // validate user title if ($userTitle !== null) { try { if (mb_strlen($userTitle) > USER_TITLE_MAX_LENGTH) { throw new UserInputException('__userTitle', 'tooLong'); } if (!StringUtil::executeWordFilter($userTitle, USER_FORBIDDEN_TITLES)) { throw new UserInputException('__userTitle', 'forbidden'); } } catch (UserInputException $e) { $errors[$e->getField()] = $e->getType(); } } // validation was successful if (empty($errors)) { $saveOptions = $optionHandler->save(); $data = array('options' => $saveOptions); // save user title if ($userTitle !== null) { $data['data'] = array('userTitle' => $userTitle); } $userAction = new UserAction(array($this->userProfile->userID), 'update', $data); $userAction->executeAction(); // check if the user will be automatically added to new // user groups because of the changed user options UserGroupAssignmentHandler::getInstance()->checkUsers(array($this->userProfile->userID)); // return parsed template $user = new User($this->userProfile->userID); // reload option handler $optionHandler = $this->getOptionHandler($user, false); $options = $optionHandler->getOptionTree(); WCF::getTPL()->assign(array('options' => $options, 'userID' => $this->userProfile->userID)); return array('success' => true, 'template' => WCF::getTPL()->fetch('userProfileAbout')); } else { // validation failed WCF::getTPL()->assign(array('errorType' => $errors, 'optionTree' => $optionHandler->getOptionTree(), '__userTitle' => $userTitle !== null ? $userTitle : $this->userProfile->userTitle)); return array('success' => false, 'template' => WCF::getTPL()->fetch('userProfileAboutEditable')); } }
private static function fixBBCodes($message) { static $sizeRegex = null; static $quoteRegex = null; static $quoteCallback = null; if ($sizeRegex === null) { $quoteRegex = new Regex('\\[quote author=(.*?) link=topic=\\d+\\.msg(\\d+)#msg\\2 date=\\d+\\]'); $quoteCallback = new Callback(function ($matches) { $username = str_replace(array("\\", "'"), array("\\\\", "\\'"), $matches[1]); $postID = $matches[2]; $postLink = LinkHandler::getInstance()->getLink('Thread', array('application' => 'wbb', 'postID' => $postID, 'forceFrontend' => true)) . '#post' . $postID; $postLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $postLink); return "[quote='" . $username . "','" . $postLink . "']"; }); $sizeRegex = new Regex('\\[size=(8|10|12|14|18|24|34)pt\\]'); } // use proper WCF 2 bbcode $message = strtr($message, array('<br />' => "\n", '[iurl]' => '[url]', '[/iurl]' => '[/url]', '[left]' => '[align=left]', '[/left]' => '[/align]', '[right]' => '[align=right]', '[/right]' => '[/align]', '[center]' => '[align=center]', '[/center]' => '[/align]', '[ftp]' => '[url]', '[/ftp]' => '[/url]', '[php]' => '[code=php]', '[/php]' => '[/code]')); // fix size bbcode $message = $sizeRegex->replace($message, '[size=\\1]'); // convert html entities in text $message = StringUtil::decodeHTML($message); // quotes $message = $quoteRegex->replace($message, $quoteCallback); // remove crap $message = MessageUtil::stripCrap($message); return $message; }
/** * @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; }
private static function fixBBCodes($message) { static $mediaRegex = null; static $mediaCallback = null; static $userRegex = null; static $userCallback = null; static $quoteRegex = null; static $quoteCallback = null; if ($mediaRegex === null) { $mediaRegex = new Regex('\\[media=(youtube|vimeo|dailymotion)\\]([a-zA-Z0-9_-]+)', Regex::CASE_INSENSITIVE); $mediaCallback = new Callback(function ($matches) { switch ($matches[1]) { case 'youtube': $url = 'https://www.youtube.com/watch?v=' . $matches[2]; break; case 'vimeo': $url = 'http://vimeo.com/' . $matches[2]; break; case 'dailymotion': $url = 'http://dailymotion.com/video/' . $matches[2]; break; } return '[media]' . $url; }); $userRegex = new Regex('\\[user=(\\d+)\\](.*?)\\[/user\\]', Regex::CASE_INSENSITIVE); $userCallback = new Callback(function ($matches) { $userLink = LinkHandler::getInstance()->getLink('User', array('userID' => $matches[1], 'forceFrontend' => true)); $userLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $userLink); return "[url='" . $userLink . "']" . $matches[2] . "[/url]"; }); $quoteRegex = new Regex('\\[quote=("?)(?P<username>[^,\\]\\n]*)(?:, post: (?P<postID>\\d+)(?:, member: \\d+)?)?\\1\\]', Regex::CASE_INSENSITIVE); $quoteCallback = new Callback(function ($matches) { if (isset($matches['username']) && $matches['username']) { $username = str_replace(array("\\", "'"), array("\\\\", "\\'"), $matches['username']); if (isset($matches['postID']) && $matches['postID']) { $postLink = LinkHandler::getInstance()->getLink('Thread', array('application' => 'wbb', 'postID' => $matches['postID'], 'forceFrontend' => true)) . '#post' . $matches['postID']; $postLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $postLink); return "[quote='" . $username . "','" . $postLink . "']"; } return "[quote='" . $username . "']"; } return "[quote]"; }); } $message = $mediaRegex->replace($message, $mediaCallback); $message = $userRegex->replace($message, $userCallback); $message = $quoteRegex->replace($message, $quoteCallback); // fix size bbcodes $message = preg_replace_callback('/\\[size=\'?(\\d+)\'?\\]/i', function ($matches) { $size = 36; switch ($matches[1]) { case 1: $size = 8; break; case 2: $size = 10; break; case 3: $size = 12; break; case 4: $size = 14; break; case 5: $size = 18; break; case 6: $size = 24; break; } return '[size=' . $size . ']'; }, $message); static $map = array('[php]' => '[code=php]', '[/php]' => '[/code]', '[html]' => '[code=html]', '[/html]' => '[/code]', '[center]' => '[align=center]', '[/center]' => '[/align]', '[right]' => '[align=right]', '[/right]' => '[/align]', '[attach=full]' => '[attach]'); // use proper WCF 2 bbcode $message = str_ireplace(array_keys($map), array_values($map), $message); // remove crap $message = MessageUtil::stripCrap($message); return $message; }
protected static function fixBBCodes($text, $uid) { // fix closing list tags $text = preg_replace('~\\[/list:(u|o)~i', '[/list', $text); // fix closing list element tags $text = preg_replace('~\\[/\\*:m:' . $uid . '\\]~i', '', $text); // remove uid $text = preg_replace('~\\[(/?[^:\\]]+):' . $uid . '~', '[$1', $text); $text = preg_replace('~:' . $uid . '\\]~', ']', $text); // fix size bbcode $text = preg_replace_callback('~(?<=\\[size=)\\d+(?=\\])~', function ($matches) { $wbbSize = 24; if ($matches[0] <= 50) { $wbbSize = 8; } else { if ($matches[0] <= 85) { $wbbSize = 10; } else { if ($matches[0] <= 150) { $wbbSize = 14; } else { if ($matches[0] <= 200) { $wbbSize = 18; } } } } return $wbbSize; }, $text); // see: https://github.com/phpbb/phpbb3/blob/179f41475b555d0a3314d779d0d7423f66f0fb95/phpBB/includes/functions.php#L3767 $text = preg_replace('#<!\\-\\- s(.*?) \\-\\-><img src=".*? \\/><!\\-\\- s\\1 \\-\\->#', '\\1', $text); $text = preg_replace('#<!\\-\\- e \\-\\-><a href="mailto:(.*?)">.*?</a><!\\-\\- e \\-\\->#', '[email]\\1[/email]', $text); $text = preg_replace('#<!\\-\\- ([mw]) \\-\\-><a (?:class="[\\w-]+" )?href="(.*?)">.*?</a><!\\-\\- \\1 \\-\\->#', '[url]\\2[/url]', $text); $text = preg_replace('#<!\\-\\- l \\-\\-><a (?:class="[\\w-]+" )?href="(.*?)(?:(&|\\?)sid=[0-9a-f]{32})?">.*?</a><!\\-\\- l \\-\\->#', '[url]\\1[/url]', $text); // fix code php bbcode... $text = preg_replace_callback('#\\[code(=php)?\\](.*)\\[/code\\]#s', function ($matches) { $content = $matches[2]; $content = str_replace(array('<br />', ' '), array("\n", "\t"), $content); $content = preg_replace('#(?:<span class="syntax[^"]*">|</span>)#', '', $content); return '[code' . $matches[1] . ']' . $content . '[/code]'; }, $text); // convert attachments $text = preg_replace('~\\[attachment=(\\d+)\\]<!-- ia\\1 -->.*?<!-- ia\\1 -->\\[/attachment\\]~', '', $text); // TODO: not supported right now // remove crap $text = MessageUtil::stripCrap($text); return $text; }
/** * add private conversation * * @param Object $oMbqEtPc */ public function addMbqEtPc($oMbqEtPc) { //ref wcf\form\MessageForm,wcf\form\ConversationAddForm $oMbqEtPc->convTitle->setOriValue(StringUtil::trim($oMbqEtPc->convTitle->oriValue)); $oMbqEtPc->convContent->setOriValue(MessageUtil::stripCrap(StringUtil::trim($oMbqEtPc->convContent->oriValue))); $attachmentObjectType = 'com.woltlab.wcf.conversation.message'; $attachmentObjectID = 0; $tmpHash = StringUtil::getRandomID(); $attachmentParentObjectID = 0; // check max pc permission if (ConversationHandler::getInstance()->getConversationCount() >= WCF::getSession()->getPermission('user.conversation.maxConversations')) { MbqError::alert('', 'Sorry.You can not create more conversations.', '', MBQ_ERR_APP); } //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'); //begin validate try { $participantIDs = Conversation::validateParticipants(implode(",", $oMbqEtPc->userNames->oriValue)); } catch (UserInputException $e) { MbqError::alert('', $e->getMessage(), '', MBQ_ERR_APP); } catch (Exception $e) { MbqError::alert('', $e->getMessage(), '', MBQ_ERR_APP); } if (empty($participantIDs)) { MbqError::alert('', 'Need valid participant user ids.', '', MBQ_ERR_APP); } // check number of participants if (count($participantIDs) > WCF::getSession()->getPermission('user.conversation.maxParticipants')) { MbqError::alert('', 'Too many participants.', '', MBQ_ERR_APP); } $allowedBBCodesPermission = 'user.message.allowedBBCodes'; //validateSubject if (empty($oMbqEtPc->convTitle->oriValue)) { MbqError::alert('', "Need conversation title.", '', MBQ_ERR_APP); } if (StringUtil::length($oMbqEtPc->convTitle->oriValue) > 255) { MbqError::alert('', "Conversation title is too long.", '', MBQ_ERR_APP); } // search for censored words if (ENABLE_CENSORSHIP) { $result = Censorship::getInstance()->test($oMbqEtPc->convTitle->oriValue); if ($result) { MbqError::alert('', "Found censored words in conversation title.", '', MBQ_ERR_APP); } } //validateText if (empty($oMbqEtPc->convContent->oriValue)) { MbqError::alert('', "Need conversation content.", '', MBQ_ERR_APP); } // check text length if ($maxTextLength != 0 && StringUtil::length($oMbqEtPc->convContent->oriValue) > $maxTextLength) { MbqError::alert('', "Conversation content is too long.", '', MBQ_ERR_APP); } if ($enableBBCodes && $allowedBBCodesPermission) { $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($oMbqEtPc->convContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission)))); if (!empty($disallowedBBCodes)) { MbqError::alert('', "Conversation content included disallowed bbcodes.", '', MBQ_ERR_APP); } } // search for censored words if (ENABLE_CENSORSHIP) { $result = Censorship::getInstance()->test($oMbqEtPc->convContent->oriValue); if ($result) { MbqError::alert('', "Found censored words in conversation 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) { $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission))))); } else { $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue)); } } else { $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue, array())); } } // save conversation $data = array('subject' => $oMbqEtPc->convTitle->oriValue, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, 'isDraft' => 0, 'participantCanInvite' => 0); $conversationData = array('data' => $data, 'attachmentHandler' => $attachmentHandler, 'messageData' => array('message' => $oMbqEtPc->convContent->oriValue, 'enableBBCodes' => $enableBBCodes, 'enableHtml' => $enableHtml, 'enableSmilies' => $enableSmilies, 'showSignature' => $showSignature)); $conversationData['participants'] = $participantIDs; $conversationData['invisibleParticipants'] = array(); $objectAction = new ConversationAction(array(), 'create', $conversationData); $resultValues = $objectAction->executeAction(); if ($resultValues['returnValues']->conversationID) { $convId = $resultValues['returnValues']->conversationID; $messageId = $resultValues['returnValues']->messageID; $oMbqRdEtPc = MbqMain::$oClk->newObj('MbqRdEtPc'); $oMbqEtPc = $oMbqRdEtPc->initOMbqEtPc($convId, array('case' => 'byConvId')); } else { MbqError::alert('', "Can not create topic.", '', MBQ_ERR_APP); } return $oMbqEtPc; }
/** * 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; }
private static function fixBBCodes($message) { static $quoteRegex = null; static $quoteCallback = null; static $imgRegex = null; static $mediaRegex = null; if ($quoteRegex === null) { $quoteRegex = new Regex('\\[quote=(.*?);n(\\d+)\\]', Regex::CASE_INSENSITIVE); $quoteCallback = new Callback(function ($matches) { $username = str_replace(array("\\", "'"), array("\\\\", "\\'"), $matches[1]); $postID = $matches[2]; $postLink = LinkHandler::getInstance()->getLink('Thread', array('application' => 'wbb', 'postID' => $postID, 'forceFrontend' => true)) . '#post' . $postID; $postLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $postLink); return "[quote='" . $username . "','" . $postLink . "']"; }); $imgRegex = new Regex('\\[img width=(\\d+) height=\\d+\\](.*?)\\[/img\\]'); $mediaRegex = new Regex('\\[video=([a-z]+);([a-z0-9-_]+)\\]', Regex::CASE_INSENSITIVE); } // use proper WCF 2 bbcode $replacements = array('[left]' => '[align=left]', '[/left]' => '[/align]', '[right]' => '[align=right]', '[/right]' => '[/align]', '[center]' => '[align=center]', '[/center]' => '[/align]', '[php]' => '[code=php]', '[/php]' => '[/code]', '[html]' => '[code=html]', '[/html]' => '[/code]', '[/video]' => '[/media]'); $message = str_ireplace(array_keys($replacements), array_values($replacements), $message); // quotes $message = $quoteRegex->replace($message, $quoteCallback); // img $message = $imgRegex->replace($message, "[img='\\2',none,\\1][/img]"); // fix size bbcodes $message = preg_replace_callback('/\\[size=\'?(\\d+)\'?\\]/i', function ($matches) { $size = 36; switch ($matches[1]) { case 1: $size = 8; break; case 2: $size = 10; break; case 3: $size = 12; break; case 4: $size = 14; break; case 5: $size = 18; break; case 6: $size = 24; break; } return '[size=' . $size . ']'; }, $message); // media $message = $mediaRegex->replace($message, '[media]'); $message = MessageUtil::stripCrap($message); return $message; }
/** * @see \wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['subject'])) { $this->subject = StringUtil::trim(MessageUtil::stripCrap($_POST['subject'])); } if (isset($_POST['text'])) { $this->text = StringUtil::trim(MessageUtil::stripCrap($_POST['text'])); } // settings $this->enableSmilies = $this->enableHtml = $this->enableBBCodes = $this->preParse = $this->showSignature = 0; if (isset($_POST['preParse'])) { $this->preParse = intval($_POST['preParse']); } if (isset($_POST['enableSmilies']) && WCF::getSession()->getPermission($this->permissionCanUseSmilies)) { $this->enableSmilies = intval($_POST['enableSmilies']); } if (isset($_POST['enableHtml']) && WCF::getSession()->getPermission($this->permissionCanUseHtml)) { $this->enableHtml = intval($_POST['enableHtml']); } if (isset($_POST['enableBBCodes']) && WCF::getSession()->getPermission($this->permissionCanUseBBCodes)) { $this->enableBBCodes = intval($_POST['enableBBCodes']); } if (isset($_POST['showSignature'])) { $this->showSignature = intval($_POST['showSignature']); } // multilingualism if (isset($_POST['languageID'])) { $this->languageID = intval($_POST['languageID']); } }
private static function fixBBCodes($text) { $text = str_ireplace('[center]', '[align=center]', $text); $text = str_ireplace('[/center]', '[/align]', $text); // remove crap $text = MessageUtil::stripCrap($text); return $text; }
private static function fixBBCodes($message) { static $videoRegex = null; static $quoteRegex = null; static $quoteCallback = null; static $imgRegex = null; static $imgCallback = null; static $attachmentRegex = null; if ($videoRegex === null) { $videoRegex = new Regex('\\[video=[a-z]+\\]'); $quoteRegex = new Regex('\\[quote=\'(.*?)\' pid=\'(\\d+)\' dateline=\'\\d+\'\\]'); $quoteCallback = new Callback(function ($matches) { $username = str_replace(array("\\", "'"), array("\\\\", "\\'"), $matches[1]); $postID = $matches[2]; $postLink = LinkHandler::getInstance()->getLink('Thread', array('application' => 'wbb', 'postID' => $postID, 'forceFrontend' => true)) . '#post' . $postID; $postLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $postLink); return "[quote='" . $username . "','" . $postLink . "']"; }); $imgRegex = new Regex('\\[img(?:=(\\d)x\\d)?(?: align=(left|right))?\\](?:\\r\\n?|\\n?)(https?://(?:[^<>"\']+?))\\[/img\\]'); $imgCallback = new Callback(function ($matches) { $escapedLink = str_replace(array("\\", "'"), array("\\\\", "\\'"), $matches[3]); if ($matches[1] && $matches[2]) { return "[img='" . $escapedLink . "'," . $matches[2] . "," . $matches[1] . "][/img]"; } else { if ($matches[1]) { return "[img='" . $escapedLink . "',none," . $matches[1] . "][/img]"; } else { if ($matches[2]) { return "[img='" . $escapedLink . "'," . $matches[2] . "][/img]"; } else { return "[img]" . $matches[3] . "[/img]"; } } } }); $attachmentRegex = new Regex('\\[attachment=([0-9]+)\\]'); } // fix size bbcodes $message = preg_replace_callback('/\\[size=((?:xx?-)?(?:small|large)|medium)\\]/i', function ($matches) { $size = 12; switch ($matches[1]) { case 'xx-small': $size = 8; break; case 'x-small': $size = 10; break; case 'small': $size = 12; break; case 'medium': $size = 14; break; case 'large': $size = 18; break; case 'x-large': $size = 24; break; case 'xx-large': $size = 36; break; } return '[size=' . $size . ']'; }, $message); // attachment bbcodes $message = $attachmentRegex->replace($message, '[attach=\\1][/attach]'); // img bbcodes $message = $imgRegex->replace($message, $imgCallback); // code bbcodes $message = str_replace('[php]', '[code=php]', $message); // media bbcodes $message = $videoRegex->replace($message, '[media]\\1'); $message = str_replace('[/video]', '[/media]', $message); // quotes $message = $quoteRegex->replace($message, $quoteCallback); // remove crap $message = MessageUtil::stripCrap($message); return $message; }
/** * 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); } }
/** * 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; }
/** * Validates message parameter. */ protected function validateMessage() { $this->readString('message', false, 'data'); $this->parameters['data']['message'] = MessageUtil::stripCrap($this->parameters['data']['message']); if (empty($this->parameters['data']['message'])) { throw new UserInputException('message'); } CommentHandler::enforceCensorship($this->parameters['data']['message']); }