Image Widget - Version 3.3.4

Version Description

  • Fix javascript bugs in the widget admin UI. ( thanks for filing this @joo-joo )
  • Fix notices in php error log.
  • Add widget description filter $args and $instance ( thanks @jeffreyzinn )
  • Fixed localization and renamed key to 'image-widget'
Download this release

Release Info

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

Code changes from version 3.3.3 to 3.3.4

image-widget.js DELETED
@@ -1,198 +0,0 @@
1
- (function($){
2
-
3
- window.set_active_widget = function(instance_id) {
4
- self.IW_instance = instance_id;
5
- }
6
-
7
- function image_widget_send_to_editor(h) {
8
- // ignore content returned from media uploader and use variables passed to window instead
9
-
10
- // store attachment id in hidden field
11
- $( '#widget-'+self.IW_instance+'-image' ).val( self.IW_img_id );
12
-
13
- // display attachment preview
14
- $( '#display-widget-'+self.IW_instance+'-image' ).html( self.IW_html );
15
-
16
- // change width & height fields in widget to match image
17
- $( '#widget-'+self.IW_instance+'-width' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('width'));
18
- $( '#widget-'+self.IW_instance+'-height' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('height'));
19
-
20
- // set alignment in widget
21
- $( '#widget-'+self.IW_instance+'-align' ).val(self.IW_align);
22
-
23
- // set title in widget
24
- $( '#widget-'+self.IW_instance+'-title' ).val(self.IW_title);
25
-
26
- // set caption in widget
27
- $( '#widget-'+self.IW_instance+'-description' ).val(self.IW_caption);
28
-
29
- // set alt text in widget
30
- $( '#widget-'+self.IW_instance+'-alt' ).val(self.IW_alt);
31
-
32
- // set link in widget
33
- $( '#widget-'+self.IW_instance+'-link' ).val(self.IW_url);
34
-
35
- // close thickbox
36
- tb_remove();
37
-
38
- // change button text
39
- $('#add_image-widget-'+self.IW_instance+'-image').html($('#add_image-widget-'+self.IW_instance+'-image').html().replace(/Add Image/g, 'Change Image'));
40
- }
41
-
42
- function changeImgWidth(instance) {
43
- var width = $( '#widget-'+instance+'-width' ).val();
44
- var height = Math.round(width / imgRatio(instance));
45
- changeImgSize(instance,width,height);
46
- }
47
-
48
- function changeImgHeight(instance) {
49
- var height = $( '#widget-'+instance+'-height' ).val();
50
- var width = Math.round(height * imgRatio(instance));
51
- changeImgSize(instance,width,height);
52
- }
53
-
54
- function imgRatio(instance) {
55
- var width_old = $( '#display-widget-'+instance+'-image img').attr('width');
56
- var height_old = $( '#display-widget-'+instance+'-image img').attr('height');
57
- var ratio = width_old / height_old;
58
- return ratio;
59
- }
60
-
61
- function changeImgSize(instance,width,height) {
62
- if (isNaN(width) || width < 1) {
63
- $( '#widget-'+instance+'-width' ).val('');
64
- width = 'none';
65
- } else {
66
- $( '#widget-'+instance+'-width' ).val(width);
67
- width = width + 'px';
68
- }
69
- $( '#display-widget-'+instance+'-image img' ).css({
70
- 'width':width
71
- });
72
-
73
- if (isNaN(height) || height < 1) {
74
- $( '#widget-'+instance+'-height' ).val('');
75
- height = 'none';
76
- } else {
77
- $( '#widget-'+instance+'-height' ).val(height);
78
- height = height + 'px';
79
- }
80
- $( '#display-widget-'+instance+'-image img' ).css({
81
- 'height':height
82
- });
83
- }
84
-
85
- function changeImgAlign(instance) {
86
- var align = $( '#widget-'+instance+'-align' ).val();
87
- $( '#display-widget-'+instance+'-image img' ).attr(
88
- 'class', (align == 'none' ? '' : 'align'+align)
89
- );
90
- }
91
-
92
- function imgHandler(event) {
93
- event.preventDefault();
94
- window.send_to_editor = image_widget_send_to_editor;
95
- tb_show("Add an Image", event.target.href, false);
96
- }
97
-
98
- $(document).ready(function() {
99
- // Use new style event handling since $.fn.live() will be deprecated
100
- if ( typeof $.fn.on !== 'undefined' ) {
101
- $("#wpbody").on("click", ".thickbox-image-widget", imgHandler);
102
- }
103
- else {
104
- $("a.thickbox-image-widget").live('click', imgHandler);
105
- }
106
-
107
- // Modify thickbox link to fit window. Adapted from wp-admin\js\media-upload.dev.js.
108
- $('a.thickbox-image-widget').each( function() {
109
- var href = $(this).attr('href'), width = $(window).width(), H = $(window).height(), W = ( 720 < width ) ? 720 : width;
110
- if ( ! href ) return;
111
- href = href.replace(/&width=[0-9]+/g, '');
112
- href = href.replace(/&height=[0-9]+/g, '');
113
- $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) );
114
- });
115
- });
116
-
117
- })(jQuery);
118
-
119
- /* Fix browser upload */
120
-
121
- jQuery(document).ready(function() {
122
-
123
- jQuery('form#image-form').submit(function(){
124
- var wp_ref = jQuery("input[name='_wp_http_referer']").val();
125
- // _wp_http_referer only contains the widget_sp_image if the
126
- // previous action was pressing the add image link in an Image Widget
127
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String/indexOf
128
- if( wp_ref.indexOf('widget_sp_image') != -1 ) {
129
- var parsed_url = parse_url(wp_ref);
130
- var nw_action_url = jQuery('form#image-form').attr('action');
131
-
132
- // make sure the widget_sp_image is not part of the form action url
133
- // so we will add it to fix the context
134
- if( nw_action_url.indexOf('widget_sp_image') == -1 ) {
135
- nw_action_url = nw_action_url + '&' + parsed_url.query;
136
- jQuery('form#image-form').attr('action', nw_action_url);
137
- }
138
- }
139
- return true;
140
- });
141
- });
142
-
143
-
144
- /*
145
- * Thanks to http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js
146
- */
147
- function parse_url (str, component) {
148
- // http://kevin.vanzonneveld.net
149
- // + original by: Steven Levithan (http://blog.stevenlevithan.com)
150
- // + reimplemented by: Brett Zamir (http://brett-zamir.me)
151
- // + input by: Lorenzo Pisani
152
- // + input by: Tony
153
- // + improved by: Brett Zamir (http://brett-zamir.me)
154
- // % note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
155
- // % note: blog post at http://blog.stevenlevithan.com/archives/parseuri
156
- // % note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
157
- // % note: Does not replace invalid characters with '_' as in PHP, nor does it return false with
158
- // % note: a seriously malformed URL.
159
- // % note: Besides function name, is essentially the same as parseUri as well as our allowing
160
- // % note: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
161
- // * example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
162
- // * returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
163
- var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',
164
- 'relative', 'path', 'directory', 'file', 'query', 'fragment'],
165
- ini = (this.php_js && this.php_js.ini) || {},
166
- mode = (ini['phpjs.parse_url.mode'] &&
167
- ini['phpjs.parse_url.mode'].local_value) || 'php',
168
- parser = {
169
- php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
170
- strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
171
- loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
172
- };
173
-
174
- var m = parser[mode].exec(str),
175
- uri = {},
176
- i = 14;
177
- while (i--) {
178
- if (m[i]) {
179
- uri[key[i]] = m[i];
180
- }
181
- }
182
-
183
- if (component) {
184
- return uri[component.replace('PHP_URL_', '').toLowerCase()];
185
- }
186
- if (mode !== 'php') {
187
- var name = (ini['phpjs.parse_url.queryKey'] &&
188
- ini['phpjs.parse_url.queryKey'].local_value) || 'queryKey';
189
- parser = /(?:^|&)([^&=]*)=?([^&]*)/g;
190
- uri[name] = {};
191
- uri[key[12]].replace(parser, function ($0, $1, $2) {
192
- if ($1) {uri[name][$1] = $2;}
193
- });
194
- }
195
- delete uri.source;
196
- return uri;
197
- }
198
- /* /wp-admin/media-upload.php?type=image&widget_id=widget_sp_image-11& */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
image-widget.php CHANGED
@@ -2,9 +2,9 @@
2
  /*
3
  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: Modern Tribe, Inc.
7
- Version: 3.3.3
8
  Author URI: http://tri.be
9
  */
