SEO Smart Links - Version 2.1

Version Description

Download this release

Release Info

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

Code changes from version 2.0 to 2.1

Files changed (2) hide show
  1. readme.txt +6 -1
  2. seo-links.php +61 -46
readme.txt CHANGED
@@ -19,8 +19,13 @@ Further SEO Smart links allows you to set up your own keywords and set of matchi
19
 
20
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
21
 
22
- Change log:
23
 
 
 
 
 
 
24
  v2.0
25
  - Added the option for case sensitive matching
26
 
19
 
20
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
21
 
22
+ What is new:
23
 
24
+
25
+ v2.1
26
+ - Performance optimization and new option to link to cats and tags with used at least n times (thanks Dominik Deobald!)
27
+
28
+
29
  v2.0
30
  - Added the option for case sensitive matching
31
 
seo-links.php CHANGED
@@ -2,9 +2,9 @@
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
- Version: 2.0
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
- Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com/vladimir
9
  Description: SEO Smart Links provides automatic SEO benefits for your site in addition to custom keyword lists, nofollow and much more.
10
  */
@@ -75,14 +75,19 @@ function SEOLinks_process_text($text, $mode)
75
  }
76
 
77
  }
 
78
 
79
  $maxlinks=($options['maxlinks']>0) ? $options['maxlinks'] : 0;
80
  $maxsingle=($options['maxsingle']>0) ? $options['maxsingle'] : -1;
 
81
 
82
  $arrignore=$this->explode_trim(",", ($options['ignore']));
83
 
84
- $reg_post = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/imsU';
85
- $reg = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU';
 
 
 
86
 
87
  $text = " $text ";
88
 
@@ -118,18 +123,18 @@ function SEOLinks_process_text($text, $mode)
118
 
119
  if ((!$maxlinks || ($links < $maxlinks)) && (trailingslashit($url)!=$thisurl) && !in_array( $options['casesens'] ? $name : strtolower($name), $arrignore))
120
  {
121
-
122
- $name= preg_quote($name, '/');
123
-
124
- $replace="<a title=\"$1\" href=\"$url\">$1</a>";
125
- $regexp=str_replace('$name', $name, $reg);
126
- //$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))(?<!\p{L})($name)(?!\p{L})/imsU";
127
- $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
128
- if ($newtext!=$text) {
129
- $links++;
130
- $text=$newtext;
131
- }
132
-
133
  }
134
  }
135
  }
@@ -139,8 +144,6 @@ function SEOLinks_process_text($text, $mode)
139
  if ($options['lposts'] || $options['lpages'])
140
  {
141
  if ( !$posts = wp_cache_get( 'seo-links-posts', 'seo-smart-links' ) ) {
142
-
143
-
144
  $query="SELECT post_title, ID, post_type FROM $wpdb->posts WHERE post_status = 'publish' AND LENGTH(post_title)>3 ORDER BY LENGTH(post_title) DESC";
145
  $posts = $wpdb->get_results($query);
146
 
@@ -153,19 +156,21 @@ function SEOLinks_process_text($text, $mode)
153
  if ((($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page')) &&
154
  (!$maxlinks || ($links < $maxlinks)) && (($options['casesens'] ? $postitem->post_title : strtolower($postitem->post_title))!=$thistitle) && (!in_array( ($options['casesens'] ? $postitem->post_title : strtolower($postitem->post_title)), $arrignore)) )
155
  {
156
- $name = preg_quote($postitem->post_title, '/');
157
-
158
- $regexp=str_replace('$name', $name, $reg_post);
159
-
 
 
 
160
 
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_permalink($postitem->ID);
166
- $links++;
167
- $text=str_replace('$$$url$$$', $url, $newtext);
168
- }
169
  }
170
  }
171
  }
@@ -175,7 +180,7 @@ function SEOLinks_process_text($text, $mode)
175
  {
176
  if ( !$categories = wp_cache_get( 'seo-links-categories', '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 = 'category' AND LENGTH($wpdb->terms.name)>3 ORDER BY LENGTH($wpdb->terms.name) DESC";
179
  $categories = $wpdb->get_results($query);
180
 
181
  wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
@@ -185,6 +190,7 @@ function SEOLinks_process_text($text, $mode)
185
  {
186
  if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $cat->name : strtolower($cat->name), $arrignore) )
187
  {
 
188
  $name= preg_quote($cat->name, '/');
189
  $regexp=str_replace('$name', $name, $reg); ;
190
  $replace='<a title="$1" href="$$$url$$$">$1</a>';
@@ -194,8 +200,8 @@ function SEOLinks_process_text($text, $mode)
194
  $url = (get_category_link($cat->term_id));
195
  $links++;
196
  $text=str_replace('$$$url$$$', $url, $newtext);
197
- }
198
-
199
  }
200
  }
201
  }
@@ -203,12 +209,11 @@ function SEOLinks_process_text($text, $mode)
203
  // tags
