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

Version Description

Download this release

Release Info

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

Code changes from version 4.0.1b2 to 4.0.1b3

Files changed (4) hide show
  1. class-core.php +45 -10
  2. readme.txt +2 -1
  3. template-thumbnails.php +6 -16
  4. yarpp.php +2 -2
class-core.php CHANGED
@@ -122,6 +122,7 @@ class YARPP {
122
'auto_display_archive' => false, // new in 4
123
'auto_display_post_types' => array( 'post' ), // new in 4, replacing auto_display
124
'pools' => array( 'message' => mt_rand(0,5) ), // new in 4
125
);
126
}
127
@@ -299,6 +300,25 @@ class YARPP {
299
return $_wp_additional_image_sizes['yarpp-thumbnail'];
300
}
301
302
/*
303
* UPGRADE ROUTINES
304
*/
@@ -324,6 +344,8 @@ class YARPP {
324
$this->upgrade_3_5_2b2();
325
if ( $last_version && version_compare('3.6b7', $last_version) > 0 )
326
$this->upgrade_3_6b7();
327
328
$this->cache->upgrade($last_version);
329
// flush cache in 3.4.1b5 as 3.4 messed up calculations.
@@ -333,7 +355,7 @@ class YARPP {
333
$this->version_info(true);
334
335
update_option('yarpp_version',YARPP_VERSION);
336
- delete_transient( 'yarpp_optin' );
337
}
338
339
function upgrade_3_4b2() {
@@ -545,6 +567,10 @@ class YARPP {
545
update_option( 'yarpp', $options );
546
}
547
548
private $post_types = null;
549
function get_post_types( $field = 'name' ) {
550
if ( is_null($this->post_types) ) {
@@ -1089,7 +1115,7 @@ class YARPP {
1089
1090
// @since 3.3: use PHP serialized format instead of JSON
1091
function version_info( $enforce_cache = false ) {
1092
- if (false === ($result = get_transient('yarpp_version_info')) || $enforce_cache) {
1093
$version = YARPP_VERSION;
1094
$remote = wp_remote_post("http://yarpp.org/checkversion.php?format=php&version={$version}");
1095
@@ -1097,46 +1123,55 @@ class YARPP {
1097
return false;
1098
1099
if ( $result = @unserialize($remote['body']) )
1100
- set_transient('yarpp_version_info', $result, 60*60*12);
1101
}
1102
return $result;
1103
}
1104
1105
// @since 4: optional data collection (default off)
1106
function optin_ping() {
1107
- if ( $this->get_timeout( 'yarpp_optin' ) )
1108
return true;
1109
1110
$remote = wp_remote_post( 'http://yarpp.org/optin/1/', array( 'body' => $this->optin_data() ) );
1111
if ( is_wp_error($remote) || !isset($remote['body']) || $remote['body'] != 'ok' ) {
1112
// try again later
1113
- $this->set_timeout( 'yarpp_optin', 60 * 60 );
1114
return false;
1115
}
1116
- $this->set_timeout( 'yarpp_optin', 60 * 60 * 24 * 7 );
1117
return true;
1118
}
1119
1120
// a version of the transient functions which is unaffected by caching plugin behavior.
1121
- // we want to store this long.
1122
- private function get_timeout( $transient ) {
1123
$transient_timeout = $transient . '_timeout';
1124
if ( intval( get_option( $transient_timeout ) ) < time() ) {
1125
delete_option( $transient_timeout );
1126
return false; // timed out
1127
}
1128
- return true; // still ok
1129
}
1130
1131
- private function set_timeout( $transient, $expiration = 0 ) {
1132
$transient_timeout = $transient . '_timeout';
1133
if ( false === get_option( $transient_timeout ) ) {
1134
add_option( $transient_timeout, time() + $expiration, '', 'no' );
1135
} else {
1136
update_option( $transient_timeout, time() + $expiration );
1137
}
1138
}
1139
1140
// 3.5.2: clean_pre is deprecated in WP 3.4, so implement here.
1141
function clean_pre( $text ) {
1142
$text = str_replace(array('<br />', '<br/>', '<br>'), array('', '', ''), $text);
122
'auto_display_archive' => false, // new in 4
123
'auto_display_post_types' => array( 'post' ), // new in 4, replacing auto_display
124
'pools' => array( 'message' => mt_rand(0,5) ), // new in 4
125
+ 'generate_thumbnails' => false, // new in 4.0.1
126
);
127
}
128
300
return $_wp_additional_image_sizes['yarpp-thumbnail'];
301
}
302
303
+ // code based on Viper's Regenerate Thumbnails plugin
304
+ function ensure_resized_post_thumbnail( $post_id, $size, $dimensions ) {
305
+ $thumbnail_id = get_post_thumbnail_id( $post_id );
306
+ $downsized = image_downsize( $thumbnail_id, $size );
307
+ if ( $dimensions['crop'] && $downsized[1] && $downsized[2] &&
308
+ ( $downsized[1] != $dimensions['width'] || $downsized[2] != $dimensions['height'] ) ) {
309
+ // we want to trigger recomputation of the thumbnail here
310
+ // (only if downsized width and height are specified, for Photon behavior)
311
+ $fullsizepath = get_attached_file( $thumbnail_id );
312
+ if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) {
313
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
314
+ $metadata = wp_generate_attachment_metadata( $thumbnail_id, $fullsizepath );
315
+ if ( !is_wp_error( $metadata ) ) {
316
+ wp_update_attachment_metadata( $thumbnail_id, $metadata );
317
+ }
318
+ }
319
+ }
320
+ }
321
+
322
/*
323
* UPGRADE ROUTINES
324
*/
344
$this->upgrade_3_5_2b2();
345
if ( $last_version && version_compare('3.6b7', $last_version) > 0 )
346
$this->upgrade_3_6b7();
347
+ if ( $last_version && version_compare('4.0.1', $last_version) > 0 )
348
+ $this->upgrade_4_0_1();
349
350
$this->cache->upgrade($last_version);
351
// flush cache in 3.4.1b5 as 3.4 messed up calculations.
355
$this->version_info(true);
356
357
update_option('yarpp_version',YARPP_VERSION);
358
+ $this->delete_transient( 'yarpp_optin' );
359
}
360
361
function upgrade_3_4b2() {
567
update_option( 'yarpp', $options );
568
}
569
570
+ function upgrade_4_0_1() {
571
+ delete_transient('yarpp_version_info');
572
+ }
573
+
574
private $post_types = null;
575
function get_post_types( $field = 'name' ) {
576
if ( is_null($this->post_types) ) {
1115
1116
// @since 3.3: use PHP serialized format instead of JSON
1117
function version_info( $enforce_cache = false ) {
1118
+ if (false === ($result = $this->get_transient('yarpp_version_info')) || $enforce_cache) {
1119
$version = YARPP_VERSION;
1120
$remote = wp_remote_post("http://yarpp.org/checkversion.php?format=php&version={$version}");
1121
1123
return false;
1124
1125
if ( $result = @unserialize($remote['body']) )
1126
+ $this->set_transient('yarpp_version_info', $result, 60 * 60 * 24);
1127
}
1128
return $result;
1129
}
1130
1131
// @since 4: optional data collection (default off)
1132
function optin_ping() {
1133
+ if ( $this->get_transient( 'yarpp_optin' ) )
1134
return true;
1135
1136
$remote = wp_remote_post( 'http://yarpp.org/optin/1/', array( 'body' => $this->optin_data() ) );
1137
if ( is_wp_error($remote) || !isset($remote['body']) || $remote['body'] != 'ok' ) {
1138
// try again later
1139
+ $this->set_transient( 'yarpp_optin', null, 60 * 60 );
1140
return false;
1141
}
1142
+ $this->set_transient( 'yarpp_optin', null, 60 * 60 * 24 * 7 );
1143
return true;
1144
}
1145
1146
// a version of the transient functions which is unaffected by caching plugin behavior.
1147
+ // we want to control the lifetime of data.
1148
+ private function get_transient( $transient ) {
1149
$transient_timeout = $transient . '_timeout';
1150
if ( intval( get_option( $transient_timeout ) ) < time() ) {
1151
delete_option( $transient_timeout );
1152
return false; // timed out
1153
}
1154
+ return get_option( $transient, true ); // still ok
1155
}
1156
1157
+ private function set_transient( $transient, $data = null, $expiration = 0 ) {
1158
$transient_timeout = $transient . '_timeout';
1159
if ( false === get_option( $transient_timeout ) ) {
1160
add_option( $transient_timeout, time() + $expiration, '', 'no' );
1161
+ if ( !is_null( $data ) )
1162
+ add_option( $transient, $data, '', 'no' );
1163
} else {
1164
update_option( $transient_timeout, time() + $expiration );
1165
+ if ( !is_null( $data ) )
1166
+ update_option( $transient, $data );
1167
}
1168
}
1169
1170
+ private function delete_transient( $transient ) {
1171
+ delete_option( $transient );
1172
+ delete_option( $transient . '_timeout' );
1173
+ }
1174
+
1175
// 3.5.2: clean_pre is deprecated in WP 3.4, so implement here.
1176
function clean_pre( $text ) {
1177
$text = str_replace(array('<br />', '<br/>', '<br>'), array('', '', ''), $text);
readme.txt CHANGED
@@ -243,9 +243,10 @@ If you are a bilingual speaker of English and another language and an avid user
243
244
= 4.0.1 =
245
* Improvements to thumbnail handling
246
- * Thumbnails of the appropriate size are generated on the fly, if they do not already exist
247
* Thumbnail size can be specified by adding `add_image_size( 'yarpp-thumbnail', $width, $height, true );` to your theme's `functions.php` file. In the future I may add some UI to the settings to also set this... feedback is requested on whether this is a good idea.
248
* Fixed a typo and simplified an item in the dynamic `styles-thumbnails.php` styles
249
* Bugfix: a class of `yarpp-related-` with a stray hyphen was sometimes being produced. Now fixed so it produces `yarpp-related`.
250
* [Bugfix](http://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache): `term_relationships` table was being joined when unnecessary
251
* [Bugfix](http://wordpress.org/support/topic/no-option-to-add-widget-title-in-theme-using-hybrid-core-framework): widget options would not display if custom templates were not available
243
244
= 4.0.1 =
245
* Improvements to thumbnail handling
246
* Thumbnail size can be specified by adding `add_image_size( 'yarpp-thumbnail', $width, $height, true );` to your theme's `functions.php` file. In the future I may add some UI to the settings to also set this... feedback is requested on whether this is a good idea.
247
+ * YARPP now registers its thumbnail size properly. To have WordPress build thumbnails of the right size, use the [Regenerate Thumbnails](http://wordpress.org/extend/plugins/regenerate-thumbnails/) plugin.
248
* Fixed a typo and simplified an item in the dynamic `styles-thumbnails.php` styles
249
+ * Thumbnails of appropriate size can be generated on the fly, if they do not already exist, by calling `yarpp_set_option('generate_thumbnails', true);`. This is turned off by default and hidden for due to performance concerns.
250
* Bugfix: a class of `yarpp-related-` with a stray hyphen was sometimes being produced. Now fixed so it produces `yarpp-related`.
251
* [Bugfix](http://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache): `term_relationships` table was being joined when unnecessary
252
* [Bugfix](http://wordpress.org/support/topic/no-option-to-add-widget-title-in-theme-using-hybrid-core-framework): widget options would not display if custom templates were not available
template-thumbnails.php CHANGED
@@ -18,7 +18,10 @@ if ( false !== ($dimensions = $this->thumbnail_size()) ) {
18
$size = '120x120'; // the ultimate default
19
$width = 120;
20
$height = 120;
21
- $dimensions = array( $width, $height, false );
22
// @todo true for crop?
23
}
24
@@ -37,21 +40,8 @@ if (have_posts()) {
37
$output .= "<a class='yarpp-thumbnail' href='" . get_permalink() . "' title='" . the_title_attribute('echo=0') . "'>" . "\n";
38
39
if ( has_post_thumbnail() ) {
40
- $thumbnail_id = get_post_thumbnail_id( get_the_ID() );
41
- $downsized = image_downsize( $thumbnail_id, $size );
42
- if ( $dimensions['crop'] && $downsized[1] && $downsized[2] &&
43
- ( $downsized[1] != $width || $downsized[2] != $height ) ) {
44
- // we want to trigger recomputation of the thumbnail here
45
- // (only if downsized width and height are specified, for Photon behavior)
46
- $fullsizepath = get_attached_file( $thumbnail_id );
47
- if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) {
48
- require_once(ABSPATH . 'wp-admin/includes/image.php');
49
- $metadata = wp_generate_attachment_metadata( $thumbnail_id, $fullsizepath );
50
- if ( !is_wp_error( $metadata ) ) {
51
- wp_update_attachment_metadata( get_post_thumbnail_id( get_the_ID() ), $metadata );
52
- }
53
- }
54
- }
55
$output .= get_the_post_thumbnail( null, $size );
56
} else {
57
$output .= '<span class="yarpp-thumbnail-default"><img src="' . esc_url($thumbnails_default) . '"/></span>';
18
$size = '120x120'; // the ultimate default
19
$width = 120;
20
$height = 120;
21
+ $dimensions = array(
22
+ 'width' => $width,
23
+ 'height' => $height,
24
+ 'crop' => false );
25
// @todo true for crop?
26
}
27
40
$output .= "<a class='yarpp-thumbnail' href='" . get_permalink() . "' title='" . the_title_attribute('echo=0') . "'>" . "\n";
41
42
if ( has_post_thumbnail() ) {
43
+ if ( $this->get_option( 'generate_thumbnails' ) )
44
+ $this->ensure_resized_post_thumbnail( get_the_ID(), $size, $dimensions );
45
$output .= get_the_post_thumbnail( null, $size );
46
} else {
47
$output .= '<span class="yarpp-thumbnail-default"><img src="' . esc_url($thumbnails_default) . '"/></span>';
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.1b2
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.1b2');
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. Now with Now with thumbnail support built-in!
6
+ Version: 4.0.1b3
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.1b3');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');