/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { $src = ''; if (isset($openingTag['attributes'][0])) { $src = $openingTag['attributes'][0]; } if ($parser->getOutputType() == 'text/html') { $float = ''; if (isset($openingTag['attributes'][1])) { $float = $openingTag['attributes'][1]; } $style = ''; if ($float == 'left' || $float == 'right') { $style = 'float: ' . $float . '; margin: ' . ($float == 'left' ? '0 15px 7px 0' : '0 0 7px 15px') . ';'; } $width = 0; if (isset($openingTag['attributes'][2])) { $width = $openingTag['attributes'][2]; $style .= 'width: ' . $width . 'px;'; } return '<img src="' . $src . '" class="jsResizeImage" alt=""' . ($style ? ' style="' . $style . '"' : '') . ' />'; } else { if ($parser->getOutputType() == 'text/simplified-html') { $src = StringUtil::decodeHTML($src); $path = parse_url($src, PHP_URL_PATH); if ($path !== false) { return StringUtil::encodeHTML(basename($path)); } return ''; } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { if ($parser->getOutputType() == 'text/html') { $quoteLink = !empty($openingTag['attributes'][1]) ? $openingTag['attributes'][1] : ''; $externalQuoteLink = !empty($openingTag['attributes'][1]) ? !ApplicationHandler::getInstance()->isInternalURL($openingTag['attributes'][1]) : false; if (!$externalQuoteLink) { $quoteLink = preg_replace('~^https?://~', RouteHandler::getProtocol(), $quoteLink); } $quoteAuthor = !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : ''; $quoteAuthorObject = null; if ($quoteAuthor && !$externalQuoteLink) { $quoteAuthorLC = mb_strtolower(StringUtil::decodeHTML($quoteAuthor)); foreach (MessageEmbeddedObjectManager::getInstance()->getObjects('com.woltlab.wcf.quote') as $user) { if (mb_strtolower($user->username) == $quoteAuthorLC) { $quoteAuthorObject = $user; break; } } } WCF::getTPL()->assign(array('content' => $content, 'quoteLink' => $quoteLink, 'quoteAuthor' => $quoteAuthor, 'quoteAuthorObject' => $quoteAuthorObject, 'isExternalQuoteLink' => $externalQuoteLink)); return WCF::getTPL()->fetch('quoteBBCodeTag'); } else { if ($parser->getOutputType() == 'text/simplified-html') { return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.quote.text', array('content' => $content, 'cite' => !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '')) . "\n"; } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { if (mb_strpos($content, '[*]') !== false) { // get list elements $listElements = preg_split('/\\[\\*\\]/', StringUtil::trim($content), -1, PREG_SPLIT_NO_EMPTY); // remove empty elements foreach ($listElements as $key => $val) { $listElements[$key] = StringUtil::trim($val); if (empty($listElements[$key]) || $listElements[$key] == '<br />') { unset($listElements[$key]); } } if (!empty($listElements)) { // get list style type $listType = 'disc'; if (isset($openingTag['attributes'][0])) { $listType = $openingTag['attributes'][0]; } $listType = strtolower($listType); // replace old types if ($listType == '1') { $listType = 'decimal'; } if ($listType == 'a') { $listType = 'lower-latin'; } if ($parser->getOutputType() == 'text/html') { // build list html $listHTML = 'ol'; if ($listType == 'none' || $listType == 'circle' || $listType == 'square' || $listType == 'disc') { $listHTML = 'ul'; } return '<' . $listHTML . ' style="list-style-type: ' . $listType . '" class="nativeList"><li>' . implode('</li><li>', $listElements) . '</li></' . $listHTML . '>'; } else { if ($parser->getOutputType() == 'text/simplified-html') { $result = ''; $i = 1; foreach ($listElements as $listElement) { switch ($listType) { case 'decimal': $result .= $i . '. '; break; default: $result .= '- '; } $result .= $listElement . "\n"; $i++; } return $result; } } } } // no valid list // return bbcode as text return $openingTag['source'] . $content . $closingTag['source']; }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // copyright TeraliosBBCodesCopyright::callCopyright(); $content = StringUtil::trim($content); if (!empty($content) || mb_strpos($content, '[.]') !== false && mb_strpos($content, '[:]') !== false) { $content = str_replace('[.]', '[*]', $content); // build main list elements $listElements = preg_split('#\\[\\*\\]#', $content, -1, PREG_SPLIT_NO_EMPTY); foreach ($listElements as $key => $val) { $val = StringUtil::trim($val); if (empty($val) || $val == '<br />') { unset($listElements[$key]); } else { $listElements[$key] = $val; } } // build list if (!empty($listElements)) { $listContent = ''; foreach ($listElements as $point) { if (mb_substr_count($point, '[:]') == 1) { // reset key and value. $key = $value = ''; // split list element on [:] in key and definition of key. list($key, $value) = preg_split('#\\[:\\]#', $point, -1); $key = StringUtil::trim($key); $value = StringUtil::trim($value); if (empty($value)) { $value = WCF::getLanguage()->get('wcf.bbcode.dlist.noDefinition'); } // key is not empty. if (!empty($key)) { if ($parser->getOutputType() == 'text/html') { $listContent .= '<dt>' . $key . '</dt><dd>' . $value . '</dd>'; } else { if ($parser->getOutputType() == 'text/simplified-html') { $listContent .= '*' . $key . ': ' . $value . "\n"; } } } } } if (!empty($listContent)) { if ($parser->getOutputType() == 'text/html') { return '<dl class="dlistBBCode">' . $listContent . '</dl><span></span>'; } else { if ($parser->getOutputType() == 'text/simplified-html') { return $listContent; } } } } } return '[dlist]' . $content . '[/dlist]'; }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { if ($parser->getOutputType() == 'text/html') { WCF::getTPL()->assign(array('content' => $content, 'buttonTitle' => !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '')); return WCF::getTPL()->fetch('spoilerBBCodeTag'); } if ($parser->getOutputType() == 'text/simplified-html') { return WCF::getLanguage()->get('wcf.bbcode.spoiler.text'); } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // copyright TeraliosBBCodesCopyright::callCopyright(); $tag = mb_strtolower($openingTag['name']); // heading and subheading tag html. if ($parser->getOutputType() == 'text/html') { // map attributes $this->mapAttributes($openingTag); // assign attributes $anchor = $this->anchor; $noIndex = $this->noIndex; // check anchor and set automark if (BBCODES_HEADLINE_AUTOMARK == 1 && empty($anchor)) { $anchor = substr(md5($content), 0, 10); } else { if (empty($anchor)) { $anchor = ''; } } // check anchor if (!empty($anchor)) { $anchor = sprintf(static::$anchorPrefix, static::anchorExists($anchor, $anchor)); if ($noIndex != true) { $anchor = Directory::getInstance()->addEntry($anchor, StringUtil::decodeHTML($content), $tag == 'h1' ? true : false); } else { $anchor = new Entry($anchor, StringUtil::decodeHTML($content)); } } // assign to template WCF::getTPL()->assign(array('hsTag' => $tag, 'hsEntry' => $anchor, 'hsHeading' => $content, 'hsLinkTitle' => StringUtil::stripHTML($content))); return WCF::getTPL()->fetch('headingBBCode'); } else { if ($parser->getOutputType('text/simplified-html')) { switch ($tag) { case 'h1': $return = '--- ' . $content . ' ---<br />'; break; default: $return = '-- ' . $content . ' --<br />'; break; } return $return; } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { $content = StringUtil::trim($content); if ($parser->getOutputType() == 'text/html') { foreach (BBCodeMediaProvider::getCache() as $provider) { if ($provider->matches($content)) { return $provider->getOutput($content); } } } if ($parser->getOutputType() == 'text/simplified-html') { foreach (BBCodeMediaProvider::getCache() as $provider) { if ($provider->matches($content)) { return StringUtil::getAnchorTag($content); } } } return StringUtil::encodeHTML($content); }
/** * @see \wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { parent::validate($option, $newValue); if ($option->allowedbbcodepermission) { $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($newValue, explode(',', ArrayUtil::trim(WCF::getSession()->getPermission($option->allowedbbcodepermission)))); if (!empty($disallowedBBCodes)) { WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes); throw new UserInputException($option->optionName, 'disallowedBBCodes'); } } }
/** * Validates parameters for signature preview. */ public function validateGetMessagePreview() { $this->readString('message', true, 'data'); if (!isset($this->parameters['options'])) { throw new UserInputException('options'); } if (isset($this->parameters['options']['enableBBCodes']) && WCF::getSession()->getPermission('user.signature.canUseBBCodes')) { $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($this->parameters['data']['message'], explode(',', WCF::getSession()->getPermission('user.signature.allowedBBCodes'))); if (!empty($disallowedBBCodes)) { throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', array('disallowedBBCodes' => $disallowedBBCodes))); } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { //copyright TeraliosBBCodesCopyright::callCopyright(); // map attributes $this->mapAttributes($openingTag); // assign vattributes $title = $this->title; $position = $this->position; $size = $this->size; // size settings. if ($size <= 0 && ($position == 'left' || $position == 'right')) { $size = 2; } else { if ($size >= 4) { $size = 0; $position = 'none'; } } // parse box with out HTML if ($parser->getOutputType() == 'text/simplified-html') { if (!empty($title)) { $return = '<br />----( ' . $title . ' )----<br />'; } else { $return = '<br />--------<br />'; } $return .= $content; $return .= '<br />--------<br />'; return $return; } else { if ($parser->getOutputType() == 'text/html') { WCF::getTPL()->assign(array('boxTitle' => $title, 'boxPosition' => $position, 'boxSize' => $size, 'boxContent' => $content)); return WCF::getTPL()->fetch('contentBoxBBCode', 'wcf'); } } }
/** * Parses a temporary message and loads found embedded objects. * * @param string $message */ public function parseTemporaryMessage($message) { // remove [code] tags $message = BBCodeParser::getInstance()->removeCodeTags($message); // set active message information $this->activeMessageObjectTypeID = -1; $this->activeMessageID = -1; // get embedded objects foreach ($this->getEmbeddedObjectHandlers() as $handler) { $objectIDs = $handler->parseMessage($message); if (!empty($objectIDs)) { // save assignments $this->messageEmbeddedObjects[$this->activeMessageObjectTypeID][$this->activeMessageID][$handler->objectTypeID] = $objectIDs; // loads objects $this->embeddedObjects[$handler->objectTypeID] = $handler->loadObjects($objectIDs); } } }
/** * @see \wcf\data\IMessageQuickReplyAction::validateMessage() */ public function validateMessage(DatabaseObject $container, $message) { if (mb_strlen($message) > WCF::getSession()->getPermission('user.conversation.maxLength')) { throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', array('maxTextLength' => WCF::getSession()->getPermission('user.conversation.maxLength')))); } // search for disallowed bbcodes $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($message, explode(',', WCF::getSession()->getPermission('user.message.allowedBBCodes'))); if (!empty($disallowedBBCodes)) { throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', array('disallowedBBCodes' => $disallowedBBCodes))); } // search for censored words if (ENABLE_CENSORSHIP) { $result = Censorship::getInstance()->test($message); if ($result) { throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', array('censoredWords' => $result))); } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // encode html $content = self::trim($content); // get attributes $this->mapAttributes($openingTag); // fetch highlighter-classname $className = '\\wcf\\system\\bbcode\\highlighter\\PlainHighlighter'; // no highlighting for strings over a certain size, to prevent DoS // this serves as a safety net in case one of the regular expressions // in a highlighter causes PCRE to exhaust resources, such as the stack if (strlen($content) < 16384) { if ($this->codeType) { $className = '\\wcf\\system\\bbcode\\highlighter\\' . StringUtil::firstCharToUpperCase(mb_strtolower($this->codeType)) . 'Highlighter'; switch (mb_substr($className, strlen('\\wcf\\system\\bbcode\\highlighter\\'))) { case 'ShellHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\BashHighlighter'; break; case 'C++Highlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\CHighlighter'; break; case 'JavascriptHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\JsHighlighter'; break; case 'LatexHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\TexHighlighter'; break; } } else { // try to guess highlighter if (mb_strpos($content, '<?php') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\PhpHighlighter'; } else { if (mb_strpos($content, '<html') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\HtmlHighlighter'; } else { if (mb_strpos($content, '<?xml') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\XmlHighlighter'; } else { if (mb_strpos($content, 'SELECT') === 0 || mb_strpos($content, 'UPDATE') === 0 || mb_strpos($content, 'INSERT') === 0 || mb_strpos($content, 'DELETE') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\SqlHighlighter'; } else { if (mb_strpos($content, 'import java.') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\JavaHighlighter'; } else { if (mb_strpos($content, "---") !== false && mb_strpos($content, "\n+++") !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\DiffHighlighter'; } else { if (mb_strpos($content, "\n#include ") !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\CHighlighter'; } else { if (mb_strpos($content, '#!/usr/bin/perl') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\PerlHighlighter'; } else { if (mb_strpos($content, 'def __init__(self') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\PythonHighlighter'; } else { if (Regex::compile('^#!/bin/(ba|z)?sh')->match($content)) { $className = '\\wcf\\system\\bbcode\\highlighter\\BashHighlighter'; } else { if (mb_strpos($content, '\\documentclass') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\TexHighlighter'; } else { if (Regex::compile('[-\\+\\.,\\[\\]\\>\\<]{9}')->match($content)) { // 9 times a brainfuck char in a row -> seems to be brainfuck $className = '\\wcf\\system\\bbcode\\highlighter\\BrainfuckHighlighter'; } } } } } } } } } } } } } } if (!class_exists($className)) { $className = '\\wcf\\system\\bbcode\\highlighter\\PlainHighlighter'; } if ($parser->getOutputType() == 'text/html') { $highlightedContent = self::fixMarkup(explode("\n", $className::getInstance()->highlight($content))); // show template WCF::getTPL()->assign(array('lineNumbers' => self::makeLineNumbers($content, $this->startLineNumber), 'startLineNumber' => $this->startLineNumber, 'content' => $highlightedContent, 'highlighter' => $className::getInstance(), 'filename' => $this->filename, 'lines' => substr_count($content, "\n") + 1)); return WCF::getTPL()->fetch('codeBBCodeTag'); } else { if ($parser->getOutputType() == 'text/simplified-html') { return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.code.text', array('highlighterTitle' => $className::getInstance()->getTitle(), 'lines' => substr_count($content, "\n") + 1)); } } }
/** * 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\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // copyright counter. TeraliosBBCodesCopyright::callCopyright(); TeraliosUtil::easterEgg(16); // map attributes $this->mapAttributes($openingTag); // assign values $title = $this->title; $position = $this->position; $points = array(); // build array $content = str_replace('[.]', '[*]', $content); if (preg_match(self::SPLIT_PATTERN, $content)) { // split on [+] [-] or [*] $elements = array(); $elements = preg_split(self::SPLIT_PATTERN, $content, -1, PREG_SPLIT_DELIM_CAPTURE); // remove first element. unset($elements[0]); // build array for points. if (!empty($elements)) { $i = 1; $count = count($elements); while ($i < $count) { $sign = $elements[$i]; $value = StringUtil::trim($elements[$i + 1]); // check value, when is not empty, add. if (!empty($value) && $value != '<br />') { if (!isset($points[$sign])) { $points[$sign] = array(); } $points[$sign][] = $value; } // current index + 2 $i = $i + 2; } } } // output if (empty($points)) { return '[procontra]' . $content . '[/procontra]'; } else { if ($parser->getOutputType() == 'text/html') { // assign variables WCF::getTPL()->assign(array('pcTitle' => $title, 'pcPoints' => $points, 'pcPosition' => $position)); return WCF::getTPL()->fetch('proContraBBCodeTag'); } else { if ($parser->getOutputType() == 'text/simplified-html') { // no supports simplified html. $return = $title . '<br />'; $return .= str_repeat('-', mb_strlen($title)) . '<br />'; foreach ($points as $sign => $values) { $length = count($values); if ($length > 0) { $length--; for ($i = 0; $i <= $length; $i++) { $return .= $sign . ' ' . $values[$i] . '<br />'; } } } return $return; } } } }
/** * @see \wcf\system\bbcode\BBCodeParser::isValidTagAttribute() */ protected function isValidTagAttribute(array $tagAttributes, BBCodeAttribute $definedTagAttribute) { if (!parent::isValidTagAttribute($tagAttributes, $definedTagAttribute)) { return false; } // check for cached codes if (isset($tagAttributes[$definedTagAttribute->attributeNo]) && preg_match('/@@[a-f0-9]{40}@@/', $tagAttributes[$definedTagAttribute->attributeNo])) { return false; } return true; }
/** * 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; }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { if ($parser->getOutputType() == 'text/html') { $parsedContent = Regex::compile('(?:\\s|<br />)*(\\[tr\\].*\\[/tr\\])(?:\\s|<br />)*', Regex::CASE_INSENSITIVE | Regex::DOT_ALL)->replace($content, '\\1'); // check syntax $regex = new Regex('\\[/?t[rd]\\]', Regex::CASE_INSENSITIVE); if ($regex->match($parsedContent, true)) { $matches = $regex->getMatches(); $openTags = array(); $openTDs = 0; $firstRowTDs = 0; // parse tags foreach ($matches[0] as $match) { switch ($match) { case '[td]': if (end($openTags) !== '[tr]') { return; } $openTags[] = $match; $openTDs++; break; case '[/td]': if (end($openTags) !== '[td]') { return; } array_pop($openTags); break; case '[tr]': if (!empty($openTags)) { return; } $openTags[] = $match; break; case '[/tr]': if (end($openTags) !== '[tr]') { return; } array_pop($openTags); // check that every row has got the same number of tds if ($firstRowTDs === 0) { $firstRowTDs = $openTDs; } if ($openTDs !== $firstRowTDs) { return; } $openTDs = 0; break; } } if (!empty($openTags)) { return; } } else { return ''; } // tr $parsedContent = Regex::compile('\\[tr\\](?:\\s|<br />)*', Regex::CASE_INSENSITIVE)->replace($parsedContent, '<tr>'); // td $parsedContent = str_ireplace('[td]', '<td>', $parsedContent); // /td $parsedContent = Regex::compile('\\[/td\\](?:\\s|<br />)*', Regex::CASE_INSENSITIVE)->replace($parsedContent, '</td>'); // /tr $parsedContent = Regex::compile('\\[/tr\\](?:\\s|<br />)*', Regex::CASE_INSENSITIVE)->replace($parsedContent, '</tr>'); return '<div class="container bbcodeTable"><table class="table responsiveTable"><tbody>' . $parsedContent . '</tbody></table></div>'; } else { if ($parser->getOutputType() == 'text/simplified-html') { // remove table tags $content = str_ireplace('[td]', '* ', $content); $content = str_ireplace('[/td]', ' ', $content); $content = str_ireplace('[tr]', '', $content); $content = str_ireplace('[/tr]', '', $content); return $content; } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // call copyright TeraliosBBCodesCopyright::callCopyright(); // default values $attachmentID = 0; $float = 'none'; $type = 'default'; $link = ''; $text = ''; $isImage = false; // parameter values $attachmentID = isset($openingTag['attributes'][0]) ? intval($openingTag['attributes'][0]) : 0; $float = isset($openingTag['attributes'][1]) ? mb_strtolower($openingTag['attributes'][1]) : 'none'; switch ($float) { case 'left': case 'right': case 'none': break; default: $float = 'none'; } $text = StringUtil::trim($content); $title = WCF::getLanguage()->getDynamicVariable('wcf.bbcode.xattach.title', array('xaID' => $attachmentID)); // get attachment $attachment = MessageEmbeddedObjectManager::getInstance()->getObject('de.teralios.bbcodes.attachment', $attachmentID); if ($attachment === null) { if (static::$attachmentList !== null) { $attachments = static::$attachmentList->getGroupedObjects(static::$objectID); if (isset($attachments[$attachmentID])) { $attachment = $attachments[$attachmentID]; $attachment->markAsEmbedded(); } } } // Attachment if ($attachment !== null) { $title = !empty($attachment->filename) ? WCF::getLanguage()->getDynamicVariable('wcf.bbcode.xattach.title.full', array('xaFilename' => $attachment->filename, 'xaDownloads' => $attachment->downloads)) : $title; $linkParameters = array('object' => $attachment); // can view image if ($attachment->showAsImage() && $attachment->canViewPreview()) { if ($attachment->hasThumbnail()) { $linkParameters['thumbnail'] = 1; } $isImage = true; $link = '<img src="' . StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', $linkParameters)) . '"' . (!$attachment->hasThumbnail() ? ' class="embeddedAttachmentLink jsResizeImage"' : '') . ' style="width: ' . ($attachment->hasThumbnail() ? $attachment->thumbnailWidth : $attachment->width) . 'px; height: ' . ($attachment->hasThumbnail() ? $attachment->thumbnailHeight : $attachment->height) . 'px" alt="" />'; if ($attachment->hasThumbnail() && $attachment->canDownload()) { $link = '<a href="' . StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment))) . '" title="' . $title . '" class="embeddedAttachmentLink jsImageViewer">' . $link . '</a>'; } } else { if ($attachment->showAsImage()) { $link = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment))); $type = 'image'; } else { $link = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment))); $type = self::getType($attachment); } } } else { $link = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('id' => $attachmentID))); } if ($parser->getOutputType() == 'text/html') { WCF::getTPL()->assign(array('xaLink' => $link, 'xaTitle' => $title, 'xaIcon' => self::choseIcon($type), 'xaIsImage' => $isImage, 'xaText' => $text, 'xaFloat' => $float, 'xaNoBorder' => BBCODES_XATTACH_FREESTYLE)); $result = WCF::getTPL()->fetch('xAttachBBCode'); } else { $result = StringUtil::getAnchorTag($link, $title) . (!empty($text) ? ' (' . $text . ')' : ''); } return $result; }
/** * 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; }
/** * Validates the message text. */ protected function validateText() { if (empty($this->text)) { throw new UserInputException('text'); } // check text length if ($this->maxTextLength != 0 && mb_strlen($this->text) > $this->maxTextLength) { throw new UserInputException('text', 'tooLong'); } if ($this->enableBBCodes && $this->allowedBBCodesPermission) { $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($this->text, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($this->allowedBBCodesPermission)))); if (!empty($disallowedBBCodes)) { WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes); throw new UserInputException('text', 'disallowedBBCodes'); } } // search for censored words if (ENABLE_CENSORSHIP) { $result = Censorship::getInstance()->test($this->text); if ($result) { WCF::getTPL()->assign('censoredWords', $result); throw new UserInputException('text', 'censoredWordsFound'); } } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // get attachment id $attachmentID = 0; if (isset($openingTag['attributes'][0])) { $attachmentID = $openingTag['attributes'][0]; } // get embedded object $attachment = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.attachment', $attachmentID); if ($attachment === null) { if (self::$attachmentList !== null) { $attachments = self::$attachmentList->getGroupedObjects(self::$objectID); if (isset($attachments[$attachmentID])) { $attachment = $attachments[$attachmentID]; // mark attachment as embedded $attachment->markAsEmbedded(); } } } if ($attachment !== null) { if ($attachment->showAsImage() && $attachment->canViewPreview() && $parser->getOutputType() == 'text/html') { // image $alignment = isset($openingTag['attributes'][1]) ? $openingTag['attributes'][1] : ''; $width = isset($openingTag['attributes'][2]) ? $openingTag['attributes'][2] : 0; // check if width is valid and the original is accessible by viewer if ($width > 0) { if ($attachment->canDownload()) { // check if width exceeds image width if ($width > $attachment->width) { $width = $attachment->width; } } else { $width = 0; } } $result = ''; if ($width > 0) { $class = ''; if ($alignment == 'left' || $alignment == 'right') { $class = 'messageFloatObject' . ucfirst($alignment); } $source = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment))); $title = StringUtil::encodeHTML($attachment->filename); $result = '<a href="' . $source . '" title="' . $title . '" class="embeddedAttachmentLink jsImageViewer' . ($class ? ' ' . $class : '') . '"><img src="' . $source . '" style="width: ' . $width . 'px" alt="" /></a>'; } else { $linkParameters = array('object' => $attachment); if ($attachment->hasThumbnail()) { $linkParameters['thumbnail'] = 1; } $class = ''; if ($alignment == 'left' || $alignment == 'right') { $class = 'messageFloatObject' . ucfirst($alignment); } $imageClasses = ''; if (!$attachment->hasThumbnail()) { $imageClasses = 'embeddedAttachmentLink jsResizeImage'; } if ($class && (!$attachment->hasThumbnail() || !$attachment->canDownload())) { $imageClasses .= ' ' . $class; } $result = '<img src="' . StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', $linkParameters)) . '"' . ($imageClasses ? ' class="' . $imageClasses . '"' : '') . ' style="width: ' . ($attachment->hasThumbnail() ? $attachment->thumbnailWidth : $attachment->width) . 'px; height: ' . ($attachment->hasThumbnail() ? $attachment->thumbnailHeight : $attachment->height) . 'px;" alt="" />'; if ($attachment->hasThumbnail() && $attachment->canDownload()) { $result = '<a href="' . StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment))) . '" title="' . StringUtil::encodeHTML($attachment->filename) . '" class="embeddedAttachmentLink jsImageViewer' . ($class ? ' ' . $class : '') . '">' . $result . '</a>'; } } return $result; } else { // file return StringUtil::getAnchorTag(LinkHandler::getInstance()->getLink('Attachment', array('object' => $attachment)), !empty($content) && $content != $attachmentID ? $content : $attachment->filename); } } // fallback return StringUtil::getAnchorTag(LinkHandler::getInstance()->getLink('Attachment', array('id' => $attachmentID))); }