Discarding bbcode content if it matches the first attribute
authorAlexander Ebert <ebert@woltlab.com>
Sun, 24 Jul 2016 11:15:43 +0000 (13:15 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 24 Jul 2016 11:15:43 +0000 (13:15 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeWoltlabMetacode.class.php

index d0874ddc4afdb8940912dda11a153fd7da3c484a..e3e46b7ee59f2a19a8d613e338aababa568811a5 100644 (file)
@@ -1,9 +1,11 @@
 <?php
 namespace wcf\system\html\input\node;
+use wcf\data\bbcode\BBCodeCache;
 use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\html\metacode\converter\IMetacodeConverter;
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\util\DOMUtil;
+use wcf\util\StringUtil;
 
 /**
  * Processes `<woltlab-metacode>` and converts them if appropriate.
@@ -91,6 +93,19 @@ class HtmlInputNodeWoltlabMetacode extends AbstractHtmlInputNode {
                        }
                        
                        if ($converter === null) {
+                               // check if the bbcode's content should be used as first attribute and it
+                               // matches the elements content
+                               $bbcode = BBCodeCache::getInstance()->getBBCodeByTag($name);
+                               if ($bbcode !== null) {
+                                       $bbcodeAttributes = $bbcode->getAttributes();
+                                       $attr = (isset($bbcodeAttributes[0])) ? $bbcodeAttributes[0] : null;
+                                       
+                                       if ($attr !== null && $attr->useText && !empty($attributes[0]) && StringUtil::trim($attributes[0]) == StringUtil::trim($element->textContent)) {
+                                               // discard content as it is already present in the first attribute
+                                               $element->textContent = '';
+                                       }
+                               }
+                               
                                // no available converter, metacode will be handled during output generation
                                continue;
                        }