Ultimate Posts Widget - Version 1.8.1

Version Description

  • Add content display option
Download this release

Release Info

Developer bostondv
Plugin Icon wp plugin Ultimate Posts Widget
Version 1.8.1
Comparing to
See all releases

Code changes from version 1.7 to 1.8.1

Files changed (2) hide show
  1. readme.txt +17 -3
  2. ultimate-posts-widget.php +689 -611
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Ultimate Posts Widget ===
2
  Contributors: bostondv
3
  Donate link: http://www.pomelodesign.com/donate
4
- Tags: widget, recent posts, custom post types, sticky posts, featured image, post thumbnail, excerpts, category
5
  Requires at least: 3.0
6
- Tested up to: 3.6
7
- Stable tag: 1.7
8
  License: GPL2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -26,11 +26,13 @@ Options:
26
  * Display publish time
27
  * Display post author
28
  * Display excerpt
 
29
  * Display read more link
30
  * Display featured image
31
  * Display more button link
32
  * Display post categories
33
  * Display post tags
 
34
  * Custom widget title link
35
  * Custom read more link text
36
  * Custom excerpt length (in words)
@@ -54,6 +56,7 @@ This plugin uses the [TimThumb library](http://www.binarymoon.co.uk/projects/tim
54
  * Cache permissions - The cache directory `wp-content/plugins/ultimate-posts-widget/cache` should be set to 777 or if that doesn't work, you may find 755 is ok.
55
  * Image sizes - TimThumb is configured to only work for images smaller than 1500 x 1500. The plugin and automatically selects the "Large" size from Settings > Media, if it is greater than 1500 x 1500 you will need to reduce the size or modify the configuration in `thumb.php` to support larger image sizes.
56
  * Tilde(~) in url - Timthumb has a known issue with this, please use a url without a tilde until a fix is available. [Bug report](https://code.google.com/p/timthumb/issues/detail?id=263)
 
57
 
58
  Still stuck? See [additional troubleshooting tips](http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/) from the TimThumb author.
59
 
@@ -63,6 +66,17 @@ Still stuck? See [additional troubleshooting tips](http://www.binarymoon.co.uk/2
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
 
 
 
 
 
 
66
  = 1.7 =
67
 
68
  * Added show author option
1
  === Ultimate Posts Widget ===
2
  Contributors: bostondv
3
  Donate link: http://www.pomelodesign.com/donate
4
+ Tags: widget, recent posts, custom post types, sticky posts, featured image, post thumbnail, excerpts, category, custom fields
5
  Requires at least: 3.0
6
+ Tested up to: 3.6.1
7
+ Stable tag: 1.8.1
8
  License: GPL2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
26
  * Display publish time
27
  * Display post author
28
  * Display excerpt
29
+ * Display content
30
  * Display read more link
31
  * Display featured image
32
  * Display more button link
33
  * Display post categories
34
  * Display post tags
35
+ * Display custom fields
36
  * Custom widget title link
37
  * Custom read more link text
38
  * Custom excerpt length (in words)
56
  * Cache permissions - The cache directory `wp-content/plugins/ultimate-posts-widget/cache` should be set to 777 or if that doesn't work, you may find 755 is ok.
57
  * Image sizes - TimThumb is configured to only work for images smaller than 1500 x 1500. The plugin and automatically selects the "Large" size from Settings > Media, if it is greater than 1500 x 1500 you will need to reduce the size or modify the configuration in `thumb.php` to support larger image sizes.
58
  * Tilde(~) in url - Timthumb has a known issue with this, please use a url without a tilde until a fix is available. [Bug report](https://code.google.com/p/timthumb/issues/detail?id=263)
59
+ * Thumbnail images only work with WordPress' native post thumbnail / featured image. Many theme use a custom image field for thumbnails, these are not supported.
60
 
61
  Still stuck? See [additional troubleshooting tips](http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/) from the TimThumb author.
62
 
66
 
67
  == Changelog ==
68
 
69
+ = 1.8.1 =
70
+
71
+ * Add content display option
72
+
73
+ = 1.8 =
74
+
75
+ * Add custom field display
76
+ * Re-organized widget options
77
+ * Use proper alt tag for image thumbnails
78
+ * Better title attribute for links
79
+
80
  = 1.7 =
81
 
82
  * Added show author option
ultimate-posts-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Ultimate Posts Widget
4
  Plugin URI: http://wordpress.org/plugins/ultimate-posts-widget/
5
  Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
6
- Version: 1.7
7
  Author: Boston Dell-Vandenberg
8
  Author URI: http://pomelodesign.com
9
  License: GPL2
@@ -25,624 +25,702 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
 
26
  if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
27
 
28
- class WP_Widget_Ultimate_Posts extends WP_Widget {
29
-
30
- function WP_Widget_Ultimate_Posts() {
31
-
32
- $widget_ops = array( 'classname' => 'widget_ultimate_posts', 'description' => __( 'Displays list of posts with an array of options', 'upw' ) );
33
- $this->WP_Widget( 'sticky-posts', __( 'Ultimate Posts', 'upw' ), $widget_ops );
34
- $this->alt_option_name = 'widget_ultimate_posts';
35
-
36
- add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
37
- add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
38
- add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
39
-
40
- load_plugin_textdomain('upw', false, basename( dirname( __FILE__ ) ) . '/languages' );
41
-
42
- }
43
-
44
- function widget( $args, $instance ) {
45
-
46
- global $post;
47
- $current_post_id = $post->ID;
48
-
49
- if( !function_exists('get_image_path') ) {
50
- function get_image_path($src) {
51
- global $blog_id;
52
- if(isset($blog_id) && $blog_id > 0) {
53
- $imageParts = explode('/files/' , $src);
54
- if(isset($imageParts[1])) {
55
- $src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
56
- }
57
- }
58
- return $src;
59
- }
60
- }
61
-
62
- $cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
63
-
64
- if ( !is_array( $cache ) )
65
- $cache = array();
66
-
67
- if ( isset( $cache[$args['widget_id']] ) ) {
68
- echo $cache[$args['widget_id']];
69
- return;
70
- }
71
-
72
- ob_start();
73
- extract( $args );
74
-
75
- $title = apply_filters( 'widget_title', $instance['title'] );
76
- $title_link = $instance['title_link'];
77
- $number = $instance['number'];
78
- $types = ($instance['types'] ? explode(',', $instance['types']) : '');
79
- $cats = ($instance['cats'] ? explode(',', $instance['cats']) : '');
80
- $atcat = $instance['atcat'] ? true : false;
81
- $thumb_w = $instance['thumb_w'];
82
- $thumb_h = $instance['thumb_h'];
83
- $thumb_crop = $instance['thumb_crop'];
84
- $excerpt_length = $instance['excerpt_length'];
85
- $excerpt_readmore = $instance['excerpt_readmore'];
86
- $sticky = $instance['sticky'];
87
- $order = $instance['order'];
88
- $orderby = $instance['orderby'];
89
-
90
- // Sticky posts
91
- if ($sticky == 'only') {
92
- $sticky_query = array( 'post__in' => get_option( 'sticky_posts' ) );
93
- } elseif ($sticky == 'hide') {
94
- $sticky_query = array( 'post__not_in' => get_option( 'sticky_posts' ) );
95
- } else {
96
- $sticky_query = null;
97
- }
98
-
99
- // If $atcat true and in category
100
- if ($atcat && is_category()) {
101
- $cats = get_query_var('cat');
102
- }
103
-
104
- // If $atcat true and is single post
105
- if ($atcat && is_single()) {
106
- $cats = '';
107
- foreach (get_the_category() as $catt) {
108
- $cats .= $catt->cat_ID.' ';
109
- }
110
- $cats = str_replace(" ", ",", trim($cats));
111
- }
112
-
113
- //Excerpt more filter
114
- $new_excerpt_more = create_function('$more', 'return "...";');
115
- add_filter('excerpt_more', $new_excerpt_more);
116
-
117
- // Excerpt length filter
118
- $new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
119
- if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);
120
-
121
- echo $before_widget;
122
- if ( $title ) {
123
- echo $before_title;
124
- if ( $title_link ) echo "<a href='$title_link'>";
125
- echo $title;
126
- if ( $title_link ) echo "</a>";
127
- echo $after_title;
128
- }
129
-
130
- $args = array(
131
- 'showposts' => $number,
132
- 'order' => $order,
133
- 'orderby' => $orderby,
134
- 'category__in' => $cats,
135
- 'post_type' => $types
136
- );
137
-
138
- if (!empty($sticky_query)) {
139
- $args[key($sticky_query)] = reset($sticky_query);
140
- }
141
-
142
- $r = new WP_Query( $args );
143
-
144
- if ( $r->have_posts() ) :
145
-
146
- echo '<ul>';
147
-
148
- while ( $r->have_posts() ) : $r->the_post();
149
-
150
- ?>
151
-
152
- <li class="<?php echo ($post->ID == $current_post_id && is_single())?'current-post-item':'' ?>">
153
-
154
- <?php
155
- if ( function_exists('the_post_thumbnail') &&
156
- current_theme_supports("post-thumbnails") &&
157
- $instance["show_thumbnail"] &&
158
- has_post_thumbnail() ) :
159
- $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large');
160
- $plugin_dir = 'ultimate-posts-widget';
161
- ?>
162
-
163
- <div class="upw-image">
164
- <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
165
- <img src="<?php echo WP_PLUGIN_URL . '/ultimate-posts-widget/thumb.php?src='. get_image_path($thumbnail[0]) .'&amp;h='.$thumb_h.'&amp;w='.$thumb_w.'&amp;zc='.$thumb_crop; ?>" alt="<?php the_title_attribute(); ?>" />
166
- </a>
167
- </div>
168
-
169
- <?php endif; ?>
170
-
171
- <div class="upw-content">
172
-
173
- <?php if ( get_the_title() && $instance['show_title'] ) : ?>
174
- <p class="post-title">
175
- <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>">
176
- <?php the_title(); ?>
177
- </a>
178
- </p>
179
- <?php endif; ?>
180
-
181
- <?php if ( $instance['show_date'] || $instance['show_time'] ) : ?>
182
- <p class="post-date">
183
- <?php
184
- if ( $instance['show_date'] && $instance['show_time'] ) {
185
- the_time(get_option('date_format') . ' ' . get_option('time_format'));
186
- } elseif ( $instance['show_date'] && !$instance['show_time'] ) {
187
- the_time(get_option('date_format'));
188
- } else {
189
- the_time(get_option('time_format'));
190
- }
191
- ?>
192
- </p>
193
- <?php endif; ?>
194
-
195
- <?php if( $instance['show_author'] ) : ?>
196
- <p class="post-author">
197
- <span class="post-author-label"><?php _e('By', 'upw'); ?>:</span>
198
- <?php the_author_posts_link(); ?>
199
- </p>
200
- <?php endif; ?>
201
-
202
- <?php if ( $instance['show_excerpt'] ) :
203
- if ( $instance['show_readmore'] ) : $linkmore = ' <a href="'.get_permalink().'" class="more-link">'.$excerpt_readmore.'</a>'; else: $linkmore =''; endif; ?>
204
- <p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
205
- <?php endif; ?>
206
-
207
- <?php if ( $instance['show_cats'] ) : ?>
208
- <p class="post-cats">
209
- <span class="post-cats-label"><?php _e('Categories', 'upw'); ?>:</span>
210
- <span class="post-cats-list"><?php the_category(', '); ?></span>
211
- </p>
212
- <?php endif; ?>
213
-
214
- <?php if ( $instance['show_tags'] ) : ?>
215
- <p class="post-tags">
216
- <span class="post-tags-label"><?php _e('Tags', 'upw'); ?>:</span>
217
- <?php the_tags('<span class="post-tags-list">', ', ', '</span>'); ?>
218
- </p>
219
- <?php endif; ?>
220
- </div>
221
-
222
- </li>
223
-
224
- <?php
225
- endwhile;
226
- echo '</ul>';
227
-
228
- if ( $instance['show_morebutton'] ) : ?>
229
- <div class="upw-more">
230
- <a href="<?php echo $instance['morebutton_url']; ?>" class="button"><?php echo $instance['morebutton_text']; ?></a>
231
- </div>
232
- <?php endif;
233
-
234
- // Reset the global $the_post as this query will have stomped on it
235
- wp_reset_postdata();
236
-
237
- else :
238
-
239
- echo __('No posts found.', 'upw');
240
-
241
- endif;
242
-
243
- echo $after_widget;
244
-
245
- if ($cache) {
246
- $cache[$args['widget_id']] = ob_get_flush();
247
- }
248
- wp_cache_set( 'widget_ultimate_posts', $cache, 'widget' );
249
- }
250
-
251
- function update( $new_instance, $old_instance ) {
252
- $instance = $old_instance;
253
-
254
- $instance['title'] = strip_tags( $new_instance['title'] );
255
- $instance['title_link'] = strip_tags( $new_instance['title_link'] );
256
- $instance['number'] = strip_tags( $new_instance['number'] );
257
- $instance['types'] = (isset( $new_instance['types'] )) ? implode(',', (array) $new_instance['types']) : '';
258
- $instance['cats'] = (isset( $new_instance['cats'] )) ? implode(',', (array) $new_instance['cats']) : '';
259
- $instance['atcat'] = isset( $new_instance['atcat'] );
260
- $instance['show_excerpt'] = isset( $new_instance['show_excerpt'] );
261
- $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] );
262
- $instance['show_date'] = isset( $new_instance['show_date'] );
263
- $instance['show_time'] = isset( $new_instance['show_time'] );
264
- $instance['show_title'] = isset( $new_instance['show_title'] );
265
- $instance['show_author'] = isset( $new_instance['show_author'] );
266
- $instance['thumb_w'] = strip_tags( $new_instance['thumb_w'] );
267
- $instance['thumb_h'] = strip_tags( $new_instance['thumb_h'] );
268
- $instance['thumb_crop'] = $new_instance['thumb_crop'];
269
- $instance['show_readmore'] = isset( $new_instance['show_readmore']);
270
- $instance['excerpt_length'] = strip_tags( $new_instance['excerpt_length'] );
271
- $instance['excerpt_readmore'] = strip_tags( $new_instance['excerpt_readmore'] );
272
- $instance['sticky'] = $new_instance['sticky'];
273
- $instance['order'] = $new_instance['order'];
274
- $instance['orderby'] = $new_instance['orderby'];
275
- $instance['show_morebutton'] = isset( $new_instance['show_morebutton'] );
276
- $instance['morebutton_url'] = strip_tags( $new_instance['morebutton_url'] );
277
- $instance['morebutton_text'] = strip_tags( $new_instance['morebutton_text'] );
278
- $instance['show_cats'] = isset( $new_instance['show_cats'] );
279
- $instance['show_tags'] = isset( $new_instance['show_tags'] );
280
-
281
-
282
- $this->flush_widget_cache();
283
-
284
- $alloptions = wp_cache_get( 'alloptions', 'options' );
285
- if ( isset( $alloptions['widget_ultimate_posts'] ) )
286
- delete_option( 'widget_ultimate_posts' );
287
-
288
- return $instance;
289
-
290
- }
291
-
292
- function flush_widget_cache() {
293
-
294
- wp_cache_delete( 'widget_ultimate_posts', 'widget' );
295
-
296
- }
297
-
298
- function form( $instance ) {
299
-
300
- // Set default arguments
301
- $instance = wp_parse_args( (array) $instance, array(
302
- 'title' => '',
303
- 'title_link' => '' ,
304
- 'number' => '5',
305
- 'types' => 'post',
306
- 'cats' => '',
307
- 'atcat' => false,
308
- 'thumb_w' => 100,
309
- 'thumb_h' => 100,
310
- 'thumb_crop' => 1,
311
- 'excerpt_length' => 10,
312
- 'excerpt_readmore' => __('Read more &rarr;', 'upw'),
313
- 'order' => 'DESC',
314
- 'orderby' => 'date',
315
- 'morebutton_text' => __('View More Posts', 'upw'),
316
- 'morebutton_url' => site_url(),
317
- 'sticky' => 'show',
318
- 'show_cats' => false,
319
- 'show_tags' => false,
320
- 'show_title' => false,
321
- 'show_date' => false,
322
- 'show_time' => false,
323
- 'show_author' => false,
324
- 'show_excerpt' => false,
325
- 'show_readmore' => false,
326
- 'show_thumbnail' => false,
327
- 'show_morebutton' => false
328
- ) );
329
-
330
- // Or use the instance
331
- $title = strip_tags($instance['title']);
332
- $title_link = strip_tags($instance['title_link']);
333
- $number = strip_tags($instance['number']);
334
- $types = $instance['types'];
335
- $cats = $instance['cats'];
336
- $atcat = $instance['atcat'];
337
- $thumb_w = strip_tags($instance['thumb_w']);
338
- $thumb_h = strip_tags($instance['thumb_h']);
339
- $thumb_crop = strip_tags($instance['thumb_crop']);
340
- $excerpt_length = strip_tags($instance['excerpt_length']);
341
- $excerpt_readmore = strip_tags($instance['excerpt_readmore']);
342
- $order = $instance['order'];
343
- $orderby = $instance['orderby'];
344
- $morebutton_text = strip_tags($instance['morebutton_text']);
345
- $morebutton_url = strip_tags($instance['morebutton_url']);
346
- $sticky = $instance['sticky'];
347
- $show_cats = $instance['show_cats'];
348
- $show_tags = $instance['show_tags'];
349
- $show_title = $instance['show_title'];
350
- $show_date = $instance['show_date'];
351
- $show_time = $instance['show_time'];
352
- $show_author = $instance['show_author'];
353
- $show_excerpt = $instance['show_excerpt'];
354
- $show_readmore = $instance['show_readmore'];
355
- $show_thumbnail = $instance['show_thumbnail'];
356
- $show_morebutton = $instance['show_morebutton'];
357
-
358
- //Let's turn $types and $cats into an array
359
- $types = explode(',', $types);
360
- $cats = explode(',', $cats);
361
-
362
- //Count number of post types for select box sizing
363
- $cpt_types = get_post_types( array( 'public' => true ), 'names' );
364
- foreach ($cpt_types as $cpt ) {
365
- $cpt_ar[] = $cpt;
366
- }
367
- $n = count($cpt_ar);
368
- if($n > 10) { $n = 10; }
369
-
370
- //Count number of categories for select box sizing
371
- $cat_list = get_categories( 'hide_empty=0' );
372
- foreach ($cat_list as $cat ) {
373
- $cat_ar[] = $cat;
374
- }
375
- $c = count($cat_ar);
376
- if($c > 10) { $c = 10; }
377
-
378
- ?>
379
-
380
- <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'upw' ); ?>:</label>
381
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
382
-
383
- <p><label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Title URL', 'upw' ); ?>:</label>
384
- <input class="widefat" id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" type="text" value="<?php echo $title_link; ?>" /></p>
385
-
386
- <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts', 'upw' ); ?>:</label>
387
- <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="2" /></p>
388
-
389
- <p>
390
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" type="checkbox" <?php checked( (bool) $show_title, true ); ?> />
391
- <label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Show title', 'upw' ); ?></label>
392
- </p>
393
-
394
- <p>
395
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" type="checkbox" <?php checked( (bool) $show_date, true ); ?> />
396
- <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show published date', 'upw' ); ?></label>
397
- </p>
398
-
399
- <p>
400
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_time' ); ?>" name="<?php echo $this->get_field_name( 'show_time' ); ?>" type="checkbox" <?php checked( (bool) $show_time, true ); ?> />
401
- <label for="<?php echo $this->get_field_id( 'show_time' ); ?>"><?php _e( 'Show published time', 'upw' ); ?></label>
402
- </p>
403
-
404
- <p>
405
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_author' ); ?>" name="<?php echo $this->get_field_name( 'show_author' ); ?>" type="checkbox" <?php checked( (bool) $show_author, true ); ?> />
406
- <label for="<?php echo $this->get_field_id( 'show_author' ); ?>"><?php _e( 'Show post author', 'upw' ); ?></label>
407
- </p>
408
-
409
- <p>
410
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_excerpt' ); ?>" name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" type="checkbox" <?php checked( (bool) $show_excerpt, true ); ?> />
411
- <label for="<?php echo $this->get_field_id( 'show_excerpt' ); ?>"><?php _e( 'Show excerpt', 'upw' ); ?></label>
412
- </p>
413
-
414
- <p>
415
- <label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e( 'Excerpt length (in words)', 'upw' ); ?>:</label>
416
- <input style="text-align: center;" type="text" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" size="3" />
417
- </p>
418
-
419
- <p>
420
- <label for="<?php echo $this->get_field_id('show_readmore'); ?>">
421
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_readmore'); ?>" name="<?php echo $this->get_field_name('show_readmore'); ?>"<?php checked( (bool) $show_readmore, true ); ?> />
422
- <?php _e( 'Show read more link', 'upw' ); ?>
423
- </label>
424
- </p>
425
-
426
- <p>
427
- <label for="<?php echo $this->get_field_id('excerpt_readmore'); ?>"><?php _e( 'Read more text', 'upw' ); ?>:</label>
428
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('excerpt_readmore'); ?>" name="<?php echo $this->get_field_name('excerpt_readmore'); ?>" value="<?php echo $excerpt_readmore; ?>" />
429
- </p>
430
-
431
- <?php if ( function_exists('the_post_thumbnail') && current_theme_supports( 'post-thumbnails' ) ) : ?>
432
-
433
- <p>
434
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" type="checkbox" <?php checked( (bool) $show_thumbnail, true ); ?> />
435
- <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show thumbnail', 'upw' ); ?></label>
436
- </p>
437
-
438
- <p>
439
- <label><?php _e('Thumbnail size', 'upw'); ?>:</label>
440
- <br />
441
- <label for="<?php echo $this->get_field_id('thumb_w'); ?>">
442
- <?php _e('W', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_w'); ?>" name="<?php echo $this->get_field_name('thumb_w'); ?>" value="<?php echo $thumb_w; ?>" />
443
- </label>
444
- <label for="<?php echo $this->get_field_id('thumb_h'); ?>">
445
- <?php _e('H', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_h'); ?>" name="<?php echo $this->get_field_name('thumb_h'); ?>" value="<?php echo $thumb_h; ?>" />
446
- </label>
447
- </p>
448
-
449
- <p>
450
- <label><?php _e('Crop mode', 'upw'); ?>:</label>
451
- <br />
452
- <select id="<?php echo $this->get_field_id('thumb_crop'); ?>" name="<?php echo $this->get_field_name('thumb_crop'); ?>">
453
- <option value="1"<?php if($thumb_crop == 1) echo ' selected'; ?>><?php _e('Scale &amp; Crop to Fit', 'upw'); ?></option>
454
- <option value="0"<?php if($thumb_crop == 0) echo ' selected'; ?>><?php _e('Stretch to Fit', 'upw'); ?></option>
455
- <option value="2"<?php if($thumb_crop == 2) echo ' selected'; ?>><?php _e('Proportional Scale', 'upw'); ?></option>
456
- <option value="3"<?php if($thumb_crop == 3) echo ' selected'; ?>><?php _e('Proportional Scale No Borders', 'upw'); ?></option>
457
- </select>
458
- </p>
459
-
460
- <?php endif; ?>
461
-
462
- <p>
463
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_morebutton'); ?>" name="<?php echo $this->get_field_name('show_morebutton'); ?>" <?php checked( (bool) $show_morebutton, true ); ?> />
464
- <label for="<?php echo $this->get_field_id('show_morebutton'); ?>"> <?php _e('Show more button', 'upw'); ?></label>
465
- </p>
466
-
467
- <p>
468
- <label for="<?php echo $this->get_field_id('morebutton_text'); ?>"><?php _e( 'More button text', 'upw' ); ?>:</label>
469
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_text'); ?>" name="<?php echo $this->get_field_name('morebutton_text'); ?>" value="<?php echo $morebutton_text; ?>" />
470
- </p>
471
-
472
- <p>
473
- <label for="<?php echo $this->get_field_id('morebutton_url'); ?>"><?php _e( 'More button URL', 'upw' ); ?>:</label>
474
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_url'); ?>" name="<?php echo $this->get_field_name('morebutton_url'); ?>" value="<?php echo $morebutton_url; ?>" />
475
- </p>
476
-
477
- <p>
478
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atcat'); ?>" name="<?php echo $this->get_field_name('atcat'); ?>" <?php checked( (bool) $atcat, true ); ?> />
479
- <label for="<?php echo $this->get_field_id('atcat'); ?>"> <?php _e('Show posts only from current category', 'upw');?></label>
480
- </p>
481
-
482
- <p>
483
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_cats'); ?>" name="<?php echo $this->get_field_name('show_cats'); ?>" <?php checked( (bool) $show_cats, true ); ?> />
484
- <label for="<?php echo $this->get_field_id('show_cats'); ?>"> <?php _e('Show post categories', 'upw'); ?></label>
485
- </p>
486
-
487
- <p>
488
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_tags'); ?>" name="<?php echo $this->get_field_name('show_tags'); ?>" <?php checked( (bool) $show_tags, true ); ?> />
489
- <label for="<?php echo $this->get_field_id('show_tags'); ?>"> <?php _e('Show post tags', 'upw'); ?></label>
490
- </p>
491
-
492
- <p>
493
- <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e( 'Select categories', 'upw' ); ?>:</label>
494
- <select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
495
- <?php
496
- $categories = get_categories( 'hide_empty=0' );
497
- foreach ($categories as $category ) { ?>
498
- <option value="<?php echo $category->term_id; ?>" <?php if( in_array($category->term_id, $cats)) { echo 'selected="selected"'; } ?>><?php echo $category->cat_name;?></option>
499
- <?php } ?>
500
- </select>
501
- </p>
502
-
503
- <p>
504
- <label for="<?php echo $this->get_field_id('types'); ?>"><?php _e( 'Select post types', 'upw' ); ?>:</label>
505
- <select name="<?php echo $this->get_field_name('types'); ?>[]" id="<?php echo $this->get_field_id('types'); ?>" class="widefat" style="height: auto;" size="<?php echo $n ?>" multiple>
506
- <?php
507
- $args = array( 'public' => true );
508
- $post_types = get_post_types( $args, 'names' );
509
- foreach ($post_types as $post_type ) { ?>
510
- <option value="<?php echo $post_type; ?>" <?php if( in_array($post_type, $types)) { echo 'selected="selected"'; } ?>><?php echo $post_type;?></option>
511
- <?php } ?>
512
- </select>
513
- </p>
514
-
515
- <p>
516
- <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e( 'Sticky posts', 'upw' ); ?>:</label>
517
- <select name="<?php echo $this->get_field_name('sticky'); ?>" id="<?php echo $this->get_field_id('sticky'); ?>" class="widefat">
518
- <option value="show"<?php if( $sticky === 'show') echo ' selected'; ?>><?php _e('Show All Posts', 'upw'); ?></option>
519
- <option value="hide"<?php if( $sticky == 'hide') echo ' selected'; ?>><?php _e('Hide Sticky Posts', 'upw'); ?></option>
520
- <option value="only"<?php if( $sticky == 'only') echo ' selected'; ?>><?php _e('Show Only Sticky Posts', 'upw'); ?></option>
521
- </select>
522
- </p>
523
-
524
- <p>
525
- <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Order by', 'upw' ); ?>:</label>
526
- <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
527
- <option value="date"<?php if( $orderby == 'date') echo ' selected'; ?>><?php _e('Published Date', 'upw'); ?></option>
528
- <option value="title"<?php if( $orderby == 'title') echo ' selected'; ?>><?php _e('Title', 'upw'); ?></option>
529
- <option value="comment_count"<?php if( $orderby == 'comment_count') echo ' selected'; ?>><?php _e('Comment Count', 'upw'); ?></option>
530
- <option value="rand"<?php if( $orderby == 'rand') echo ' selected'; ?>><?php _e('Random'); ?></option>
531
- </select>
532
- </p>
533
-
534
- <p>
535
- <label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Order', 'upw' ); ?>:</label>
536
- <select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
537
- <option value="DESC"<?php if( $order == 'DESC') echo ' selected'; ?>><?php _e('Descending', 'upw'); ?></option>
538
- <option value="ASC"<?php if( $order == 'ASC') echo ' selected'; ?>><?php _e('Ascending', 'upw'); ?></option>
539
- </select>
540
- </p>
541
-
542
- <p class="credits"><small><?php _e('Developed by', 'upw'); ?> <a href="http://pomelodesign.com">Pomelo Design</a></small></p>
543
-
544
- <?php if ( $instance ) { ?>
545
-
546
- <script>
547
-
548
- jQuery(document).ready(function($){
549
-
550
- var show_excerpt = $("#<?php echo $this->get_field_id( 'show_excerpt' ); ?>");
551
- var show_readmore = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>");
552
- var show_thumbnail = $("#<?php echo $this->get_field_id( 'show_thumbnail' ); ?>");
553
- var excerpt_length = $("#<?php echo $this->get_field_id( 'excerpt_length' ); ?>").parents('p');
554
- var excerpt_readmore = $("#<?php echo $this->get_field_id( 'excerpt_readmore' ); ?>").parents('p');
555
- var thumb_w = $("#<?php echo $this->get_field_id( 'thumb_w' ); ?>").parents('p');
556
- var thumb_crop = $("#<?php echo $this->get_field_id( 'thumb_crop' ); ?>").parents('p');
557
- var show_morebutton = $("#<?php echo $this->get_field_id( 'show_morebutton' ); ?>");
558
- var morebutton_text = $("#<?php echo $this->get_field_id( 'morebutton_text' ); ?>").parents('p');
559
- var morebutton_url = $("#<?php echo $this->get_field_id( 'morebutton_url' ); ?>").parents('p');
560
-
561
- <?php
562
- // Use PHP to determine if not checked and hide if so
563
- // jQuery method was acting up
564
- if ( !$show_excerpt ) {
565
- echo 'excerpt_length.hide();';
566
- }
567
- if ( !$show_readmore ) {
568
- echo 'excerpt_readmore.hide();';
569
- }
570
- if ( !$show_thumbnail ) {
571
- echo 'thumb_w.hide();';
572
- echo 'thumb_crop.hide();';
573
- }
574
- if ( !$show_morebutton ) {
575
- echo 'morebutton_text.hide();';
576
- echo 'morebutton_url.hide();';
577
- }
578
- ?>
579
-
580
- // Toggle excerpt length on click
581
- show_excerpt.click(function(){
582
-
583
- if ( $(this).is(":checked") ) {
584
- excerpt_length.show("fast");
585
- } else {
586
- excerpt_length.hide("fast");
587
- }
588
-
589
- });
590
-
591
- // Toggle excerpt length on click
592
- show_readmore.click(function(){
593
-
594
- if ( $(this).is(":checked") ) {
595
- excerpt_readmore.show("fast");
596
- } else {
597
- excerpt_readmore.hide("fast");
598
- }
599
-
600
- });
601
-
602
- // Toggle excerpt length on click
603
- show_thumbnail.click(function(){
604
-
605
- if ( $(this).is(":checked") ) {
606
- thumb_w.show("fast");
607
- thumb_crop.show("fast");
608
- } else {
609
- thumb_w.hide("fast");
610
- thumb_crop.hide("fast");
611
- }
612
-
613
- });
614
-
615
- // Toggle more button on click
616
- show_morebutton.click(function(){
617
-
618
- if ( $(this).is(":checked") ) {
619
- morebutton_text.show("fast");
620
- morebutton_url.show("fast");
621
- } else {
622
- morebutton_text.hide("fast");
623
- morebutton_url.hide("fast");
624
- }
625
-
626
- });
627
-
628
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
630
- </script>
 
 
 
631
 
632
- <?php
 
 
 
 
 
 
633
 
634
- }
 
 
635
 
636
- }
637
 
638
- }
639
 
640
- function init_WP_Widget_Ultimate_Posts() {
641
 
642
- register_widget( 'WP_Widget_Ultimate_Posts' );
643
 
644
- }
645
 
646
- add_action( 'widgets_init', 'init_WP_Widget_Ultimate_Posts' );
 
 
 
 
 
 
647
 
648
  }
3
  Plugin Name: Ultimate Posts Widget
4
  Plugin URI: http://wordpress.org/plugins/ultimate-posts-widget/
5
  Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
6
+ Version: 1.8.1
7
  Author: Boston Dell-Vandenberg
8
  Author URI: http://pomelodesign.com
9
  License: GPL2
25
 
26
  if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
27
 
28
+ class WP_Widget_Ultimate_Posts extends WP_Widget {
29
+
30
+ function WP_Widget_Ultimate_Posts() {
31
+
32
+ $widget_options = array(
33
+ 'classname' => 'widget_ultimate_posts',
34
+ 'description' => __( 'Displays list of posts with an array of options', 'upw' )
35
+ );
36
+
37
+ $control_options = array();
38
+
39
+ $this->WP_Widget(
40
+ 'sticky-posts',
41
+ __( 'Ultimate Posts', 'upw' ),
42
+ $widget_options,
43
+ $control_options
44
+ );
45
+
46
+ $this->alt_option_name = 'widget_ultimate_posts';
47
+
48
+ add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
49
+ add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
50
+ add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
51
+
52
+ load_plugin_textdomain('upw', false, basename( dirname( __FILE__ ) ) . '/languages' );
53
+
54
+ }
55
+
56
+ function widget( $args, $instance ) {
57
+
58
+ global $post;
59
+ $current_post_id = $post->ID;
60
+
61
+ if( !function_exists('get_image_path') ) {
62
+ function get_image_path($src) {
63
+ global $blog_id;
64
+ if(isset($blog_id) && $blog_id > 0) {
65
+ $imageParts = explode('/files/' , $src);
66
+ if(isset($imageParts[1])) {
67
+ $src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
68
+ }
69
+ }
70
+ return $src;
71
+ }
72
+ }
73
+
74
+ $cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
75
+
76
+ if ( !is_array( $cache ) )
77
+ $cache = array();
78
+
79
+ if ( isset( $cache[$args['widget_id']] ) ) {
80
+ echo $cache[$args['widget_id']];
81
+ return;
82
+ }
83
+
84
+ ob_start();
85
+ extract( $args );
86
+
87
+ $title = apply_filters( 'widget_title', $instance['title'] );
88
+ $title_link = $instance['title_link'];
89
+ $number = $instance['number'];
90
+ $types = ($instance['types'] ? explode(',', $instance['types']) : '');
91
+ $cats = ($instance['cats'] ? explode(',', $instance['cats']) : '');
92
+ $atcat = $instance['atcat'] ? true : false;
93
+ $thumb_w = $instance['thumb_w'];
94
+ $thumb_h = $instance['thumb_h'];
95
+ $thumb_crop = $instance['thumb_crop'];
96
+ $excerpt_length = $instance['excerpt_length'];
97
+ $excerpt_readmore = $instance['excerpt_readmore'];
98
+ $sticky = $instance['sticky'];
99
+ $order = $instance['order'];
100
+ $orderby = $instance['orderby'];
101
+ $custom_fields = $instance['custom_fields'];
102
+
103
+ // Sticky posts
104
+ if ($sticky == 'only') {
105
+ $sticky_query = array( 'post__in' => get_option( 'sticky_posts' ) );
106
+ } elseif ($sticky == 'hide') {
107
+ $sticky_query = array( 'post__not_in' => get_option( 'sticky_posts' ) );
108
+ } else {
109
+ $sticky_query = null;
110
+ }
111
+
112
+ // If $atcat true and in category
113
+ if ($atcat && is_category()) {
114
+ $cats = get_query_var('cat');
115
+ }
116
+
117
+ // If $atcat true and is single post
118
+ if ($atcat && is_single()) {
119
+ $cats = '';
120
+ foreach (get_the_category() as $catt) {
121
+ $cats .= $catt->cat_ID.' ';
122
+ }
123
+ $cats = str_replace(" ", ",", trim($cats));
124
+ }
125
+
126
+ //Excerpt more filter
127
+ $new_excerpt_more = create_function('$more', 'return "...";');
128
+ add_filter('excerpt_more', $new_excerpt_more);
129
+
130
+ // Excerpt length filter
131
+ $new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
132
+ if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);
133
+
134
+ echo $before_widget;
135
+ if ( $title ) {
136
+ echo $before_title;
137
+ if ( $title_link ) echo "<a href='$title_link'>";
138
+ echo $title;
139
+ if ( $title_link ) echo "</a>";
140
+ echo $after_title;
141
+ }
142
+
143
+ $args = array(
144
+ 'showposts' => $number,
145
+ 'order' => $order,
146
+ 'orderby' => $orderby,
147
+ 'category__in' => $cats,
148
+ 'post_type' => $types
149
+ );
150
+
151
+ if (!empty($sticky_query)) {
152
+ $args[key($sticky_query)] = reset($sticky_query);
153
+ }
154
+
155
+ $r = new WP_Query( $args );
156
+
157
+ if ( $r->have_posts() ) :
158
+
159
+ echo '<ul>';
160
+
161
+ while ( $r->have_posts() ) : $r->the_post();
162
+
163
+ ?>
164
+
165
+ <li class="<?php echo ($post->ID == $current_post_id && is_single())?'current-post-item':'' ?>">
166
+
167
+ <?php
168
+ if ( function_exists('the_post_thumbnail') &&
169
+ current_theme_supports("post-thumbnails") &&
170
+ $instance["show_thumbnail"] &&
171
+ has_post_thumbnail() ) :
172
+ $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large');
173
+ $thumbnail_alt = get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true);
174
+ $plugin_dir = 'ultimate-posts-widget';
175
+ ?>
176
+
177
+ <div class="upw-image">
178
+ <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(array('before'=>'Permalink to: ')); ?>">
179
+ <img src="<?php echo WP_PLUGIN_URL . '/ultimate-posts-widget/thumb.php?src='. get_image_path($thumbnail[0]) .'&amp;h='.$thumb_h.'&amp;w='.$thumb_w.'&amp;zc='.$thumb_crop; ?>" alt="<?php echo $thumbnail_alt; ?>" />
180
+ </a>
181
+ </div>
182
+
183
+ <?php endif; ?>
184
+
185
+ <div class="upw-content">
186
+
187
+ <?php if ( get_the_title() && $instance['show_title'] ) : ?>
188
+ <p class="post-title">
189
+ <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(array('before'=>'Permalink to: ')); ?>">
190
+ <?php the_title(); ?>
191
+ </a>
192
+ </p>
193
+ <?php endif; ?>
194
+
195
+ <?php if ( $instance['show_date'] || $instance['show_time'] ) : ?>
196
+ <p class="post-date">
197
+ <?php
198
+ if ( $instance['show_date'] && $instance['show_time'] ) {
199
+ the_time(get_option('date_format') . ' ' . get_option('time_format'));
200
+ } elseif ( $instance['show_date'] && !$instance['show_time'] ) {
201
+ the_time(get_option('date_format'));
202
+ } else {
203
+ the_time(get_option('time_format'));
204
+ }
205
+ ?>
206
+ </p>
207
+ <?php endif; ?>
208
+
209
+ <?php if( $instance['show_author'] ) : ?>
210
+ <p class="post-author">
211
+ <span class="post-author-label"><?php _e('By', 'upw'); ?>:</span>
212
+ <?php the_author_posts_link(); ?>
213
+ </p>
214
+ <?php endif; ?>
215
+
216
+ <?php if ( $instance['show_excerpt'] ) :
217
+ if ( $instance['show_readmore'] ) : $linkmore = ' <a href="'.get_permalink().'" class="more-link" title="'.the_title_attribute(array('before'=>'Permalink to: ', 'echo'=>false)).'">'.$excerpt_readmore.'</a>'; else: $linkmore =''; endif; ?>
218
+ <p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
219
+ <?php endif; ?>
220
+
221
+ <?php if ( $instance['show_content'] ) : ?>
222
+ <p class="post-content"><?php the_content() ?></p>
223
+ <?php endif; ?>
224
+
225
+ <?php if ( $instance['show_cats'] ) : ?>
226
+ <p class="post-cats">
227
+ <span class="post-cats-label"><?php _e('Categories', 'upw'); ?>:</span>
228
+ <span class="post-cats-list"><?php the_category(', '); ?></span>
229
+ </p>
230
+ <?php endif; ?>
231
+
232
+ <?php if ( $instance['show_tags'] ) : ?>
233
+ <p class="post-tags">
234
+ <span class="post-tags-label"><?php _e('Tags', 'upw'); ?>:</span>
235
+ <?php the_tags('<span class="post-tags-list">', ', ', '</span>'); ?>
236
+ </p>
237
+ <?php endif; ?>
238
+
239
+ <?php if ( $custom_fields ) {
240
+ $custom_field_name = explode(',', $custom_fields);
241
+ foreach ($custom_field_name as $name) {
242
+ $name = trim($name);
243
+ $custom_field_values = get_post_meta($post->ID, $name, true);
244
+ if ($custom_field_values) {
245
+ echo '<p class="post-meta post-meta-'.$name.'">';
246
+ if (!is_array($custom_field_values)) {
247
+ echo $custom_field_values;
248
+ } else {
249
+ $last_value = end($custom_field_values);
250
+ foreach ($custom_field_values as $value) {
251
+ echo $value;
252
+ if ($value != $last_value) echo ', ';
253
+ }
254
+ }
255
+ echo '</p>';
256
+ }
257
+ }
258
+ } ?>
259
+
260
+ </div>
261
+
262
+ </li>
263
+
264
+ <?php
265
+ endwhile;
266
+ echo '</ul>';
267
+
268
+ if ( $instance['show_morebutton'] ) : ?>
269
+ <div class="upw-more">
270
+ <a href="<?php echo $instance['morebutton_url']; ?>" class="button"><?php echo $instance['morebutton_text']; ?></a>
271
+ </div>
272
+ <?php endif;
273
+
274
+ // Reset the global $the_post as this query will have stomped on it
275
+ wp_reset_postdata();
276
+
277
+ else :
278
+
279
+ echo __('No posts found.', 'upw');
280
+
281
+ endif;
282
+
283
+ echo $after_widget;
284
+
285
+ if ($cache) {
286
+ $cache[$args['widget_id']] = ob_get_flush();
287
+ }
288
+ wp_cache_set( 'widget_ultimate_posts', $cache, 'widget' );
289
+ }
290
+
291
+ function update( $new_instance, $old_instance ) {
292
+ $instance = $old_instance;
293
+
294
+ $instance['title'] = strip_tags( $new_instance['title'] );
295
+ $instance['title_link'] = strip_tags( $new_instance['title_link'] );
296
+ $instance['number'] = strip_tags( $new_instance['number'] );
297
+ $instance['types'] = (isset( $new_instance['types'] )) ? implode(',', (array) $new_instance['types']) : '';
298
+ $instance['cats'] = (isset( $new_instance['cats'] )) ? implode(',', (array) $new_instance['cats']) : '';
299
+ $instance['atcat'] = isset( $new_instance['atcat'] );
300
+ $instance['show_excerpt'] = isset( $new_instance['show_excerpt'] );
301
+ $instance['show_content'] = isset( $new_instance['show_content'] );
302
+ $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] );
303
+ $instance['show_date'] = isset( $new_instance['show_date'] );
304
+ $instance['show_time'] = isset( $new_instance['show_time'] );
305
+ $instance['show_title'] = isset( $new_instance['show_title'] );
306
+ $instance['show_author'] = isset( $new_instance['show_author'] );
307
+ $instance['thumb_w'] = strip_tags( $new_instance['thumb_w'] );
308
+ $instance['thumb_h'] = strip_tags( $new_instance['thumb_h'] );
309
+ $instance['thumb_crop'] = $new_instance['thumb_crop'];
310
+ $instance['show_readmore'] = isset( $new_instance['show_readmore']);
311
+ $instance['excerpt_length'] = strip_tags( $new_instance['excerpt_length'] );
312
+ $instance['excerpt_readmore'] = strip_tags( $new_instance['excerpt_readmore'] );
313
+ $instance['sticky'] = $new_instance['sticky'];
314
+ $instance['order'] = $new_instance['order'];
315
+ $instance['orderby'] = $new_instance['orderby'];
316
+ $instance['show_morebutton'] = isset( $new_instance['show_morebutton'] );
317
+ $instance['morebutton_url'] = strip_tags( $new_instance['morebutton_url'] );
318
+ $instance['morebutton_text'] = strip_tags( $new_instance['morebutton_text'] );
319
+ $instance['show_cats'] = isset( $new_instance['show_cats'] );
320
+ $instance['show_tags'] = isset( $new_instance['show_tags'] );
321
+ $instance['custom_fields'] = strip_tags( $new_instance['custom_fields'] );
322
+
323
+ $this->flush_widget_cache();
324
+
325
+ $alloptions = wp_cache_get( 'alloptions', 'options' );
326
+ if ( isset( $alloptions['widget_ultimate_posts'] ) )
327
+ delete_option( 'widget_ultimate_posts' );
328
+
329
+ return $instance;
330
+
331
+ }
332
+
333
+ function flush_widget_cache() {
334
+
335
+ wp_cache_delete( 'widget_ultimate_posts', 'widget' );
336
+
337
+ }
338
+
339
+ function form( $instance ) {
340
+
341
+ // Set default arguments
342
+ $instance = wp_parse_args( (array) $instance, array(
343
+ 'title' => '',
344
+ 'title_link' => '' ,
345
+ 'number' => '5',
346
+ 'types' => 'post',
347
+ 'cats' => '',
348
+ 'atcat' => false,
349
+ 'thumb_w' => 100,
350
+ 'thumb_h' => 100,
351
+ 'thumb_crop' => 1,
352
+ 'excerpt_length' => 10,
353
+ 'excerpt_readmore' => __('Read more &rarr;', 'upw'),
354
+ 'order' => 'DESC',
355
+ 'orderby' => 'date',
356
+ 'morebutton_text' => __('View More Posts', 'upw'),
357
+ 'morebutton_url' => site_url(),
358
+ 'sticky' => 'show',
359
+ 'show_cats' => false,
360
+ 'show_tags' => false,
361
+ 'show_title' => false,
362
+ 'show_date' => false,
363
+ 'show_time' => false,
364
+ 'show_author' => false,
365
+ 'show_excerpt' => false,
366
+ 'show_content' => false,
367
+ 'show_readmore' => false,
368
+ 'show_thumbnail' => false,
369
+ 'custom_fields' => '',
370
+ 'show_morebutton' => false
371
+ ) );
372
+
373
+ // Or use the instance
374
+ $title = strip_tags($instance['title']);
375
+ $title_link = strip_tags($instance['title_link']);
376
+ $number = strip_tags($instance['number']);
377
+ $types = $instance['types'];
378
+ $cats = $instance['cats'];
379
+ $atcat = $instance['atcat'];
380
+ $thumb_w = strip_tags($instance['thumb_w']);
381
+ $thumb_h = strip_tags($instance['thumb_h']);
382
+ $thumb_crop = strip_tags($instance['thumb_crop']);
383
+ $excerpt_length = strip_tags($instance['excerpt_length']);
384
+ $excerpt_readmore = strip_tags($instance['excerpt_readmore']);
385
+ $order = $instance['order'];
386
+ $orderby = $instance['orderby'];
387
+ $morebutton_text = strip_tags($instance['morebutton_text']);
388
+ $morebutton_url = strip_tags($instance['morebutton_url']);
389
+ $sticky = $instance['sticky'];
390
+ $show_cats = $instance['show_cats'];
391
+ $show_tags = $instance['show_tags'];
392
+ $show_title = $instance['show_title'];
393
+ $show_date = $instance['show_date'];
394
+ $show_time = $instance['show_time'];
395
+ $show_author = $instance['show_author'];
396
+ $show_excerpt = $instance['show_excerpt'];
397
+ $show_content = $instance['show_content'];
398
+ $show_readmore = $instance['show_readmore'];
399
+ $show_thumbnail = $instance['show_thumbnail'];
400
+ $show_morebutton = $instance['show_morebutton'];
401
+ $custom_fields = strip_tags($instance['custom_fields']);
402
+
403
+ //Let's turn $types and $cats into an array
404
+ $types = explode(',', $types);
405
+ $cats = explode(',', $cats);
406
+
407
+ //Count number of post types for select box sizing
408
+ $cpt_types = get_post_types( array( 'public' => true ), 'names' );
409
+ foreach ($cpt_types as $cpt ) {
410
+ $cpt_ar[] = $cpt;
411
+ }
412
+ $n = count($cpt_ar);
413
+ if($n > 10) { $n = 10; }
414
+
415
+ //Count number of categories for select box sizing
416
+ $cat_list = get_categories( 'hide_empty=0' );
417
+ foreach ($cat_list as $cat ) {
418
+ $cat_ar[] = $cat;
419
+ }
420
+ $c = count($cat_ar);
421
+ if($c > 10) { $c = 10; }
422
+
423
+ ?>
424
+
425
+ <style>
426
+ .upw-divider {
427
+ border: 0;
428
+ border-top: 1px solid #DFDFDF;
429
+ }
430
+ </style>
431
+
432
+ <p>
433
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'upw' ); ?>:</label>
434
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
435
+ </p>
436
+
437
+ <p>
438
+ <label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Title URL', 'upw' ); ?>:</label>
439
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" type="text" value="<?php echo $title_link; ?>" />
440
+ </p>
441
+
442
+ <p>
443
+ <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts', 'upw' ); ?>:</label>
444
+ <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="2" />
445
+ </p>
446
+
447
+ <p>
448
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_morebutton'); ?>" name="<?php echo $this->get_field_name('show_morebutton'); ?>" <?php checked( (bool) $show_morebutton, true ); ?> />
449
+ <label for="<?php echo $this->get_field_id('show_morebutton'); ?>"> <?php _e('Show more button', 'upw'); ?></label>
450
+ </p>
451
+
452
+ <p>
453
+ <label for="<?php echo $this->get_field_id('morebutton_text'); ?>"><?php _e( 'More button text', 'upw' ); ?>:</label>
454
+ <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_text'); ?>" name="<?php echo $this->get_field_name('morebutton_text'); ?>" value="<?php echo $morebutton_text; ?>" />
455
+ </p>
456
+
457
+ <p>
458
+ <label for="<?php echo $this->get_field_id('morebutton_url'); ?>"><?php _e( 'More button URL', 'upw' ); ?>:</label>
459
+ <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_url'); ?>" name="<?php echo $this->get_field_name('morebutton_url'); ?>" value="<?php echo $morebutton_url; ?>" />
460
+ </p>
461
+
462
+ <hr class="upw-divider">
463
+
464
+ <h4>Post Display</h4>
465
+
466
+ <p>
467
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" type="checkbox" <?php checked( (bool) $show_title, true ); ?> />
468
+ <label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Show title', 'upw' ); ?></label>
469
+ </p>
470
+
471
+ <p>
472
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" type="checkbox" <?php checked( (bool) $show_date, true ); ?> />
473
+ <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show published date', 'upw' ); ?></label>
474
+ </p>
475
+
476
+ <p>
477
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_time' ); ?>" name="<?php echo $this->get_field_name( 'show_time' ); ?>" type="checkbox" <?php checked( (bool) $show_time, true ); ?> />
478
+ <label for="<?php echo $this->get_field_id( 'show_time' ); ?>"><?php _e( 'Show published time', 'upw' ); ?></label>
479
+ </p>
480
+
481
+ <p>
482
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_author' ); ?>" name="<?php echo $this->get_field_name( 'show_author' ); ?>" type="checkbox" <?php checked( (bool) $show_author, true ); ?> />
483
+ <label for="<?php echo $this->get_field_id( 'show_author' ); ?>"><?php _e( 'Show post author', 'upw' ); ?></label>
484
+ </p>
485
+
486
+ <p>
487
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_excerpt' ); ?>" name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" type="checkbox" <?php checked( (bool) $show_excerpt, true ); ?> />
488
+ <label for="<?php echo $this->get_field_id( 'show_excerpt' ); ?>"><?php _e( 'Show excerpt', 'upw' ); ?></label>
489
+ </p>
490
+
491
+ <p>
492
+ <label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e( 'Excerpt length (in words)', 'upw' ); ?>:</label>
493
+ <input style="text-align: center;" type="text" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" size="3" />
494
+ </p>
495
+
496
+ <p>
497
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_content' ); ?>" name="<?php echo $this->get_field_name( 'show_content' ); ?>" type="checkbox" <?php checked( (bool) $show_content, true ); ?> />
498
+ <label for="<?php echo $this->get_field_id( 'show_content' ); ?>"><?php _e( 'Show content', 'upw' ); ?></label>
499
+ </p>
500
+
501
+ <p>
502
+ <label for="<?php echo $this->get_field_id('show_readmore'); ?>">
503
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_readmore'); ?>" name="<?php echo $this->get_field_name('show_readmore'); ?>"<?php checked( (bool) $show_readmore, true ); ?> />
504
+ <?php _e( 'Show read more link', 'upw' ); ?>
505
+ </label>
506
+ </p>
507
+
508
+ <p>
509
+ <label for="<?php echo $this->get_field_id('excerpt_readmore'); ?>"><?php _e( 'Read more text', 'upw' ); ?>:</label>
510
+ <input class="widefat" type="text" id="<?php echo $this->get_field_id('excerpt_readmore'); ?>" name="<?php echo $this->get_field_name('excerpt_readmore'); ?>" value="<?php echo $excerpt_readmore; ?>" />
511
+ </p>
512
+
513
+ <?php if ( function_exists('the_post_thumbnail') && current_theme_supports( 'post-thumbnails' ) ) : ?>
514
+
515
+ <p>
516
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" type="checkbox" <?php checked( (bool) $show_thumbnail, true ); ?> />
517
+ <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show thumbnail', 'upw' ); ?></label>
518
+ </p>
519
+
520
+ <p>
521
+ <label><?php _e('Thumbnail size', 'upw'); ?>:</label>
522
+ <br />
523
+ <label for="<?php echo $this->get_field_id('thumb_w'); ?>">
524
+ <?php _e('W', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_w'); ?>" name="<?php echo $this->get_field_name('thumb_w'); ?>" value="<?php echo $thumb_w; ?>" />
525
+ </label>
526
+ <label for="<?php echo $this->get_field_id('thumb_h'); ?>">
527
+ <?php _e('H', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_h'); ?>" name="<?php echo $this->get_field_name('thumb_h'); ?>" value="<?php echo $thumb_h; ?>" />
528
+ </label>
529
+ </p>
530
+
531
+ <p>
532
+ <label><?php _e('Crop mode', 'upw'); ?>:</label>
533
+ <br />
534
+ <select id="<?php echo $this->get_field_id('thumb_crop'); ?>" name="<?php echo $this->get_field_name('thumb_crop'); ?>">
535
+ <option value="1"<?php if($thumb_crop == 1) echo ' selected'; ?>><?php _e('Scale &amp; Crop to Fit', 'upw'); ?></option>
536
+ <option value="0"<?php if($thumb_crop == 0) echo ' selected'; ?>><?php _e('Stretch to Fit', 'upw'); ?></option>
537
+ <option value="2"<?php if($thumb_crop == 2) echo ' selected'; ?>><?php _e('Proportional Scale', 'upw'); ?></option>
538
+ <option value="3"<?php if($thumb_crop == 3) echo ' selected'; ?>><?php _e('Proportional Scale No Borders', 'upw'); ?></option>
539
+ </select>
540
+ </p>
541
+
542
+ <?php endif; ?>
543
+
544
+ <p>
545
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_cats'); ?>" name="<?php echo $this->get_field_name('show_cats'); ?>" <?php checked( (bool) $show_cats, true ); ?> />
546
+ <label for="<?php echo $this->get_field_id('show_cats'); ?>"> <?php _e('Show post categories', 'upw'); ?></label>
547
+ </p>
548
+
549
+ <p>
550
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_tags'); ?>" name="<?php echo $this->get_field_name('show_tags'); ?>" <?php checked( (bool) $show_tags, true ); ?> />
551
+ <label for="<?php echo $this->get_field_id('show_tags'); ?>"> <?php _e('Show post tags', 'upw'); ?></label>
552
+ </p>
553
+
554
+ <p>
555
+ <label for="<?php echo $this->get_field_id( 'custom_fields' ); ?>"><?php _e( 'Show Custom Fields (comma separated)', 'upw' ); ?>:</label>
556
+ <input class="widefat" id="<?php echo $this->get_field_id( 'custom_fields' ); ?>" name="<?php echo $this->get_field_name( 'custom_fields' ); ?>" type="text" value="<?php echo $custom_fields; ?>" />
557
+ </p>
558
+
559
+ <hr class="upw-divider">
560
+
561
+ <h4>Filters</h4>
562
+
563
+ <p>
564
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atcat'); ?>" name="<?php echo $this->get_field_name('atcat'); ?>" <?php checked( (bool) $atcat, true ); ?> />
565
+ <label for="<?php echo $this->get_field_id('atcat'); ?>"> <?php _e('Show posts only from current category', 'upw');?></label>
566
+ </p>
567
+
568
+ <p>
569
+ <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e( 'Categories', 'upw' ); ?>:</label>
570
+ <select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
571
+ <?php
572
+ $categories = get_categories( 'hide_empty=0' );
573
+ foreach ($categories as $category ) { ?>
574
+ <option value="<?php echo $category->term_id; ?>" <?php if( in_array($category->term_id, $cats)) { echo 'selected="selected"'; } ?>><?php echo $category->cat_name;?></option>
575
+ <?php } ?>
576
+ </select>
577
+ </p>
578
+
579
+ <p>
580
+ <label for="<?php echo $this->get_field_id('types'); ?>"><?php _e( 'Post types', 'upw' ); ?>:</label>
581
+ <select name="<?php echo $this->get_field_name('types'); ?>[]" id="<?php echo $this->get_field_id('types'); ?>" class="widefat" style="height: auto;" size="<?php echo $n ?>" multiple>
582
+ <?php
583
+ $args = array( 'public' => true );
584
+ $post_types = get_post_types( $args, 'names' );
585
+ foreach ($post_types as $post_type ) { ?>
586
+ <option value="<?php echo $post_type; ?>" <?php if( in_array($post_type, $types)) { echo 'selected="selected"'; } ?>><?php echo $post_type;?></option>
587
+ <?php } ?>
588
+ </select>
589
+ </p>
590
+
591
+ <p>
592
+ <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e( 'Sticky posts', 'upw' ); ?>:</label>
593
+ <select name="<?php echo $this->get_field_name('sticky'); ?>" id="<?php echo $this->get_field_id('sticky'); ?>" class="widefat">
594
+ <option value="show"<?php if( $sticky === 'show') echo ' selected'; ?>><?php _e('Show All Posts', 'upw'); ?></option>
595
+ <option value="hide"<?php if( $sticky == 'hide') echo ' selected'; ?>><?php _e('Hide Sticky Posts', 'upw'); ?></option>
596
+ <option value="only"<?php if( $sticky == 'only') echo ' selected'; ?>><?php _e('Show Only Sticky Posts', 'upw'); ?></option>
597
+ </select>
598
+ </p>
599
+
600
+ <hr class="upw-divider">
601
+
602
+ <h4>Order</h4>
603
+
604
+ <p>
605
+ <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
606
+ <option value="date"<?php if( $orderby == 'date') echo ' selected'; ?>><?php _e('Published Date', 'upw'); ?></option>
607
+ <option value="title"<?php if( $orderby == 'title') echo ' selected'; ?>><?php _e('Title', 'upw'); ?></option>
608
+ <option value="comment_count"<?php if( $orderby == 'comment_count') echo ' selected'; ?>><?php _e('Comment Count', 'upw'); ?></option>
609
+ <option value="rand"<?php if( $orderby == 'rand') echo ' selected'; ?>><?php _e('Random'); ?></option>
610
+ </select>
611
+ </p>
612
+
613
+ <p>
614
+ <select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
615
+ <option value="DESC"<?php if( $order == 'DESC') echo ' selected'; ?>><?php _e('Descending', 'upw'); ?></option>
616
+ <option value="ASC"<?php if( $order == 'ASC') echo ' selected'; ?>><?php _e('Ascending', 'upw'); ?></option>
617
+ </select>
618
+ </p>
619
+
620
+ <p class="credits"><small><?php _e('Developed by', 'upw'); ?> <a href="http://pomelodesign.com">Pomelo Design</a></small></p>
621
+
622
+ <?php if ( $instance ) { ?>
623
+
624
+ <script>
625
+
626
+ jQuery(document).ready(function($){
627
+
628
+ var show_excerpt = $("#<?php echo $this->get_field_id( 'show_excerpt' ); ?>");
629
+ var show_readmore = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>");
630
+ var show_thumbnail = $("#<?php echo $this->get_field_id( 'show_thumbnail' ); ?>");
631
+ var excerpt_length = $("#<?php echo $this->get_field_id( 'excerpt_length' ); ?>").parents('p');
632
+ var excerpt_readmore = $("#<?php echo $this->get_field_id( 'excerpt_readmore' ); ?>").parents('p');
633
+ var thumb_w = $("#<?php echo $this->get_field_id( 'thumb_w' ); ?>").parents('p');
634
+ var thumb_crop = $("#<?php echo $this->get_field_id( 'thumb_crop' ); ?>").parents('p');
635
+ var show_morebutton = $("#<?php echo $this->get_field_id( 'show_morebutton' ); ?>");
636
+ var morebutton_text = $("#<?php echo $this->get_field_id( 'morebutton_text' ); ?>").parents('p');
637
+ var morebutton_url = $("#<?php echo $this->get_field_id( 'morebutton_url' ); ?>").parents('p');
638
+
639
+ <?php
640
+ // Use PHP to determine if not checked and hide if so
641
+ // jQuery method was acting up
642
+ if ( !$show_excerpt ) {
643
+ echo 'excerpt_length.hide();';
644
+ }
645
+ if ( !$show_readmore ) {
646
+ echo 'excerpt_readmore.hide();';
647
+ }
648
+ if ( !$show_thumbnail ) {
649
+ echo 'thumb_w.hide();';
650
+ echo 'thumb_crop.hide();';
651
+ }
652
+ if ( !$show_morebutton ) {
653
+ echo 'morebutton_text.hide();';
654
+ echo 'morebutton_url.hide();';
655
+ }
656
+ ?>
657
+
658
+ // Toggle excerpt length on click
659
+ show_excerpt.click(function(){
660
+
661
+ if ( $(this).is(":checked") ) {
662
+ excerpt_length.show("fast");
663
+ } else {
664
+ excerpt_length.hide("fast");
665
+ }
666
+
667
+ });
668
+
669
+ // Toggle excerpt length on click
670
+ show_readmore.click(function(){
671
+
672
+ if ( $(this).is(":checked") ) {
673
+ excerpt_readmore.show("fast");
674
+ } else {
675
+ excerpt_readmore.hide("fast");
676
+ }
677
+
678
+ });
679
+
680
+ // Toggle excerpt length on click
681
+ show_thumbnail.click(function(){
682
+
683
+ if ( $(this).is(":checked") ) {
684
+ thumb_w.show("fast");
685
+ thumb_crop.show("fast");
686
+ } else {
687
+ thumb_w.hide("fast");
688
+ thumb_crop.hide("fast");
689
+ }
690
 
691
+ });
692
+
693
+ // Toggle more button on click
694
+ show_morebutton.click(function(){
695
 
696
+ if ( $(this).is(":checked") ) {
697
+ morebutton_text.show("fast");
698
+ morebutton_url.show("fast");
699
+ } else {
700
+ morebutton_text.hide("fast");
701
+ morebutton_url.hide("fast");
702
+ }
703
 
704
+ });
705
+
706
+ });
707
 
708
+ </script>
709
 
710
+ <?php
711
 
712
+ }
713
 
714
+ }
715
 
716
+ }
717
 
718
+ function init_WP_Widget_Ultimate_Posts() {
719
+
720
+ register_widget( 'WP_Widget_Ultimate_Posts' );
721
+
722
+ }
723
+
724
+ add_action( 'widgets_init', 'init_WP_Widget_Ultimate_Posts' );
725
 
726
  }