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

Version Description

Download this release

Release Info

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

Code changes from version 3.4.4b2 to 3.4.4b3

class-admin.php CHANGED
@@ -3,7 +3,7 @@
3
class YARPP_Admin {
4
public $core;
5
public $hook;
6
-
7
function __construct( &$core ) {
8
$this->core = &$core;
9
@@ -21,6 +21,19 @@ class YARPP_Admin {
21
add_filter( 'default_hidden_meta_boxes', array( $this, 'default_hidden_meta_boxes' ), 10, 2 );
22
}
23
24
function ajax_register() {
25
// Register AJAX services
26
if ( defined('DOING_AJAX') && DOING_AJAX ) {
3
class YARPP_Admin {
4
public $core;
5
public $hook;
6
+
7
function __construct( &$core ) {
8
$this->core = &$core;
9
21
add_filter( 'default_hidden_meta_boxes', array( $this, 'default_hidden_meta_boxes' ), 10, 2 );
22
}
23
24
+ private $templates = null;
25
+ public function get_templates() {
26
+ if ( is_null($this->templates) ) {
27
+ $this->templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
28
+ // if glob hits an error, it returns false.
29
+ if ( $this->templates === false )
30
+ $this->templates = array();
31
+ // get basenames only
32
+ $this->templates = array_map('basename', $this->templates);
33
+ }
34
+ return (array) $this->templates;
35
+ }
36
+
37
function ajax_register() {
38
// Register AJAX services
39
if ( defined('DOING_AJAX') && DOING_AJAX ) {
class-cache.php CHANGED
@@ -478,15 +478,14 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
478
*/
479
public function where_filter($arg) {
480
global $wpdb;
481
- $threshold = yarpp_get_option('threshold');
482
// modify the where clause to use the related ID list.
483
if (!count($this->related_IDs))
484
$this->related_IDs = array(0);
485
$arg = preg_replace("!{$wpdb->posts}.ID = \d+!","{$wpdb->posts}.ID in (".join(',',$this->related_IDs).")",$arg);
486
487
// if we have "recent only" set, add an additional condition
488
- if (yarpp_get_option("recent_only"))
489
- $arg .= " and post_date > date_sub(now(), interval ".yarpp_get_option("recent_number")." ".yarpp_get_option("recent_units").") ";
490
return $arg;
491
}
492
@@ -538,6 +537,8 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
538
global $wpdb;
539
540
$this->yarpp_time = true;
541
542
$this->related_postdata = $wpdb->get_results($this->sql($reference_ID, $args), ARRAY_A);
543
$this->related_IDs = wp_list_pluck( $this->related_postdata, 'ID' );
478
*/
479
public function where_filter($arg) {
480
global $wpdb;
481
// modify the where clause to use the related ID list.
482
if (!count($this->related_IDs))
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
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);
544
$this->related_IDs = wp_list_pluck( $this->related_postdata, 'ID' );
class-core.php CHANGED
@@ -14,8 +14,6 @@ class YARPP {
14
15
public $myisam = true;
16
17
- public $templates = array();
18
-
19
// here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
20
public $default_options = array();
21
@@ -64,7 +62,6 @@ class YARPP {
64
$this->default_options = array(
65
'threshold' => 5,
66
'limit' => 5,
67
- 'template_file' => '', // new in 2.2
68
'excerpt_length' => 10,
69
'recent_number' => 12,
70
'recent_units' => 'month',
@@ -77,7 +74,6 @@ class YARPP {
77
'no_results' => '<p>'.__('No related posts.','yarpp').'</p>',
78
'order' => 'score DESC',
79
'rss_limit' => 3,
80
- 'rss_template_file' => '', // new in 2.2
81
'rss_excerpt_length' => 10,
82
'rss_before_title' => '<li>',
83
'rss_after_title' => '</li>',
@@ -89,10 +85,14 @@ class YARPP {
89
'rss_order' => 'score DESC',
90
'past_only' => true,
91
'show_excerpt' => false,
92
- 'recent_only' => false, // new in 3.0
93
- 'use_template' => false, // new in 2.2
94
'rss_show_excerpt' => false,
95
- 'rss_use_template' => false, // new in 2.2
96
'show_pass_post' => false,
97
'cross_relate' => false,
98
'auto_display' => true,
@@ -241,6 +241,8 @@ class YARPP {
241
$this->upgrade_3_4b8();
242
if ( $last_version && version_compare('3.4.4b2', $last_version) > 0 )
243
$this->upgrade_3_4_4b2();
244
245
$this->cache->upgrade($last_version);
246
// flush cache in 3.4.1b5 as 3.4 messed up calculations.
@@ -414,6 +416,17 @@ class YARPP {
414
update_option( 'yarpp', $options );
415
}
416
417
private $post_types = null;
418
function get_post_types( $field = false ) {
419
if ( is_null($this->post_types) ) {
@@ -481,7 +494,7 @@ class YARPP {
481
482
$this->setup_active_cache( $args );
483
484
- $options = array( 'domain', 'limit', 'use_template', 'order', 'template_file', 'promote_yarpp' );
485
extract( $this->parse_args( $args, $options ) );
486
487
$cache_status = $this->active_cache->enforce($reference_ID);
@@ -517,15 +530,15 @@ class YARPP {
517
$this->prep_query( $current_query->is_feed );
518
$related_query = $wp_query; // backwards compatibility
519
520
- if ($domain == 'metabox') {
521
include(YARPP_DIR.'/template-metabox.php');
522
- } elseif ($use_template && file_exists(STYLESHEETPATH . '/' . $template_file) && $template_file != '') {
523
global $post;
524
ob_start();
525
- include(STYLESHEETPATH . '/' . $template_file);
526
$output = ob_get_contents();
527
ob_end_clean();
528
- } elseif ($domain == 'widget') {
529
include(YARPP_DIR.'/template-widget.php');
530
} else {
531
include(YARPP_DIR.'/template-builtin.php');
@@ -635,7 +648,7 @@ class YARPP {
635
if ( $this->cache_bypass->demo_time ) // if we're already in a demo YARPP loop, stop now.
636
return false;
637
638
- $options = array( 'domain', 'limit', 'use_template', 'order', 'template_file', 'promote_yarpp' );
639
extract( $this->parse_args( $args, $options ) );
640
641
$this->cache_bypass->begin_demo_time( $limit );
@@ -647,10 +660,10 @@ class YARPP {
647
$this->prep_query( $domain == 'rss' );
648
$related_query = $wp_query; // backwards compatibility
649
650
- if ($use_template && file_exists(STYLESHEETPATH . '/' . $template_file) && $template_file != '') {
651
global $post;
652
ob_start();
653
- include(STYLESHEETPATH . '/' . $template_file);
654
$output = ob_get_contents();
655
ob_end_clean();
656
} else {
@@ -668,7 +681,7 @@ class YARPP {
668
}
669
670
public function parse_args( $args, $options ) {
671
- $options_with_rss_variants = array( 'limit', 'template_file', 'excerpt_length', 'before_title', 'after_title', 'before_post', 'after_post', 'before_related', 'after_related', 'no_results', 'order' );
672
673
$r = array();
674
foreach ( $options as $option ) {
14
15
public $myisam = true;
16
17
// here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
18
public $default_options = array();
19
62
$this->default_options = array(
63
'threshold' => 5,
64
'limit' => 5,
65
'excerpt_length' => 10,
66
'recent_number' => 12,
67
'recent_units' => 'month',
74
'no_results' => '<p>'.__('No related posts.','yarpp').'</p>',
75
'order' => 'score DESC',
76
'rss_limit' => 3,
77
'rss_excerpt_length' => 10,
78
'rss_before_title' => '<li>',
79
'rss_after_title' => '</li>',
85
'rss_order' => 'score DESC',
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,
97
'cross_relate' => false,
98
'auto_display' => true,
241
$this->upgrade_3_4b8();
242
if ( $last_version && version_compare('3.4.4b2', $last_version) > 0 )
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.
416
update_option( 'yarpp', $options );
417
}
418
419
+ function upgrade_3_4_4b3() {
420
+ $options = $this->get_option();
421
+ $options['template'] = $options['use_template'] ? $options['template_file'] : false;
422
+ $options['rss_template'] = $options['rss_use_template'] ? $options['rss_template_file'] : false;
423
+ unset( $options['use_template'] );
424
+ unset( $options['template_file'] );
425
+ unset( $options['rss_use_template'] );
426
+ unset( $options['rss_template_file'] );
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) ) {
494
495
$this->setup_active_cache( $args );
496
497
+ $options = array( 'domain', 'limit', 'template', 'order', 'promote_yarpp' );
498
extract( $this->parse_args( $args, $options ) );
499
500
$cache_status = $this->active_cache->enforce($reference_ID);
530
$this->prep_query( $current_query->is_feed );
531
$related_query = $wp_query; // backwards compatibility
532
533
+ if ( 'metabox' == $domain ) {
534
include(YARPP_DIR.'/template-metabox.php');
535
+ } elseif ( !!$template && file_exists(STYLESHEETPATH . '/' . $template) ) {
536
global $post;
537
ob_start();
538
+ include(STYLESHEETPATH . '/' . $template);
539
$output = ob_get_contents();
540
ob_end_clean();
541
+ } elseif ( 'widget' == $domain ) {
542
include(YARPP_DIR.'/template-widget.php');
543
} else {
544
include(YARPP_DIR.'/template-builtin.php');
648
if ( $this->cache_bypass->demo_time ) // if we're already in a demo YARPP loop, stop now.
649
return false;
650
651
+ $options = array( 'domain', 'limit', 'template', 'order', 'promote_yarpp' );
652
extract( $this->parse_args( $args, $options ) );
653
654
$this->cache_bypass->begin_demo_time( $limit );
660
$this->prep_query( $domain == 'rss' );
661
$related_query = $wp_query; // backwards compatibility
662
663
+ if ( !!$template && file_exists(STYLESHEETPATH . '/' . $template) ) {
664
global $post;
665
ob_start();
666
+ include(STYLESHEETPATH . '/' . $template);
667
$output = ob_get_contents();
668
ob_end_clean();
669
} else {
681
}
682
683
public function parse_args( $args, $options ) {
684
+ $options_with_rss_variants = array( 'limit', 'template', 'excerpt_length', 'before_title', 'after_title', 'before_post', 'after_post', 'before_related', 'after_related', 'no_results', 'order' );
685
686
$r = array();
687
foreach ( $options as $option ) {
class-widget.php CHANGED
@@ -14,18 +14,19 @@ class YARPP_Widget extends WP_Widget {
14
15
extract($args);
16
17
$instance['post_type'] = ($post->post_type == 'page' ? array('page') : array('post'));
18
if ( yarpp_get_option('cross_relate') )
19
$instance['post_type'] = array('post','page');
20
21
$title = apply_filters('widget_title', $instance['title']);
22
echo $before_widget;
23
- if ( !$instance['use_template'] ) {
24
echo $before_title;
25
- if ($title)
26
- echo $title;
27
- else
28
- _e('Related Posts (YARPP)','yarpp');
29
echo $after_title;
30
}
31
@@ -35,60 +36,63 @@ class YARPP_Widget extends WP_Widget {
35
}
36
37
function update($new_instance, $old_instance) {
38
- // this starts with default values.
39
- $instance = array( 'promote_yarpp' => 0, 'use_template' => 0 );
40
- foreach ( $instance as $field => $val ) {
41
- if ( isset($new_instance[$field]) )
42
- $instance[$field] = 1;
43
- }
44
- if ($instance['use_template']) {
45
- $instance['template_file'] = $new_instance['template_file'];
46
$instance['title'] = $old_instance['title'];
47
- } else {
48
- $instance['template_file'] = $old_instance['template_file'];
49
$instance['title'] = $new_instance['title'];
50
- }
51
return $instance;
52
}
53
54
function form($instance) {
55
- $title = esc_attr($instance['title']);
56
- $template_file = $instance['template_file'];
57
?>
58
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
59
-
60
- <?php // if there are YARPP templates installed...
61
-
62
- $templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
63
- if ( is_array($templates) && count($templates) ): ?>
64
-
65
- <p><input class="checkbox" id="<?php echo $this->get_field_id('use_template'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="checkbox" <?php checked($instance['use_template'], true) ?> /> <label for="<?php echo $this->get_field_id('use_template'); ?>"><?php _e("Display using a custom template file",'yarpp');?></label></p>
66
- <p id="<?php echo $this->get_field_id('template_file_p'); ?>"><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>">
67
- <?php foreach ($templates as $template): ?>
68
- <option value='<?php echo htmlspecialchars(basename($template))?>'<?php echo (basename($template)==$template_file)?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
69
- <?php endforeach; ?>
70
- </select><p>
71
-
72
- <?php endif; ?>
73
74
- <p><input class="checkbox" id="<?php echo $this->get_field_id('promote_yarpp'); ?>" name="<?php echo $this->get_field_name('promote_yarpp'); ?>" type="checkbox" <?php checked($instance['images'], true) ?> /> <label for="<?php echo $this->get_field_id('promote_yarpp'); ?>"><?php _e("Help promote Yet Another Related Posts Plugin?",'yarpp'); ?></label></p>
75
76
- <script type="text/javascript">
77
- jQuery(function($) {
78
- function ensureTemplateChoice() {
79
- if ($('#<?php echo $this->get_field_id('use_template'); ?>').attr('checked')) {
80
- $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',true);
81
- $('#<?php echo $this->get_field_id('template_file_p'); ?>').show();
82
- } else {
83
- $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',false);
84
- $('#<?php echo $this->get_field_id('template_file_p'); ?>').hide();
85
- }
86
}
87
- $('#<?php echo $this->get_field_id('use_template'); ?>').change(ensureTemplateChoice);
88
- ensureTemplateChoice();
89
- });
90
- </script>
91
92
<?php
93
}
94
}
14
15
extract($args);
16
17
+ // compatibility with pre-3.4.4 settings:
18
+ if ( isset($instance['use_template']) )
19
+ $instance['template'] = $instance['use_template'] ? $instance['template_file'] : false;
20
+
21
$instance['post_type'] = ($post->post_type == 'page' ? array('page') : array('post'));
22
if ( yarpp_get_option('cross_relate') )
23
$instance['post_type'] = array('post','page');
24
25
$title = apply_filters('widget_title', $instance['title']);
26
echo $before_widget;
27
+ if ( !$instance['template'] ) {
28
echo $before_title;
29
+ echo $title;
30
echo $after_title;
31
}
32
36
}
37
38
function update($new_instance, $old_instance) {
39
+ $instance = array(
40
+ 'promote_yarpp' => isset($new_instance['promote_yarpp']),
41
+ 'template' => isset($new_instance['use_template']) ? $new_instance['template_file'] : false
42
+ );
43
+
44
+ if ( !!$instance['template'] ) // don't save the title change.
45
$instance['title'] = $old_instance['title'];
46
+ else // save the title change:
47
$instance['title'] = $new_instance['title'];
48
+
49
return $instance;
50
}
51
52
function form($instance) {
53
+ global $yarpp;
54
+
55
+ $instance = wp_parse_args( $instance, array(
56
+ 'title' => __('Related Posts (YARPP)','yarpp'),
57
+ 'template' => false,
58
+ 'promote_yarpp' => false
59
+ ) );
60
+
61
+ // compatibility with pre-3.4.4 settings:
62
+ if ( isset($instance['use_template']) )
63
+ $instance['template'] = $instance['template_file'];
64
+
65
?>
66
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" /></label></p>
67
68
+ <?php // if there are YARPP templates installed...
69
+ $templates = $yarpp->admin->get_templates();
70
+ if ( count($templates) ): ?>
71
72
+ <p><input class="checkbox" id="<?php echo $this->get_field_id('use_template'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="checkbox" <?php checked(!!$instance['template']) ?> /> <label for="<?php echo $this->get_field_id('use_template'); ?>"><?php _e("Display using a custom template file",'yarpp');?></label></p>
73
+ <p id="<?php echo $this->get_field_id('template_file_p'); ?>"><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>">
74
+ <?php foreach ($templates as $template): ?>
75
+ <option value='<?php echo esc_attr($template); ?>'<?php selected($template, $instance['template']);?>><?php echo esc_html($template); ?></option>
76
+ <?php endforeach; ?>
77
+ </select><p>
78
+ <script type="text/javascript">
79
+ jQuery(function($) {
80
+ function ensureTemplateChoice() {
81
+ if ($('#<?php echo $this->get_field_id('use_template'); ?>').attr('checked')) {
82
+ $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',true);
83
+ $('#<?php echo $this->get_field_id('template_file_p'); ?>').show();
84
+ } else {
85
+ $('#<?php echo $this->get_field_id('title'); ?>').attr('disabled',false);
86
+ $('#<?php echo $this->get_field_id('template_file_p'); ?>').hide();
87
}
88
+ }
89
+ $('#<?php echo $this->get_field_id('use_template'); ?>').change(ensureTemplateChoice);
90
+ ensureTemplateChoice();
91
+ });
92
+ </script>
93
+ <?php endif; ?>
94
95
+ <p><input class="checkbox" id="<?php echo $this->get_field_id('promote_yarpp'); ?>" name="<?php echo $this->get_field_name('promote_yarpp'); ?>" type="checkbox" <?php checked($instance['promote_yarpp']) ?> /> <label for="<?php echo $this->get_field_id('promote_yarpp'); ?>"><?php _e("Help promote Yet Another Related Posts Plugin?",'yarpp'); ?></label></p>
96
<?php
97
}
98
}
options-meta-boxes.php CHANGED
@@ -1,11 +1,21 @@
1
<?php
2
3
class YARPP_Meta_Box {
4
- function checkbox($option,$desc,$tr="<tr valign='top'>
5
- <th class='th-full' colspan='2' scope='row'>",$inputplus = '',$thplus='') {
6
- echo " $tr<input $inputplus type='checkbox' name='$option' value='true'". ((yarpp_get_option($option) == 1) ? ' checked="checked"': '' )." /> $desc</th>$thplus
7
</tr>";
8
}
9
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
10
<th scope='row'>", $note = '') {
11
$value = esc_attr(yarpp_get_option($option));
@@ -166,15 +176,17 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
166
<th class='th-full' colspan='2' scope='row' style='width:100%;'>",'','<td rowspan="3" style="border-left:8px transparent solid;"><b>'.__("Website display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
167
."<div id='display_demo_web' style='overflow:auto;width:350px;max-height:500px;'></div></td>");
168
$this->textbox('limit',__('Maximum number of related posts:','yarpp'));
169
- $this->checkbox('use_template',__("Display using a custom template file",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This advanced option gives you full power to customize how your related posts are displayed. Templates (stored in your theme folder) are written in PHP.",'yarpp')."</span></a>","<tr valign='top'><th colspan='2'>",' class="template"'.(!(is_array($yarpp->templates) && count($yarpp->templates))?' disabled="disabled"':'')); ?>
170
</tbody></table>
171
<table class="form-table" style="clear:none;"><tbody>
172
<tr valign='top' class='templated'>
173
<th><?php _e("Template file:",'yarpp');?></th>
174
<td>
175
<select name="template_file" id="template_file">
176
- <?php foreach (glob(STYLESHEETPATH . '/yarpp-template-*.php') as $template): ?>
177
- <option value='<?php echo esc_attr(basename($template))?>'<?php echo (basename($template)==yarpp_get_option('template_file'))?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
178
<?php endforeach; ?>
179
</select>
180
</td>
@@ -224,7 +236,8 @@ $this->checkbox('rss_excerpt_display',__("Display related posts in the descripti
224
225
$this->textbox('rss_limit',__('Maximum number of related posts:','yarpp'),2, "<tr valign='top' class='rss_displayed'>
226
<th scope='row'>");
227
- $this->checkbox('rss_use_template',__("Display using a custom template file",'yarpp')." <!--<span style='color:red;'>".__('NEW!','yarpp')."</span>--> <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This advanced option gives you full power to customize how your related posts are displayed. Templates (stored in your theme folder) are written in PHP.",'yarpp')."</span></a>","<tr valign='top' class='rss_displayed'><th colspan='2'>",' class="rss_template"'.(!(is_array($yarpp->templates) && count($yarpp->templates))?' disabled="disabled"':'')); ?>
228
</tbody></table>
229
<table class="form-table rss_displayed" style="clear:none;">
230
<tbody>
@@ -232,8 +245,10 @@ $this->checkbox('rss_excerpt_display',__("Display related posts in the descripti
232
<th><?php _e("Template file:",'yarpp');?></th>
233
<td>
234
<select name="rss_template_file" id="rss_template_file">
235
- <?php foreach (glob(STYLESHEETPATH . '/yarpp-template-*.php') as $template): ?>
236
- <option value='<?php echo htmlspecialchars(basename($template))?>'<?php echo (basename($template)==yarpp_get_option('rss_template_file'))?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
237
<?php endforeach; ?>
238
</select>
239
</td>
1
<?php
2
3
class YARPP_Meta_Box {
4
+ function checkbox($option,$desc,$tr="<tr valign='top'><th class='th-full' colspan='2' scope='row'>",$inputplus = '',$thplus='') {
5
+ echo "$tr<input $inputplus type='checkbox' name='$option' value='true'";
6
+ checked(yarpp_get_option($option) == 1);
7
+ echo " /> $desc</th>$thplus
8
</tr>";
9
}
10
+ function template_checkbox( $rss = false, $trextra = '' ) {
11
+ global $yarpp;
12
+ $pre = $rss ? 'rss_' : '';
13
+ $chosen_template = yarpp_get_option( "{$pre}template" );
14
+ echo "<tr valign='top'{$trextra}><th colspan='2'><input type='checkbox' name='{$pre}use_template' class='{$pre}template' value='true'";
15
+ disabled(!count($yarpp->admin->get_templates()), true);
16
+ checked( !!$chosen_template );
17
+ echo " /> " . __("Display using a custom template file",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This advanced option gives you full power to customize how your related posts are displayed. Templates (stored in your theme folder) are written in PHP.",'yarpp')."</span></a>" . "</th></tr>";
18
+ }
19
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
20
<th scope='row'>", $note = '') {
21
$value = esc_attr(yarpp_get_option($option));
176
<th class='th-full' colspan='2' scope='row' style='width:100%;'>",'','<td rowspan="3" style="border-left:8px transparent solid;"><b>'.__("Website display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
177
."<div id='display_demo_web' style='overflow:auto;width:350px;max-height:500px;'></div></td>");
178
$this->textbox('limit',__('Maximum number of related posts:','yarpp'));
179
+ $this->template_checkbox( false );
180
+ ?>
181
</tbody></table>
182
<table class="form-table" style="clear:none;"><tbody>
183
<tr valign='top' class='templated'>
184
<th><?php _e("Template file:",'yarpp');?></th>
185
<td>
186
<select name="template_file" id="template_file">
187
+ <?php
188
+ foreach ($yarpp->admin->get_templates() as $template): ?>
189
+ <option value='<?php echo esc_attr($template)?>'<?php selected($template, $chosen_template);?>><?php echo esc_html($template)?></option>
190
<?php endforeach; ?>
191
</select>
192
</td>
236
237
$this->textbox('rss_limit',__('Maximum number of related posts:','yarpp'),2, "<tr valign='top' class='rss_displayed'>
238
<th scope='row'>");
239
+ $this->template_checkbox( true, " class='rss_displayed'" );
240
+ ?>
241
</tbody></table>
242
<table class="form-table rss_displayed" style="clear:none;">
243
<tbody>
245
<th><?php _e("Template file:",'yarpp');?></th>
246
<td>
247
<select name="rss_template_file" id="rss_template_file">
248
+ <?php
249
+ $chosen_template = yarpp_get_option('rss_template');
250
+ foreach ($yarpp->admin->get_templates() as $template): ?>
251
+ <option value='<?php echo esc_attr($template);?>'<?php selected($template, $chosen_template);?>><?php echo esc_html($template);?></option>
252
<?php endforeach; ?>
253
</select>
254
</td>
options.php CHANGED
@@ -8,9 +8,8 @@ else
8
$yarpp->upgrade_check();
9
10
// check to see that templates are in the right place
11
- $yarpp->templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
12
- if ( !(is_array($yarpp->templates) && count($yarpp->templates)) ) {
13
- yarpp_set_option(array('use_template' => false, 'rss_use_template' => false));
14
}
15
16
// 3.3: move version checking here, in PHP:
@@ -118,9 +117,11 @@ if (isset($_POST['update_yarpp'])) {
118
}
119
}
120
121
- if ( isset($_POST['exclude']) ) {
122
$new_options['exclude'] = implode(',',array_keys($_POST['exclude']));
123
- }
124
125
$new_options = apply_filters( 'yarpp_settings_save', $new_options );
126
yarpp_set_option($new_options);
8
$yarpp->upgrade_check();
9
10
// check to see that templates are in the right place
11
+ if ( !count($yarpp->admin->get_templates()) ) {
12
+ yarpp_set_option( array( 'template' => false, 'rss_template' => false) );
13
}
14
15
// 3.3: move version checking here, in PHP:
117
}
118
}
119
120
+ if ( isset($_POST['exclude']) )
121
$new_options['exclude'] = implode(',',array_keys($_POST['exclude']));
122
+
123
+ $new_options['template'] = isset($_POST['use_template']) ? $_POST['template_file'] : false;
124
+ $new_options['rss_template'] = isset($_POST['rss_use_template']) ? $_POST['rss_template_file'] : false;
125
126
$new_options = apply_filters( 'yarpp_settings_save', $new_options );
127
yarpp_set_option($new_options);
readme.txt CHANGED
@@ -121,6 +121,56 @@ However, YARPP does have difficulty with languages that don't place spaces betwe
121
122
The official [YARPP Experiments](http://wordpress.org/extend/plugins/yarpp-experiments/) plugin adds manual cache controls, letting you flush the cache and build it up manually.
123
124
== Localizations ==
125
126
YARPP is currently localized in the following languages:
@@ -174,10 +224,12 @@ If you are a bilingual speaker of English and another language and an avid user
174
== Changelog ==
175
176
= 3.4.4 =
177
* Further main query optimization:
178
* What's cooler than joining four tables? Joining two.
179
* Exclude now simply uses `term_taxonomy_id`s instead of `term_id`s
180
- * Change format of `weight` paramters in options and in optional args
181
* Added "consider with extra weight" to taxonomy criteria as well
182
* Code cleanup:
183
* Don't clear the cache when it's already empty
121
122
The official [YARPP Experiments](http://wordpress.org/extend/plugins/yarpp-experiments/) plugin adds manual cache controls, letting you flush the cache and build it up manually.
123
124
+ == Developing with YARPP ==
125
+
126
+ = Custom displays and custom post type support =
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
141
+ 'weight' => array(
142
+ 'body' => 1,
143
+ 'title' => 2, // larger weights mean this criteria will be weighted more heavily
144
+ 'tax' => array(
145
+ 'post_tag' => 1,
146
+ ... // put any taxonomies you want to consider here with their weights
147
+ )
148
+ ),
149
+ // Specify taxonomies and a number here to require that a certain number be shared:
150
+ 'require_tax' => array(
151
+ 'post_tag' => 1 // for example, this requires all results to have at least one 'post_tag' in common.
152
+ ),
153
+ // The threshold which must be met by the "match score"
154
+ 'threshold' => 5,
155
+
156
+ // Display options:
157
+ 'template' => , // either the name of a file in your active theme or the boolean false to use the builtin template
158
+ 'limit' => 5, // maximum number of results
159
+ 'order' => 'score DESC'
160
+ ));
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
+
168
+ = Custom taxonomy support =
169
+
170
+ Any taxonomy, including custom taxonomies, may be specified in the `weight` or `require_tax` arguments in a custom display as above. `term_taxonomy_id`s specified in the `exclude` argument may be of any taxonomy.
171
+
172
+ If you would like to choose custom taxonomies to choose in the YARPP settings UI, either to exclude certain terms or to consider them in the relatedness formula via the UI, the taxonomy must (a) have either the `show_ui` or `yarpp_support` attribute set to true and (b) must apply to either the post types `post` or `page` or both.
173
+
174
== Localizations ==
175
176
YARPP is currently localized in the following languages:
224
== Changelog ==
225
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
233
* Added "consider with extra weight" to taxonomy criteria as well
234
* Code cleanup:
235
* Don't clear the cache when it's already empty
template-builtin.php CHANGED
@@ -3,7 +3,8 @@
3
* YARPP's built-in "template"
4
*
5
* This "template" is used when you choose not to use a template.
6
- * If you want to create a new template, look at templates/template-example.php as an example.
7
*/
8
9
get_currentuserinfo();
3
* YARPP's built-in "template"
4
*
5
* This "template" is used when you choose not to use a template.
6
+ * If you want to create a new template, look at yarpp-templates/yarpp-template-example.php as an example.
7
+ * More information on the custom templates is available at http://mitcho.com/blog/projects/yarpp-3-templates/
8
*/
9
10
get_currentuserinfo();
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.4b2
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.4b2');
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.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', ':)');