Version Description
Download this release
Release Info
Developer | mitchoyoshitaka |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 2.0.4 |
Comparing to | |
See all releases |
Code changes from version 2.0.1 to 2.0.4
- includes.php +57 -19
- magic.php +14 -12
- options.php +1 -1
- readme.txt +9 -2
- yarpp.php +2 -2
includes.php
CHANGED
@@ -31,7 +31,7 @@ function yarpp_enabled() {
|
|
31 |
global $wpdb;
|
32 |
$indexdata = $wpdb->get_results("show index from $wpdb->posts");
|
33 |
foreach ($indexdata as $index) {
|
34 |
-
if ($index->Key_name == '
|
35 |
}
|
36 |
return 0;
|
37 |
}
|
@@ -43,15 +43,17 @@ function yarpp_activate() {
|
|
43 |
add_option('yarpp_'.$option,$yarpp_options[$option]);
|
44 |
}
|
45 |
if (!yarpp_enabled()) {
|
46 |
-
$wpdb->query("ALTER TABLE
|
|
|
|
|
47 |
}
|
48 |
-
add_option('yarpp_version','2.
|
49 |
-
update_option('yarpp_version','2.
|
50 |
return 1;
|
51 |
}
|
52 |
|
53 |
function yarpp_upgrade_check() {
|
54 |
-
global $yarpp_value_options, $yarpp_binary_options;
|
55 |
|
56 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
57 |
yarpp_activate(); // just to make sure, in case the plugin was just replaced and not deactivated / activated
|
@@ -60,7 +62,7 @@ function yarpp_upgrade_check() {
|
|
60 |
update_option('yarpp_version','1.5');
|
61 |
}
|
62 |
|
63 |
-
if (get_option('yarpp_version') < 2
|
64 |
foreach (array_keys($yarpp_value_options) as $option) {
|
65 |
if (!get_option('yarpp_'.$option))
|
66 |
add_option('yarpp_'.$option,$yarpp_value_options[$option]);
|
@@ -71,7 +73,26 @@ function yarpp_upgrade_check() {
|
|
71 |
}
|
72 |
|
73 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 2.0. YARPP 2.0 adds the much requested ability to limit related entry results by certain tags or categories. 2.0 also brings more fine tuned control of the magic algorithm, letting you specify how the algorithm should consider or not consider entry content, titles, tags, and categories. Make sure to adjust the new settings to your liking and perhaps readjust your threshold.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p></div>';
|
74 |
-
update_option('yarpp_version','2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
|
77 |
}
|
@@ -82,7 +103,7 @@ function yarpp_admin_menu() {
|
|
82 |
}
|
83 |
|
84 |
function yarpp_options_page() {
|
85 |
-
require('
|
86 |
}
|
87 |
|
88 |
// This function was written by tyok
|
@@ -140,32 +161,49 @@ function yarpp_white($filter) {
|
|
140 |
|
141 |
/* FYI, apply_filters_if_white was used here to avoid a loop in apply_filters('the_content') > yarpp_default() > yarpp_related() > current_post_keywords() > apply_filters('the_content').*/
|
142 |
|
143 |
-
function apply_filters_if_white($tag, $
|
144 |
-
global $wp_filter, $merged_filters, $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
if ( !isset(
|
147 |
-
|
|
|
|
|
148 |
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
151 |
|
152 |
reset( $wp_filter[ $tag ] );
|
153 |
|
154 |
-
|
|
|
|
|
155 |
|
156 |
do{
|
157 |
foreach( (array) current($wp_filter[$tag]) as $the_ ) {
|
158 |
if ( !is_null($the_['function'])
|
159 |
and yarpp_white($the_['function'])){ // HACK
|
160 |
-
$args[1] = $
|
161 |
-
$
|
162 |
-
$string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
|
163 |
}
|
164 |
}
|
165 |
|
166 |
} while ( next($wp_filter[$tag]) !== false );
|
167 |
|
168 |
-
|
|
|
|
|
169 |
}
|
170 |
|
171 |
// upgrade to 1.5!
|
31 |
global $wpdb;
|
32 |
$indexdata = $wpdb->get_results("show index from $wpdb->posts");
|
33 |
foreach ($indexdata as $index) {
|
34 |
+
if ($index->Key_name == 'yarpp_title') return 1;
|
35 |
}
|
36 |
return 0;
|
37 |
}
|
43 |
add_option('yarpp_'.$option,$yarpp_options[$option]);
|
44 |
}
|
45 |
if (!yarpp_enabled()) {
|
46 |
+
// $wpdb->query("ALTER TABLE `wp_posts` DROP INDEX `yarpp_cache`");
|
47 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title`)");
|
48 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)");
|
49 |
}
|
50 |
+
add_option('yarpp_version','2.04');
|
51 |
+
update_option('yarpp_version','2.04');
|
52 |
return 1;
|
53 |
}
|
54 |
|
55 |
function yarpp_upgrade_check() {
|
56 |
+
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
57 |
|
58 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
59 |
yarpp_activate(); // just to make sure, in case the plugin was just replaced and not deactivated / activated
|
62 |
update_option('yarpp_version','1.5');
|
63 |
}
|
64 |
|
65 |
+
if (get_option('yarpp_version') < 2) {
|
66 |
foreach (array_keys($yarpp_value_options) as $option) {
|
67 |
if (!get_option('yarpp_'.$option))
|
68 |
add_option('yarpp_'.$option,$yarpp_value_options[$option]);
|
73 |
}
|
74 |
|
75 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 2.0. YARPP 2.0 adds the much requested ability to limit related entry results by certain tags or categories. 2.0 also brings more fine tuned control of the magic algorithm, letting you specify how the algorithm should consider or not consider entry content, titles, tags, and categories. Make sure to adjust the new settings to your liking and perhaps readjust your threshold.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p></div>';
|
76 |
+
update_option('yarpp_version','2.0');
|
77 |
+
}
|
78 |
+
|
79 |
+
if (get_option('yarpp_version') < 2.02) {
|
80 |
+
update_option('yarpp_version','2.02');
|
81 |
+
}
|
82 |
+
|
83 |
+
if (get_option('yarpp_version') < 2.03) {
|
84 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title`)");
|
85 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)"); update_option('yarpp_version','2.03');
|
86 |
+
}
|
87 |
+
|
88 |
+
if (get_option('yarpp_version') < 2.04) {
|
89 |
+
update_option('yarpp_version','2.04');
|
90 |
+
}
|
91 |
+
|
92 |
+
// just in case, try to add the index one more time.
|
93 |
+
if (!yarpp_enabled()) {
|
94 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title`)");
|
95 |
+
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)");
|
96 |
}
|
97 |
|
98 |
}
|
103 |
}
|
104 |
|
105 |
function yarpp_options_page() {
|
106 |
+
require(str_replace('includes.php','options.php',__FILE__));
|
107 |
}
|
108 |
|
109 |
// This function was written by tyok
|
161 |
|
162 |
/* FYI, apply_filters_if_white was used here to avoid a loop in apply_filters('the_content') > yarpp_default() > yarpp_related() > current_post_keywords() > apply_filters('the_content').*/
|
163 |
|
164 |
+
function apply_filters_if_white($tag, $value) {
|
165 |
+
global $wp_filter, $merged_filters, $wp_current_filter;
|
166 |
+
|
167 |
+
$args = array();
|
168 |
+
$wp_current_filter[] = $tag;
|
169 |
+
|
170 |
+
// Do 'all' actions first
|
171 |
+
if ( isset($wp_filter['all']) ) {
|
172 |
+
$args = func_get_args();
|
173 |
+
_wp_call_all_hook($args);
|
174 |
+
}
|
175 |
|
176 |
+
if ( !isset($wp_filter[$tag]) ) {
|
177 |
+
array_pop($wp_current_filter);
|
178 |
+
return $value;
|
179 |
+
}
|
180 |
|
181 |
+
// Sort
|
182 |
+
if ( !isset( $merged_filters[ $tag ] ) ) {
|
183 |
+
ksort($wp_filter[$tag]);
|
184 |
+
$merged_filters[ $tag ] = true;
|
185 |
+
}
|
186 |
|
187 |
reset( $wp_filter[ $tag ] );
|
188 |
|
189 |
+
if ( empty($args) )
|
190 |
+
$args = func_get_args();
|
191 |
+
|
192 |
|
193 |
do{
|
194 |
foreach( (array) current($wp_filter[$tag]) as $the_ ) {
|
195 |
if ( !is_null($the_['function'])
|
196 |
and yarpp_white($the_['function'])){ // HACK
|
197 |
+
$args[1] = $value;
|
198 |
+
$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
|
|
|
199 |
}
|
200 |
}
|
201 |
|
202 |
} while ( next($wp_filter[$tag]) !== false );
|
203 |
|
204 |
+
array_pop( $wp_current_filter );
|
205 |
+
|
206 |
+
return $value;
|
207 |
}
|
208 |
|
209 |
// upgrade to 1.5!
|
magic.php
CHANGED
@@ -82,23 +82,22 @@ function yarpp_sql($options_array,$giveresults = true) {
|
|
82 |
|
83 |
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
|
84 |
|
85 |
-
$weightedthresh = $threshold
|
86 |
|
87 |
// get disallowed categories and tags
|
88 |
|
89 |
$disterms = implode(',', array_filter(array_merge(explode(',',get_option('yarpp_discats')),explode(',',get_option('yarpp_distags'))),'is_numeric'));
|
90 |
|
91 |
-
|
92 |
$sql = "SELECT *, (bodyscore * $bodyweight + titlescore * $titleweight + tagscore * $tagweight + catscore * $catweight) AS score
|
93 |
from (
|
94 |
-
select ID, post_title, post_date, post_content, (MATCH (post_content) AGAINST ('
|
95 |
-
from $wpdb->posts
|
96 |
-
|
97 |
select count(*) as block, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy natural join $wpdb->terms
|
98 |
where $wpdb->terms.term_id in ($disterms)
|
99 |
group by object_id
|
100 |
-
) as poolblock on ($wpdb->posts.ID = poolblock.object_id)
|
101 |
-
|
102 |
select count(*) as tagscore, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy
|
103 |
where $wpdb->term_taxonomy.taxonomy = 'post_tag'
|
104 |
and $wpdb->term_taxonomy.term_taxonomy_id in (select term_taxonomy_id from $wpdb->term_relationships where object_id = '$post->ID')
|
@@ -113,17 +112,20 @@ function yarpp_sql($options_array,$giveresults = true) {
|
|
113 |
where ((post_status IN ( 'publish', 'static' ) && ID != '$post->ID')"
|
114 |
.($past_only ?" and post_date <= '$now' ":' ')
|
115 |
.((!$show_pass_post)?" and post_password ='' ":' ')
|
116 |
-
." and post_type IN ('".implode("', '",$type)."')
|
117 |
-
and block IS NULL
|
118 |
-
)
|
119 |
-
) as rawscores
|
120 |
-
|
|
|
121 |
.((get_option('yarpp_categories') == 3)?' and catscore >= 1':'')
|
122 |
.((get_option('yarpp_categories') == 4)?' and catscore >= 2':'')
|
123 |
.((get_option('yarpp_tags') == 3)?' and tagscore >= 1':'')
|
124 |
.((get_option('yarpp_tags') == 4)?' and tagscore >= 2':'')
|
125 |
." order by ".((get_option('yarpp_order')?get_option('yarpp_order'):"score desc"))." limit $limit";
|
126 |
|
|
|
|
|
127 |
if (!$giveresults) {
|
128 |
$sql = 'select count(*) from ('.$sql.')';
|
129 |
}
|
82 |
|
83 |
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
|
84 |
|
85 |
+
$weightedthresh = $threshold/($totalweight + 0.1);
|
86 |
|
87 |
// get disallowed categories and tags
|
88 |
|
89 |
$disterms = implode(',', array_filter(array_merge(explode(',',get_option('yarpp_discats')),explode(',',get_option('yarpp_distags'))),'is_numeric'));
|
90 |
|
|
|
91 |
$sql = "SELECT *, (bodyscore * $bodyweight + titlescore * $titleweight + tagscore * $tagweight + catscore * $catweight) AS score
|
92 |
from (
|
93 |
+
select ID, post_title, post_date, post_content, (MATCH (post_content) AGAINST ('".post_body_keywords()."')) as bodyscore, (MATCH (post_title) AGAINST ('".post_title_keywords()."')) as titlescore, ifnull(catscore,0) as catscore, ifnull(tagscore,0) as tagscore
|
94 |
+
from $wpdb->posts "
|
95 |
+
.(count(array_filter(array_merge(explode(',',get_option('yarpp_discats')),explode(',',get_option('yarpp_distags'))),'is_numeric'))?" left join (
|
96 |
select count(*) as block, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy natural join $wpdb->terms
|
97 |
where $wpdb->terms.term_id in ($disterms)
|
98 |
group by object_id
|
99 |
+
) as poolblock on ($wpdb->posts.ID = poolblock.object_id)":'')
|
100 |
+
." left join (
|
101 |
select count(*) as tagscore, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy
|
102 |
where $wpdb->term_taxonomy.taxonomy = 'post_tag'
|
103 |
and $wpdb->term_taxonomy.term_taxonomy_id in (select term_taxonomy_id from $wpdb->term_relationships where object_id = '$post->ID')
|
112 |
where ((post_status IN ( 'publish', 'static' ) && ID != '$post->ID')"
|
113 |
.($past_only ?" and post_date <= '$now' ":' ')
|
114 |
.((!$show_pass_post)?" and post_password ='' ":' ')
|
115 |
+
." and post_type IN ('".implode("', '",$type)."')"
|
116 |
+
.(count(array_filter(array_merge(explode(',',get_option('yarpp_discats')),explode(',',get_option('yarpp_distags'))),'is_numeric'))?" and block IS NULL":'').
|
117 |
+
" )
|
118 |
+
) as rawscores";
|
119 |
+
|
120 |
+
$sql .= " where (bodyscore * $bodyweight + titlescore * $titleweight + tagscore * $tagweight + catscore * $catweight) >= $threshold"
|
121 |
.((get_option('yarpp_categories') == 3)?' and catscore >= 1':'')
|
122 |
.((get_option('yarpp_categories') == 4)?' and catscore >= 2':'')
|
123 |
.((get_option('yarpp_tags') == 3)?' and tagscore >= 1':'')
|
124 |
.((get_option('yarpp_tags') == 4)?' and tagscore >= 2':'')
|
125 |
." order by ".((get_option('yarpp_order')?get_option('yarpp_order'):"score desc"))." limit $limit";
|
126 |
|
127 |
+
//echo $sql;
|
128 |
+
|
129 |
if (!$giveresults) {
|
130 |
$sql = 'select count(*) from ('.$sql.')';
|
131 |
}
|
options.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
-
global $yarpp_value_options, $yarpp_binary_options;
|
5 |
if (!yarpp_enabled()) {
|
6 |
echo '<div class="updated">';
|
7 |
if (yarpp_activate()) echo 'The YARPP database had an error but has been fixed.';
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
+
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
5 |
if (!yarpp_enabled()) {
|
6 |
echo '<div class="updated">';
|
7 |
if (yarpp_activate()) echo 'The YARPP database had an error but has been fixed.';
|
readme.txt
CHANGED
@@ -6,8 +6,8 @@ Plugin URI: http://mitcho.com/code/yarpp/
|
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mitcho%40mitcho%2ecom&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
7 |
Tags: related, posts, post, pages, page
|
8 |
Requires at least: 2.3
|
9 |
-
Tested up to: 2.
|
10 |
-
Stable tag: 2.0.
|
11 |
|
12 |
Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold. New and improved, version 2.0!
|
13 |
|
@@ -88,6 +88,13 @@ I highly recommend you disactivate YARPP, replace it with the new one, and then
|
|
88 |
* 2.0.1
|
89 |
* Bugfix: [`admin_menu` instead of `admin_head`](http://konstruktors.com/blog/wordpress/277-fixing-postpost-and-ozh-absolute-comments-plugins/)
|
90 |
* Bugfix: [a variable scope issue](http://wordpress.org/support/topic/188550) crucial for 2.0 upgrading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
== Future versions ==
|
93 |
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mitcho%40mitcho%2ecom&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
7 |
Tags: related, posts, post, pages, page
|
8 |
Requires at least: 2.3
|
9 |
+
Tested up to: 2.6
|
10 |
+
Stable tag: 2.0.4
|
11 |
|
12 |
Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold. New and improved, version 2.0!
|
13 |
|
88 |
* 2.0.1
|
89 |
* Bugfix: [`admin_menu` instead of `admin_head`](http://konstruktors.com/blog/wordpress/277-fixing-postpost-and-ozh-absolute-comments-plugins/)
|
90 |
* Bugfix: [a variable scope issue](http://wordpress.org/support/topic/188550) crucial for 2.0 upgrading
|
91 |
+
* 2.0.2
|
92 |
+
* Versioning bugfix (rerelease of 2.0.1)
|
93 |
+
* 2.0.3
|
94 |
+
* Bugfix: [2.0.2 accidentally required some tags or categories to be disabled](http://wordpress.org/support/topic/188745)
|
95 |
+
* 2.0.4 - what 2.0 should have been
|
96 |
+
* Bugfix: new fulltext query for MySQL 5 compatibility
|
97 |
+
* Bugfix: updated apply_filters to work with WP 2.6
|
98 |
|
99 |
== Future versions ==
|
100 |
|
yarpp.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://mitcho.com/code/yarpp/
|
5 |
-
Description: Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold.
|
6 |
-
Version: 2.0
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|
2 |
/*
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://mitcho.com/code/yarpp/
|
5 |
+
Description: Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold. New and improved, version 2.0!
|
6 |
+
Version: 2.0.4
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|