SEO Smart Links - Version 1.2

Version Description

Download this release

Release Info

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

Code changes from version 1.1 to 1.2

Files changed (3) hide show
  1. readme.txt +5 -0
  2. screenshot-1.png +0 -0
  3. seo-links.php +85 -37
readme.txt CHANGED
@@ -18,6 +18,11 @@ It also give your visitors an opportunity to visit other sections of your site t
18
 
19
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
20
 
 
 
 
 
 
21
  v1.1:
22
  - Fixed preg_replace() problem
23
 
18
 
19
  Everything happens completely transparent, and you can edit the options from the administration settings panel.
20
 
21
+
22
+ v1.2:
23
+ - Added limits options
24
+ - Fixed small bugs
25
+
26
  v1.1:
27
  - Fixed preg_replace() problem
28
 
screenshot-1.png CHANGED
Binary file
seo-links.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
- Version: 1.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
@@ -36,30 +36,44 @@ class SEOLinks {
36
 
37
  }
38
 
39
- function SEOLinks_process_text($text)
40
  {
41
 
42
  global $wpdb, $post;
43
 
44
  $options = $this->get_options();
45
 
46
-
47
- $text = " $text ";
48
-
49
 
50
  //$wpdb->terms;
51
  //$wpdb->term_taxonomy
52
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- if (($post->post_type=='page' && !$options['pageself']) || ($post->post_type=='post' && !$options['postself']))
55
- $add=', '.$post->post_title;
56
- else
57
- $add='';
 
58
 
59
- $arrignore=$this->explode_trim(",", strtolower($options['ignore'].$add));
60
 
61
 
62
 
 
 
 
 
63
  if ($options['lposts'] || $options['lpages'])
64
  {
65
 
@@ -73,12 +87,23 @@ if ($options['lposts'] || $options['lpages'])
73
  if (!in_array( strtolower($name), $arrignore))
74
  if ( ($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page') )
75
  {
76
-
77
  $url = (get_permalink($postitem->ID));
78
 
79
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
80
- $replace="<a href=\"$url\">$1</a>";
81
- $text = preg_replace($regexp, $replace, $text);
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
  }
84
  }
@@ -94,8 +119,18 @@ if ($options['lcats'])
94
  {
95
  $url = (get_category_link($cat->term_id));
96
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
97
- $replace="<a href=\"$url\">$1</a>";
98
- $text = preg_replace($regexp, $replace, $text);
 
 
 
 
 
 
 
 
 
 
99
  }
100
  }
101
  }
@@ -112,8 +147,18 @@ if ($options['ltags'])
112
  {
113
  $url = (get_tag_link($tag->term_id));
114
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
115
- $replace="<a href=\"$url\">$1</a>";
116
- $text = preg_replace($regexp, $replace, $text);
 
 
 
 
 
 
 
 
 
 
117
  }
118
  }
119
  }
@@ -123,27 +168,16 @@ return trim( $text );
123
  }
124
 
125
  function SEOLinks_the_content_filter($text) {
126
- return $this->SEOLinks_process_text($text);
127
  }
128
 
129
  function SEOLinks_comment_text_filter($text) {
130
- return $this->SEOLinks_process_text($text);
131
  }
132
 
133
  // Handle our options
134
  function get_options() {
135
- $options = array(
136
- 'post' => "",
137
- 'postself' => "",
138
- 'page' => "",
139
- 'pageself' => "",
140
- 'comment' => "",
141
- 'lposts' => "",
142
- 'lpages' => "",
143
- 'ltags' => "",
144
- 'lcats' => "",
145
- 'ignore' => "",
146
- );
147
 
148
  $existing_options = get_option($this->SEOLinks_DB_option);
149
 
@@ -184,11 +218,14 @@ function explode_trim($separator, $text)
184
  $options['lpages']='on';
185
  $options['lcats']='';
186
  $options['ltags']='';
187
- $options['ignore']='about,';
 
 
188
 
189
 
190
  update_option($this->SEOLinks_DB_option, $options);
191
- }
 
192
  }
193
 
194
  function handle_options()
@@ -209,6 +246,9 @@ function explode_trim($separator, $text)
209
  $options['lcats']=$_POST['lcats'];
