Version Description
Download this release
Release Info
| Developer | peterchester |
| Plugin | |
| Version | 3.0.5 |
| Comparing to | |
| See all releases | |
Code changes from version 3.0.4 to 3.0.5
- image-widget.js +100 -30
- image-widget.php +287 -219
- readme.txt +15 -2
image-widget.js
CHANGED
|
@@ -1,31 +1,101 @@
|
|
| 1 |
-
function set_active_widget(
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
//
|
| 12 |
-
jQuery( '#'+
|
| 13 |
-
|
| 14 |
-
//
|
| 15 |
-
jQuery( '#
|
| 16 |
-
jQuery( '#display-'+
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
//
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
jQuery(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
});
|
| 1 |
+
function set_active_widget(instance_id) {
|
| 2 |
+
self.IW_instance = instance_id;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
function send_to_editor(h) {
|
| 6 |
+
// ignore content returned from media uploader and use variables passed to window instead
|
| 7 |
+
|
| 8 |
+
// store attachment id in hidden field
|
| 9 |
+
jQuery( '#widget-'+self.IW_instance+'-image' ).val( self.IW_img_id );
|
| 10 |
+
|
| 11 |
+
// display attachment preview
|
| 12 |
+
jQuery( '#display-widget-'+self.IW_instance+'-image' ).html( self.IW_html );
|
| 13 |
+
|
| 14 |
+
// change width & height fields in widget to match image
|
| 15 |
+
jQuery( '#widget-'+self.IW_instance+'-width' ).val(jQuery( '#display-widget-'+self.IW_instance+'-image img').attr('width'));
|
| 16 |
+
jQuery( '#widget-'+self.IW_instance+'-height' ).val(jQuery( '#display-widget-'+self.IW_instance+'-image img').attr('height'));
|
| 17 |
+
|
| 18 |
+
// set alignment in widget
|
| 19 |
+
jQuery( '#widget-'+self.IW_instance+'-align' ).val(self.IW_align);
|
| 20 |
+
|
| 21 |
+
// set title in widget
|
| 22 |
+
jQuery( '#widget-'+self.IW_instance+'-title' ).val(self.IW_title);
|
| 23 |
+
|
| 24 |
+
// set caption in widget
|
| 25 |
+
jQuery( '#widget-'+self.IW_instance+'-description' ).val(self.IW_alt);
|
| 26 |
+
|
| 27 |
+
// set link in widget
|
| 28 |
+
jQuery( '#widget-'+self.IW_instance+'-link' ).val(self.IW_url);
|
| 29 |
+
|
| 30 |
+
// close thickbox
|
| 31 |
+
tb_remove();
|
| 32 |
+
|
| 33 |
+
// change button text
|
| 34 |
+
jQuery('#add_image-widget-'+self.IW_instance+'-image').html(jQuery('#add_image-widget-'+self.IW_instance+'-image').html().replace(/Add Image/g, 'Change Image'));
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function changeImgWidth(instance) {
|
| 38 |
+
var width = jQuery( '#widget-'+instance+'-width' ).val();
|
| 39 |
+
var height = Math.round(width / imgRatio(instance));
|
| 40 |
+
changeImgSize(instance,width,height);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function changeImgHeight(instance) {
|
| 44 |
+
var height = jQuery( '#widget-'+instance+'-height' ).val();
|
| 45 |
+
var width = Math.round(height * imgRatio(instance));
|
| 46 |
+
changeImgSize(instance,width,height);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function imgRatio(instance) {
|
| 50 |
+
var width_old = jQuery( '#display-widget-'+instance+'-image img').attr('width');
|
| 51 |
+
var height_old = jQuery( '#display-widget-'+instance+'-image img').attr('height');
|
| 52 |
+
var ratio = width_old / height_old;
|
| 53 |
+
return ratio;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
function changeImgSize(instance,width,height) {
|
| 57 |
+
if (isNaN(width) || width < 1) {
|
| 58 |
+
jQuery( '#widget-'+instance+'-width' ).val('');
|
| 59 |
+
width = 'none';
|
| 60 |
+
} else {
|
| 61 |
+
jQuery( '#widget-'+instance+'-width' ).val(width);
|
| 62 |
+
width = width + 'px';
|
| 63 |
+
}
|
| 64 |
+
jQuery( '#display-widget-'+instance+'-image img' ).css({
|
| 65 |
+
'width':width,
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
if (isNaN(height) || height < 1) {
|
| 69 |
+
jQuery( '#widget-'+instance+'-height' ).val('');
|
| 70 |
+
height = 'none';
|
| 71 |
+
} else {
|
| 72 |
+
jQuery( '#widget-'+instance+'-height' ).val(height);
|
| 73 |
+
height = height + 'px';
|
| 74 |
+
}
|
| 75 |
+
jQuery( '#display-widget-'+instance+'-image img' ).css({
|
| 76 |
+
'height':height
|
| 77 |
+
});
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function changeImgAlign(instance) {
|
| 81 |
+
var align = jQuery( '#widget-'+instance+'-align' ).val();
|
| 82 |
+
jQuery( '#display-widget-'+instance+'-image img' ).attr(
|
| 83 |
+
'class', (align == 'none' ? '' : 'align'+align)
|
| 84 |
+
);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
jQuery(document).ready(function() {
|
| 88 |
+
jQuery("body").click(function(event) {
|
| 89 |
+
if (jQuery(event.target).is('a.thickbox-image-widget')) {
|
| 90 |
+
tb_show("Add an Image", event.target.href, false);
|
| 91 |
+
}
|
| 92 |
+
});
|
| 93 |
+
// Modify thickbox link to fit window. Adapted from wp-admin\js\media-upload.dev.js.
|
| 94 |
+
jQuery('a.thickbox-image-widget').each( function() {
|
| 95 |
+
var href = jQuery(this).attr('href'), width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
|
| 96 |
+
if ( ! href ) return;
|
| 97 |
+
href = href.replace(/&width=[0-9]+/g, '');
|
| 98 |
+
href = href.replace(/&height=[0-9]+/g, '');
|
| 99 |
+
jQuery(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) );
|
| 100 |
+
});
|
| 101 |
});
|
image-widget.php
CHANGED
|
@@ -1,219 +1,287 @@
|
|
| 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.
|
| 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 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
*
|
| 47 |
-
*
|
| 48 |
-
* @param int $
|
| 49 |
-
* @
|
| 50 |
-
* @
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
$image = $attachment_url;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
*
|
| 80 |
-
*
|
| 81 |
-
* @param string $
|
| 82 |
-
* @param
|
| 83 |
-
* @param string $
|
| 84 |
-
* @param string $
|
| 85 |
-
* @param
|
| 86 |
-
* @
|
| 87 |
-
* @
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
*
|
| 165 |
-
*
|
| 166 |
-
* @
|
| 167 |
-
* @
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
<
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
<?php
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.5
|
| 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 our filter to send modified output back to image widget
|
| 40 |
+
add_filter( 'image_send_to_editor', array( $this,'image_send_to_editor'), 10, 7 );
|
| 41 |
+
add_action( 'admin_head-widgets.php', array( $this, 'admin_head' ) );
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Retrieve resized image URL
|
| 47 |
+
*
|
| 48 |
+
* @param int $id Post ID or Attachment ID
|
| 49 |
+
* @param int $width desired width of image (optional)
|
| 50 |
+
* @param int $height desired height of image (optional)
|
| 51 |
+
* @return string URL
|
| 52 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 53 |
+
*/
|
| 54 |
+
function get_image_url( $id, $width=false, $height=false ) {
|
| 55 |
+
|
| 56 |
+
/**/
|
| 57 |
+
// Get attachment and resize but return attachment path (needs to return url)
|
| 58 |
+
$attachment = wp_get_attachment_metadata( $id );
|
| 59 |
+
$attachment_url = wp_get_attachment_url( $id );
|
| 60 |
+
if (isset($attachment_url)) {
|
| 61 |
+
if ($width && $height) {
|
| 62 |
+
$uploads = wp_upload_dir();
|
| 63 |
+
$imgpath = $uploads['basedir'].'/'.$attachment['file'];
|
| 64 |
+
if ($image = image_resize( $imgpath, $width, $height )) {
|
| 65 |
+
$image = path_join( dirname($attachment_url), basename($image) );
|
| 66 |
+
} else {
|
| 67 |
+
$image = $attachment_url;
|
| 68 |
+
}
|
| 69 |
+
} else {
|
| 70 |
+
$image = $attachment_url;
|
| 71 |
+
}
|
| 72 |
+
if (isset($image)) {
|
| 73 |
+
return $image;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Filter image_end_to_editor results
|
| 80 |
+
*
|
| 81 |
+
* @param string $html
|
| 82 |
+
* @param int $id
|
| 83 |
+
* @param string $alt
|
| 84 |
+
* @param string $title
|
| 85 |
+
* @param string $align
|
| 86 |
+
* @param string $url
|
| 87 |
+
* @param array $size
|
| 88 |
+
* @return string javascript array of attachment url and id or just the url
|
| 89 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 90 |
+
*/
|
| 91 |
+
function image_send_to_editor( $html, $id, $alt, $title, $align, $url, $size ) {
|
| 92 |
+
// Normally, media uploader return an HTML string (in this case, typically a complete image tag surrounded by a caption).
|
| 93 |
+
// Don't change that; instead, send custom javascript variables back to opener.
|
| 94 |
+
// Check that this is for the widget. Shouldn't hurt anything if it runs, but let's do it needlessly.
|
| 95 |
+
if (strpos($_REQUEST['_wp_http_referer'],$this->id_base)) {
|
| 96 |
+
?>
|
| 97 |
+
<script type="text/javascript">
|
| 98 |
+
// send image variables back to opener
|
| 99 |
+
var win = window.dialogArguments || opener || parent || top;
|
| 100 |
+
win.IW_html = '<?php echo addslashes($html) ?>';
|
| 101 |
+
win.IW_img_id = '<?php echo $id ?>';
|
| 102 |
+
win.IW_alt = '<?php echo addslashes($alt) ?>';
|
| 103 |
+
win.IW_title = '<?php echo addslashes($title) ?>';
|
| 104 |
+
win.IW_align = '<?php echo $align ?>';
|
| 105 |
+
win.IW_url = '<?php echo $url ?>';
|
| 106 |
+
win.IW_size = '<?php echo $size ?>';
|
| 107 |
+
//alert("sending variables: id: "+win.IW_img_id+"\n"+"alt: "+win.IW_alt+"\n"+"title: "+win.IW_title+"\n"+"align: "+win.IW_align+"\n"+"url: "+win.IW_url+"\n"+"size: "+win.IW_size);
|
| 108 |
+
</script>
|
| 109 |
+
<?php
|
| 110 |
+
}
|
| 111 |
+
return $html;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Widget frontend output
|
| 116 |
+
*
|
| 117 |
+
* @param array $args
|
| 118 |
+
* @param array $instance
|
| 119 |
+
* @return void
|
| 120 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 121 |
+
*/
|
| 122 |
+
function widget( $args, $instance ) {
|
| 123 |
+
extract($args);
|
| 124 |
+
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
|
| 125 |
+
echo $before_widget;
|
| 126 |
+
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
|
| 127 |
+
if (!empty($instance['image'])) {
|
| 128 |
+
if ($instance['link']) {
|
| 129 |
+
echo '<a class="'.$instance['classname'].'-image-link" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
|
| 130 |
+
}
|
| 131 |
+
if ($instance['imageurl']) {
|
| 132 |
+
echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
|
| 133 |
+
if (!empty($instance['width']) && is_numeric($instance['width'])) {
|
| 134 |
+
echo "max-width: {$instance['width']}px;";
|
| 135 |
+
}
|
| 136 |
+
if (!empty($instance['height']) && is_numeric($instance['height'])) {
|
| 137 |
+
echo "max-height: {$instance['height']}px;";
|
| 138 |
+
}
|
| 139 |
+
echo "\"";
|
| 140 |
+
if (!empty($instance['align']) && $instance['align'] != 'none') {
|
| 141 |
+
echo " class=\"align{$instance['align']}\"";
|
| 142 |
+
}
|
| 143 |
+
echo " />";
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if ($instance['link']) { echo '</a>'; }
|
| 147 |
+
}
|
| 148 |
+
if (!empty($instance['description'])) {
|
| 149 |
+
$text = apply_filters( 'widget_text', $instance['description'] );
|
| 150 |
+
echo '<p class="'.$this->widget_ops['classname'].'-description" >';
|
| 151 |
+
if ($instance['link']) {
|
| 152 |
+
echo '<a class="'.$this->widget_ops['classname'].'-image-link-p" href="'.$instance['link'].'" target="'.$instance['linktarget'].'">';
|
| 153 |
+
}
|
| 154 |
+
echo wpautop($text);
|
| 155 |
+
if ($instance['link']) { echo '</a>'; }
|
| 156 |
+
echo "</p>";
|
| 157 |
+
}
|
| 158 |
+
echo $after_widget;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Update widget options
|
| 163 |
+
*
|
| 164 |
+
* @param object $new_instance Widget Instance
|
| 165 |
+
* @param object $old_instance Widget Instance
|
| 166 |
+
* @return object
|
| 167 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 168 |
+
*/
|
| 169 |
+
function update( $new_instance, $old_instance ) {
|
| 170 |
+
$instance = $old_instance;
|
| 171 |
+
$instance['title'] = strip_tags($new_instance['title']);
|
| 172 |
+
if ( isset($new_instance['description']) ) {
|
| 173 |
+
if ( current_user_can('unfiltered_html') ) {
|
| 174 |
+
$instance['description'] = $new_instance['description'];
|
| 175 |
+
} else {
|
| 176 |
+
$instance['description'] = wp_filter_post_kses($new_instance['description']);
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
$instance['link'] = $new_instance['link'];
|
| 180 |
+
$instance['image'] = $new_instance['image'];
|
| 181 |
+
$instance['imageurl'] = $this->get_image_url($new_instance['image'],$new_instance['width'],$new_instance['height']); // image resizing not working right now
|
| 182 |
+
$instance['linktarget'] = $new_instance['linktarget'];
|
| 183 |
+
$instance['width'] = $new_instance['width'];
|
| 184 |
+
$instance['height'] = $new_instance['height'];
|
| 185 |
+
$instance['align'] = $new_instance['align'];
|
| 186 |
+
|
| 187 |
+
return $instance;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* Form UI
|
| 192 |
+
*
|
| 193 |
+
* @param object $instance Widget Instance
|
| 194 |
+
* @return void
|
| 195 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 196 |
+
*/
|
| 197 |
+
function form( $instance ) {
|
| 198 |
+
|
| 199 |
+
$instance = wp_parse_args( (array) $instance, array(
|
| 200 |
+
'title' => '',
|
| 201 |
+
'description' => '',
|
| 202 |
+
'link' => '',
|
| 203 |
+
'linktarget' => '',
|
| 204 |
+
'width' => '',
|
| 205 |
+
'height' => '',
|
| 206 |
+
'image' => '',
|
| 207 |
+
'imageurl' => '',
|
| 208 |
+
'align' => ''
|
| 209 |
+
) );
|
| 210 |
+
?>
|
| 211 |
+
|
| 212 |
+
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'sp_image_widget'); ?></label>
|
| 213 |
+
<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>
|
| 214 |
+
|
| 215 |
+
<p><label for="<?php echo $this->get_field_id('image'); ?>"><?php _e('Image:', 'sp_image_widget'); ?></label>
|
| 216 |
+
<?php
|
| 217 |
+
$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.
|
| 218 |
+
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src");
|
| 219 |
+
$image_title = __(($instance['image'] ? 'Change Image' : 'Add Image'), 'sp_image_widget');
|
| 220 |
+
?><br />
|
| 221 |
+
<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>
|
| 222 |
+
<div id="display-<?php echo $this->get_field_id('image'); ?>"><?php
|
| 223 |
+
if ($instance['imageurl']) {
|
| 224 |
+
echo "<img src=\"{$instance['imageurl']}\" alt=\"{$instance['title']}\" style=\"";
|
| 225 |
+
if ($instance['width'] && is_numeric($instance['width'])) {
|
| 226 |
+
echo "max-width: {$instance['width']}px;";
|
| 227 |
+
}
|
| 228 |
+
if ($instance['height'] && is_numeric($instance['height'])) {
|
| 229 |
+
echo "max-height: {$instance['height']}px;";
|
| 230 |
+
}
|
| 231 |
+
echo "\"";
|
| 232 |
+
if (!empty($instance['align']) && $instance['align'] != 'none') {
|
| 233 |
+
echo " class=\"align{$instance['align']}\"";
|
| 234 |
+
}
|
| 235 |
+
echo " />";
|
| 236 |
+
}
|
| 237 |
+
?></div>
|
| 238 |
+
<br clear="all" />
|
| 239 |
+
<input id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="hidden" value="<?php echo $instance['image']; ?>" />
|
| 240 |
+
</p>
|
| 241 |
+
|
| 242 |
+
<p><label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Caption:', 'sp_image_widget'); ?></label>
|
| 243 |
+
<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>
|
| 244 |
+
|
| 245 |
+
<p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Link:', 'sp_image_widget'); ?></label>
|
| 246 |
+
<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 />
|
| 247 |
+
<select name="<?php echo $this->get_field_name('linktarget'); ?>" id="<?php echo $this->get_field_id('linktarget'); ?>">
|
| 248 |
+
<option value="_self"<?php selected( $instance['linktarget'], '_self' ); ?>><?php _e('Stay in Window', 'sp_image_widget'); ?></option>
|
| 249 |
+
<option value="_blank"<?php selected( $instance['linktarget'], '_blank' ); ?>><?php _e('Open New Window', 'sp_image_widget'); ?></option>
|
| 250 |
+
</select></p>
|
| 251 |
+
|
| 252 |
+
<p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'sp_image_widget'); ?></label>
|
| 253 |
+
<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>
|
| 254 |
+
|
| 255 |
+
<p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'sp_image_widget'); ?></label>
|
| 256 |
+
<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>
|
| 257 |
+
|
| 258 |
+
<p><label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', 'sp_image_widget'); ?></label>
|
| 259 |
+
<select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" onchange="changeImgAlign('<?php echo $this->id; ?>')">
|
| 260 |
+
<option value="none"<?php selected( $instance['align'], 'none' ); ?>><?php _e('none', 'sp_image_widget'); ?></option>
|
| 261 |
+
<option value="left"<?php selected( $instance['align'], 'left' ); ?>><?php _e('left', 'sp_image_widget'); ?></option>
|
| 262 |
+
<option value="center"<?php selected( $instance['align'], 'center' ); ?>><?php _e('center', 'sp_image_widget'); ?></option>
|
| 263 |
+
<option value="right"<?php selected( $instance['align'], 'right' ); ?>><?php _e('right', 'sp_image_widget'); ?></option>
|
| 264 |
+
</select></p>
|
| 265 |
+
|
| 266 |
+
<?php
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
/**
|
| 270 |
+
* Admin header css
|
| 271 |
+
*
|
| 272 |
+
* @return void
|
| 273 |
+
* @author Shane & Peter, Inc. (Peter Chester)
|
| 274 |
+
*/
|
| 275 |
+
function admin_head() {
|
| 276 |
+
?>
|
| 277 |
+
<style type="text/css">
|
| 278 |
+
.aligncenter {
|
| 279 |
+
display: block;
|
| 280 |
+
margin-left: auto;
|
| 281 |
+
margin-right: auto;
|
| 282 |
+
}
|
| 283 |
+
</style>
|
| 284 |
+
<?php
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
?>
|
readme.txt
CHANGED
|
@@ -4,14 +4,14 @@ Donate link: http://www.shaneandpeter.com
|
|
| 4 |
Tags: widget, image, ad, banner, simple, upload, sidebar
|
| 5 |
Requires at least: 2.8
|
| 6 |
Tested up to: 2.8.4
|
| 7 |
-
Stable tag: 3.0.
|
| 8 |
|
| 9 |
== Description ==
|
| 10 |
|
| 11 |
Simple image widget. Use native Wordpress upload thickbox to add image widgets to your site.
|
| 12 |
|
| 13 |
* MU Compatible
|
| 14 |
-
* Handles image resizing
|
| 15 |
* Link the image
|
| 16 |
* Title and Description
|
| 17 |
* Very versitile. All fields are optional.
|
|
@@ -35,6 +35,19 @@ If you find any bugs or have any ideas, please mail us.
|
|
| 35 |
|
| 36 |
== Changelog ==
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
New in version 3.0.3
|
| 39 |
|
| 40 |
* Fixed the broken "Add Image" link (THANK YOU SMURKAS!!!)
|
| 4 |
Tags: widget, image, ad, banner, simple, upload, sidebar
|
| 5 |
Requires at least: 2.8
|
| 6 |
Tested up to: 2.8.4
|
| 7 |
+
Stable tag: 3.0.5
|
| 8 |
|
| 9 |
== Description ==
|
| 10 |
|
| 11 |
Simple image widget. Use native Wordpress upload thickbox to add image widgets to your site.
|
| 12 |
|
| 13 |
* MU Compatible
|
| 14 |
+
* Handles image resizing and alignment
|
| 15 |
* Link the image
|
| 16 |
* Title and Description
|
| 17 |
* Very versitile. All fields are optional.
|
| 35 |
|
| 36 |
== Changelog ==
|
| 37 |
|
| 38 |
+
New in version 3.0.5
|
| 39 |
+
|
| 40 |
+
Thank you smurkas, squigie and laurie!!! Special thanks to Cameron Clark from http://prolifique.com a.k.a capnhairdo for contributing invaluable javascript debugging skills and throwing together some great code.
|
| 41 |
+
|
| 42 |
+
* PHP4 compatibility
|
| 43 |
+
* Tighter integration with the thickbok uploader attributes including caption, description, alignment, and link
|
| 44 |
+
* Tighter image resize preview
|
| 45 |
+
* Add Image link becomes "Change Image" once image has been added
|
| 46 |
+
|
| 47 |
+
New in version 3.0.4
|
| 48 |
+
|
| 49 |
+
* Minor description changes
|
| 50 |
+
|
| 51 |
New in version 3.0.3
|
| 52 |
|
| 53 |
* Fixed the broken "Add Image" link (THANK YOU SMURKAS!!!)
|
