PluginProbe ʕ •ᴥ•ʔ
Image Widget / 3.0.4
Image Widget v3.0.4
trunk 1.0 2.0 2.1 2.2 2.2.1 2.2.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.2 3.2.1 3.2.10 3.2.11 3.2.2 3.2.3 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1 4.1.1 4.1.2 4.2 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9
image-widget / image-widget.php
image-widget Last commit date
image-widget.js 16 years ago image-widget.php 16 years ago readme.txt 16 years ago screenshot-1.png 16 years ago
image-widget.php
220 lines
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.4
8 Author URI: http://www.shaneandpeter.com
9 */
10
11 // Load the widget on widgets_init
12 function load_sp_image_widget() {
13 register_widget('SP_Image_Widget');
14 }
15 add_action('widgets_init', 'load_sp_image_widget');
16
17 /**
18 * SP Image Widget class
19 *
20 * @author Shane & Peter, Inc. (Peter Chester)
21 **/
22 class SP_Image_Widget extends WP_Widget {
23
24 /**
25 * SP Image Widget constructor
26 *
27 * @return void
28 * @author Shane & Peter, Inc. (Peter Chester)
29 */
30 function SP_Image_Widget() {
31 $widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', 'sp_image_widget' ) );
32 $control_ops = array( 'id_base' => 'widget_sp_image' );
33 $this->WP_Widget('widget_sp_image', __('Image Widget', 'sp_image_widget'), $widget_ops, $control_ops);
34
35 if (WP_ADMIN) {
36 wp_enqueue_script( 'thickbox' );
37 wp_enqueue_style( 'thickbox' );
38 wp_enqueue_script( $control_ops['id_base'], WP_PLUGIN_URL.'/image-widget/image-widget.js' );
39 add_filter( 'image_send_to_editor', array( $this,'image_send_to_editor'), 10, 7 );
40 }
41 }
42
43 /**
44 * Retrieve resized image URL
45 *
46 * @param int $id Post ID or Attachment ID
47 * @param int $width desired width of image (optional)
48 * @param int $height desired height of image (optional)
49 * @return string URL
50 * @author Shane & Peter, Inc. (Peter Chester)
51 */
52 function get_image_url( $id, $width=false, $height=false ) {
53
54 /**/
55 // Get attachment and resize but return attachment path (needs to return url)
56 $attachment = wp_get_attachment_metadata( $id );
57 $attachment_url = wp_get_attachment_url( $id );
58 if (isset($attachment_url)) {
59 if ($width && $height) {
60 $uploads = wp_upload_dir();
61 $imgpath = $uploads['basedir'].'/'.$attachment['file'];
62 if ($image = image_resize( $imgpath, $width, $height )) {
63 $image = path_join( dirname($attachment_url), basename($image) );
64 } else {
65 $image = $attachment_url;
66 }
67 } else {
68 $image = $attachment_url;
69 }
70 if (isset($image)) {
71 return $image;
72 }
73 }
74 }
75
76 /**
77 * Filter image_end_to_editor results
78 *
79 * @param string $html
80 * @param int $id
81 * @param string $alt
82 * @param string $title
83 * @param string $align
84 * @param string $url
85 * @param array $size
86 * @return string javascript array of attachment url and id or just the url
87 * @author Shane & Peter, Inc. (Peter Chester)
88 */
89 function image_send_to_editor( $html, $id, $alt, $title, $align, $url, $size ) {
90 if (strpos($_REQUEST['_wp_http_referer'],$this->id)) { // check that this is for the widget. SEE NOTE #1
91 $img = addslashes('<img src="' . wp_get_attachment_url( $id ) . '" />');
92 return "new Array ( '$id', '$img' )";
93 } else {
94 return $html;
95 }
96 }
97
98 /**
99 * Widget frontend output
100 *
101 * @param array $args
102 * @param array $instance
103 * @return void
104 * @author Shane & Peter, Inc. (Peter Chester)
105 */
106 function widget( $args, $instance ) {
107 extract($args);
108 $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
109 echo $before_widget;
110 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
111 if (!empty($instance['image'])) {
112 if ($instance['link']) {
113 echo '<a class="'.$instance['classname'].'-image-link" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
114 }
115
116 if ($instance['imageurl']) {
117 echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" />";
118 }
119
120 if ($instance['link']) { echo '</a>'; }
121 }
122 if (!empty($instance['description'])) {
123 $text = apply_filters( 'widget_text', $instance['description'] );
124 echo '<p class="'.$this->widget_ops['classname'].'-description" >';
125 if ($instance['link']) {
126 echo '<a class="'.$this->widget_ops['classname'].'-image-link-p" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
127 }
128 echo wpautop($text);
129 if ($instance['link']) { echo '</a>'; }
130 echo "</p>";
131 }
132 echo $after_widget;
133 }
134
135 /**
136 * Update widget options
137 *
138 * @param object $new_instance Widget Instance
139 * @param object $old_instance Widget Instance
140 * @return object
141 * @author Shane & Peter, Inc. (Peter Chester)
142 */
143 function update( $new_instance, $old_instance ) {
144 $instance = $old_instance;
145 $instance['title'] = strip_tags($new_instance['title']);
146 if ( isset($new_instance['description']) ) {
147 if ( current_user_can('unfiltered_html') ) {
148 $instance['description'] = $new_instance['description'];
149 } else {
150 $instance['description'] = wp_filter_post_kses($new_instance['description']);
151 }
152 }
153 $instance['link'] = $new_instance['link'];
154 $instance['image'] = $new_instance['image'];
155 $instance['imageurl'] = $this->get_image_url($new_instance['image'],$new_instance['width'],$new_instance['height']);
156 $instance['linktarget'] = $new_instance['linktarget'];
157 $instance['width'] = $new_instance['width'];
158 $instance['height'] = $new_instance['height'];
159
160 return $instance;
161 }
162
163 /**
164 * Form UI
165 *
166 * @param object $instance Widget Instance
167 * @return void
168 * @author Shane & Peter, Inc. (Peter Chester)
169 */
170 function form( $instance ) {
171
172 $instance = wp_parse_args( (array) $instance, array(
173 'title' => '',
174 'description' => '',
175 'link' => '',
176 'linktarget' => '',
177 'width' => '',
178 'height' => '',
179 'image' => '',
180 'imageurl' => ''
181 ) );
182 ?>
183
184 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'sp_image_widget'); ?></label>
185 <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>
186
187 <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', 'sp_image_widget'); ?></label>
188 <?php
189 $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.
190 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
191 $image_title = __('Add an Image', 'sp_image_widget');
192 ?><br />
193 <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->get_field_id('image'); ?>','<?php echo $this->get_field_id('width'); ?>','<?php echo $this->get_field_id('height'); ?>');return false;"><img src='images/media-button-image.gif' alt='<?php echo $image_title; ?>' /> <?php echo $image_title; ?></a>
194 <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
195 if ($instance['imageurl']) { echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" />"; }
196 ?></div>
197 <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
198 </p>
199
200 <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Description:', 'sp_image_widget'); ?></label>
201 <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>
202
203 <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', 'sp_image_widget'); ?></label>
204 <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 />
205 <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
206 <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', 'sp_image_widget'); ?></option>
207 <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', 'sp_image_widget'); ?></option>
208 </select></p>
209
210 <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'sp_image_widget'); ?></label>
211 <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'])); ?>" /></p>
212
213 <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'sp_image_widget'); ?></label>
214 <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'])); ?>" /></p>
215
216 <?php
217 }
218 }
219 ?>
220