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

Version Description

Download this release

Release Info

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

Code changes from version 4.0.6b2 to 4.0.6b3

Files changed (6) hide show
  1. class-cache.php +2 -2
  2. class-core.php +70 -16
  3. options-meta-boxes.php +4 -4
  4. options.php +23 -29
  5. readme.txt +2 -0
  6. yarpp.php +4 -4
class-cache.php CHANGED
@@ -162,9 +162,9 @@ abstract class YARPP_Cache {
162
163
$newsql .= 'ROUND(0';
164
165
- if ((int) @$weight['body'])
166
$newsql .= " + (MATCH (post_content) AGAINST ('".$wpdb->escape($keywords['body'])."')) * ". absint($weight['body']);
167
- if ((int) @$weight['title'])
168
$newsql .= " + (MATCH (post_title) AGAINST ('".$wpdb->escape($keywords['title'])."')) * ". absint($weight['title']);
169
170
// Build tax criteria query parts based on the weights
162
163
$newsql .= 'ROUND(0';
164
165
+ if ( isset($weight['body']) && (int) $weight['body'] )
166
$newsql .= " + (MATCH (post_content) AGAINST ('".$wpdb->escape($keywords['body'])."')) * ". absint($weight['body']);
167
+ if ( isset($weight['body']) && (int) $weight['title'] )
168
$newsql .= " + (MATCH (post_title) AGAINST ('".$wpdb->escape($keywords['title'])."')) * ". absint($weight['title']);
169
170
// Build tax criteria query parts based on the weights
class-core.php CHANGED
@@ -12,8 +12,6 @@ class YARPP {
12
public $admin;
13
private $storage_class;
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
public $default_hidden_metaboxes = array( 'yarpp_pool', 'yarpp_relatedness' );
@@ -56,6 +54,9 @@ class YARPP {
56
57
if ( isset($_REQUEST['yarpp_debug']) )
58
$this->debug = true;
59
60
// new in 3.4: only load UI if we're in the admin
61
if ( is_admin() ) {
@@ -197,14 +198,17 @@ class YARPP {
197
if ( $this->cache->is_enabled() === false )
198
return false;
199
200
- return $this->diagnostic_fulltext_indices();
201
}
202
203
// @since 3.5.2: function to enforce YARPP setup
204
- // if new install, activate; else upgrade
205
function enforce() {
206
- if ( !get_option('yarpp_version') )
207
- $this->activate();
208
else
209
$this->upgrade();
210
@@ -215,9 +219,9 @@ class YARPP {
215
function activate() {
216
global $wpdb;
217
218
- if ( !$this->diagnostic_fulltext_indices() ) {
219
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
220
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
221
}
222
223
if ( $this->cache->is_enabled() === false ) {
@@ -231,6 +235,7 @@ class YARPP {
231
232
if ( !get_option('yarpp_version') ) {
233
// new install
234
add_option( 'yarpp_version', YARPP_VERSION );
235
$this->version_info(true);
236
} else {
@@ -258,6 +263,54 @@ class YARPP {
258
return 'UNKNOWN';
259
}
260
261
function diagnostic_fulltext_indices() {
262
global $wpdb;
263
$wpdb->get_results("show index from $wpdb->posts where Key_name = 'yarpp_title' or Key_name = 'yarpp_content'");
@@ -718,7 +771,7 @@ class YARPP {
718
}
719
720
public function optin_data() {
721
- global $wpdb, $yarpp;
722
723
$comments = wp_count_comments();
724
$users = count_users();
@@ -751,6 +804,7 @@ class YARPP {
751
),
752
'diagnostics' => array(
753
'myisam_posts' => $this->diagnostic_myisam_posts(),
754
'fulltext_indices' => $this->diagnostic_fulltext_indices(),
755
'hidden_metaboxes' => $this->diagnostic_hidden_metaboxes(),
756
'post_thumbnails' => $this->diagnostic_post_thumbnails(),
@@ -780,20 +834,20 @@ class YARPP {
780
781
$changed = array();
782
foreach ( $check_changed as $key ) {
783
- if ( $yarpp->default_options[$key] != $settings[$key] )
784
$changed[] = $key;
785
}
786
foreach ( array( 'before_related', 'rss_before_related' ) as $key ) {
787
if ( $settings[$key] != '<p>'.__('Related posts:','yarpp').'</p><ol>' &&
788
- $settings[$key] != $yarpp->default_options[$key] )
789
$changed[] = $key;
790
}
791
$data['yarpp']['changed_settings'] = implode( '|', $changed );
792
793
- if ( method_exists( $yarpp->cache, 'cache_status' ) )
794
- $data['yarpp']['cache_status'] = $yarpp->cache->cache_status();
795
- if ( method_exists( $yarpp->cache, 'stats' ) ) {
796
- $stats = $yarpp->cache->stats();
797
$flattened = array();
798
foreach ( $stats as $key => $value )
799
$flattened[] = "$key:$value";
12
public $admin;
13
private $storage_class;
14
15
// 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.
16
public $default_options = array();
17
public $default_hidden_metaboxes = array( 'yarpp_pool', 'yarpp_relatedness' );
54
55
if ( isset($_REQUEST['yarpp_debug']) )
56
$this->debug = true;
57
+
58
+ if ( !get_option('yarpp_version') )
59
+ update_option( 'yarpp_activated', true );
60
61
// new in 3.4: only load UI if we're in the admin
62
if ( is_admin() ) {
198
if ( $this->cache->is_enabled() === false )
199
return false;
200
201
+ if ( !$this->diagnostic_fulltext_disabled() )
202
+ return $this->diagnostic_fulltext_indices();
203
+
204
+ return true;
205
}
206
207
// @since 3.5.2: function to enforce YARPP setup
208
+ // if not ready, activate; else upgrade
209
function enforce() {
210
+ if ( !$this->enabled() )
211
+ $this->activate(); // activate calls upgrade later, so it's covered.
212
else
213
$this->upgrade();
214
219
function activate() {
220
global $wpdb;
221
222
+ // if it's not known to be disabled, but the indexes aren't there:
223
+ if ( !$this->diagnostic_fulltext_disabled() && !$this->diagnostic_fulltext_indices() ) {
224
+ $this->enable_fulltext();
225
}
226
227
if ( $this->cache->is_enabled() === false ) {
235
236
if ( !get_option('yarpp_version') ) {
237
// new install
238
+
239
add_option( 'yarpp_version', YARPP_VERSION );
240
$this->version_info(true);
241
} else {
263
return 'UNKNOWN';
264
}
265
266
+ function diagnostic_fulltext_disabled() {
267
+ return get_option( 'yarpp_fulltext_disabled', false );
268
+ }
269
+
270
+ function enable_fulltext( $override_myisam = false ) {
271
+ global $wpdb;
272
+
273
+ // todo: check the myisam_override option instead.
274
+ if ( !$override_myisam ) {
275
+ $table_type = $this->diagnostic_myisam_posts();
276
+ if ( $table_type !== true ) {
277
+ $this->disable_fulltext();
278
+ return;
279
+ }
280
+ }
281
+
282
+ // temporarily ensure that errors are not displayed:
283
+ $previous_value = $wpdb->hide_errors();
284
+
285
+ $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
286
+ if ( !empty($wpdb->last_error) )
287
+ $this->disable_fulltext();
288
+
289
+ $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
290
+ if ( !empty($wpdb->last_error) )
291
+ $this->disable_fulltext();
292
+
293
+ // restore previous setting
294
+ $wpdb->show_errors( $previous_value );
295
+ }
296
+
297
+ function disable_fulltext() {
298
+ if ( get_option( 'yarpp_fulltext_disabled', false ) == true )
299
+ return;
300
+
301
+ // rm title and body weights:
302
+ $weight = $this->get_option('weight');
303
+ unset($weight['title']);
304
+ unset($weight['body']);
305
+ $this->set_option(array('weight' => $weight));
306
+
307
+ // cut threshold by half:
308
+ $threshold = (float) $this->get_option('threshold');
309
+ $this->set_option(array('threshold' => round($threshold / 2) ));
310
+
311
+ update_option( 'yarpp_fulltext_disabled', true );
312
+ }
313
+
314
function diagnostic_fulltext_indices() {
315
global $wpdb;
316
$wpdb->get_results("show index from $wpdb->posts where Key_name = 'yarpp_title' or Key_name = 'yarpp_content'");
771
}
772
773
public function optin_data() {
774
+ global $wpdb;
775
776
$comments = wp_count_comments();
777
$users = count_users();
804
),
805
'diagnostics' => array(
806
'myisam_posts' => $this->diagnostic_myisam_posts(),
807
+ 'fulltext_disabled' => $this->diagnostic_fulltext_disabled(),
808
'fulltext_indices' => $this->diagnostic_fulltext_indices(),
809
'hidden_metaboxes' => $this->diagnostic_hidden_metaboxes(),
810
'post_thumbnails' => $this->diagnostic_post_thumbnails(),
834
835
$changed = array();
836
foreach ( $check_changed as $key ) {
837
+ if ( $this->default_options[$key] != $settings[$key] )
838
$changed[] = $key;
839
}
840
foreach ( array( 'before_related', 'rss_before_related' ) as $key ) {
841
if ( $settings[$key] != '<p>'.__('Related posts:','yarpp').'</p><ol>' &&
842
+ $settings[$key] != $this->default_options[$key] )
843
$changed[] = $key;
844
}
845
$data['yarpp']['changed_settings'] = implode( '|', $changed );
846
847
+ if ( method_exists( $this->cache, 'cache_status' ) )
848
+ $data['yarpp']['cache_status'] = $this->cache->cache_status();
849
+ if ( method_exists( $this->cache, 'stats' ) ) {
850
+ $stats = $this->cache->stats();
851
$flattened = array();
852
foreach ( $stats as $key => $value )
853
$flattened[] = "$key:$value";
options-meta-boxes.php CHANGED
@@ -116,13 +116,13 @@ class YARPP_Meta_Box {
116
$weight = (int) yarpp_get_option( "weight[$option]" );
117
118
// both require MyISAM fulltext indexing:
119
- $myisam = !$yarpp->myisam ? ' readonly="readonly" disabled="disabled"' : '';
120
121
echo "<div class='yarpp_form_row yarpp_form_select'><div class='yarpp_form_label'>$desc</div><div>";
122
echo "<select name='weight[$option]'>";
123
- echo "<option $myisam value='no'". ( !$weight ? ' selected="selected"': '' )." >".__( "do not consider", 'yarpp' )."</option>";
124
- echo "<option $myisam value='consider'". ( ( $weight == 1 ) ? ' selected="selected"': '' )." > ".__( "consider", 'yarpp' )."</option>";
125
- echo "<option $myisam value='consider_extra'". ( ( $weight > 1 ) ? ' selected="selected"': '' )." > ".__( "consider with extra weight", 'yarpp' )."</option>";
126
echo "</select></div></div>";
127
}
128
116
$weight = (int) yarpp_get_option( "weight[$option]" );
117
118
// both require MyISAM fulltext indexing:
119
+ $fulltext = $yarpp->diagnostic_fulltext_disabled() ? ' readonly="readonly" disabled="disabled"' : '';
120
121
echo "<div class='yarpp_form_row yarpp_form_select'><div class='yarpp_form_label'>$desc</div><div>";
122
echo "<select name='weight[$option]'>";
123
+ echo "<option $fulltext value='no'". ( !$weight ? ' selected="selected"': '' )." >".__( "do not consider", 'yarpp' )."</option>";
124
+ echo "<option $fulltext value='consider'". ( ( $weight == 1 ) ? ' selected="selected"': '' )." > ".__( "consider", 'yarpp' )."</option>";
125
+ echo "<option $fulltext value='consider_extra'". ( ( $weight > 1 ) ? ' selected="selected"': '' )." > ".__( "consider with extra weight", 'yarpp' )."</option>";
126
echo "</select></div></div>";
127
}
128
options.php CHANGED
@@ -43,43 +43,37 @@ if ( current_user_can('update_plugins' ) ) {
43
}
44
45
if (isset($_POST['myisam_override'])) {
46
- yarpp_set_option('myisam_override',1);
47
echo "<div class='updated'>"
48
.__("The MyISAM check has been overridden. You may now use the \"consider titles\" and \"consider bodies\" relatedness criteria.",'yarpp')
49
."</div>";
50
}
51
52
- if ( !yarpp_get_option('myisam_override') ) {
53
- $yarpp_check_return = $yarpp->diagnostic_myisam_posts();
54
- if ($yarpp_check_return !== true) { // if it's not *exactly* true
55
- echo "<div class='updated'>"
56
- .sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.",'yarpp'), $wpdb->posts, $yarpp_check_return)
57
- ."<br />"
58
- .sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.",'yarpp'), $wpdb->posts, $wpdb->posts)
59
- ."<br />"
60
- .sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'), $wpdb->posts)
61
- ."<br />"
62
- ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
63
- .__("Trust me. Let me use MyISAM features.",'yarpp')
64
- ."'></input></form>"
65
- ."</div>";
66
-
67
- $weight = yarpp_get_option('weight');
68
- unset($weight['title']);
69
- unset($weight['body']);
70
- yarpp_set_option(array('weight' => $weight));
71
- $yarpp->myisam = false;
72
- }
73
}
74
75
- if ( $yarpp->myisam && !$yarpp->enabled() ) {
76
echo '<div class="updated">';
77
- if ( $yarpp->activate() ) {
78
- _e('The YARPP database had an error but has been fixed.','yarpp');
79
- } else {
80
- _e('The YARPP database has an error which could not be fixed.','yarpp');
81
- printf(__('Please try <a href="%s" target="_blank">manual SQL setup</a>.','yarpp'), 'http://mitcho.com/code/yarpp/sql.php?prefix='.urlencode($wpdb->prefix));
82
- }
83
echo '</div>';
84
}
85
43
}
44
45
if (isset($_POST['myisam_override'])) {
46
+ yarpp_set_option( 'myisam_override', 1 );
47
echo "<div class='updated'>"
48
.__("The MyISAM check has been overridden. You may now use the \"consider titles\" and \"consider bodies\" relatedness criteria.",'yarpp')
49
."</div>";
50
+
51
+ $yarpp->enable_fulltext( true );
52
}
53
54
+ $table_type = $yarpp->diagnostic_myisam_posts();
55
+ if ( $table_type !== true )
56
+ $yarpp->disable_fulltext();
57
+
58
+ if ( !yarpp_get_option('myisam_override') && $yarpp->diagnostic_fulltext_disabled() ) {
59
+ echo "<div class='updated'>"
60
+ .sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.",'yarpp'), $wpdb->posts, $table_type)
61
+ ."<br />"
62
+ .sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.",'yarpp'), $wpdb->posts, $wpdb->posts)
63
+ ."<br />"
64
+ .sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'), $wpdb->posts)
65
+ ."<br />"
66
+ ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
67
+ .__("Trust me. Let me use MyISAM features.",'yarpp')
68
+ ."'></input></form>"
69
+ ."</div>";
70
}
71
72
+ if ( !$yarpp->enabled() && !$yarpp->activate() ) {
73
echo '<div class="updated">';
74
+ _e('The YARPP database has an error which could not be fixed.','yarpp');
75
+ echo ' ';
76
+ printf(__('Please try <a href="%s" target="_blank">manual SQL setup</a>.','yarpp'), 'http://mitcho.com/code/yarpp/sql.php?prefix='.urlencode($wpdb->prefix));
77
echo '</div>';
78
}
79
readme.txt CHANGED
@@ -256,6 +256,8 @@ If you are a bilingual speaker of English and another language and an avid user
256
= 4.0.6 =
257
* YARPP's automatic display will not run on posts which include the HTML comment `<!--noyarpp-->` [by request](https://wordpress.org/support/topic/disabling-yarrp-on-specific-pages).
258
* Bundled `yarpp-template-wpml.php` is now called `yarpp-template-multilingual.php`, following [discussion with the author of the Polylang plugin](https://wordpress.org/support/topic/better-integration-of-yarpp-and-polylang).
259
* Localizations
260
* Added Estonian (`est_EST`) by [JOURNAL](http://journal24.info/)
261
* Added Gujrati (`gu_IN`) by [Vikas Arora](http://www.wiznicworld.com/)
256
= 4.0.6 =
257
* YARPP's automatic display will not run on posts which include the HTML comment `<!--noyarpp-->` [by request](https://wordpress.org/support/topic/disabling-yarrp-on-specific-pages).
258
* Bundled `yarpp-template-wpml.php` is now called `yarpp-template-multilingual.php`, following [discussion with the author of the Polylang plugin](https://wordpress.org/support/topic/better-integration-of-yarpp-and-polylang).
259
+ * More robust activation handling, particularly when network-activated.
260
+ * Improved handling of exceptions, for example when fulltext indexes cannot be created or non-MyISAM tables are used.
261
* Localizations
262
* Added Estonian (`est_EST`) by [JOURNAL](http://journal24.info/)
263
* Added Gujrati (`gu_IN`) by [Vikas Arora](http://www.wiznicworld.com/)
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. Now with Now with thumbnail support built-in!
6
- Version: 4.0.6b2
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', '4.0.6b2');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
@@ -54,7 +54,7 @@ function yarpp_get_option($option = null) {
54
return $yarpp->get_option($option);
55
}
56
57
- function yarpp_plugin_activate() {
58
update_option( 'yarpp_activated', true );
59
}
60
- add_action( 'activate_' . plugin_basename(__FILE__), 'yarpp_plugin_activate' );
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. Now with Now with thumbnail support built-in!
6
+ Version: 4.0.6b3
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', '4.0.6b3');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
54
return $yarpp->get_option($option);
55
}
56
57
+ function yarpp_plugin_activate( $network_wide ) {
58
update_option( 'yarpp_activated', true );
59
}
60
+ add_action( 'activate_' . plugin_basename(__FILE__), 'yarpp_plugin_activate', 10, 1 );