Image Widget - Version 3.0

Version Description

Download this release

Release Info

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

Code changes from version 2.2.2 to 3.0

Files changed (4) hide show
  1. image-widget.js +22 -0
  2. image-widget.php +123 -519
  3. readme.txt +11 -7
  4. screenshot-1.png +0 -0
image-widget.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function set_active_widget(imageId,widthId,heightId) {
2
+ // establish which widget is being updated
3
+ currentImageId = imageId;
4
+ currentWidthId = widthId;
5
+ currentHeightId = heightId;
6
+ }
7
+ function send_to_editor(h) {
8
+ vars = eval(h);
9
+
10
+ // store attachment id in hidden field
11
+ jQuery( '#'+currentImageId ).val( vars[0] );
12
+
13
+ // display attachment preview
14
+ jQuery( '#display-'+currentImageId ).html( vars[1] );
15
+ jQuery( '#display-'+currentImageId+' > img' ).css({
16
+ 'max-width':jQuery( '#'+currentWidthId ).val()+'px',
17
+ 'max-height':jQuery( '#'+currentHeightId ).val()+'px'
18
+ });
19
+
20
+ // close thickbox
21
+ tb_remove();
22
+ }
image-widget.php CHANGED
@@ -1,562 +1,166 @@
1
  <?php
2
-
3
  /*
4
  Plugin Name: Image Widget
5
  Plugin URI: http://www.shaneandpeter.com/wordpress
6
- Description: This widget accepts a title, a link and an image and displays them. The admin panel is separated from the widget to offer independant control
7
- Author: Shane and Peter, Inc. [Contributors: Kevin Miller, Nick Ohrn]
8
- Version: 2.2.2
9
  Author URI: http://www.shaneandpeter.com
10
  */
11
 
12
  /*
13
- Feature Ideas
14
 
15
- * Settings in the widget editor that mirror the Editor view
16
- * Size setting in the widget editor
17
 
18
  */
19
 
