Image Widget - Version 2.2

Version Description

Download this release

Release Info

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

Code changes from version 2.1 to 2.2

Files changed (2) hide show
  1. image-widget.php +85 -54
  2. readme.txt +6 -1
image-widget.php CHANGED
@@ -5,10 +5,18 @@ 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.1
9
  Author URI: http://www.shaneandpeter.com
10
  */
11
 
 
 
 
 
 
 
 
 
12
  class sp_image_widget {
13
 
14
  var $options = array(
@@ -37,6 +45,7 @@ class sp_image_widget {
37
 
38
  var $is_widget_id = false;
39
 
 
40
  function sp_image_widget() {
41
 
42
  $this->is_admin_page = (isset($_GET['page']) && $_GET['page'] == $this->options['control_options']['id_base']) ? true : false;
@@ -46,6 +55,7 @@ class sp_image_widget {
46
  add_action('admin_menu', array(&$this, 'admin_menu'));
47
  }
48
 
 
49
  function admin_head() {
50
 
51
  // TODO: Submit this as a patch to Wordpress
@@ -72,18 +82,23 @@ class sp_image_widget {
72
  <?php
73
  }
74
 
 
75
  function admin_menu() {
76
  add_management_page($this->options['widget_name'], $this->options['widget_name'], 5, $this->options['control_options']['id_base'], array(&$this, 'control'));
77
  }
78
 
 
79
  function get_options() {
80
  return get_option('widget_' . $this->options['control_options']['id_base']);
81
  }
82
 
 
83
  function update_options($options) {
84
  return update_option('widget_' . $this->options['control_options']['id_base'], $options);
85
  }
86
 
 
 
87
  function widget($arguments, $widget_arguments = 1) {
88
 
89
  extract($arguments, EXTR_SKIP);
@@ -106,41 +121,51 @@ class sp_image_widget {
106
  $linktarget = !empty($widget_options['linktarget']);
107
 
108
  echo '<div id="'.$this->options['control_options']['id_base'].'-'.$number.'" class="widget '.$this->options['widget_options']['classname'].'">';
109
- ?>
110
- <?php //echo $before_title; ?>
 
 
 
 
 
 
 
111
 
112
- <?php if (!empty($widget_options['title'])): ?>
113
-
114
- <?= $before_title ?>
115
-
116
- <?= $widget_options['title'] ?>
117
-
118
- <?= $after_title ?>
119
-
120
- <?php endif; ?>
121
-
122
- <?php if (!empty($widget_options['image'])): ?>
123
 
124
- <?= ($link ? '<a class="' . $this->options['widget_options']['classname'] . '-image-link" href="' . $widget_options['link'] . '" target="' . $widget_options['linktarget'] . '">' : '') . '<img class="' . $this->options['widget_options']['classname'] . '-image" src="' . $widget_options['image'] . '" alt="image widget" />' . ($link ? '</a>' : '') ?>
125
-
126
- <?php endif; ?>
127
-
128
- <?php if (!empty($widget_options['description'])): ?>
129
-
130
- <p class="<?= $this->options['widget_options']['classname'] ?>-description" >
131
- <?= ($link ? '<a class="' . $this->options['widget_options']['classname'] . '-image-link-p" href="' . $widget_options['link'] . '" target="' . $widget_options['linktarget'] . '">' : '')?>
132
- <?= html_entity_decode($widget_options['description']) ?>
133
- <?= ($link ? '</a>' : '') ?></p>
134
-
135
- <?php endif; ?>
136
 
137
- <?= $after_widget ?>
 
 
 
 
 
 
 
 
 
138
 
139
- <?php
140
 
141
-
 
 
 
 
 
142
  }
143
 
 
 
144
  function register() {
145
 
146
  if (!$options = $this->get_options()) {
@@ -165,6 +190,7 @@ class sp_image_widget {
165
  }
166
 
167
 
 
168
  function control($widget_arguments = 1) {
169
 
170
  global $wp_registered_sidebars, $wp_registered_widgets;
@@ -360,7 +386,7 @@ class sp_image_widget {
360
 
361
  <div class="wrap">
362
 
363
- <h2><?= $this->admin_menu_header ?></h2>
364
 
365
  <?php if (!$first_widget_id): ?>
366
 
@@ -370,7 +396,7 @@ class sp_image_widget {
370
 
371
  <?php else: ?>
372
 
373
- <form name="form_<?= $this->options['control_options']['id_base'] ?>" method="post" action="<?= str_replace('%7E', '~', $_SERVER['REQUEST_URI']) ?>" enctype="multipart/form-data">
374
 
375
  <p>
376
  Select which Image Widget you would like to edit.
@@ -380,19 +406,22 @@ class sp_image_widget {
380
 
381
  <select id="sp_image_admin_dropdown" name="sp_image_admin_dropdown" style="width: 400px;" >
382
 
383
- <?php foreach ($dropdown as $_sidebar => $_info): ?>
384
 
385
- <?php $_widget_count = 1; ?>
386
 
387
- <?php foreach ($dropdown[$_sidebar] as $_widget): ?>
388
 
389
- <option value="<?= $_widget['id'].'&sidebar='.$_sidebar ?>" <?= ($_widget['selected'] ? ' SELECTED ' : '') ?>><?= $wp_registered_sidebars[$_sidebar]['name'] ?>&nbsp;&raquo;&nbsp;<?= $this->ordinalize($_widget_count) ?> widget</option>
 
 
 
390
 
391
- <?php $_widget_count++; ?>
392
 
393
- <?php endforeach; ?>
394
 
395
- <?php endforeach; ?>
396
 
397
  </select>
398
 
@@ -402,7 +431,7 @@ class sp_image_widget {
402
  sp_image_admin_dropdown.onchange = function() {
403
  widget_num = sp_image_admin_dropdown.options[sp_image_admin_dropdown.selectedIndex].value.split('&');
404
  if (widget_num[0] > 0) {
405
- location.href = '<?= get_option('home'); ?>/wp-admin/tools.php?page=<?= $this->options['control_options']['id_base'] ?>&widget_id=' + sp_image_admin_dropdown.options[sp_image_admin_dropdown.selectedIndex].value;
406
  }
407
  }
408
  /* ]]> */
@@ -415,20 +444,20 @@ class sp_image_widget {
415
 
416
  <tr>
417
  <th>
418
- <label for="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][title]"><?= _e('Title:') ?></label>
419
  </th>
420
  <td>
421
- <input type="text" id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][title]" name="<?= $this->options['control_options']['id_base'] ?>-title" value="<?= $form_options['title'] ?>" />
422
  </td>
423
  </tr>
424
 
425
  <tr>
426
  <th>
427
- <label for="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][link]"><?= _e('Link:') ?></label>
428
  </th>
429
  <td>
430
- <input type="text" id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][link]" name="<?= $this->options['control_options']['id_base'] ?>-link" value="<?= $form_options['link'] ?>" >
431
- <select id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][linktarget]" name="<?= $this->options['control_options']['id_base'] ?>-linktarget">
432
  <option value="_self"<?php if ($form_options['linktarget']=="_self") { echo " selected"; } ?>>Same Window</option>
433
  <option value="_blank"<?php if ($form_options['linktarget']=="_blank") { echo " selected"; } ?>>New Window</option>
434
  </select>
@@ -437,28 +466,28 @@ class sp_image_widget {
437
 
438
  <tr>
439
  <th>
440
- <label for="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][description]"><?= _e('Description:') ?></label>
441
  </th>
442
  <td>
443
- <textarea type="text" id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][description]" name="<?= $this->options['control_options']['id_base'] ?>-description"><?= $form_options['description'] ?></textarea>
444
  </td>
445
  </tr>
446
  <tr>
447
  <th>
448
- <label for="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][image]"><?= _e('Image:') ?></label>
449
  </th>
450
  <td>
451
- <input type="file" id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][image]" name="<?= $this->options['control_options']['id_base'] ?>-image" />
452
  </td>
453
  </tr>
454
 
455
  <tr>
456
  <th>
457
- <label><?= _e('Preview Image:') ?></label>
458
  </th>
459
  <td>
460
  <?php if ($form_options['image']): ?>
461
- <img src="<?= $form_options['image'] ?>" border="0" />
462
  <?php endif; ?>
463
  </td>
464
  </tr>
@@ -467,10 +496,10 @@ class sp_image_widget {
467
  </table>
468
 
469
  <p class="submit">
470
- <input type="submit" value="Save" id="<?= $this->options['control_options']['id_base'] ?>[<?= $number ?>][submit]" name="<?= $this->options['control_options']['id_base'] ?>-submit" value="1" />
471
  </p>
472
 
473
- <?= wp_nonce_field($this->options['control_options']['id_base']) ?>
474
 
475
  </form>
476
 
@@ -484,8 +513,8 @@ class sp_image_widget {
484
  <small>To edit the properties of this widget visit:
485
  <br />
486
  <?php if ($_GET['sidebar']) $_sidebar = $_GET['sidebar']; else $_sidebar = 'sidebar-1'; ?>
487
- Manage &raquo; <a href="../wp-admin/tools.php?page=<?= $this->options['control_options']['id_base'] ?>&widget_id=<?= $number ?>&sidebar=<?php echo $_sidebar; ?>"><?= $this->options['widget_name'] ?></a></small>
488
- <input type="hidden" id="widget-sp_image-submit-<?= $number ?>" name="widget-sp_image[<?= $number ?>][submit]" value="1" />
489
  </p>
490
 
491
  <?php
@@ -493,6 +522,8 @@ class sp_image_widget {
493
 
494
  }
495
 
 
 
496
  function ordinalize($number) {
497
 
498
  if (in_array(($number % 100), range(11, 13))) {
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
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(
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;
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
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);
121
  $linktarget = !empty($widget_options['linktarget']);
122
 
123
  echo '<div id="'.$this->options['control_options']['id_base'].'-'.$number.'" class="widget '.$this->options['widget_options']['classname'].'">';
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
+ echo "</div>\n";
164
+
165
  }
166
 
167
+
168
+ // Widget Registration
169
  function register() {
170
 
171
  if (!$options = $this->get_options()) {
190
  }
191
 
192
 
193
+ // Widget Controller
194
  function control($widget_arguments = 1) {
195
 
196
  global $wp_registered_sidebars, $wp_registered_widgets;
386
 
387
  <div class="wrap">
388
 
389
+ <h2><?php echo $this->admin_menu_header; ?></h2>
390
 
391
  <?php if (!$first_widget_id): ?>
392
 
396
 
397
  <?php else: ?>
398
 
399
+ <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">
400
 
401
  <p>
402
  Select which Image Widget you would like to edit.
406
 
407
  <select id="sp_image_admin_dropdown" name="sp_image_admin_dropdown" style="width: 400px;" >
408
 
409
+ <?php foreach ($dropdown as $_sidebar => $_info):
410
 
411
+ $_widget_count = 1;
412
 
413
+ foreach ($dropdown[$_sidebar] as $_widget):
414
 
415
+
416
+ echo '<option value="' . $_widget['id'] . '&sidebar=' . $_sidebar . '"';
417
+ if ($_widget['selected']) { echo ' SELECTED '; }
418
+ echo '>' . $wp_registered_sidebars[$_sidebar]['name'] . '&nbsp;&raquo;&nbsp;' . $this->ordinalize($_widget_count) . ' widget</option>';
419
 
420
+ $_widget_count++;
421
 
422
+ endforeach;
423
 
424
+ endforeach; ?>
425
 
426
  </select>
427
 
431
  sp_image_admin_dropdown.onchange = function() {
432
  widget_num = sp_image_admin_dropdown.options[sp_image_admin_dropdown.selectedIndex].value.split('&');
433
  if (widget_num[0] > 0) {
434
+ 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;
435
  }
436
  }
437
  /* ]]> */
444
 
445
  <tr>
446
  <th>
447
+ <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][title]"><?php echo _e('Title:') ?></label>
448
  </th>
449
  <td>
450
+ <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']; ?>" />
451
  </td>
452
  </tr>
453
 
454
  <tr>
455
  <th>
456
+ <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][link]"><?php echo _e('Link:'); ?></label>
457
  </th>
458
  <td>
459
+ <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']; ?>" >
460
+ <select id="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][linktarget]" name="<?php echo $this->options['control_options']['id_base']; ?>-linktarget">
461
  <option value="_self"<?php if ($form_options['linktarget']=="_self") { echo " selected"; } ?>>Same Window</option>
462
  <option value="_blank"<?php if ($form_options['linktarget']=="_blank") { echo " selected"; } ?>>New Window</option>
463
  </select>
466
 
467
  <tr>
468
  <th>
469
+ <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][description]"><?php echo _e('Description:'); ?></label>
470
  </th>
471
  <td>
472
+ <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>
473
  </td>
474
  </tr>
475
  <tr>
476
  <th>
477
+ <label for="<?php echo $this->options['control_options']['id_base']; ?>[<?php echo $number; ?>][image]"><?php echo _e('Image:'); ?></label>
478
  </th>
479
  <td>
480
+ <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" />
481
  </td>
482
  </tr>
483
 
484
  <tr>
485
  <th>
486
+ <label><?php echo _e('Preview Image:'); ?></label>
487
  </th>
488
  <td>
489
  <?php if ($form_options['image']): ?>
490
+ <img src="<?php echo $form_options['image']; ?>" border="0" />
491
  <?php endif; ?>
492
  </td>
493
  </tr>
496
  </table>
497
 
498
  <p class="submit">
499
+ <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" />
500
  </p>
501
 
502
+ <?php echo wp_nonce_field($this->options['control_options']['id_base']); ?>
503
 
504
  </form>
505
 
513
  <small>To edit the properties of this widget visit:
514
  <br />
515
  <?php if ($_GET['sidebar']) $_sidebar = $_GET['sidebar']; else $_sidebar = 'sidebar-1'; ?>
516
+ 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>
517
+ <input type="hidden" id="widget-sp_image-submit-<?php echo $number; ?>" name="widget-sp_image[<?php echo $number; ?>][submit]" value="1" />
518
  </p>
519
 
520
  <?php
522
 
523
  }
524
 
525
+
526
+ // Widget Positioning Suffixes
527
  function ordinalize($number) {
528
 
529
  if (in_array(($number % 100), range(11, 13))) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.1
8
 
9
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
10
 
@@ -33,6 +33,11 @@ If you find any bugs or have any ideas, please mail us.
33
 
34
  == Changelog ==
35
 
 
 
 
 
 
36
  New in version 2.1
37
 
38
  * Link Target
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
8
 
9
  Simple image widget. Allows for placement of an image in the sidebar without requiring Design access.
10
 
33
 
34
  == Changelog ==
35
 
36
+ New in version 2.2
37
+
38
+ * Fixed missing DIV close tag (Thank you Jesper Goos)
39
+ * Updated all short tags to proper php tags (Thank you Jonathan Volks from Mannix Marketing)
40
+
41
  New in version 2.1
42
 
43
  * Link Target