10
 
@@ -23,8 +23,6 @@ add_action('widgets_init', 'tribe_load_image_widget');
23
  **/
24
  class Tribe_Image_Widget extends WP_Widget {
25
 
26
- var $pluginDomain = 'sp_image_widget';
27
-
28
  /**
29
  * SP Image Widget constructor
30
  *
@@ -32,33 +30,26 @@ class Tribe_Image_Widget extends WP_Widget {
32
  */
33
  function Tribe_Image_Widget() {
34
  $this->loadPluginTextDomain();
35
- $widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', $this->pluginDomain ) );
36
  $control_ops = array( 'id_base' => 'widget_sp_image' );
37
- $this->WP_Widget('widget_sp_image', __('Image Widget', $this->pluginDomain), $widget_ops, $control_ops);
38
- $this->register_scripts_and_styles();
 
39
 
 
40
  global $pagenow;
41
- if (defined("WP_ADMIN") && WP_ADMIN) {
42
- add_action( 'admin_init', array( $this, 'fix_async_upload_image' ) );
43
-
44
- if ( 'widgets.php' == $pagenow ) {
45
- wp_enqueue_style( 'thickbox' );
46
- wp_enqueue_script( 'tribe-image-widget' );
47
- add_action( 'admin_head-widgets.php', array( $this, 'admin_head' ) );
48
- }
49
- elseif ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) {
50
- wp_enqueue_script( 'fix-browser-upload' );
51
- add_filter( 'image_send_to_editor', array( $this,'image_send_to_editor'), 1, 8 );
52
- add_filter( 'gettext', array( $this, 'replace_text_in_thickbox' ), 1, 3 );
53
- add_filter( 'media_upload_tabs', array( $this, 'media_upload_tabs' ) );
54
- }
55
  }
56
-
57
- }
58
-
59
- function register_scripts_and_styles() {
60
- $dir = plugins_url('/', __FILE__);
61
- wp_register_script( 'tribe-image-widget', $dir . 'image-widget.js', array('jquery','thickbox'), false, true );
 
62
  }
