Yet Another Related Posts Plugin (YARPP) - Version 3.2.1b3

Version Description

Download this release

Release Info

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

Code changes from version 3.2.1b2 to 3.2.1b3

Files changed (7) hide show
  1. cache-postmeta.php +7 -5
  2. cache-tables.php +6 -6
  3. includes.php +22 -88
  4. keywords.php +73 -0
  5. magic.php +7 -5
  6. readme.txt +4 -1
  7. yarpp.php +4 -3
cache-postmeta.php CHANGED
@@ -14,6 +14,8 @@ class YARPP_Cache_Postmeta {
14
  var $name = "postmeta";
15
  var $yarpp_time = false;
16
  var $demo_time = false;
 
 
17
 
18
  /**
19
  * SETUP/STATUS
@@ -74,10 +76,10 @@ class YARPP_Cache_Postmeta {
74
  }
75
 
76
  function orderby_filter($arg) {
77
- global $wpdb, $yarpp_score_override;
78
  // only order by score if the score function is added in fields_filter, which only happens
79
  // if there are related posts in the postdata
80
- if ($this->yarpp_time && $yarpp_score_override &&
81
  is_array($this->related_postdata) && count($this->related_postdata))
82
  return str_replace("$wpdb->posts.post_date","score",$arg);
83
  return $arg;
@@ -108,9 +110,9 @@ class YARPP_Cache_Postmeta {
108
  }
109
 
110
  function limit_filter($arg) {
111
- global $wpdb, $yarpp_online_limit;
112
- if ($this->yarpp_time and $yarpp_online_limit)
113
- return " limit $yarpp_online_limit ";
114
  return $arg;
115
  }
116
 
14
  var $name = "postmeta";
15
  var $yarpp_time = false;
16
  var $demo_time = false;
17
+ var $score_override = false;
18
+ var $online_limit = false;
19
 
20
  /**
21
  * SETUP/STATUS
76
  }
77
 
78
  function orderby_filter($arg) {
79
+ global $wpdb;
80
  // only order by score if the score function is added in fields_filter, which only happens
81
  // if there are related posts in the postdata
82
+ if ($this->yarpp_time && $this->score_override &&
83
  is_array($this->related_postdata) && count($this->related_postdata))
84
  return str_replace("$wpdb->posts.post_date","score",$arg);
85
  return $arg;
110
  }
111
 
112
  function limit_filter($arg) {
113
+ global $wpdb;
114
+ if ($this->yarpp_time and $this->online_limit)
115
+ return " limit {$this->online_limit} ";
116
  return $arg;
117
  }
118
 
cache-tables.php CHANGED
@@ -9,6 +9,7 @@ class YARPP_Cache_Tables {
9
  var $name = "custom tables";
10
  var $yarpp_time = false;
11
  var $demo_time = false;
 
12
 
13
  /**
14
  * SETUP/STATUS
@@ -109,10 +110,9 @@ class YARPP_Cache_Tables {
109
  }
110
 
111
  function orderby_filter($arg) {
112
- global $wpdb, $yarpp_score_override;
113
- if ($this->yarpp_time and $yarpp_score_override) {
114
  $arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
115
- }
116
  return $arg;
117
  }
118
 
@@ -136,9 +136,9 @@ class YARPP_Cache_Tables {
136
  }
137
 
138
  function limit_filter($arg) {
139
- global $wpdb, $yarpp_online_limit;
140
- if ($this->yarpp_time and $yarpp_online_limit) {
141
- return " limit $yarpp_online_limit ";
142
  }
143
  return $arg;
144
  }
9
  var $name = "custom tables";
10
  var $yarpp_time = false;
11
  var $demo_time = false;
12
+ var $score_override = false;
13
 
14
  /**
15
  * SETUP/STATUS
110
  }
111
 
112
  function orderby_filter($arg) {
113
+ global $wpdb;
114
+ if ($this->yarpp_time and $this->score_override)
115
  $arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
 
116
  return $arg;
117
  }
118
 
136
  }
137
 
138
  function limit_filter($arg) {
139
+ global $wpdb;
140
+ if ($this->yarpp_time and $this->online_limit) {
141
+ return " limit {$this->online_limit} ";
142
  }
143
  return $arg;
144
  }
includes.php CHANGED
@@ -102,10 +102,12 @@ function yarpp_activate() {
102
  return 0;
103
  }
104
 
105
- if (!get_option('yarpp_version'))
106
  add_option('yarpp_version',YARPP_VERSION);
107
- else
 
108
  yarpp_upgrade_check();
 
109
 
110
  return 1;
111
  }
@@ -138,6 +140,8 @@ function yarpp_upgrade_check() {
138
 
139
  $yarpp_cache->upgrade($last_version);
140
 
 
 
141
  update_option('yarpp_version',YARPP_VERSION);
142
  }
143
 
@@ -303,83 +307,6 @@ function yarpp_rss_excerpt($content) {
303
  return $content;
304
  }
305
 
306
-
307
- /* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist. It's defined here. */
308
-
309
- /* blacklisted so far:
310
- - diggZ-Et
311
- - reddZ-Et
312
- - dzoneZ-Et
313
- - WP-Syntax
314
- - Viper's Video Quicktags
315
- - WP-CodeBox
316
- - WP shortcodes
317
- - WP Greet Box
318
- //- Tweet This - could not reproduce problem.
319
- */
320
-
321
- $yarpp_blacklist = array(null,'yarpp_default','diggZEt_AddBut','reddZEt_AddBut','dzoneZEt_AddBut','wp_syntax_before_filter','wp_syntax_after_filter','wp_codebox_before_filter','wp_codebox_after_filter','do_shortcode');//,'insert_tweet_this'
322
- $yarpp_blackmethods = array(null,'addinlinejs','replacebbcode','filter_content');
323
-
324
- function yarpp_white($filter) {
325
- global $yarpp_blacklist;
326
- global $yarpp_blackmethods;
327
- if (is_array($filter)) {
328
- if (array_search($filter[1],$yarpp_blackmethods)) //print_r($filter[1]);
329
- return false;
330
- }
331
- if (array_search($filter,$yarpp_blacklist)) //print_r($filter);
332
- return false;
333
- return true;
334
- }
335
-
336
- /* 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').*/
337
-
338
- function apply_filters_if_white($tag, $value) {
339
- global $wp_filter, $merged_filters, $wp_current_filter;
340
-
341
- $args = array();
342
- $wp_current_filter[] = $tag;
343
-
344
- // Do 'all' actions first
345
- if ( isset($wp_filter['all']) ) {
346
- $args = func_get_args();
347
- _wp_call_all_hook($args);
348
- }
349
-
350
- if ( !isset($wp_filter[$tag]) ) {
351
- array_pop($wp_current_filter);
352
- return $value;
353
- }
354
-
355
- // Sort
356
- if ( !isset( $merged_filters[ $tag ] ) ) {
357
- ksort($wp_filter[$tag]);
358
- $merged_filters[ $tag ] = true;
359
- }
360
-
361
- reset( $wp_filter[ $tag ] );
362
-
363
- if ( empty($args) )
364
- $args = func_get_args();
365
-
366
-
367
- do{
368
- foreach( (array) current($wp_filter[$tag]) as $the_ ) {
369
- if ( !is_null($the_['function'])
370
- and yarpp_white($the_['function'])){ // HACK
371
- $args[1] = $value;
372
- $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
373
- }
374
- }
375
-
376
- } while ( next($wp_filter[$tag]) !== false );
377
-
378
- array_pop( $wp_current_filter );
379
-
380
- return $value;
381
- }
382
-
383
  // Used only in demo mode
384
  if (!defined('LOREMIPSUM'))
385
  define('LOREMIPSUM','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras tincidunt justo a urna. Ut turpis. Phasellus convallis, odio sit amet cursus convallis, eros orci scelerisque velit, ut sodales neque nisl at ante. Suspendisse metus. Curabitur auctor pede quis mi. Pellentesque lorem justo, condimentum ac, dapibus sit amet, ornare et, erat. Quisque velit. Etiam sodales dui feugiat neque suscipit bibendum. Integer mattis. Nullam et ante non sem commodo malesuada. Pellentesque ultrices fermentum lectus. Maecenas hendrerit neque ac est. Fusce tortor mi, tristique sed, cursus at, pellentesque non, dui. Suspendisse potenti.');
@@ -417,15 +344,22 @@ function yarpp_microtime_float() {
417
  return ((float)$usec + (float)$sec);
418
  }
419
 
420
- function yarpp_version_json() {
421
- check_ajax_referer('yarpp_version_json');
422
- $version = YARPP_VERSION;
423
- $remote = wp_remote_post("http://mitcho.com/code/yarpp/checkversion.php?version=$version");
424
- if (is_wp_error($remote)) {
425
- echo '{}';
426
- exit;
427
- }
428
- echo $remote['body'];
 
 
 
 
 
 
 
429
  exit;
430
  }
431
 
102
  return 0;
103
  }
