diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php new file mode 100644 index 00000000000..ae0fdd4bad4 --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php @@ -0,0 +1,55 @@ +` and removes invalid tables. This action can + * be done safely, because completely messed up tables have already + * been crippled by HTMLPurifier. + * + * @author Alexander Ebert + * @copyright 2001-2016 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Html\Input\Node + * @since 3.0 + */ +class HtmlInputNodeWoltlabTable extends AbstractHtmlInputNode { + /** + * @inheritDoc + */ + protected $tagName = 'table'; + + /** + * @inheritDoc + */ + public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) { + return []; + } + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $trs = []; + /** @var \DOMElement $tr */ + foreach ($element->getElementsByTagName('tr') as $tr) { + $trs[] = $tr; + } + + // check if each `` has at least one `` + foreach ($trs as $tr) { + if ($tr->getElementsByTagName('td')->length === 0) { + DOMUtil::removeNode($tr); + } + } + + if ($element->getElementsByTagName('tr')->length === 0) { + // garbage table, remove + DOMUtil::removeNode($element); + } + } + } +}