SEO Smart Links - Version 1.7.1

Version Description

Download this release

Release Info

Developer freediver
Plugin Icon 128x128 SEO Smart Links
Version 1.7.1
Comparing to
See all releases

Code changes from version 1.7 to 1.7.1

Files changed (2) hide show
  1. readme.txt +5 -0
  2. seo-links.php +45 -70
readme.txt CHANGED
@@ -21,6 +21,11 @@ Everything happens completely transparent, and you can edit the options from the
21
 
22
 
23
  Change log
 
 
 
 
 
24
  v1.7
25
  - Performance optimization of the plugin. SEO Smart Links causes much lesser strain on the server.
26
 
21
 
22
 
23
  Change log
24
+
25
+ v1.7.1
26
+ - More performance optimizations
27
+ - External links now work correctly for blogs on sites
28
+
29
  v1.7
30
  - Performance optimization of the plugin. SEO Smart Links causes much lesser strain on the server.
31
 
seo-links.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
- Version: 1.7
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
  Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com
@@ -49,11 +49,8 @@ function SEOLinks_process_text($text, $mode)
49
  $options = $this->get_options();
50
 
51
  $links=0;
52
-
53
-
54
- //$wpdb->terms;
55
- //$wpdb->term_taxonomy
56
 
 
57
 
58
  if ($options['onlysingle'] && !(is_single() || is_page()))
59
  return $text;
@@ -87,30 +84,27 @@ $text = " $text ";
87
  if (!empty($options['customkey']))
88
  {
89
 
90
- $kw_array = array();
91
- foreach (explode("\n", $options['customkey']) as $line) {
92
- list($keyword, $url) = array_map('trim', explode(",", $line, 2));
93
- if (!empty($keyword)) $kw_array[$keyword] = $url;
94
- }
95
 
96
  foreach ($kw_array as $name=>$url)
97
  {
98
- $name= preg_quote($name, '/');
99
- if (!in_array( strtolower($name), $arrignore))
100
  {
101
-
102
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
103
  $replace="<a title=\"$1\" href=\"$url\">$1</a>";
104
 
 
 
 
 
 
105
 
106
- if (!$maxlinks || ($links < $maxlinks))
107
- {
108
- $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
109
- if ($newtext!=$text) {
110
- $links++;
111
- $text=$newtext;
112
- }
113
- }
114
  }
115
  }
116
 
@@ -131,26 +125,20 @@ if ($options['lposts'] || $options['lpages'])
131
 
132
  foreach ($posts as $postitem)
133
  {
134
- $name = preg_quote($postitem->post_title, '/');
135
-
136
-
137
- if (!in_array( strtolower($name), $arrignore))
138
- if ( ($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page') )
139
- {
140
-
141
- $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
142
- $replace='<a title="$1" href="$$$url$$$">$1</a>';
143
-
144
- if (!$maxlinks || ($links < $maxlinks))
145
  {
 
 
 
 
146
  $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
147
  if ($newtext!=$text) {
148
  $url = get_permalink($postitem->ID);
149
  $links++;
150
  $text=str_replace('$$$url$$$', $url, $newtext);
151
- }
152
  }
153
- }
154
  }
155
  }
156
 
@@ -159,7 +147,6 @@ if ($options['lcats'])
159
  if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
160
 
161
  $query="SELECT $wpdb->terms.name, $wpdb->terms.term_id FROM $wpdb->terms LEFT JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'category' AND LENGTH($wpdb->terms.name)>3 ORDER BY LENGTH($wpdb->terms.name) DESC";
162
- //$query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'category'";
163
  $categories = $wpdb->get_results($query);
164
 
165
  wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
@@ -167,27 +154,19 @@ if ($options['lcats'])
167
 
168
  foreach ($categories as $cat)
169
  {
170
- $name= preg_quote($cat->name, '/');
171
-
172
-
173
- if (!in_array( strtolower($name), $arrignore))
174
  {
175
-
176
- $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
177
- $replace='<a title="$1" href="$$$url$$$">$1</a>';
178
 
179
-
180
- if (!$maxlinks || ($links < $maxlinks))
181
- {
182
-
183
  $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
184
- if ($newtext!=$text) {
185
-
186
  $url = (get_category_link($cat->term_id));
187
  $links++;
188
  $text=str_replace('$$$url$$$', $url, $newtext);
189
  }
190
- }
191
  }
192
  }
193
  }
@@ -197,7 +176,6 @@ if ($options['ltags'])
197
  if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
198
 
199
  $query="SELECT $wpdb->terms.name, $wpdb->terms.term_id FROM $wpdb->terms LEFT JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'post_tag' AND LENGTH($wpdb->terms.name)>3 ORDER BY LENGTH($wpdb->terms.name) DESC";
200
- //$query="SELECT wp_terms.name, wp_terms.term_id FROM wp_terms LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = 'post_tag'";
201
  $tags = $wpdb->get_results($query);
202
 
203
  wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
@@ -205,24 +183,18 @@ if ($options['ltags'])
205
 
206
  foreach ($tags as $tag)
207
  {
208
- $name = preg_quote($tag->name, '/');
209
- if (!in_array( strtolower($name), $arrignore))
210
  {
211
-
212
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
213
  $replace='<a title="$1" href="$$$url$$$">$1</a>';
214
-
215
- if (!$maxlinks || ($links < $maxlinks))
216
- {
217
-
218
- $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
219
- if ($newtext!=$text) {
220
- $url = (get_tag_link($tag->term_id));
221
- $links++;
222
- $text=str_replace('$$$url$$$', $url, $newtext);
223
- }
224
- }
225
-
226
  }
227
  }
228
  }
