Yet Another Related Posts Plugin (YARPP) - Version 3.4.4b4

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 3.4.4b4
Comparing to
See all releases

Code changes from version 3.4.4b3 to 3.4.4b4

cache-postmeta.php CHANGED
@@ -63,9 +63,10 @@ class YARPP_Cache_Postmeta extends YARPP_Cache {
63
  $this->related_IDs = array(0);
64
  $arg = preg_replace("!{$wpdb->posts}.ID = \d+!","{$wpdb->posts}.ID in (".join(',',$this->related_IDs).")",$arg);
65
 
66
- // if we have "recent only" set, add an additional condition
67
- if (yarpp_get_option("recent_only"))
68
- $arg .= " and post_date > date_sub(now(), interval ".yarpp_get_option("recent_number")." ".yarpp_get_option("recent_units").") ";
 
69
  return $arg;
70
  }
71
 
63
  $this->related_IDs = array(0);
64
  $arg = preg_replace("!{$wpdb->posts}.ID = \d+!","{$wpdb->posts}.ID in (".join(',',$this->related_IDs).")",$arg);
65
 
66
+ // if recent is set, add an additional condition
67
+ $recent = yarpp_get_option('recent');
68
+ if ( !!$recent )
69
+ $arg .= " and post_date > date_sub(now(), interval {$recent}) ";
70
  return $arg;
71
  }
72
 
cache-tables.php CHANGED
@@ -94,8 +94,9 @@ class YARPP_Cache_Tables extends YARPP_Cache {
94
 
95
  $arg = str_replace("$wpdb->posts.ID = ","yarpp.score >= $threshold and yarpp.reference_ID = ",$arg);
96
 
97
- if (yarpp_get_option("recent_only"))
98
- $arg .= " and post_date > date_sub(now(), interval ".yarpp_get_option("recent_number")." ".yarpp_get_option("recent_units").") ";
 
99
  }
100
  return $arg;
101
  }
94
 
95
  $arg = str_replace("$wpdb->posts.ID = ","yarpp.score >= $threshold and yarpp.reference_ID = ",$arg);
96
 
97
+ $recent = yarpp_get_option('recent');
98
+ if ( !!$recent )
99
+ $arg .= " and post_date > date_sub(now(), interval {$recent}) ";
100
  }
101
  return $arg;
102
  }
class-cache.php CHANGED
@@ -147,7 +147,7 @@ abstract class YARPP_Cache {
147
  $reference_post = $post;
148
  }
149
 
150
- $options = array( 'threshold', 'show_pass_post', 'past_only', 'weight', 'require_tax', 'exclude', 'recent_only', 'recent_number', 'recent_units', 'limit' );
151
  extract( $this->core->parse_args($args, $options) );
152
  // The maximum number of items we'll ever want to cache
153
  $limit = max($limit, $this->core->get_option('rss_limit'));
@@ -187,8 +187,8 @@ abstract class YARPP_Cache {
187
  $newsql .= " and post_date <= '$reference_post->post_date' ";
188
  if ( !$show_pass_post )
189
  $newsql .= " and post_password ='' ";
190
- if ( $recent_only )
191
- $newsql .= " and post_date > date_sub(now(), interval $recent_number $recent_units) ";
192
 
193
  $newsql .= " and post_type = 'post'";
194
 
@@ -483,9 +483,9 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
483
  $this->related_IDs = array(0);
484
  $arg = preg_replace("!{$wpdb->posts}.ID = \d+!","{$wpdb->posts}.ID in (".join(',',$this->related_IDs).")",$arg);
485
 
486
- // if we have "recent only" set, add an additional condition
487
- if ($this->args["recent_only"])
488
- $arg .= " and post_date > date_sub(now(), interval {$this->args['recent_number']} {$this->args['recent_units']}) ";
489
  return $arg;
490
  }
491
 
@@ -537,7 +537,7 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
537
  global $wpdb;
538
 
539
  $this->yarpp_time = true;
540
- $options = array( 'threshold', 'show_pass_post', 'past_only', 'weight', 'require_tax', 'exclude', 'recent_only', 'recent_number', 'recent_units', 'limit' );
541
  $this->args = $this->core->parse_args($args, $options);
542
 
543
  $this->related_postdata = $wpdb->get_results($this->sql($reference_ID, $args), ARRAY_A);
147
  $reference_post = $post;
148
  }
149
 
150
+ $options = array( 'threshold', 'show_pass_post', 'past_only', 'weight', 'require_tax', 'exclude', 'recent', 'limit' );
151
  extract( $this->core->parse_args($args, $options) );
152
  // The maximum number of items we'll ever want to cache
