Image Widget - Version 3.2

Version Description

  • Abstract views for widget output and widget admin.
  • Support theme override of the widget output! Now you can layout the widget however you'd like.
  • Added filter to override template call.
Download this release

Release Info

Developer peterchester
Plugin Icon 128x128 Image Widget
Version 3.2
Comparing to
See all releases

Code changes from version 3.1.6 to 3.2

Files changed (4) hide show
  1. image-widget.php +31 -99
  2. readme.txt +32 -3
  3. views/widget-admin.php +56 -0
  4. views/widget.php +37 -0
image-widget.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Image Widget
4
  Plugin URI: http://wordpress.org/extend/plugins/image-widget/
5
  Description: Simple image widget that uses native Wordpress upload thickbox to add image widgets to your site.
6
  Author: Shane and Peter, Inc.
7
- Version: 3.1.6
8
  Author URI: http://www.shaneandpeter.com
9
  */
10
 
@@ -163,7 +163,6 @@ class SP_Image_Widget extends WP_Widget {
163
  win.IW_align = '<?php echo $align ?>';
164
  win.IW_url = '<?php echo $url ?>';
165
  win.IW_size = '<?php echo $size ?>';
166
- //alert("sending variables: id: "+win.IW_img_id+"\n"+"alt: "+win.IW_alt+"\n"+"title: "+win.IW_title+"\n"+"align: "+win.IW_align+"\n"+"url: "+win.IW_url+"\n"+"size: "+win.IW_size);
167
  </script>
168
  <?php
169
  }