104
 
105
+ if (!get_option('yarpp_version')) {
106
  add_option('yarpp_version',YARPP_VERSION);
107
+ yarpp_version_json(true);
108
+ } else {
109
  yarpp_upgrade_check();
110
+ }
111
 
112
  return 1;
113
  }
140
 
141
  $yarpp_cache->upgrade($last_version);
142
 
143
+ yarpp_version_json(true);
144
+
145
  update_option('yarpp_version',YARPP_VERSION);
146
  }
147
 
307
  return $content;
308
  }
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  // Used only in demo mode
311
  if (!defined('LOREMIPSUM'))
312
  define('LOREMIPSUM','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras tincidunt justo a urna. Ut turpis. Phasellus convallis, odio sit amet cursus convallis, eros orci scelerisque velit, ut sodales neque nisl at ante. Suspendisse metus. Curabitur auctor pede quis mi. Pellentesque lorem justo, condimentum ac, dapibus sit amet, ornare et, erat. Quisque velit. Etiam sodales dui feugiat neque suscipit bibendum. Integer mattis. Nullam et ante non sem commodo malesuada. Pellentesque ultrices fermentum lectus. Maecenas hendrerit neque ac est. Fusce tortor mi, tristique sed, cursus at, pellentesque non, dui. Suspendisse potenti.');