153
  $limit = max($limit, $this->core->get_option('rss_limit'));
187
  $newsql .= " and post_date <= '$reference_post->post_date' ";
188
  if ( !$show_pass_post )
189
  $newsql .= " and post_password ='' ";
190
+ if ( !!$recent )
191
+ $newsql .= " and post_date > date_sub(now(), interval {$recent}) ";
192
 
193
  $newsql .= " and post_type = 'post'";
194
 
483
  $this->related_IDs = array(0);
484
  $arg = preg_replace("!{$wpdb->posts}.ID = \d+!","{$wpdb->posts}.ID in (".join(',',$this->related_IDs).")",$arg);
485
 
486
+ // if we have recent set, add an additional condition
487
+ if ( !!$this->args['recent'] )
488
+ $arg .= " and post_date > date_sub(now(), interval {$this->args['recent']}) ";
489
  return $arg;
490
  }
491
 
537
  global $wpdb;
538
 
539
  $this->yarpp_time = true;
540
+ $options = array( 'threshold', 'show_pass_post', 'past_only', 'weight', 'require_tax', 'exclude', 'recent', 'limit' );
541
  $this->args = $this->core->parse_args($args, $options);
542
 
543
  $this->related_postdata = $wpdb->get_results($this->sql($reference_ID, $args), ARRAY_A);
