Related Posts Thumbnails Plugin for WordPress - Version 1.1.1

Version Description

  • removed PHP warning on settings page somebody may experience
  • full HTML support in top text field
Download this release

Release Info

Developer marynixie
Plugin Icon 128x128 Related Posts Thumbnails Plugin for WordPress
Version 1.1.1
Comparing to
See all releases

Code changes from version 1.1 to 1.1.1

Files changed (2) hide show
  1. readme.txt +8 -1
  2. related-posts-thumbnails.php +73 -56
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wordpress.shaldybina.com/donate
4
  Tags: related, posts, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 2.9.2
7
- Stable tag: 1.1
8
 
9
  Customizable plugin, that nicely displays related posts thumbnails under the post.
10
 
@@ -55,6 +55,10 @@ If there are no images of the specified size in the post, or file does not exist
55
 
56
  == Changelog ==
57
 
 
 
 
 
58
  = 1.1 =
59
  * removed PHP warnings for getimagesize and file if wrong header was received
60
  * fixed Categories and Tags confusion (when you selected Categories relation was based on Tags and vice versa)
@@ -66,6 +70,9 @@ If there are no images of the specified size in the post, or file does not exist
66
 
67
  == Upgrade Notice ==
68
 
 
 
 
69
  = 1.1 =
70
  This version includes categories/tags confusion in settings, elimination of warnings in case of wrong headers, new features - Categories and custom field support.
71
 
4
  Tags: related, posts, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 2.9.2
7
+ Stable tag: 1.1.1
8
 
9
  Customizable plugin, that nicely displays related posts thumbnails under the post.
10
 
55
 
56
  == Changelog ==
57
 
58
+ = 1.1.1 =
59
+ * removed PHP warning on settings page somebody may experience
60
+ * full HTML support in top text field
61
+
62
  = 1.1 =
63
  * removed PHP warnings for getimagesize and file if wrong header was received
64
  * fixed Categories and Tags confusion (when you selected Categories relation was based on Tags and vice versa)
70
 
71
  == Upgrade Notice ==
72
 
73
+ = 1.1.1 =
74
+ This version includes elimination of warning on settings page some may experience, plus full html support in top text field.
75
+
76
  = 1.1 =
77
  This version includes categories/tags confusion in settings, elimination of warnings in case of wrong headers, new features - Categories and custom field support.
78
 
related-posts-thumbnails.php CHANGED
@@ -2,7 +2,7 @@
2
  Plugin Name: Related Posts Thumbnails
3
  Plugin URI: http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
4
  Description: Showing related posts thumbnails under the post.
5
- Version: 1.1
6
  Author: Maria Shaldybina
7
  Author URI: http://shaldybina.com/
8
  */