20
- class sp_image_widget {
21
-
22
- var $options = array(
23
- 'widget_options' => array(
24
- 'classname' => 'widget_sp_image',
25
- 'description' => 'Showcase a single image with a Title/URL/Description'
26
- ),
27
- 'control_options' => array(
28
- 'width' => null,
29
- 'height' => 200,
30
- 'id_base' => 'sp_image'
31
- ),
32
- 'default_widget_options' => array(
33
- 'title' => '',
34
- 'link' => '',
35
- 'linktarget' => '',
36
- 'description' => '',
37
- 'image' => ''
38
- ),
39
- 'widget_name' => 'Image Widget'
40
- );
41
-
42
- var $admin_menu_header = 'Image Widgets';
43
-
44
- var $is_admin_page = false;
45
 
46
- var $is_widget_id = false;
47
 
48
- // Setup Widget
49
- function sp_image_widget() {
50
-
51
- $this->is_admin_page = (isset($_GET['page']) && $_GET['page'] == $this->options['control_options']['id_base']) ? true : false;
52
- $this->is_widget_id = (isset($_GET['widget_id'])) ? $_GET['widget_id'] : false;
53
-
54
- add_action('admin_head', array(&$this, 'admin_head'));
55
- add_action('admin_menu', array(&$this, 'admin_menu'));
 
 
 
56
  }
57
-
58
- // Admin Header
59
- function admin_head() {
60
 
61
- // TODO: Submit this as a patch to Wordpress
62
- //
63
- // FIX: Fixes the control div from hiccupping when it opens.
64
- ?>
65
-
66
- <style type="text/css">
67
-
68
- .widget-control {
69
- padding: 0px !important;
70
- }
71
-
72
- .widget-control div.widget-control-actions {
73
- padding: 15px 15px 15px 15px !important;
74
- }
75
-
76
- .widget-control p {
77
- padding: 15px 15px 0 15px !important;
78
- }
79
-
80
- </style>
81
-
82
- <?php
83
- }
84
-
85
- // Admin Menu
86
- function admin_menu() {
87
- add_management_page($this->options['widget_name'], $this->options['widget_name'], 5, $this->options['control_options']['id_base'], array(&$this, 'control'));
88
- }
89
-
90
- // Get Widget Options
91
- function get_options() {
92
- return get_option('widget_' . $this->options['control_options']['id_base']);
93
  }
94
 
95
- // Set Widget Options
96
- function update_options($options) {
97
- return update_option('widget_' . $this->options['control_options']['id_base'], $options);
 
 
 
 
98
  }
99
 
100
-
101
- // Display Widget Output
102
- function widget($arguments, $widget_arguments = 1) {
103
-
104
- extract($arguments, EXTR_SKIP);
105
-
106
- if (is_numeric($widget_arguments)) {
107
- $widget_arguments = array( 'number' => $widget_arguments );
108
- }
109
- $widget_arguments = wp_parse_args($widget_arguments, array('number' => -1));
110
- extract($widget_arguments, EXTR_SKIP);
111
-
112
- $options = $this->get_options();
113
- if (!isset($options[$number])) {
114
- return;
115
- }
116
-
117
- $widget_options = $options[$number];
118
-
119
-
120
- $link = !empty($widget_options['link']);
121
- $linktarget = !empty($widget_options['linktarget']);
122
-
123
  echo $before_widget;
124
-
125
-
126
- if (!empty($widget_options['title'])) {
127
- echo $before_title;
128
- echo $widget_options['title'];
129
- echo $after_title;
130
- }
131
-
132
- if (!empty($widget_options['image'])) {
133
-
134
- if ($link) {
135
- echo '<a class="' . $this->options['widget_options']['classname'] . '-image-link" href="' . $widget_options['link'] . '" target="' . $widget_options['linktarget'] . '">';
136
  }
137
-
138
- echo '<img class="' . $this->options['widget_options']['classname'] . '-image" src="' . $widget_options['image'] . '" alt="image widget" />';
139
-
140
- if ($link) {
141
- echo '</a>';
142
  }
143
 
 
144
  }
145
-
146
- if (!empty($widget_options['description'])) {
147
-
148
- echo '<p class="' . $this->options['widget_options']['classname'] . '-description" >';
149
- if ($link) {
150
- echo '<a class="' . $this->options['widget_options']['classname'] . '-image-link-p" href="' . $widget_options['link'] . '" target="' . $widget_options['linktarget'] . '">';
151
  }
152
-
153
- echo html_entity_decode($widget_options['description']);
154
-
155
- if ($link) { echo '</a>'; }
156
-
157
  echo "</p>";
158
-
159
  }
160
-
161
  echo $after_widget;
162
-
163
  }
164
 
165
-
166
- // Widget Registration
167
- function register() {
168
-
169
- if (!$options = $this->get_options()) {
170
- $options = array();
171
- }
172
-
173
- $id = false;
174
-
175
- foreach (array_keys($options) as $option) {
176
- $widget_options = array_merge(array(), $this->options);
177
-
178
- $id = $this->options['control_options']['id_base'] . '-' . $option;
179
-
180
- wp_register_sidebar_widget($id, $this->options['widget_name'], array(&$this, 'widget'), $this->options['widget_options'], array('number' => $option));
181
- wp_register_widget_control($id, $this->options['widget_name'], array(&$this, 'control'), $this->options['control_options'], array('number' => $option));
182
- }
183
-
184
- if (!$id) {
185
- wp_register_sidebar_widget($this->options['control_options']['id_base'] . '-1', $this->options['widget_name'], array(&$this, 'widget'), $this->options['widget_options'], array('number' => -1));
186
- wp_register_widget_control($this->options['control_options']['id_base'] . '-1', $this->options['widget_name'], array(&$this, 'control'), $this->options['control_options'], array('number' => -1));
187
- }
188
- }
189
-
190
-
191
- // Widget Controller
192
- function control($widget_arguments = 1) {
193
-
194
- global $wp_registered_sidebars, $wp_registered_widgets;
195
- static $updated = false;
196
-
197
- if (is_numeric($widget_arguments)) {
198
- $widget_arguments = array('number' => $widget_arguments);
199
- }
200
- $widget_arguments = wp_parse_args( $widget_arguments, array('number' => -1));
201
- extract($widget_arguments, EXTR_SKIP);
202
-
203
- $options = $this->get_options();
204
- if (!is_array($options)) {
205
- $options = array();
206
- }
207
-
208
- if ((!$updated && !empty($_POST['sidebar'])) || ($this->is_admin_page)) {
209
-
210
- $sidebar = (string) $_POST['sidebar'];
211
-
212
- $sidebars_widgets = wp_get_sidebars_widgets();
213
- if (isset($sidebars_widgets[$sidebar])) {
214
- $this_sidebar =& $sidebars_widgets[$sidebar];
215
  } else {
216
- $this_sidebar = array();
217
- }
218
- }
219
-
220
-
221
- // Widget Control
222
- if (!$updated && !empty($_POST['sidebar'])) {
223
-
224
- foreach ($this_sidebar as $_widget_id) {
225
-
226
- if ('widget_' . $this->options['control_options']['id_base'] == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
227
-
228
- $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
229
-
230
- if (!in_array($this->options['control_options']['id_base'] . '-$widget_number', $_POST['widget-id'])) {
231
- unset($options[$widget_number]);
232
- }
233
- }
234
- }
235
-
236
- //
237
- // UNCOMMENT TO USE THE WIDGET CONTROL FOR UPDATING THE INFORMATION INSTEAD, WILL NEED THE FORM PROCESSING CODE
238
- //
239
- foreach ((array) $_POST['widget-' . $this->options['control_options']['id_base']] as $widget_number => $widget_image_instance) {
240
-
241
- $new_options = array_merge($this->options['default_widget_options'], array());
242
-
243
- // ---------- Update Options: CUSTOM ---------- //
244
-
245
- // WE DON'T USE THIS AS WE DON'T HAVE
246
- // FORM IN THE WIDGET CONTROL!!!
247
-
248
- // ---------- Update Options: CUSTOM ---------- //
249
-
250
- if (!isset($options[$widget_number])) {
251
- $options[$widget_number] = $new_options;
252
- }
253
  }
254
-
255
- $this->update_options($options);
256
-
257
- $updated = true;
258
-
259
  }
260
-
261
- $number = ($number == -1 ? '%i%' : $number);
262
-
263
- // ---------- CUSTOMIZATIONS FOR ADMIN MENU AS WELL AS WIDGET CONTROL ---------- //
264
- if ($this->is_admin_page):
265
-
266
- // Process Form Submission
267
- if ($_POST[$this->options['control_options']['id_base'] . '-submit']) {
268
-
269
- $new_options = array_merge($this->options['default_widget_options'], array());
270
-
271
- // ---------- Update Options: CUSTOM ---------- //
272
-
273
- // strip off the sidebar ID that we appended in the dropdown form for navigation
274
- $split_it = explode('&',$_POST['sp_image_admin_dropdown']);
275
-
276
- $_POST['sp_image_admin_dropdown'] = $split_it[0];
277
-
278
- // sanitize the title by removing all non ASCII characters - this include funky quotes, etc. from Word documents
279
- $new_options['title'] = $_POST[$this->options['control_options']['id_base'] . '-title'];
280
- $new_options['title'] = ereg_replace("[^A-Za-z0-9 _!-@#$%^&*()_+={}\":<>?/.,;'|\\~`]", "", $new_options['title']);
281
- $new_options['title'] = htmlentities(stripslashes($new_options['title']));
282
-
283
- $new_options['link'] = htmlentities(stripslashes($_POST[$this->options['control_options']['id_base'] . '-link']));
284
-
285
- $new_options['linktarget'] = htmlentities(stripslashes($_POST[$this->options['control_options']['id_base'] . '-linktarget']));
286
-
287
- $new_options['description'] = $_POST[$this->options['control_options']['id_base'] . '-description'];
288
- $new_options['description'] = ereg_replace("[^A-Za-z0-9 _!-@#$%^&*()_+={}\":<>?/.,;'|\\~`]", "", $new_options['description']);
289
- $new_options['description'] = htmlentities(stripslashes($new_options['description']));
290
-
291
- if ($_FILES[$this->options['control_options']['id_base'] . '-image']['size'] > 0) {
292
-
293
- $file = wp_handle_upload($_FILES[$this->options['control_options']['id_base'] . '-image'], array('test_form' => false, 'unique_filename_callback' => array($this,'sp_unique_filename') ));
294
-
295
- // Required Debug
296
- if (isset($file['error'])) {
297
- die($file['error']);
298
- }
299
-
300
- $_url = str_replace(basename($file['file']), '', $file['url']);
301
- $_path = str_replace(basename($file['file']), '', $file['file']);
302
- $_extension = explode('/', $_FILES[$this->options['control_options']['id_base'] . '-image']['type']);
303
- $_target = $this->options['control_options']['id_base'] . '-' . $_POST['sp_image_admin_dropdown'] . '-' . time() . '.' . $_extension[1];
304
-
305
- rename($file['file'], $_path . $_target);
306
-
307
- $url = $_url . $_target;
308
- $type = $file['type'];
309
- $file = $_path . $_target;
310
- $file_name = basename($file);
311
-
312
- // Construct the object array
313
- $_post_object = array(
314
- 'post_title' => $file_name,
315
- 'post_content' => $url,
316
- 'post_mime_type' => $type,
317
- 'guid' => $url
318
- );
319
-
320
- $_post_id = wp_insert_attachment($_post_object, $file);
321
- list($width, $height, $type, $attributes) = getimagesize($file);
322
-
323
- wp_update_attachment_metadata($id, wp_generate_attachment_metadata($_post_id, $file));
324
-
325
- do_action('wp_create_file_in_uploads', $file, $_post_id);
326
-
327
- $new_options['image'] = htmlentities(stripslashes($url));
328
-
329
- } else {
330
- $new_options['image'] = $options[$_POST['sp_image_admin_dropdown']]['image'];
331
- }
332
-
333
- $options[$_POST['sp_image_admin_dropdown']] = $new_options;
334
-
335
- // ---------- Update Options: CUSTOM ---------- //
336
-
337
- $this->update_options($options);
338
- }
339
-
340
- $dropdown = array();
341
- $first_widget_id = false;
342
- $first_sidebar = false;
343
-
344
- foreach ($sidebars_widgets as $_sidebar => $_widgets) {
345
-
346
- if (!isset($dropdown[$_sidebar])) {
347
- $dropdown[$_sidebar] = array();
348
- }
349
-
350
- foreach ($sidebars_widgets[$_sidebar] as $_widget) {
351
-
352
- $_t = explode('-', $_widget);
353
- $_widget_class = $_t[0];
354
- $_widget_id = $_t[1];
355
-
356
- if (isset($options[$_widget_id])) {
357
-
358
- $first_widget_id = $first_widget_id ? $first_widget_id : $_widget_id;
359
- $first_sidebar = $first_sidebar ? $first_sidebar : $_sidebar;
360
-
361
- array_push($dropdown[$_sidebar],
362
- array(
363
- 'id' => $_widget_id,
364
- 'classname' => $_widget_class,
365
- 'options' => $options[$_widget_id],
366
- 'selected' => (($this->is_widget_id == $_widget_id) ? true : false)
367
- )
368
- );
369
-
370
- }
371
-
372
- }
373
-
374
- }
375
-
376
- if ($this->is_widget_id && isset($options[$this->is_widget_id])) {
377
- $form_options = $options[$this->is_widget_id];
378
- } else {
379
- $form_options = $options[$first_widget_id];
380
- $dropdown[$first_sidebar][0]['selected'] = true;
381
- }
382
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  ?>
384
-
385
- <div class="wrap">
386
-
387
- <h2><?php echo $this->admin_menu_header; ?></h2>
388
-
389
- <?php if (!$first_widget_id): ?>
390
-
391
- <p>
392
- You must add a widget to a sidebar (Design &raquo; Widgets) before you can edit one.
393
- </p>
394
-
395
- <?php else: ?>
396
-
397
- <form name="form_<?php echo $this->options['control_options']['id_base']; ?>" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>" enctype="multipart/form-data">
398
 
399
- <p>
400
- Select which Image Widget you would like to edit.
401
- </p>
402
-
403
- <p>
404
 
405
- <select id="sp_image_admin_dropdown" name="sp_image_admin_dropdown" style="width: 400px;" >
406
-
407
- <?php foreach ($dropdown as $_sidebar => $_info):
408
-
409
- $_widget_count = 1;
410
-
411
- foreach ($dropdown[$_sidebar] as $_widget):
412
-
413
-
414
- echo '<option value="' . $_widget['id'] . '&sidebar=' . $_sidebar . '"';
415
- if ($_widget['selected']) { echo ' SELECTED '; }
416
- echo '>' . $wp_registered_sidebars[$_sidebar]['name'] . '&nbsp;&raquo;&nbsp;' . $this->ordinalize($_widget_count) . ' widget</option>';
417
-
418
- $_widget_count++;
419
-
420
- endforeach;
421
-
422
- endforeach; ?>
423
-
424
- </select>
425
-
426
- <script type='text/javascript'>
427
- /* <![CDATA[ */
428
- var sp_image_admin_dropdown = document.getElementById('sp_image_admin_dropdown');
429
- sp_image_admin_dropdown.onchange = function() {
430
- widget_num = sp_image_admin_dropdown.options[sp_image_admin_dropdown.selectedIndex].value.split('&');
431
- if (widget_num[0] > 0) {
432
- location.href = '<?php echo get_option('home'); ?>/wp-admin/tools.php?page=<?php echo $this->options['control_options']['id_base']; ?>&widget_id=' + sp_image_admin_dropdown.options[sp_image_admin_dropdown.selectedIndex].value;
433
- }
434
- }
435
- /* ]]> */
436
- </script>
437
-
438
- </p>
439
-
440
- <table class="form-table">
441
- <tbody>
442
-
443
- <tr>
444
- <th>
445
- <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][title]"><?php echo _e('Title:') ?></label>
446
- </th>
447
- <td>
448
- <input type="text" id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][title]" name="<?php echo $this->options['control_options']['id_base']; ?>-title" value="<?php echo $form_options['title']; ?>" />
449
- </td>
450
- </tr>
451
-
452
- <tr>
453
- <th>
454
- <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][link]"><?php echo _e('Link:'); ?></label>
455
- </th>
456
- <td>
457
- <input type="text" id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][link]" name="<?php echo $this->options['control_options']['id_base']; ?>-link" value="<?php echo $form_options['link']; ?>" >
458
- <select id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][linktarget]" name="<?php echo $this->options['control_options']['id_base']; ?>-linktarget">
459
- <option value="_self"<?php if ($form_options['linktarget']=="_self") { echo " selected"; } ?>>Same Window</option>
460
- <option value="_blank"<?php if ($form_options['linktarget']=="_blank") { echo " selected"; } ?>>New Window</option>
461
- </select>
462
- </td>
463
- </tr>
464
-
465
- <tr>
466
- <th>
467
- <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][description]"><?php echo _e('Description:'); ?></label>
468
- </th>
469
- <td>
470
- <textarea type="text" id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][description]" name="<?php echo $this->options['control_options']['id_base']; ?>-description"><?php echo $form_options['description']; ?></textarea>
471
- </td>
472
- </tr>
473
- <tr>
474
- <th>
475
- <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][image]"><?php echo _e('Image:'); ?></label>
476
- </th>
477
- <td>
478
- <input type="file" id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][image]" name="<?php echo $this->options['control_options']['id_base']; ?>-image" />
479
- </td>
480
- </tr>
481
-
482
- <tr>
483
- <th>
484
- <label><?php echo _e('Preview Image:'); ?></label>
485
- </th>
486
- <td>
487
- <?php if ($form_options['image']): ?>
488
- <img src="<?php echo $form_options['image']; ?>" border="0" />
489
- <?php endif; ?>
490
- </td>
491
- </tr>
492
-
493
- </tbody>
494
- </table>
495
-
496
- <p class="submit">
497
- <input type="submit" value="Save" id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][submit]" name="<?php echo $this->options['control_options']['id_base']; ?>-submit" value="1" />
498
- </p>
499
-
500
- <?php echo wp_nonce_field($this->options['control_options']['id_base']); ?>
501
-
502
- </form>
503
-
504
- <?php endif; ?>
505
-
506
- </div>
507
-
508
- <?php else: ?>
509
-
510
- <p>
511
- <small>To edit the properties of this widget visit:
512
- <br />
513
- <?php if ($_GET['sidebar']) $_sidebar = $_GET['sidebar']; else $_sidebar = 'sidebar-1'; ?>
514
- Manage &raquo; <a href="../wp-admin/tools.php?page=<?php echo $this->options['control_options']['id_base']; ?>&widget_id=<?php echo $number; ?>&sidebar=<?php echo $_sidebar; ?>"><?php echo $this->options['widget_name']; ?></a></small>
515
- <input type="hidden" id="widget-sp_image-submit-<?php echo $number; ?>" name="widget-sp_image[<?php echo $number; ?>][submit]" value="1" />
516
- </p>
517
-
518
  <?php
