Version Description
- Take two! With issues now with breaking google adsense code reverted back to 4.2 parsing code but added more advanced dom attribute parsing code to handle various link configurations.
Download this release
Release Info
Developer | Mike_Koepke |
Plugin | External Links |
Version | 5.1 |
Comparing to | |
See all releases |
Code changes from version 5.2 to 5.1
- anchor-utils/anchor-utils.php +18 -17
- readme.txt +2 -7
- sem-external-links-admin.php +6 -21
- sem-external-links.php +11 -20
anchor-utils/anchor-utils.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
* Anchor Utils
|
4 |
* Author: Denis de Bernardy & Mike Koepke <http://www.semiologic.com>
|
5 |
-
* Version: 1.
|
6 |
*/
|
7 |
|
8 |
if ( @ini_get('pcre.backtrack_limit') <= 750000 )
|
@@ -19,14 +19,13 @@ if ( @ini_get('pcre.recursion_limit') <= 250000 )
|
|
19 |
class anchor_utils {
|
20 |
|
21 |
/**
|
22 |
-
*
|
23 |
*/
|
24 |
-
public function __construct(
|
25 |
add_filter('the_content', array($this, 'filter'), 100);
|
26 |
add_filter('the_excerpt', array($this, 'filter'), 100);
|
|
|
27 |
add_filter('comment_text', array($this, 'filter'), 100);
|
28 |
-
if ( $inc_text_widgets )
|
29 |
-
add_filter('widget_text', array($this, 'filter'), 100);
|
30 |
|
31 |
add_action('wp_head', array($this, 'ob_start'), 10000);
|
32 |
} #anchor_utils
|
@@ -62,17 +61,17 @@ class anchor_utils {
|
|
62 |
global $escape_anchor_filter;
|
63 |
$escape_anchor_filter = array();
|
64 |
|
65 |
-
$text =
|
66 |
|
67 |
$text = preg_replace_callback("/
|
68 |
<\s*a\s+
|
69 |
([^<>]+)
|
70 |
>
|
71 |
-
(
|
72 |
<\s*\/\s*a\s*>
|
73 |
/isx", array($this, 'ob_filter_callback'), $text);
|
74 |
|
75 |
-
$text =
|
76 |
|
77 |
return $text;
|
78 |
} # ob_filter()
|
@@ -108,7 +107,7 @@ class anchor_utils {
|
|
108 |
return $match[0];
|
109 |
|
110 |
# parse anchor
|
111 |
-
$anchor =
|
112 |
|
113 |
if ( !$anchor )
|
114 |
return $match[0];
|
@@ -117,7 +116,7 @@ class anchor_utils {
|
|
117 |
$anchor = apply_filters('ob_filter_anchor', $anchor);
|
118 |
|
119 |
# return anchor
|
120 |
-
return
|
121 |
} # ob_filter_callback()
|
122 |
|
123 |
|
@@ -135,17 +134,17 @@ class anchor_utils {
|
|
135 |
global $escape_anchor_filter;
|
136 |
$escape_anchor_filter = array();
|
137 |
|
138 |
-
$text =
|
139 |
|
140 |
$text = preg_replace_callback("/
|
141 |
<\s*a\s+
|
142 |
([^<>]+)
|
143 |
>
|
144 |
-
(
|
145 |
<\s*\/\s*a\s*>
|
146 |
/isx", array($this, 'filter_callback'), $text);
|
147 |
|
148 |
-
$text =
|
149 |
|
150 |
return $text;
|
151 |
} # filter()
|
@@ -164,7 +163,7 @@ class anchor_utils {
|
|
164 |
return $match[0];
|
165 |
|
166 |
# parse anchor
|
167 |
-
$anchor =
|
168 |
|
169 |
if ( !$anchor )
|
170 |
return $match[0];
|
@@ -173,7 +172,7 @@ class anchor_utils {
|
|
173 |
$anchor = apply_filters('filter_anchor', $anchor);
|
174 |
|
175 |
# return anchor
|
176 |
-
return
|
177 |
} # filter_callback()
|
178 |
|
179 |
|
@@ -186,8 +185,7 @@ class anchor_utils {
|
|
186 |
|
187 |
function parse_anchor($match) {
|
188 |
$anchor = array();
|
189 |
-
|
190 |
-
$anchor['attr'] = $this->parse_attrs($match[1]);
|
191 |
|
192 |
if ( !is_array($anchor['attr']) || empty($anchor['attr']['href']) # parser error or no link
|
193 |
|| trim($anchor['attr']['href']) != esc_url($anchor['attr']['href'], null, 'db') ) # likely a script
|
@@ -389,3 +387,6 @@ class anchor_utils {
|
|
389 |
return $arr;
|
390 |
}
|
391 |
} # anchor_utils
|
|
|
|
|
|
2 |
/*
|
3 |
* Anchor Utils
|
4 |
* Author: Denis de Bernardy & Mike Koepke <http://www.semiologic.com>
|
5 |
+
* Version: 1.3
|
6 |
*/
|
7 |
|
8 |
if ( @ini_get('pcre.backtrack_limit') <= 750000 )
|
19 |
class anchor_utils {
|
20 |
|
21 |
/**
|
22 |
+
* anchor_utils
|
23 |
*/
|
24 |
+
public function __construct() {
|
25 |
add_filter('the_content', array($this, 'filter'), 100);
|
26 |
add_filter('the_excerpt', array($this, 'filter'), 100);
|
27 |
+
add_filter('widget_text', array($this, 'filter'), 100);
|
28 |
add_filter('comment_text', array($this, 'filter'), 100);
|
|
|
|
|
29 |
|
30 |
add_action('wp_head', array($this, 'ob_start'), 10000);
|
31 |
} #anchor_utils
|
61 |
global $escape_anchor_filter;
|
62 |
$escape_anchor_filter = array();
|
63 |
|
64 |
+
$text = anchor_utils::escape($text);
|
65 |
|
66 |
$text = preg_replace_callback("/
|
67 |
<\s*a\s+
|
68 |
([^<>]+)
|
69 |
>
|
70 |
+
(.+?)
|
71 |
<\s*\/\s*a\s*>
|
72 |
/isx", array($this, 'ob_filter_callback'), $text);
|
73 |
|
74 |
+
$text = anchor_utils::unescape($text);
|
75 |
|
76 |
return $text;
|
77 |
} # ob_filter()
|
107 |
return $match[0];
|
108 |
|
109 |
# parse anchor
|
110 |
+
$anchor = anchor_utils::parse_anchor($match);
|
111 |
|
112 |
if ( !$anchor )
|
113 |
return $match[0];
|
116 |
$anchor = apply_filters('ob_filter_anchor', $anchor);
|
117 |
|
118 |
# return anchor
|
119 |
+
return anchor_utils::build_anchor($anchor);
|
120 |
} # ob_filter_callback()
|
121 |
|
122 |
|
134 |
global $escape_anchor_filter;
|
135 |
$escape_anchor_filter = array();
|
136 |
|
137 |
+
$text = anchor_utils::escape($text);
|
138 |
|
139 |
$text = preg_replace_callback("/
|
140 |
<\s*a\s+
|
141 |
([^<>]+)
|
142 |
>
|
143 |
+
(.+?)
|
144 |
<\s*\/\s*a\s*>
|
145 |
/isx", array($this, 'filter_callback'), $text);
|
146 |
|
147 |
+
$text = anchor_utils::unescape($text);
|
148 |
|
149 |
return $text;
|
150 |
} # filter()
|
163 |
return $match[0];
|
164 |
|
165 |
# parse anchor
|
166 |
+
$anchor = anchor_utils::parse_anchor($match);
|
167 |
|
168 |
if ( !$anchor )
|
169 |
return $match[0];
|
172 |
$anchor = apply_filters('filter_anchor', $anchor);
|
173 |
|
174 |
# return anchor
|
175 |
+
return anchor_utils::build_anchor($anchor);
|
176 |
} # filter_callback()
|
177 |
|
178 |
|
185 |
|
186 |
function parse_anchor($match) {
|
187 |
$anchor = array();
|
188 |
+
$anchor['attr'] = anchor_utils::parse_attrs($match[1]);
|
|
|
189 |
|
190 |
if ( !is_array($anchor['attr']) || empty($anchor['attr']['href']) # parser error or no link
|
191 |
|| trim($anchor['attr']['href']) != esc_url($anchor['attr']['href'], null, 'db') ) # likely a script
|
387 |
return $arr;
|
388 |
}
|
389 |
} # anchor_utils
|
390 |
+
|
391 |
+
$anchor_utils = new anchor_utils();
|
392 |
+
?>
|
readme.txt
CHANGED
@@ -16,10 +16,10 @@ The external links plugin for WordPress lets you process outgoing links differen
|
|
16 |
|
17 |
Under Settings / External Links, you can configure the plugin to:
|
18 |
|
19 |
-
- Process all outgoing links, rather than only those within your entries' content
|
20 |
- Add an external link icon to outgoing links. You can use a class="no_icon" attribute on links to override this.
|
21 |
-
- Add rel=nofollow to the links. You can use a rel="follow" attribute on links to override this.
|
22 |
- Open outgoing links in new windows. Note that this can damage your visitor's trust towards your site in that they can think your site used a pop-under.
|
|
|
23 |
|
24 |
= Help Me! =
|
25 |
|
@@ -36,11 +36,6 @@ If you require more dedicated assistance, consider using [Semiologic Pro](http:/
|
|
36 |
|
37 |
== Change Log ==
|
38 |
|
39 |
-
= 5.2 =
|
40 |
-
|
41 |
-
- Further updates to the link attribute parsing code
|
42 |
-
- Fixed bug where external link was not processed if it was preceded by an empty text anchor link.
|
43 |
-
|
44 |
= 5.1 =
|
45 |
|
46 |
- Take two! With issues now with breaking google adsense code reverted back to 4.2 parsing code but added more advanced dom attribute parsing code to handle various link configurations.
|
16 |
|
17 |
Under Settings / External Links, you can configure the plugin to:
|
18 |
|
19 |
+
- Process all outgoing links, rather than only those within your entries' content.
|
20 |
- Add an external link icon to outgoing links. You can use a class="no_icon" attribute on links to override this.
|
|
|
21 |
- Open outgoing links in new windows. Note that this can damage your visitor's trust towards your site in that they can think your site used a pop-under.
|
22 |
+
- Add rel=nofollow to the links. You can use a rel="follow" attribute on links to override this.
|
23 |
|
24 |
= Help Me! =
|
25 |
|
36 |
|
37 |
== Change Log ==
|
38 |
|
|
|
|
|
|
|
|
|
|
|
39 |
= 5.1 =
|
40 |
|
41 |
- Take two! With issues now with breaking google adsense code reverted back to 4.2 parsing code but added more advanced dom attribute parsing code to handle various link configurations.
|
sem-external-links-admin.php
CHANGED
@@ -25,10 +25,10 @@ class external_links_admin {
|
|
25 |
|
26 |
check_admin_referer('external_links');
|
27 |
|
28 |
-
foreach ( array('global', 'icon', 'target', 'nofollow'
|
29 |
$$var = isset($_POST[$var]);
|
30 |
|
31 |
-
update_option('external_links', compact('global', 'icon', 'target', 'nofollow'
|
32 |
|
33 |
echo "<div class=\"updated fade\">\n"
|
34 |
. "<p>"
|
@@ -67,7 +67,7 @@ class external_links_admin {
|
|
67 |
echo '<h2>' . __('External Links Settings', 'external-links') . '</h2>' . "\n";
|
68 |
|
69 |
echo '<table class="form-table">' . "\n";
|
70 |
-
|
71 |
echo '<tr>' . "\n"
|
72 |
. '<th scope="row">'
|
73 |
. __('Apply Globally', 'external-links')
|
@@ -78,26 +78,11 @@ class external_links_admin {
|
|
78 |
. checked($options['global'], true, false)
|
79 |
. ' />'
|
80 |
. ' '
|
81 |
-
. __('Apply these settings to all outbound links
|
82 |
. '</label>'
|
83 |
. '</td>' . "\n"
|
84 |
. '</tr>' . "\n";
|
85 |
-
|
86 |
-
echo '<tr>' . "\n"
|
87 |
-
. '<th scope="row">'
|
88 |
-
. __('Apply to Text Widgets', 'external-links')
|
89 |
-
. '</th>' . "\n"
|
90 |
-
. '<td>'
|
91 |
-
. '<label>'
|
92 |
-
. '<input type="checkbox" name="text_widgets"'
|
93 |
-
. checked($options['text_widgets'], true, false)
|
94 |
-
. ' />'
|
95 |
-
. ' '
|
96 |
-
. __('Apply these settings to all text widgets in addition to those in posts and comments.', 'external-links')
|
97 |
-
. '</label>'
|
98 |
-
. '</td>' . "\n"
|
99 |
-
. '</tr>' . "\n";
|
100 |
-
|
101 |
echo '<tr>' . "\n"
|
102 |
. '<th scope="row">'
|
103 |
. __('Add Icons', 'external-links')
|
@@ -128,7 +113,7 @@ class external_links_admin {
|
|
128 |
. __('Add a rel=nofollow attribute to outbound links.', 'external-links')
|
129 |
. '</label>'
|
130 |
. '<br />' . "\n"
|
131 |
-
. __('Note: You can override this behavior by adding
|
132 |
. '</td>' . "\n"
|
133 |
. '</tr>' . "\n";
|
134 |
|
25 |
|
26 |
check_admin_referer('external_links');
|
27 |
|
28 |
+
foreach ( array('global', 'icon', 'target', 'nofollow') as $var )
|
29 |
$$var = isset($_POST[$var]);
|
30 |
|
31 |
+
update_option('external_links', compact('global', 'icon', 'target', 'nofollow'));
|
32 |
|
33 |
echo "<div class=\"updated fade\">\n"
|
34 |
. "<p>"
|
67 |
echo '<h2>' . __('External Links Settings', 'external-links') . '</h2>' . "\n";
|
68 |
|
69 |
echo '<table class="form-table">' . "\n";
|
70 |
+
|
71 |
echo '<tr>' . "\n"
|
72 |
. '<th scope="row">'
|
73 |
. __('Apply Globally', 'external-links')
|
78 |
. checked($options['global'], true, false)
|
79 |
. ' />'
|
80 |
. ' '
|
81 |
+
. __('Apply these settings to all outbound links, including those in headers, footers and sidebars, rather than only those in posts/pages, comments and text widgets.', 'external-links')
|
82 |
. '</label>'
|
83 |
. '</td>' . "\n"
|
84 |
. '</tr>' . "\n";
|
85 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
echo '<tr>' . "\n"
|
87 |
. '<th scope="row">'
|
88 |
. __('Add Icons', 'external-links')
|
113 |
. __('Add a rel=nofollow attribute to outbound links.', 'external-links')
|
114 |
. '</label>'
|
115 |
. '<br />' . "\n"
|
116 |
+
. __('Note: You can override this behavior by adding a rel="follow" to individual links.', 'external-links')
|
117 |
. '</td>' . "\n"
|
118 |
. '</tr>' . "\n";
|
119 |
|
sem-external-links.php
CHANGED
@@ -3,20 +3,20 @@
|
|
3 |
Plugin Name: External Links
|
4 |
Plugin URI: http://www.semiologic.com/software/external-links/
|
5 |
Description: Marks outbound links as such, with various effects that are configurable under <a href="options-general.php?page=external-links">Settings / External Links</a>.
|
6 |
-
Version: 5.
|
7 |
Author: Denis de Bernardy & Mike Koepke
|
8 |
Author URI: http://www.semiologic.com
|
9 |
Text Domain: external-links
|
10 |
Domain Path: /lang
|
11 |
-
License: Dual licensed under the MIT and GPL licenses
|
12 |
*/
|
13 |
|
14 |
/*
|
15 |
Terms of use
|
16 |
------------
|
17 |
|
18 |
-
This software is copyright Denis de Bernardy & Mike Koepke, and is distributed under the terms of the
|
19 |
|
|
|
20 |
**/
|
21 |
|
22 |
|
@@ -33,8 +33,6 @@ class external_links {
|
|
33 |
|
34 |
protected $opts;
|
35 |
|
36 |
-
protected $anchor_utils;
|
37 |
-
|
38 |
/**
|
39 |
* constructor()
|
40 |
*/
|
@@ -46,12 +44,6 @@ class external_links {
|
|
46 |
|
47 |
$o = external_links::get_options();
|
48 |
|
49 |
-
$inc_text_widgets = false;
|
50 |
-
if ( isset( $o['text_widgets'] ) && $o['text_widgets'] )
|
51 |
-
$inc_text_widgets = true;
|
52 |
-
|
53 |
-
$this->anchor_utils = new anchor_utils( $inc_text_widgets );
|
54 |
-
|
55 |
if ( $o['icon'] )
|
56 |
add_action('wp_print_styles', array($this, 'styles'), 5);
|
57 |
|
@@ -220,13 +212,13 @@ class external_links {
|
|
220 |
|
221 |
$o = get_option('external_links');
|
222 |
|
223 |
-
if ( $o === false
|
224 |
$o = external_links::init_options();
|
225 |
-
|
226 |
return $o;
|
227 |
} # get_options()
|
228 |
-
|
229 |
-
|
230 |
/**
|
231 |
* init_options()
|
232 |
*
|
@@ -241,20 +233,18 @@ class external_links {
|
|
241 |
'icon' => true,
|
242 |
'target' => false,
|
243 |
'nofollow' => true,
|
244 |
-
'text_widgets' => true,
|
245 |
);
|
246 |
|
247 |
if ( !$o )
|
248 |
$o = $defaults;
|
249 |
else
|
250 |
$o = wp_parse_args($o, $defaults);
|
251 |
-
|
252 |
update_option('external_links', $o);
|
253 |
-
|
254 |
return $o;
|
255 |
} # init_options()
|
256 |
-
|
257 |
-
|
258 |
|
259 |
/**
|
260 |
* admin_menu()
|
@@ -281,3 +271,4 @@ function external_links_admin() {
|
|
281 |
add_action('load-settings_page_external-links', 'external_links_admin');
|
282 |
|
283 |
$external_links = new external_links();
|
|
3 |
Plugin Name: External Links
|
4 |
Plugin URI: http://www.semiologic.com/software/external-links/
|
5 |
Description: Marks outbound links as such, with various effects that are configurable under <a href="options-general.php?page=external-links">Settings / External Links</a>.
|
6 |
+
Version: 5.1
|
7 |
Author: Denis de Bernardy & Mike Koepke
|
8 |
Author URI: http://www.semiologic.com
|
9 |
Text Domain: external-links
|
10 |
Domain Path: /lang
|
|
|
11 |
*/
|
12 |
|
13 |
/*
|
14 |
Terms of use
|
15 |
------------
|
16 |
|
17 |
+
This software is copyright Denis de Bernardy & Mike Koepke, and is distributed under the terms of the GPL license, v2.
|
18 |
|
19 |
+
http://www.opensource.org/licenses/gpl-2.0.php
|
20 |
**/
|
21 |
|
22 |
|
33 |
|
34 |
protected $opts;
|
35 |
|
|
|
|
|
36 |
/**
|
37 |
* constructor()
|
38 |
*/
|
44 |
|
45 |
$o = external_links::get_options();
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
if ( $o['icon'] )
|
48 |
add_action('wp_print_styles', array($this, 'styles'), 5);
|
49 |
|
212 |
|
213 |
$o = get_option('external_links');
|
214 |
|
215 |
+
if ( $o === false )
|
216 |
$o = external_links::init_options();
|
217 |
+
|
218 |
return $o;
|
219 |
} # get_options()
|
220 |
+
|
221 |
+
|
222 |
/**
|
223 |
* init_options()
|
224 |
*
|
233 |
'icon' => true,
|
234 |
'target' => false,
|
235 |
'nofollow' => true,
|
|
|
236 |
);
|
237 |
|
238 |
if ( !$o )
|
239 |
$o = $defaults;
|
240 |
else
|
241 |
$o = wp_parse_args($o, $defaults);
|
242 |
+
|
243 |
update_option('external_links', $o);
|
244 |
+
|
245 |
return $o;
|
246 |
} # init_options()
|
247 |
+
|
|
|
248 |
|
249 |
/**
|
250 |
* admin_menu()
|
271 |
add_action('load-settings_page_external-links', 'external_links_admin');
|
272 |
|
273 |
$external_links = new external_links();
|
274 |
+
?>
|