204
  if ($options['ltags'])
205
  {
206
-
207
  if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
208
 
209
- $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";
210
  $tags = $wpdb->get_results($query);
211
-
212
  wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
213
  }
214
 
@@ -216,16 +221,18 @@ function SEOLinks_process_text($text, $mode)
216
  {
217
  if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $tag->name : strtolower($tag->name), $arrignore) )
218
  {
219
- $name = preg_quote($tag->name, '/');
220
- $regexp=str_replace('$name', $name, $reg); ;
221
- $replace='<a title="$1" href="$$$url$$$">$1</a>';
222
-
223
- $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
224
- if ($newtext!=$text) {
225
- $url = (get_tag_link($tag->term_id));
226
- $links++;
227
- $text=str_replace('$$$url$$$', $url, $newtext);
228
- }
 
 
229
  }
230
  }
231
  }
@@ -294,6 +301,7 @@ function SEOLinks_comment_text_filter($text) {
294
  'ignore' => 'about,',
295
  'maxlinks' => 3,
296
  'maxsingle' => 1,
 
297
  'customkey' => '',
298
  'nofoln' =>'',
299
  'nofolo' =>'',
@@ -348,6 +356,7 @@ function SEOLinks_comment_text_filter($text) {
348
  $options['ignore']=$_POST['ignore'];
349
  $options['maxlinks']=(int) $_POST['maxlinks'];
350
  $options['maxsingle']=(int) $_POST['maxsingle'];
 
351
  $options['customkey']=$_POST['customkey'];
352
  $options['nofoln']=$_POST['nofoln'];
353
  $options['nofolo']=$_POST['nofolo'];
@@ -379,6 +388,7 @@ function SEOLinks_comment_text_filter($text) {
379
  $ignore=$options['ignore'];
380
  $maxlinks=$options['maxlinks'];
381
  $maxsingle=$options['maxsingle'];
 
382
  $customkey=stripslashes($options['customkey']);
383
  $nofoln=$options['nofoln']=='on'?'checked':'';
384
  $nofolo=$options['nofolo']=='on'?'checked':'';
@@ -386,6 +396,8 @@ function SEOLinks_comment_text_filter($text) {
386
  $blanko=$options['blanko']=='on'?'checked':'';
387
  $onlysingle=$options['onlysingle']=='on'?'checked':'';
388
  $casesens=$options['casesens']=='on'?'checked':'';
 
 
389
 
390
  $nonce=wp_create_nonce( 'seo-smart-links');
391
 
@@ -440,6 +452,9 @@ function SEOLinks_comment_text_filter($text) {
440
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
441
  <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> (may slow down performance) <br>
442
  <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> (may slow down performance) <br>
 
 
 
443
 
444
  <h2>Settings</h2>
445
  <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: 2.1
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
+ Author: Vladimir Prelovac</a>
8
  Author URI: http://www.prelovac.com/vladimir
9
  Description: SEO Smart Links provides automatic SEO benefits for your site in addition to custom keyword lists, nofollow and much more.
10
  */
75
  }
76
 
77
  }
78
+
79
 
80
  $maxlinks=($options['maxlinks']>0) ? $options['maxlinks'] : 0;
81
  $maxsingle=($options['maxsingle']>0) ? $options['maxsingle'] : -1;
82
+ $minusage = ($options['minusage']>0) ? $options['minusage'] : 1;
83
 
84
  $arrignore=$this->explode_trim(",", ($options['ignore']));
85
 
86
+ // $reg_post = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/imsU';
87
+ // $reg = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU';
88
+ $reg_post = $options['casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($name)/msU' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($name)/imsU';
89
+ $reg = $options['casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))\b($name)\b/msU' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))\b($name)\b/imsU';
90
+ $strpos_fnc = $options['casesens'] ? 'strpos' : 'stripos';
91
 
92
  $text = " $text ";
93
 
123
 
124
  if ((!$maxlinks || ($links < $maxlinks)) && (trailingslashit($url)!=$thisurl) && !in_array( $options['casesens'] ? $name : strtolower($name), $arrignore))
125
  {
126
+ if ($strpos_fnc($text, $name) !== false) { // credit to Dominik Deobald
127
+ $name= preg_quote($name, '/');
128
+
129
+ $replace="<a title=\"$1\" href=\"$url\">$1</a>";
130
+ $regexp=str_replace('$name', $name, $reg);
131
+ //$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))(?<!\p{L})($name)(?!\p{L})/imsU";
132
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
133
+ if ($newtext!=$text) {
134
+ $links++;
135
+ $text=$newtext;
136
+ }
137
+ }
138
  }
139
  }
140
  }
144
  if ($options['lposts'] || $options['lpages'])
145
  {
146
  if ( !$posts = wp_cache_get( 'seo-links-posts', 'seo-smart-links' ) ) {
 
 
147
  $query="SELECT post_title, ID, post_type FROM $wpdb->posts WHERE post_status = 'publish' AND LENGTH(post_title)>3 ORDER BY LENGTH(post_title) DESC";
148
  $posts = $wpdb->get_results($query);
149
 
156
  if ((($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page')) &&
157
  (!$maxlinks || ($links < $maxlinks)) && (($options['casesens'] ? $postitem->post_title : strtolower($postitem->post_title))!=$thistitle) && (!in_array( ($options['casesens'] ? $postitem->post_title : strtolower($postitem->post_title)), $arrignore)) )
158
  {
159
+ if ($strpos_fnc($text, $postitem->post_title) !== false) { // credit to Dominik Deobald
160
+ $name = preg_quote($postitem->post_title, '/');
161
+
162
+ $regexp=str_replace('$name', $name, $reg_post);
163
+
164
+
165
+ $replace='<a title="$1" href="$$$url$$$">$1</a>';
166
 
167
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
168
+ if ($newtext!=$text) {
169
+ $url = get_permalink($postitem->ID);
170
+ $links++;
171
+ $text=str_replace('$$$url$$$', $url, $newtext);
172
+ }
173
+ }
 
174
  }
175
  }
176
  }
180
  {
181
  if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
182
 
183
+ $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 AND $wpdb->term_taxonomy.count >= $minusage ORDER BY LENGTH($wpdb->terms.name) DESC";
184
  $categories = $wpdb->get_results($query);
185
 
186
  wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
190
  {
191
  if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $cat->name : strtolower($cat->name), $arrignore) )
192
  {
193
+ if ($strpos_fnc($text, $cat->name) !== false) { // credit to Dominik Deobald
194
  $name= preg_quote($cat->name, '/');
195
  $regexp=str_replace('$name', $name, $reg); ;
196
  $replace='<a title="$1" href="$$$url$$$">$1</a>';
200
  $url = (get_category_link($cat->term_id));
201
  $links++;
202
  $text=str_replace('$$$url$$$', $url, $newtext);
203
+ }
204
+ }
205
  }
206
  }
207
  }
