Yet Another Related Posts Plugin (YARPP) - Version 3.4b10

Version Description

Download this release

Release Info

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

Code changes from version 3.4b9 to 3.4b10

Files changed (10) hide show
  1. blogglue.php +6 -0
  2. cache-tables.php +2 -2
  3. class-admin.php +39 -14
  4. class-cache.php +8 -12
  5. options.js +0 -141
  6. options.php +7 -5
  7. readme.txt +4 -2
  8. related-functions.php +10 -10
  9. template-metabox.php +2 -3
  10. yarpp.php +2 -2
blogglue.php CHANGED
@@ -1,4 +1,10 @@
1
<?php
2
function add_yarpp_blogglue_meta_box() {
3
class YARPP_Meta_Box_BlogGlue extends YARPP_Meta_Box {
4
function display() {
1
<?php
2
+ function yarpp_blogglue_enqueue() {
3
+ wp_enqueue_script( 'thickbox' );
4
+ wp_enqueue_style( 'thickbox' );
5
+ }
6
+ add_action( 'admin_enqueue_scripts', 'yarpp_blogglue_enqueue' );
7
+
8
function add_yarpp_blogglue_meta_box() {
9
class YARPP_Meta_Box_BlogGlue extends YARPP_Meta_Box {
10
function display() {
cache-tables.php CHANGED
@@ -267,8 +267,8 @@ class YARPP_Cache_Tables extends YARPP_Cache {
267
$body_terms = $this->body_keywords($ID);
268
$title_terms = $this->title_keywords($ID);
269
270
- if (defined('DB_CHARSET') && DB_CHARSET) {
271
- $wpdb->query('set names '.DB_CHARSET);
272
}
273
274
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " (ID,body,title) values ($ID,'$body_terms ','$title_terms ') on duplicate key update date = now(), body = '$body_terms ', title = '$title_terms '");
267
$body_terms = $this->body_keywords($ID);
268
$title_terms = $this->title_keywords($ID);
269
270
+ if ( !empty($wpdb->dbh) && defined('DB_CHARSET') ) {
271
+ $wpdb->set_charset( $wpdb->dbh, DB_CHARSET );
272
}
273
274
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " (ID,body,title) values ($ID,'$body_terms ','$title_terms ') on duplicate key update date = now(), body = '$body_terms ', title = '$title_terms '");
class-admin.php CHANGED
@@ -18,6 +18,7 @@ class YARPP_Admin {
18
if ( defined('DOING_AJAX') && DOING_AJAX ) {
19
add_action( 'wp_ajax_yarpp_display_exclude_terms', array( $this, 'ajax_display_exclude_terms' ) );
20
add_action( 'wp_ajax_yarpp_display_demo', array( $this, 'ajax_display_demo' ) );
21
}
22
}
23
@@ -40,13 +41,14 @@ class YARPP_Admin {
40
// since 3.3
41
function enqueue() {
42
global $current_screen;
43
if (is_object($current_screen) && $current_screen->id == 'settings_page_yarpp') {
44
- $version = defined('WP_DEBUG') && WP_DEBUG ? time() : YARPP_VERSION;
45
wp_enqueue_script( 'postbox' );
46
wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), $version );
47
- wp_enqueue_script( 'yarpp_options', plugins_url( 'options.js', __FILE__ ), array('jquery'), $version );
48
- // wp_enqueue_script( 'thickbox' );
49
- // wp_enqueue_style( 'thickbox' );
50
}
51
}
52
@@ -62,17 +64,15 @@ class YARPP_Admin {
62
// for proper metabox support:
63
require(YARPP_DIR.'/options.php');
64
}
65
-
66
function metabox() {
67
- echo '<style>#yarpp_relatedposts h3 .postbox-title-action { right: 30px; top: 5px; position: absolute; padding: 0 }</style><div id="yarpp-related-posts">';
68
- if ( get_the_ID() )
69
- $this->core->display_related(null, array(
70
- 'post_type' => array('post'),
71
- 'domain' => 'metabox'
72
- ));
73
- else
74
- echo "<p>".__("Related entries may be displayed once you save your entry",'yarpp').".</p>";
75
- echo '</div>';
76
}
77
78
// since 3.3: default metaboxes to show:
@@ -87,6 +87,8 @@ class YARPP_Admin {
87
*/
88
89
function ajax_display_exclude_terms() {
90
if ( !isset($_REQUEST['taxonomy']) )
91
return;
92
@@ -123,7 +125,30 @@ class YARPP_Admin {
123
exit;
124
}
125
126
function ajax_display_demo() {
127
header("HTTP/1.1 200");
128
header("Content-Type: text/html; charset=UTF-8");
129
18
if ( defined('DOING_AJAX') && DOING_AJAX ) {
19
add_action( 'wp_ajax_yarpp_display_exclude_terms', array( $this, 'ajax_display_exclude_terms' ) );
20
add_action( 'wp_ajax_yarpp_display_demo', array( $this, 'ajax_display_demo' ) );
21
+ add_action( 'wp_ajax_yarpp_display', array( $this, 'ajax_display' ) );
22
}
23
}
24
41
// since 3.3
42
function enqueue() {
43
global $current_screen;
44
+ $version = defined('WP_DEBUG') && WP_DEBUG ? time() : YARPP_VERSION;
45
if (is_object($current_screen) && $current_screen->id == 'settings_page_yarpp') {
46
wp_enqueue_script( 'postbox' );
47
wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), $version );
48
+ wp_enqueue_script( 'yarpp_options', plugins_url( 'js/options.js', __FILE__ ), array('jquery'), $version );
49
+ }
50
+ if (is_object($current_screen) && $current_screen->id == 'post') {
51
+ wp_enqueue_script( 'yarpp_metabox', plugins_url( 'js/metabox.js', __FILE__ ), array('jquery'), $version );
52
}
53
}
54
64
// for proper metabox support:
65
require(YARPP_DIR.'/options.php');
66
}
67
+
68
+ // since 3.4: don't actually compute results here, but use ajax instead
69
function metabox() {
70
+ echo '<style>#yarpp_relatedposts h3 .postbox-title-action { right: 30px; top: 5px; position: absolute; padding: 0 } #yarpp_relatedposts:hover .edit-box { display: inline; }</style>';
71
+ if ( !get_the_ID() ) {
72
+ echo "<div><p>".__("Related entries may be displayed once you save your entry",'yarpp').".</p></div>";
73
+ } else {
74
+ echo '<div id="yarpp-related-posts"><img src="' . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . '" alt="" /></div>';
75
+ }
76
}
77
78
// since 3.3: default metaboxes to show:
87
*/
88
89
function ajax_display_exclude_terms() {
90
+ // @todo nonce
91
+
92
if ( !isset($_REQUEST['taxonomy']) )
93
return;
94
125
exit;
126
}
127
128
+ function ajax_display() {
129
+ // @todo nonce
130
+
131
+ if ( !isset($_REQUEST['ID']) )
132
+ return;
133
+
134
+ header("HTTP/1.1 200");
135
+ header("Content-Type: text/html; charset=UTF-8");
136
+
137
+ $args = array(
138
+ 'post_type' => array('post'),
139
+ 'domain' => isset($_REQUEST['domain']) ? $_REQUEST['domain'] : 'website'
140
+ );
141
+ if ( $this->core->get_option('cross_relate') )
142
+ $args['post_type'] = array('post', 'page');
143
+
144
+ $return = $this->core->display_related($_REQUEST['ID'], $args, false);
145
+ echo $return;
146
+ exit;
147
+ }
148
+
149
function ajax_display_demo() {
150
+ // @todo nonce?
151
+
152
header("HTTP/1.1 200");
153
header("Content-Type: text/html; charset=UTF-8");
154
class-cache.php CHANGED
@@ -49,20 +49,16 @@ abstract class YARPP_Cache {
49
* POST STATUS INTERACTIONS
50
*/
51
52
- function save_post($post_ID, $force=true) {
53
global $wpdb;
54
55
- // new in 3.2: don't compute cache during import
56
- if ( defined( 'WP_IMPORTING' ) )
57
return;
58
-
59
- $post = get_post( $post_ID );
60
- $parent_ID = $post->post_parent;
61
-
62
- if ( $parent_ID != $post_ID && $parent_ID )
63
- $post_ID = $parent_ID;
64
-
65
- $this->enforce((int) $post_ID, $force);
66
}
67
68
// Clear the cache for this entry and for all posts which are "related" to it.
@@ -110,7 +106,7 @@ abstract class YARPP_Cache {
110
* SQL!
111
*/
112
113
- function sql( $reference_ID = false, $args ) {
114
global $wpdb, $post;
115
116
if ( is_object($post) && !$reference_ID ) {
49
* POST STATUS INTERACTIONS
50
*/
51
52
+ function save_post($post_ID) {
53
global $wpdb;
54
55
+ // @since 3.2: don't compute cache during import
56
+ // @since 3.4: don't compute on revisions
57
+ if (defined('WP_IMPORTING') || wp_is_post_revision($post_ID))
58
return;
59
+
60
+ // @since 3.4: simply clear the cache on save; don't recompute.
61
+ $this->clear((int) $post_ID);
62
}
63
64
// Clear the cache for this entry and for all posts which are "related" to it.
106
* SQL!
107
*/
108
109
+ function sql( $reference_ID = false, $args = array() ) {
110
global $wpdb, $post;
111
112
if ( is_object($post) && !$reference_ID ) {
options.js DELETED
@@ -1,141 +0,0 @@
1
- jQuery(function($) {
2
- // since 3.3: add screen option toggles
3
- postboxes.add_postbox_toggles(pagenow);
4
-
5
- function template() {
6
- if ($('.template').attr('checked')) {
7
- $('.templated').show();
8
- $('.not_templated').hide();
9
- } else {
10
- $('.templated').hide();
11
- $('.not_templated').show();
12
- }
13
- excerpt();
14
- }
15
- $('.template').click(template);
16
- template();
17
-
18
- function excerpt() {
19
- if (!$('.template').attr('checked') && $('.show_excerpt').attr('checked'))
20
- $('.excerpted').show();
21
- else
22
- $('.excerpted').hide();
23
- }
24
- $('.show_excerpt,.template').click(excerpt);
25
-
26
- var loaded_demo_web = false;
27
- function display() {
28
- if ( !$('#yarpp_display_web .inside').is(':visible') )
29
- return;
30
- if ( !loaded_demo_web ) {
31
- loaded_demo_web = true;
32
- var demo_web = $('#display_demo_web');
33
- $.ajax({type:'POST',
34
- url: ajaxurl,
35
- data:'action=yarpp_display_demo&domain=website',
36
- beforeSend:function(){demo_web.html(loading)},
37
- success:function(html){demo_web.html('<pre>'+html+'</pre>')},
38
- dataType:'html'});
39
- }
40
- }
41
- $('#yarpp_display_web .handlediv, #yarpp_display_web-hide').click(display);
42
- display();
43
-
44
- var loaded_demo_rss = false;
45
- function rss_display() {
46
- if ( !$('#yarpp_display_rss .inside').is(':visible') )
47
- return;
48
- if ($('.rss_display').attr('checked')) {
49
- $('.rss_displayed').show();
50
- if ( !loaded_demo_rss ) {
51
- loaded_demo_rss = true;
52
- var demo_rss = $('#display_demo_rss');
53
- $.ajax({type:'POST',
54
- url: ajaxurl,
55
- data:'action=yarpp_display_demo&domain=rss',
56
- beforeSend:function(){demo_rss.html(loading)},
57
- success:function(html){demo_rss.html('<pre>'+html+'</pre>')},
58
- dataType:'html'});
59
- }
60
- rss_template();
61
- } else {
62
- $('.rss_displayed').hide();
63
- }
64
- }
65
- $('.rss_display, #yarpp_display_rss .handlediv, #yarpp_display_rss-hide').click(rss_display);
66
- rss_display();
67
-
68
- function rss_template() {
69
- if ($('.rss_template').attr('checked')) {
70
- $('.rss_templated').show();
71
- $('.rss_not_templated').hide();
72
- } else {
73
- $('.rss_templated').hide();
74
- $('.rss_not_templated').show();
75
- }
76
- rss_excerpt();
77
- }
78
- $('.rss_template').click(rss_template);
79
-
80
- function rss_excerpt() {
81
- if ($('.rss_display').attr('checked') && $('.rss_show_excerpt').attr('checked'))
82
- $('.rss_excerpted').show();
83
- else
84
- $('.rss_excerpted').hide();
85
- }
86
- $('.rss_display,.rss_show_excerpt').click(rss_excerpt);
87
-
88
- var loaded_disallows = false;
89
- function load_disallows() {
90
- if ( loaded_disallows || !$('#yarpp_pool .inside').is(':visible') )
91
- return;
92
- loaded_disallows = true;
93
-
94
- var finished_taxonomies = {},
95
- term_indices = {};
96
- function load_disallow(taxonomy) {
97
- if (taxonomy in finished_taxonomies)
98
- return;
99
- var display = $('#exclude_' + taxonomy);
100
- // only do one query at a time:
101
- if (display.find('.loading').length)
102
- return;
103
-
104
- if ( taxonomy in term_indices )
105
- term_indices[taxonomy] = term_indices[taxonomy] + 100;
106
- else
107
- term_indices[taxonomy] = 0;
108
- $.ajax({type:'POST',
109
- url: ajaxurl,
110
- data: { action: 'yarpp_display_exclude_terms',
111
- taxonomy: taxonomy,
112
- offset: term_indices[taxonomy]
113
- },
114
- beforeSend:function(){
115
- display.append(loading)
116
- },
117
- success:function(html){
118
- display.find('.loading').remove();
119
- if (':(' == html) { // no more :(
120
- finished_taxonomies[taxonomy] = true;
121
- return;
122
- }
123
- display.append(html);
124
- },
125
- dataType:'html'}
126
- );
127
- }
128
-
129
- ['post_tag', 'category'].forEach(function(taxonomy) {
130
- load_disallow(taxonomy);
131
- $('#exclude_' + taxonomy).parent('.scroll_wrapper').scroll(function() {
132
- var parent = $(this),
133
- content = parent.children('div');
134
- if ( parent.scrollTop() + parent.height() > content.height() - 10 )
135
- load_disallow(taxonomy);
136
- })
137
- });
138
- }
139
- $('#yarpp_pool .handlediv, #yarpp_pool-hide').click(load_disallows);
140
- load_disallows();
141
- });
options.php CHANGED
@@ -75,14 +75,14 @@ if ( !yarpp_get_option('myisam_override') ) {
75
}
76
77
if ( $yarpp->myisam && !$yarpp->enabled() ) {
78
- echo '<div class="updated"><p>';
79
if ( $yarpp->activate() ) {
80
_e('The YARPP database had an error but has been fixed.','yarpp');
81
} else {
82
_e('The YARPP database has an error which could not be fixed.','yarpp');
83
printf(__('Please try <a href="%s" target="_blank">manual SQL setup</a>.','yarpp'), 'http://mitcho.com/code/yarpp/sql.php?prefix='.urlencode($wpdb->prefix));
84
}
85
- echo '</div></p>';
86
}
87
88
if (isset($_POST['update_yarpp'])) {
@@ -154,9 +154,11 @@ var spinner = '<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>'
154
</script>
155
156
<div>
157
- <p class="submit">
158
- <input type="submit" class='button-primary' name="update_yarpp" value="<?php _e("Update options",'yarpp')?>" />
159
- </p>
160
</div>
161
162
</form>
75
}
76
77
if ( $yarpp->myisam && !$yarpp->enabled() ) {
78
+ echo '<div class="updated">';
79
if ( $yarpp->activate() ) {
80
_e('The YARPP database had an error but has been fixed.','yarpp');
81
} else {
82
_e('The YARPP database has an error which could not be fixed.','yarpp');
83
printf(__('Please try <a href="%s" target="_blank">manual SQL setup</a>.','yarpp'), 'http://mitcho.com/code/yarpp/sql.php?prefix='.urlencode($wpdb->prefix));
84
}
85
+ echo '</div>';
86
}
87
88
if (isset($_POST['update_yarpp'])) {
154
</script>
155
156
<div>
157
+ <input type="submit" class='button-primary' name="update_yarpp" value="<?php _e( 'Save Changes' )?>" />
158
</div>
159
160
+ </div><!--#poststuff-->
161
+
162
</form>
163
+
164
+ </div><!--.wrap-->
readme.txt CHANGED
@@ -203,9 +203,11 @@ If you are a bilingual speaker of English and another language and an avid user
203
* 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
204
* Added `yarpp_get_related()` function can be used similar to `get_posts()`
205
* Significant code cleanup
206
- * Move many internal functions into a global object `$yarpp` of class `YARPP`; references to the global `$yarpp_cache` should now be to global `$yarpp->cache`.
207
* Created the "bypass" cache engine which is used when custom arguments are specified.
208
- * Switch to bypass cache for demos.
209
* Removed the many different options entries, replacing them with a single `yarpp` option (except `yarpp_version`)
210
* Fixed issues with display options field data escaping and slashing once and for all
211
* Performance improvements on pages with "no related posts"
203
* 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
204
* Added `yarpp_get_related()` function can be used similar to `get_posts()`
205
* Significant code cleanup
206
+ * Move many internal functions into a global object `$yarpp` of class `YARPP`; references to the global `$yarpp_cache` should now be to global `$yarpp->cache`
207
* Created the "bypass" cache engine which is used when custom arguments are specified.
208
+ * Switch to bypass cache for demos
209
+ * Now only clears cache on post update, and only computes results for actual posts, not revisions (thanks to Andrei Mikhaylov)
210
+ * Don't compute related posts for the metabox on the edit screen; display them via ajax instead
211
* Removed the many different options entries, replacing them with a single `yarpp` option (except `yarpp_version`)
212
* Fixed issues with display options field data escaping and slashing once and for all
213
* Performance improvements on pages with "no related posts"
related-functions.php CHANGED
@@ -31,39 +31,39 @@ function yarpp_get_related($reference_ID, $args = array()) {
31
// Since YARPP 2.1, these functions receive (optionally) one array argument. See the documentation for instructions on how to customize their output.
32
33
function related_posts($args = array(),$echo=true,$reference_ID=false) {
34
- $args['type'] = array('post');
35
if ( yarpp_get_option('cross_relate') )
36
- $args['type'] = array('post', 'page');
37
return yarpp_related($reference_ID, $args, $echo);
38
}
39
40
function related_pages($args = array(),$echo=true,$reference_ID=false) {
41
- $args['type'] = array('page');
42
if ( yarpp_get_option('cross_relate') )
43
- $args['type'] = array('post', 'page');
44
return yarpp_related($reference_ID, $args, $echo);
45
}
46
47
function related_entries($args = array(),$echo=true,$reference_ID=false) {
48
- $args['type'] = array('post', 'page');
49
return yarpp_related($reference_ID, $args, $echo);
50
}
51
52
function related_posts_exist($args = array(),$reference_ID=false) {
53
- $args['type'] = array('post');
54
if ( yarpp_get_option('cross_relate') )
55
- $args['type'] = array('post', 'page');
56
return yarpp_related_exist($reference_ID, $args);
57
}
58
59
function related_pages_exist($args = array(),$reference_ID=false) {
60
- $args['type'] = array('page');
61
if ( yarpp_get_option('cross_relate') )
62
- $args['type'] = array('post', 'page');
63
return yarpp_related_exist($reference_ID, $args);
64
}
65
66
function related_entries_exist($args = array(),$reference_ID=false) {
67
- $args['type'] = array('post', 'page');
68
return yarpp_related_exist($reference_ID, $args);
69
}
31
// Since YARPP 2.1, these functions receive (optionally) one array argument. See the documentation for instructions on how to customize their output.
32
33
function related_posts($args = array(),$echo=true,$reference_ID=false) {
34
+ $args['post_type'] = array('post');
35
if ( yarpp_get_option('cross_relate') )
36
+ $args['post_type'] = array('post', 'page');
37
return yarpp_related($reference_ID, $args, $echo);
38
}
39
40
function related_pages($args = array(),$echo=true,$reference_ID=false) {
41
+ $args['post_type'] = array('page');
42
if ( yarpp_get_option('cross_relate') )
43
+ $args['post_type'] = array('post', 'page');
44
return yarpp_related($reference_ID, $args, $echo);
45
}
46
47
function related_entries($args = array(),$echo=true,$reference_ID=false) {
48
+ $args['post_type'] = array('post', 'page');
49
return yarpp_related($reference_ID, $args, $echo);
50
}
51
52
function related_posts_exist($args = array(),$reference_ID=false) {
53
+ $args['post_type'] = array('post');
54
if ( yarpp_get_option('cross_relate') )
55
+ $args['post_type'] = array('post', 'page');
56
return yarpp_related_exist($reference_ID, $args);
57
}
58
59
function related_pages_exist($args = array(),$reference_ID=false) {
60
+ $args['post_type'] = array('page');
61
if ( yarpp_get_option('cross_relate') )
62
+ $args['post_type'] = array('post', 'page');
63
return yarpp_related_exist($reference_ID, $args);
64
}
65
66
function related_entries_exist($args = array(),$reference_ID=false) {
67
+ $args['post_type'] = array('post', 'page');
68
return yarpp_related_exist($reference_ID, $args);
69
}
template-metabox.php CHANGED
@@ -1,11 +1,10 @@
1
<?php
2
global $yarpp;
3
4
- $yarpp->cache->save_post($reference_ID, false); // enforce the cache, but don't force it
5
-
6
- $keywords = $yarpp->cache->get_keywords($reference_ID);
7
8
if ($yarpp->debug) {
9
$output .= "<p>body keywords: {$keywords['body']}</p>";
10
$output .= "<p>title keywords: {$keywords['title']}</p>";
11
}
1
<?php
2
global $yarpp;
3
4
+ $yarpp->cache->enforce($reference_ID, false); // enforce the cache, but don't force it
5
6
if ($yarpp->debug) {
7
+ $keywords = $yarpp->cache->get_keywords($reference_ID);
8
$output .= "<p>body keywords: {$keywords['body']}</p>";
9
$output .= "<p>title keywords: {$keywords['title']}</p>";
10
}
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.4b9
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.4b9');
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.4b10
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.4b10');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');