<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joseph Scott &#187; makeitlink</title>
	<atom:link href="http://josephscott.org/archives/tag/makeitlink/feed/" rel="self" type="application/rss+xml" />
	<link>http://josephscott.org</link>
	<description></description>
	<lastBuildDate>Thu, 29 Jul 2010 16:56:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
	<atom:link rel='hub' href='http://josephscott.org/?pushpress=hub'/>
<cloud domain='josephscott.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>MakeItLink Update</title>
		<link>http://josephscott.org/archives/2009/10/makeitlink-update/</link>
		<comments>http://josephscott.org/archives/2009/10/makeitlink-update/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 14:01:24 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[makeitlink]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://josephscott.org/archives/2009/10/makeitlink-update/</guid>
		<description><![CDATA[With the upcoming release of WordPress 2.9 I thought this would be a good time to re-sync my original MakeItLink PHP class. I went back and did some additional checks with the make_clickable function in WordPress and found a few cases where it wasn&#8217;t generating the expected URL. That resulted in ticket #10990 and just [...]


Related posts:<ol><li><a href='http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/' rel='bookmark' title='Permanent Link: MakeItLink &#8211; Detecting URLs In Text And Making Them Links'>MakeItLink &#8211; Detecting URLs In Text And Making Them Links</a></li>
<li><a href='http://josephscott.org/code/php/makeitlink/' rel='bookmark' title='Permanent Link: MakeItLink'>MakeItLink</a></li>
<li><a href='http://josephscott.org/archives/2009/02/update-on-libxml2-issues/' rel='bookmark' title='Permanent Link: Update On libxml2 Issues'>Update On libxml2 Issues</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>With the upcoming release of WordPress 2.9 I thought this would be a good time to re-sync my <a href="http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/">original MakeItLink PHP class</a>.  I went back and did some additional checks with the make_clickable function in WordPress and found a few cases where it wasn&#8217;t generating the expected URL.  That resulted in <a href="http://core.trac.wordpress.org/ticket/10990">ticket #10990</a> and just like before filosofo did a great job of improving my fix.</p>
<p>After a few rounds of tests (from <a href="http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_formatting.php">text_includes_formatting.php</a>) the various example strings all worked as expected.  The last diff by filosofo has been committed to -trunk and will be part of WordPress 2.9.</p>
<p>I expanded my <a href="http://josephscott.org/code/php/makeitlink/">MakeItLink page</a> with an updated version of the code (0.2.0), a basic example and some background.  For those who want to go right into the code it&#8217;s available <a href="http://josephscott.org/projects/code/php/makeitlink/makeitlink.php.txt">here</a>.</p>


<p>Related posts:<ol><li><a href='http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/' rel='bookmark' title='Permanent Link: MakeItLink &#8211; Detecting URLs In Text And Making Them Links'>MakeItLink &#8211; Detecting URLs In Text And Making Them Links</a></li>
<li><a href='http://josephscott.org/code/php/makeitlink/' rel='bookmark' title='Permanent Link: MakeItLink'>MakeItLink</a></li>
<li><a href='http://josephscott.org/archives/2009/02/update-on-libxml2-issues/' rel='bookmark' title='Permanent Link: Update On libxml2 Issues'>Update On libxml2 Issues</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2009/10/makeitlink-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MakeItLink &#8211; Detecting URLs In Text And Making Them Links</title>
		<link>http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/</link>
		<comments>http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 16:00:56 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[makeitlink]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=467</guid>
		<description><![CDATA[In late October Jeff Atwood wrote about The Problems With URLs, describing the problems of parsing out URLs in text and transforming them into links. Here&#8217;s a simple example: My website is at http://josephscott.org/ Would be changed into: My website is at &#60;a href=&#8217;http://josephscott.org/&#8217;&#62;http://josephscott.org/&#60;/a&#62; Sounds simple right? Once you start looking at what the valid [...]


Related posts:<ol><li><a href='http://josephscott.org/code/php/makeitlink/' rel='bookmark' title='Permanent Link: MakeItLink'>MakeItLink</a></li>
<li><a href='http://josephscott.org/archives/2009/10/makeitlink-update/' rel='bookmark' title='Permanent Link: MakeItLink Update'>MakeItLink Update</a></li>
<li><a href='http://josephscott.org/archives/2010/02/php-helpers-make_slug/' rel='bookmark' title='Permanent Link: PHP Helpers: make_slug'>PHP Helpers: make_slug</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In late October Jeff Atwood wrote about <a href="http://www.codinghorror.com/blog/archives/001181.html">The Problems With URLs</a>, describing the problems of parsing out URLs in text and transforming them into links.  Here&#8217;s a simple example:</p>
<blockquote><p>
My website is at http://josephscott.org/
</p></blockquote>
<p>Would be changed into:</p>
<blockquote><p>
My website is at &lt;a href=&#8217;http://josephscott.org/&#8217;&gt;http://josephscott.org/&lt;/a&gt;
</p></blockquote>
<p>Sounds simple right?  Once you start looking at what the valid character set is for URLs things get tricky.  I won&#8217;t rehash all of items, go the <a href="http://www.codinghorror.com/blog/archives/001181.html">The Problem With URLs</a> post to see an example of some of the problems.</p>
<p>I knew that <a href="http://wordpress.org/">WordPress</a> had a <a href="http://trac.wordpress.org/browser/tags/2.6.5/wp-includes/formatting.php#L685">make_clickable</a> function (in wp-includes/formatting.php) that did this exact thing.  After testing this against some of the problems that Jeff points out it became clear that make_clickable() didn&#8217;t handle these edge cases.  I made some rather crude tweaks to the WordPress code to fix some of these and opened <a href="http://trac.wordpress.org/ticket/8300">ticket 8300</a> with my patches.  Then filosofo came along and not only cleaned up my hacks, but reduced the amount of code needed in general.  Major kudos to filosofo!</p>
<p>At this point it looks like we&#8217;ve got code to make make_clickable() work correctly with problem URLs.  I&#8217;m going to wait until after WordPress 2.7 is released to push for getting this code committed since we&#8217;re trying to get 2.7 wrapped up.</p>
<p>I got thinking, this bit of code would be really handy to have as a stand alone library.  So I pulled out the various pieces of code needed to make this work and put it together in a single PHP class: MakeItLink</p>
<pre class="brush: php;">
class MakeItLink {
    protected function _link_www( $matches ) {
        $url = $matches[2];
        $url = MakeItLink::cleanURL( $url );
        if( empty( $url ) ) {
            return $matches[0];
        }

        return &quot;{$matches[1]}&lt;a href='{$url}'&gt;{$url}&lt;/a&gt;&quot;;
    }

    public function cleanURL( $url ) {
        if( $url == '' ) {
            return $url;
        }

        $url = preg_replace( &quot;|[^a-z0-9-~+_.?#=!&amp;;,/:%@$*'()x80-xff]|i&quot;, '', $url );
        $url = str_replace( array( &quot;%0d&quot;, &quot;%0a&quot; ), '', $url );
        $url = str_replace( &quot;;//&quot;, &quot;://&quot;, $url );

        /* If the URL doesn't appear to contain a scheme, we
         * presume it needs http:// appended (unless a relative
         * link starting with / or a php file).
         */
        if(
            strpos( $url, &quot;:&quot; ) === false
            &amp;&amp; substr( $url, 0, 1 ) != &quot;/&quot;
            &amp;&amp; !preg_match( &quot;|^[a-z0-9-]+?.php|i&quot;, $url )
        ) {
            $url = &quot;http://{$url}&quot;;
        }

        // Replace ampersans and single quotes
        $url = preg_replace( &quot;|&amp;([^#])(?![a-z]{2,8};)|&quot;, &quot;&amp;#038;$1&quot;, $url );
        $url = str_replace( &quot;'&quot;, &quot;&amp;#039;&quot;, $url );

        return $url;
    }

    public function transform( $text ) {
        $text = &quot; {$text}&quot;;

        $text = preg_replace_callback(
            '#(?&lt;=[\s&gt;])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&amp;~/\-=?@\[\](+]|[.,;:](?![\s&lt;])|(?(1)\)(?![\s&lt;])|\)))*)#is',
            array( 'MakeItLink', '_link_www' ),
            $text
        );

        $text = preg_replace( '#(&lt;a( [^&gt;]+?&gt;|&gt;))&lt;a [^&gt;]+?&gt;([^&gt;]+?)&lt;/a&gt;&lt;/a&gt;#i', &quot;$1$3&lt;/a&gt;&quot;, $text );
        $text = trim( $text );

        return $text;
    }
}
</pre>
<p>It&#8217;s very easy to use, just load up the text you want to search for link and call the transform method:</p>
<pre class="brush: php;">
$text = MakeItLink::transform( $text );
</pre>
<p>All of this code came out of WordPress, which is licensed under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GPL</a>, so consider the MakeItLink code GPL as well.  If you&#8217;ve got some improvements let me know and make sure that it gets back into the original WordPress functions as well.</p>


<p>Related posts:<ol><li><a href='http://josephscott.org/code/php/makeitlink/' rel='bookmark' title='Permanent Link: MakeItLink'>MakeItLink</a></li>
<li><a href='http://josephscott.org/archives/2009/10/makeitlink-update/' rel='bookmark' title='Permanent Link: MakeItLink Update'>MakeItLink Update</a></li>
<li><a href='http://josephscott.org/archives/2010/02/php-helpers-make_slug/' rel='bookmark' title='Permanent Link: PHP Helpers: make_slug'>PHP Helpers: make_slug</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-them-links/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>