From: Alexander Ebert Date: Wed, 20 Jul 2016 11:01:03 +0000 (+0200) Subject: Added support for disallowed bbcodes X-Git-Tag: 3.0.0_Beta_1~1035 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=25863cff5dcb31c893b073aedf678b778a14d9fa;p=GitHub%2FWoltLab%2FWCF.git Added support for disallowed bbcodes --- diff --git a/com.woltlab.wcf/templates/wysiwygToolbar.tpl b/com.woltlab.wcf/templates/wysiwygToolbar.tpl index d0f180fcbe..706de87217 100644 --- a/com.woltlab.wcf/templates/wysiwygToolbar.tpl +++ b/com.woltlab.wcf/templates/wysiwygToolbar.tpl @@ -53,9 +53,7 @@ buttons.push('alignment'); {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')} buttons.push('woltlabImage'); {/if} -{if $__wcf->getBBCodeHandler()->isAvailableBBCode('table')} - buttons.push('table'); -{/if} +buttons.push('table'); buttons.push('wcfSeparator'); diff --git a/wcfsetup/install/files/acp/templates/bbcodeList.tpl b/wcfsetup/install/files/acp/templates/bbcodeList.tpl index b47145f7f4..61e44a54fd 100644 --- a/wcfsetup/install/files/acp/templates/bbcodeList.tpl +++ b/wcfsetup/install/files/acp/templates/bbcodeList.tpl @@ -4,7 +4,6 @@ // @@ -46,7 +45,6 @@ {foreach from=$objects item=bbcode} - {if $bbcode->canDelete()} diff --git a/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php b/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php index 85b4662c3d..0b42924d49 100644 --- a/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php +++ b/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php @@ -24,11 +24,16 @@ use wcf\system\WCF; * @property-read string $wysiwygIcon * @property-read string $buttonLabel * @property-read integer $isSourceCode - * @property-read integer $isDisabled * @property-read integer $showButton * @property-read integer $originIsSystem */ class BBCode extends ProcessibleDatabaseObject implements IRouteController { + /** + * list of attributes + * @var BBCodeAttribute[] + */ + protected $attributes; + /** * @inheritDoc */ @@ -51,12 +56,21 @@ class BBCode extends ProcessibleDatabaseObject implements IRouteController { */ public function getAttributes() { if ($this->attributes === null) { - $this->data['attributes'] = BBCodeCache::getInstance()->getBBCodeAttributes($this->bbcodeTag); + $this->attributes = BBCodeCache::getInstance()->getBBCodeAttributes($this->bbcodeTag); } return $this->attributes; } + /** + * Sets the attributes of this bbcode. + * + * @param BBCodeAttribute[] $attributes list of attributes + */ + public function setAttributes(array $attributes) { + $this->attributes = $attributes; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php b/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php index c4f893d165..6fd9f98c97 100644 --- a/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php +++ b/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php @@ -3,7 +3,6 @@ namespace wcf\data\bbcode; use wcf\data\user\group\UserGroup; use wcf\data\user\group\UserGroupEditor; use wcf\data\AbstractDatabaseObjectAction; -use wcf\data\IToggleAction; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\PermissionDeniedException; use wcf\system\WCF; @@ -19,7 +18,7 @@ use wcf\system\WCF; * @method BBCodeEditor[] getObjects() * @method BBCodeEditor getSingleObject() */ -class BBCodeAction extends AbstractDatabaseObjectAction implements IToggleAction { +class BBCodeAction extends AbstractDatabaseObjectAction { /** * @inheritDoc */ @@ -38,7 +37,7 @@ class BBCodeAction extends AbstractDatabaseObjectAction implements IToggleAction /** * @inheritDoc */ - protected $requireACP = ['delete', 'toggle', 'update']; + protected $requireACP = ['delete', 'update']; /** * @inheritDoc @@ -110,22 +109,4 @@ class BBCodeAction extends AbstractDatabaseObjectAction implements IToggleAction } } } - - /** - * @inheritDoc - */ - public function validateToggle() { - parent::validateUpdate(); - } - - /** - * @inheritDoc - */ - public function toggle() { - foreach ($this->getObjects() as $bbcode) { - $bbcode->update([ - 'isDisabled' => $bbcode->isDisabled ? 0 : 1 - ]); - } - } } diff --git a/wcfsetup/install/files/lib/form/MessageForm.class.php b/wcfsetup/install/files/lib/form/MessageForm.class.php index b79e89eb5d..4e7082229b 100644 --- a/wcfsetup/install/files/lib/form/MessageForm.class.php +++ b/wcfsetup/install/files/lib/form/MessageForm.class.php @@ -26,12 +26,6 @@ use wcf\util\StringUtil; * @package WoltLabSuite\Core\Form */ abstract class MessageForm extends AbstractCaptchaForm { - /** - * name of the permission which contains the allowed BBCodes - * @var string - */ - public $allowedBBCodesPermission = 'user.message.allowedBBCodes'; - /** * attachment handler * @var AttachmentHandler @@ -68,6 +62,12 @@ abstract class MessageForm extends AbstractCaptchaForm { */ public $defaultSmilies = []; + /** + * name of the permission which contains the disallowed BBCodes + * @var string + */ + public $disallowedBBCodesPermission = 'user.message.disallowedBBCodes'; + /** * enables multilingualism * @var boolean @@ -213,28 +213,28 @@ abstract class MessageForm extends AbstractCaptchaForm { throw new UserInputException('text'); } - // check text length - if ($this->maxTextLength != 0 && mb_strlen($this->text) > $this->maxTextLength) { - throw new UserInputException('text', 'tooLong'); + if ($this->disallowedBBCodesPermission) { + BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', WCF::getSession()->getPermission($this->disallowedBBCodesPermission))); } $this->htmlInputProcessor = new HtmlInputProcessor(); $this->htmlInputProcessor->process($this->text, $this->messageObjectType, 0); - // TODO: add checks for disallowed bbcodes and stuff - $this->htmlInputProcessor->validate(); + // check text length + $message = $this->htmlInputProcessor->getTextContent(); + if ($this->maxTextLength != 0 && mb_strlen($message) > $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'); - } - }*/ + $disallowedBBCodes = $this->htmlInputProcessor->validate(); + 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); + $result = Censorship::getInstance()->test($message); if ($result) { WCF::getTPL()->assign('censoredWords', $result); throw new UserInputException('text', 'censoredWordsFound'); @@ -309,8 +309,8 @@ abstract class MessageForm extends AbstractCaptchaForm { } } - if ($this->allowedBBCodesPermission) { - BBCodeHandler::getInstance()->setAllowedBBCodes(explode(',', WCF::getSession()->getPermission($this->allowedBBCodesPermission))); + if ($this->disallowedBBCodesPermission) { + BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', WCF::getSession()->getPermission($this->disallowedBBCodesPermission))); } } @@ -334,9 +334,5 @@ abstract class MessageForm extends AbstractCaptchaForm { 'text' => $this->text, 'tmpHash' => $this->tmpHash ]); - - if ($this->allowedBBCodesPermission) { - WCF::getTPL()->assign('allowedBBCodes', explode(',', ArrayUtil::trim(WCF::getSession()->getPermission($this->allowedBBCodesPermission)))); - } } } diff --git a/wcfsetup/install/files/lib/form/SignatureEditForm.class.php b/wcfsetup/install/files/lib/form/SignatureEditForm.class.php index ece637f04f..b4ec37f299 100644 --- a/wcfsetup/install/files/lib/form/SignatureEditForm.class.php +++ b/wcfsetup/install/files/lib/form/SignatureEditForm.class.php @@ -16,6 +16,11 @@ use wcf\system\WCF; * @package WoltLabSuite\Core\Form */ class SignatureEditForm extends MessageForm { + /** + * @inheritDoc + */ + public $disallowedBBCodesPermission = 'user.signature.disallowedBBCodes'; + /** * @inheritDoc */ @@ -29,7 +34,7 @@ class SignatureEditForm extends MessageForm { /** * @inheritDoc */ - public $templateName = 'signatureEdit'; + public $showSignatureSetting = false; /** * parsed signature cache @@ -38,15 +43,9 @@ class SignatureEditForm extends MessageForm { public $signatureCache; /** - * TODO: this is still missing * @inheritDoc */ - public $allowedBBCodesPermission = 'user.signature.allowedBBCodes'; - - /** - * @inheritDoc - */ - public $showSignatureSetting = false; + public $templateName = 'signatureEdit'; /** * @inheritDoc diff --git a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php index 2dcf58cbd9..80fdb7ac5f 100644 --- a/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/BBCodeHandler.class.php @@ -14,16 +14,16 @@ use wcf\system\SingletonFactory; */ class BBCodeHandler extends SingletonFactory { /** - * list of BBCodes allowed for usage + * list of BBCodes displayed as buttons * @var BBCode[] */ - protected $allowedBBCodes = []; + protected $buttonBBCodes = []; /** - * list of BBCodes displayed as buttons + * list of BBCodes disallowed for usage * @var BBCode[] */ - protected $buttonBBCodes = []; + protected $disallowedBBCodes = []; /** * list of BBCodes which contain raw code (disabled BBCode parsing) @@ -49,22 +49,7 @@ class BBCodeHandler extends SingletonFactory { * @return boolean */ public function isAvailableBBCode($bbCodeTag) { - // TODO - return true; - - $bbCode = BBCodeCache::getInstance()->getBBCodeByTag($bbCodeTag); - if ($bbCode === null || $bbCode->isDisabled) { - return false; - } - - if (in_array('all', $this->allowedBBCodes)) { - return true; - } - else if (in_array('none', $this->allowedBBCodes)) { - return false; - } - - return in_array($bbCodeTag, $this->allowedBBCodes); + return !in_array($bbCodeTag, $this->disallowedBBCodes); } /** @@ -98,13 +83,21 @@ class BBCodeHandler extends SingletonFactory { return $buttons; } + /** + * @param string[] $bbcodes + * @deprecated 3.0 - please use setDisallowedBBCodes() instead + */ + public function setAllowedBBCodes(array $bbcodes) { + throw new \RuntimeException("setAllowedBBCodes() is no longer supported, please use setDisallowedBBCodes() instead."); + } + /** * Sets the allowed BBCodes. * * @param string[] $bbCodes */ - public function setAllowedBBCodes(array $bbCodes) { - $this->allowedBBCodes = $bbCodes; + public function setDisallowedBBCodes(array $bbCodes) { + $this->disallowedBBCodes = $bbCodes; } /** diff --git a/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php index 9b8e508406..0bc513e92e 100644 --- a/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/BBCodeParser.class.php @@ -523,25 +523,10 @@ class BBCodeParser extends SingletonFactory { * @param string $text * @param string[] $allowedBBCodes * @return string[] + * @deprecated 3.0 - please use HtmlInputProcessor::validate() instead */ public function validateBBCodes($text, array $allowedBBCodes) { - // if all BBCodes are allowed, return directly - if (in_array('all', $allowedBBCodes)) { - return []; - } - - $this->setText($text); - $this->buildTagArray(false); - $this->buildXMLStructure(); - - $usedDisallowedBBCodes = []; - foreach ($this->tagArray as $tag) { - if (!in_array($tag['name'], $allowedBBCodes) && !isset($usedDisallowedBBCodes[$tag['name']])) { - $usedDisallowedBBCodes[$tag['name']] = $tag['name']; - } - } - - return $usedDisallowedBBCodes; + throw new \RuntimeException("validateBBCodes() is no longer supported, please use HtmlInputProcessor::validate() instead."); } /** diff --git a/wcfsetup/install/files/lib/system/cache/builder/BBCodeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/BBCodeCacheBuilder.class.php index f2c2fa74b6..bd49634e48 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/BBCodeCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/BBCodeCacheBuilder.class.php @@ -1,7 +1,7 @@ prepareStatement($sql); $statement->execute(); @@ -36,14 +35,14 @@ class BBCodeCacheBuilder extends AbstractCacheBuilder { } // get bbcodes - $sql = "SELECT * - FROM wcf".WCF_N."_bbcode - WHERE isDisabled = 0"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(); - while ($row = $statement->fetchArray()) { - $row['attributes'] = (isset($attributes[$row['bbcodeTag']]) ? $attributes[$row['bbcodeTag']] : []); - $data['bbcodes'][$row['bbcodeTag']] = new BBCode(null, $row); + $bbcodeList = new BBCodeList(); + $bbcodeList->readObjects(); + foreach ($bbcodeList as $bbcode) { + if (isset($attributes[$bbcode->bbcodeTag])) { + $bbcode->setAttributes($attributes[$bbcode->bbcodeTag]); + } + + $data['bbcodes'][$bbcode->bbcodeTag] = $bbcode; } // get code highlighters diff --git a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php index ee0cbc2eb7..686d9a81f1 100644 --- a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php @@ -5,6 +5,7 @@ use wcf\system\html\input\filter\IHtmlInputFilter; use wcf\system\html\input\filter\MessageHtmlInputFilter; use wcf\system\html\input\node\HtmlInputNodeProcessor; use wcf\system\html\AbstractHtmlProcessor; +use wcf\system\WCF; use wcf\util\StringUtil; /** @@ -82,8 +83,13 @@ class HtmlInputProcessor extends AbstractHtmlProcessor { $this->embeddedContent = $this->getHtmlInputNodeProcessor()->getEmbeddedContent(); } + /** + * Checks the input html for disallowed bbcodes and returns any matches. + * + * @return string[] list of matched disallowed bbcodes + */ public function validate() { - // TODO + return $this->getHtmlInputNodeProcessor()->validate(); } /** @@ -95,6 +101,15 @@ class HtmlInputProcessor extends AbstractHtmlProcessor { return $this->getHtmlInputNodeProcessor()->getHtml(); } + /** + * Returns the raw text content of current document. + * + * @return string raw text content + */ + public function getTextContent() { + return $this->getHtmlInputNodeProcessor()->getTextContent(); + } + /** * Returns the all embedded content data. * diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php index f3c3de9783..c534df2415 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php @@ -1,5 +1,6 @@ isAvailableBBCode('img')) ? [] : ['img']; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index 90bc8478fc..ad13cd6b4c 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -1,7 +1,10 @@ fireAction($this, 'afterProcess'); } + /** + * Checks the input html for disallowed bbcodes and returns any matches. + * + * @return string[] list of matched disallowed bbcodes + */ + public function validate() { + $result = []; + + $this->invokeNodeHandlers('wcf\system\html\input\node\HtmlInputNode', [], function(IHtmlNode $nodeHandler) use (&$result) { + $disallowed = $nodeHandler->isAllowed($this); + if ($disallowed) { + $result[] = array_merge($result, $disallowed); + } + }); + + // handle custom nodes that have no dedicated handler + $customTags = [ + 'color' => 'woltlab-color', + 'font' => 'woltlab-size', + 'size' => 'woltlab-size', + 'spoiler' => 'woltlab-spoiler' + ]; + + foreach ($customTags as $bbcode => $tagName) { + if (BBCodeHandler::getInstance()->isAvailableBBCode($bbcode)) { + continue; + } + + if ($this->getDocument()->getElementsByTagName($tagName)->length) { + $result[] = $bbcode; + } + } + + return $result; + } + + /** + * Returns the raw text content of current document. + * + * @return string raw text content + */ + public function getTextContent() { + return StringUtil::trim($this->getDocument()->getElementsByTagName('body')->item(0)->textContent); + } + /** * Processes embedded content. */ diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php index 818fc04f4a..0dd50488ad 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php @@ -3,6 +3,7 @@ namespace wcf\system\html\input\node; use wcf\data\bbcode\media\provider\BBCodeMediaProvider; use wcf\data\smiley\Smiley; use wcf\data\smiley\SmileyCache; +use wcf\system\bbcode\BBCodeHandler; use wcf\system\bbcode\HtmlBBCodeParser; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\WCF; @@ -146,6 +147,10 @@ class HtmlInputNodeTextParser { $users = $this->lookupUsernames($usernames); } + $allowEmail = BBCodeHandler::getInstance()->isAvailableBBCode('email'); + $allowMedia = BBCodeHandler::getInstance()->isAvailableBBCode('media'); + $allowURL = BBCodeHandler::getInstance()->isAvailableBBCode('url'); + for ($i = 0, $length = count($nodes); $i < $length; $i++) { /** @var \DOMText $node */ $node = $nodes[$i]; @@ -155,7 +160,13 @@ class HtmlInputNodeTextParser { $value = $this->parseMention($node, $value, $users); } - $value = $this->parseURL($node, $value); + if ($allowURL || $allowMedia) { + $value = $this->parseURL($node, $value, $allowURL, $allowMedia); + } + + if ($allowEmail) { + $value = $this->parseEmail($node, $value); + } $value = $this->parseSmiley($node, $value); @@ -304,9 +315,11 @@ class HtmlInputNodeTextParser { * * @param \DOMText $text text node * @param string $value node value + * @param boolean $allowURL url bbcode is allowed + * @param boolean $allowMedia media bbcode is allowed * @return string modified node value with replacement placeholders */ - protected function parseURL(\DOMText $text, $value) { + protected function parseURL(\DOMText $text, $value, $allowURL, $allowMedia) { static $urlPattern = ''; if ($urlPattern === '') { $urlPattern = '~ @@ -329,16 +342,26 @@ class HtmlInputNodeTextParser { )?~ix'; } - return preg_replace_callback($urlPattern, function($matches) use ($text) { + return preg_replace_callback($urlPattern, function($matches) use ($text, $allowURL, $allowMedia) { $link = $matches[0]; if (BBCodeMediaProvider::isMediaURL($link)) { - $element = $this->htmlInputNodeProcessor->createMetacodeElement($text, 'media', [$link]); + if ($allowMedia) { + $element = $this->htmlInputNodeProcessor->createMetacodeElement($text, 'media', [$link]); + } + else { + return $matches[0]; + } } else { - $element = $text->ownerDocument->createElement('a'); - $element->setAttribute('href', $link); - $element->textContent = $link; + if ($allowURL) { + $element = $text->ownerDocument->createElement('a'); + $element->setAttribute('href', $link); + $element->textContent = $link; + } + else { + return $matches[0]; + } } return $this->addReplacement($text, $element); @@ -353,7 +376,7 @@ class HtmlInputNodeTextParser { * @return string modified node value with replacement placeholders */ protected function parseEmail(\DOMText $text, $value) { - if (mb_strpos($this->text, '@') === false) { + if (mb_strpos($value, '@') === false) { return $value; } diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMention.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMention.class.php index 3f520f9a7f..91e37d82c2 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMention.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMention.class.php @@ -17,6 +17,14 @@ class HtmlInputNodeWoltlabMention extends AbstractHtmlInputNode { */ protected $tagName = 'woltlab-mention'; + /** + * @inheritDoc + */ + public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) { + // mentions are always allowed + return []; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php index 9311e2c91f..d0874ddc4a 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php @@ -1,5 +1,6 @@ getDocument()->getElementsByTagName($this->tagName) as $element) { + $bbcodes[] = $element->getAttribute('data-name'); + } + + $disallowedBBCodes = []; + foreach ($bbcodes as $bbcode) { + if (BBCodeHandler::getInstance()->isAvailableBBCode($bbcode)) { + continue; + } + + $disallowedBBCodes[] = $bbcode; + } + + return $disallowedBBCodes; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php index d8577a335c..0028740a49 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacodeMarker.class.php @@ -40,6 +40,14 @@ class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode { $this->sourceElements = HtmlBBCodeParser::getInstance()->getSourceBBCodes(); } + /** + * @inheritDoc + */ + public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) { + // metacode-marker isn't present at time of validation + return []; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php index fa254f03de..57a7f1466d 100644 --- a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php @@ -242,8 +242,9 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor { * * @param string $classNamePattern full namespace pattern for class guessing * @param string[] $skipTags list of tag names that should be ignored + * @param callable $callback optional callback */ - protected function invokeNodeHandlers($classNamePattern, array $skipTags = []) { + protected function invokeNodeHandlers($classNamePattern, array $skipTags = [], callable $callback = null) { $skipTags = array_merge($skipTags, ['html', 'head', 'title', 'meta', 'body', 'link']); $tags = []; @@ -263,7 +264,12 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor { }, $tagName); $className = $classNamePattern . ucfirst($tagName); if (class_exists($className)) { - $this->invokeHtmlNode(new $className); + if ($callback === null) { + $this->invokeHtmlNode(new $className); + } + else { + $callback(new $className); + } } } } diff --git a/wcfsetup/install/files/lib/system/html/node/IHtmlNode.class.php b/wcfsetup/install/files/lib/system/html/node/IHtmlNode.class.php index 2f71694cf1..a19289e12b 100644 --- a/wcfsetup/install/files/lib/system/html/node/IHtmlNode.class.php +++ b/wcfsetup/install/files/lib/system/html/node/IHtmlNode.class.php @@ -18,10 +18,18 @@ interface IHtmlNode { */ public function getTagName(); + /** + * Checks for disallowed bbcodes, must return the offending bbcode on match. + * + * @param AbstractHtmlNodeProcessor $htmlNodeProcessor node processor instance + * @return string[] disallowed bbcodes on match or empty array + */ + public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor); + /** * Processes the provided elements and marks them for replacement if applicable. * - * @param \DOMElement[] $elements static list of matched elements, does not change when removing elements + * @param \DOMElement[] $elements static list of matched elements, does not change when removing elements * @param AbstractHtmlNodeProcessor $htmlNodeProcessor node processor instance */ public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor); diff --git a/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php b/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php index fd5898ba39..9841fb0dd7 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/AbstractHtmlOutputNode.class.php @@ -1,6 +1,7 @@ allowedBBodes = $allowedBBCodes; + public function setDisallowedBBCodes(array $disallowedBBCodes) { + BBCodeHandler::getInstance()->setDisallowedBBCodes($disallowedBBCodes); } /** diff --git a/wcfsetup/install/files/lib/system/option/user/group/BBCodeSelectUserGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/user/group/BBCodeSelectUserGroupOptionType.class.php index d54885176a..284d83cc5a 100644 --- a/wcfsetup/install/files/lib/system/option/user/group/BBCodeSelectUserGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/user/group/BBCodeSelectUserGroupOptionType.class.php @@ -20,7 +20,13 @@ class BBCodeSelectUserGroupOptionType extends AbstractOptionType implements IUse * available BBCodes * @var string[] */ - protected $bbCodes = null; + protected $bbCodes; + + /** + * list of bbcode tags that are always available + * @var string[] + */ + protected static $alwaysAvailable = ['align', 'attach', 'b', 'code', 'i', 'list', 'quote', 's', 'sub', 'sup', 'table', 'td', 'tr', 'tt', 'u', 'wsm', 'wsmg', 'wsp']; /** * @inheritDoc @@ -41,17 +47,10 @@ class BBCodeSelectUserGroupOptionType extends AbstractOptionType implements IUse $this->loadBBCodeSelection(); } - if ($value == 'all') { - $selectedBBCodes = $this->bbCodes; - } - else { - $selectedBBCodes = explode(',', $value); - } - WCF::getTPL()->assign([ 'bbCodes' => $this->bbCodes, 'option' => $option, - 'selectedBBCodes' => $selectedBBCodes + 'selectedBBCodes' => explode(',', $value) ]); return WCF::getTPL()->fetch('bbCodeSelectOptionType'); @@ -64,6 +63,8 @@ class BBCodeSelectUserGroupOptionType extends AbstractOptionType implements IUse */ protected function loadBBCodeSelection() { $this->bbCodes = array_keys(BBCodeCache::getInstance()->getBBCodes()); + $this->bbCodes = array_diff($this->bbCodes, self::$alwaysAvailable); + asort($this->bbCodes); } @@ -75,19 +76,14 @@ class BBCodeSelectUserGroupOptionType extends AbstractOptionType implements IUse $this->loadBBCodeSelection(); } - if ($defaultValue == 'all') { - $defaultValue = $this->bbCodes; - } - else if (empty($defaultValue) || $defaultValue == 'none') { + if (empty($defaultValue)) { $defaultValue = []; } else { $defaultValue = explode(',', StringUtil::unifyNewlines($defaultValue)); } - if ($groupValue == 'all') { - $groupValue = $this->bbCodes; - } - else if (empty($groupValue) || $groupValue == 'none') { + + if (empty($groupValue)) { $groupValue = []; } else { @@ -123,6 +119,8 @@ class BBCodeSelectUserGroupOptionType extends AbstractOptionType implements IUse * @inheritDoc */ public function compare($value1, $value2) { + // TODO: fix this + // handle special case where no allowed BBCodes have been set if (empty($value1)) { if (empty($value2)) { diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 39f2f50d21..068938b7c6 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -395,11 +395,8 @@ - - - - - + + nicht verwendet werden.]]> @@ -420,11 +417,8 @@ - - - - - + + nicht verwendet werden.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 682997bd66..8d3446eefe 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -395,11 +395,8 @@ Examples for medium ID detection: - - - - - + + cannot be used by the users of this user group.]]> @@ -420,11 +417,8 @@ Examples for medium ID detection: - - - - - + + cannot be used in the signature.]]> diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 772844eb00..58ab336bd9 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -240,7 +240,6 @@ CREATE TABLE wcf1_bbcode ( buttonLabel VARCHAR(255) NOT NULL DEFAULT '', isBlockElement TINYINT(1) NOT NULL DEFAULT 0, isSourceCode TINYINT(1) NOT NULL DEFAULT 0, - isDisabled TINYINT(1) NOT NULL DEFAULT 0, showButton TINYINT(1) NOT NULL DEFAULT 0, originIsSystem TINYINT(1) NOT NULL DEFAULT 0, UNIQUE KEY bbcodeTag (bbcodeTag)