Added trimming inside quotes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jan 2017 17:45:27 +0000 (18:45 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jan 2017 17:45:27 +0000 (18:45 +0100)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index 89041d0b6dee52d7d3752c8aa8c0774e2c27cb92..d08bf32ad8f5bcd37330c1141bea6980fd399dc2 100644 (file)
@@ -295,6 +295,60 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor {
                                
                        }
                }
+               
+               // trim quotes
+               /** @var \DOMElement $quote */
+               foreach ($this->getDocument()->getElementsByTagName('woltlab-quote') as $quote) {
+                       $removeElements = [];
+                       for ($i = 0, $length = $quote->childNodes->length; $i < $length; $i++) {
+                               $node = $quote->childNodes->item($i);
+                               if ($node->nodeType === XML_TEXT_NODE) {
+                                       continue;
+                               }
+                               
+                               if ($node->nodeName === 'p' && $node->childNodes->length === 1) {
+                                       $child = $node->childNodes->item(0);
+                                       if ($child->nodeType === XML_ELEMENT_NODE && $child->nodeName === 'br') {
+                                               $removeElements[] = $node;
+                                       }
+                                       else {
+                                               break;
+                                       }
+                               }
+                               else {
+                                       break;
+                               }
+                       }
+                       
+                       foreach ($removeElements as $removeElement) {
+                               $quote->removeChild($removeElement);
+                       }
+                       
+                       $removeElements = [];
+                       for ($i = $quote->childNodes->length - 1; $i >= 0; $i--) {
+                               $node = $quote->childNodes->item($i);
+                               if ($node->nodeType === XML_TEXT_NODE) {
+                                       continue;
+                               }
+                               
+                               if ($node->nodeName === 'p' && $node->childNodes->length === 1) {
+                                       $child = $node->childNodes->item(0);
+                                       if ($child->nodeType === XML_ELEMENT_NODE && $child->nodeName === 'br') {
+                                               $removeElements[] = $node;
+                                       }
+                                       else {
+                                               break;
+                                       }
+                               }
+                               else {
+                                       break;
+                               }
+                       }
+                       
+                       foreach ($removeElements as $removeElement) {
+                               $quote->removeChild($removeElement);
+                       }
+               }
        }
        
        /**