Version Description
- Fixed also check url's starting with //
- Fixed wpel_external_link also applied on ignored links
Download this release
Release Info
Developer | freelancephp |
Plugin | WP External Links (nofollow new tab seo) |
Version | 1.51 |
Comparing to | |
See all releases |
Code changes from version 1.50 to 1.51
- LICENSE +20 -0
- README.md +6 -0
- includes/class-wp-external-links.php +32 -32
- readme.txt +11 -4
- wp-external-links.php +2 -2
LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The MIT License (MIT)
|
2 |
+
|
3 |
+
Copyright (c) 2014 Victor Villaverde Laan
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6 |
+
this software and associated documentation files (the "Software"), to deal in
|
7 |
+
the Software without restriction, including without limitation the rights to
|
8 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10 |
+
subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
README.md
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
WP-External-Links
|
2 |
+
=================
|
3 |
+
|
4 |
+
Put it on Github so everybody can contribute code changes.
|
5 |
+
|
6 |
+
See http://wordpress.org/plugins/wp-external-links/
|
includes/class-wp-external-links.php
CHANGED
@@ -202,19 +202,29 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
202 |
* @return boolean
|
203 |
*/
|
204 |
private function is_external( $href, $rel ) {
|
205 |
-
// check if this links should be ignored
|
206 |
-
for ( $x = 0, $count = count($this->ignored); $x < $count; $x++ ) {
|
207 |
-
if ( strrpos( $href, $this->ignored[ $x ] ) !== FALSE )
|
208 |
-
return FALSE;
|
209 |
-
}
|
210 |
-
|
211 |
return ( isset( $href ) AND ( strpos( $rel, 'external' ) !== FALSE
|
212 |
OR ( strpos( $href, strtolower( get_bloginfo( 'wpurl' ) ) ) === FALSE )
|
213 |
AND ( substr( $href, 0, 7 ) == 'http://'
|
214 |
OR substr( $href, 0, 8 ) == 'https://'
|
215 |
-
OR substr( $href, 0, 6 ) == 'ftp://'
|
|
|
216 |
}
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
/**
|
219 |
* Filter content
|
220 |
* @param string $content
|
@@ -266,7 +276,6 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
266 |
$space = ' '; # a single space
|
267 |
|
268 |
foreach ( $attrs as $j => $curr ) {
|
269 |
-
|
270 |
if ( $mode < 0 ) {# name
|
271 |
if ( '=' === $curr ) {
|
272 |
$mode = 1;
|
@@ -283,6 +292,7 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
283 |
}
|
284 |
}
|
285 |
} elseif ( $mode > 0 ) {# value
|
|
|
286 |
if ( $stop === false ) {
|
287 |
if ( ! ctype_space($curr) ) {
|
288 |
if ( '"' === $curr || "'" === $curr ) {
|
@@ -336,9 +346,13 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
336 |
$href = trim( $href );
|
337 |
|
338 |
// check if it is an external link and not excluded
|
339 |
-
if ( ! $this->is_external( $href, $rel )
|
340 |
return $matches[ 0 ];
|
341 |
|
|
|
|
|
|
|
|
|
342 |
// set rel="external" (when not already set)
|
343 |
if ( $this->get_opt( 'external' ) )
|
344 |
$this->add_attr_value( $attrs, 'rel', 'external' );
|
@@ -348,8 +362,9 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
348 |
$this->add_attr_value( $attrs, 'rel', 'nofollow' );
|
349 |
|
350 |
// set title
|
351 |
-
$
|
352 |
-
|
|
|
353 |
|
354 |
// set user-defined class
|
355 |
$class = $this->get_opt( 'class_name' );
|
@@ -377,18 +392,16 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
377 |
}
|
378 |
|
379 |
// create element code
|
380 |
-
$link = '<a
|
381 |
|
382 |
-
foreach ( $attrs AS $key => $value )
|
383 |
-
$link .= $key .'="'. $value .'"
|
384 |
-
|
385 |
-
// remove last space
|
386 |
-
$link = substr( $link, 0, -1 );
|
387 |
|
388 |
$link .= '>'. $matches[ 2 ] .'</a>';
|
389 |
|
390 |
// filter
|
391 |
-
$link = apply_filters('wpel_external_link', $link, $matches[ 0 ], $matches[ 2 ], $attrs);
|
392 |
|
393 |
return $link;
|
394 |
}
|
@@ -454,19 +467,6 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
454 |
// set document
|
455 |
$doc = phpQuery::newDocument( $content );
|
456 |
|
457 |
-
/*
|
458 |
-
$regexp_xml = '/<\?xml(.*?)\?>/is';
|
459 |
-
$regexp_xhtml = '/<!DOCTYPE(.*?)xhtml(.*?)>/is';
|
460 |
-
|
461 |
-
if ( preg_match( $regexp_xml, $content ) > 0 ) {
|
462 |
-
$doc = phpQuery::newDocumentXML( $content, get_bloginfo( 'charset' ) );
|
463 |
-
} elseif ( preg_match( $regexp_xhtml, $content ) > 0 ) {
|
464 |
-
$doc = phpQuery::newDocumentXHTML( $content, get_bloginfo( 'charset' ) );
|
465 |
-
} else {
|
466 |
-
$doc = phpQuery::newDocumentHTML( $content, get_bloginfo( 'charset' ) );
|
467 |
-
}
|
468 |
-
*/
|
469 |
-
|
470 |
$excl_sel = $this->get_opt( 'filter_excl_sel' );
|
471 |
|
472 |
// set excludes
|
@@ -524,7 +524,7 @@ var wpExtLinks = { baseUrl: '<?php echo get_bloginfo( 'wpurl' ) ?>', target: '<?
|
|
524 |
$rel = strtolower( $a->attr( 'rel' ) . '' );
|
525 |
|
526 |
// check if it is an external link and not excluded
|
527 |
-
if ( ! $this->is_external( $href, $rel ) )
|
528 |
return $a;
|
529 |
|
530 |
// add "external" to rel-attribute
|
202 |
* @return boolean
|
203 |
*/
|
204 |
private function is_external( $href, $rel ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
return ( isset( $href ) AND ( strpos( $rel, 'external' ) !== FALSE
|
206 |
OR ( strpos( $href, strtolower( get_bloginfo( 'wpurl' ) ) ) === FALSE )
|
207 |
AND ( substr( $href, 0, 7 ) == 'http://'
|
208 |
OR substr( $href, 0, 8 ) == 'https://'
|
209 |
+
OR substr( $href, 0, 6 ) == 'ftp://'
|
210 |
+
OR substr( $href, 0, 2 ) == '//' ) ) );
|
211 |
}
|
212 |
|
213 |
+
/**
|
214 |
+
* Is an ignored link
|
215 |
+
* @param string $href
|
216 |
+
* @return boolean
|
217 |
+
*/
|
218 |
+
private function is_ignored( $href ) {
|
219 |
+
// check if this links should be ignored
|
220 |
+
for ( $x = 0, $count = count($this->ignored); $x < $count; $x++ ) {
|
221 |
+
if ( strrpos( $href, $this->ignored[ $x ] ) !== FALSE )
|
222 |
+
return TRUE;
|
223 |
+
}
|
224 |
+
|
225 |
+
return FALSE;
|
226 |
+
}
|
227 |
+
|
228 |
/**
|
229 |
* Filter content
|
230 |
* @param string $content
|
276 |
$space = ' '; # a single space
|
277 |
|
278 |
foreach ( $attrs as $j => $curr ) {
|
|
|
279 |
if ( $mode < 0 ) {# name
|
280 |
if ( '=' === $curr ) {
|
281 |
$mode = 1;
|
292 |
}
|
293 |
}
|
294 |
} elseif ( $mode > 0 ) {# value
|
295 |
+
|
296 |
if ( $stop === false ) {
|
297 |
if ( ! ctype_space($curr) ) {
|
298 |
if ( '"' === $curr || "'" === $curr ) {
|
346 |
$href = trim( $href );
|
347 |
|
348 |
// check if it is an external link and not excluded
|
349 |
+
if ( ! $this->is_external( $href, $rel ))
|
350 |
return $matches[ 0 ];
|
351 |
|
352 |
+
if ( $this->is_ignored( $href ) ) {
|
353 |
+
return apply_filters('wpel_external_link', $matches[ 0 ], $matches[ 0 ], $matches[ 2 ], $attrs, true);
|
354 |
+
}
|
355 |
+
|
356 |
// set rel="external" (when not already set)
|
357 |
if ( $this->get_opt( 'external' ) )
|
358 |
$this->add_attr_value( $attrs, 'rel', 'external' );
|
362 |
$this->add_attr_value( $attrs, 'rel', 'nofollow' );
|
363 |
|
364 |
// set title
|
365 |
+
$title_format = $this->get_opt( 'title' );
|
366 |
+
$title = ( isset( $attrs[ 'title' ] ) ) ? $attrs[ 'title' ] : '';
|
367 |
+
$attrs[ 'title' ] = str_replace( '%title%', $title, $title_format );
|
368 |
|
369 |
// set user-defined class
|
370 |
$class = $this->get_opt( 'class_name' );
|
392 |
}
|
393 |
|
394 |
// create element code
|
395 |
+
$link = '<a';
|
396 |
|
397 |
+
foreach ( $attrs AS $key => $value ) {
|
398 |
+
$link .= ' '. $key .'="'. $value .'"';
|
399 |
+
}
|
|
|
|
|
400 |
|
401 |
$link .= '>'. $matches[ 2 ] .'</a>';
|
402 |
|
403 |
// filter
|
404 |
+
$link = apply_filters('wpel_external_link', $link, $matches[ 0 ], $matches[ 2 ], $attrs, false);
|
405 |
|
406 |
return $link;
|
407 |
}
|
467 |
// set document
|
468 |
$doc = phpQuery::newDocument( $content );
|
469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
$excl_sel = $this->get_opt( 'filter_excl_sel' );
|
471 |
|
472 |
// set excludes
|
524 |
$rel = strtolower( $a->attr( 'rel' ) . '' );
|
525 |
|
526 |
// check if it is an external link and not excluded
|
527 |
+
if ( ! $this->is_external( $href, $rel ) || $this->is_ignored( $href ) )
|
528 |
return $a;
|
529 |
|
530 |
// add "external" to rel-attribute
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: freelancephp
|
3 |
Tags: links, external, icon, target, _blank, _new, _none, rel, nofollow, new window, new tab, javascript, xhtml, seo
|
4 |
Requires at least: 3.4.0
|
5 |
-
Tested up to: 3.8.
|
6 |
-
Stable tag: 1.
|
7 |
|
8 |
Open external links in a new window or tab, adding "nofollow", set link icon, styling, SEO friendly options and more. Easy install and go.
|
9 |
|
@@ -29,6 +29,9 @@ After activating the plugin all options are already set to make your external li
|
|
29 |
This plugin has the same [requirements](http://wordpress.org/about/requirements/) as WordPress.
|
30 |
If you are experiencing any problems, just take a look at the [FAQ](http://wordpress.org/extend/plugins/wp-external-links/faq/) or report it in the [support section](http://wordpress.org/support/plugin/wp-external-links). You can also send me a mail with [this contactform](http://www.freelancephp.net/contact/).
|
31 |
|
|
|
|
|
|
|
32 |
= Like this plugin? =
|
33 |
Please [rate this plugin](http://wordpress.org/support/view/plugin-reviews/wp-external-links-plugin) or [post a comment](http://www.freelancephp.net/wp-external-links-plugin/) on my blog.
|
34 |
|
@@ -62,7 +65,7 @@ add_action('wpel_ready', 'extra_filters');`
|
|
62 |
|
63 |
= Filter hook =
|
64 |
The wpel_external_link filter gives you the possibility to manipulate output of the mailto created by the plugin, like:
|
65 |
-
`function special_external_link($created_link, $original_link, $label, $attrs
|
66 |
// skip links that contain the class "not-external"
|
67 |
if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
|
68 |
return $original_link;
|
@@ -70,7 +73,7 @@ The wpel_external_link filter gives you the possibility to manipulate output of
|
|
70 |
|
71 |
return '<b>'. $created_link .'</b>';
|
72 |
}
|
73 |
-
add_filter('wpel_external_link', 'special_external_link', 10,
|
74 |
|
75 |
Now all external links will be processed and wrapped around a `<b>`-tag. And links containing the class "not-external" will not be processed by the plugin at all (and stay the way they are).
|
76 |
|
@@ -81,6 +84,10 @@ Now all external links will be processed and wrapped around a `<b>`-tag. And lin
|
|
81 |
|
82 |
== Changelog ==
|
83 |
|
|
|
|
|
|
|
|
|
84 |
= 1.50 =
|
85 |
* Removed stylesheet file to save extra request
|
86 |
* Added option for loading js file in wp_footer
|
2 |
Contributors: freelancephp
|
3 |
Tags: links, external, icon, target, _blank, _new, _none, rel, nofollow, new window, new tab, javascript, xhtml, seo
|
4 |
Requires at least: 3.4.0
|
5 |
+
Tested up to: 3.8.2
|
6 |
+
Stable tag: 1.51
|
7 |
|
8 |
Open external links in a new window or tab, adding "nofollow", set link icon, styling, SEO friendly options and more. Easy install and go.
|
9 |
|
29 |
This plugin has the same [requirements](http://wordpress.org/about/requirements/) as WordPress.
|
30 |
If you are experiencing any problems, just take a look at the [FAQ](http://wordpress.org/extend/plugins/wp-external-links/faq/) or report it in the [support section](http://wordpress.org/support/plugin/wp-external-links). You can also send me a mail with [this contactform](http://www.freelancephp.net/contact/).
|
31 |
|
32 |
+
= Github =
|
33 |
+
I published the code on [Github](https://github.com/freelancephp/WP-External-Links) so anybody can commit code changes.
|
34 |
+
|
35 |
= Like this plugin? =
|
36 |
Please [rate this plugin](http://wordpress.org/support/view/plugin-reviews/wp-external-links-plugin) or [post a comment](http://www.freelancephp.net/wp-external-links-plugin/) on my blog.
|
37 |
|
65 |
|
66 |
= Filter hook =
|
67 |
The wpel_external_link filter gives you the possibility to manipulate output of the mailto created by the plugin, like:
|
68 |
+
`function special_external_link($created_link, $original_link, $label, $attrs, $is_ignored_link) {
|
69 |
// skip links that contain the class "not-external"
|
70 |
if (isset($attrs['class']) && strpos($attrs['class'], 'not-external') !== false) {
|
71 |
return $original_link;
|
73 |
|
74 |
return '<b>'. $created_link .'</b>';
|
75 |
}
|
76 |
+
add_filter('wpel_external_link', 'special_external_link', 10, 5);`
|
77 |
|
78 |
Now all external links will be processed and wrapped around a `<b>`-tag. And links containing the class "not-external" will not be processed by the plugin at all (and stay the way they are).
|
79 |
|
84 |
|
85 |
== Changelog ==
|
86 |
|
87 |
+
= 1.51 =
|
88 |
+
* Fixed also check url's starting with //
|
89 |
+
* Fixed wpel_external_link also applied on ignored links
|
90 |
+
|
91 |
= 1.50 =
|
92 |
* Removed stylesheet file to save extra request
|
93 |
* Added option for loading js file in wp_footer
|
wp-external-links.php
CHANGED
@@ -4,14 +4,14 @@ Plugin Name: WP External Links
|
|
4 |
Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
|
5 |
Description: Open external links in a new window/tab, add "external" / "nofollow" to rel-attribute, set icon, XHTML strict, SEO friendly...
|
6 |
Author: Victor Villaverde Laan
|
7 |
-
Version: 1.
|
8 |
Author URI: http://www.freelancephp.net
|
9 |
License: Dual licensed under the MIT and GPL licenses
|
10 |
*/
|
11 |
|
12 |
// constants
|
13 |
if (!defined('WP_EXTERNAL_LINKS_FILE')) { define('WP_EXTERNAL_LINKS_FILE', __FILE__); }
|
14 |
-
if (!defined('WP_EXTERNAL_LINKS_VERSION')) { define('WP_EXTERNAL_LINKS_VERSION', '1.
|
15 |
if (!defined('WP_EXTERNAL_LINKS_KEY')) { define('WP_EXTERNAL_LINKS_KEY', 'wp_external_links'); }
|
16 |
if (!defined('WP_EXTERNAL_LINKS_DOMAIN')) { define('WP_EXTERNAL_LINKS_DOMAIN', 'wp-external-links'); }
|
17 |
if (!defined('WP_EXTERNAL_LINKS_OPTIONS_NAME')) { define('WP_EXTERNAL_LINKS_OPTIONS_NAME', 'WP_External_Links_options'); }
|
4 |
Plugin URI: http://www.freelancephp.net/wp-external-links-plugin
|
5 |
Description: Open external links in a new window/tab, add "external" / "nofollow" to rel-attribute, set icon, XHTML strict, SEO friendly...
|
6 |
Author: Victor Villaverde Laan
|
7 |
+
Version: 1.51
|
8 |
Author URI: http://www.freelancephp.net
|
9 |
License: Dual licensed under the MIT and GPL licenses
|
10 |
*/
|
11 |
|
12 |
// constants
|
13 |
if (!defined('WP_EXTERNAL_LINKS_FILE')) { define('WP_EXTERNAL_LINKS_FILE', __FILE__); }
|
14 |
+
if (!defined('WP_EXTERNAL_LINKS_VERSION')) { define('WP_EXTERNAL_LINKS_VERSION', '1.51'); }
|
15 |
if (!defined('WP_EXTERNAL_LINKS_KEY')) { define('WP_EXTERNAL_LINKS_KEY', 'wp_external_links'); }
|
16 |
if (!defined('WP_EXTERNAL_LINKS_DOMAIN')) { define('WP_EXTERNAL_LINKS_DOMAIN', 'wp-external-links'); }
|
17 |
if (!defined('WP_EXTERNAL_LINKS_OPTIONS_NAME')) { define('WP_EXTERNAL_LINKS_OPTIONS_NAME', 'WP_External_Links_options'); }
|