public
Description: Wordpress plugin to add target='_blank' to external links
Homepage: http://veilleperso.com
Clone URL: git://github.com/veilleperso/or_target_blank.git
Search Repo:
Bug fix pattern matching
veilleperso (author)
Wed Apr 09 07:34:50 -0700 2008
commit  1ff3828c5fcf548e1aed9e871939f28b76d48f82
tree    5e9504da9188121429778998c1e0ec9799a26dbd
parent  35ce91178048d3766620e5c6cee88d6c183578f4
...
3
4
5
6
 
7
8
9
10
11
 
12
13
14
 
15
16
17
18
19
20
 
21
22
23
24
25
26
 
 
 
 
 
...
3
4
5
 
6
7
8
9
10
 
11
12
13
 
14
15
16
17
18
19
 
20
21
22
23
 
 
 
24
25
26
27
28
0
@@ -3,25 +3,27 @@
0
   Plugin Name: Target Blank
0
   Plugin Author: Olivier Ruffin
0
   Description: A Wordpress plugin to add a target='_blank' to all post and comments links which are external to the blog
0
- Version: 1.0
0
+ Version: 1.1
0
   Author: Olivier Ruffin
0
   Author URI: http://veilleperso.com
0
 */
0
 
0
-define('OR_EXTERNAL_LINK', "/^".preg_quote(get_option("siteurl"), "/i")."/");
0
+define('OR_INTERNAL_LINK', "/^".preg_quote(get_option("siteurl"), "/i")."/");
0
 
0
 function or_convert_external_link($matches) {
0
- if (preg_match(OR_EXTERNAL_LINK, $matches[2])) return "<a href=\"$matches[2]\"$matches[1]$matches[3]>";
0
+ if (preg_match(OR_INTERNAL_LINK, $matches[2])) return "<a href=\"$matches[2]\"$matches[1]$matches[3]>";
0
   else return "<a href=\"$matches[2]\"$matches[1]$matches[3] target=\"_blank\">";
0
 }
0
   
0
 function or_external_link($text) {
0
   // use a target blank on external links
0
- $pattern = '/<a(.*?)href=[\"\'](https*:\/\/.*?)[\"\'](.*?)>/i';
0
+ $pattern = '/<a([^>]*?)href=[\"\'](https*:\/\/.*?)[\"\']([^>]*?)>/i';
0
   return preg_replace_callback($pattern, 'or_convert_external_link', $text);
0
 }
0
 
0
-add_filter('comment_text', 'or_external_link', 999);
0
-add_filter('the_content', 'or_external_link', 999);
0
-add_filter('get_comment_author_link', 'or_external_link', 999);
0
+if (!is_feed()) {
0
+ add_filter('comment_text', 'or_external_link', 999);
0
+ add_filter('the_content', 'or_external_link', 999);
0
+ add_filter('get_comment_author_link', 'or_external_link', 999);
0
+}

Comments

    No one has commented yet.