Re-added `buildParsedString()`
authorAlexander Ebert <ebert@woltlab.com>
Tue, 4 Oct 2016 11:02:04 +0000 (13:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 4 Oct 2016 11:02:04 +0000 (13:02 +0200)
wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php

index 9160ac096725ec920ef10ec0cdf34e79d2b9e0e0..da877f77c90db6d8c7df559f07898879c47c8c31 100644 (file)
@@ -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.
         *