/**
* Renders a URL tag.
*
* @param array $tag Information about the tag reference; keys: tag, option, children
* @param array $rendererStates Renderer states to push down
*
* @return string Rendered tag
*/
public function renderTagUrl(array $tag, array $rendererStates)
{
if (!empty($tag['option']))
{
$url = $tag['option'];
$text = $this->renderSubTree($tag['children'], $rendererStates);
}
else
{
$url = $this->stringifyTree($tag['children']);
$text = urldecode($url);
if (!preg_match('/./u', $text))
{
$text = $url;
}
$text = XenForo_Helper_String::censorString($text);
if (!empty($rendererStates['shortenUrl']))
{
$length = utf8_strlen($text);
if ($length > 100)
{
$text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
}
}
$text = htmlspecialchars($text);
}
$url = $this->_getValidUrl($url);
if (!$url)
{
return $text;
}
else
{
list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
$class = $class ? " class=\"$class\"" : '';
$target = $target ? " target=\"$target\"" : '';
if ($type == 'internal')
{
$noFollow = '';
}
else
{
$noFollow = (empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"');
}
$url = XenForo_Helper_String::censorString($url);
if (!empty($rendererStates['noFollowDefault']))
{
return $text;
}
return '<a href="' . htmlspecialchars($url) . '"' . $target . $class . $noFollow . '>' . $text . '</a>';
}
}