209
  // tags
210
  if ($options['ltags'])
211
  {
 
212
  if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
213
 
214
+ $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 AND $wpdb->term_taxonomy.count >= $minusage ORDER BY LENGTH($wpdb->terms.name) DESC";
215
  $tags = $wpdb->get_results($query);
216
+
217
  wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
218
  }
219
 
221
  {
222
  if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $tag->name : strtolower($tag->name), $arrignore) )
223
  {
224
+ if ($strpos_fnc($text, $tag->name) !== false) { // credit to Dominik Deobald
225
+ $name = preg_quote($tag->name, '/');
226
+ $regexp=str_replace('$name', $name, $reg); ;
227
+ $replace='<a title="$1" href="$$$url$$$">$1</a>';
228
+
229
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
230
+ if ($newtext!=$text) {
231
+ $url = (get_tag_link($tag->term_id));
232
+ $links++;
233
+ $text=str_replace('$$$url$$$', $url, $newtext);
234
+ }
235
+ }
236
  }
237
  }
238
  }
301
  'ignore' => 'about,',
302
  'maxlinks' => 3,
303
  'maxsingle' => 1,
304
+ 'minusage' => 1,
305
  'customkey' => '',
306
  'nofoln' =>'',
307
  'nofolo' =>'',
356
  $options['ignore']=$_POST['ignore'];
357
  $options['maxlinks']=(int) $_POST['maxlinks'];
358
  $options['maxsingle']=(int) $_POST['maxsingle'];
359
+ $options['minusage']=(int) $_POST['minusage']; // credit to Dominik Deobald
360
  $options['customkey']=$_POST['customkey'];
361
  $options['nofoln']=$_POST['nofoln'];
362
  $options['nofolo']=$_POST['nofolo'];
388
  $ignore=$options['ignore'];
389
  $maxlinks=$options['maxlinks'];
390
  $maxsingle=$options['maxsingle'];
391
+ $minusage=$options['minusage'];
392
  $customkey=stripslashes($options['customkey']);
393
  $nofoln=$options['nofoln']=='on'?'checked':'';
394
  $nofolo=$options['nofolo']=='on'?'checked':'';
396
  $blanko=$options['blanko']=='on'?'checked':'';
397
  $onlysingle=$options['onlysingle']=='on'?'checked':'';
398
  $casesens=$options['casesens']=='on'?'checked':'';
399
+
400
+ if (!is_numeric($minusage)) $minusage = 1;
401
 
402
  $nonce=wp_create_nonce( 'seo-smart-links');
403
 
452
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
453
  <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> (may slow down performance) <br>
454
  <input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> (may slow down performance) <br>
455
+ <br>
456
+ Link tags and categories that have been used at least <input type="text" name="minusage" size="2" value="$minusage"/> times.
457
+ <br>
458
 
459
  <h2>Settings</h2>
460
  <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>