From c6d889fb79a1691144ba29f2572665e8e879e473 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 4 Oct 2016 13:02:04 +0200 Subject: [PATCH] Re-added `buildParsedString()` --- .../system/bbcode/HtmlBBCodeParser.class.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php index 9160ac0967..da877f77c9 100644 --- a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php @@ -173,6 +173,94 @@ class HtmlBBCodeParser extends BBCodeParser { $this->textArray = $newTextArray; } + /** + * Builds the parsed string. + */ + public function buildParsedString() { + // reset parsed text + $this->parsedText = ''; + + // create text buffer + $buffer =& $this->parsedText; + + // stack of buffered tags + $bufferedTagStack = []; + + // loop through the tags + $i = -1; + foreach ($this->tagArray as $i => $tag) { + // append text to buffer + $buffer .= $this->textArray[$i]; + + if ($tag['closing']) { + // get buffered opening tag + $openingTag = end($bufferedTagStack); + + // closing tag + if ($openingTag && $openingTag['name'] == $tag['name']) { + $hideBuffer = false; + // insert buffered content as attribute value + foreach ($this->bbcodes[$tag['name']]->getAttributes() as $attribute) { + if ($attribute->useText && !isset($openingTag['attributes'][$attribute->attributeNo])) { + $openingTag['attributes'][$attribute->attributeNo] = $buffer; + $hideBuffer = true; + break; + } + } + + // validate tag attributes again + if ($this->isValidTag($openingTag)) { + if ($this->bbcodes[$tag['name']]->className) { + // difference to the original implementation: use the custom HTML element than to process them directly + $parsedTag = $this->compileTag($openingTag, $buffer, $tag); + } + else { + // build tag + $parsedTag = $this->buildOpeningTag($openingTag); + $closingTag = $this->buildClosingTag($tag); + if (!empty($closingTag) && $hideBuffer) $parsedTag .= $buffer.$closingTag; + } + } + else { + $parsedTag = $openingTag['source'].$buffer.$tag['source']; + } + + // close current buffer + array_pop($bufferedTagStack); + + // open previous buffer + if (count($bufferedTagStack) > 0) { + $bufferedTag =& $bufferedTagStack[count($bufferedTagStack) - 1]; + $buffer =& $bufferedTag['buffer']; + } + else { + $buffer =& $this->parsedText; + } + + // append parsed tag + $buffer .= $parsedTag; + } + else { + $buffer .= $this->buildClosingTag($tag); + } + } + else { + // opening tag + if ($this->needBuffering($tag)) { + // start buffering + $tag['buffer'] = ''; + $bufferedTagStack[] = $tag; + $buffer =& $bufferedTagStack[count($bufferedTagStack) - 1]['buffer']; + } + else { + $buffer .= $this->buildOpeningTag($tag); + } + } + } + + if (isset($this->textArray[$i + 1])) $this->parsedText .= $this->textArray[$i + 1]; + } + /** * Builds the bbcode output. * -- 2.20.1