Version Description
Download this release
Release Info
Developer | freediver |
Plugin | SEO Smart Links |
Version | 1.7.2 |
Comparing to | |
See all releases |
Code changes from version 1.7.1 to 1.7.2
- seo-links.php +134 -128
seo-links.php
CHANGED
@@ -2,11 +2,11 @@
|
|
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
|
9 |
-
Description: SEO Smart Links provides
|
10 |
|
11 |
*/
|
12 |
|
@@ -52,154 +52,156 @@ function SEOLinks_process_text($text, $mode)
|
|
52 |
|
53 |
|
54 |
|
55 |
-
if ($options['onlysingle'] && !(is_single() || is_page()))
|
56 |
-
return $text;
|
57 |
-
|
58 |
-
if (!$mode)
|
59 |
-
{
|
60 |
-
if ($post->post_type=='post' && !$options['post'])
|
61 |
-
return $text;
|
62 |
-
else if ($post->post_type=='page' && !$options['page'])
|
63 |
return $text;
|
64 |
|
65 |
-
if (
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
$arrignore=$this->explode_trim(",", strtolower($options['ignore'].$add));
|
80 |
-
|
81 |
-
$text = " $text ";
|
82 |
-
|
83 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
{
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
{
|
98 |
-
$name= preg_quote($name, '/');
|
99 |
-
$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
|
100 |
-
$replace="<a title=\"$1\" href=\"$url\">$1</a>";
|
101 |
|
102 |
-
$
|
103 |
-
|
104 |
-
$
|
105 |
-
$
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
-
|
111 |
-
|
112 |
-
}
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
124 |
-
|
125 |
|
126 |
-
|
|
|
127 |
{
|
128 |
-
if (
|
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 |
-
|
136 |
-
|
137 |
-
$url = get_permalink($postitem->ID);
|
138 |
-
$links++;
|
139 |
-
$text=str_replace('$$$url$$$', $url, $newtext);
|
140 |
-
}
|
141 |
-
}
|
142 |
-
}
|
143 |
-
}
|
144 |
-
|
145 |
-
if ($options['lcats'])
|
146 |
-
{
|
147 |
-
if ( !$categories = wp_cache_get( 'seo-links-categories', 'seo-smart-links' ) ) {
|
148 |
|
149 |
-
|
150 |
-
|
151 |
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
}
|
154 |
-
|
155 |
-
|
|
|
156 |
{
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
{
|
159 |
-
|
|
|
|
|
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 = (
|
166 |
$links++;
|
167 |
$text=str_replace('$$$url$$$', $url, $newtext);
|
168 |
-
}
|
169 |
-
|
170 |
-
}
|
171 |
-
}
|
172 |
-
}
|
173 |
-
if ($options['ltags'])
|
174 |
-
{
|
175 |
-
|
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 );
|
182 |
-
}
|
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 |
-
|
201 |
-
|
202 |
-
return trim( $text );
|
203 |
|
204 |
}
|
205 |
|
@@ -209,7 +211,7 @@ function SEOLinks_the_content_filter($text) {
|
|
209 |
|
210 |
$options = $this->get_options();
|
211 |
$link=parse_url(get_bloginfo('wpurl'));
|
212 |
-
$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
|
@@ -222,11 +224,15 @@ function SEOLinks_comment_text_filter($text) {
|
|
222 |
$result = $this->SEOLinks_process_text($text, 1);
|
223 |
|
224 |
$options = $this->get_options();
|
|
|
|
|
|
|
225 |
if ($options['blanko'])
|
226 |
-
$result = preg_replace('%<a(\s+.*?href=\S(?!' .
|
227 |
-
|
228 |
if ($options['nofolo'])
|
229 |
-
$result = preg_replace('%<a(\s+.*?href=\S(?!' .
|
|
|
230 |
return $result;
|
231 |
}
|
232 |
|
2 |
|
3 |
/*
|
4 |
Plugin Name: SEO Smart Links
|
5 |
+
Version: 1.7.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/vladimir
|
9 |
+
Description: SEO Smart Links provides SEO benefits for your blog by inter-linking the articles.
|
10 |
|
11 |
*/
|
12 |
|
52 |
|
53 |
|
54 |
|
55 |
+
if ($options['onlysingle'] && !(is_single() || is_page()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
return $text;
|
57 |
|
58 |
+
if (!$mode)
|
59 |
+
{
|
60 |
+
if ($post->post_type=='post' && !$options['post'])
|
61 |
+
return $text;
|
62 |
+
else if ($post->post_type=='page' && !$options['page'])
|
63 |
+
return $text;
|
64 |
+
|
65 |
+
if (($post->post_type=='page' && !$options['pageself']) || ($post->post_type=='post' && !$options['postself']))
|
66 |
+
$add=', '.$post->post_title;
|
67 |
+
else
|
68 |
+
$add='';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
+
|
72 |
+
$maxlinks=($options['maxlinks']>0) ? $options['maxlinks'] : 0;
|
73 |
+
|
74 |
+
$maxsingle=($options['maxsingle']>0) ? $options['maxsingle'] : -1;
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
$arrignore=$this->explode_trim(",", strtolower($options['ignore'].$add));
|
80 |
+
|
81 |
+
$text = " $text ";
|
82 |
+
|
83 |
+
// custom keywords
|
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 |
}
|
|
|
|
|
|
|
111 |
|
112 |
+
// posts and pages
|
113 |
+
if ($options['lposts'] || $options['lpages'])
|
114 |
+
{
|
115 |
+
if ( !$posts = wp_cache_get( 'seo-links-posts', 'seo-smart-links' ) ) {
|
116 |
+
|
117 |
+
|
118 |
+
$query="SELECT post_title, ID, guid, post_type FROM $wpdb->posts WHERE post_status = 'publish' AND LENGTH(post_title)>3 ORDER BY LENGTH(post_title) DESC";
|
119 |
+
$posts = $wpdb->get_results($query);
|
120 |
+
|
121 |
+
wp_cache_add( 'seo-links-posts', $posts, 'seo-smart-links', 86400 );
|
122 |
+
}
|
123 |
+
|
124 |
|
125 |
+
foreach ($posts as $postitem)
|
126 |
+
{
|
127 |
+
if (($options['lposts'] && $postitem->post_type=='post') || ($options['lpages'] && $postitem->post_type=='page') &&
|
128 |
+
!$maxlinks || ($links < $maxlinks) && !in_array( strtolower($postitem->post_title), $arrignore) && strstr($text, $postitem->post_title) )
|
129 |
+
{
|
130 |
+
$name = preg_quote($postitem->post_title, '/');
|
131 |
+
$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
|
132 |
+
$replace='<a title="$1" href="$$$url$$$">$1</a>';
|
133 |
+
|
134 |
+
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
135 |
+
if ($newtext!=$text) {
|
136 |
+
$url = get_permalink($postitem->ID);
|
137 |
+
$links++;
|
138 |
+
$text=str_replace('$$$url$$$', $url, $newtext);
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
}
|
|
|
143 |
|
144 |
+
// categories
|
145 |
+
if ($options['lcats'])
|
146 |
{
|
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 );
|
153 |
+
}
|
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 |
}
|
173 |
+
|
174 |
+
// tags
|
175 |
+
if ($options['ltags'])
|
176 |
{
|
177 |
+
|
178 |
+
if ( !$tags = wp_cache_get( 'seo-links-tags', 'seo-smart-links' ) ) {
|
179 |
+
|
180 |
+
$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";
|
181 |
+
$tags = $wpdb->get_results($query);
|
182 |
+
|
183 |
+
wp_cache_add( 'seo-links-tags', $tags, 'seo-smart-links',86400 );
|
184 |
+
}
|
185 |
+
|
186 |
+
foreach ($tags as $tag)
|
187 |
{
|
188 |
+
if (!$maxlinks || ($links < $maxlinks) && !in_array( strtolower($name), $arrignore) && strstr($text, $tag->name))
|
189 |
+
{
|
190 |
+
$name = preg_quote($tag->name, '/');
|
191 |
$regexp="/(?!(?:[^<]+>|[^>]+<\/a>))\b($name)\b/imsU";
|
192 |
$replace='<a title="$1" href="$$$url$$$">$1</a>';
|
193 |
+
|
194 |
$newtext = preg_replace($regexp, $replace, $text, $maxsingle);
|
195 |
+
if ($newtext!=$text) {
|
196 |
+
$url = (get_tag_link($tag->term_id));
|
197 |
$links++;
|
198 |
$text=str_replace('$$$url$$$', $url, $newtext);
|
199 |
+
}
|
200 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
}
|
202 |
}
|
203 |
+
|
204 |
+
return trim( $text );
|
|
|
205 |
|
206 |
}
|
207 |
|
211 |
|
212 |
$options = $this->get_options();
|
213 |
$link=parse_url(get_bloginfo('wpurl'));
|
214 |
+
$host='http://'.$link['host'];
|
215 |
|
216 |
if ($options['blanko'])
|
217 |
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
|
224 |
$result = $this->SEOLinks_process_text($text, 1);
|
225 |
|
226 |
$options = $this->get_options();
|
227 |
+
$link=parse_url(get_bloginfo('wpurl'));
|
228 |
+
$host='http://'.$link['host'];
|
229 |
+
|
230 |
if ($options['blanko'])
|
231 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a target="_blank"\\1', $result); // credit to Kaf Oseo
|
232 |
+
|
233 |
if ($options['nofolo'])
|
234 |
+
$result = preg_replace('%<a(\s+.*?href=\S(?!' . $host . '))%i', '<a rel="nofollow"\\1', $result);
|
235 |
+
|
236 |
return $result;
|
237 |
}
|
238 |
|