344
  return ((float)$usec + (float)$sec);
345
  }
346
 
347
+ function yarpp_version_json($just_cache = false) {
348
+ if (!$just_cache)
349
+ check_ajax_referer('yarpp_version_json');
350
+
351
+ if (!$just_cache && false === ($result = get_transient('yarpp_version_json'))) {
352
+ $version = YARPP_VERSION;
353
+ $remote = wp_remote_post("http://mitcho.com/code/yarpp/checkversion.php?version=$version");
354
+
355
+ $result = (is_wp_error($remote) ? '{}' : $remote['body']);
356
+
357
+ set_transient('yarpp_version_json', $result, 60*60*12);
358
+ }
359
+ if ($just_cache)
360
+ return $result;
361
+
362
+ echo $result;
363
  exit;
364
  }
365
 
keywords.php CHANGED
@@ -52,3 +52,76 @@ function post_body_keywords($ID,$max = 20) {
52
  $content = html_entity_strip($content);
53
  return yarpp_extract_keywords($content,$max);
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  $content = html_entity_strip($content);
53
  return yarpp_extract_keywords($content,$max);
54
  }
55
+
56
+ /* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist. It's defined here. */
57
+
58
+ /* blacklisted so far:
59
+ - diggZ-Et
60
+ - reddZ-Et
61
+ - dzoneZ-Et
62
+ - WP-Syntax
63
+ - Viper's Video Quicktags
64
+ - WP-CodeBox
65
+ - WP shortcodes
66
+ - WP Greet Box
67
+ //- Tweet This - could not reproduce problem.
68
+ */
69
+
70
+ $yarpp_blacklist = array(null,'yarpp_default','diggZEt_AddBut','reddZEt_AddBut','dzoneZEt_AddBut','wp_syntax_before_filter','wp_syntax_after_filter','wp_codebox_before_filter','wp_codebox_after_filter','do_shortcode');//,'insert_tweet_this'
71
+ $yarpp_blackmethods = array(null,'addinlinejs','replacebbcode','filter_content');
72
+
73
+ function yarpp_white($filter) {
74
+ global $yarpp_blacklist;
75
+ global $yarpp_blackmethods;
76
+ if (is_array($filter)) {
77
+ if (array_search($filter[1],$yarpp_blackmethods)) //print_r($filter[1]);
78
+ return false;
79
+ }
80
+ if (array_search($filter,$yarpp_blacklist)) //print_r($filter);
81
+ return false;
82
+ return true;
83
+ }
84
+
85
+ /* 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').*/
86
+ function apply_filters_if_white($tag, $value) {
87
+ global $wp_filter, $merged_filters, $wp_current_filter;
88
+
89
+ $args = array();
90
+ $wp_current_filter[] = $tag;
91
+
92
+ // Do 'all' actions first
93
+ if ( isset($wp_filter['all']) ) {
94
+ $args = func_get_args();
95
+ _wp_call_all_hook($args);
96
+ }
97
+
98
+ if ( !isset($wp_filter[$tag]) ) {
99
+ array_pop($wp_current_filter);
100
+ return $value;
101
+ }
102
+
103
+ // Sort
104
+ if ( !isset( $merged_filters[ $tag ] ) ) {
105
+ ksort($wp_filter[$tag]);
106
+ $merged_filters[ $tag ] = true;
107
+ }
108
+
109
+ reset( $wp_filter[ $tag ] );
110
+
111
+ if ( empty($args) )
112
+ $args = func_get_args();
113
+
114
+ do {
115
+ foreach( (array) current($wp_filter[$tag]) as $the_ )
116
+ if ( !is_null($the_['function'])
117
+ and yarpp_white($the_['function'])){ // HACK
118
+ $args[1] = $value;
119
+ $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
120
+ }
121
+
122
+ } while ( next($wp_filter[$tag]) !== false );
123
+
124
+ array_pop( $wp_current_filter );
125
+
126
+ return $value;
127
+ }
magic.php CHANGED
@@ -3,16 +3,18 @@
3
  //=TEMPLATING/DISPLAY===========
4
 
5
  function yarpp_set_score_override_flag($q) {
6
- global $yarpp_cache, $yarpp_score_override, $yarpp_online_limit;
7
  if ($yarpp_cache->yarpp_time) {
8
- $yarpp_score_override = ($q->query_vars['orderby'] == 'score');
9
 
10
  if (!empty($q->query_vars['showposts'])) {
11
- $yarpp_online_limit = $q->query_vars['showposts'];
12
  } else {
13
- $yarpp_online_limit = false;
14
  }
15
-
 
 
16
  }
17
  }
18
 
3
  //=TEMPLATING/DISPLAY===========
4
 
5
  function yarpp_set_score_override_flag($q) {
6
+ global $yarpp_cache;
7
  if ($yarpp_cache->yarpp_time) {
8
+ $yarpp_cache->score_override = ($q->query_vars['orderby'] == 'score');
9
 
10
  if (!empty($q->query_vars['showposts'])) {
11
+ $yarpp_cache->online_limit = $q->query_vars['showposts'];
12
  } else {
13
+ $yarpp_cache->online_limit = false;
14
  }
15
+ } else {
16
+ $yarpp_cache->score_override = false;
17
+ $yarpp_cache->online_limit = false;
18
  }
19
  }
20
 
readme.txt CHANGED
@@ -187,14 +187,17 @@ If you are a bilingual speaker of English and another language and an avid user
187
 
188
  = 3.2.1 =
189
  * Bugfix: [Duplicate results shown for some users](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-yarpp-post-duplicate-related-articles)
 
 
 
190
  * Better handling of [`post_status` transitions](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-changed-post-to-draft-still-showing-up-as-related-to-other-posts).
191
  * Bugfix: [the widget was not working on pages](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-showing-yarp-widget-in-pages-and-subpages)
192
  * Added overused words list for French, thanks to [saymonz](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-french-overused-words)
193
  * Minor code cleanup:
194
  * Fixed [a bug in `yarpp_related_exists()`](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-fatal-error-call-to-undefined-method-yarpp_cache_tablesstart_yarpp_time)
195
- * Minor security fix in version-checking code
196
  * Removed legacy code for gracefully upgrading from YARPP versions < 1.5 and working with WordPress versions < 2.8.
197
  * Cleanup of `yarpp_upgrade_check()` calling
 
198
  * Eliminated a couple globals
199
  * Cleaned up some edge case causes for "unexpected output" on plugin activation
200
  * Removed WP Help Center badge, as they are closing
187
 
188
  = 3.2.1 =
189
  * Bugfix: [Duplicate results shown for some users](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-yarpp-post-duplicate-related-articles)
190
+ * Bugfix: [With PHP4, the "related posts" would simply show the current post](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-yarpp-showing-same-post)
191
+ * This was due to an issue with [object references in PHP4](http://www.obdev.at/developers/articles/00002.html). What a pain!
192
+ * A big thanks to Brendon Held of [inMotion Graphics](http://www.imgwebdesign.com) for being incredibly patient and letting me try out different diagnostics on his server.
193
  * Better handling of [`post_status` transitions](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-changed-post-to-draft-still-showing-up-as-related-to-other-posts).
194
  * Bugfix: [the widget was not working on pages](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-showing-yarp-widget-in-pages-and-subpages)
195
  * Added overused words list for French, thanks to [saymonz](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-french-overused-words)
196
  * Minor code cleanup:
197
  * Fixed [a bug in `yarpp_related_exists()`](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-fatal-error-call-to-undefined-method-yarpp_cache_tablesstart_yarpp_time)
 
198
  * Removed legacy code for gracefully upgrading from YARPP versions < 1.5 and working with WordPress versions < 2.8.
199
  * Cleanup of `yarpp_upgrade_check()` calling
200
+ * Cleanup of `yarpp_version_json()`, including caching and minor security fix
201
  * Eliminated a couple globals
202
  * Cleaned up some edge case causes for "unexpected output" on plugin activation
203
  * Removed WP Help Center badge, as they are closing
yarpp.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Yet Another Related Posts Plugin
4
  Plugin URI: http://mitcho.com/code/yarpp/
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.2.1b2
7
  Author: mitcho (Michael Yoshitaka Erlewine)
8
  Author URI: http://mitcho.com/
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4DATK4999L&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&charset=UTF%2d8
@@ -13,7 +13,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4D
13
  if (isset($_REQUEST['yarpp_debug']))
14
  $yarpp_debug = true;
15
 
16
- define('YARPP_VERSION','3.2.1b2');
17
  define('YARPP_DIR',dirname(__FILE__));
18
  // 3.2.1: safer new version checking
19
  add_action('wp_ajax_yarpp_version_json', 'yarpp_version_json');
@@ -30,7 +30,8 @@ if (!defined('YARPP_CACHE_TYPE'))
30
  define('YARPP_CACHE_TYPE', 'tables');
31
  global $yarpp_cache, $yarpp_storage_class;
32
  require_once(YARPP_DIR . '/cache-' . YARPP_CACHE_TYPE . '.php');
33
- $yarpp_cache = new $yarpp_storage_class;
 
34
 
35
  // Setup admin
36
  add_action('admin_menu','yarpp_admin_menu');
3
  Plugin Name: Yet Another Related Posts Plugin
4
  Plugin URI: http://mitcho.com/code/yarpp/
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.2.1b3
7
  Author: mitcho (Michael Yoshitaka Erlewine)
8
  Author URI: http://mitcho.com/
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4DATK4999L&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&charset=UTF%2d8
13
  if (isset($_REQUEST['yarpp_debug']))
14
  $yarpp_debug = true;
15
 
16
+ define('YARPP_VERSION','3.2.1b3');
17
  define('YARPP_DIR',dirname(__FILE__));
18
  // 3.2.1: safer new version checking
19
  add_action('wp_ajax_yarpp_version_json', 'yarpp_version_json');
30
  define('YARPP_CACHE_TYPE', 'tables');
31
  global $yarpp_cache, $yarpp_storage_class;
32
  require_once(YARPP_DIR . '/cache-' . YARPP_CACHE_TYPE . '.php');
33
+ // For PHP 4, we have to pass this object by reference:
34
+ $yarpp_cache =& new $yarpp_storage_class;
35
 
36
  // Setup admin
37
  add_action('admin_menu','yarpp_admin_menu');