Properly handling bbcodes with content being treated as source
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 Aug 2016 09:52:56 +0000 (11:52 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 Aug 2016 09:53:02 +0000 (11:53 +0200)
wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabMetacode.class.php

index d7b314c37eb63e235cb7875b28f89744bc75fdd8..acddebcc22be96f0ec1ef411d10b4ba6949a141a 100644 (file)
@@ -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, '<!-- META_CODE_INNER_CONTENT -->', $closingTag, $this);
                        }
                        else {
index 368c418e6b7f857fc2c6ca34ac9b0ffbd9ffdc48..eec7967800b38de3a85ae8017578d5e627fb9dd9 100644 (file)
@@ -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']);
        }
 }