class-core.php CHANGED
@@ -63,8 +63,7 @@ class YARPP {
63
  'threshold' => 5,
64
  'limit' => 5,
65
  'excerpt_length' => 10,
66
- 'recent_number' => 12,
67
- 'recent_units' => 'month',
68
  'before_title' => '<li>',
69
  'after_title' => '</li>',
70
  'before_post' => ' <small>',
@@ -86,11 +85,6 @@ class YARPP {
86
  'past_only' => true,
87
  'show_excerpt' => false,
88
  'rss_show_excerpt' => false,
89
- 'recent_only' => false, // new in 3.0
90
- //'use_template' => false, // new in 2.2
91
- //'rss_use_template' => false, // new in 2.2
92
- //'template_file' => '', // new in 2.2
93
- //'rss_template_file' => '', // new in 2.2
94
  'template' => false, // new in 3.4.4
95
  'rss_template' => false, // new in 3.4.4
96
  'show_pass_post' => false,
@@ -128,7 +122,7 @@ class YARPP {
128
  $new_options = array_merge( $current_options, $options );
129
 
130
  // new in 3.1: clear cache when updating certain settings.
131
- $clear_cache_options = array( 'show_pass_post', 'recent_only', 'threshold' );
132
  $new_options_which_require_flush = array_intersect( array_keys( array_diff_assoc($options, $current_options) ), $clear_cache_options );
133
  if ( count($new_options_which_require_flush) ||
134
  ( $new_options['limit'] > $current_options['limit'] ) ||
@@ -243,7 +237,9 @@ class YARPP {
243
  $this->upgrade_3_4_4b2();
244
  if ( $last_version && version_compare('3.4.4b3', $last_version) > 0 )
245
  $this->upgrade_3_4_4b3();
246
-
 
 
247
  $this->cache->upgrade($last_version);
248
  // flush cache in 3.4.1b5 as 3.4 messed up calculations.
249
  if ( $last_version && version_compare('3.4.1b5', $last_version) > 0 )
@@ -427,6 +423,16 @@ class YARPP {
427
  update_option( 'yarpp', $options );
428
  }
429
 
 
 
 
 
 
 
 
 
 
 
430
  private $post_types = null;
431
  function get_post_types( $field = false ) {
432
  if ( is_null($this->post_types) ) {
@@ -449,7 +455,7 @@ class YARPP {
449
 
450
  private $taxonomies = null;
451
  function get_taxonomies( $field = false ) {
452
- if ( is_null($this->post_types) ) {
453
  $this->taxonomies = get_taxonomies(array(), 'objects');
454
  $this->taxonomies = array_filter( $this->taxonomies, array($this, 'taxonomy_filter') );
455
  }
@@ -702,7 +708,7 @@ class YARPP {
702
 
703
  private function setup_active_cache( $args ) {
704
  // the options which the main sql query cares about:
705
- $magic_options = array( 'limit', 'threshold', 'show_pass_post', 'past_only', 'weight', 'exclude', 'require_tax', 'recent_only', 'recent_number', 'recent_units' );
706
 
707
  $defaults = $this->get_option();
708
  foreach ( $magic_options as $option ) {
63
  'threshold' => 5,
64
  'limit' => 5,
65
  'excerpt_length' => 10,
66
+ 'recent' => false, // new in 3.4.4
 
67
  'before_title' => '<li>',
68
  'after_title' => '</li>',
69
  'before_post' => ' <small>',
85
  'past_only' => true,
86
  'show_excerpt' => false,
87
  'rss_show_excerpt' => false,
 
 
 
 
 
88
  'template' => false, // new in 3.4.4
89
  'rss_template' => false, // new in 3.4.4
90
  'show_pass_post' => false,
122
  $new_options = array_merge( $current_options, $options );
123
 
124
  // new in 3.1: clear cache when updating certain settings.
125
+ $clear_cache_options = array( 'show_pass_post', 'recent', 'threshold' );
126
  $new_options_which_require_flush = array_intersect( array_keys( array_diff_assoc($options, $current_options) ), $clear_cache_options );
127
  if ( count($new_options_which_require_flush) ||
128
  ( $new_options['limit'] > $current_options['limit'] ) ||
237
  $this->upgrade_3_4_4b2();
238
  if ( $last_version && version_compare('3.4.4b3', $last_version) > 0 )
239
  $this->upgrade_3_4_4b3();
240
+ if ( $last_version && version_compare('3.4.4b4', $last_version) > 0 )
241
+ $this->upgrade_3_4_4b4();
242
+
243
  $this->cache->upgrade($last_version);
244
  // flush cache in 3.4.1b5 as 3.4 messed up calculations.
245
  if ( $last_version && version_compare('3.4.1b5', $last_version) > 0 )
423
  update_option( 'yarpp', $options );
424
  }
425
 
426
+ function upgrade_3_4_4b4() {
427
+ $options = $this->get_option();
428
+ $options['recent'] = $options['recent_only'] ?
429
+ $options['recent_number'] . ' ' . $options['recent_units'] : false;
430
+ unset( $options['recent_only'] );
431
+ unset( $options['recent_number'] );
432
+ unset( $options['recent_units'] );
433
+ update_option( 'yarpp', $options );
434
+ }
435
+
436
  private $post_types = null;
437
  function get_post_types( $field = false ) {
438
  if ( is_null($this->post_types) ) {
455
 
456
  private $taxonomies = null;
457
  function get_taxonomies( $field = false ) {
458
+ if ( is_null($this->taxonomies) ) {
459
  $this->taxonomies = get_taxonomies(array(), 'objects');
460
  $this->taxonomies = array_filter( $this->taxonomies, array($this, 'taxonomy_filter') );
461
  }
708
 
709
  private function setup_active_cache( $args ) {
710
  // the options which the main sql query cares about:
711
+ $magic_options = array( 'limit', 'threshold', 'show_pass_post', 'past_only', 'weight', 'exclude', 'require_tax', 'recent' );
712
 
713
  $defaults = $this->get_option();
714
  foreach ( $magic_options as $option ) {
options-meta-boxes.php CHANGED
@@ -110,22 +110,34 @@ if ( count($exclude_term_ids) ) {
110
 
111
  <table class="form-table" style="margin-top: 0; clear:none;">
112
  <tbody>
 
113
  <?php
114
  foreach ($yarpp->get_taxonomies() as $taxonomy) {
115
  $this->exclude($taxonomy->name, sprintf(__('Disallow by %s:','yarpp'), $taxonomy->labels->singular_name));
116
  }
117
  $this->checkbox('show_pass_post',__("Show password protected posts?",'yarpp'));
118
 
119
- $recent_number = "<input name=\"recent_number\" type=\"text\" id=\"recent_number\" value=\"".esc_attr(yarpp_get_option('recent_number'))."\" size=\"2\" />";
120
- $recent_units = yarpp_get_option('recent_units');
 
 
 
 
 
 
121
  $recent_units = "<select name=\"recent_units\" id=\"recent_units\">
122
  <option value='day'". (('day'==$recent_units)?" selected='selected'":'').">".__('day(s)','yarpp')."</option>
123
  <option value='week'". (('week'==$recent_units)?" selected='selected'":'').">".__('week(s)','yarpp')."</option>
124
  <option value='month'". (('month'==$recent_units)?" selected='selected'":'').">".__('month(s)','yarpp')."</option>
125
  </select>";
126
- $this->checkbox('recent_only',str_replace('NUMBER',$recent_number,str_replace('UNITS',$recent_units,__("Show only posts from the past NUMBER UNITS",'yarpp'))));
127
- ?>
128
 
 
 
 
 
 
 
 
129
  </tbody>
130
  </table>
131
  <?php
@@ -154,7 +166,7 @@ class YARPP_Meta_Box_Relatedness extends YARPP_Meta_Box {
154
  $this->tax_weight($taxonomy);
155
  }
156
 
157
- $this->checkbox('cross_relate',__("Cross-relate posts and pages?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("When the \"Cross-relate posts and pages\" option is selected, the <code>related_posts()</code>, <code>related_pages()</code>, and <code>related_entries()</code> all will give the same output, returning both related pages and posts.",'yarpp')."</span></a>");
158
  $this->checkbox('past_only',__("Show only previous posts?",'yarpp'));
159
  ?>
160
  </tbody>
110
 
111
  <table class="form-table" style="margin-top: 0; clear:none;">
112
  <tbody>
113
+ <tr><th><?php _e('Post types considered:', 'yarpp'); ?></th><td><?php echo implode(', ', $yarpp->get_post_types('label')); ?> <a href='http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/other-notes'><?php _e('more&gt;','yarpp');?></a></td></tr>
114
  <?php
115
  foreach ($yarpp->get_taxonomies() as $taxonomy) {
116
  $this->exclude($taxonomy->name, sprintf(__('Disallow by %s:','yarpp'), $taxonomy->labels->singular_name));
117
  }
118
  $this->checkbox('show_pass_post',__("Show password protected posts?",'yarpp'));
119
 
120
+ $recent = yarpp_get_option('recent');
121
+ if ( !!$recent ) {
122
+ list($recent_number, $recent_units) = explode(' ', $recent);
123
+ } else {
124
+ $recent_number = 12;
125
+ $recent_units = 'month';
126
+ }
127
+ $recent_number = "<input name=\"recent_number\" type=\"text\" id=\"recent_number\" value=\"".esc_attr($recent_number)."\" size=\"2\" />";
128
  $recent_units = "<select name=\"recent_units\" id=\"recent_units\">
129
  <option value='day'". (('day'==$recent_units)?" selected='selected'":'').">".__('day(s)','yarpp')."</option>
130
  <option value='week'". (('week'==$recent_units)?" selected='selected'":'').">".__('week(s)','yarpp')."</option>
131
  <option value='month'". (('month'==$recent_units)?" selected='selected'":'').">".__('month(s)','yarpp')."</option>
132
  </select>";
 
 
133
 
134
+ echo "<tr valign='top'><th class='th-full' colspan='2' scope='row'><input type='checkbox' name='recent_only' value='true'";
135
+ checked(!!$recent);
136
+ echo " /> ";
137
+ echo str_replace('NUMBER',$recent_number,str_replace('UNITS',$recent_units,__("Show only posts from the past NUMBER UNITS",'yarpp')));
138
+ echo "</th></tr>";
139
+
140
+ ?>
141
  </tbody>
142
  </table>
143
  <?php
166
  $this->tax_weight($taxonomy);
167
  }
168
 
169
+ $this->checkbox('cross_relate',__("Display results from all post types",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("When \"display results from all post types\" is off, only posts will be displayed as related to a post, only pages will be displayed as related to a page, etc.",'yarpp')."</span></a>");
170
  $this->checkbox('past_only',__("Show only previous posts?",'yarpp'));
171
  ?>
172
  </tbody>
options.php CHANGED
@@ -88,7 +88,8 @@ if (isset($_POST['update_yarpp'])) {
88
  if ( is_bool($default) )
89
  $new_options[$option] = isset($_POST[$option]);
90
  // @todo: do we really want to stripslashes here anymore?
91
- if ( (is_string($default) || is_int($default)) && is_string(@$_POST[$option]) )
 
92
  $new_options[$option] = stripslashes($_POST[$option]);
93
  }
94
 
@@ -117,6 +118,9 @@ if (isset($_POST['update_yarpp'])) {
117
  }
118
  }
119
 
 
 
 
120
  if ( isset($_POST['exclude']) )
121
  $new_options['exclude'] = implode(',',array_keys($_POST['exclude']));
122
 
88
  if ( is_bool($default) )
89
  $new_options[$option] = isset($_POST[$option]);
90
  // @todo: do we really want to stripslashes here anymore?
91
+ if ( (is_string($default) || is_int($default)) &&
92
+ isset($_POST[$option]) && is_string($_POST[$option]) )
93
  $new_options[$option] = stripslashes($_POST[$option]);
94
  }
95
 
118
  }
119
  }
120
 
121
+ $new_options['recent'] = isset($_POST['recent_only']) ?
122
+ $_POST['recent_number'] . ' ' . $_POST['recent_units'] : false;
123
+
124
  if ( isset($_POST['exclude']) )
125
  $new_options['exclude'] = implode(',',array_keys($_POST['exclude']));
126
 
readme.txt CHANGED
@@ -127,14 +127,13 @@ The official [YARPP Experiments](http://wordpress.org/extend/plugins/yarpp-exper
127
 
128
  Developers can call YARPP's powerful relatedness algorithm from anywhere in their own code.
129
 
130
- yarpp_display_related(get_the_ID(), array(
131
  // Pool options: these determine the "pool" of entities which are considered
132
  'post_type' => array('post', 'page', ...),
133
  'show_pass_post' => false, // show password-protected posts
134
  'past_only' => false, // show only posts which were published before the reference post
135
  'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
136
- // @todo: change format of "recent" options
137
- // 'recent_only', 'recent_number', 'recent_units',
138
 
139
  // Relatedness options: these determine how "relatedness" is computed
140
  // Weights are used to construct the "match score" between candidates and the reference post
@@ -161,7 +160,7 @@ Developers can call YARPP's powerful relatedness algorithm from anywhere in thei
161
 
162
  Options which are not specified will default to those specified in the YARPP settings page. Additionally, if you are using the builtin template rather than specifying a custom template file in `template`, the following arguments can be used to override the various parts of the builtin template: `before_title`, `after_title`, `before_post`, `after_post`, `before_related`, `after_related`, `no_results`, `excerpt_length`.
163
 
164
- If you need to use related entries programmatically or to know whether they exist, you can use the functions `yarpp_get_related($reference_ID, $args)` and `yarpp_related_exist($reference_ID, $args)`. `yarpp_get_related` returns an array of `post` objects, just like the WordPress function `get_posts`. `yarpp_related_exist` returns a boolean for whether any such related entries exist. For each function, `$args` takes the same arguments as those shown for `yarpp_display_related` above, except for the various display and template options.
165
 
166
  Note that custom YARPP queries using the functions mentioned here are *not* cached in the built-in YARPP caching system. Thus, if you notice any performance hits, you may need to write your own code to cache the results.
167
 
@@ -226,7 +225,7 @@ If you are a bilingual speaker of English and another language and an avid user
226
  = 3.4.4 =
227
  * New public YARPP query API
228
  * Documentation in the "other notes" section of the readme
229
- * Changed format of `weight` and `template` paramters in options and in optional args
230
  * Further main query optimization:
231
  * What's cooler than joining four tables? Joining two.
232
  * Exclude now simply uses `term_taxonomy_id`s instead of `term_id`s
127
 
128
  Developers can call YARPP's powerful relatedness algorithm from anywhere in their own code.
129
 
130
+ yarpp_related(get_the_ID(), array(
131
  // Pool options: these determine the "pool" of entities which are considered
132
  'post_type' => array('post', 'page', ...),
133
  'show_pass_post' => false, // show password-protected posts
134
  'past_only' => false, // show only posts which were published before the reference post
135
  'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
136
+ 'recent' => false, // to limit to entries published recently, set to something like '15 day', '20 week', or '12 month'.
 
137
 
138
  // Relatedness options: these determine how "relatedness" is computed
139
  // Weights are used to construct the "match score" between candidates and the reference post
160
 
161
  Options which are not specified will default to those specified in the YARPP settings page. Additionally, if you are using the builtin template rather than specifying a custom template file in `template`, the following arguments can be used to override the various parts of the builtin template: `before_title`, `after_title`, `before_post`, `after_post`, `before_related`, `after_related`, `no_results`, `excerpt_length`.
162
 
163
+ If you need to use related entries programmatically or to know whether they exist, you can use the functions `yarpp_get_related($reference_ID, $args)` and `yarpp_related_exist($reference_ID, $args)`. `yarpp_get_related` returns an array of `post` objects, just like the WordPress function `get_posts`. `yarpp_related_exist` returns a boolean for whether any such related entries exist. For each function, `$args` takes the same arguments as those shown for `yarpp_related` above, except for the various display and template options.
164
 
165
  Note that custom YARPP queries using the functions mentioned here are *not* cached in the built-in YARPP caching system. Thus, if you notice any performance hits, you may need to write your own code to cache the results.
166
 
225
  = 3.4.4 =
226
  * New public YARPP query API
227
  * Documentation in the "other notes" section of the readme
228
+ * Changed format of `weight`, `template`, `recent` parameters in options and in optional args
229
  * Further main query optimization:
230
  * What's cooler than joining four tables? Joining two.
231
  * Exclude now simply uses `term_taxonomy_id`s instead of `term_id`s
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.4.4b3
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.4.4b3');
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.4.4b4
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.4.4b4');
13
  define('YARPP_DIR', dirname(__FILE__));
14
  define('YARPP_NO_RELATED', ':(');
15
  define('YARPP_RELATED', ':)');