210
  $options['ltags']=$_POST['ltags'];
211
  $options['ignore']=$_POST['ignore'];
 
 
 
212
 
213
 
214
  update_option($this->SEOLinks_DB_option, $options);
@@ -230,6 +270,8 @@ function explode_trim($separator, $text)
230
  $lcats=$options['lcats']=='on'?'checked':'';
231
  $ltags=$options['ltags']=='on'?'checked':'';
232
  $ignore=$options['ignore'];
 
 
233
 
234
  $imgpath=trailingslashit(get_option('siteurl')). 'wp-content/plugins/seo-automatic-links/i';
235
  echo <<<END
@@ -263,16 +305,16 @@ function explode_trim($separator, $text)
263
 
264
  <p>SEO Smart Links can automatically link keywords and phrases in your posts and comments with corresponding posts, pages, categories and tags on your blog.</p>
265
 
266
- <h4>Processing</h4>
267
  <p>SEO Smart Links can process your posts, pages and comments. Select your preference.</p>
268
  <input type="checkbox" name="post" $post/><label for="post"> Posts</label>
269
  <ul><input type="checkbox" name="postself" $postself/><label for="postself"> Allow links to itself</label></ul>
270
- <input type="checkbox" name="page" $post/><label for="page"> Pages</label>
271
  <ul><input type="checkbox" name="pageself" $postself/><label for="pageself"> Allow links to itself</label></ul>
272
  <input type="checkbox" name="comment" $comment /><label for="comment"> Comments</label> <br>
273
 
274
- <h4>Link to</h4>
275
- <p>Select what you want automatically to link to.</p>
276
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
277
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
278
  <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> <br>
@@ -282,6 +324,12 @@ function explode_trim($separator, $text)
282
  <p>You may wish to ignore certain words or phrases. Seperate them by comma.</p>
283
  <input type="text" name="ignore" size="90" value="$ignore"/>
284
 
 
 
 
 
 
 
285
 
286
  <div class="submit"><input type="submit" name="Submit" value="Update" /></div>
287
  </form>
2
 
