Improve plain/text formatting of anchor tags and smilies (#2483)
authorMaximilian Mader <max@bastelstu.be>
Tue, 28 Nov 2017 19:31:51 +0000 (20:31 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 28 Nov 2017 19:31:51 +0000 (20:31 +0100)
* 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

wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php

index 8c38e8e8c28f714333f1a11bdeaeec854c9d802d..50a45326de0ce2e33c4c0af3225c780a11801cdc 100644 (file)
@@ -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);
                        }
                }
        }
index fcbed30d0133c5b3c3c3c53c1b3a9dba5bb12aa8..fe0296b6ad426bf2b4492075ff82ff626eb63673 100644 (file)
@@ -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