From 1416f0513bbb7bda196942d6f821db6f0514f7ff Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 11 Oct 2016 12:44:29 +0200 Subject: [PATCH] Fixed missing output handling of links --- .../output/node/HtmlOutputNodeA.class.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php 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 new file mode 100644 index 0000000000..db91ebd6d3 --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php @@ -0,0 +1,69 @@ + + * @package WoltLabSuite\Core\System\Html\Output\Node + * @since 3.0 + */ +class HtmlOutputNodeA extends AbstractHtmlOutputNode { + /** + * @inheritDoc + */ + protected $tagName = 'a'; + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $href = $element->getAttribute('href'); + if (ApplicationHandler::getInstance()->isInternalURL($href)) { + $element->setAttribute('href', preg_replace('~^https?://~', RouteHandler::getProtocol(), $href)); + } + else { + $element->setAttribute('class', 'externalURL'); + + $rel = ''; + if (EXTERNAL_LINK_REL_NOFOLLOW) { + $rel = 'nofollow'; + } + + if (EXTERNAL_LINK_TARGET_BLANK) { + if (!empty($rel)) $rel .= ' '; + + $rel .= 'noopener noreferrer'; + + $element->setAttribute('target', '_blank'); + } + + if (!empty($rel)) { + $element->setAttribute('rel', $rel); + } + } + + $value = StringUtil::trim($element->textContent); + 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) + ) + ); + } + } + } +} -- 2.20.1