From 208665db3f5e1cbf41ce414f7765b3c2e9e85f37 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 29 Aug 2016 11:52:56 +0200 Subject: [PATCH] Properly handling bbcodes with content being treated as source --- .../lib/system/bbcode/HtmlBBCodeParser.class.php | 12 +++++++++--- .../node/HtmlOutputNodeWoltlabMetacode.class.php | 10 ++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php index d7b314c37e..acddebcc22 100644 --- a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php @@ -323,16 +323,22 @@ class HtmlBBCodeParser extends BBCodeParser { * * @param string $name bbcode identifier * @param array $attributes list of attributes + * @param \DOMElement $element element * @return string parsed bbcode */ - public function getHtmlOutput($name, array $attributes) { + public function getHtmlOutput($name, array $attributes, \DOMElement $element) { if (isset($this->bbcodes[$name])) { + $bbcode = $this->bbcodes[$name]; + if ($bbcode->isSourceCode) { + array_unshift($attributes, $element->textContent); + } + $openingTag = ['attributes' => $attributes, 'name' => $name]; $closingTag = ['name' => $name]; - if ($this->bbcodes[$name]->getProcessor()) { + if ($bbcode->getProcessor()) { /** @var IBBCode $processor */ - $processor = $this->bbcodes[$name]->getProcessor(); + $processor = $bbcode->getProcessor(); return $processor->getParsedTag($openingTag, '', $closingTag, $this); } else { 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 368c418e6b..eec7967800 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 @@ -29,12 +29,14 @@ class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlOutputNode { $attributes = $element->getAttribute('data-attributes'); $nodeIdentifier = StringUtil::getRandomID(); + + $element = $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier); + $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [ 'name' => $name, - 'attributes' => $htmlNodeProcessor->parseAttributes($attributes) + 'attributes' => $htmlNodeProcessor->parseAttributes($attributes), + 'element' => $element ]); - - $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier); } } @@ -44,6 +46,6 @@ class HtmlOutputNodeWoltlabMetacode extends AbstractHtmlOutputNode { public function replaceTag(array $data) { HtmlBBCodeParser::getInstance()->setOutputType($this->outputType); - return HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes']); + return HtmlBBCodeParser::getInstance()->getHtmlOutput($data['name'], $data['attributes'], $data['element']); } } -- 2.20.1