Yet Another Related Posts Plugin (YARPP) - Version 4.0.3b2

Version Description

Download this release

Release Info

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

Code changes from version 4.0.3b1 to 4.0.3b2

Files changed (4) hide show
  1. class-core.php +49 -6
  2. readme.txt +1 -0
  3. template-thumbnails.php +5 -17
  4. yarpp.php +2 -2
class-core.php CHANGED
@@ -43,10 +43,11 @@ class YARPP {
43
  add_filter( 'the_content', array( $this, 'the_content' ), 1200 );
44
  add_filter( 'the_content_feed', array( $this, 'the_content_feed' ), 600 );
45
  add_filter( 'the_excerpt_rss', array( $this, 'the_excerpt_rss' ), 600 );
 
46
 
47
  // register yarpp-thumbnail size, if theme has not already
48
  // @todo: make these UI-configurable?
49
- if ( false === $this->thumbnail_size() ) {
50
  $width = 120;
51
  $height = 120;
52
  $crop = true;
@@ -300,17 +301,55 @@ class YARPP {
300
  return defined('YARPP_GENERATE_THUMBNAILS') && YARPP_GENERATE_THUMBNAILS;
301
  }
302
 
303
- function thumbnail_size() {
 
 
 
 
 
 
 
304
  global $_wp_additional_image_sizes;
305
  if ( !isset($_wp_additional_image_sizes['yarpp-thumbnail']) )
306
- return false;
307
- return $_wp_additional_image_sizes['yarpp-thumbnail'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
309
 
310
  // code based on Viper's Regenerate Thumbnails plugin
311
- function ensure_resized_post_thumbnail( $post_id, $size, $dimensions ) {
 
312
  $thumbnail_id = get_post_thumbnail_id( $post_id );
313
- $downsized = image_downsize( $thumbnail_id, $size );
314
  if ( $dimensions['crop'] && $downsized[1] && $downsized[2] &&
315
  ( $downsized[1] != $dimensions['width'] || $downsized[2] != $dimensions['height'] ) ) {
316
  // we want to trigger recomputation of the thumbnail here
@@ -606,6 +645,10 @@ class YARPP {
606
  delete_transient('yarpp_version_info');
607
  }
608
 
 
 
 
 
609
  private $post_types = null;
610
  function get_post_types( $field = 'name' ) {
611
  if ( is_null($this->post_types) ) {
43
  add_filter( 'the_content', array( $this, 'the_content' ), 1200 );
44
  add_filter( 'the_content_feed', array( $this, 'the_content_feed' ), 600 );
45
  add_filter( 'the_excerpt_rss', array( $this, 'the_excerpt_rss' ), 600 );
46
+ add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_thumbnails' ) );
47
 
48
  // register yarpp-thumbnail size, if theme has not already
49
  // @todo: make these UI-configurable?
50
+ if ( !($dimensions = $this->thumbnail_dimensions()) || isset($dimensions['_default']) ) {
51
  $width = 120;
52
  $height = 120;
53
  $crop = true;
301
  return defined('YARPP_GENERATE_THUMBNAILS') && YARPP_GENERATE_THUMBNAILS;
302
  }
303
 
304
+ private $default_dimensions = array(
305
+ 'width' => 120,
306
+ 'height' => 120,
307
+ 'crop' => false, // @todo true for crop?
308
+ 'size' => '120x120',
309
+ '_default' => true
310
+ );
311
+ function thumbnail_dimensions() {
312
  global $_wp_additional_image_sizes;
313
  if ( !isset($_wp_additional_image_sizes['yarpp-thumbnail']) )
314
+ return $this->default_dimensions;
315
+
316
+ $dimensions = $_wp_additional_image_sizes['yarpp-thumbnail'];
317
+ $dimensions['size'] = 'yarpp-thumbnail';
318
+
319
+ // ensure YARPP dimensions format:
320
+ $dimensions['width'] = (int) $dimensions['width'];
321
+ $dimensions['height'] = (int) $dimensions['height'];
322
+ return $dimensions;
323
+ }
324
+
325
+ function maybe_enqueue_thumbnails() {
326
+ if ( is_feed() )
327
+ return;
328
+
329
+ $auto_display_post_types = $this->get_option( 'auto_display_post_types' );
330
+
331
+ // if it's not an auto-display post type, return
332
+ if ( !in_array( get_post_type(), $auto_display_post_types ) )
333
+ return;
334
+
335
+ if ( !is_singular() && !(
336
+ $this->get_option('auto_display_archive') &&
337
+ ( is_archive() || is_home() )
338
+ ) )
339
+ return;
340
+
341
+ $this->enqueue_thumbnails( $this->thumbnail_dimensions() );
342
+ }
343
+
344
+ function enqueue_thumbnails( $dimensions ) {
345
+ wp_enqueue_style( "yarpp-thumbnails-" . $dimensions['size'], plugins_url( 'styles-thumbnails.php?' . http_build_query( array( 'width' => $dimensions['width'], 'height' => $dimensions['height'] ) ), __FILE__ ), array(), YARPP_VERSION, 'all' );
346
  }
347
 
348
  // code based on Viper's Regenerate Thumbnails plugin
349
+ // $dimensions must be an array with size, crop, height, width attributes
350
+ function ensure_resized_post_thumbnail( $post_id, $dimensions ) {
351
  $thumbnail_id = get_post_thumbnail_id( $post_id );
352
+ $downsized = image_downsize( $thumbnail_id, $dimensions['size'] );
353
  if ( $dimensions['crop'] && $downsized[1] && $downsized[2] &&
354
  ( $downsized[1] != $dimensions['width'] || $downsized[2] != $dimensions['height'] ) ) {
355
  // we want to trigger recomputation of the thumbnail here
645
  delete_transient('yarpp_version_info');
646
  }
647
 
648
+ /*
649
+ * UTILITIES
650
+ */
651
+
652
  private $post_types = null;
653
  function get_post_types( $field = 'name' ) {
654
  if ( is_null($this->post_types) ) {
readme.txt CHANGED
@@ -259,6 +259,7 @@ If you are a bilingual speaker of English and another language and an avid user
259
 
260
  = 4.0.3 =
261
  * Bugfix: on sites where custom templates are not available, the "thumbnails" display option would get reset when visiting the YARPP settings page
 
262
  * Updated Polish localization
263
 
264
  = 4.0.2 =
259
 
260
  = 4.0.3 =
261
  * Bugfix: on sites where custom templates are not available, the "thumbnails" display option would get reset when visiting the YARPP settings page
262
+ * [Bugfix](http://wordpress.org/support/topic/yarpp-css-is-delayed-or-doesnt-load): the CSS for YARPP's thumbnails display would load at the foot of the page, and therefore would cause some style-flashing. This is fixed for automatic includes, but not for widgets or manual calls.
263
  * Updated Polish localization
264
 
265
  = 4.0.2 =
template-thumbnails.php CHANGED
@@ -10,26 +10,14 @@
10
 
11
  $options = array( 'thumbnails_heading', 'thumbnails_default', 'no_results' );
12
  extract( $this->parse_args( $args, $options ) );
13
- if ( false !== ($dimensions = $this->thumbnail_size()) ) {
14
- $width = (int) $dimensions['width'];
15
- $height = (int) $dimensions['height'];
16
- $size = 'yarpp-thumbnail';
17
- } else {
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
 
28
  // a little easter egg: if the default image URL is left blank,
29
  // default to the theme's header image. (hopefully it has one)
30
  if ( empty($thumbnails_default) )
31
  $thumbnails_default = get_header_image();
32
 
 
 
33
  $output .= '<h3>' . $thumbnails_heading . '</h3>' . "\n";
34
 
35
  if (have_posts()) {
@@ -42,8 +30,8 @@ if (have_posts()) {
42
  $post_thumbnail_html = '';
43
  if ( has_post_thumbnail() ) {
44
  if ( $this->diagnostic_generate_thumbnails() )
45
- $this->ensure_resized_post_thumbnail( get_the_ID(), $size, $dimensions );
46
- $post_thumbnail_html = get_the_post_thumbnail( null, $size );
47
  }
48
 
49
  if ( trim($post_thumbnail_html) != '' )
@@ -60,4 +48,4 @@ if (have_posts()) {
60
  $output .= $no_results;
61
  }
62
 
63
- wp_enqueue_style( "yarpp-thumbnails-$size", plugins_url( 'styles-thumbnails.php?' . http_build_query( compact('height','width') ), __FILE__ ), array(), YARPP_VERSION, 'all' );
10
 
11
  $options = array( 'thumbnails_heading', 'thumbnails_default', 'no_results' );
12
  extract( $this->parse_args( $args, $options ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  // a little easter egg: if the default image URL is left blank,
15
  // default to the theme's header image. (hopefully it has one)
16
  if ( empty($thumbnails_default) )
17
  $thumbnails_default = get_header_image();
18
 
19
+ $dimensions = $this->thumbnail_dimensions();
20
+
21
  $output .= '<h3>' . $thumbnails_heading . '</h3>' . "\n";
22
 
23
  if (have_posts()) {
30
  $post_thumbnail_html = '';
31
  if ( has_post_thumbnail() ) {
32
  if ( $this->diagnostic_generate_thumbnails() )
33
+ $this->ensure_resized_post_thumbnail( get_the_ID(), $dimensions );
34
+ $post_thumbnail_html = get_the_post_thumbnail( null, $dimensions['size'] );
35
  }
36
 
37
  if ( trim($post_thumbnail_html) != '' )
48
  $output .= $no_results;
49
  }
50
 
51
+ $this->enqueue_thumbnails( $dimensions );
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.3b1
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.3b1');
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.3b2
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.3b2');
13
  define('YARPP_DIR', dirname(__FILE__));
14
  define('YARPP_NO_RELATED', ':(');
15
  define('YARPP_RELATED', ':)');