From: Alexander Ebert Date: Mon, 23 May 2022 15:04:16 +0000 (+0200) Subject: Mark quotes that have been stripped empty X-Git-Tag: 5.5.0_Beta_4~27 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f44a77903e1ec4f10b9bfec974203582bfd1e3e9;p=GitHub%2FWoltLab%2FWCF.git Mark quotes that have been stripped empty See https://www.woltlab.com/community/thread/295675-zitieren-von-zitaten-f%C3%BChrt-zu-leerem-zitat/ --- 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];