From f44a77903e1ec4f10b9bfec974203582bfd1e3e9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 23 May 2022 17:04:16 +0200 Subject: [PATCH] Mark quotes that have been stripped empty See https://www.woltlab.com/community/thread/295675-zitieren-von-zitaten-f%C3%BChrt-zu-leerem-zitat/ --- .../html/input/HtmlInputProcessor.class.php | 4 ++-- .../node/HtmlInputNodeProcessor.class.php | 24 ++++++++++++++++++- .../quote/MessageQuoteManager.class.php | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php index 38ed61b938..1cd6948342 100644 --- a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php @@ -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); } /** diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index db60a8cbc5..9385bea52d 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -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); + } + } } /** diff --git a/wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php b/wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php index cbb4201836..c719dd7220 100644 --- a/wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php +++ b/wcfsetup/install/files/lib/system/message/quote/MessageQuoteManager.class.php @@ -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]; -- 2.20.1