XF 1.1 How to deactivate direct links?

Jake Bunce

XenForo moderator
Staff member
#2
File edit:

library/XenForo/BbCode/Formatter/Base.php

Add the red code:

Rich (BB code):
	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 (!utf8_check($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);

			// return '<a href="' . htmlspecialchars($url) . '"' . $target . $class . $noFollow . '>' . $text . '</a>';
			return $text;
		}
	}
Or this modification can be made into an addon that extends this class, similar to this:

http://xenforo.com/community/threads/force-rich-code-tag.20317/
 

Jake Bunce

XenForo moderator
Staff member
#4
This works very well for all users but is there a way I can allow only admin links to parse?
library/XenForo/BbCode/Formatter/Base.php

Add the red code:

Rich (BB code):
	/**
	 * 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>';
		}
	}
This doesn't directly check the admin status, but the noFollow flag is always true for regular users and false for admins/mods, so it works in this case.
 
Top