External images displayed as link are now shown as such
authorAlexander Ebert <ebert@woltlab.com>
Sat, 19 May 2018 18:17:07 +0000 (20:17 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 19 May 2018 18:17:07 +0000 (20:17 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php

index ebb60d87f3817f8250b97c290ec4846a04aee284..4d03b03d4ef64b47b94d23c1b906b89650646879 100644 (file)
@@ -32,24 +32,7 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode {
                                $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);
-                               }
+                               self::markLinkAsExternal($element);
                        }
                        
                        $value = StringUtil::trim($element->textContent);
@@ -79,4 +62,30 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode {
                        }
                }
        }
+       
+       /**
+        * Marks an element as external.
+        * 
+        * @param       \DOMElement     $element
+        */
+       public static function markLinkAsExternal(\DOMElement $element) {
+               $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);
+               }
+       }
 }
index 54d4067ff8705a42928720be6d44d997ad1fb7c9..fe73a9edfd9b9353afacc867f44f2ebcc3789018 100644 (file)
@@ -132,6 +132,8 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode {
                                        $link = $element->ownerDocument->createElement('a');
                                        $link->setAttribute('href', $src);
                                        $link->textContent = $src;
+                                       HtmlOutputNodeA::markLinkAsExternal($link);
+                                       
                                        $element->parentNode->insertBefore($link, $element);
                                        
                                        $element->parentNode->insertBefore($element->ownerDocument->createTextNode(']'), $element);