63
 
64
  function fix_async_upload_image() {
@@ -69,7 +60,7 @@ class Tribe_Image_Widget extends WP_Widget {
69
  }
70
 
71
  function loadPluginTextDomain() {
72
- load_plugin_textdomain( $this->pluginDomain, false, trailingslashit(basename(dirname(__FILE__))) . 'lang/');
73
  }
74
 
75
  /**
@@ -136,7 +127,7 @@ class Tribe_Image_Widget extends WP_Widget {
136
  function replace_text_in_thickbox($translated_text, $source_text, $domain) {
137
  if ( $this->is_sp_widget_context() ) {
138
  if ('Insert into Post' == $source_text) {
139
- return __('Insert Into Widget', $this->pluginDomain );
140
  }
141
  }
142
  return $translated_text;
@@ -229,7 +220,7 @@ class Tribe_Image_Widget extends WP_Widget {
229
  $instance['link'] = $new_instance['link'];
230
  $instance['image'] = $new_instance['image'];
231
  $instance['imageurl'] = $this->get_image_url($new_instance['image'],$new_instance['width'],$new_instance['height']); // image resizing not working right now
232
- if( $_SERVER["HTTPS"] == "on" ) {
233
  $instance['imageurl'] = str_replace('http://', 'https://', $instance['imageurl']);
234
  }
235
  $instance['linktarget'] = $new_instance['linktarget'];
2
  /*
3
  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: Modern Tribe, Inc.
7
+ Version: 3.3.4
8
  Author URI: http://tri.be
9
  */
10
 
23
  **/
24
  class Tribe_Image_Widget extends WP_Widget {
25
 
 
 
26
  /**
27
  * SP Image Widget constructor
28
  *
30
  */
31
  function Tribe_Image_Widget() {
32
  $this->loadPluginTextDomain();
33
+ $widget_ops = array( 'classname' => 'widget_sp_image', 'description' => __( 'Showcase a single image with a Title, URL, and a Description', 'image_widget' ) );
34
  $control_ops = array( 'id_base' => 'widget_sp_image' );
35
+ $this->WP_Widget('widget_sp_image', __('Image Widget', 'image_widget'), $widget_ops, $control_ops);
36
+ add_action( 'admin_init', array( $this, 'admin_setup' ) );
37
+ }
38
 
39
+ function admin_setup() {
40
  global $pagenow;
41
+ if ( 'widgets.php' == $pagenow ) {
42
+ wp_enqueue_style( 'thickbox' );
43
+ wp_enqueue_script( 'tribe-image-widget', plugins_url('resources/js/image-widget.js', __FILE__), array('thickbox'), FALSE, TRUE );
44
+ add_action( 'admin_head-widgets.php', array( $this, 'admin_head' ) );
 
 
 
 
 
 
 
 
 
 
45
  }
46
+ elseif ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) {
47
+ wp_enqueue_script( 'tribe-image-widget-fix-uploader', plugins_url('resources/js/image-widget-upload-fixer.js', __FILE__), array('jquery'), FALSE, TRUE );
48
+ add_filter( 'image_send_to_editor', array( $this,'image_send_to_editor'), 1, 8 );
49
+ add_filter( 'gettext', array( $this, 'replace_text_in_thickbox' ), 1, 3 );
50
+ add_filter( 'media_upload_tabs', array( $this, 'media_upload_tabs' ) );
51
+ }
52
+ $this->fix_async_upload_image();
53
  }
54
 
55
  function fix_async_upload_image() {
60
  }
61
 
62
  function loadPluginTextDomain() {
63
+ load_plugin_textdomain( 'image_widget', false, trailingslashit(basename(dirname(__FILE__))) . 'lang/');
64
  }
65
 
66
  /**
127
  function replace_text_in_thickbox($translated_text, $source_text, $domain) {
128
  if ( $this->is_sp_widget_context() ) {
129
  if ('Insert into Post' == $source_text) {
130
+ return __('Insert Into Widget', 'image_widget' );
131
  }
132
  }
133
  return $translated_text;
220
  $instance['link'] = $new_instance['link'];
221
  $instance['image'] = $new_instance['image'];
222
  $instance['imageurl'] = $this->get_image_url($new_instance['image'],$new_instance['width'],$new_instance['height']); // image resizing not working right now
223
+ if( isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ) {
224
  $instance['imageurl'] = str_replace('http://', 'https://', $instance['imageurl']);
225
  }
226
  $instance['linktarget'] = $new_instance['linktarget'];
lang/{SP_Image_Widget-de_DE.mo → Image_Widget-de_DE.mo} RENAMED
File without changes
lang/{SP_Image_Widget-de_DE.po → Image_Widget-de_DE.po} RENAMED
File without changes
lang/{SP_Image_Widget-fr_FR.mo → Image_Widget-fr_FR.mo} RENAMED
File without changes
lang/{SP_Image_Widget-fr_FR.po → Image_Widget-fr_FR.po} RENAMED
File without changes
lang/{SP_Image_Widget-ja.mo → Image_Widget-ja.mo} RENAMED
File without changes
lang/{SP_Image_Widget-ja.po → Image_Widget-ja.po} RENAMED
File without changes
lang/{SP_Image_Widget-pl_PL.mo → Image_Widget-pl_PL.mo} RENAMED
File without changes
lang/{SP_Image_Widget-pl_PL.po → Image_Widget-pl_PL.po} RENAMED
File without changes
lang/{SP_Image_Widget-pt_BR.mo → Image_Widget-pt_BR.mo} RENAMED
File without changes
lang/{SP_Image_Widget-pt_BR.po → Image_Widget-pt_BR.po} RENAMED
File without changes
lang/{SP_Image_Widget-ro_RO.mo → Image_Widget-ro_RO.mo} RENAMED
File without changes
lang/{SP_Image_Widget-ro_RO.po → Image_Widget-ro_RO.po} RENAMED
File without changes
lang/{sp_image_widget-sv_SE.mo → Image_Widget-sv_SE.mo} RENAMED
File without changes
lang/{sp_image_widget-sv_SE.po → Image_Widget-sv_SE.po} RENAMED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: widget, image, ad, banner, simple, upload, sidebar, admin, thickbox, resize
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
- Stable tag: 3.3.3
8
 
9
  == Description ==
10
 
@@ -72,9 +72,16 @@ function my_template_filter($template) {
72
 
73
  == Changelog ==
74
 
 
 
 
 
 
 
 
75
  = 3.3.3 =
76
 
77
- * Romanian translation courtesy of Alexander Ovsov at Web Geek Science.
78
 
79
  = 3.3.2 =
80
 
@@ -132,13 +139,13 @@ function my_template_filter($template) {
132
 
133
  * Added Portuguese translation courtesy of Gustavo Machado
134
 
135
- = 3.2.1 =
136
 
137
  * Fix image widget public declaration bug.
138
 
139
  = 3.2 =
140
 
141
- * Abstract views for widget output and widget admin.
142
  * Support theme override of the widget output! Now you can layout the widget however you'd like.
143
  * Added filter to override template call.
144
 
@@ -218,7 +225,7 @@ Thank you @smurkas, @squigie and @laurie!!! Special thanks to Cameron Clark fro
218
 
219
  = 3.0 =
220
 
221
- * Completely remodeled the plugin to use the native wordpress uploader and be compatible with Wordpress 2.8 plugin architecture.
222
  * Removed externalized widget admin.
223
 
224
  = 2.2.2 =
4
  Tags: widget, image, ad, banner, simple, upload, sidebar, admin, thickbox, resize
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
+ Stable tag: 3.3.4
8
 
9
  == Description ==
10
 
72
 
73
  == Changelog ==
74
 
75
+ = 3.3.4 =
76
+
77
+ * Fix javascript bugs in the widget admin UI. ( thanks for filing this @joo-joo )
78
+ * Fix notices in php error log.
79
+ * Add widget description filter $args and $instance ( thanks @jeffreyzinn )
80
+ * Fixed localization and renamed key to 'image-widget'
81
+
82
  = 3.3.3 =
83
 
84
+ * Romanian translation courtesy of Alexander Ovsov at Web Geek Science (http://webhostinggeeks.com).
85
 
86
  = 3.3.2 =
87
 
139
 
140
  * Added Portuguese translation courtesy of Gustavo Machado
141
 
142
+ = 3.2.1 =
143
 
144
  * Fix image widget public declaration bug.
145
 
146
  = 3.2 =
147
 
148
+ * Abstract views for widget output and widget admin.
149
  * Support theme override of the widget output! Now you can layout the widget however you'd like.
150
  * Added filter to override template call.
151
 
225
 
226
  = 3.0 =
227
 
228
+ * Completely remodeled the plugin to use the native WordPress uploader and be compatible with Wordpress 2.8 plugin architecture.
229
  * Removed externalized widget admin.
230
 
231
  = 2.2.2 =
resources/js/image-widget-upload-fixer.js ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+
3
+ jQuery('form#image-form').submit(function(){
4
+ var wp_ref = jQuery("input[name='_wp_http_referer']").val();
5
+ // _wp_http_referer only contains the widget_sp_image if the
6
+ // previous action was pressing the add image link in an Image Widget
7
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String/indexOf
8
+ if( wp_ref.indexOf('widget_sp_image') != -1 ) {
9
+ var parsed_url = parse_url(wp_ref);
10
+ var nw_action_url = jQuery('form#image-form').attr('action');
11
+
12
+ // make sure the widget_sp_image is not part of the form action url
13
+ // so we will add it to fix the context
14
+ if( nw_action_url.indexOf('widget_sp_image') == -1 ) {
15
+ nw_action_url = nw_action_url + '&' + parsed_url.query;
16
+ jQuery('form#image-form').attr('action', nw_action_url);
17
+ }
18
+ }
19
+ return true;
20
+ });
21
+ });
22
+
23
+
24
+ /*
25
+ * Thanks to http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js
26
+ */
27
+ function parse_url (str, component) {
28
+ // http://kevin.vanzonneveld.net
29
+ // + original by: Steven Levithan (http://blog.stevenlevithan.com)
30
+ // + reimplemented by: Brett Zamir (http://brett-zamir.me)
31
+ // + input by: Lorenzo Pisani
32
+ // + input by: Tony
33
+ // + improved by: Brett Zamir (http://brett-zamir.me)
34
+ // % note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
35
+ // % note: blog post at http://blog.stevenlevithan.com/archives/parseuri
36
+ // % note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
37
+ // % note: Does not replace invalid characters with '_' as in PHP, nor does it return false with
38
+ // % note: a seriously malformed URL.
39
+ // % note: Besides function name, is essentially the same as parseUri as well as our allowing
40
+ // % note: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
41
+ // * example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
42
+ // * returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
43
+ var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',
44
+ 'relative', 'path', 'directory', 'file', 'query', 'fragment'],
45
+ ini = (this.php_js && this.php_js.ini) || {},
46
+ mode = (ini['phpjs.parse_url.mode'] &&
47
+ ini['phpjs.parse_url.mode'].local_value) || 'php',
48
+ parser = {
49
+ php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
50
+ strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
51
+ loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
52
+ };
53
+
54
+ var m = parser[mode].exec(str),
55
+ uri = {},
56
+ i = 14;
57
+ while (i--) {
58
+ if (m[i]) {
59
+ uri[key[i]] = m[i];
60
+ }
61
+ }
62
+
63
+ if (component) {
64
+ return uri[component.replace('PHP_URL_', '').toLowerCase()];
65
+ }
66
+ if (mode !== 'php') {
67
+ var name = (ini['phpjs.parse_url.queryKey'] &&
68
+ ini['phpjs.parse_url.queryKey'].local_value) || 'queryKey';
69
+ parser = /(?:^|&)([^&=]*)=?([^&]*)/g;
70
+ uri[name] = {};
71
+ uri[key[12]].replace(parser, function ($0, $1, $2) {
72
+ if ($1) {uri[name][$1] = $2;}
73
+ });
74
+ }
75
+ delete uri.source;
76
+ return uri;
77
+ }
78
+
79
+ /* /wp-admin/media-upload.php?type=image&widget_id=widget_sp_image-11& */
resources/js/image-widget.js ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var imageWidget;
2
+
3
+ (function($){
4
+
5
+ imageWidget = {
6
+
7
+ sendToEditor : function(h) {
8
+ // ignore content returned from media uploader and use variables passed to window instead
9
+
10
+ // store attachment id in hidden field
11
+ $( '#widget-'+self.IW_instance+'-image' ).val( self.IW_img_id );
12
+
13
+ // display attachment preview
14
+ $( '#display-widget-'+self.IW_instance+'-image' ).html( self.IW_html );
15
+
16
+ // change width & height fields in widget to match image
17
+ $( '#widget-'+self.IW_instance+'-width' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('width'));
18
+ $( '#widget-'+self.IW_instance+'-height' ).val($( '#display-widget-'+self.IW_instance+'-image img').attr('height'));
19
+
20
+ // set alignment in widget
21
+ $( '#widget-'+self.IW_instance+'-align' ).val(self.IW_align);
22
+
23
+ // set title in widget
24
+ $( '#widget-'+self.IW_instance+'-title' ).val(self.IW_title);
25
+
26
+ // set caption in widget
27
+ $( '#widget-'+self.IW_instance+'-description' ).val(self.IW_caption);
28
+
29
+ // set alt text in widget
30
+ $( '#widget-'+self.IW_instance+'-alt' ).val(self.IW_alt);
31
+
32
+ // set link in widget
33
+ $( '#widget-'+self.IW_instance+'-link' ).val(self.IW_url);
34
+
35
+ // close thickbox
36
+ tb_remove();
37
+
38
+ // change button text
39
+ $('#add_image-widget-'+self.IW_instance+'-image').html($('#add_image-widget-'+self.IW_instance+'-image').html().replace(/Add Image/g, 'Change Image'));
40
+ },
41
+
42
+ changeImgWidth : function(instance) {
43
+ var width = $( '#widget-'+instance+'-width' ).val();
44
+ var height = Math.round(width / imageWidget.imgRatio(instance));
45
+ imageWidget.changeImgSize(instance,width,height);
46
+ },
47
+
48
+ changeImgHeight : function(instance) {
49
+ var height = $( '#widget-'+instance+'-height' ).val();
50
+ var width = Math.round(height * imageWidget.imgRatio(instance));
51
+ imageWidget.changeImgSize(instance,width,height);
52
+ },
53
+
54
+ imgRatio : function(instance) {
55
+ var width_old = $( '#display-widget-'+instance+'-image img').attr('width');
56
+ var height_old = $( '#display-widget-'+instance+'-image img').attr('height');
57
+ var ratio = width_old / height_old;
58
+ return ratio;
59
+ },
60
+
61
+ changeImgSize : function(instance,width,height) {
62
+ if (isNaN(width) || width < 1) {
63
+ $( '#widget-'+instance+'-width' ).val('');
64
+ width = 'none';
65
+ } else {
66
+ $( '#widget-'+instance+'-width' ).val(width);
67
+ width = width + 'px';
68
+ }
69
+ $( '#display-widget-'+instance+'-image img' ).css({
70
+ 'width':width
71
+ });
72
+
73
+ if (isNaN(height) || height < 1) {
74
+ $( '#widget-'+instance+'-height' ).val('');
75
+ height = 'none';
76
+ } else {
77
+ $( '#widget-'+instance+'-height' ).val(height);
78
+ height = height + 'px';
79
+ }
80
+ $( '#display-widget-'+instance+'-image img' ).css({
81
+ 'height':height
82
+ });
83
+ },
84
+
85
+ changeImgAlign : function(instance) {
86
+ var align = $( '#widget-'+instance+'-align' ).val();
87
+ $( '#display-widget-'+instance+'-image img' ).attr(
88
+ 'class', (align == 'none' ? '' : 'align'+align)
89
+ );
90
+ },
91
+
92
+ imgHandler : function(event) {
93
+ event.preventDefault();
94
+ window.send_to_editor = imageWidget.sendToEditor;
95
+ tb_show("Add an Image", event.target.href, false);
96
+ },
97
+
98
+ setActiveWidget : function(instance_id) {
99
+ self.IW_instance = instance_id;
100
+ }
101
+
102
+ };
103
+
104
+ $(document).ready(function() {
105
+ // Use new style event handling since $.fn.live() will be deprecated
106
+ if ( typeof $.fn.on !== 'undefined' ) {
107
+ $("#wpbody").on("click", ".thickbox-image-widget", imageWidget.imgHandler);
108
+ }
109
+ else {
110
+ $("a.thickbox-image-widget").live('click', imageWidget.imgHandler);
111
+ }
112
+
113
+ // Modify thickbox link to fit window. Adapted from wp-admin\js\media-upload.dev.js.
114
+ $('a.thickbox-image-widget').each( function() {
115
+ var href = $(this).attr('href'), width = $(window).width(), H = $(window).height(), W = ( 720 < width ) ? 720 : width;
116
+ if ( ! href ) return;
117
+ href = href.replace(/&width=[0-9]+/g, '');
118
+ href = href.replace(/&height=[0-9]+/g, '');
119
+ $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) );
120
+ });
121
+ });
122
+
123
+ })(jQuery);
views/widget-admin.php CHANGED
@@ -7,17 +7,17 @@
7
  if ( !defined('ABSPATH') )