@@ -236,10 +208,13 @@ function SEOLinks_the_content_filter($text) {
236
  $result=$this->SEOLinks_process_text($text, 0);
237
 
238
  $options = $this->get_options();
 
 
 
239
  if ($options['blanko'])
240
- $result = preg_replace('%<a(\s+.*?href=\S(?!' . get_bloginfo('wpurl') . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
241
  if ($options['nofolo'])
242
- $result = preg_replace('%<a(\s+.*?href=\S(?!' . get_bloginfo('wpurl') . '))%i', '<a rel="nofollow"\\1', $result);
243
  return $result;
244
  }
245
 
@@ -414,14 +389,14 @@ function SEOLinks_comment_text_filter($text) {
414
  <ul><input type="checkbox" name="postself" $postself/><label for="postself"> Allow links to itself</label></ul>
415
  <input type="checkbox" name="page" $page/><label for="page"> Pages</label>
416
  <ul><input type="checkbox" name="pageself" $pageself/><label for="pageself"> Allow links to itself</label></ul>
417
- <input type="checkbox" name="comment" $comment /><label for="comment"> Comments</label> <br>
418
 
419
  <h4>Target</h4>
420
  <p>The targets SEO Smart links should consider. The match will be based on post/page title or category/tag name, case insensitive.</p>
421
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
422
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
423
- <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> <br>
424
- <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> <br>
425
 
426
  <h4>Only single</h4>
427
  <p>To reduce database load you can choose to have SEO SMART links work only on single posts and pages (for example not on main page or archives).</p>
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
+ Version: 1.7.1
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
  Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com
49
  $options = $this->get_options();
50
 
51
  $links=0;
 
 
 
 
52
 
53
+
54
 
55
  if ($options['onlysingle'] && !(is_single() || is_page()))
56
  return $text;
84
  if (!empty($options['customkey']))
85
  {
86
 
87
+ $kw_array = array();
88
+ foreach (explode("\n", $options['customkey']) as $line) {
89
+ list($keyword, $url) = array_map('trim', explode(",", $line, 2));
90
+ if (!empty($keyword)) $kw_array[$keyword] = $url;
91
+ }
92
 
93
  foreach ($kw_array as $name=>$url)
94
  {
95
+
96
+ if (!$maxlinks || ($links < $maxlinks) && !in_array( strtolower($name), $arrignore) && strstr($text, $name))
97
  {
98
+ $name= preg_quote($name, '/');
99
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
100
  $replace="<a title=\"$1\" href=\"$url\">$1</a>";
101
 
102
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
103
+ if ($newtext!=$text) {
104
+ $links++;
105
+ $text=$newtext;
106
+ }
107
 
 
 
 
 
 
 
 
 
108
  }
109
  }
110
 
125
 
126
  foreach ($posts as $postitem)
127
  {
128
+ if (($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page') &&
129
+ !$maxlinks || ($links < $maxlinks) && !in_array( strtolower($postitem->post_title), $arrignore) && strstr($text, $postitem->post_title) )
 
 
 
 
 
 
 
 
 
130
  {
131
+ $name = preg_quote($postitem->post_title, '/');
132
+ $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
133
+ $replace='<a title="$1" href="$$$url$$$">$1</a>';
134
+
135
  $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
136
  if ($newtext!=$text) {
137
  $url = get_permalink($postitem->ID);
138
  $links++;
139
  $text=str_replace('$$$url$$$', $url, $newtext);
140
+ }
141
  }
 
142
  }
143
  }
144
 
147
  if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
148
 
149
  $query="SELECT $wpdb->terms.name, $wpdb->terms.term_id FROM $wpdb->terms LEFT JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'category' AND LENGTH($wpdb->terms.name)>3 ORDER BY LENGTH($wpdb->terms.name) DESC";
 
150
  $categories = $wpdb->get_results($query);
151
 
152
  wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
154
 
155
  foreach ($categories as $cat)
156
  {
157
+ if (!$maxlinks || ($links < $maxlinks) && !in_array( strtolower($cat->name), $arrignore) && strstr($text, $cat->name) )
 
 
 
158
  {
159
+ $name= preg_quote($cat->name, '/');
160
+ $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
161
+ $replace='<a title="$1" href="$$$url$$$">$1</a>';
162
 
 
 
 
 
163
  $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
164
+ if ($newtext!=$text) {
 
165
  $url = (get_category_link($cat->term_id));
166
  $links++;
167
  $text=str_replace('$$$url$$$', $url, $newtext);
168
  }
169
+
170
  }
171
  }
172
  }
176
  if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
177
 
178
  $query="SELECT $wpdb->terms.name, $wpdb->terms.term_id FROM $wpdb->terms LEFT JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'post_tag' AND LENGTH($wpdb->terms.name)>3 ORDER BY LENGTH($wpdb->terms.name) DESC";
 
179
  $tags = $wpdb->get_results($query);
180
 
181
  wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
183
 
184
  foreach ($tags as $tag)
185
  {
186
+ if (!$maxlinks || ($links < $maxlinks) && !in_array( strtolower($name), $arrignore) && strstr($text, $tag->name))
 
187
  {
188
+ $name = preg_quote($tag->name, '/');
189
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
190
  $replace='<a title="$1" href="$$$url$$$">$1</a>';
191
+
192
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
193
+ if ($newtext!=$text) {
194
+ $url = (get_tag_link($tag->term_id));
195
+ $links++;
196
+ $text=str_replace('$$$url$$$', $url, $newtext);
197
+ }
 
 
 
 
 
198
  }
199
  }
200
  }
208
  $result=$this->SEOLinks_process_text($text, 0);
209
 
210
  $options = $this->get_options();
211
+ $link=parse_url(get_bloginfo('wpurl'));
212
+ $host=$link['host'];
213
+
214
  if ($options['blanko'])
215
+ $result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
216
  if ($options['nofolo'])
217
+ $result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a rel="nofollow"\\1', $result);
218
  return $result;
219
  }
220
 
389
  <ul><input type="checkbox" name="postself" $postself/><label for="postself"> Allow links to itself</label></ul>
390
  <input type="checkbox" name="page" $page/><label for="page"> Pages</label>
391
  <ul><input type="checkbox" name="pageself" $pageself/><label for="pageself"> Allow links to itself</label></ul>
392
+ <input type="checkbox" name="comment" $comment /><label for="comment"> Comments</label> (may slow down performance) <br>
393
 
394
  <h4>Target</h4>
395
  <p>The targets SEO Smart links should consider. The match will be based on post/page title or category/tag name, case insensitive.</p>
396
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
397
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
398
+ <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> (may slow down performance) <br>
399
+ <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> (may slow down performance) <br>
400
 
401
  <h4>Only single</h4>
402
  <p>To reduce database load you can choose to have SEO SMART links work only on single posts and pages (for example not on main page or archives).</p>