<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Putting external link icon in WordPress</title>
	<atom:link href="http://codegrad.hub.ph/marking-external-links-icon-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://codegrad.hub.ph/marking-external-links-icon-wordpress/</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 11:45:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Greten</title>
		<link>http://codegrad.hub.ph/marking-external-links-icon-wordpress/#comment-20430</link>
		<dc:creator>Greten</dc:creator>
		<pubDate>Wed, 02 Feb 2011 14:43:28 +0000</pubDate>
		<guid isPermaLink="false">http://codegrad.hub.ph/?p=1051#comment-20430</guid>
		<description>Obsessive nature? Ha ha ha! I&#039;m like that too although I learned lately to focus on what I really need to make life less stressful.

Thank you for sharing that code. I hope one of the visitors of this page will find it useful. Regards!</description>
		<content:encoded><![CDATA[<p>Obsessive nature? Ha ha ha! I&#8217;m like that too although I learned lately to focus on what I really need to make life less stressful.</p>
<p>Thank you for sharing that code. I hope one of the visitors of this page will find it useful. Regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clay</title>
		<link>http://codegrad.hub.ph/marking-external-links-icon-wordpress/#comment-20399</link>
		<dc:creator>Clay</dc:creator>
		<pubDate>Mon, 31 Jan 2011 22:54:28 +0000</pubDate>
		<guid isPermaLink="false">http://codegrad.hub.ph/?p=1051#comment-20399</guid>
		<description>So I have a slightly obsessive nature at times... I generated the following to handle links regardless of their inclusion of a title, to exclude links that contain an image, and to be flexible enough to adapt to other filters (like if you wanted to change the class of a &lt;i&gt;text block&lt;/i&gt; if it contains specific text.)

You can define the start and end of a section to search for (in this case &#039;&lt;a&#039; and &#039;&lt;/a&#039; to find anchors), define a trigger term (in this case &#039;href=&#039; to find linked anchors), and define exclusion terms (so in the case that the trigger term exists within the section but one of the exclusion terms also exists, in this case either an img &#039;&lt;img&#039; or a relative reference &#039;www.domain.com&#039;, &#039;&quot;#&#039;, or &#039;&quot;&quot;&#039;, the new text will not be inserted.

The new text is defined as $r.  The function is not as hairy as it looks -- I just commented it up profusely.

Hope this helps someone :)
C
 
============================================
function exticon( $t ) {
// $n is the needle array, where
// $n[0] defines the section beginning,
// $n[1] defines the trigger term, or the term that determines insertion,
// $n[2] defines the section end,
// $n[3] - $n[n] define exclusion term/s, or the term/s that preclude insertion

      $n = array(
             &quot;&lt;a&quot;,      // section beginning
             &quot;href=&quot;,  // trigger term
             &quot;&lt;/a&quot;,    // section end
             &quot;&lt;img&quot;,  // from here to end - exclusion terms
             &quot;www.domain.com&quot;,
             &quot;\&quot;#&quot;,
             &quot;\&quot;\&quot;&quot;
             );
// $pN is a position marker to move the point of focus along the string
      $pN = 0;
// $r is the text to insert into the string
      $r = &quot; class=\&quot;ext-link\&quot;&quot;;
// $iR is length (+1) of $r to add to marker to account for string padding after insertion
      $iR = strlen( $r ) + 1;
// while the position marker is before the end of the string,
      while( $pN &lt; strlen( $t ) ) {
// get the position of the first element of the needle array
// ( if the element does not appear, the result is FALSE )
             $p[0] = strpos( $t, $n[0], $pN );
// if section beginning exists,
             if( $p[0] ) {
// get the position of the remaining elements of the needle array
             for( $i = 1; $i &lt; count( $n ); $i++ ) {
                  $p[$i] = strpos( $t, $n[$i], $p[0] );
             }
// move the marker to the section end and
                 $pN = $p[2] + 1;
// if trigger term exists within the section,
                 if( $p[1] &amp;&amp; ( $p[1] &lt; $p[2] ) ) {
// check for the exclusion terms --
                     for( $j = 3; $j &lt; count( $n ); $j++ ) {
                          if( $p[$j] &amp;&amp; ( $p[$j] &lt; $p[2] ) ) {
// if ANY exist within the section, move the marker to the section end and restart the while loop
                              $pN = $p[2] + 1;
                              continue 2;
                          }
                     }
// set position for insertion at 2 past section beginning
                     $pR = $p[0] + 2;
// insert $r
                     $t = substr_replace( $t, $r, $pR, 0 );
// move the marker to the section end (padded to account for the insertion text length
                     $pN = $p[2] + $iR;
                 }
// if there is no section beginning string, break the loop
             } else break;
      }
      return $t;
}</description>
		<content:encoded><![CDATA[<p>So I have a slightly obsessive nature at times&#8230; I generated the following to handle links regardless of their inclusion of a title, to exclude links that contain an image, and to be flexible enough to adapt to other filters (like if you wanted to change the class of a <i>text block</i> if it contains specific text.)</p>
<p>You can define the start and end of a section to search for (in this case &#8216;&lt;a&#039; and &#039;&lt;/a&#039; to find anchors), define a trigger term (in this case &#039;href=&#039; to find linked anchors), and define exclusion terms (so in the case that the trigger term exists within the section but one of the exclusion terms also exists, in this case either an img &#039;&lt;img&#039; or a relative reference &#039;www.domain.com&#039;, &#039;&quot;#&#039;, or &#039;&quot;&quot;&#039;, the new text will not be inserted.</p>
<p>The new text is defined as $r.  The function is not as hairy as it looks &#8212; I just commented it up profusely.</p>
<p>Hope this helps someone <img src='http://codegrad.hub.ph/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
C</p>
<p>============================================<br />
function exticon( $t ) {<br />
// $n is the needle array, where<br />
// $n[0] defines the section beginning,<br />
// $n[1] defines the trigger term, or the term that determines insertion,<br />
// $n[2] defines the section end,<br />
// $n[3] &#8211; $n[n] define exclusion term/s, or the term/s that preclude insertion</p>
<p>      $n = array(<br />
             &quot;&lt;a&quot;,      // section beginning<br />
             &quot;href=&quot;,  // trigger term<br />
             &quot;&lt;/a&quot;,    // section end<br />
             &quot;&lt;img&quot;,  // from here to end &#8211; exclusion terms<br />
             &quot;www.domain.com&quot;,<br />
             &quot;\&quot;#&quot;,<br />
             &quot;\&quot;\&quot;&quot;<br />
             );<br />
// $pN is a position marker to move the point of focus along the string<br />
      $pN = 0;<br />
// $r is the text to insert into the string<br />
      $r = &quot; class=\&quot;ext-link\&quot;&quot;;<br />
// $iR is length (+1) of $r to add to marker to account for string padding after insertion<br />
      $iR = strlen( $r ) + 1;<br />
// while the position marker is before the end of the string,<br />
      while( $pN &lt; strlen( $t ) ) {<br />
// get the position of the first element of the needle array<br />
// ( if the element does not appear, the result is FALSE )<br />
             $p[0] = strpos( $t, $n[0], $pN );<br />
// if section beginning exists,<br />
             if( $p[0] ) {<br />
// get the position of the remaining elements of the needle array<br />
             for( $i = 1; $i &lt; count( $n ); $i++ ) {<br />
                  $p[$i] = strpos( $t, $n[$i], $p[0] );<br />
             }<br />
// move the marker to the section end and<br />
                 $pN = $p[2] + 1;<br />
// if trigger term exists within the section,<br />
                 if( $p[1] &amp;&amp; ( $p[1] &lt; $p[2] ) ) {<br />
// check for the exclusion terms &#8211;<br />
                     for( $j = 3; $j &lt; count( $n ); $j++ ) {<br />
                          if( $p[$j] &amp;&amp; ( $p[$j] &lt; $p[2] ) ) {<br />
// if ANY exist within the section, move the marker to the section end and restart the while loop<br />
                              $pN = $p[2] + 1;<br />
                              continue 2;<br />
                          }<br />
                     }<br />
// set position for insertion at 2 past section beginning<br />
                     $pR = $p[0] + 2;<br />
// insert $r<br />
                     $t = substr_replace( $t, $r, $pR, 0 );<br />
// move the marker to the section end (padded to account for the insertion text length<br />
                     $pN = $p[2] + $iR;<br />
                 }<br />
// if there is no section beginning string, break the loop<br />
             } else break;<br />
      }<br />
      return $t;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greten</title>
		<link>http://codegrad.hub.ph/marking-external-links-icon-wordpress/#comment-20361</link>
		<dc:creator>Greten</dc:creator>
		<pubDate>Sat, 29 Jan 2011 19:17:11 +0000</pubDate>
		<guid isPermaLink="false">http://codegrad.hub.ph/?p=1051#comment-20361</guid>
		<description>Thanks Clay, your solution has been incorporated in this post. I just realized that I don&#039;t really need to scan the &quot;&lt;a&quot; part since whenever href is used, it is always there.</description>
		<content:encoded><![CDATA[<p>Thanks Clay, your solution has been incorporated in this post. I just realized that I don&#8217;t really need to scan the &#8220;&lt;a&#8221; part since whenever href is used, it is always there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clay</title>
		<link>http://codegrad.hub.ph/marking-external-links-icon-wordpress/#comment-20348</link>
		<dc:creator>Clay</dc:creator>
		<pubDate>Fri, 28 Jan 2011 17:47:50 +0000</pubDate>
		<guid isPermaLink="false">http://codegrad.hub.ph/?p=1051#comment-20348</guid>
		<description>I&#039;ve changed the code to scan for &#039;&quot; href&#039; instead of &#039;&lt;a href&#039; to catch only links with titles, as the above code misses those and also adds the external link icon to any linked images (awkward...)

Since WP adds the title between &#039;&lt;a &#039; and &#039;href=&#039;, the above code ignores any posts with titles.  We entitle all posts on our blog, so the replacement I have suggested works for us.  Of course, if you only entitle _some_, neither solution works for everything.

My $0.02.  I will post a more comprehensive solution if I ever figure out how to wrangle regular expressions to auto-detect &lt;a&gt;&lt;/a&gt; and keep those from being updated.

Cheers
C</description>
		<content:encoded><![CDATA[<p>I&#8217;ve changed the code to scan for &#8216;&#8221; href&#8217; instead of &#8216;&lt;a href&#039; to catch only links with titles, as the above code misses those and also adds the external link icon to any linked images (awkward&#8230;)</p>
<p>Since WP adds the title between &#039;&lt;a &#039; and &#039;href=&#039;, the above code ignores any posts with titles.  We entitle all posts on our blog, so the replacement I have suggested works for us.  Of course, if you only entitle _some_, neither solution works for everything.</p>
<p>My $0.02.  I will post a more comprehensive solution if I ever figure out how to wrangle regular expressions to auto-detect <a></a> and keep those from being updated.</p>
<p>Cheers<br />
C</p>
]]></content:encoded>
	</item>
</channel>
</rss>

