MyBB Community Forums
How to stop periods from ruining links? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Community Archive (https://community.mybb.com/forum-106.html)
+--- Forum: Archived Forums (https://community.mybb.com/forum-143.html)
+---- Forum: Archived Development and Support (https://community.mybb.com/forum-155.html)
+----- Forum: MyBB 1.6 (https://community.mybb.com/forum-138.html)
+------ Forum: 1.6 General Support (https://community.mybb.com/forum-127.html)
+------ Thread: How to stop periods from ruining links? (/thread-151553.html)



How to stop periods from ruining links? - DrXotick - 2014-03-01

Anytime someone writes a link and adds a period at the end, MyBB includes the period as part of the link, which ruins the link when someone tries to go to it.

Anyway to fix this? It doesn't seem to happen with the default theme here at community.mybb.com. Not sure what the issue could be.


RE: How to stop periods from ruining links? - Nathan Malcolm - 2014-03-01

It's a known issue. There's a WIP patch on Github if you wish to test it out:

https://github.com/mybb/mybb/pull/110.patch


RE: How to stop periods from ruining links? - DrXotick - 2014-03-01

Which version should I follow?

It looks like there are several solutions there. The latest one at the bottom doesn't seem to match my parser.php.


RE: How to stop periods from ruining links? - Nathan Malcolm - 2014-03-01

Edit ./inc/class_parser.php and replace:

	/**
	* Parses URLs automatically.
	*
	* @param string The message to be parsed
	* @return string The parsed message.
	*/
	function mycode_auto_url($message)
	{	
		$message = " ".$message;
		$message = preg_replace("#([\>\s\(\)])(http|https|ftp|news){1}://([^\/\"\s\<\[\.]+\.([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message);
		$message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2.$3[/url]", $message);
		$message = my_substr($message, 1);
		
		return $message;
	}

with:

	/**
	* Parses URLs automatically.
	*
	* @param string The message to be parsed
	* @return string The parsed message.
	*/
	function mycode_auto_url($message)
	{
		$message = " ".$message;
		// Links should end with slashes, numbers, characters and braces but not with dots, commas or question marks
		$message = preg_replace_callback("#([\>\s\(\)])(http|https|ftp|news){1}://([^\/\"\s\<\[\.]+\.([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<]*)?([\w\/\)]))#iu", array($this, 'mycode_auto_url_callback'), $message);
		$message = preg_replace_callback("#([\>\s\(\)])(www|ftp)\.(([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<]*)?([\w\/\)]))#iu", array($this, 'mycode_auto_url_callback'), $message);
		$message = my_substr($message, 1);
		
		return $message;
	}

	/**
	* Parses URLs automatically.
	*
	* @param array Matches
	* @return string The parsed message.
	*/
	function mycode_auto_url_callback($matches)
	{
		$external = '';
		// Allow links like http://en.wikipedia.org/wiki/PHP_(disambiguation) but detect mismatching braces
		while(my_substr($matches[3], -1) == ')')
		{
			if(substr_count($matches[3], ')') > substr_count($matches[3], '('))
			{
				$matches[3] = my_substr($matches[3], 0, -1);
				$external = ')'.$external;
			}
			else
			{
				break;
			}

			// Example: ([...] http://en.wikipedia.org/Example_(disambiguation).)
			$last_char = my_substr($matches[3], -1);
			while($last_char == '.' || $last_char == ',' || $last_char == '?')
			{
				$matches[3] = my_substr($matches[3], 0, -1);
				$external = $last_char.$external;
				$last_char = my_substr($matches[3], -1);
			}
		}
		if($matches[2] == 'www' || $matches[2] == 'ftp')
		{
			return "{$matches[1]}[url]{$matches[2]}.{$matches[3]}[/url]{$external}";
		}
		else
		{
			return "{$matches[1]}[url]{$matches[2]}://{$matches[3]}[/url]{$external}";
		}
	}

For future reference, you can apply patches using the 'patch' utility on Linux.

cd /path/to/mybb
wget https://github.com/mybb/mybb/pull/110.patch
patch -p1 110.patch



RE: How to stop periods from ruining links? - DrXotick - 2014-03-01

Okay. That worked. I just wasn't sure which to apply.

I found this as well after following some links from your first link.

https://github.com/Stefan-ST/mybb/commit/ab9374c7ad09853928daf65434867e0df5921918

I assume it's the same patch.

Thanks for your time.