3
  /*
4
  Plugin Name: SEO Smart Links
5
+ Version: 1.2
6
  Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links
7
  Author: Vladimir Prelovac
8
  Author URI: http://www.prelovac.com
36
 
37
  }
38
 
39
+ function SEOLinks_process_text($text, $mode)
40
  {
41
 
42
  global $wpdb, $post;
43
 
44
  $options = $this->get_options();
45
 
46
+ $links=0;
47
+
 
48
 
49
  //$wpdb->terms;
50
  //$wpdb->term_taxonomy
51
 
52
+ if (!$mode)
53
+ {
54
+ if ($post->post_type=='post' && !$options['post'])
55
+ return $text;
56
+ else if ($post->post_type=='page' && !$options['page'])
57
+ return $text;
58
+
59
+ if (($post->post_type=='page' && !$options['pageself']) || ($post->post_type=='post' && !$options['postself']))
60
+ $add=', '.$post->post_title;
61
+ else
62
+ $add='';
63
 
64
+ }
65
+
66
+ $maxlinks=($options['maxlinks']>0) ? $options['maxlinks'] : 0;
67
+
68
+ $maxsingle=($options['maxsingle']>0) ? $options['maxsingle'] : -1;
69
 
 
70
 
71
 
72
 
73
+ $arrignore=$this->explode_trim(",", strtolower($options['ignore'].$add));
74
+
75
+ $text = " $text ";
76
+
77
  if ($options['lposts'] || $options['lpages'])
78
  {
79
 
87
  if (!in_array( strtolower($name), $arrignore))
88
  if ( ($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page') )
89
  {
90
+
91
  $url = (get_permalink($postitem->ID));
92
 
93
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
94
+ $replace="<a title=\"$1\" href=\"$url\">$1</a>";
95
+
96
+
97
+
98
+ if (!$maxlinks || ($links < $maxlinks))
99
+ {
100
+
101
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
102
+ if ($newtext!=$text) {
103
+ $links++;
104
+ $text=$newtext;
105
+ }
106
+ }
107
  }
108
  }
109
  }
119
  {
120
  $url = (get_category_link($cat->term_id));
121
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
122
+ $replace="<a title=\"$1\" href=\"$url\">$1</a>";
123
+
124
+
125
+ if (!$maxlinks || ($links < $maxlinks))
126
+ {
127
+
128
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
129
+ if ($newtext!=$text) {
130
+ $links++;
131
+ $text=$newtext;
132
+ }
133
+ }
134
  }
135
  }
136
  }
147
  {
148
  $url = (get_tag_link($tag->term_id));
149
  $regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
150
+ $replace="<a title=\"$1\" href=\"$url\">$1</a>";
151
+
152
+ if (!$maxlinks || ($links < $maxlinks))
153
+ {
154
+
155
+ $newtext = preg_replace($regexp, $replace, $text, $maxsingle);
156
+ if ($newtext!=$text) {
157
+ $links++;
158
+ $text=$newtext;
159
+ }
160
+ }
161
+
162
  }
163
  }
164
  }
168
  }
169
 
170
  function SEOLinks_the_content_filter($text) {
171
+ return $this->SEOLinks_process_text($text, 0);
172
  }
173
 
174
  function SEOLinks_comment_text_filter($text) {
175
+ return $this->SEOLinks_process_text($text, 1);
176
  }
177
 
178
  // Handle our options
179
  function get_options() {
180
+
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  $existing_options = get_option($this->SEOLinks_DB_option);
183
 
218
  $options['lpages']='on';
219
  $options['lcats']='';
220
  $options['ltags']='';
221
+ $options['ignore']='about,';
222
+ $options['maxlinks']=3;
223
+ $options['maxsingle']=1;
224
 
225
 
226
  update_option($this->SEOLinks_DB_option, $options);
227
+ }
228
+
229
  }
230
 
231
  function handle_options()
246
  $options['lcats']=$_POST['lcats'];
247
  $options['ltags']=$_POST['ltags'];
248
  $options['ignore']=$_POST['ignore'];
249
+ $options['maxlinks']=$_POST['maxlinks'];
250
+ $options['maxsingle']=$_POST['maxsingle'];
251
+
252
 
253
 
254
  update_option($this->SEOLinks_DB_option, $options);
270
  $lcats=$options['lcats']=='on'?'checked':'';
271
  $ltags=$options['ltags']=='on'?'checked':'';
272
  $ignore=$options['ignore'];
273
+ $maxlinks=$options['maxlinks'];
274
+ $maxsingle=$options['maxsingle'];
275
 
276
  $imgpath=trailingslashit(get_option('siteurl')). 'wp-content/plugins/seo-automatic-links/i';
277
  echo <<<END
305
 
306
  <p>SEO Smart Links can automatically link keywords and phrases in your posts and comments with corresponding posts, pages, categories and tags on your blog.</p>
307
 
308
+ <h4>Source</h4>
309
  <p>SEO Smart Links can process your posts, pages and comments. Select your preference.</p>
310
  <input type="checkbox" name="post" $post/><label for="post"> Posts</label>
311
  <ul><input type="checkbox" name="postself" $postself/><label for="postself"> Allow links to itself</label></ul>
312
+ <input type="checkbox" name="page" $page/><label for="page"> Pages</label>
313
  <ul><input type="checkbox" name="pageself" $postself/><label for="pageself"> Allow links to itself</label></ul>
314
  <input type="checkbox" name="comment" $comment /><label for="comment"> Comments</label> <br>
315
 
316
+ <h4>Links</h4>
317
+ <p>Select automatic link targets.</p>
318
  <input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
319
  <input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
320
  <input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> <br>
324
  <p>You may wish to ignore certain words or phrases. Seperate them by comma.</p>
325
  <input type="text" name="ignore" size="90" value="$ignore"/>
326
 
327
+ <h4>Limits</h4>
328
+ <p>You can limit the maximum number of links you want to generate in a post. Set to 0 or empty for no limit. </p>
329
+ Max Links: <input type="text" name="maxlinks" size="2" value="$maxlinks"/>
330
+ <p>You can also limit maximum number of links towards the same target in a post. Set to 0 or empty for no limit. </p>
331
+ Max Single: <input type="text" name="maxsingle" size="2" value="$maxsingle"/>
332
+
333
 
334
  <div class="submit"><input type="submit" name="Submit" value="Update" /></div>
335
  </form>