Version Description
Download this release
Release Info
Developer | RobMarsh |
Plugin | Similar Posts – Best Related Posts Plugin for WordPress |
Version | 2.6.1.0 |
Comparing to | |
See all releases |
Code changes from version 2.6.0.1 to 2.6.1.0
- readme.txt +7 -3
- similar-posts-admin.php +6 -1
- similar-posts.php +47 -34
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Similar Posts ===
|
2 |
Contributors: RobMarsh
|
3 |
-
Donate link:
|
4 |
Tags: posts, related, similar, related posts, similar posts, tags, post-plugins
|
5 |
Requires at least: 1.5
|
6 |
-
Tested up to: 2.6.
|
7 |
-
Stable tag: 2.6.0
|
8 |
Displays a list of posts similar to the current one based on content, title and/or tags.
|
9 |
|
10 |
== Description ==
|
@@ -31,6 +31,10 @@ This plugin **requires** the latest version of the *Post-Plugin Library:* [downl
|
|
31 |
|
32 |
== Version History ==
|
33 |
|
|
|
|
|
|
|
|
|
34 |
* 2.6.0.1
|
35 |
* bug fix: installation code was failing on some systems
|
36 |
* 2.6.0.0
|
1 |
=== Similar Posts ===
|
2 |
Contributors: RobMarsh
|
3 |
+
Donate link: http://rmarsh.com/donate/similar-posts/
|
4 |
Tags: posts, related, similar, related posts, similar posts, tags, post-plugins
|
5 |
Requires at least: 1.5
|
6 |
+
Tested up to: 2.6.1
|
7 |
+
Stable tag: 2.6.1.0
|
8 |
Displays a list of posts similar to the current one based on content, title and/or tags.
|
9 |
|
10 |
== Description ==
|
31 |
|
32 |
== Version History ==
|
33 |
|
34 |
+
* 2.6.1.0
|
35 |
+
* the current post can be marked manually
|
36 |
+
* widgets now honour the option to show no output if list is empty
|
37 |
+
* fixed a bug with finding the right language files
|
38 |
* 2.6.0.1
|
39 |
* bug fix: installation code was failing on some systems
|
40 |
* 2.6.0.0
|
similar-posts-admin.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
// Admin stuff for Similar Posts Plugin, Version 2.6.0
|
4 |
|
5 |
function similar_posts_option_menu() {
|
6 |
add_options_page(__('Similar Posts Options', 'similar_posts'), __('Similar Posts', 'similar_posts'), 8, 'similar-posts', 'similar_posts_options_page');
|
@@ -45,6 +45,11 @@ function similar_posts_options_page(){
|
|
45 |
$m->add_subpage('Report a Bug', 'bug', 'similar_posts_bug_subpage');
|
46 |
$m->add_subpage('Remove this Plugin', 'remove', 'similar_posts_remove_subpage');
|
47 |
$m->display();
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
function similar_posts_general_options_subpage(){
|
1 |
<?php
|
2 |
|
3 |
+
// Admin stuff for Similar Posts Plugin, Version 2.6.1.0
|
4 |
|
5 |
function similar_posts_option_menu() {
|
6 |
add_options_page(__('Similar Posts Options', 'similar_posts'), __('Similar Posts', 'similar_posts'), 8, 'similar-posts', 'similar_posts_options_page');
|
45 |
$m->add_subpage('Report a Bug', 'bug', 'similar_posts_bug_subpage');
|
46 |
$m->add_subpage('Remove this Plugin', 'remove', 'similar_posts_remove_subpage');
|
47 |
$m->display();
|
48 |
+
add_action('in_admin_footer', 'similar_posts_admin_footer');
|
49 |
+
}
|
50 |
+
|
51 |
+
function similar_posts_admin_footer() {
|
52 |
+
ppl_admin_footer(str_replace('-admin', '', __FILE__), "similar-posts");
|
53 |
}
|
54 |
|
55 |
function similar_posts_general_options_subpage(){
|
similar-posts.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name:Similar Posts
|
4 |
Plugin URI: http://rmarsh.com/plugins/similar-posts/
|
5 |
Description: Displays a <a href="options-general.php?page=similar-posts.php">highly configurable</a> list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags. Don't be disturbed if it takes a few moments to complete the installation -- the plugin is indexing your posts. <a href="http://rmarsh.com/plugins/post-options/">Instructions and help online</a>. Requires the latest version of the <a href="http://wordpress.org/extend/plugins/post-plugin-library/">Post-Plugin Library</a> to be installed.
|
6 |
-
Version: 2.6.0
|
7 |
Author: Rob Marsh, SJ
|
8 |
Author URI: http://rmarsh.com/
|
9 |
*/
|
@@ -22,7 +22,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 |
GNU General Public License for more details: http://www.gnu.org/licenses/gpl.txt
|
23 |
*/
|
24 |
|
25 |
-
$similar_posts_version = $similar_posts_feed_version= '2.6.0
|
26 |
|
27 |
/*
|
28 |
Template Tag: Displays the posts most similar to the current post.
|
@@ -34,22 +34,30 @@ function similar_posts($args = '') {
|
|
34 |
echo SimilarPosts::execute($args);
|
35 |
}
|
36 |
|
|
|
|
|
|
|
|
|
|
|
37 |
/*
|
38 |
|
39 |
'innards'
|
40 |
|
41 |
*/
|
42 |
|
|
|
43 |
if (!defined('DSEP')) define('DSEP', DIRECTORY_SEPARATOR);
|
44 |
if (!defined('POST_PLUGIN_LIBRARY')) SimilarPosts::install_post_plugin_library();
|
45 |
|
|
|
|
|
46 |
class SimilarPosts {
|
47 |
|
48 |
function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
|
49 |
if (!SimilarPosts::check_post_plugin_library('<a href="http://downloads.wordpress.org/plugin/post-plugin-library.zip">'.__('Post-Plugin Library missing').'</a>')) return '';
|
50 |
-
global $table_prefix, $wpdb, $wp_version;
|
51 |
$start_time = ppl_microtime();
|
52 |
-
$postid = ppl_current_post_id();
|
53 |
if (defined('POC_CACHE_4')) {
|
54 |
$cache_key = $option_key.$postid.$args;
|
55 |
$result = poc_cache_fetch($cache_key);
|
@@ -127,14 +135,14 @@ class SimilarPosts {
|
|
127 |
if ($exclude_posts) $where[] = where_excluded_posts(trim($options['excluded_posts']));
|
128 |
if ($include_posts) $where[] = where_included_posts(trim($options['included_posts']));
|
129 |
if ($use_tag_str) $where[] = where_tag_str($options['tag_str']);
|
130 |
-
if ($omit_current_post) $where[] = where_omit_post();
|
131 |
if ($hide_pass) $where[] = where_hide_pass();
|
132 |
if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
|
133 |
if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
|
134 |
$sql .= "WHERE ".implode(' AND ', $where);
|
135 |
if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
|
136 |
$sql .= " ORDER BY score DESC LIMIT $limit";
|
137 |
-
|
138 |
} else {
|
139 |
$results = false;
|
140 |
}
|
@@ -157,7 +165,7 @@ class SimilarPosts {
|
|
157 |
}
|
158 |
}
|
159 |
if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
|
160 |
-
return $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time));
|
161 |
}
|
162 |
|
163 |
// tries to install the post-plugin-library plugin
|
@@ -233,30 +241,32 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
|
|
233 |
$oldrank[$vertex] = 0.25;
|
234 |
}
|
235 |
$n = count($graph);
|
236 |
-
$
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
$
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
247 |
}
|
248 |
-
$
|
249 |
-
$error
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
}
|
251 |
-
|
252 |
-
//echo $error . '<br>';
|
253 |
-
} while ($error > $error_margin);
|
254 |
-
arsort($rank);
|
255 |
-
if ($num_terms < 1) $num_terms = 1;
|
256 |
-
$rank = array_slice($rank, 0, $num_terms);
|
257 |
-
foreach ($rank as $vertex => $score) {
|
258 |
-
$terms .= ' ' . $vertex;
|
259 |
-
}
|
260 |
$res[] = $terms;
|
261 |
$res[] = $results[0]['title'];
|
262 |
$res[] = $results[0]['tags'];
|
@@ -506,10 +516,13 @@ function widget_rrm_similar_posts_init() {
|
|
506 |
$number = 1;
|
507 |
else if ( $number > 15 )
|
508 |
$number = 15;
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
|
|
|
|
|
|
513 |
}
|
514 |
}
|
515 |
function widget_rrm_similar_posts_control() {
|
@@ -550,7 +563,7 @@ $language = substr(WPLANG, 0, 2);
|
|
550 |
if ($language == '') {
|
551 |
$language = 'en';
|
552 |
}
|
553 |
-
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.$language.
|
554 |
//see if the directory exists and if not revert to the default English dir
|
555 |
if (!file_exists($languagedir)) {
|
556 |
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.'en'.DSEP;
|
3 |
Plugin Name:Similar Posts
|
4 |
Plugin URI: http://rmarsh.com/plugins/similar-posts/
|
5 |
Description: Displays a <a href="options-general.php?page=similar-posts.php">highly configurable</a> list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags. Don't be disturbed if it takes a few moments to complete the installation -- the plugin is indexing your posts. <a href="http://rmarsh.com/plugins/post-options/">Instructions and help online</a>. Requires the latest version of the <a href="http://wordpress.org/extend/plugins/post-plugin-library/">Post-Plugin Library</a> to be installed.
|
6 |
+
Version: 2.6.1.0
|
7 |
Author: Rob Marsh, SJ
|
8 |
Author URI: http://rmarsh.com/
|
9 |
*/
|
22 |
GNU General Public License for more details: http://www.gnu.org/licenses/gpl.txt
|
23 |
*/
|
24 |
|
25 |
+
$similar_posts_version = $similar_posts_feed_version= '2.6.1.0';
|
26 |
|
27 |
/*
|
28 |
Template Tag: Displays the posts most similar to the current post.
|
34 |
echo SimilarPosts::execute($args);
|
35 |
}
|
36 |
|
37 |
+
function similar_posts_mark_current(){
|
38 |
+
global $post, $similar_posts_current_ID;
|
39 |
+
$similar_posts_current_ID = $post->ID;
|
40 |
+
}
|
41 |
+
|
42 |
/*
|
43 |
|
44 |
'innards'
|
45 |
|
46 |
*/
|
47 |
|
48 |
+
|
49 |
if (!defined('DSEP')) define('DSEP', DIRECTORY_SEPARATOR);
|
50 |
if (!defined('POST_PLUGIN_LIBRARY')) SimilarPosts::install_post_plugin_library();
|
51 |
|
52 |
+
$similar_posts_current_ID = -1;
|
53 |
+
|
54 |
class SimilarPosts {
|
55 |
|
56 |
function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
|
57 |
if (!SimilarPosts::check_post_plugin_library('<a href="http://downloads.wordpress.org/plugin/post-plugin-library.zip">'.__('Post-Plugin Library missing').'</a>')) return '';
|
58 |
+
global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;
|
59 |
$start_time = ppl_microtime();
|
60 |
+
$postid = ppl_current_post_id($similar_posts_current_ID);
|
61 |
if (defined('POC_CACHE_4')) {
|
62 |
$cache_key = $option_key.$postid.$args;
|
63 |
$result = poc_cache_fetch($cache_key);
|
135 |
if ($exclude_posts) $where[] = where_excluded_posts(trim($options['excluded_posts']));
|
136 |
if ($include_posts) $where[] = where_included_posts(trim($options['included_posts']));
|
137 |
if ($use_tag_str) $where[] = where_tag_str($options['tag_str']);
|
138 |
+
if ($omit_current_post) $where[] = where_omit_post($similar_posts_current_ID);
|
139 |
if ($hide_pass) $where[] = where_hide_pass();
|
140 |
if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
|
141 |
if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
|
142 |
$sql .= "WHERE ".implode(' AND ', $where);
|
143 |
if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
|
144 |
$sql .= " ORDER BY score DESC LIMIT $limit";
|
145 |
+
$results = $wpdb->get_results($sql);
|
146 |
} else {
|
147 |
$results = false;
|
148 |
}
|
165 |
}
|
166 |
}
|
167 |
if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
|
168 |
+
return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
|
169 |
}
|
170 |
|
171 |
// tries to install the post-plugin-library plugin
|
241 |
$oldrank[$vertex] = 0.25;
|
242 |
}
|
243 |
$n = count($graph);
|
244 |
+
if ($n > 0) {
|
245 |
+
$base = 0.15 / $n;
|
246 |
+
$error_margin = $n * 0.005;
|
247 |
+
do {
|
248 |
+
$error = 0.0;
|
249 |
+
// the edge-weighted PageRank calculation
|
250 |
+
reset($graph);
|
251 |
+
while (list($vertex, $in_edges) = each($graph)) {
|
252 |
+
$r = 0;
|
253 |
+
reset($in_edges);
|
254 |
+
while (list($edge, $weight) = each($in_edges)) {
|
255 |
+
$r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
|
256 |
+
}
|
257 |
+
$rank[$vertex] = $base + 0.95 * $r;
|
258 |
+
$error += abs($rank[$vertex] - $oldrank[$vertex]);
|
259 |
}
|
260 |
+
$oldrank = $rank;
|
261 |
+
//echo $error . '<br>';
|
262 |
+
} while ($error > $error_margin);
|
263 |
+
arsort($rank);
|
264 |
+
if ($num_terms < 1) $num_terms = 1;
|
265 |
+
$rank = array_slice($rank, 0, $num_terms);
|
266 |
+
foreach ($rank as $vertex => $score) {
|
267 |
+
$terms .= ' ' . $vertex;
|
268 |
}
|
269 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
$res[] = $terms;
|
271 |
$res[] = $results[0]['title'];
|
272 |
$res[] = $results[0]['tags'];
|
516 |
$number = 1;
|
517 |
else if ( $number > 15 )
|
518 |
$number = 15;
|
519 |
+
$output = SimilarPosts::execute('limit='.$number);
|
520 |
+
if ($output) {
|
521 |
+
echo $before_widget;
|
522 |
+
echo $before_title.$title.$after_title;
|
523 |
+
echo $output;
|
524 |
+
echo $after_widget;
|
525 |
+
}
|
526 |
}
|
527 |
}
|
528 |
function widget_rrm_similar_posts_control() {
|
563 |
if ($language == '') {
|
564 |
$language = 'en';
|
565 |
}
|
566 |
+
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.$language.DSEP;
|
567 |
//see if the directory exists and if not revert to the default English dir
|
568 |
if (!file_exists($languagedir)) {
|
569 |
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.'en'.DSEP;
|