From: Alexander Ebert Date: Sun, 3 Nov 2019 18:42:29 +0000 (+0100) Subject: Prevent the generation of HTML anchors if $removeLinks is set X-Git-Tag: 5.2.0_Beta_3~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4984dd679a1766d332abcec477ea46595165c60a;p=GitHub%2FWoltLab%2FWCF.git Prevent the generation of HTML anchors if $removeLinks is set --- diff --git a/com.woltlab.wcf/templates/mediaBBCodeTag.tpl b/com.woltlab.wcf/templates/mediaBBCodeTag.tpl index f18d734ab3..01a0c79541 100644 --- a/com.woltlab.wcf/templates/mediaBBCodeTag.tpl +++ b/com.woltlab.wcf/templates/mediaBBCodeTag.tpl @@ -1,6 +1,7 @@ +{if !$removeLinks|isset}{assign var='removeLinks' value=false}{/if} {if $thumbnailSize != 'original'} - {$media->altText} + {if !$removeLinks}{/if}{$media->altText}{if !$removeLinks}{/if} {else} {$media->altText} {/if} diff --git a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php index 730aa992ea..75683fdd2c 100644 --- a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php @@ -52,6 +52,12 @@ class HtmlBBCodeParser extends BBCodeParser { */ protected $validBBCodePattern = '~^[a-z](?:[a-z0-9\-_]+)?$~'; + /** + * @var bool + * @since 5.2 + */ + protected $removeLinks; + /** * @inheritDoc */ @@ -414,6 +420,22 @@ class HtmlBBCodeParser extends BBCodeParser { return $bbcodes; } + /** + * @param bool $removeLinks + * @since 5.2 + */ + public function setRemoveLinks($removeLinks) { + $this->removeLinks = $removeLinks; + } + + /** + * @return bool + * @since 5.2 + */ + public function getRemoveLinks() { + return $this->removeLinks; + } + /** * Compiles tag fragments into the custom HTML element. * diff --git a/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php index 444b3fbaf0..332c2a9adb 100644 --- a/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/WoltLabSuiteMediaBBCode.class.php @@ -32,9 +32,22 @@ class WoltLabSuiteMediaBBCode extends AbstractBBCode { return ''; } + $removeLinks = false; + if ($parser instanceof HtmlBBCodeParser && $parser->getRemoveLinks()) { + $removeLinks = true; + } + /** @var ViewableMedia $media */ $media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $mediaID); if ($media !== null && $media->isAccessible()) { + if ($removeLinks && !$media->isImage) { + if ($parser->getOutputType() === 'text/html' || $parser->getOutputType() === 'text/simplified-html') { + return StringUtil::encodeHTML($media->getTitle()); + } + + return StringUtil::encodeHTML($this->getLink($media)); + } + if ($parser->getOutputType() == 'text/html') { if ($media->isImage) { $thumbnailSize = (!empty($openingTag['attributes'][1])) ? $openingTag['attributes'][1] : 'original'; @@ -48,6 +61,7 @@ class WoltLabSuiteMediaBBCode extends AbstractBBCode { return WCF::getTPL()->fetch('mediaBBCodeTag', 'wcf', [ 'mediaLink' => $this->getLink($media), + 'removeLinks' => $removeLinks, 'thumbnailLink' => $thumbnailSize !== 'original' ? $this->getThumbnailLink($media, $thumbnailSize) : '' ]); } 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 bdc03ffc47..b136aed869 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 @@ -19,6 +19,11 @@ abstract class AbstractHtmlOutputNode extends AbstractHtmlNode implements IHtmlO */ protected $outputType = 'text/html'; + /** + * @var bool + */ + protected $removeLinks = false; + /** * @inheritDoc */ @@ -33,4 +38,12 @@ abstract class AbstractHtmlOutputNode extends AbstractHtmlNode implements IHtmlO public function setOutputType($outputType) { $this->outputType = $outputType; } + + /** + * @param bool $removeLinks + * @since 5.2 + */ + public function setRemoveLinks($removeLinks) { + $this->removeLinks = $removeLinks; + } } diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php index 65eca5bca4..86160cb32e 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php @@ -287,6 +287,7 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor { protected function invokeHtmlNode(IHtmlNode $htmlNode) { /** @var IHtmlOutputNode $htmlNode */ $htmlNode->setOutputType($this->outputType); + $htmlNode->setRemoveLinks($this->getHtmlProcessor()->removeLinks); parent::invokeHtmlNode($htmlNode); } diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php index 9523d8355b..b470729017 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php @@ -46,6 +46,16 @@ class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlOutputNode { public function replaceTag(array $data) { HtmlBBCodeParser::getInstance()->setOutputType($this->outputType); - return HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes'], $data['element']); + if ($this->removeLinks) { + HtmlBBCodeParser::getInstance()->setRemoveLinks($this->removeLinks); + } + + $output = HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes'], $data['element']); + + if ($this->removeLinks) { + HtmlBBCodeParser::getInstance()->setRemoveLinks(false); + } + + return $output; } } diff --git a/wcfsetup/install/files/lib/system/html/output/node/IHtmlOutputNode.class.php b/wcfsetup/install/files/lib/system/html/output/node/IHtmlOutputNode.class.php index 9fd3e8c5a1..e8f5797c0e 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/IHtmlOutputNode.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/IHtmlOutputNode.class.php @@ -18,4 +18,12 @@ interface IHtmlOutputNode extends IHtmlNode { * @param string $outputType desired output type */ public function setOutputType($outputType); + + /** + * Requests the HTML output to omit any HTML anchor. + * + * @param bool $removeLinks + * @since 5.2 + */ + public function setRemoveLinks($removeLinks); }