Version Description
- Added option to exclude certain posts and pages from automatic linking (credits to Gabriel Paladino)
Download this release
Release Info
Developer | freediver |
Plugin | SEO Smart Links |
Version | 2.2 |
Comparing to | |
See all releases |
Code changes from version 2.1 to 2.2
- readme.txt +12 -21
- seo-links.php +553 -540
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: freediver
|
|
3 |
Donate link: https://www.networkforgood.org/donation/MakeDonation.aspx?ORGID2=520781390
|
4 |
Tags: Post, posts, comments, links, seo, google, automatic
|
5 |
Requires at least: 2.3
|
6 |
-
Tested up to: 2.
|
7 |
Stable tag: trunk
|
8 |
|
9 |
SEO Smart Links provides automatic SEO benefits for your site in addition to custom keyword lists, nofollow and much more.
|
@@ -19,31 +19,22 @@ 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 |
-
What is new:
|
23 |
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
- Added the option for case sensitive matching
|
31 |
-
|
32 |
-
v1.9.3
|
33 |
-
- Various improvements and bug fixes
|
34 |
-
|
35 |
-
v1.8.0
|
36 |
-
- Added support for non-english characters (Unicode)
|
37 |
-
- Added support for keyword synonyms (in keywords section of the settings screen)
|
38 |
|
39 |
-
v1.7.1
|
40 |
-
- More performance optimizations
|
41 |
-
- External links now work correctly for blogs on sites
|
42 |
-
|
43 |
-
v1.7
|
44 |
-
- Performance optimization of the plugin. SEO Smart Links causes much lesser strain on the server.
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
== Credits ==
|
49 |
|
3 |
Donate link: https://www.networkforgood.org/donation/MakeDonation.aspx?ORGID2=520781390
|
4 |
Tags: Post, posts, comments, links, seo, google, automatic
|
5 |
Requires at least: 2.3
|
6 |
+
Tested up to: 2.8.4
|
7 |
Stable tag: trunk
|
8 |
|
9 |
SEO Smart Links provides automatic SEO benefits for your site in addition to custom keyword lists, nofollow and much more.
|
19 |
|
20 |
Everything happens completely transparent, and you can edit the options from the administration settings panel.
|
21 |
|
|
|
22 |
|
23 |
+
== Changelog ==
|
24 |
|
25 |
+
= 2.2 =
|
26 |
+
* Added option to exclude certain posts and pages from automatic linking (credits to Gabriel Paladino)
|
27 |
|
28 |
+
= 2.1 =
|
29 |
+
* Performance optimization and new option to link to cats and tags with used at least n times (thanks Dominik Deobald!)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
= 2.0 =
|
33 |
+
* Added the option for case sensitive matching
|
34 |
+
|
35 |
+
= 1.8.0 =
|
36 |
+
* Added support for non-english characters (Unicode)
|
37 |
+
* Added support for keyword synonyms (in keywords section of the settings screen)
|
38 |
|
39 |
== Credits ==
|
40 |
|
seo-links.php
CHANGED
@@ -1,541 +1,554 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
Plugin Name: SEO Smart Links
|
5 |
-
Version: 2.
|
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 |
-
*/
|
11 |
-
|
12 |
-
// todo It's possible to have option for case insensitive ?
|
13 |
-
// $count in preg_replace, max links towards same url
|
14 |
-
// If possible I'd be interested in having the plugin to not autolink keywords within (ie H1, H2 etc)
|
15 |
-
|
16 |
-
// Avoid name collisions.
|
17 |
-
if ( !class_exists('SEOLinks') ) :
|
18 |
-
|
19 |
-
class SEOLinks {
|
20 |
-
|
21 |
-
// Name for our options in the DB
|
22 |
-
var $SEOLinks_DB_option = 'SEOLinks';
|
23 |
-
var $SEOLinks_options;
|
24 |
-
|
25 |
-
// Initialize WordPress hooks
|
26 |
-
function SEOLinks() {
|
27 |
-
$options = $this->get_options();
|
28 |
-
if ($options)
|
29 |
-
{
|
30 |
-
if ($options['post'] || $options['page'])
|
31 |
-
add_filter('the_content', array(&$this, 'SEOLinks_the_content_filter'), 10);
|
32 |
-
if ($options['comment'])
|
33 |
-
add_filter('comment_text', array(&$this, 'SEOLinks_comment_text_filter'), 10);
|
34 |
-
}
|
35 |
-
|
36 |
-
add_action( 'create_category', array(&$this, 'SEOLinks_delete_cache'));
|
37 |
-
add_action( 'edit_category', array(&$this,'SEOLinks_delete_cache'));
|
38 |
-
add_action( 'edit_post', array(&$this,'SEOLinks_delete_cache'));
|
39 |
-
add_action( 'save_post', array(&$this,'SEOLinks_delete_cache'));
|
40 |
-
// Add Options Page
|
41 |
-
add_action('admin_menu', array(&$this, 'SEOLinks_admin_menu'));
|
42 |
-
|
43 |
-
}
|
44 |
-
|
45 |
-
function SEOLinks_process_text($text, $mode)
|
46 |
-
{
|
47 |
-
|
48 |
-
global $wpdb, $post;
|
49 |
-
|
50 |
-
$options = $this->get_options();
|
51 |
-
|
52 |
-
$links=0;
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
if ($options['onlysingle'] && !(is_single() || is_page()))
|
58 |
-
return $text;
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
$
|
89 |
-
|
90 |
-
$
|
91 |
-
|
92 |
-
$
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
{
|
123 |
-
|
124 |
-
if ((
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
}
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
$
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
'
|
299 |
-
'
|
300 |
-
'
|
301 |
-
'
|
302 |
-
'
|
303 |
-
'
|
304 |
-
'
|
305 |
-
'
|
306 |
-
'
|
307 |
-
'
|
308 |
-
|
309 |
-
'
|
310 |
-
'
|
311 |
-
'
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
{
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
$options['
|
355 |
-
$options['
|
356 |
-
$options['
|
357 |
-
$options['
|
358 |
-
$options['
|
359 |
-
$options['
|
360 |
-
$options['
|
361 |
-
$options['
|
362 |
-
$options['
|
363 |
-
$options['
|
364 |
-
|
365 |
-
$options['
|
366 |
-
$options['
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
$
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
$
|
386 |
-
|
387 |
-
$
|
388 |
-
$
|
389 |
-
$
|
390 |
-
$
|
391 |
-
$
|
392 |
-
$
|
393 |
-
$
|
394 |
-
$
|
395 |
-
$
|
396 |
-
$
|
397 |
-
|
398 |
-
$
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
$
|
403 |
-
|
404 |
-
$
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
<input type="
|
442 |
-
<
|
443 |
-
|
444 |
-
<
|
445 |
-
<
|
446 |
-
<
|
447 |
-
|
448 |
-
|
449 |
-
<
|
450 |
-
<
|
451 |
-
<input type="checkbox" name="
|
452 |
-
<
|
453 |
-
<input type="checkbox" name="
|
454 |
-
<input type="checkbox" name="
|
455 |
-
<br
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
<
|
460 |
-
<
|
461 |
-
<input type="checkbox" name="
|
462 |
-
|
463 |
-
<
|
464 |
-
<
|
465 |
-
|
466 |
-
<
|
467 |
-
|
468 |
-
<
|
469 |
-
<
|
470 |
-
|
471 |
-
|
472 |
-
<
|
473 |
-
<
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
<
|
481 |
-
|
482 |
-
<
|
483 |
-
<
|
484 |
-
|
485 |
-
<
|
486 |
-
|
487 |
-
<br
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
<
|
494 |
-
|
495 |
-
|
496 |
-
<
|
497 |
-
|
498 |
-
|
499 |
-
<
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
</
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Plugin Name: SEO Smart Links
|
5 |
+
Version: 2.2
|
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 |
+
*/
|
11 |
+
|
12 |
+
// todo It's possible to have option for case insensitive ?
|
13 |
+
// $count in preg_replace, max links towards same url
|
14 |
+
// If possible I'd be interested in having the plugin to not autolink keywords within (ie H1, H2 etc)
|
15 |
+
|
16 |
+
// Avoid name collisions.
|
17 |
+
if ( !class_exists('SEOLinks') ) :
|
18 |
+
|
19 |
+
class SEOLinks {
|
20 |
+
|
21 |
+
// Name for our options in the DB
|
22 |
+
var $SEOLinks_DB_option = 'SEOLinks';
|
23 |
+
var $SEOLinks_options;
|
24 |
+
|
25 |
+
// Initialize WordPress hooks
|
26 |
+
function SEOLinks() {
|
27 |
+
$options = $this->get_options();
|
28 |
+
if ($options)
|
29 |
+
{
|
30 |
+
if ($options['post'] || $options['page'])
|
31 |
+
add_filter('the_content', array(&$this, 'SEOLinks_the_content_filter'), 10);
|
32 |
+
if ($options['comment'])
|
33 |
+
add_filter('comment_text', array(&$this, 'SEOLinks_comment_text_filter'), 10);
|
34 |
+
}
|
35 |
+
|
36 |
+
add_action( 'create_category', array(&$this, 'SEOLinks_delete_cache'));
|
37 |
+
add_action( 'edit_category', array(&$this,'SEOLinks_delete_cache'));
|
38 |
+
add_action( 'edit_post', array(&$this,'SEOLinks_delete_cache'));
|
39 |
+
add_action( 'save_post', array(&$this,'SEOLinks_delete_cache'));
|
40 |
+
// Add Options Page
|
41 |
+
add_action('admin_menu', array(&$this, 'SEOLinks_admin_menu'));
|
42 |
+
|
43 |
+
}
|
44 |
+
|
45 |
+
function SEOLinks_process_text($text, $mode)
|
46 |
+
{
|
47 |
+
|
48 |
+
global $wpdb, $post;
|
49 |
+
|
50 |
+
$options = $this->get_options();
|
51 |
+
|
52 |
+
$links=0;
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
if ($options['onlysingle'] && !(is_single() || is_page()))
|
58 |
+
return $text;
|
59 |
+
|
60 |
+
$arrignorepost=$this->explode_trim(",", ($options['ignorepost']));
|
61 |
+
|
62 |
+
if (is_page($arrignorepost) || is_single($arrignorepost)) {
|
63 |
+
return $text;
|
64 |
+
}
|
65 |
+
|
66 |
+
if (!$mode)
|
67 |
+
{
|
68 |
+
if ($post->post_type=='post' && !$options['post'])
|
69 |
+
return $text;
|
70 |
+
else if ($post->post_type=='page' && !$options['page'])
|
71 |
+
return $text;
|
72 |
+
|
73 |
+
if (($post->post_type=='page' && !$options['pageself']) || ($post->post_type=='post' && !$options['postself'])) {
|
74 |
+
|
75 |
+
$thistitle=$options['casesens'] ? $post->post_title : strtolower($post->post_title);
|
76 |
+
$thisurl=trailingslashit(get_permalink($post->ID));
|
77 |
+
}
|
78 |
+
else {
|
79 |
+
$thistitle='';
|
80 |
+
$thisurl='';
|
81 |
+
}
|
82 |
+
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
$maxlinks=($options['maxlinks']>0) ? $options['maxlinks'] : 0;
|
87 |
+
$maxsingle=($options['maxsingle']>0) ? $options['maxsingle'] : -1;
|
88 |
+
$minusage = ($options['minusage']>0) ? $options['minusage'] : 1;
|
89 |
+
|
90 |
+
$arrignore=$this->explode_trim(",", ($options['ignore']));
|
91 |
+
|
92 |
+
// $reg_post = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))($name)/imsU';
|
93 |
+
// $reg = $options['casesens'] ? '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/msU' : '/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU';
|
94 |
+
$reg_post = $options['casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($name)/msU' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($name)/imsU';
|
95 |
+
$reg = $options['casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))\b($name)\b/msU' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))\b($name)\b/imsU';
|
96 |
+
$strpos_fnc = $options['casesens'] ? 'strpos' : 'stripos';
|
97 |
+
|
98 |
+
$text = " $text ";
|
99 |
+
|
100 |
+
// custom keywords
|
101 |
+
if (!empty($options['customkey']))
|
102 |
+
{
|
103 |
+
$kw_array = array();
|
104 |
+
|
105 |
+
// thanks PK for the suggestion
|
106 |
+
foreach (explode("\n", $options['customkey']) as $line) {
|
107 |
+
$chunks = array_map('trim', explode(",", $line));
|
108 |
+
$total_chuncks = count($chunks);
|
109 |
+
if($total_chuncks > 2) {
|
110 |
+
$i = 0;
|
111 |
+
$url = $chunks[$total_chuncks-1];
|
112 |
+
while($i < $total_chuncks-1) {
|
113 |
+
if (!empty($chunks[$i])) $kw_array[$chunks[$i]] = $url;
|
114 |
+
$i++;
|
115 |
+
}
|
116 |
+
} else {
|
117 |
+
list($keyword, $url) = array_map('trim', explode(",", $line, 2));
|
118 |
+
if (!empty($keyword)) $kw_array[$keyword] = $url;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
/*foreach (explode("\n", $options['customkey']) as $line) {
|
123 |
+
list($keyword, $url) = array_map('trim', explode(",", $line, 2));
|
124 |
+
if (!empty($keyword)) $kw_array[$keyword] = $url;
|
125 |
+
}*/
|
126 |
+
|
127 |
+
foreach ($kw_array as $name=>$url)
|
128 |
+
{
|
129 |
+
|
130 |
+
if ((!$maxlinks || ($links < $maxlinks)) && (trailingslashit($url)!=$thisurl) && !in_array( $options['casesens'] ? $name : strtolower($name), $arrignore))
|
131 |
+
{
|
132 |
+
if ($strpos_fnc($text, $name) !== false) { // credit to Dominik Deobald
|
133 |
+
$name= preg_quote($name, '/');
|
134 |
+
|
135 |
+
$replace="<a title=\"$1\" href=\"$url\">$1</a>";
|
136 |
+
$regexp=str_replace('$name', $name, $reg);
|
137 |
+
//$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))(?<!\p{L})($name)(?!\p{L})/imsU";
|
138 |
+
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
139 |
+
if ($newtext!=$text) {
|
140 |
+
$links++;
|
141 |
+
$text=$newtext;
|
142 |
+
}
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
|
149 |
+
// posts and pages
|
150 |
+
if ($options['lposts'] || $options['lpages'])
|
151 |
+
{
|
152 |
+
if ( !$posts = wp_cache_get( 'seo-links-posts', 'seo-smart-links' ) ) {
|
153 |
+
$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";
|
154 |
+
$posts = $wpdb->get_results($query);
|
155 |
+
|
156 |
+
wp_cache_add( 'seo-links-posts', $posts, 'seo-smart-links', 86400 );
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
foreach ($posts as $postitem)
|
161 |
+
{
|
162 |
+
if ((($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page')) &&
|
163 |
+
(!$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)) )
|
164 |
+
{
|
165 |
+
if ($strpos_fnc($text, $postitem->post_title) !== false) { // credit to Dominik Deobald
|
166 |
+
$name = preg_quote($postitem->post_title, '/');
|
167 |
+
|
168 |
+
$regexp=str_replace('$name', $name, $reg_post);
|
169 |
+
|
170 |
+
|
171 |
+
$replace='<a title="$1" href="$$$url$$$">$1</a>';
|
172 |
+
|
173 |
+
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
174 |
+
if ($newtext!=$text) {
|
175 |
+
$url = get_permalink($postitem->ID);
|
176 |
+
$links++;
|
177 |
+
$text=str_replace('$$$url$$$', $url, $newtext);
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
// categories
|
185 |
+
if ($options['lcats'])
|
186 |
+
{
|
187 |
+
if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
|
188 |
+
|
189 |
+
$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";
|
190 |
+
$categories = $wpdb->get_results($query);
|
191 |
+
|
192 |
+
wp_cache_add( 'seo-links-categories', $categories, 'seo-smart-links',86400 );
|
193 |
+
}
|
194 |
+
|
195 |
+
foreach ($categories as $cat)
|
196 |
+
{
|
197 |
+
if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $cat->name : strtolower($cat->name), $arrignore) )
|
198 |
+
{
|
199 |
+
if ($strpos_fnc($text, $cat->name) !== false) { // credit to Dominik Deobald
|
200 |
+
$name= preg_quote($cat->name, '/');
|
201 |
+
$regexp=str_replace('$name', $name, $reg); ;
|
202 |
+
$replace='<a title="$1" href="$$$url$$$">$1</a>';
|
203 |
+
|
204 |
+
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
205 |
+
if ($newtext!=$text) {
|
206 |
+
$url = (get_category_link($cat->term_id));
|
207 |
+
$links++;
|
208 |
+
$text=str_replace('$$$url$$$', $url, $newtext);
|
209 |
+
}
|
210 |
+
}
|
211 |
+
}
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
// tags
|
216 |
+
if ($options['ltags'])
|
217 |
+
{
|
218 |
+
if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
|
219 |
+
|
220 |
+
$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";
|
221 |
+
$tags = $wpdb->get_results($query);
|
222 |
+
|
223 |
+
wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
|
224 |
+
}
|
225 |
+
|
226 |
+
foreach ($tags as $tag)
|
227 |
+
{
|
228 |
+
if ((!$maxlinks || ($links < $maxlinks)) && !in_array( $options['casesens'] ? $tag->name : strtolower($tag->name), $arrignore) )
|
229 |
+
{
|
230 |
+
if ($strpos_fnc($text, $tag->name) !== false) { // credit to Dominik Deobald
|
231 |
+
$name = preg_quote($tag->name, '/');
|
232 |
+
$regexp=str_replace('$name', $name, $reg); ;
|
233 |
+
$replace='<a title="$1" href="$$$url$$$">$1</a>';
|
234 |
+
|
235 |
+
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
236 |
+
if ($newtext!=$text) {
|
237 |
+
$url = (get_tag_link($tag->term_id));
|
238 |
+
$links++;
|
239 |
+
$text=str_replace('$$$url$$$', $url, $newtext);
|
240 |
+
}
|
241 |
+
}
|
242 |
+
}
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
return trim( $text );
|
247 |
+
|
248 |
+
}
|
249 |
+
|
250 |
+
function SEOLinks_the_content_filter($text) {
|
251 |
+
|
252 |
+
$result=$this->SEOLinks_process_text($text, 0);
|
253 |
+
|
254 |
+
$options = $this->get_options();
|
255 |
+
$link=parse_url(get_bloginfo('wpurl'));
|
256 |
+
$host='http://'.$link['host'];
|
257 |
+
|
258 |
+
if ($options['blanko'])
|
259 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
|
260 |
+
|
261 |
+
if ($options['nofolo'])
|
262 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a rel="nofollow"\\1', $result);
|
263 |
+
return $result;
|
264 |
+
}
|
265 |
+
|
266 |
+
function SEOLinks_comment_text_filter($text) {
|
267 |
+
$result = $this->SEOLinks_process_text($text, 1);
|
268 |
+
|
269 |
+
$options = $this->get_options();
|
270 |
+
$link=parse_url(get_bloginfo('wpurl'));
|
271 |
+
$host='http://'.$link['host'];
|
272 |
+
|
273 |
+
if ($options['blanko'])
|
274 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
|
275 |
+
|
276 |
+
if ($options['nofolo'])
|
277 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a rel="nofollow"\\1', $result);
|
278 |
+
|
279 |
+
return $result;
|
280 |
+
}
|
281 |
+
|
282 |
+
function explode_trim($separator, $text)
|
283 |
+
{
|
284 |
+
$arr = explode($separator, $text);
|
285 |
+
|
286 |
+
$ret = array();
|
287 |
+
foreach($arr as $e)
|
288 |
+
{
|
289 |
+
$ret[] = trim($e);
|
290 |
+
}
|
291 |
+
return $ret;
|
292 |
+
}
|
293 |
+
|
294 |
+
// Handle our options
|
295 |
+
function get_options() {
|
296 |
+
|
297 |
+
$options = array(
|
298 |
+
'post' => 'on',
|
299 |
+
'postself' => '',
|
300 |
+
'page' => 'on',
|
301 |
+
'pageself' => '',
|
302 |
+
'comment' => '',
|
303 |
+
'lposts' => 'on',
|
304 |
+
'lpages' => 'on',
|
305 |
+
'lcats' => '',
|
306 |
+
'ltags' => '',
|
307 |
+
'ignore' => 'about,',
|
308 |
+
'ignorepost' => 'contact',
|
309 |
+
'maxlinks' => 3,
|
310 |
+
'maxsingle' => 1,
|
311 |
+
'minusage' => 1,
|
312 |
+
'customkey' => '',
|
313 |
+
'nofoln' =>'',
|
314 |
+
'nofolo' =>'',
|
315 |
+
'blankn' =>'',
|
316 |
+
'blanko' =>'',
|
317 |
+
'onlysingle' => 'on',
|
318 |
+
'casesens' =>''
|
319 |
+
|
320 |
+
);
|
321 |
+
|
322 |
+
$saved = get_option($this->SEOLinks_DB_option);
|
323 |
+
|
324 |
+
|
325 |
+
if (!empty($saved)) {
|
326 |
+
foreach ($saved as $key => $option)
|
327 |
+
$options[$key] = $option;
|
328 |
+
}
|
329 |
+
|
330 |
+
if ($saved != $options)
|
331 |
+
update_option($this->SEOLinks_DB_option, $options);
|
332 |
+
|
333 |
+
return $options;
|
334 |
+
|
335 |
+
}
|
336 |
+
|
337 |
+
|
338 |
+
|
339 |
+
// Set up everything
|
340 |
+
function install() {
|
341 |
+
$SEOLinks_options = $this->get_options();
|
342 |
+
|
343 |
+
|
344 |
+
}
|
345 |
+
|
346 |
+
function handle_options()
|
347 |
+
{
|
348 |
+
|
349 |
+
$options = $this->get_options();
|
350 |
+
if ( isset($_POST['submitted']) ) {
|
351 |
+
|
352 |
+
check_admin_referer('seo-smart-links');
|
353 |
+
|
354 |
+
$options['post']=$_POST['post'];
|
355 |
+
$options['postself']=$_POST['postself'];
|
356 |
+
$options['page']=$_POST['page'];
|
357 |
+
$options['pageself']=$_POST['pageself'];
|
358 |
+
$options['comment']=$_POST['comment'];
|
359 |
+
$options['lposts']=$_POST['lposts'];
|
360 |
+
$options['lpages']=$_POST['lpages'];
|
361 |
+
$options['lcats']=$_POST['lcats'];
|
362 |
+
$options['ltags']=$_POST['ltags'];
|
363 |
+
$options['ignore']=$_POST['ignore'];
|
364 |
+
$options['ignorepost']=$_POST['ignorepost'];
|
365 |
+
$options['maxlinks']=(int) $_POST['maxlinks'];
|
366 |
+
$options['maxsingle']=(int) $_POST['maxsingle'];
|
367 |
+
$options['minusage']=(int) $_POST['minusage']; // credit to Dominik Deobald
|
368 |
+
$options['customkey']=$_POST['customkey'];
|
369 |
+
$options['nofoln']=$_POST['nofoln'];
|
370 |
+
$options['nofolo']=$_POST['nofolo'];
|
371 |
+
$options['blankn']=$_POST['blankn'];
|
372 |
+
$options['blanko']=$_POST['blanko'];
|
373 |
+
$options['onlysingle']=$_POST['onlysingle'];
|
374 |
+
$options['casesens']=$_POST['casesens'];
|
375 |
+
|
376 |
+
|
377 |
+
update_option($this->SEOLinks_DB_option, $options);
|
378 |
+
$this->SEOLinks_delete_cache(0);
|
379 |
+
echo '<div class="updated fade"><p>Plugin settings saved.</p></div>';
|
380 |
+
}
|
381 |
+
|
382 |
+
|
383 |
+
|
384 |
+
|
385 |
+
$action_url = $_SERVER['REQUEST_URI'];
|
386 |
+
|
387 |
+
$post=$options['post']=='on'?'checked':'';
|
388 |
+
$postself=$options['postself']=='on'?'checked':'';
|
389 |
+
$page=$options['page']=='on'?'checked':'';
|
390 |
+
$pageself=$options['pageself']=='on'?'checked':'';
|
391 |
+
$comment=$options['comment']=='on'?'checked':'';
|
392 |
+
$lposts=$options['lposts']=='on'?'checked':'';
|
393 |
+
$lpages=$options['lpages']=='on'?'checked':'';
|
394 |
+
$lcats=$options['lcats']=='on'?'checked':'';
|
395 |
+
$ltags=$options['ltags']=='on'?'checked':'';
|
396 |
+
$ignore=$options['ignore'];
|
397 |
+
$ignorepost=$options['ignorepost'];
|
398 |
+
$maxlinks=$options['maxlinks'];
|
399 |
+
$maxsingle=$options['maxsingle'];
|
400 |
+
$minusage=$options['minusage'];
|
401 |
+
$customkey=stripslashes($options['customkey']);
|
402 |
+
$nofoln=$options['nofoln']=='on'?'checked':'';
|
403 |
+
$nofolo=$options['nofolo']=='on'?'checked':'';
|
404 |
+
$blankn=$options['blankn']=='on'?'checked':'';
|
405 |
+
$blanko=$options['blanko']=='on'?'checked':'';
|
406 |
+
$onlysingle=$options['onlysingle']=='on'?'checked':'';
|
407 |
+
$casesens=$options['casesens']=='on'?'checked':'';
|
408 |
+
|
409 |
+
if (!is_numeric($minusage)) $minusage = 1;
|
410 |
+
|
411 |
+
$nonce=wp_create_nonce( 'seo-smart-links');
|
412 |
+
|
413 |
+
$imgpath=trailingslashit(get_option('siteurl')). 'wp-content/plugins/seo-automatic-links/i';
|
414 |
+
echo <<<END
|
415 |
+
|
416 |
+
<div class="wrap" style="max-width:950px !important;">
|
417 |
+
<h2>SEO Smart Links</h2>
|
418 |
+
|
419 |
+
<div id="poststuff" style="margin-top:10px;">
|
420 |
+
|
421 |
+
<div id="sideblock" style="float:right;width:220px;margin-left:10px;">
|
422 |
+
<h2>Information</h2>
|
423 |
+
<div id="dbx-content" style="text-decoration:none;">
|
424 |
+
<img src="$imgpath/home.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins/seo-smart-links"> SEO Smart Links Home</a><br />
|
425 |
+
<img src="$imgpath/rate.png"><a style="text-decoration:none;" href="http://wordpress.org/extend/plugins/seo-automatic-links/"> Rate this plugin</a><br />
|
426 |
+
<img src="$imgpath/help.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/forum"> Support and Help</a><br />
|
427 |
+
<br />
|
428 |
+
<a style="text-decoration:none;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2567254"><img src="$imgpath/paypal.gif"></a>
|
429 |
+
<br /><br />
|
430 |
+
<img src="$imgpath/more.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins"> Cool WordPress Plugins</a><br />
|
431 |
+
<img src="$imgpath/twit.png"><a style="text-decoration:none;" href="http://twitter.com/vprelovac"> Follow updates on Twitter</a><br />
|
432 |
+
<img src="$imgpath/idea.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/services"> Need a WordPress Expert?</a>
|
433 |
+
</div>
|
434 |
+
</div>
|
435 |
+
|
436 |
+
<div id="mainblock" style="width:710px">
|
437 |
+
|
438 |
+
<div class="dbx-content">
|
439 |
+
<form name="SEOLinks" action="$action_url" method="post">
|
440 |
+
<input type="hidden" id="_wpnonce" name="_wpnonce" value="$nonce" />
|
441 |
+
<input type="hidden" name="submitted" value="1" />
|
442 |
+
<h2>Overview</h2>
|
443 |
+
|
444 |
+
<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>
|
445 |
+
<p>Further SEO Smart links allows you to set up your own keywords and set of matching URLs.</p>
|
446 |
+
<p>Finally SEO Smart links allows you to set nofollow attribute and open links in new window.</p>
|
447 |
+
|
448 |
+
<h2>Internal Links</h2>
|
449 |
+
<p>SEO Smart Links can process your posts, pages and comments in search for keywords to automatically interlink.</p>
|
450 |
+
<input type="checkbox" name="post" $post/><label for="post"> Posts</label>
|
451 |
+
<ul> <input type="checkbox" name="postself" $postself/><label for="postself"> Allow links to self</label></ul>
|
452 |
+
<br />
|
453 |
+
<input type="checkbox" name="page" $page/><label for="page"> Pages</label>
|
454 |
+
<ul> <input type="checkbox" name="pageself" $pageself/><label for="pageself"> Allow links to self</label></ul>
|
455 |
+
<br />
|
456 |
+
<input type="checkbox" name="comment" $comment /><label for="comment"> Comments</label> (may slow down performance) <br>
|
457 |
+
|
458 |
+
<h4>Target</h4>
|
459 |
+
<p>The targets SEO Smart links should consider. The match will be based on post/page title or category/tag name, case insensitive.</p>
|
460 |
+
<input type="checkbox" name="lposts" $lposts /><label for="lposts"> Posts</label> <br>
|
461 |
+
<input type="checkbox" name="lpages" $lpages /><label for="lpages"> Pages</label> <br>
|
462 |
+
<input type="checkbox" name="lcats" $lcats /><label for="lcats"> Categories</label> (may slow down performance) <br>
|
463 |
+
<input type="checkbox" name="ltags" $ltags /><label for="ltags"> Tags</label> (may slow down performance) <br>
|
464 |
+
<br>
|
465 |
+
Link tags and categories that have been used at least <input type="text" name="minusage" size="2" value="$minusage"/> times.
|
466 |
+
<br>
|
467 |
+
|
468 |
+
<h2>Settings</h2>
|
469 |
+
<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>
|
470 |
+
<input type="checkbox" name="onlysingle" $onlysingle /><label for="onlysingle"> Process only single posts and pages</label> <br>
|
471 |
+
|
472 |
+
<p>Set whether matching should be case sensitive.</p>
|
473 |
+
<input type="checkbox" name="casesens" $casesens /><label for="casesens"> Case sensitive matching</label> <br>
|
474 |
+
|
475 |
+
<h4>Ignore Posts and Pages</h4>
|
476 |
+
<p>You may wish to forbid automatic linking on certain posts or pages. Seperate them by comma. (id, slug or name)</p>
|
477 |
+
<input type="text" name="ignorepost" size="90" value="$ignorepost"/>
|
478 |
+
<br>
|
479 |
+
|
480 |
+
<h4>Ignore keywords</h4>
|
481 |
+
<p>You may wish to ignore certain words or phrases from automatic linking. Seperate them by comma.</p>
|
482 |
+
<input type="text" name="ignore" size="90" value="$ignore"/>
|
483 |
+
<br><br>
|
484 |
+
|
485 |
+
<h4>Custom Keywords</h4>
|
486 |
+
<p>Here you can enter manually the extra keywords you want to automaticaly link. Use comma to seperate keywords and add target url at the end. Use a new line for new url and set of keywords. You can have these keywords link to any url, not only your site.</p>
|
487 |
+
<p>Example:<br />
|
488 |
+
vladimir prelovac, http://www.prelovac.com/vladimir<br />
|
489 |
+
cars, car, autos, auto, http://mycarblog.com/<br />
|
490 |
+
</p>
|
491 |
+
|
492 |
+
<textarea name="customkey" id="customkey" rows="10" cols="90" >$customkey</textarea>
|
493 |
+
<br><br>
|
494 |
+
|
495 |
+
<h4>Limits</h4>
|
496 |
+
<p>You can limit the maximum number of links SEO Smart Links will generate per post. Set to 0 for no limit. </p>
|
497 |
+
Max Links: <input type="text" name="maxlinks" size="2" value="$maxlinks"/>
|
498 |
+
<p>You can also limit maximum number of links created with the same keyword. Set to 0 for no limit. </p>
|
499 |
+
Max Single: <input type="text" name="maxsingle" size="2" value="$maxsingle"/>
|
500 |
+
<br><br>
|
501 |
+
|
502 |
+
<h4>External Links</h4>
|
503 |
+
<p>SEO Smart links can open external links in new window and add nofollow attribute.</p>
|
504 |
+
|
505 |
+
|
506 |
+
<input type="checkbox" name="nofolo" $nofolo /><label for="nofolo"> Add nofollow attribute</label> <br>
|
507 |
+
|
508 |
+
|
509 |
+
<input type="checkbox" name="blanko" $blanko /><label for="blanko"> Open in new window</label> <br>
|
510 |
+
|
511 |
+
|
512 |
+
<div class="submit"><input type="submit" name="Submit" value="Update options" class="button-primary" /></div>
|
513 |
+
</form>
|
514 |
+
</div>
|
515 |
+
|
516 |
+
<br/><br/><h3> </h3>
|
517 |
+
</div>
|
518 |
+
|
519 |
+
</div>
|
520 |
+
|
521 |
+
<h5>WordPress plugin by <a href="http://www.prelovac.com/vladimir/">Vladimir Prelovac</a></h5>
|
522 |
+
</div>
|
523 |
+
END;
|
524 |
+
|
525 |
+
|
526 |
+
}
|
527 |
+
|
528 |
+
function SEOLinks_admin_menu()
|
529 |
+
{
|
530 |
+
add_options_page('SEO Smart Links Options', 'SEO Smart Links', 8, basename(__FILE__), array(&$this, 'handle_options'));
|
531 |
+
}
|
532 |
+
|
533 |
+
function SEOLinks_delete_cache($id) {
|
534 |
+
wp_cache_delete( 'seo-links-categories', 'seo-smart-links' );
|
535 |
+
wp_cache_delete( 'seo-links-tags', 'seo-smart-links' );
|
536 |
+
wp_cache_delete( 'seo-links-posts', 'seo-smart-links' );
|
537 |
+
}
|
538 |
+
//add_action( 'comment_post', 'SEOLinks_delete_cache');
|
539 |
+
//add_action( 'wp_set_comment_status', 'SEOLinks_delete_cache');
|
540 |
+
|
541 |
+
|
542 |
+
}
|
543 |
+
|
544 |
+
endif;
|
545 |
+
|
546 |
+
if ( class_exists('SEOLinks') ) :
|
547 |
+
|
548 |
+
$SEOLinks = new SEOLinks();
|
549 |
+
if (isset($SEOLinks)) {
|
550 |
+
register_activation_hook( __FILE__, array(&$SEOLinks, 'install') );
|
551 |
+
}
|
552 |
+
endif;
|
553 |
+
|
554 |
?>
|