<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="modx.smith.en.xsl"?>
<mod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phpbb.com/mods/xml/modx-1.2.2.xsd">
	<header>
		<license>GNU General Public License v2</license>
		
		<title lang="en">Shorten Long URLs</title>
		
		<description lang="en">
			Shortens display of long urls entered in [url]link[/url] format.
		</description>
		
		<author-notes lang="en"><![CDATA[
When someone posts a URL longer than 55 characters without using the URL BBCode tags, phpBB 3's "magic URLs" feature displays the link in a shortened form to prevent an unsightly appearance, such as the link stretching the width of a page or forcing users to scroll to the side to see some content.However, this form of shortening is not applied to the same URLs if they are posted using the URL BBCode format of [url]address[/url].

This modification applies a similar shortening technique at the time of posting. The [url]address[/url] BBCode is automatically converted to the similar [url=address]text[/url] format. The displayed text of the link still uses a portion of the address, but there is no longer threat of display issues caused by the link.
		]]></author-notes>
		
		<author-group>
			<author>
				<username>Thoul</username>
				<homepage>http://www.phpbbsmith.com</homepage>
			</author>
		</author-group>
		
		<mod-version>1.0.0</mod-version>
		
		<installation>
			<level>easy</level>
			<time>120</time>
			<target-version>3.0.5</target-version>
		</installation>

		<history>
			<entry>
				<date>2009-06-27</date>
				<rev-version>1.0.0</rev-version>
				<changelog lang="en">
					<change>Initial release.</change>
				</changelog>
			</entry>
		</history>
	</header>
	
	<action-group>
		<open src="includes/message_parser.php">
			<edit>
				<find><![CDATA[			return ($var1) ? '[url=' . $this->bbcode_specialchars($url) . ':' . $this->bbcode_uid . ']' . $var2 . '[/url:' . $this->bbcode_uid . ']' : '[url:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($url) . '[/url:' . $this->bbcode_uid . ']';]]></find>
				<action type="before-add"><![CDATA[//----------------------------------------------------------------------
// Shorten Long URLs - Begin Code Alteration
//
			if( !$var1 )
			{
				// We have a url entered as [url]fullurl[/url]
				// This would normally display the full url as the link text,
				// but very long urls or unbroken strings may stretch the page.
				if( strlen($url) > 55 )
				{
					// We have a potential problem url, so let's give it a shortened text.
					$var1	= $url;
					// Strip the schema and www. from the link text to prevent
					// magic url parsing from hiding the link by parsing the
					// text as a link
					$var2	= preg_replace('#^([a-z][a-z\d+\-.]*:/{2})(www.)?#i', '', $url);
					$var2	= substr($var2, 0, 39) . ' ... ' . substr($var2, -10);
					$var2	= $this->bbcode_specialchars($var2);
				}
			}
//
// Shorten Long URLs - End Code Alteration
//----------------------------------------------------------------------]]>
</action>
			</edit>
		</open>
	</action-group>
</mod>
