<span class="quoteBoxTitle">
{if $quoteAuthor}
{if $quoteLink}
- <a href="{@$quoteLink}"{if $isExternalQuoteLink} class="externalURL"{if EXTERNAL_LINK_REL_NOFOLLOW || EXTERNAL_LINK_TARGET_BLANK}rel="{if EXTERNAL_LINK_REL_NOFOLLOW}nofollow{/if} {if EXTERNAL_LINK_TARGET_BLANK}noopener noreferrer{/if}"{/if}{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}{/if}>{lang}wcf.bbcode.quote.title{/lang}</a>
+ <a {anchorAttributes url=$quoteLink}>{lang}wcf.bbcode.quote.title{/lang}</a>
{else}
{lang}wcf.bbcode.quote.title{/lang}
{/if}
<ul class="buttonList iconList">
{content}
{if $user->homepage && $user->homepage != 'http://'}
- <li><a class="jsTooltip" href="{$user->homepage}" title="{lang}wcf.user.option.homepage{/lang}"{if EXTERNAL_LINK_REL_NOFOLLOW || EXTERNAL_LINK_TARGET_BLANK} rel="{if EXTERNAL_LINK_REL_NOFOLLOW}nofollow{/if}{if EXTERNAL_LINK_TARGET_BLANK}{if EXTERNAL_LINK_REL_NOFOLLOW} {/if}noopener noreferrer{/if}"{/if}{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}><span class="icon icon16 fa-home"></span> <span class="invisible">{lang}wcf.user.option.homepage{/lang}</span></a></li>
+ <li><a class="jsTooltip" title="{lang}wcf.user.option.homepage{/lang}" {anchorAttributes url=$user->homepage appendClassname=false}><span class="icon icon16 fa-home"></span> <span class="invisible">{lang}wcf.user.option.homepage{/lang}</span></a></li>
{/if}
{if $user->userID != $__wcf->user->userID}
<div class="details userInformation">
<div class="containerHeadline">
- <h3>{if $user->getSpider()->spiderURL}<a href="{$user->getSpider()->spiderURL}" class="externalURL"{if EXTERNAL_LINK_REL_NOFOLLOW || EXTERNAL_LINK_TARGET_BLANK} rel="{if EXTERNAL_LINK_REL_NOFOLLOW}nofollow{/if}{if EXTERNAL_LINK_TARGET_BLANK}{if EXTERNAL_LINK_REL_NOFOLLOW} {/if}noopener noreferrer{/if}"{/if}{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}>{$user->getSpider()->spiderName}</a>{else}{$user->getSpider()->spiderName}{/if}</h3>
+ <h3>{if $user->getSpider()->spiderURL}<a {anchorAttributes url=$user->getSpider()->spiderURL}>{$user->getSpider()->spiderName}</a>{else}{$user->getSpider()->spiderName}{/if}</h3>
{@$locationData}
</div>
--- /dev/null
+<?php
+namespace wcf\system\template\plugin;
+use wcf\system\application\ApplicationHandler;
+use wcf\system\request\RouteHandler;
+use wcf\system\template\TemplateEngine;
+use wcf\util\StringUtil;
+
+/**
+ * Template function plugin which generates attributes for `a` HTML elements.
+ *
+ * Required parameter:
+ * `url` (string)
+ * Optional parameter:
+ * `appendHref` (bool, default true)
+ * `appendClassname` (bool, default true)
+ *
+ * Usage:
+ * {anchorAttributes url=$url}
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Template\Plugin
+ * @since 5.3
+ */
+class AnchorAttributesFunctionTemplatePlugin implements IFunctionTemplatePlugin {
+ /**
+ * @inheritDoc
+ */
+ public function execute($tagArgs, TemplateEngine $tplObj) {
+ if (empty($tagArgs['url'])) {
+ throw new \InvalidArgumentException("Missing 'url' attribute.");
+ }
+ $url = $tagArgs['url'];
+ $appendClassname = $tagArgs['appendClassname'] ?? true;
+ $appendHref = $tagArgs['appendHref'] ?? true;
+
+ $external = true;
+ if (ApplicationHandler::getInstance()->isInternalURL($url)) {
+ $external = false;
+ $url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
+ }
+
+ $attributes = '';
+ if ($appendHref) {
+ $attributes = 'href="' . StringUtil::encodeHTML($url) . '"';
+ }
+
+ if ($external) {
+ if ($appendClassname) {
+ $attributes .= ' class="externalURL"';
+ }
+
+ $rel = 'nofollow';
+ if (EXTERNAL_LINK_TARGET_BLANK) {
+ $rel .= ' noopener noreferrer';
+ $attributes .= 'target="_blank"';
+ }
+
+ $attributes .= ' rel="' . $rel . '"';
+ }
+
+ return StringUtil::trim($attributes);
+ }
+}
$url = sprintf(IP_ADDRESS_SEARCH_ENGINE ?: self::SEARCH_ENGINE_URL_DEFAULT, $ipAddress);
$title = WCF::getLanguage()->getDynamicVariable('wcf.user.ipAddress.searchEngine', ['host' => $domain, 'ipAddress' => $ipAddress]);
- return '<a href="' . $url . '"' . (EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="nofollow"' : '') .(EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '') . ' title="' . $title . '">' . $ipAddress . '</a>';
+ return '<a '. StringUtil::getAnchorTagAttributes($url) .' title="' . $title . '">' . $ipAddress . '</a>';
}
}
public static function getAnchorTag($url, $title = '', $encodeTitle = true) {
$url = self::trim($url);
- $external = true;
- if (ApplicationHandler::getInstance()->isInternalURL($url)) {
- $external = false;
- $url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
- }
-
// cut visible url
if (empty($title)) {
// use URL and remove protocol and www subdomain
if (!$encodeTitle) $title = self::encodeHTML($title);
}
- return '<a href="'.self::encodeHTML($url).'"'.($external ? (' class="externalURL"'.((EXTERNAL_LINK_REL_NOFOLLOW || EXTERNAL_LINK_TARGET_BLANK) ? (' rel="'.(EXTERNAL_LINK_REL_NOFOLLOW ? 'nofollow' : '').((EXTERNAL_LINK_REL_NOFOLLOW && EXTERNAL_LINK_TARGET_BLANK) ? ' ' : '').(EXTERNAL_LINK_TARGET_BLANK ? 'noopener noreferrer' : '').'"') : '').(EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '')) : '').'>'.($encodeTitle ? self::encodeHTML($title) : $title).'</a>';
+ return '<a '. self::getAnchorTagAttributes($url) .'>' . ($encodeTitle ? self::encodeHTML($title) : $title) . '</a>';
+ }
+
+ /**
+ * Generates the attributes for an anchor tag from given URL.
+ *
+ * @param string $url
+ * @return string attributes
+ * @since 5.3
+ */
+ public static function getAnchorTagAttributes($url) {
+ $external = true;
+ if (ApplicationHandler::getInstance()->isInternalURL($url)) {
+ $external = false;
+ $url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
+ }
+
+ $attributes = 'href="' . self::encodeHTML($url) . '"';
+ if ($external) {
+ $attributes .= ' class="externalURL"';
+ $rel = 'nofollow';
+ if (EXTERNAL_LINK_TARGET_BLANK) {
+ $rel .= ' noopener noreferrer';
+ $attributes .= 'target="_blank"';
+ }
+
+ $attributes .= ' rel="' . $rel . '"';
+ }
+
+ return $attributes;
}
/**