@@ -49,7 +49,7 @@ class RelatedPostsThumbnails {
49
 
50
  function relpoststh_show( $content ) { // Displaying related posts on the site
51
  if ( $this->is_relpoststh_show() ) {
52
- $content .= get_option( 'relpoststh_top_text', $this->top_text );
53
  $content .= $this->relpoststh_get();
54
  }
55
  return $content;
@@ -59,6 +59,9 @@ class RelatedPostsThumbnails {
59
  $id = get_the_ID();
60
  $relation = get_option( 'relpoststh_relation', $this->relation );
61
  $posts_number = get_option( 'relpoststh_number', $this->number );
 
 
 
62
  $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
63
  $text_length = get_option( 'relpoststh_textlength', $this->text_length );
64
  $thsource = get_option( 'relpoststh_thsource', $this->thsource );
@@ -82,12 +85,18 @@ class RelatedPostsThumbnails {
82
  $query_args['category__in'] = array(0); // if no categories were specified return nothing
83
  }
84
  }
85
- $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
 
86
  }
87
 
88
  if ( $relation == 'tags' || $relation == 'both' ) {
89
  $query_args = array( 'tag__in' => wp_get_object_terms( $id, array( 'post_tag' ), array( 'fields' => 'ids' ) ) );
90
- $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
 
 
 
 
 
91
  }
92
 
93
  if ( $relation == 'both' ) {
@@ -98,6 +107,7 @@ class RelatedPostsThumbnails {
98
  $posts = array_slice( $posts_unique, 0, $posts_number );
99
  }
100
 
 
101
  if ( $thsource == 'custom-field' ) {
102
  $width = get_option( 'relpoststh_customwidth', $this->custom_width );
103
  $height = get_option( 'relpoststh_customheight', $this->custom_height );
@@ -109,61 +119,67 @@ class RelatedPostsThumbnails {
109
  }
110
  elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
111
  global $_wp_additional_image_sizes;
112
- $width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
113
- $height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
114
- }
115
- else { // theme is not supporting but settings were not changed
116
- $poststhname = 'thumbnail';
117
- $width = get_option( "thumbnail_size_w" );
118
- $height = get_option( "thumbnail_size_h" );
119
  }
120
  }
 
 
 
 
 
 
 
 
 
 
121
 
122
- if ( count( $posts ) ) { // rendering related posts HTML
123
- $output = '<div style="clear: both"></div><div style="border: 0pt none ; margin: 0pt; padding: 0pt;">';
124
- foreach( $posts as $post ) {
125
- $image = '';
126
- $url = '';
127
- if ( $thsource == 'custom-field' ) {
128
- $url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
 
 
 
 
 
 
 
 
129
  }
130
- else {
131
- if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { // using built in Wordpress feature
132
- $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
133
- if ( $post_thumbnail_id ) {
134
- $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
135
- $url = $image[0];
 
 
136
  }
137
- }
138
- else { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
139
- $wud = wp_upload_dir();
140
- preg_match_all( '|<img.*?src=[\'"](' . $wud['baseurl'] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
141
- if ( isset( $matches ) ) $image = $matches[1][0];
142
- if ( strlen( trim( $image ) ) > 0 ) {
143
- $image_sizes = @getimagesize( $image );
144
- if ( isset( $image_sizes[0] ) && $image_sizes[0] == $width ) { // if this image is the same size as we need
145
- $url = $image;
146
- }
147
- else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
148
- $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
149
- }
150
  }
151
  }
152
  }
153
- if ( empty( $url ) || false === @fopen( $url, 'r' ) ) { // using default image if no image was found or no such file on server
154
- $url = get_option( 'relpoststh_default_image', $this->default_image );
155
- }
156
- $title = ( strlen( $post->post_title ) > $text_length ) ? substr( $post->post_title, 0, $text_length) . '...' : $post->post_title;
157
- $output .= '<a onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'" onmouseover="this.style.backgroundColor=\'' . get_option( 'relpoststh_hoverbackground', $this->hoverbackground ) . '\'" style="border-right: 1px solid ' . get_option( 'relpoststh_bordercolor', $this->border_color ) . '; border-bottom: medium none; margin: 0pt; padding: 6px; display: block; float: left; text-decoration: none; text-align: left; cursor: pointer;" href="' . get_permalink( $post->ID ) . '">';
158
- $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; width: ' . $width . 'px; height: ' . ( $height + 75 ) . 'px;">';
159
- $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; background: transparent url(' . $url . ') no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: ' . $width . 'px; height: ' . $height . 'px;"></div>';
160
- $output .= '<div style="border: 0pt none; margin: 3px 0pt 0pt; padding: 0pt; font-family: ' . get_option( 'relpoststh_fontfamily', $this->font_family ) . '; font-style: normal; font-variant: normal; font-weight: normal; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . '</div>';
161
- $output .= '</div>';
162
- $output .= '</a>';
 
163
 
164
- } // end foreach
165
- $output .= '</div><div style="clear: both"></div>';
166
- } // end if found posts
167
  return $output;
168
  }
169
 
@@ -177,12 +193,11 @@ class RelatedPostsThumbnails {
177
  if ( $categories_all != '1') { // only specific categories were selected
178
  $post_categories = wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) );
179
  $relpoststh_categories = unserialize( get_option( 'relpoststh_categories' ) );
180
- if ( !is_array( $relpoststh_categories ) )
181
- $relpoststh_categories = array();
182
  $common_categories = array_intersect( $relpoststh_categories, $post_categories );
