<?php
namespace wcf\util;
+use wcf\system\application\ApplicationHandler;
use wcf\system\WCF;
/**
return $truncatedString;
}
+ /**
+ * Generates an anchor tag from given URL.
+ *
+ * @param string $url
+ * @param string $title
+ * @return string anchor tag
+ */
+ public static function getAnchorTag($url, $title = '') {
+ $external = true;
+ if (ApplicationHandler::getInstance()->isInternalURL($url)) {
+ $external = false;
+ }
+
+ // cut visible url
+ if (empty($title)) {
+ // use URL and remove protocol and www subdomain
+ $title = preg_replace('~^(?:https?|ftps?)://(?:www\.)?~i', '', $url);
+
+ if (self::length($title) > 60) {
+ $title = self::substring($title, 0, 30) . self::HELLIP . self::substring($title, -25);
+ }
+ }
+
+ return '<a href="'.self::encodeHTML($url).'"'.($external ? (' class="externalURL"'.(EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="nofollow"' : '').(EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '')) : '').'>'.self::encodeHTML($title).'</a>';
+ }
+
/**
* Splits given string into smaller chunks.
*