519
- endif;
520
-
521
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
 
523
-
524
- // Widget Positioning Suffixes
525
- function ordinalize($number) {
526
-
527
- if (in_array(($number % 100), range(11, 13))) {
528
- return $number . 'th';
529
- } else {
530
-
531
- switch (($number % 10)) {
532
- case 1:
533
-
534
- return $number . 'st';
535
- break;
536
-
537
- case 2:
538
-
539
- return $number . 'nd';
540
- break;
541
-
542
- case 3:
543
-
544
- return $number . 'rd';
545
-
546
- default:
547
-
548
- return $number . 'th';
549
- break;
550
- }
551
- }
552
  }
553
-
554
  }
555
-
556
- // Instantiate class
557
- $sp_image = new sp_image_widget();
558
-
559
- // Load actions
560
- add_action('widgets_init', array($sp_image, 'register'));
561
-
562
  ?>
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
8
  Author URI: http://www.shaneandpeter.com
9
  */
10
 
11
  /*
12
+ Bugs
13
 
14
+ * reclicking Add image doesn't work
 
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' ) );
27
+ $control_ops = array( 'id_base' => 'widget_sp_image' );
28
+ $this->WP_Widget('widget_sp_image', __('Image Widget'), $widget_ops, $control_ops);
29
+
30
+ if (WP_ADMIN) {
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
+ /**/
41
+ // Get attachment and resize but return attachment path (needs to return url)
42
+ $attachment = wp_get_attachment_metadata( $id );
43
+ $attachment_url = wp_get_attachment_url( $id );
44
+ if (isset($attachment_url)) {
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
+ }
53
+ if (isset($image)) {
54
+ return $image;
55
+ }
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' )";
63
+ } else {
64
+ return $html;
65
+ }
66
  }
