Image Widget - Version 3.0.2

Version Description

Download this release

Release Info

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

Code changes from version 3.0.1 to 3.0.2

Files changed (2) hide show
  1. image-widget.php +69 -8
  2. readme.txt +5 -1
image-widget.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: Image Widget
4
- Plugin URI: http://www.shaneandpeter.com/wordpress
5
  Description: This widget accepts a title, an image, a link and a description and displays them.
6
  Author: Shane and Peter, Inc.
7
- Version: 3.0.1
8
  Author URI: http://www.shaneandpeter.com
9
  */
10
 
@@ -15,13 +15,26 @@ Bugs
15
 
16
  */
17
 
 
 
18
  function load_sp_image_widget() {
19
  register_widget('SP_Image_Widget');
20
  }
21
  add_action('widgets_init', 'load_sp_image_widget');
22
 
 
 
 
 
 
23
  class SP_Image_Widget extends WP_Widget {
24
-
 
 
 
 
 
 
25
  function SP_Image_Widget() {
26
  $widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', 'sp_image_widget' ) );
27
  $control_ops = array( 'id_base' => 'widget_sp_image' );
@@ -31,10 +44,19 @@ class SP_Image_Widget extends WP_Widget {
31
  wp_enqueue_script( 'thickbox' );
32
  wp_enqueue_style( 'thickbox' );
33
  wp_enqueue_script( $control_ops['id_base'], WP_PLUGIN_URL.'/image-widget/image-widget.js' );
34
- add_filter( 'image_send_to_editor', array( $this,'imageurl'), 10, 7 );
35
  }
36
  }
37
-
 
 
 
 
 
 
 
 
 
38
  function get_image_url( $id, $width=false, $height=false ) {
39
 
40
  /**/
@@ -45,8 +67,11 @@ class SP_Image_Widget extends WP_Widget {
45
  if ($width && $height) {
46
  $uploads = wp_upload_dir();
47
  $imgpath = $uploads['basedir'].'/'.$attachment['file'];
48
- $image = image_resize( $imgpath, $width, $height );
49
- $image = path_join( dirname($attachment_url), basename($image) );
 
 
 
50
  } else {
51
  $image = $attachment_url;
52
  }
@@ -56,7 +81,20 @@ class SP_Image_Widget extends WP_Widget {
56
  }
57
  }
58
 
59
- function imageurl( $html, $id, $alt, $title, $align, $url, $size ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  if (strpos($_REQUEST['_wp_http_referer'],$this->id)) { // check that this is for the widget. SEE NOTE #1
61
  $img = addslashes('<img src="' . wp_get_attachment_url( $id ) . '" />');
62
  return "new Array ( '$id', '$img' )";
@@ -65,6 +103,14 @@ class SP_Image_Widget extends WP_Widget {
65
  }
66
  }
67
 
 
 
 
 
 
 
 
 
68
  function widget( $args, $instance ) {
69
  extract($args);
70
  $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
@@ -94,6 +140,14 @@ class SP_Image_Widget extends WP_Widget {
94
  echo $after_widget;
95
  }
96
 
 
 
 
 
 
 
 
 
97
  function update( $new_instance, $old_instance ) {
98
  $instance = $old_instance;
99
  $instance['title'] = strip_tags($new_instance['title']);
@@ -114,6 +168,13 @@ class SP_Image_Widget extends WP_Widget {
114
  return $instance;
115
  }
116
 
 
 
 
 
 
 
 
117
  function form( $instance ) {
118
 
119
  $instance = wp_parse_args( (array) $instance, array(
1
  <?php
2
  /*
3
  Plugin Name: Image Widget
4
+ Plugin URI: http://wordpress.org/extend/plugins/image-widget/
5
  Description: This widget accepts a title, an image, a link and a description and displays them.
6
  Author: Shane and Peter, Inc.
7
+ Version: 3.0.2
8
  Author URI: http://www.shaneandpeter.com
9
  */
10
 
15
 
16
  */
17
 
18
+
19
+ // Load the widget on widgets_init
20
  function load_sp_image_widget() {
21
  register_widget('SP_Image_Widget');
22
  }
23
  add_action('widgets_init', 'load_sp_image_widget');
24
 
25
+ /**
26
+ * SP Image Widget class
27
+ *
28
+ * @author Shane & Peter, Inc. (Peter Chester)
29
+ **/
30
  class SP_Image_Widget extends WP_Widget {
31
+
32
+ /**
33
+ * SP Image Widget constructor
34
+ *
35
+ * @return void
36
+ * @author Shane & Peter, Inc. (Peter Chester)
37
+ */
38
  function SP_Image_Widget() {
39
  $widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', 'sp_image_widget' ) );
40
  $control_ops = array( 'id_base' => 'widget_sp_image' );
44
  wp_enqueue_script( 'thickbox' );
45
  wp_enqueue_style( 'thickbox' );
46
  wp_enqueue_script( $control_ops['id_base'], WP_PLUGIN_URL.'/image-widget/image-widget.js' );
47
+ add_filter( 'image_send_to_editor', array( $this,'image_send_to_editor'), 10, 7 );
48
  }
49
  }
50
+
51
+ /**
52
+ * Retrieve resized image URL
53
+ *
54
+ * @param int $id Post ID or Attachment ID
55
+ * @param int $width desired width of image (optional)
56
+ * @param int $height desired height of image (optional)
57
+ * @return string URL
58
+ * @author Shane & Peter, Inc. (Peter Chester)
59
+ */
60
  function get_image_url( $id, $width=false, $height=false ) {
61
 
62
  /**/
67
  if ($width && $height) {
68
  $uploads = wp_upload_dir();
69
  $imgpath = $uploads['basedir'].'/'.$attachment['file'];
70
+ if ($image = image_resize( $imgpath, $width, $height )) {
71
+ $image = path_join( dirname($attachment_url), basename($image) );
72
+ } else {
73
+ $image = $attachment_url;
74
+ }
75
  } else {
76
  $image = $attachment_url;
77
  }
81
  }
82
  }
83
 
84
+ /**
85
+ * Filter image_end_to_editor results
86
+ *
87
+ * @param string $html
88
+ * @param int $id
89
+ * @param string $alt
90
+ * @param string $title
91
+ * @param string $align
92
+ * @param string $url
93
+ * @param array $size
94
+ * @return string javascript array of attachment url and id or just the url
95
+ * @author Shane & Peter, Inc. (Peter Chester)
96
+ */
97
+ function image_send_to_editor( $html, $id, $alt, $title, $align, $url, $size ) {
98
  if (strpos($_REQUEST['_wp_http_referer'],$this->id)) { // check that this is for the widget. SEE NOTE #1
99
  $img = addslashes('<img src="' . wp_get_attachment_url( $id ) . '" />');
100
  return "new Array ( '$id', '$img' )";
103
  }
104
  }
105
 
106
+ /**
107
+ * Widget frontend output
108
+ *
109
+ * @param array $args
110
+ * @param array $instance
111
+ * @return void
112
+ * @author Shane & Peter, Inc. (Peter Chester)
113
+ */
114
  function widget( $args, $instance ) {
115
  extract($args);
116
  $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
140
  echo $after_widget;
141
  }
142
 
143
+ /**
144
+ * Update widget options
145
+ *
146
+ * @param object $new_instance Widget Instance
147
+ * @param object $old_instance Widget Instance
148
+ * @return object
149
+ * @author Shane & Peter, Inc. (Peter Chester)
150
+ */
151
  function update( $new_instance, $old_instance ) {
152
  $instance = $old_instance;
153
  $instance['title'] = strip_tags($new_instance['title']);
168
  return $instance;
169
  }
170
 
171
+ /**
172
+ * Form UI
173
+ *
174
+ * @param object $instance Widget Instance
175
+ * @return void
176
+ * @author Shane & Peter, Inc. (Peter Chester)
177
+ */
178
  function form( $instance ) {
179
 
180
  $instance = wp_parse_args( (array) $instance, array(
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.shaneandpeter.com
4
  Tags: widget, image, ad, banner, simple, upload, sidebar
5
  Requires at least: 2.8
6
  Tested up to: 2.8.4
7
- Stable tag: 3.0.1
8
 
9
  Simple image widget. Use native Wordpress upload thickbox to add image widgets to your site.
10
 
@@ -31,6 +31,10 @@ Todo:
31
  If you find any bugs or have any ideas, please mail us.
32
 
33
  == Changelog ==
 
 
 
 
34
 
35
  New in version 3.0.1
36
 
4
  Tags: widget, image, ad, banner, simple, upload, sidebar
5
  Requires at least: 2.8
6
  Tested up to: 2.8.4
7
+ Stable tag: 3.0.2
8
 
9
  Simple image widget. Use native Wordpress upload thickbox to add image widgets to your site.
10
 
31
  If you find any bugs or have any ideas, please mail us.
32
 
33
  == Changelog ==
34
+ New in version 3.0.2
35
+
36
+ * Added PHPDoc comments
37
+ * Temporarily fixed install bug where no image is saved if resize is not working. (thank you Paul Kaiser from Champaign, Il for your helpful QA support)
38
 
39
  New in version 3.0.1
40