Version Description
Download this release
Release Info
Developer | mitchoyoshitaka |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 4.0.1b1 |
Comparing to | |
See all releases |
Code changes from version 4.0 to 4.0.1b1
- class-admin.php +0 -2
- class-core.php +50 -9
- readme.txt +9 -0
- styles-thumbnails.php +4 -9
- template-thumbnails.php +25 -15
- yarpp.php +3 -3
class-admin.php
CHANGED
@@ -23,8 +23,6 @@ class YARPP_Admin {
|
|
23 |
exit;
|
24 |
}
|
25 |
|
26 |
-
//add_image_size( 'yarpp-thumbnail', $width, $height, $crop );
|
27 |
-
|
28 |
add_action( 'admin_init', array( $this, 'ajax_register' ) );
|
29 |
add_action( 'admin_menu', array( $this, 'ui_register' ) );
|
30 |
add_filter( 'current_screen', array( $this, 'settings_screen' ) );
|
23 |
exit;
|
24 |
}
|
25 |
|
|
|
|
|
26 |
add_action( 'admin_init', array( $this, 'ajax_register' ) );
|
27 |
add_action( 'admin_menu', array( $this, 'ui_register' ) );
|
28 |
add_filter( 'current_screen', array( $this, 'settings_screen' ) );
|
class-core.php
CHANGED
@@ -44,6 +44,15 @@ class YARPP {
|
|
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 |
if ( isset($_REQUEST['yarpp_debug']) )
|
48 |
$this->debug = true;
|
49 |
|
@@ -283,6 +292,13 @@ class YARPP {
|
|
283 |
return $this->cache->cache_status() > 0.1 && $avg > 2;
|
284 |
}
|
285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
/*
|
287 |
* UPGRADE ROUTINES
|
288 |
*/
|
@@ -949,9 +965,12 @@ class YARPP {
|
|
949 |
'after_related', 'no_results', 'order', 'promote_yarpp',
|
950 |
'thumbnails_heading', 'thumbnails_default' );
|
951 |
|
|
|
|
|
|
|
952 |
$r = array();
|
953 |
foreach ( $options as $option ) {
|
954 |
-
if (
|
955 |
in_array( $option, $options_with_rss_variants ) )
|
956 |
$default = $this->get_option( 'rss_' . $option );
|
957 |
else
|
@@ -1024,7 +1043,7 @@ class YARPP {
|
|
1024 |
else
|
1025 |
$post_types = array( get_post_type() );
|
1026 |
|
1027 |
-
$post_types = apply_filters( 'yarpp_map_post_types', $post_types );
|
1028 |
|
1029 |
return $content . $this->display_related(null, array(
|
1030 |
'post_type' => $post_types,
|
@@ -1037,13 +1056,16 @@ class YARPP {
|
|
1037 |
return $content;
|
1038 |
|
1039 |
if ( $this->get_option('cross_relate') )
|
1040 |
-
$
|
1041 |
-
else if ( 'page' == get_post_type() )
|
1042 |
-
$type = array( 'page' );
|
1043 |
else
|
1044 |
-
$
|
|
|
|
|
1045 |
|
1046 |
-
return $content . $this->display_related(null, array(
|
|
|
|
|
|
|
1047 |
}
|
1048 |
|
1049 |
function the_excerpt_rss($content) {
|
@@ -1082,7 +1104,7 @@ class YARPP {
|
|
1082 |
|
1083 |
// @since 4: optional data collection (default off)
|
1084 |
function optin_ping() {
|
1085 |
-
if (
|
1086 |
return true;
|
1087 |
|
1088 |
$remote = wp_remote_post( 'http://yarpp.org/optin/1/', array( 'body' => $this->optin_data() ) );
|
@@ -1091,9 +1113,28 @@ class YARPP {
|
|
1091 |
return false;
|
1092 |
|
1093 |
if ( $result = $remote['body'] )
|
1094 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1095 |
}
|
1096 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1097 |
|
1098 |
// 3.5.2: clean_pre is deprecated in WP 3.4, so implement here.
|
1099 |
function clean_pre( $text ) {
|
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;
|
53 |
+
add_image_size( 'yarpp-thumbnail', $width, $height, $crop );
|
54 |
+
}
|
55 |
+
|
56 |
if ( isset($_REQUEST['yarpp_debug']) )
|
57 |
$this->debug = true;
|
58 |
|
292 |
return $this->cache->cache_status() > 0.1 && $avg > 2;
|
293 |
}
|
294 |
|
295 |
+
function thumbnail_size() {
|
296 |
+
global $_wp_additional_image_sizes;
|
297 |
+
if ( !isset($_wp_additional_image_sizes['yarpp-thumbnail']) )
|
298 |
+
return false;
|
299 |
+
return $_wp_additional_image_sizes['yarpp-thumbnail'];
|
300 |
+
}
|
301 |
+
|
302 |
/*
|
303 |
* UPGRADE ROUTINES
|
304 |
*/
|
965 |
'after_related', 'no_results', 'order', 'promote_yarpp',
|
966 |
'thumbnails_heading', 'thumbnails_default' );
|
967 |
|
968 |
+
if ( !isset($args['domain']) )
|
969 |
+
$args['domain'] = 'website';
|
970 |
+
|
971 |
$r = array();
|
972 |
foreach ( $options as $option ) {
|
973 |
+
if ( 'rss' == $args['domain'] &&
|
974 |
in_array( $option, $options_with_rss_variants ) )
|
975 |
$default = $this->get_option( 'rss_' . $option );
|
976 |
else
|
1043 |
else
|
1044 |
$post_types = array( get_post_type() );
|
1045 |
|
1046 |
+
$post_types = apply_filters( 'yarpp_map_post_types', $post_types, 'website' );
|
1047 |
|
1048 |
return $content . $this->display_related(null, array(
|
1049 |
'post_type' => $post_types,
|
1056 |
return $content;
|
1057 |
|
1058 |
if ( $this->get_option('cross_relate') )
|
1059 |
+
$post_types = $this->get_post_types();
|
|
|
|
|
1060 |
else
|
1061 |
+
$post_types = array( get_post_type() );
|
1062 |
+
|
1063 |
+
$post_types = apply_filters( 'yarpp_map_post_types', $post_types, 'rss' );
|
1064 |
|
1065 |
+
return $content . $this->display_related(null, array(
|
1066 |
+
'post_type' => $post_types,
|
1067 |
+
'domain' => 'rss'
|
1068 |
+
), false);
|
1069 |
}
|
1070 |
|
1071 |
function the_excerpt_rss($content) {
|
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() ) );
|
1113 |
return false;
|
1114 |
|
1115 |
if ( $result = $remote['body'] )
|
1116 |
+
$this->set_timeout( 'yarpp_optin', 60 * 60 * 24 * 7 );
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
// a version of the transient functions which is unaffected by caching plugin behavior.
|
1120 |
+
// we want to store this long.
|
1121 |
+
private function get_timeout( $transient ) {
|
1122 |
+
$transient_timeout = $transient . '_timeout';
|
1123 |
+
if ( get_option( $transient_timeout ) < time() ) {
|
1124 |
+
delete_option( $transient_timeout );
|
1125 |
+
return false; // timed out
|
1126 |
+
}
|
1127 |
+
return true; // still ok
|
1128 |
}
|
1129 |
|
1130 |
+
private function set_timeout( $transient, $expiration = 0 ) {
|
1131 |
+
$transient_timeout = $transient . '_timeout';
|
1132 |
+
if ( false === get_option( $transient_timeout ) ) {
|
1133 |
+
add_option( $transient_timeout, time() + $expiration, '', 'no' );
|
1134 |
+
} else {
|
1135 |
+
update_option( $transient_timeout, time() + $expiration );
|
1136 |
+
}
|
1137 |
+
}
|
1138 |
|
1139 |
// 3.5.2: clean_pre is deprecated in WP 3.4, so implement here.
|
1140 |
function clean_pre( $text ) {
|
readme.txt
CHANGED
@@ -241,6 +241,15 @@ If you are a bilingual speaker of English and another language and an avid user
|
|
241 |
|
242 |
== Changelog ==
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
= 4.0 =
|
245 |
* New thumbnail template option!
|
246 |
* No PHP required—just visit the settings page
|
241 |
|
242 |
== Changelog ==
|
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: some transients expired too soon if object caching was used
|
251 |
+
* The `yarpp_map_post_types` filter now also applies to feeds and takes an extra argument to know whether the context is `website` or `rss`.
|
252 |
+
|
253 |
= 4.0 =
|
254 |
* New thumbnail template option!
|
255 |
* No PHP required—just visit the settings page
|
styles-thumbnails.php
CHANGED
@@ -10,7 +10,7 @@ $width = 120;
|
|
10 |
if ( isset($_GET['height']) )
|
11 |
$height = (int) $_GET['height'];
|
12 |
if ( isset($_GET['width']) )
|
13 |
-
$
|
14 |
|
15 |
$margin = 5;
|
16 |
$width_with_margins = $width + 2 * $margin;
|
@@ -38,7 +38,6 @@ header( 'Content-Type: text/css' );
|
|
38 |
margin: <?php echo $margin; ?>px;
|
39 |
}
|
40 |
.yarpp-thumbnails-horizontal .yarpp-thumbnail > img, .yarpp-thumbnails-horizontal .yarpp-thumbnail-default {
|
41 |
-
margin-bottom: 0px;
|
42 |
display: block;
|
43 |
}
|
44 |
.yarpp-thumbnails-horizontal .yarpp-thumbnail-title {
|
@@ -55,11 +54,7 @@ header( 'Content-Type: text/css' );
|
|
55 |
.yarpp-thumbnail-default {
|
56 |
overflow: hidden;
|
57 |
}
|
58 |
-
.yarpp-thumbnail-default > img
|
59 |
-
height: <?php echo $height; ?>px;
|
60 |
-
|
61 |
-
}
|
62 |
-
.yarpp-thumbnail-default > img.yarpp-thumbnail-default-tall {
|
63 |
-
width: <?php echo $width; ?>px;
|
64 |
-
max-height: none;
|
65 |
}
|
10 |
if ( isset($_GET['height']) )
|
11 |
$height = (int) $_GET['height'];
|
12 |
if ( isset($_GET['width']) )
|
13 |
+
$width = (int) $_GET['width'];
|
14 |
|
15 |
$margin = 5;
|
16 |
$width_with_margins = $width + 2 * $margin;
|
38 |
margin: <?php echo $margin; ?>px;
|
39 |
}
|
40 |
.yarpp-thumbnails-horizontal .yarpp-thumbnail > img, .yarpp-thumbnails-horizontal .yarpp-thumbnail-default {
|
|
|
41 |
display: block;
|
42 |
}
|
43 |
.yarpp-thumbnails-horizontal .yarpp-thumbnail-title {
|
54 |
.yarpp-thumbnail-default {
|
55 |
overflow: hidden;
|
56 |
}
|
57 |
+
.yarpp-thumbnail-default > img {
|
58 |
+
min-height: <?php echo $height; ?>px;
|
59 |
+
min-width: <?php echo $width; ?>px;
|
|
|
|
|
|
|
|
|
60 |
}
|
template-thumbnails.php
CHANGED
@@ -10,22 +10,16 @@
|
|
10 |
|
11 |
$options = array( 'thumbnails_heading', 'thumbnails_default', 'no_results' );
|
12 |
extract( $this->parse_args( $args, $options ) );
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
// if ( isset($_wp_additional_image_sizes['yarpp-thumbnail']) )
|
18 |
-
// $size = 'yarpp-thumbnail';
|
19 |
-
// elseif ( isset($_wp_additional_image_sizes['post-thumbnail']) )
|
20 |
-
// $size = 'post-thumbnail';
|
21 |
-
|
22 |
-
if ( isset($size) ) {
|
23 |
-
$width = (int) $_wp_additional_image_sizes[$size]['width'];
|
24 |
-
$height = (int) $_wp_additional_image_sizes[$size]['height'];
|
25 |
} else {
|
26 |
$size = '120x120'; // the ultimate default
|
27 |
$width = 120;
|
28 |
$height = 120;
|
|
|
|
|
29 |
}
|
30 |
|
31 |
// a little easter egg: if the default image URL is left blank,
|
@@ -42,11 +36,27 @@ if (have_posts()) {
|
|
42 |
|
43 |
$output .= "<a class='yarpp-thumbnail' href='" . get_permalink() . "' title='" . the_title_attribute('echo=0') . "'>" . "\n";
|
44 |
|
45 |
-
if ( has_post_thumbnail() )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
$output .= get_the_post_thumbnail( null, $size );
|
47 |
-
else
|
48 |
-
$output .= '<span class="yarpp-thumbnail-default"><img
|
49 |
// assume default images (header images) are wider than they are tall
|
|
|
50 |
|
51 |
$output .= '<span class="yarpp-thumbnail-title">' . get_the_title() . '</span>';
|
52 |
$output .= '</a>' . "\n";
|
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( $width, $height, false );
|
22 |
+
// @todo true for crop?
|
23 |
}
|
24 |
|
25 |
// a little easter egg: if the default image URL is left blank,
|
36 |
|
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>';
|
58 |
// assume default images (header images) are wider than they are tall
|
59 |
+
}
|
60 |
|
61 |
$output .= '<span class="yarpp-thumbnail-title">' . get_the_title() . '</span>';
|
62 |
$output .= '</a>' . "\n";
|
yarpp.php
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
/*
|
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
|
6 |
-
Version: 4.0
|
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');
|
13 |
define('YARPP_DIR', dirname(__FILE__));
|
14 |
define('YARPP_NO_RELATED', ':(');
|
15 |
define('YARPP_RELATED', ':)');
|
2 |
/*
|
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.1b1
|
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.1b1');
|
13 |
define('YARPP_DIR', dirname(__FILE__));
|
14 |
define('YARPP_NO_RELATED', ':(');
|
15 |
define('YARPP_RELATED', ':)');
|