Mark quotes that have been stripped empty
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 May 2022 15:04:16 +0000 (17:04 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 May 2022 15:04:16 +0000 (17:04 +0200)
See https://www.woltlab.com/community/thread/295675-zitieren-von-zitaten-f%C3%BChrt-zu-leerem-zitat/

wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php
wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php

index 38ed61b938df1636911a30ba3418bacdc1772a95..1cd6948342cb4a2b1a3c0279f9abfe3edc6b231a 100644 (file)
@@ -185,9 +185,9 @@ class HtmlInputProcessor extends AbstractHtmlProcessor
      *
      * @param int $depth
      */
-    public function enforceQuoteDepth($depth)
+    public function enforceQuoteDepth($depth, bool $isFullQuote = false)
     {
-        $this->getHtmlInputNodeProcessor()->enforceQuoteDepth($depth);
+        $this->getHtmlInputNodeProcessor()->enforceQuoteDepth($depth, $isFullQuote);
     }
 
     /**
index db60a8cbc54e034106c8096470c8d335b58bd516..9385bea52d923a4d402fdd82436eaf5cd3733d15 100644 (file)
@@ -272,7 +272,7 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor
      *
      * @param int $depth
      */
-    public function enforceQuoteDepth($depth)
+    public function enforceQuoteDepth($depth, bool $isFullQuote = false)
     {
         $quotes = [];
         /** @var \DOMElement $quote */
@@ -280,6 +280,7 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor
             $quotes[] = $quote;
         }
 
+        $checkQuotes = [];
         foreach ($quotes as $quote) {
             if (!$quote->parentNode) {
                 continue;
@@ -300,9 +301,30 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor
                     continue;
                 }
 
+                $checkQuotes[] = $quote->parentNode;
                 DOMUtil::removeNode($quote);
             }
         }
+
+        /**
+         * @var \DOMElement $quote
+         */
+        foreach ($checkQuotes as $quote) {
+            if ($quote->childNodes->length === 0) {
+                $quote->textContent = "[\u{2026}]";
+            }
+        }
+
+        // Check if the quoted message is now empty.
+        if ($depth === 0 && $isFullQuote && \count($quotes) > 0) {
+            /** @var \DOMElement $body */
+            $body = $this->getDocument()->getElementsByTagName('body')[0];
+            if ($body->childElementCount === 0) {
+                $p = $body->ownerDocument->createElement('p');
+                $p->textContent = "[\u{2026}]";
+                $body->appendChild($p);
+            }
+        }
     }
 
     /**
index cbb4201836fe532296b33fa27f8f006afffbef1d..c719dd722048d49c0934b3111ed35c1c2821c673 100644 (file)
@@ -145,7 +145,7 @@ class MessageQuoteManager extends SingletonFactory
                 $htmlInputProcessor->processIntermediate($fullQuote);
 
                 if (MESSAGE_MAX_QUOTE_DEPTH) {
-                    $htmlInputProcessor->enforceQuoteDepth(MESSAGE_MAX_QUOTE_DEPTH - 1);
+                    $htmlInputProcessor->enforceQuoteDepth(MESSAGE_MAX_QUOTE_DEPTH - 1, true);
                 }
 
                 $parameters = ['htmlInputProcessor' => $htmlInputProcessor];