@@ -194,43 +193,11 @@ class SP_Image_Widget extends WP_Widget {
194
  * @author Shane & Peter, Inc. (Peter Chester)
195
  */
196
  function widget( $args, $instance ) {
197
- extract($args);
198
- $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
199
- echo $before_widget;
200
- if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
201
- if (!empty($instance['image'])) {
202
- if ($instance['link']) {
203
- echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
204
- }
205
- if ($instance['imageurl']) {
206
- echo "<img src=\"{$instance['imageurl']}\" style=\"";
207
- if (!empty($instance['width']) && is_numeric($instance['width'])) {
208
- echo "max-width: {$instance['width']}px;";
209
- }
210
- if (!empty($instance['height']) && is_numeric($instance['height'])) {
211
- echo "max-height: {$instance['height']}px;";
212
- }
213
- echo "\"";
214
- if (!empty($instance['align']) && $instance['align'] != 'none') {
215
- echo " class=\"align{$instance['align']}\"";
216
- }
217
- if (!empty($instance['alt'])) {
218
- echo " alt=\"{$instance['alt']}\"";
219
- } else {
220
- echo " alt=\"{$instance['title']}\"";
221
- }
222
- echo " />";
223
- }
224
-
225
- if ($instance['link']) { echo '</a>'; }
226
- }
227
- if (!empty($instance['description'])) {
228
- $text = apply_filters( 'widget_text', $instance['description'] );
229
- echo '<div class="'.$this->widget_options['classname'].'-description" >';
230
- echo wpautop($text);
231
- echo "</div>";
232
- }
233
- echo $after_widget;
234
  }
235
 
236
  /**
@@ -284,65 +251,7 @@ class SP_Image_Widget extends WP_Widget {
284
  'align' => '',
285
  'alt' => ''
286
  ) );
287
- ?>
288
-
289
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', $this->pluginDomain); ?></label>
290
- <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['title'])); ?>" /></p>
291
-
292
- <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', $this->pluginDomain); ?></label>
293
- <?php
294
- $media_upload_iframe_src = "media-upload.php?type=image&widget_id=".$this->id; //NOTE #1: the widget id is added here to allow uploader to only return array if this is used with image widget so that all other uploads are not harmed.
295
- $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
296
- $image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), $this->pluginDomain);
297
- ?><br />
298
- <a href="<?php echo $image_upload_iframe_src; ?>&TB_iframe=true" id="add_image-<?php echo $this->get_field_id('image'); ?>" class="thickbox-image-widget" title='<?php echo $image_title; ?>' onClick="set_active_widget('<?php echo $this->id; ?>');return false;" style="text-decoration:none"><img src='images/media-button-image.gif' alt='<?php echo $image_title; ?>' align="absmiddle" /> <?php echo $image_title; ?></a>
299
- <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
300
- if ($instance['imageurl']) {
301
- echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
302
- if ($instance['width'] && is_numeric($instance['width'])) {
303
- echo "max-width: {$instance['width']}px;";
304
- }
305
- if ($instance['height'] && is_numeric($instance['height'])) {
306
- echo "max-height: {$instance['height']}px;";
307
- }
308
- echo "\"";
309
- if (!empty($instance['align']) && $instance['align'] != 'none') {
310
- echo " class=\"align{$instance['align']}\"";
311
- }
312
- echo " />";
313
- }
314
- ?></div>
315
- <br clear="all" />
316
- <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
317
- </p>
318
-
319
- <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Caption:', $this->pluginDomain); ?></label>
320
- <textarea rows="8" class="widefat" id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>"><?php echo format_to_edit($instance['description']); ?></textarea></p>
321
-
322
- <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', $this->pluginDomain); ?></label>
323
- <input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['link'])); ?>" /><br />
324
- <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
325
- <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', $this->pluginDomain); ?></option>
326
- <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', $this->pluginDomain); ?></option>
327
- </select></p>
328
-
329
- <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', $this->pluginDomain); ?></label>
330
- <input id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['width'])); ?>" onchange="changeImgWidth('<?php echo $this->id; ?>')" /></p>
331
-
332
- <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', $this->pluginDomain); ?></label>
333
- <input id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['height'])); ?>" onchange="changeImgHeight('<?php echo $this->id; ?>')" /></p>
334
-
335
- <p><label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', $this->pluginDomain); ?></label>
336
- <select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" onchange="changeImgAlign('<?php echo $this->id; ?>')">
337
- <option value="none"<?php selected( $instance['align'], 'none' ); ?>><?php _e('none', $this->pluginDomain); ?></option>
338
- <option value="left"<?php selected( $instance['align'], 'left' ); ?>><?php _e('left', $this->pluginDomain); ?></option>
339
- <option value="center"<?php selected( $instance['align'], 'center' ); ?>><?php _e('center', $this->pluginDomain); ?></option>
340
- <option value="right"<?php selected( $instance['align'], 'right' ); ?>><?php _e('right', $this->pluginDomain); ?></option>
341
- </select></p>
342
-
343
- <p><label for="<?php echo $this->get_field_id('alt'); ?>"><?php _e('Alternate Text:', $this->pluginDomain); ?></label>
344
- <input id="<?php echo $this->get_field_id('alt'); ?>" name="<?php echo $this->get_field_name('alt'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['alt'])); ?>" /></p>
345
- <?php
346
  }
347
 
348
  /**
@@ -362,5 +271,28 @@ class SP_Image_Widget extends WP_Widget {
362
  </style>
363
  <?php
364
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  }
366
- ?>
4
  Plugin URI: http://wordpress.org/extend/plugins/image-widget/
5
  Description: Simple image widget that uses native Wordpress upload thickbox to add image widgets to your site.
6
  Author: Shane and Peter, Inc.
7
+ Version: 3.2
8
  Author URI: http://www.shaneandpeter.com
9
  */
10
 
163
  win.IW_align = '<?php echo $align ?>';
164
  win.IW_url = '<?php echo $url ?>';
165
  win.IW_size = '<?php echo $size ?>';
 
166
  </script>
167
  <?php
168
  }
193
  * @author Shane & Peter, Inc. (Peter Chester)
194
  */