8
  die('-1');
9
  ?>
10
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', $this->pluginDomain); ?></label>
11
  <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>
12
 
13
- <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', $this->pluginDomain); ?></label>
14
  <?php
15
- $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.
16
  $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
17
- $image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), $this->pluginDomain);
18
  ?><br />
19
- <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>
20
- <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
21
  if ($instance['imageurl']) {
22
  echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
23
  if ($instance['width'] && is_numeric($instance['width'])) {
@@ -37,29 +37,29 @@ if ($instance['imageurl']) {
37
  <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
38
  </p>
39
 
40
- <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Caption:', $this->pluginDomain); ?></label>
41
  <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>
42
 
43
- <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', $this->pluginDomain); ?></label>
44
  <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 />
45
  <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
46
- <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', $this->pluginDomain); ?></option>
47
- <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', $this->pluginDomain); ?></option>
48
  </select></p>
49
 
50
- <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', $this->pluginDomain); ?></label>
51
- <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>
52
 
53
- <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', $this->pluginDomain); ?></label>
54
- <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>
55
 
56
- <p><label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', $this->pluginDomain); ?></label>
57
- <select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" onchange="changeImgAlign('<?php echo $this->id; ?>')">
58
- <option value="none"<?php selected( $instance['align'], 'none' ); ?>><?php _e('none', $this->pluginDomain); ?></option>
59
- <option value="left"<?php selected( $instance['align'], 'left' ); ?>><?php _e('left', $this->pluginDomain); ?></option>
60
- <option value="center"<?php selected( $instance['align'], 'center' ); ?>><?php _e('center', $this->pluginDomain); ?></option>
61
- <option value="right"<?php selected( $instance['align'], 'right' ); ?>><?php _e('right', $this->pluginDomain); ?></option>
62
  </select></p>
63
 
64
- <p><label for="<?php echo $this->get_field_id('alt'); ?>"><?php _e('Alternate Text:', $this->pluginDomain); ?></label>
65
  <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>
7
  if ( !defined('ABSPATH') )
8
  die('-1');
9
  ?>
10
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'image_widget'); ?></label>
11
  <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>
12
 
13
+ <p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', 'image_widget'); ?></label>
14
  <?php
15
+ $media_upload_iframe_src = "media-upload.php?type=image&post_id=0&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.
16
  $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
17
+ $image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), 'image_widget');
18
  ?><br />
