WP External Links (nofollow new tab seo) - Version 0.33

Version Description

  • Add option to fix js problem
  • Fixed PHP / WP notices
Download this release

Release Info

Developer freelancephp
Plugin Icon 128x128 WP External Links (nofollow new tab seo)
Version 0.33
Comparing to
See all releases

Code changes from version 0.32 to 0.33

Files changed (2) hide show
  1. readme.txt +11 -1
  2. wp-external-links.php +46 -23
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: freelancephp
3
  Tags: links, external, new window, icon, target, _blank, _new, _top, _none, rel, nofollow, javascript, xhtml strict
4
  Requires at least: 2.7.0
5
  Tested up to: 3.1.0
6
- Stable tag: 0.32
7
 
8
  Manage external links on your site: open in new window/tab, set link icon, add "external", add "nofollow" and more.
9
 
@@ -39,6 +39,8 @@ You could use single quotes for defining the string and therefore remove the dou
39
  Or you could prevent the plugin filtering the link by escaping the last slash (`</a>`) like:
40
  `document.write( '<a href="http:://google.com">Google<\/a>' );`
41
 
 
 
42
  In the last case when using the JavaScript method and jQuery the link would still be opened in the target given on the options page.
43
 
44
  [Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
@@ -55,6 +57,10 @@ In the last case when using the JavaScript method and jQuery the link would stil
55
 
56
  == Changelog ==
57
 
 
 
 
 
58
  = 0.32 =
59
  * For jQuery uses live() function so also opens dynamicly created links in given target
60
  * Fixed bug of changing `<abbr>` tag
@@ -93,6 +99,10 @@ In the last case when using the JavaScript method and jQuery the link would stil
93
 
94
  == Upgrade Notice ==
95
 
 
 
 
 
96
  = 0.32 =
97
  * For jQuery uses live() function so also opens dynamicly created links in given target
98
  * Fixed bug of changing `<abbr>` tag
3
  Tags: links, external, new window, icon, target, _blank, _new, _top, _none, rel, nofollow, javascript, xhtml strict
4
  Requires at least: 2.7.0
5
  Tested up to: 3.1.0
6
+ Stable tag: 0.33
7
 
8
  Manage external links on your site: open in new window/tab, set link icon, add "external", add "nofollow" and more.
9
 
39
  Or you could prevent the plugin filtering the link by escaping the last slash (`</a>`) like:
40
  `document.write( '<a href="http:://google.com">Google<\/a>' );`
41
 
42
+ This can be done automatically when enabling the option "Auto-fix javascript problem".
43
+
44
  In the last case when using the JavaScript method and jQuery the link would still be opened in the target given on the options page.
45
 
46
  [Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
57
 
58
  == Changelog ==
59
 
60
+ = 0.33 =
61
+ * Add option to fix js problem
62
+ * Fixed PHP / WP notices
63
+
64
  = 0.32 =
65
  * For jQuery uses live() function so also opens dynamicly created links in given target
66
  * Fixed bug of changing `<abbr>` tag
99
 
100
  == Upgrade Notice ==
101
 
102
+ = 0.33 =
103
+ * Add option to fix js problem
104
+ * Fixed PHP / WP notices
105
+
106
  = 0.32 =
107
  * For jQuery uses live() function so also opens dynamicly created links in given target
108
  * Fixed bug of changing `<abbr>` tag
wp-external-links.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP External Links
4
  Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
5
  Description: Manage external links on your site: open in new window/tab, set link icon, add "external", add "nofollow" and more.
6
  Author: Victor Villaverde Laan
7
- Version: 0.32
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  */
@@ -19,7 +19,7 @@ class WP_External_Links {
19
  * Current version
20
  * @var string
21
  */
22
- var $version = '0.32';
23
 
24
  /**
25
  * Used as prefix for options entry and could be used as text domain (for translations)
@@ -38,19 +38,32 @@ class WP_External_Links {
38
  * @var array
39
  */
40
  var $options = array(
41
- 'target' => '_none',
42
- 'use_js' => 1,
43
- 'external' => 1,
44
- 'nofollow' => 1,
45
- 'filter_whole_page' => 1,
46
- 'filter_posts' => 1,
47
- 'filter_comments' => 1,
48
- 'filter_widgets' => 1,
49
- 'icon' => 0,
50
- 'no_icon_class' => 'no-ext-icon',
51
- 'no_icon_same_window' => 0,
52
- 'class_name' => 'ext-link',
53
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  /**
56
  * PHP4 constructor
@@ -166,10 +179,8 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'url' ) ?>',target: '<?php
166
  * @return string
167
  */
168
  function filter_page( $content ) {
169
- $body_pattern = '/<body(.*?)>(.*?)<\/body[\s+]*>/is';
170
-
171
  // only replace links in <body> part
172
- return preg_replace_callback( $body_pattern, array( $this, '_callback_page_filter' ), $content );
173
  }
174
 
175
  function _callback_page_filter( $match ) {
@@ -182,20 +193,26 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'url' ) ?>',target: '<?php
182
  * @return string
183
  */
184
  function filter_content( $content ) {
185
- $a_pattern = '/<a[^A-Za-z](.*?)>(.*?)<\/a[\s+]*>/is';
 
 
 
186
 
187
  // replace links in body
188
- $content = preg_replace_callback( $a_pattern, array( $this, 'parse_link' ), $content );
189
 
190
  // remove style when no icon classes are found
191
  if ( strpos( $content, 'ext-icon-' ) === FALSE ) {
192
  // remove style with id wp-external-links-css
193
- $content = preg_replace( '/<link(.*?)wp-external-links-css(.*?)\/>[\s+]*/i', '', $content );
194
  }
195
 
196
  return $content;
197
  }
198
 
 
 
 
199
 
200
  /**
201
  * Make a clean <a> code
@@ -380,6 +397,12 @@ jQuery(function( $ ){
380
  <br/><span class="description"><?php _e( 'Note: all <code>&lt;a&gt;</code> tags in the selected contents will be converted to XHTML valid code' ) ?></span>
381
  </td>
382
  </tr>
 
 
 
 
 
 
383
  </table>
384
  </fieldset>
385
  <p class="submit">
@@ -519,7 +542,7 @@ jQuery(function( $ ){
519
  if ( ! isset( $saved_options[ $key ] ) AND $key == 'target' )
520
  continue;
521
 
522
- $this->options[ $key ] = $saved_options[ $key ];
523
  }
524
  }
525
  }
@@ -532,4 +555,4 @@ jQuery(function( $ ){
532
  */
533
  $WP_External_Links = new WP_External_Links;
534
 
535
- ?>
4
  Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
5
  Description: Manage external links on your site: open in new window/tab, set link icon, add "external", add "nofollow" and more.
6
  Author: Victor Villaverde Laan
7
+ Version: 0.33
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  */
19
  * Current version
20
  * @var string
21
  */
22
+ var $version = '0.33';
23
 
24
  /**
25
  * Used as prefix for options entry and could be used as text domain (for translations)
38
  * @var array
39
  */
40
  var $options = array(
41
+ 'target' => '_none',
42
+ 'use_js' => 1,
43
+ 'external' => 1,
44
+ 'nofollow' => 1,
45
+ 'filter_whole_page' => 1,
46
+ 'filter_posts' => 1,
47
+ 'filter_comments' => 1,
48
+ 'filter_widgets' => 1,
49
+ 'fix_js' => 1,
50
+ 'icon' => 0,
51
+ 'no_icon_class' => 'no-ext-icon',
52
+ 'no_icon_same_window' => 0,
53
+ 'class_name' => 'ext-link',
54
+ );
55
+
56
+ /**
57
+ * Regexp
58
+ * @var array
59
+ */
60
+ var $regexp_patterns = array(
61
+ 'a' => '/<a[^A-Za-z](.*?)>(.*?)<\/a[\s+]*>/is',
62
+ 'css' => '/<link(.*?)wp-external-links-css(.*?)\/>[\s+]*/i',
63
+ 'body' => '/<body(.*?)>(.*?)<\/body[\s+]*>/is',
64
+ 'script' => '/<script(.*?)>(.*?)<\/script[\s+]*>/is',
65
+ );
66
+
67
 
68
  /**
69
  * PHP4 constructor
179
  * @return string
180
  */
181
  function filter_page( $content ) {
 
 
182
  // only replace links in <body> part
183
+ return preg_replace_callback( $this->regexp_patterns[ 'body' ], array( $this, '_callback_page_filter' ), $content );
184
  }
185
 
186
  function _callback_page_filter( $match ) {
193
  * @return string
194
  */
195
  function filter_content( $content ) {
196
+ if ( $this->options[ 'fix_js' ] ) {
197
+ // fix js proble by replacing </a> by <\/a>
198
+ $content = preg_replace_callback( $this->regexp_patterns[ 'script' ], array( $this, 'fix_js' ), $content );
199
+ }
200
 
201
  // replace links in body
202
+ $content = preg_replace_callback( $this->regexp_patterns[ 'a' ], array( $this, 'parse_link' ), $content );
203
 
204
  // remove style when no icon classes are found
205
  if ( strpos( $content, 'ext-icon-' ) === FALSE ) {
206
  // remove style with id wp-external-links-css
207
+ $content = preg_replace( $this->regexp_patterns[ 'css' ], '', $content );
208
  }
209
 
210
  return $content;
211
  }
212
 
213
+ function fix_js( $match ) {
214
+ return str_replace( '</a>', '<\/a>', $match[ 0 ] );
215
+ }
216
 
217
  /**
218
  * Make a clean <a> code
397
  <br/><span class="description"><?php _e( 'Note: all <code>&lt;a&gt;</code> tags in the selected contents will be converted to XHTML valid code' ) ?></span>
398
  </td>
399
  </tr>
400
+ <tr>
401
+ <th><?php _e( 'Solve problems...', $this->domain ) ?></th>
402
+ <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[fix_js]" id="fix_js" value="1" <?php checked( '1', (int) $options['fix_js'] ); ?> />
403
+ <span><?php _e( 'Auto-fix javascript problem (by replacing <code>&lt;/a&gt;</code> with <code>&lt;\/a&gt;</code> in js)', $this->domain ) ?></span></label>
404
+ </td>
405
+ </tr>
406
  </table>
407
  </fieldset>
408
  <p class="submit">
542
  if ( ! isset( $saved_options[ $key ] ) AND $key == 'target' )
543
  continue;
544
 
545
+ $this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ];
546
  }
547
  }
548
  }
555
  */
556
  $WP_External_Links = new WP_External_Links;
557
 
558
+ /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */