Yet Another Related Posts Plugin (YARPP) - Version 3.1.2b1

Version Description

Download this release

Release Info

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

Code changes from version 3.1.1 to 3.1.2b1

Files changed (4) hide show
  1. includes.php +15 -0
  2. magic.php +9 -39
  3. readme.txt +2 -0
  4. yarpp.php +6 -16
includes.php CHANGED
@@ -414,4 +414,19 @@ function yarpp_check_version_json($version) {
414
return '{}';
415
}
416
417
?>
414
return '{}';
415
}
416
417
+ function yarpp_add_metabox() {
418
+ if (function_exists('add_meta_box')) {
419
+ add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp'), 'yarpp_metabox', 'post', 'normal' );
420
+ }
421
+ }
422
+ function yarpp_metabox() {
423
+ global $post;
424
+ echo '<div id="yarpp-related-posts">';
425
+ if ($post->ID)
426
+ yarpp_related(array('post'),array('limit'=>1000),true,false,'metabox');
427
+ else
428
+ echo "<p>Related entries may be displayed once you save your entry.</p>";
429
+ echo '</div>';
430
+ }
431
+
432
?>
magic.php CHANGED
@@ -84,10 +84,6 @@ function yarpp_sql($type,$args,$giveresults = true,$reference_ID=false,$domain='
84
$reference_ID = $post->ID;
85
}
86
87
- // set $yarpp_debug
88
- if (isset($_REQUEST['yarpp_debug']))
89
- $yarpp_debug = true;
90
-
91
// set the "domain prefix", used for all the preferences.
92
if ($domain == 'rss')
93
$domainprefix = 'rss_';
@@ -371,13 +367,8 @@ function yarpp_related_exist($type,$args,$reference_ID=false) {
371
return $result > 0 ? true: false;
372
}
373
374
- // these are the post ID's which have been updated in this caching cycle
375
- $yarpp_updated_posts = array();
376
- // here's a queue of posts whose related posts should be enforced
377
- $yarpp_caching_queue = array();
378
-
379
function yarpp_save_cache($post_ID,$force=true) {
380
- global $wpdb, $yarpp_caching_queue, $yarpp_updated_posts;
381
382
$parent_ID = $wpdb->get_var("select post_parent from $wpdb->posts where ID='$post_ID'");
383
if ($parent_ID != $post_ID and $parent_ID)
@@ -387,21 +378,7 @@ function yarpp_save_cache($post_ID,$force=true) {
387
else
388
$type = array('post');
389
390
- // add it to the queue
391
- array_push($yarpp_caching_queue,$post_ID);
392
-
393
- // any newly targetted posts will have to be cleared
394
- $yarpp_toclear = array();
395
-
396
- // go through the queue
397
- while ($ID = array_pop($yarpp_caching_queue)) {
398
- if (array_search($ID,$yarpp_updated_posts) === false) {
399
- yarpp_cache_enforce($type,$ID,$force);
400
- array_push($yarpp_toclear,$ID);
401
- }
402
- }
403
-
404
- yarpp_cache_clear($yarpp_toclear);
405
406
}
407
@@ -411,7 +388,7 @@ function yarpp_cache_clear($reference_IDs) {
411
}
412
413
function yarpp_cache_enforce($type=array('post'),$reference_ID,$force=false) {
414
- global $wpdb, $yarpp_debug, $yarpp_caching_queue;
415
416
if ($reference_ID === '' || $reference_ID === false)
417
return false;
@@ -427,23 +404,19 @@ function yarpp_cache_enforce($type=array('post'),$reference_ID,$force=false) {
427
428
yarpp_cache_keywords($reference_ID);
429
430
- // let's first record the current related posts for this reference ID
431
- $old_relations = $wpdb->get_col("select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID and ID != 0");
432
- array_push($old_relations,0);
433
-
434
- // now clear out the cruft
435
- $wpdb->query("delete from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID");
436
437
// let's update the related posts
438
$wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) ".yarpp_sql($type,array(),true,$reference_ID)." on duplicate key update date = now()");
439
440
if ($wpdb->rows_affected and $yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
441
442
- // if changes were made, let's find out which ones are new. We'll want to then add add these to the queue so their related posts can also be updated.
443
if ($wpdb->rows_affected) {
444
- $new_relations = $wpdb->get_col("select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID and ID not in (".implode(',',$old_relations).")");
445
- //echo "YARPP added (select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID and ID not in (".implode(',',$old_relations).")): ".print_r($new_relations,true)."<br/>";
446
- $yarpp_caching_queue = array_merge($yarpp_caching_queue,$new_relations);
447
}
448
449
if (!$wpdb->rows_affected) {
@@ -451,9 +424,6 @@ function yarpp_cache_enforce($type=array('post'),$reference_ID,$force=false) {
451
if (!$wpdb->rows_affected)
452
return false;
453
}
454
- //$wpdb->query("delete from {$wpdb->prefix}yarpp_related_cache where date <= date_sub(now(),interval $timeout minute)");
455
- //if ($wpdb->rows_affected)
456
- // if ($yarpp_debug) echo "<!--$wpdb->rows_affected rows were cleared as they had expired.-->";
457
458
return true;
459
84
$reference_ID = $post->ID;
85
}
86
87
// set the "domain prefix", used for all the preferences.
88
if ($domain == 'rss')
89
$domainprefix = 'rss_';
367
return $result > 0 ? true: false;
368
}
369
370
function yarpp_save_cache($post_ID,$force=true) {
371
+ global $wpdb;
372
373
$parent_ID = $wpdb->get_var("select post_parent from $wpdb->posts where ID='$post_ID'");
374
if ($parent_ID != $post_ID and $parent_ID)
378
else
379
$type = array('post');
380
381
+ yarpp_cache_enforce($type,$post_ID,$force);
382
383
}
384
388
}
389
390
function yarpp_cache_enforce($type=array('post'),$reference_ID,$force=false) {
391
+ global $wpdb, $yarpp_debug;
392
393
if ($reference_ID === '' || $reference_ID === false)
394
return false;
404
405
yarpp_cache_keywords($reference_ID);
406
407
+ // clear out the cruft
408
+ yarpp_cache_clear(array($reference_ID));
409
410
// let's update the related posts
411
$wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) ".yarpp_sql($type,array(),true,$reference_ID)." on duplicate key update date = now()");
412
413
if ($wpdb->rows_affected and $yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
414
415
+ // if changes were made, let's find out which ones are new. We'll want to clear their caches
416
+ // so that they will be rebuilt when they're hit next.
417
if ($wpdb->rows_affected) {
418
+ $new_relations = $wpdb->get_col("select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID");//and ID not in (".implode(',',$old_relations).")"
419
+ yarpp_cache_clear($new_relations);
420
}
421
422
if (!$wpdb->rows_affected) {
424
if (!$wpdb->rows_affected)
425
return false;
426
}
427
428
return true;
429
readme.txt CHANGED
@@ -148,6 +148,8 @@ If you are a bilingual speaker of English and another language and an avid user
148
149
== Changelog ==
150
151
= 3.1.1 =
152
* [Possible fix for the "no related posts" issue](http://wordpress.org/support/topic/284209/page/2) by [vkovalcik](http://wordpress.org/support/profile/5032111)
153
* Bugfix: [slight optimization to keyword function](http://wordpress.org/support/topic/284209/page/2) by [vkovalcik](http://wordpress.org/support/profile/5032111)
148
149
== Changelog ==
150
151
+ = 3.1.2 =
152
+ * Bugfix: [saving posts would sometimes timeout](http://wordpress.org/support/topic/343001)
153
= 3.1.1 =
154
* [Possible fix for the "no related posts" issue](http://wordpress.org/support/topic/284209/page/2) by [vkovalcik](http://wordpress.org/support/profile/5032111)
155
* Bugfix: [slight optimization to keyword function](http://wordpress.org/support/topic/284209/page/2) by [vkovalcik](http://wordpress.org/support/profile/5032111)
yarpp.php CHANGED
@@ -3,13 +3,13 @@
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.1.1
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
10
*/
11
12
- define('YARPP_VERSION','3.1.1');
13
14
require_once('includes.php');
15
require_once('related-functions.php');
@@ -40,21 +40,8 @@ load_plugin_textdomain('yarpp', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__))
40
add_action('plugins_loaded', 'widget_yarpp_init');
41
// new in 3.0: add meta box
42
add_action( 'admin_menu', 'yarpp_add_metabox');
43
- function yarpp_add_metabox() {
44
- if (function_exists('add_meta_box')) {
45
- add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp'), 'yarpp_metabox', 'post', 'normal' );
46
- }
47
- }
48
- function yarpp_metabox() {
49
- global $post;
50
- echo '<div id="yarpp-related-posts">';
51
- if ($post->ID)
52
- yarpp_related(array('post'),array('limit'=>1000),true,false,'metabox');
53
- else
54
- echo "<p>Related entries may be displayed once you save your entry.</p>";
55
- echo '</div>';
56
- }
57
58
add_action('save_post','yarpp_save_cache');
59
60
add_filter('posts_join','yarpp_join_filter');
@@ -65,3 +52,6 @@ add_filter('posts_request','yarpp_demo_request_filter');
65
add_filter('post_limits','yarpp_limit_filter');
66
add_action('parse_query','yarpp_set_score_override_flag'); // sets the score override flag.
67
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.1.2b1
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
10
*/
11
12
+ define('YARPP_VERSION','3.1.2b1');
13
14
require_once('includes.php');
15
require_once('related-functions.php');
40
add_action('plugins_loaded', 'widget_yarpp_init');
41
// new in 3.0: add meta box
42
add_action( 'admin_menu', 'yarpp_add_metabox');
43
44
+ // update cache on save
45
add_action('save_post','yarpp_save_cache');
46
47
add_filter('posts_join','yarpp_join_filter');
52
add_filter('post_limits','yarpp_limit_filter');
53
add_action('parse_query','yarpp_set_score_override_flag'); // sets the score override flag.
54
55
+ // set $yarpp_debug
56
+ if (isset($_REQUEST['yarpp_debug']))
57
+ $yarpp_debug = true;