183
- if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
184
  return false;
185
- }
186
  }
187
  return true;
188
  }
@@ -224,7 +239,9 @@ class RelatedPostsThumbnails {
224
  $available_sizes = array( 'thumbnail' => 'thumbnail', 'medium' => 'medium' );
225
  if ( current_theme_supports( 'post-thumbnails' ) ) {
226
  global $_wp_additional_image_sizes;
227
- $available_sizes = array_merge( $available_sizes, $_wp_additional_image_sizes );
 
 
228
  }
229
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
230
  $relpoststh_relation = get_option( 'relpoststh_relation', $this->relation );
@@ -279,7 +296,7 @@ class RelatedPostsThumbnails {
279
  <tr>
280
  <th scope="row"><?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:</th>
281
  <td>
282
- <input type="text" name="relpoststh_top_text" value="<?php echo get_option( 'relpoststh_top_text', $this->top_text ); ?>" size="50"/>
283
  </td>
284
  </tr>
285
  <tr>
2
  Plugin Name: Related Posts Thumbnails
3
  Plugin URI: http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
4
  Description: Showing related posts thumbnails under the post.
5
+ Version: 1.1.1
6
  Author: Maria Shaldybina
7
  Author URI: http://shaldybina.com/
8
  */
49
 
50
  function relpoststh_show( $content ) { // Displaying related posts on the site
51
  if ( $this->is_relpoststh_show() ) {
52
+ $content .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
53
  $content .= $this->relpoststh_get();
54
  }
55
  return $content;
59
  $id = get_the_ID();
60
  $relation = get_option( 'relpoststh_relation', $this->relation );
61
  $posts_number = get_option( 'relpoststh_number', $this->number );
62
+ if ( $posts_number <= 0 ) { // return nothing if this parameter was set to <= 0
63
+ return '';
64
+ }
65
  $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
66
  $text_length = get_option( 'relpoststh_textlength', $this->text_length );
67
  $thsource = get_option( 'relpoststh_thsource', $this->thsource );
85
  $query_args['category__in'] = array(0); // if no categories were specified return nothing
86
  }
87
  }
88
+ $query_args = ( is_array( $query_args ) ) ? array_merge( $args, $query_args ) : $args;
89
+ $posts = array_merge( $posts, $q->query( $query_args ) );
90
  }
91
 
92
  if ( $relation == 'tags' || $relation == 'both' ) {
93
  $query_args = array( 'tag__in' => wp_get_object_terms( $id, array( 'post_tag' ), array( 'fields' => 'ids' ) ) );
94
+ $query_args = ( is_array( $query_args ) ) ? array_merge( $args, $query_args ) : $args;
95
+ $posts = array_merge( $posts, $q->query( $query_args ) );
96
+ }
97
+
98
+ if ( ! ( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
99
+ return '';
100
  }
101
 
102
  if ( $relation == 'both' ) {
107
  $posts = array_slice( $posts_unique, 0, $posts_number );
108
  }
109
 
110
+ /* Calculating sizes */
111
  if ( $thsource == 'custom-field' ) {
112
  $width = get_option( 'relpoststh_customwidth', $this->custom_width );
113
  $height = get_option( 'relpoststh_customheight', $this->custom_height );
119
  }
120
  elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
121
  global $_wp_additional_image_sizes;
122
+ if ( isset( $_wp_additional_image_sizes[ $poststhname ] ) ) {
123
+ $width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
124
+ $height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
125
+ }
 
 
 
126
  }
127
  }
128
+ // displaying square if one size is not cropping
129
+ if ( $height == 9999 )
130
+ $height = $width;
131
+ if ( $width == 9999 )
132
+ $width = $height;
133
+ // theme is not supporting but settings were not changed
134
+ if ( empty( $width ) )
135
+ $width = get_option( "thumbnail_size_w" );
136
+ if ( empty( $height ) )
137
+ $height = get_option( "thumbnail_size_h" );
138
 