195
  function widget( $args, $instance ) {
196
+ extract( $args );
197
+ extract( $instance );
198
+ $title = apply_filters( 'widget_title', empty( $title ) ? '' : $title );
199
+
200
+ include( $this->getTemplateHierarchy( 'widget' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
 
203
  /**
251
  'align' => '',
252
  'alt' => ''
253
  ) );
254
+ include( $this->getTemplateHierarchy( 'widget-admin' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  }
256
 
257
  /**
271
  </style>
272
  <?php
273
  }
274
+
275
+ /**
276
+ * Loads theme files in appropriate hierarchy: 1) child theme,
277
+ * 2) parent template, 3) plugin resources. will look in the image-widget/
278
+ * directory in a theme and the views/ directory in the plugin
279
+ *
280
+ * @param string $template template file to search for
281
+ * @return template path
282
+ * @author Shane & Peter, Inc. (Matt Wiebe)
283
+ **/
284
+
285
+ public function getTemplateHierarchy($template) {
286
+ // whether or not .php was added
287
+ $template_slug = rtrim($template, '.php');
288
+ $template = $template_slug . '.php';
289
+
290
+ if ( $theme_file = locate_template(array('image-widget/'.$template)) ) {
291
+ $file = $theme_file;
292
+ } else {
293
+ $file = 'views/' . $template;
294
+ }
295
+ return apply_filters( 'sp_template_image-widget_'.$template, $file);
296
+ }
297
  }
298
+ ?>
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: Shane & Peter, Inc.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4BSPTNFFY6AL6
4
  Tags: widget, image, ad, banner, simple, upload, sidebar, admin, thickbox, resize
5
- Requires at least: 2.8
6
- Tested up to: 3.0
7
- Stable tag: 3.1.6
8
 
9
  == Description ==
10
 
@@ -17,6 +17,7 @@ Simple image widget that uses native Wordpress upload thickbox to add image widg
17
  * Very versatile. All fields are optional.
18
  * Upload, link to external image, or select an image from your media collection using the built in thickbox browser.
19
  * Language Support for German (feel free to contribute other languages)
 
20
 
21
  This plugin is actively supported and we will do our best to help you. In return we simply as 3 things:
22
 
@@ -42,8 +43,36 @@ If you find any bugs or have any ideas, please mail us.
42
 
43
  Please visit the forum for questions or comments: http://wordpress.org/tags/image-widget/
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  == Changelog ==
46
 
 
 
 
 
 
 
47
  = 3.1.6 =
48
 
49
  Fixed Wordpress 3.0 bugs. (Thanks kenvunz)
2
  Contributors: Shane & Peter, Inc.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4BSPTNFFY6AL6
4
  Tags: widget, image, ad, banner, simple, upload, sidebar, admin, thickbox, resize
5
+ Requires at least: 3.0
6
+ Tested up to: 3.0.1
7
+ Stable tag: 3.2
8
 
9
  == Description ==
10
 
17
  * Very versatile. All fields are optional.
18
  * Upload, link to external image, or select an image from your media collection using the built in thickbox browser.
19
  * Language Support for German (feel free to contribute other languages)
20
+ * Supports override of template so that you can override the template for your theme!
21
 
22
  This plugin is actively supported and we will do our best to help you. In return we simply as 3 things:
23
 
43
 
44
  Please visit the forum for questions or comments: http://wordpress.org/tags/image-widget/
45
 
46
+ = Requirements =
47
+
48
+ * PHP 5.1 or above
49
+ * WordPress 3.0 or above
50
+
51
+ == Documentation ==
52
+
53
+ The built in template can be overridden by files within your template.
54
+
55
+ = Default vs. Custom Templates =
56
+
57
+ The Image Widget comes with a default template for the widget output. If you would like to alter the widget display code, create a new folder called "image-widget" in your template directory and copy over the "views/widget.php" file.
58
+
59
+ Edit the new file to your hearts content. Please do not edit the one in the plugin folder as that will cause conflicts when you update the plugin to the latest release.
60
+
61
+ New in 3.2: You may now also use the "sp_template_image-widget_widget" filter to override the default template behavior for .php template files. Eg: if you wanted widget.php to reside in a folder called my-custom-templates/ and wanted it to be called my-custom-name.php:
62
+
63
+ `add_filter('sp_template_image-widget_widget', 'my_template_filter');
64
+ function my_template_filter($template) {
65
+ return get_template_directory() . '/my-custom-templates/my-custom-name.php';
66
+ }`
67
+
68
  == Changelog ==
69
 
70
+ = 3.2 =
71
+
72
+ * Abstract views for widget output and widget admin.
73
+ * Support theme override of the widget output! Now you can layout the widget however you'd like.
74
+ * Added filter to override template call.
75
+
76
  = 3.1.6 =
77
 
78
  Fixed Wordpress 3.0 bugs. (Thanks kenvunz)
views/widget-admin.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', $this->pluginDomain); ?></label>
2
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['title'])); ?>" /></p>
3
+
4
+ <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', $this->pluginDomain); ?></label>
5
+ <?php
6
+ $media_upload_iframe_src = "media-upload.php?type=image&widget_id=".$this->id; //NOTE #1: the widget id is added here to allow uploader to only return array if this is used with image widget so that all other uploads are not harmed.
7
+ $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
8
+ $image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), $this->pluginDomain);
9
+ ?><br />
10
+ <a href="<?php echo $image_upload_iframe_src; ?>&TB_iframe=true" id="add_image-<?php echo $this->get_field_id('image'); ?>" class="thickbox-image-widget" title='<?php echo $image_title; ?>' onClick="set_active_widget('<?php echo $this->id; ?>');return false;" style="text-decoration:none"><img src='images/media-button-image.gif' alt='<?php echo $image_title; ?>' align="absmiddle" /> <?php echo $image_title; ?></a>
11
+ <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
12
+ if ($instance['imageurl']) {
13
+ echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
14
+ if ($instance['width'] && is_numeric($instance['width'])) {
15
+ echo "max-width: {$instance['width']}px;";
16
+ }
17
+ if ($instance['height'] && is_numeric($instance['height'])) {
18
+ echo "max-height: {$instance['height']}px;";
19
+ }
20
+ echo "\"";
21
+ if (!empty($instance['align']) && $instance['align'] != 'none') {
22
+ echo " class=\"align{$instance['align']}\"";
23
+ }
24
+ echo " />";
25
+ }
26
+ ?></div>
27
+ <br clear="all" />
28
+ <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
29
+ </p>
30
+
31
+ <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Caption:', $this->pluginDomain); ?></label>
32
+ <textarea rows="8" class="widefat" id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>"><?php echo format_to_edit($instance['description']); ?></textarea></p>
33
+
34
+ <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', $this->pluginDomain); ?></label>
35
+ <input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['link'])); ?>" /><br />
36
+ <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
37
+ <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', $this->pluginDomain); ?></option>
38
+ <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', $this->pluginDomain); ?></option>
39
+ </select></p>
40
+
41
+ <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', $this->pluginDomain); ?></label>
42
+ <input id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['width'])); ?>" onchange="changeImgWidth('<?php echo $this->id; ?>')" /></p>
43
+
44
+ <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', $this->pluginDomain); ?></label>
45
+ <input id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['height'])); ?>" onchange="changeImgHeight('<?php echo $this->id; ?>')" /></p>
46
+
47
+ <p><label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', $this->pluginDomain); ?></label>
48
+ <select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" onchange="changeImgAlign('<?php echo $this->id; ?>')">
49
+ <option value="none"<?php selected( $instance['align'], 'none' ); ?>><?php _e('none', $this->pluginDomain); ?></option>
50
+ <option value="left"<?php selected( $instance['align'], 'left' ); ?>><?php _e('left', $this->pluginDomain); ?></option>
51
+ <option value="center"<?php selected( $instance['align'], 'center' ); ?>><?php _e('center', $this->pluginDomain); ?></option>
52
+ <option value="right"<?php selected( $instance['align'], 'right' ); ?>><?php _e('right', $this->pluginDomain); ?></option>
53
+ </select></p>
54
+
55
+ <p><label for="<?php echo $this->get_field_id('alt'); ?>"><?php _e('Alternate Text:', $this->pluginDomain); ?></label>
56
+ <input id="<?php echo $this->get_field_id('alt'); ?>" name="<?php echo $this->get_field_name('alt'); ?>" type="text" value="<?php echo esc_attr(strip_tags($instance['alt'])); ?>" /></p>
views/widget.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ echo $before_widget;
3
+ if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
4
+ if ( !empty( $image ) ) {
5
+ if ( $link ) {
6
+ echo '<a class="'.$this->widget_options['classname'].'-image-link" href="'.$link.'" target="'.$linktarget.'">';
7
+ }
8
+ if ( $imageurl ) {
9
+ echo "<img src=\"{$imageurl}\" style=\"";
10
+ if ( !empty( $width ) && is_numeric( $width ) ) {
11
+ echo "max-width: {$width}px;";
12
+ }
13
+ if ( !empty( $height ) && is_numeric( $height ) ) {
14
+ echo "max-height: {$height}px;";
15
+ }
16
+ echo "\"";
17
+ if ( !empty( $align ) && $align != 'none' ) {
18
+ echo " class=\"align{$align}\"";
19
+ }
20
+ if ( !empty( $alt ) ) {
21
+ echo " alt=\"{$alt}\"";
22
+ } else {
23
+ echo " alt=\"{$title}\"";
24
+ }
25
+ echo " />";
26
+ }
27
+
28
+ if ( $link ) { echo '</a>'; }
29
+ }
30
+ if ( !empty( $description ) ) {
31
+ $text = apply_filters( 'widget_text', $description );
32
+ echo '<div class="'.$this->widget_options['classname'].'-description" >';
33
+ echo wpautop( $text );
34
+ echo "</div>";
35
+ }
36
+ echo $after_widget;
37
+ ?>