Fixed missing output handling of links
authorAlexander Ebert <ebert@woltlab.com>
Tue, 11 Oct 2016 10:44:29 +0000 (12:44 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 11 Oct 2016 10:44:29 +0000 (12:44 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php [new file with mode: 0644]

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 (file)
index 0000000..db91ebd
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+namespace wcf\system\html\output\node;
+use wcf\system\application\ApplicationHandler;
+use wcf\system\html\node\AbstractHtmlNodeProcessor;
+use wcf\system\request\RouteHandler;
+use wcf\util\DOMUtil;
+use wcf\util\StringUtil;
+
+/**
+ * Processes links.
+ * 
+ * @author      Alexander Ebert
+ * @copyright   2001-2016 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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)
+                                       )
+                               );
+                       }
+               }
+       }
+}