Version Description
Download this release
Release Info
Developer | mitchoyoshitaka |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 3.4b7 |
Comparing to | |
See all releases |
Code changes from version 3.4b6 to 3.4b7
- cache-postmeta.php +1 -1
- class-core.php +1 -1
- magic.php +48 -53
- readme.txt +2 -0
- yarpp.php +2 -2
cache-postmeta.php
CHANGED
@@ -93,7 +93,7 @@ class YARPP_Cache_Postmeta {
|
|
93 |
}
|
94 |
|
95 |
public function fields_filter($arg) {
|
96 |
-
global $wpdb
|
97 |
if ($this->yarpp_time && is_array($this->related_postdata) && count($this->related_postdata)) {
|
98 |
$scores = array();
|
99 |
foreach ($this->related_postdata as $related_entry) {
|
93 |
}
|
94 |
|
95 |
public function fields_filter($arg) {
|
96 |
+
global $wpdb;
|
97 |
if ($this->yarpp_time && is_array($this->related_postdata) && count($this->related_postdata)) {
|
98 |
$scores = array();
|
99 |
foreach ($this->related_postdata as $related_entry) {
|
class-core.php
CHANGED
@@ -69,7 +69,7 @@ class YARPP {
|
|
69 |
}
|
70 |
|
71 |
function activate() {
|
72 |
-
global $
|
73 |
|
74 |
$wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
|
75 |
if (!$wpdb->num_rows)
|
69 |
}
|
70 |
|
71 |
function activate() {
|
72 |
+
global $wpdb;
|
73 |
|
74 |
$wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
|
75 |
if (!$wpdb->num_rows)
|
magic.php
CHANGED
@@ -8,6 +8,12 @@ function yarpp_sql( $reference_ID = false ) {
|
|
8 |
if ( is_object($post) && !$reference_ID ) {
|
9 |
$reference_ID = $post->ID;
|
10 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
$options = array( 'threshold', 'show_pass_post', 'past_only', 'body', 'title', 'tags', 'categories', 'exclude', 'recent_only', 'recent_number', 'recent_units');
|
13 |
$yarpp_options = yarpp_get_option();
|
@@ -15,97 +21,86 @@ function yarpp_sql( $reference_ID = false ) {
|
|
15 |
$optvals = array_intersect_key($yarpp_options, array_flip($options));
|
16 |
extract($optvals);
|
17 |
|
18 |
-
$limit = max(yarpp_get_option('limit'), yarpp_get_option('rss_limit'));
|
19 |
-
|
20 |
// Fetch keywords
|
21 |
$keywords = $yarpp->cache->get_keywords($reference_ID);
|
22 |
|
23 |
-
//
|
24 |
$weights = array(
|
25 |
'body' => (($body == 3)?3:(($body == 2)?1:0)),
|
26 |
'title' => (($title == 3)?3:(($title == 2)?1:0)),
|
27 |
-
'
|
28 |
-
'
|
29 |
);
|
30 |
-
|
31 |
-
|
32 |
-
// get disallowed categories and tags
|
33 |
-
$disterms = wp_parse_id_list($exclude['category'] . ',' . $exclude['post_tag']);
|
34 |
-
$usedisterms = count($disterms);
|
35 |
-
$disterms = implode(',', $disterms);
|
36 |
|
|
|
37 |
$criteria = array();
|
38 |
if ($weights['body'])
|
39 |
$criteria['body'] = "(MATCH (post_content) AGAINST ('".$wpdb->escape($keywords['body'])."'))";
|
40 |
if ($weights['title'])
|
41 |
$criteria['title'] = "(MATCH (post_title) AGAINST ('".$wpdb->escape($keywords['title'])."'))";
|
42 |
-
if ($weights['
|
43 |
-
$criteria['
|
44 |
-
if ($weights['
|
45 |
-
$criteria['
|
46 |
|
|
|
47 |
$newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
|
48 |
|
49 |
$newsql .= 'ROUND(0';
|
50 |
foreach ($criteria as $key => $value) {
|
51 |
-
$newsql .= "+ $value * "
|
52 |
}
|
53 |
$newsql .= ',1) as score';
|
54 |
|
55 |
$newsql .= "\n from $wpdb->posts \n";
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
AND tagrel.object_id = $wpdb->posts.ID)
|
66 |
-
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
|
67 |
-
AND tagtax.taxonomy = 'post_tag')\n";
|
68 |
-
|
69 |
-
if ($weights['cat'])
|
70 |
-
$newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $reference_ID )
|
71 |
-
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
|
72 |
-
AND catrel.object_id = $wpdb->posts.ID)
|
73 |
-
left JOIN $wpdb->term_taxonomy AS cattax ON ( catrel.term_taxonomy_id = cattax.term_taxonomy_id
|
74 |
-
AND cattax.taxonomy = 'category')\n";
|
75 |
|
76 |
// WHERE
|
77 |
|
78 |
-
$newsql .= " where
|
79 |
|
80 |
-
if ($past_only)
|
81 |
-
|
82 |
-
|
83 |
-
else
|
84 |
-
$reference_post_date = $wpdb->get_var("select post_date from $wpdb->posts where ID = $reference_ID");
|
85 |
-
$newsql .= " and post_date <= '$reference_post_date' ";
|
86 |
-
}
|
87 |
-
if (!$show_pass_post)
|
88 |
$newsql .= " and post_password ='' ";
|
89 |
-
if ($recent_only)
|
90 |
$newsql .= " and post_date > date_sub(now(), interval $recent_number $recent_units) ";
|
91 |
|
92 |
$newsql .= " and post_type = 'post'";
|
93 |
|
94 |
// GROUP BY
|
95 |
$newsql .= "\n group by ID \n";
|
|
|
96 |
// HAVING
|
97 |
-
// safethreshold is so the new calibration system works.
|
98 |
// number_format fix suggested by vkovalcik! :)
|
99 |
$safethreshold = number_format(max($threshold,0.1), 2, '.', '');
|
100 |
$newsql .= " having score >= $safethreshold";
|
101 |
-
if ($usedisterms)
|
102 |
-
$
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
// in caching, we cross-relate regardless of whether we're going to actually
|
111 |
// use it or not.
|
8 |
if ( is_object($post) && !$reference_ID ) {
|
9 |
$reference_ID = $post->ID;
|
10 |
}
|
11 |
+
|
12 |
+
if ( !is_object($post) || $reference_ID != $post->ID ) {
|
13 |
+
$reference_post = get_post( $reference_ID );
|
14 |
+
} else {
|
15 |
+
$reference_post = $post;
|
16 |
+
}
|
17 |
|
18 |
$options = array( 'threshold', 'show_pass_post', 'past_only', 'body', 'title', 'tags', 'categories', 'exclude', 'recent_only', 'recent_number', 'recent_units');
|
19 |
$yarpp_options = yarpp_get_option();
|
21 |
$optvals = array_intersect_key($yarpp_options, array_flip($options));
|
22 |
extract($optvals);
|
23 |
|
|
|
|
|
24 |
// Fetch keywords
|
25 |
$keywords = $yarpp->cache->get_keywords($reference_ID);
|
26 |
|
27 |
+
// Get weights
|
28 |
$weights = array(
|
29 |
'body' => (($body == 3)?3:(($body == 2)?1:0)),
|
30 |
'title' => (($title == 3)?3:(($title == 2)?1:0)),
|
31 |
+
'post_tag' => (($tags != 1)?1:0),
|
32 |
+
'category' => (($categories != 1)?1:0)
|
33 |
);
|
34 |
+
//$totalweight = array_sum( array_values( $weights ) );
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
// Build criteria query parts based on the weights
|
37 |
$criteria = array();
|
38 |
if ($weights['body'])
|
39 |
$criteria['body'] = "(MATCH (post_content) AGAINST ('".$wpdb->escape($keywords['body'])."'))";
|
40 |
if ($weights['title'])
|
41 |
$criteria['title'] = "(MATCH (post_title) AGAINST ('".$wpdb->escape($keywords['title'])."'))";
|
42 |
+
if ($weights['post_tag'])
|
43 |
+
$criteria['post_tag'] = "count(distinct if( termtax.taxonomy = 'post_tag', termtax.term_taxonomy_id, null ))";
|
44 |
+
if ($weights['category'])
|
45 |
+
$criteria['category'] = "count(distinct if( termtax.taxonomy = 'category', termtax.term_taxonomy_id, null ))";
|
46 |
|
47 |
+
// SELECT
|
48 |
$newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
|
49 |
|
50 |
$newsql .= 'ROUND(0';
|
51 |
foreach ($criteria as $key => $value) {
|
52 |
+
$newsql .= "+ $value * " . $weights[$key];
|
53 |
}
|
54 |
$newsql .= ',1) as score';
|
55 |
|
56 |
$newsql .= "\n from $wpdb->posts \n";
|
57 |
|
58 |
+
// Get disallowed categories and tags
|
59 |
+
$disterms = wp_parse_id_list($exclude['category'] . ',' . $exclude['post_tag']);
|
60 |
+
$usedisterms = count($disterms);
|
61 |
+
if ( $usedisterms || $weights['post_tag'] || $weights['category'] ) {
|
62 |
+
$newsql .= "left join $wpdb->term_relationships as terms on ( terms.object_id = wp_posts.ID )
|
63 |
+
left join $wpdb->term_taxonomy as termtax on ( terms.term_taxonomy_id = termtax.term_taxonomy_id )
|
64 |
+
left join $wpdb->term_relationships as refterms on ( terms.term_taxonomy_id = refterms.term_taxonomy_id and refterms.object_id = $reference_ID )";
|
65 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
// WHERE
|
68 |
|
69 |
+
$newsql .= " where post_status in ( 'publish', 'static' ) and ID != '$reference_ID'";
|
70 |
|
71 |
+
if ($past_only) // 3.1.8: revised $past_only option
|
72 |
+
$newsql .= " and post_date <= '$reference_post->post_date' ";
|
73 |
+
if ( !$show_pass_post )
|
|
|
|
|
|
|
|
|
|
|
74 |
$newsql .= " and post_password ='' ";
|
75 |
+
if ( $recent_only )
|
76 |
$newsql .= " and post_date > date_sub(now(), interval $recent_number $recent_units) ";
|
77 |
|
78 |
$newsql .= " and post_type = 'post'";
|
79 |
|
80 |
// GROUP BY
|
81 |
$newsql .= "\n group by ID \n";
|
82 |
+
|
83 |
// HAVING
|
|
|
84 |
// number_format fix suggested by vkovalcik! :)
|
85 |
$safethreshold = number_format(max($threshold,0.1), 2, '.', '');
|
86 |
$newsql .= " having score >= $safethreshold";
|
87 |
+
if ( $usedisterms ) {
|
88 |
+
$disterms = implode(',', $disterms);
|
89 |
+
$newsql .= " and bit_and(termtax.term_id in ($disterms)) = 0";
|
90 |
+
}
|
91 |
+
|
92 |
+
if ( $categories == 3 )
|
93 |
+
$newsql .= ' and '.$criteria['category'].' >= 1';
|
94 |
+
if ( $categories == 4 )
|
95 |
+
$newsql .= ' and '.$criteria['category'].' >= 2';
|
96 |
+
if ( $tags == 3 )
|
97 |
+
$newsql .= ' and '.$criteria['post_tag'].' >= 1';
|
98 |
+
if ( $tags == 4 )
|
99 |
+
$newsql .= ' and '.$criteria['post_tag'].' >= 2';
|
100 |
+
|
101 |
+
// The maximum number of items we'll ever want to cache
|
102 |
+
$limit = max(yarpp_get_option('limit'), yarpp_get_option('rss_limit'));
|
103 |
+
$newsql .= " order by score desc limit $limit";
|
104 |
|
105 |
// in caching, we cross-relate regardless of whether we're going to actually
|
106 |
// use it or not.
|
readme.txt
CHANGED
@@ -200,6 +200,7 @@ If you are a bilingual speaker of English and another language and an avid user
|
|
200 |
== Changelog ==
|
201 |
|
202 |
= 3.4 =
|
|
|
203 |
* [Bug fix](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-version-333-breaks-templates-in-widget): Custom templates could not be used in widget display
|
204 |
* Implement lazy/infinite scrolling for the "disallow tags" and "disallow categories," so the YARPP settings screen doesn't lock up the browser for sites which have a crazy number or tags or categories
|
205 |
* Significant code cleanup
|
@@ -215,6 +216,7 @@ If you are a bilingual speaker of English and another language and an avid user
|
|
215 |
* Use `get_terms` to load terms
|
216 |
* Support for [YARPP Experiments](http://wordpress.org/extend/plugins/yarpp-experiments/).
|
217 |
* Added Portuguese stopwords by Leandro Coelho ([Logística Descomplicada](http://www.logisticadescomplicada.com))
|
|
|
218 |
= 3.3.3 =
|
219 |
* [Bug fix](http://wordpress.org/support/topic/no-related-posts-1): a fix for keyword computation for pages; should improve results on pages. May require flushing of cache: see FAQ for instructions.
|
220 |
* Init YARPP on the `init` action, [for compatibility with WPML](https://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-load-sequence-yarpp-starts-before-the-wordpress-init-completes)
|
200 |
== Changelog ==
|
201 |
|
202 |
= 3.4 =
|
203 |
+
* Major optimizations to the main related posts query, in particular with regard to taxonomy lookups
|
204 |
* [Bug fix](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-version-333-breaks-templates-in-widget): Custom templates could not be used in widget display
|
205 |
* Implement lazy/infinite scrolling for the "disallow tags" and "disallow categories," so the YARPP settings screen doesn't lock up the browser for sites which have a crazy number or tags or categories
|
206 |
* Significant code cleanup
|
216 |
* Use `get_terms` to load terms
|
217 |
* Support for [YARPP Experiments](http://wordpress.org/extend/plugins/yarpp-experiments/).
|
218 |
* Added Portuguese stopwords by Leandro Coelho ([Logística Descomplicada](http://www.logisticadescomplicada.com))
|
219 |
+
* Fix formatting of the Related Posts meta box
|
220 |
= 3.3.3 =
|
221 |
* [Bug fix](http://wordpress.org/support/topic/no-related-posts-1): a fix for keyword computation for pages; should improve results on pages. May require flushing of cache: see FAQ for instructions.
|
222 |
* Init YARPP on the `init` action, [for compatibility with WPML](https://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-load-sequence-yarpp-starts-before-the-wordpress-init-completes)
|
yarpp.php
CHANGED
@@ -3,13 +3,13 @@
|
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://yarpp.org/
|
5 |
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
|
6 |
-
Version: 3.
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
Author URI: http://mitcho.com/
|
9 |
Donate link: http://tinyurl.com/donatetomitcho
|
10 |
*/
|
11 |
|
12 |
-
define('YARPP_VERSION', '3.
|
13 |
define('YARPP_DIR', dirname(__FILE__));
|
14 |
define('YARPP_NO_RELATED', ':(');
|
15 |
define('YARPP_RELATED', ':)');
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://yarpp.org/
|
5 |
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
|
6 |
+
Version: 3.4b7
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
Author URI: http://mitcho.com/
|
9 |
Donate link: http://tinyurl.com/donatetomitcho
|
10 |
*/
|
11 |
|
12 |
+
define('YARPP_VERSION', '3.4b7');
|
13 |
define('YARPP_DIR', dirname(__FILE__));
|
14 |
define('YARPP_NO_RELATED', ':(');
|
15 |
define('YARPP_RELATED', ':)');
|