67
 
68
+ function widget( $args, $instance ) {
69
+ extract($args);
70
+ $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  echo $before_widget;
72
+ if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
73
+ if (!empty($instance['image'])) {
74
+ if ($instance['link']) {
75
+ echo '<a class="'.$instance['classname'].'-image-link" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
 
 
 
 
 
 
 
 
76
  }
77
+
78
+ if ($instance['imageurl']) {
79
+ echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" />";
 
 
80
  }
81
 
82
+ if ($instance['link']) { echo '</a>'; }
83
  }
84
+ if (!empty($instance['description'])) {
85
+ $text = apply_filters( 'widget_text', $instance['description'] );
86
+ echo '<p class="'.$this->widget_ops['classname'].'-description" >';
87
+ if ($instance['link']) {
88
+ echo '<a class="'.$this->widget_ops['classname'].'-image-link-p" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
 
89
  }
90
+ echo wpautop($text);
91
+ if ($instance['link']) { echo '</a>'; }
 
 
 
92
  echo "</p>";
 
93
  }
 
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']);
100
+ if ( isset($new_instance['description']) ) {
101
+ if ( current_user_can('unfiltered_html') ) {
102
+ $instance['description'] = $new_instance['description'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  } else {
104
+ $instance['description'] = wp_filter_post_kses($new_instance['description']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
 
 
 
 
 
106
  }
107
+ $instance['link'] = $new_instance['link'];
108
+ $instance['image'] = $new_instance['image'];
109
+ $instance['imageurl'] = $this->get_image_url($new_instance['image'],$new_instance['width'],$new_instance['height']);
110
+ $instance['linktarget'] = $new_instance['linktarget'];
111
+ $instance['width'] = $new_instance['width'];
112
+ $instance['height'] = $new_instance['height'];
113
+
114
+ return $instance;
115
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
+ function form( $instance ) {
118
+
119
+ $instance = wp_parse_args( (array) $instance, array(
120
+ 'title' => '',
121
+ 'description' => '',
122
+ 'link' => '',
123
+ 'linktarget' => '',
124
+ 'width' => '',
125
+ 'height' => '',
126
+ 'image' => '',
127
+ 'imageurl' => ''
128
+ ) );
129
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
132
+ <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>
 
 
 
133
 
134
+ <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:'); ?></label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  <?php
136
+ $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.
137
+ $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
138
+ $image_title = __('Add an Image');
139
+ ?><br />
140
+ <a href="<?php echo $image_upload_iframe_src; ?>&TB_iframe=true" id="add_image-<?php echo $this->get_field_id('image'); ?>" class="thickbox" 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>
141
+ <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
142
+ if ($instance['imageurl']) { echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" />"; }
143
+ ?></div>
144
+ <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
145
+ </p>
146
+
147
+ <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Description:'); ?></label>
148
+ <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>
149
+
150
+ <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:'); ?></label>
151
+ <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 />
152
+ <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
153
+ <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window'); ?></option>
154
+ <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window'); ?></option>
155
+ </select></p>
156
+
157
+ <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:'); ?></label>
158
+ <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>
159
+
160
+ <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:'); ?></label>
161
+ <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>
162
 
163
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  }
 
165
  }
 
 
 
 
 
 
 
166
  ?>
readme.txt CHANGED
@@ -2,17 +2,17 @@
2
  Contributors: Shane & Peter, Inc.
3
  Donate link: http://www.shaneandpeter.com
4
  Tags: widget, image, ad, banner, simple
5
- Requires at least: 2.0
6
- Tested up to: 2.7.1
7
- Stable tag: 2.2.2
8
 
9
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
10
 
11
  == Description ==
12
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
13
 
14
- todo:
15
- * support image sizing (maybe)
16
 
17
  == Installation ==
18
 
@@ -26,13 +26,17 @@ todo:
26
  1. In your WordPress administration, go to the Plugins page
27
  1. Activate the Image Widget plugin and a subpage for the plugin will appear
28
  in your Manage menu.
29
- 1. Go to the Design > Widget page and place the widget in your sidebar in the Design
30
- 1. Go to Manage > Image Widget to add a title, link, and image.
31
 
32
  If you find any bugs or have any ideas, please mail us.
33
 
34
  == Changelog ==
35
 
 
 
 
 
 
36
  New in version 2.2.2
37
 
38
  * Update <li> to be $before_widget and $after_widget (Thanks again to Lois Turley)
2
  Contributors: Shane & Peter, Inc.
3
  Donate link: http://www.shaneandpeter.com
4
  Tags: widget, image, ad, banner, simple
5
+ Requires at least: 2.8
6
+ Tested up to: 2.8.4
7
+ Stable tag: 3.0
8
 
9
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
10
 
11
  == Description ==
12
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
13
 
14
+ Todo:
15
+ * Add an image breaks after save is clicked
16
 
17
  == Installation ==
18
 
26
  1. In your WordPress administration, go to the Plugins page
27
  1. Activate the Image Widget plugin and a subpage for the plugin will appear
28
  in your Manage menu.
29
+ 1. Go to the Appearance > Widget page and place the widget in your sidebar in the Design
 
30
 
31
  If you find any bugs or have any ideas, please mail us.
32
 
33
  == Changelog ==
34
 
35
+ New in version 3.0
36
+
37
+ * Completely remodeled the plugin to use the native wordpress uploader and be compatible with Wordpress 2.8 plugin architecture.
38
+ * Removed externalized widget admin.
39
+
40
  New in version 2.2.2
41
 
42
  * Update <li> to be $before_widget and $after_widget (Thanks again to Lois Turley)
screenshot-1.png CHANGED
Binary file