139
+ // rendering related posts HTML
140
+ $output = '<div style="clear: both"></div><div style="border: 0pt none ; margin: 0pt; padding: 0pt;">';
141
+ foreach( $posts as $post ) {
142
+ $image = '';
143
+ $url = '';
144
+ if ( $thsource == 'custom-field' ) {
145
+ $url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
146
+ }
147
+ else {
148
+ if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { // using built in Wordpress feature
149
+ $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
150
+ if ( $post_thumbnail_id ) {
151
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
152
+ $url = $image[0];
153
+ }
154
  }
155
+ else { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
156
+ $wud = wp_upload_dir();
157
+ preg_match_all( '|<img.*?src=[\'"](' . $wud['baseurl'] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
158
+ if ( isset( $matches ) ) $image = $matches[1][0];
159
+ if ( strlen( trim( $image ) ) > 0 ) {
160
+ $image_sizes = @getimagesize( $image );
161
+ if ( isset( $image_sizes[0] ) && $image_sizes[0] == $width ) { // if this image is the same size as we need
162
+ $url = $image;
163
  }
164
+ else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
165
+ $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
 
 
 
 
 
 
 
 
 
 
 
166
  }
167
  }
168
  }
169
+ }
170
+ if ( empty( $url ) || false === @fopen( $url, 'r' ) ) { // using default image if no image was found or no such file on server
171
+ $url = get_option( 'relpoststh_default_image', $this->default_image );
172
+ }
173
+ $title = ( strlen( $post->post_title ) > $text_length ) ? substr( $post->post_title, 0, $text_length) . '...' : $post->post_title;
174
+ $output .= '<a onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'" onmouseover="this.style.backgroundColor=\'' . get_option( 'relpoststh_hoverbackground', $this->hoverbackground ) . '\'" style="border-right: 1px solid ' . get_option( 'relpoststh_bordercolor', $this->border_color ) . '; border-bottom: medium none; margin: 0pt; padding: 6px; display: block; float: left; text-decoration: none; text-align: left; cursor: pointer;" href="' . get_permalink( $post->ID ) . '">';
175
+ $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; width: ' . $width . 'px; height: ' . ( $height + 75 ) . 'px;">';
176
+ $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; background: transparent url(' . $url . ') no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: ' . $width . 'px; height: ' . $height . 'px;"></div>';
177
+ $output .= '<div style="border: 0pt none; margin: 3px 0pt 0pt; padding: 0pt; font-family: ' . get_option( 'relpoststh_fontfamily', $this->font_family ) . '; font-style: normal; font-variant: normal; font-weight: normal; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . '</div>';
178
+ $output .= '</div>';
179
+ $output .= '</a>';
180
 
181
+ } // end foreach
182
+ $output .= '</div><div style="clear: both"></div>';
 
183
  return $output;
184
  }
185
 
193
  if ( $categories_all != '1') { // only specific categories were selected
194
  $post_categories = wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) );
195
  $relpoststh_categories = unserialize( get_option( 'relpoststh_categories' ) );
196
+ if ( !is_array( $relpoststh_categories ) || !is_array( $post_categories ) ) // no categories were selcted or post doesn't belong to any
197
+ return false;
198
  $common_categories = array_intersect( $relpoststh_categories, $post_categories );
199
+ if ( empty( $common_categories ) ) // post doesn't belong to specified categories
200
  return false;
 
201
  }
202
  return true;
203
  }
239
  $available_sizes = array( 'thumbnail' => 'thumbnail', 'medium' => 'medium' );
240
  if ( current_theme_supports( 'post-thumbnails' ) ) {
241
  global $_wp_additional_image_sizes;
242
+ if ( is_array($_wp_additional_image_sizes ) ) {
243
+ $available_sizes = array_merge( $available_sizes, $_wp_additional_image_sizes );
244
+ }
245
  }
246
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
247
  $relpoststh_relation = get_option( 'relpoststh_relation', $this->relation );
296
  <tr>
297
  <th scope="row"><?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:</th>
298
  <td>
299
+ <input type="text" name="relpoststh_top_text" value="<?php echo stripslashes( htmlspecialchars( get_option( 'relpoststh_top_text', $this->top_text ) ) ); ?>" size="50"/>
300
  </td>
301
  </tr>
302
  <tr>