From: Maximilian Mader Date: Tue, 28 Nov 2017 19:31:51 +0000 (+0100) Subject: Improve plain/text formatting of anchor tags and smilies (#2483) X-Git-Tag: 3.1.0_Beta_4~46 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cad9f99499ba24ef88b3f21023efd59baaea7803;p=GitHub%2FWoltLab%2FWCF.git Improve plain/text formatting of anchor tags and smilies (#2483) * Only truncate anchor nodes in HTML output mode Also convert links in plain/text mode into the format used by the Email subsystem. * Handle smilies in text/plain output mode --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php index 8c38e8e8c2..50a45326de 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php @@ -53,16 +53,29 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode { } $value = StringUtil::trim($element->textContent); - if (!empty($value) && $value === $href && mb_strlen($value) > 60) { - while ($element->childNodes->length) { - DOMUtil::removeNode($element->childNodes->item(0)); + + if ($this->outputType === 'text/html' || $this->outputType === 'text/simplified-html') { + if (!empty($value) && $value === $href && mb_strlen($value) > 60) { + while ($element->childNodes->length) { + DOMUtil::removeNode($element->childNodes->item(0)); + } + + $element->appendChild( + $element->ownerDocument->createTextNode( + mb_substr($value, 0, 30) . StringUtil::HELLIP . mb_substr($value, -25) + ) + ); } - - $element->appendChild( - $element->ownerDocument->createTextNode( - mb_substr($value, 0, 30) . StringUtil::HELLIP . mb_substr($value, -25) - ) - ); + } + else if ($this->outputType === 'text/plain') { + if (!empty($value) && $value !== $href) { + $text = $value . ' [URL:' . $href . ']'; + } + else { + $text = $href; + } + + $htmlNodeProcessor->replaceElementWithText($element, $text, false); } } } diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php index fcbed30d01..fe0296b6ad 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php @@ -40,10 +40,9 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode { /** @var Smiley $smiley */ $smiley = SmileyCache::getInstance()->getSmileyByCode($code); - if ($smiley === null) { + if ($smiley === null || $this->outputType === 'text/plain') { // output as raw code instead - $element->parentNode->insertBefore($element->ownerDocument->createTextNode($code), $element); - $element->parentNode->removeChild($element); + $htmlNodeProcessor->replaceElementWithText($element, ' ' . $code . ' ', false); } else { // enforce database values for src, srcset and style