19
+ <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="imageWidget.setActiveWidget('<?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>
20
+ <div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
21
  if ($instance['imageurl']) {
22
  echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
23
  if ($instance['width'] && is_numeric($instance['width'])) {
37
  <input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
38
  </p>
39
 
40
+ <p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Caption:', 'image_widget'); ?></label>
41
  <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>
42
 
43
+ <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', 'image_widget'); ?></label>
44
  <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 />
45
  <select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
46
+ <option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', 'image_widget'); ?></option>
47
+ <option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', 'image_widget'); ?></option>
48
  </select></p>
49
 
50
+ <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'image_widget'); ?></label>
51
+ <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="imageWidget.changeImgWidth('<?php echo $this->id; ?>')" /></p>
52
 
53
+ <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'image_widget'); ?></label>
54
+ <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="imageWidget.changeImgHeight('<?php echo $this->id; ?>')" /></p>
55
 
56
+ <p><label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', 'image_widget'); ?></label>
57
+ <select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" onchange="imageWidget.changeImgAlign('<?php echo $this->id; ?>')">
58
+ <option value="none"<?php selected( $instance['align'], 'none' ); ?>><?php _e('none', 'image_widget'); ?></option>
59
+ <option value="left"<?php selected( $instance['align'], 'left' ); ?>><?php _e('left', 'image_widget'); ?></option>
60
+ <option value="center"<?php selected( $instance['align'], 'center' ); ?>><?php _e('center', 'image_widget'); ?></option>
61
+ <option value="right"<?php selected( $instance['align'], 'right' ); ?>><?php _e('right', 'image_widget'); ?></option>
62
  </select></p>
63
 
64
+ <p><label for="<?php echo $this->get_field_id('alt'); ?>"><?php _e('Alternate Text:', 'image_widget'); ?></label>
65
  <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 CHANGED
@@ -40,7 +40,7 @@ if ( !empty( $image ) ) {
40
  if ( $link ) { echo '</a>'; }
41
  }
42
  if ( !empty( $description ) ) {
43
- $text = apply_filters( 'widget_text', $description );
44
  echo '<div class="'.$this->widget_options['classname'].'-description" >';
45
  echo wpautop( $text );
46
  echo "</div>";
40
  if ( $link ) { echo '</a>'; }
41
  }
42
  if ( !empty( $description ) ) {
43
+ $text = apply_filters( 'widget_text', $description, $args, $instance );
44
  echo '<div class="'.$this->widget_options['classname'].'-description" >';
45
  echo wpautop( $text );
46
  echo "</div>";