Image Editor improvements, see #10528

git-svn-id: http://svn.automattic.com/wordpress/trunk@11965 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-09-24 01:54:07 +00:00
parent e1c0fad754
commit 48932f96fe
14 changed files with 845 additions and 371 deletions

View File

@ -111,7 +111,7 @@ case 'wp-compression-test' :
die('0');
break;
case 'load-preview-image' :
case 'imgedit-preview' :
$post_id = intval($_GET['postid']);
if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
die('-1');
@ -1348,29 +1348,30 @@ case 'save-widget' :
die();
break;
case 'image-edit-save':
// $post_id is the attachment ID
$post_id = intval($_POST['postid']);
if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
case 'image-editor':
$attachment_id = intval($_POST['postid']);
if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
die('-1');
check_ajax_referer( "image_editor-$post_id" );
check_ajax_referer( "image_editor-$attachment_id" );
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
$msg = wp_save_image($post_id);
die($msg);
break;
case 'open-image-editor' :
$post_id = intval($_POST['postid']);
if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
die('-1');
check_ajax_referer( "image_editor-$post_id" );
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
wp_image_editor($post_id);
$msg = false;
switch ( $_POST['do'] ) {
case 'save' :
$msg = wp_save_image($attachment_id);
$msg = json_encode($msg);
die($msg);
break;
case 'scale' :
$msg = wp_save_image($attachment_id);
break;
case 'restore' :
$msg = wp_restore_image($attachment_id);
break;
}
wp_image_editor($attachment_id, $msg);
die();
break;
default :

File diff suppressed because one or more lines are too long

View File

@ -585,7 +585,8 @@ input.readonly, textarea.readonly {
color: #b6d1e4;
}
#media-items {
#media-items,
.imgedit-group {
border-color: #dfdfdf;
}

File diff suppressed because one or more lines are too long

View File

@ -581,7 +581,8 @@ input.readonly, textarea.readonly {
color: #999;
}
#media-items {
#media-items,
.imgedit-group {
border-color: #dfdfdf;
}

View File

@ -1 +1 @@
div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 0 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.describe-toggle-on,.describe-toggle-off{display:block;line-height:36px;float:right;margin-right:20px;}.describe-toggle-off{display:none;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload .media-upload-form p{margin:0 1em 1em 0;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.5em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:25%;text-align:center;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;border-bottom-style:solid;border-bottom-width:1px;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;border-bottom-color:#DADADA;color:#5A5A5A;}h3.media-title{color:#5A5A5A;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;font-weight:normal;}#gallery-settings .describe td{vertical-align:middle;height:3.5em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;border:1px solid #dfdfdf;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;}
div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 8px 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.describe-toggle-on,.describe-toggle-off{display:block;line-height:36px;float:right;margin-right:20px;}.describe-toggle-off{display:none;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.2em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:25%;text-align:center;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;border-bottom-style:solid;border-bottom-width:1px;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;border-bottom-color:#DADADA;color:#5A5A5A;}h3.media-title{color:#5A5A5A;font-family:Georgia,"Times New Roman",Times,serif;font-size:1.6em;font-weight:normal;}#gallery-settings .describe td{vertical-align:middle;height:3.5em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;border:1px solid #dfdfdf;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;}

View File

@ -120,7 +120,7 @@ abbr.required {
.describe td {
vertical-align: middle;
padding: 0 5px 0 0;
padding: 0 5px 8px 0;
}
.describe td.A1 {
@ -155,10 +155,6 @@ abbr.required {
/* Specific to Uploader */
#media-upload .media-upload-form p {
margin: 0 1em 1em 0;
}
#media-upload p.ml-submit {
padding: 1em 0;
}
@ -211,7 +207,7 @@ abbr.required {
}
#media-upload .describe th.label {
padding-top: .5em;
padding-top: .2em;
text-align: left;
min-width: 120px;
}

View File

@ -6,84 +6,207 @@
* @subpackage Administration
*/
function wp_image_editor($post_id) {
function wp_image_editor($post_id, $msg = false) {
$nonce = wp_create_nonce("image_editor-$post_id");
$image_size_opt = "<option value='all'>" . __('all image sizes') . "</option>\n";
$image_size_opt .= "<option value='full'>" . __('original image') . "</option>\n";
$meta = wp_get_attachment_metadata($post_id);
if ( is_array($meta) && is_array($meta['sizes']) ) {
$sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium', 'large'));
$size_names = array(
'thumbnail' => __('thumbnail'),
'medium' => __('medium'),
'large' => __('large')
);
$thumb = image_get_intermediate_size($post_id, 'thumbnail');
$note = '';
foreach ( $sizes as $size ) {
if ( array_key_exists($size, $meta['sizes']) ) {
$size_name = isset($size_names[$size]) ? $size_names[$size] : $size;
$image_size_opt .= "<option value='$size'>$size_name</option>\n";
if ( is_array($meta) && isset($meta['width']) )
$big = max( $meta['width'], $meta['height'] );
else
wp_die( __('Image data does not exist. Please re-upload the image.') );
$sizer = $big > 400 ? 400 / $big : 1;
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']);
// temp convert backup sizes
if ( isset($meta['sizes']) && is_array($meta['sizes']) ) {
$update = false;
foreach ( $meta['sizes'] as $name => $val ) {
if ( strpos($name, 'backup-') === 0 ) {
$m = array();
preg_match('/backup-([0-9]+)-(.*)/', $name, $m);
if ( !isset($backup_sizes["{$m[2]}-orig"]) )
$n = "{$m[2]}-orig";
else
$n = "{$m[2]}-{$m[1]}";
$backup_sizes[$n] = $val;
unset($meta['sizes'][$name]);
$update = true;
}
}
} ?>
if ( $update ) {
wp_update_attachment_metadata( $post_id, $meta );
update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes);
}
}
// end temp
if ( $msg ) {
if ( isset($msg->error) )
$note = "<div class='error'><p>$msg->error</p></div>";
elseif ( isset($msg->msg) )
$note = "<div class='updated'><p>$msg->msg</p></div>";
}
?>
<div class="imgedit-wrap">
<div id="imgedit-panel-<?php echo $post_id; ?>">
<div class="imgedit-menu">
<div onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-crop" title="<?php echo esc_attr__( 'Crop' ); ?>"></div><?php
<?php echo $note; ?>
<table id="imgedit-panel-<?php echo $post_id; ?>"><tbody>
<tr><td>
<div class="imgedit-menu">
<div onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop disabled" title="<?php echo esc_attr__( 'Crop' ); ?>"></div><?php
if ( function_exists('imagerotate') ) { ?>
<div onclick="imageEdit.rotate(90, <?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-rleft" title="<?php echo esc_attr__( 'Rotate couter-clockwise' ); ?>"></div>
<div onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-rright" title="<?php echo esc_attr__( 'Rotate clockwise' ); ?>"></div><?php
<div onclick="imageEdit.rotate(90, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-rleft" title="<?php echo esc_attr__( 'Rotate couter-clockwise' ); ?>"></div>
<div onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-rright" title="<?php echo esc_attr__( 'Rotate clockwise' ); ?>"></div><?php
} ?>
<div onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-fliph" title="<?php echo esc_attr__( 'Flip horizontally' ); ?>"></div>
<div onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-flipv" title="<?php echo esc_attr__( 'Flip vertically' ); ?>"></div>
<div onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph" title="<?php echo esc_attr__( 'Flip horizontally' ); ?>"></div>
<div onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv" title="<?php echo esc_attr__( 'Flip vertically' ); ?>"></div>
<div id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-undo disabled" title="<?php echo esc_attr__( 'Undo' ); ?>"></div>
<div id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>)" class="imgedit-redo disabled" title="<?php echo esc_attr__( 'Redo' ); ?>"></div>
<div id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo disabled" title="<?php echo esc_attr__( 'Undo' ); ?>"></div>
<div id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo disabled" title="<?php echo esc_attr__( 'Redo' ); ?>"></div>
<br class="clear" />
</div>
<p>
<span id="imgedit-scale-<?php echo $post_id; ?>">
<input type="checkbox" onchange="imageEdit.scaleSwitched(<?php echo $post_id; ?>)" id="imgedit-scale-switch-<?php echo $post_id; ?>" /><label for="imgedit-scale-switch-<?php echo $post_id; ?>">Scale full size image:</label>
<span id="imgedit-scale-values-<?php echo $post_id; ?>">
<input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleWidthChanged(<?php echo $post_id; ?>)" style="width:4em;" />
&times;
<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleHeightChanged(<?php echo $post_id; ?>)" style="width:4em;" />
</span>
</span>
</p>
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-aspect-x-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-aspect-y-<?php echo $post_id; ?>" value="" />
<h4><?php _e('Preview Image:'); ?></h4>
<div id="imgedit-crop-<?php echo $post_id; ?>" style="position:relative;">
<img src="<?php echo admin_url('admin-ajax.php') . "?action=load-preview-image&amp;_ajax_nonce={$nonce}&amp;postid={$post_id}&amp;ver=" . rand(1, 99999); ?>" id="image-preview-<?php echo $post_id; ?>" />
</div>
<p>
<?php _e('Apply to:'); ?>
<select id="imgedit-save-target-<?php echo $post_id; ?>" onchange="imageEdit.targetChanged(<?php echo $post_id; ?>)">
<?php echo $image_size_opt; ?>
</select>
</p>
<p>
<input type="button" onclick="imageEdit.close(<?php echo "$post_id, '$nonce'"; ?>)" class="button" value="<?php echo esc_attr__( 'Close' ); ?>" />
<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" class="button-primary" value="<?php echo esc_attr__( 'Save' ); ?>" />
</p>
<script type="text/javascript">imageEdit.targetChanged(<?php echo $post_id; ?>);</script>
</div>
<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
<input type="hidden" id="imgedit-minthumb-<?php echo $post_id; ?>" value="<?php echo ( get_option('thumbnail_size_w') . ':' . get_option('thumbnail_size_h') ); ?>" />
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width']; ?>" />
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height']; ?>" />
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url('admin-ajax.php'); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" />
</div>
<div class="imgedit-submit">
<input type="button" onclick="imageEdit.close(<?php echo "$post_id, '$nonce'"; ?>)" class="button" value="<?php echo esc_attr__( 'Cancel' ); ?>" />
<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" class="button-primary imgedit-submit-btn" value="<?php echo esc_attr__( 'Save' ); ?>" />
</div>
</td>
<td class="imgedit-settings">
<div class="imgedit-group">
<div class="imgedit-group-top">
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Scale Image'); ?></strong></a>
<div class="imgedit-help">
<p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?></p>
<p><?php printf( __('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height'] ); ?></p>
<div class="imgedit-submit">
<span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo $meta['width']; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo $meta['height']; ?>" />
<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span>
<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button-primary" value="<?php echo esc_attr__( 'Scale' ); ?>" />
</div>
</div>
</div>
<?php if ( $can_restore ) { ?>
<div class="imgedit-group-top">
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Restore Original Image'); ?></strong></a>
<div class="imgedit-help">
<p><?php _e('Discard any changes and restore the original image. Previously edited copies of the image will not be deleted.'); ?></p>
<div class="imgedit-submit">
<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'restore')" class="button-primary" value="<?php echo esc_attr__( 'Restore image' ); ?>" <?php echo $can_restore; ?> />
</div>
</div>
</div>
<?php } ?>
</div>
<div class="imgedit-group">
<div class="imgedit-group-top">
<strong><?php _e('Image Crop'); ?></strong>
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('(help)'); ?></a>
<div class="imgedit-help">
<p><?php _e('The image can be cropped by clicking on it and dragging to select the desired part. While dragging the dimensions of the selection are displayed below.'); ?></p>
<strong><?php _e('Keyboard shortcuts'); ?></strong>
<ul>
<li><?php _e('Arrow: move by 10px'); ?></li>
<li><?php _e('Shift + arrow: move by 1px'); ?></li>
<li><?php _e('Ctrl + arrow: resize by 10px'); ?></li>
<li><?php _e('Ctrl + Shift + arrow: resize by 1px'); ?></li>
<li><?php _e('Shift + drag: lock aspect ratio'); ?></li>
</ul>
<p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br />
<?php _e('You can specify the crop selection aspect ratio then hold down the Shift key while dragging to lock it. The values can be 1:1 (square), 4:3, 16:9, etc. If there is a selection, specifying aspect ratio will set it immediately.'); ?></p>
<p><strong><?php _e('Crop Selection'); ?></strong><br />
<?php _e('Once started, the selection can be adjusted by entering new values (in pixels). Note that these values are scaled to approximately match the original image dimensions. The minimum selection size equals the thumbnail size as set in the Media settings.'); ?></p>
</div>
</div>
<p>
<?php _e('Aspect ratio:'); ?>
<span class="nowrap">
<input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" style="width:3em;" />
:
<input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" style="width:3em;" />
</span>
</p>
<p id="imgedit-crop-sel-<?php echo $post_id; ?>">
<?php _e('Selection:'); ?>
<span class="nowrap">
<input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" />
:
<input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" />
</span>
</p>
</div>
<?php if ( $thumb ) {
$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
?>
<div class="imgedit-group imgedit-applyto">
<div class="imgedit-group-top">
<strong><?php _e('Thumbnail Settings'); ?></strong>
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('(help)'); ?></a>
<p class="imgedit-help"><?php _e('The thumbnail image can be cropped differently. For example it can be square or contain only a portion of the original image to showcase it better. Here you can select whether to apply changes to all image sizes or make the thumbnail different.'); ?></p>
</div>
<p>
<img src="<?php echo $thumb['url']; ?>" width="<?php echo $thumb_img[0]; ?>" height="<?php echo $thumb_img[1]; ?>" class="imgedit-size-preview" alt="" /><br /><?php _e('Current thumbnail'); ?>
</p>
<p id="imgedit-save-target-<?php echo $post_id; ?>">
<strong><?php _e('Apply changes to:'); ?></strong><br />
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
<?php _e('All image sizes'); ?></label>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" />
<?php _e('Thumbnail'); ?></label>
<label class="imgedit-label">
<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
<?php _e('All sizes except thumbnail'); ?></label>
</p>
</div>
<?php } ?>
</td></tr>
</tbody></table>
<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
<script type="text/javascript">imageEdit.init(<?php echo $post_id; ?>);</script>
<div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor."); ?></div>
</div>
<?php
}
@ -109,7 +232,7 @@ function load_image_to_edit($post, $size = 'full') {
break;
}
if ( is_resource($image) ) {
$image = apply_filters('load_image_to_edit', $image, $post->ID); // allows plugins to remove a watermark
$image = apply_filters('load_image_to_edit', $image, $post->ID);
if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
imagealphablending($image, false);
imagesavealpha($image, true);
@ -268,7 +391,6 @@ function image_edit_apply_changes($img, $changes) {
return $img;
}
function stream_preview_image($post_id) {
$post = get_post($post_id);
@ini_set('memory_limit', '256M');
@ -297,46 +419,112 @@ function stream_preview_image($post_id) {
return true;
}
function wp_restore_image($post_id) {
$meta = wp_get_attachment_metadata($post_id);
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
$restored = false;
$msg = '';
if ( !is_array($backup_sizes) ) {
$msg->error = __('Cannot load image metadata.');
return $msg;
}
$parts = pathinfo($meta['file']);
$suffix = time() . rand(100, 999);
$default_sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') );
$default_sizes[] = 'full';
foreach ( $default_sizes as $default_size ) {
if ( isset($backup_sizes["$default_size-orig"]) ) {
$data = $backup_sizes["$default_size-orig"];
if ( 'full' == $default_size ) {
$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
$meta['file'] = path_join($parts['dirname'], $data['file']);
$meta['width'] = $data['width'];
$meta['height'] = $data['height'];
list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']);
$meta['hwstring_small'] = "height='$uheight' width='$uwidth'";
$restored = update_attached_file($post_id, $meta['file']);
} else {
if ( isset($meta['sizes'][$default_size]) )
$backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
$meta['sizes'][$default_size] = $data;
}
}
}
if ( !wp_update_attachment_metadata($post_id, $meta) || !update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes) ) {
$msg->error = __('Cannot save image metadata.');
return $msg;
}
if ( !$restored )
$msg->error = __('Image metadata is inconsistent.');
else
$msg->msg = __('Image restored successfully.');
return $msg;
}
function wp_save_image($post_id) {
$msg = '';
$success = $delete = $full_resized = false;
$return = '';
$success = $delete = $scaled = $nocrop = false;
$post = get_post($post_id);
@ini_set('memory_limit', '256M');
$img = load_image_to_edit($post);
if ( !is_resource($img) )
return 'error=' . __('Unable to create new image.');
if ( !is_resource($img) ) {
$return->error = esc_js( __('Unable to create new image.') );
return $return;
}
$fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;
$fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;
$target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';
$scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do'];
if ( !empty($_REQUEST['history']) ) {
if ( $scale && $fwidth > 0 && $fheight > 0 ) {
$sX = imagesx($img);
$sY = imagesy($img);
// check if it has roughly the same w / h ratio
if ( round($sX / $sY, 2) == round($fwidth / $fheight, 2) ) {
// scale the full size image
$dst = wp_imagecreatetruecolor($fwidth, $fheight);
if ( imagecopyresampled( $dst, $img, 0, 0, 0, 0, $fwidth, $fheight, $sX, $sY ) ) {
imagedestroy($img);
$img = $dst;
$scaled = true;
}
}
if ( !$scaled ) {
$return->error = esc_js( __('Error while saving the scaled image. Please reload the page and try again.') );
return $return;
}
} elseif ( !empty($_REQUEST['history']) ) {
$changes = json_decode( stripslashes($_REQUEST['history']) );
if ( $changes )
$img = image_edit_apply_changes($img, $changes);
} else {
$return->error = esc_js( __('Nothing to save, the image has not changed.') );
return $return;
}
if ( $fwidth > 0 && $fheight > 0 ) {
// scale the full size image
$dst = wp_imagecreatetruecolor($fwidth, $fheight);
if ( imagecopyresampled( $dst, $img, 0, 0, 0, 0, $fwidth, $fheight, imagesx($img), imagesy($img) ) ) {
imagedestroy($img);
$img = $dst;
$full_resized = true;
}
$meta = wp_get_attachment_metadata($post_id);
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
if ( !is_array($meta) ) {
$return->error = esc_js( __('Image data does not exist. Please re-upload the image.') );
return $return;
}
if ( !$changes && !$full_resized )
return 'error=' . __('Nothing to save, the image is not changed.');
$meta = wp_get_attachment_metadata($post_id, false, false);
if ( !is_array($meta) )
$meta = array();
if ( !isset($meta['sizes']) || !is_array($meta['sizes']) )
$meta['sizes'] = array();
if ( !is_array($backup_sizes) )
$backup_sizes = array();
// generate new filename
$path = get_attached_file($post_id);
@ -356,11 +544,14 @@ function wp_save_image($post_id) {
}
// save the full-size file, also needed to create sub-sizes
if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) )
return 'error=' . __('Unable to save the image.');
if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) {
$return->error = esc_js( __('Unable to save the image.') );
return $return;
}
if ( 'full' == $target || 'all' == $target || $full_resized ) {
$meta['sizes']["backup-{$suffix}-full"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
if ( 'nothumb' == $target || 'all' == $target || $scaled ) {
$tag = !isset($backup_sizes['full-orig']) ? 'full-orig' : "full-$suffix";
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
$success = update_attached_file($post_id, $new_path);
$meta['file'] = get_attached_file($post_id, true); // get the path unfiltered
@ -370,21 +561,28 @@ function wp_save_image($post_id) {
list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']);
$meta['hwstring_small'] = "height='$uheight' width='$uwidth'";
if ( $success && $target == 'all' )
if ( $success && ('nothumb' == $target || 'all' == $target) ) {
$sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') );
if ( 'nothumb' == $target )
$sizes = array_diff( $sizes, array('thumbnail') );
}
$msg .= "full={$meta['width']}x{$meta['height']}!";
} elseif ( array_key_exists($target, $meta['sizes']) ) {
$sizes = array( $target );
$success = $delete = true;
$return->fw = $meta['width'];
$return->fh = $meta['height'];
} elseif ( 'thumbnail' == $target ) {
$sizes = array( 'thumbnail' );
$success = $delete = $nocrop = true;
}
if ( isset($sizes) ) {
foreach ( $sizes as $size ) {
if ( isset($meta['sizes'][$size]) )
$meta['sizes']["backup-{$suffix}-$size"] = $meta['sizes'][$size];
if ( isset($meta['sizes'][$size]) ) {
$tag = !isset($backup_sizes["$size-orig"]) ? "$size-orig" : "$size-$suffix";
$backup_sizes[$tag] = $meta['sizes'][$size];
}
$resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") );
$crop = $nocrop ? false : get_option("{$size}_crop");
$resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), $crop );
if ( $resized )
$meta['sizes'][$size] = $resized;
@ -395,10 +593,13 @@ function wp_save_image($post_id) {
if ( $success ) {
wp_update_attachment_metadata($post_id, $meta);
update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes);
if ( $target == 'thumbnail' || $target == 'all' || ( $target == 'full' && !array_key_exists('thumbnail', $meta['sizes']) ) ) {
if ( $thumb_url = get_attachment_icon_src($post_id) )
$msg .= "thumbnail={$thumb_url[0]}";
if ( $target == 'thumbnail' || $target == 'all' ) {
if ( $thumb = $meta['sizes']['thumbnail'] ) {
$file_url = wp_get_attachment_url($post_id);
$return->thumbnail = path_join( dirname($file_url), $thumb['file'] );
}
}
} else {
$delete = true;
@ -410,6 +611,8 @@ function wp_save_image($post_id) {
}
imagedestroy($img);
return $msg;
$return->msg = esc_js( __('Image saved') );
return $return;
}

View File

@ -249,7 +249,7 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
*/
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
@ -522,7 +522,7 @@ function media_sideload_image($file, $post_id, $desc = null) {
if (!empty($file) ) {
// Download file to temp location
$tmp = download_url($file);
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
@ -534,18 +534,18 @@ function media_sideload_image($file, $post_id, $desc = null) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$id = media_handle_sideload($file_array, $post_id, @$desc);
$src = $id;
// If error storing permanently, unlink
if ( is_wp_error($id) ) {
@unlink($file_array['tmp_name']);
return $id;
}
}
// Finally check to make sure the file has been saved, then return the html
if ( !empty($src) ) {
$alt = @$desc;
@ -1167,7 +1167,7 @@ function get_media_item( $attachment_id, $args = null ) {
$image_edit_button = '';
if ( gd_edit_image_support($post->post_mime_type) ) {
$nonce = wp_create_nonce("image_editor-$post->ID");
$image_edit_button = "<tr><td class='A1B1'><input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open($post->ID, \"$nonce\")' class='button' value='" . esc_attr__( 'Edit image' ) . "' /> <img src='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' /></td></tr>";
$image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open($post->ID, \"$nonce\")' class='button' value='" . esc_attr__( 'Edit image' ) . "' /> <img src='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' />";
}
$item = "
@ -1178,16 +1178,17 @@ function get_media_item( $attachment_id, $args = null ) {
<table class='slidetoggle describe $class'>
<thead class='media-item-info' id='media-head-$post->ID'>
<tr>
<td class='A1B1' rowspan='5'><img class='thumbnail' src='$thumb_url' alt='' /></td>
<td class='A1B1' id='thumbnail-head-$post->ID' rowspan='5'><img class='thumbnail' src='$thumb_url' alt='' /></td>
<td>$filename</td>
</tr>
<tr><td>$post->post_mime_type</td></tr>
<tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
<tr><td>" . apply_filters('media_meta', $media_dims, $post) . "</td></tr>
$image_edit_button
<tr><td class='A1B1'>$image_edit_button</td></tr>
</thead>
<tbody>
<tr><td style='display:none' colspan='2' id='image-editor-$post->ID'></td></tr>\n";
<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
$defaults = array(
'input' => 'text',

View File

@ -3,38 +3,50 @@ var imageEdit;
(function($) {
imageEdit = {
iasapi : {},
hold : {},
postid : '',
intval : function(f) {
return f | 0;
},
setState : function(el, s) {
if ( s )
el.removeAttr('disabled');
else
el.attr('disabled', 'disabled');
},
setClass : function(el, c) {
if ( c )
setDisabled : function(el, s) {
if ( s ) {
el.removeClass('disabled');
else
$('input', el).removeAttr('disabled');
} else {
el.addClass('disabled');
$('input', el).attr('disabled', 'disabled');
}
},
gcd : function(a, b) {
var r;
if ( a == 0 || b == 0 )
return 0;
else if ( a == b )
return a;
else {
do {
r = a % b;
a = b; b = r;
} while ( r != 0 );
return a;
}
init : function(postid, nonce) {
var t = this, old = $('#image-editor-' + t.postid),
x = t.intval( $('#imgedit-x-' + postid).val() ),
y = t.intval( $('#imgedit-y-' + postid).val() );
if ( t.postid != postid && old.length )
t.close(t.postid);
t.hold['w'] = t.hold['ow'] = x;
t.hold['h'] = t.hold['oh'] = y;
t.hold['xy_ratio'] = x / y;
t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() );
t.postid = postid;
$('#imgedit-response-' + postid).empty();
$('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) {
var k = e.keyCode;
if ( 36 < k && k < 41 )
$(this).blur()
if ( 13 == k ) {
e.preventDefault();
e.stopPropagation();
return false;
}
});
},
toggleEditor : function(postid, toggle) {
@ -43,243 +55,256 @@ imageEdit = {
if ( toggle )
wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast');
else
wait.height(500).fadeOut('fast');
wait.fadeOut('fast');
},
isChecked : function(chkbox) {
return ( !chkbox.attr('disabled') && chkbox[0].checked );
toggleHelp : function(el) {
$(el).siblings('.imgedit-help').slideToggle('fast');
return false;
},
getAspect : function(postid) {
var enable = this.isChecked( $('#imgedit-scale-switch-' + postid) ), X, Y;
getTarget : function(postid) {
return $('input:checked', '#imgedit-save-target-' + postid).val() || 'all';
},
if ( enable ) {
X = this.intval( $('#imgedit-aspect-x-' + postid).val() );
Y = this.intval( $('#imgedit-aspect-y-' + postid).val() );
return X / Y;
scaleChanged : function(postid, x) {
var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid),
warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = '';
if ( x ) {
h1 = (w.val() != '') ? this.intval( w.val() / this.hold['xy_ratio'] ) : '';
h.val( h1 );
} else {
return 0;
w1 = (h.val() != '') ? this.intval( h.val() * this.hold['xy_ratio'] ) : '';
w.val( w1 );
}
if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) )
warn.css('visibility', 'visible');
else
warn.css('visibility', 'hidden');
},
scaleWidthChanged : function(postid) {
var src = $('#imgedit-scale-width-' + postid), aspect;
getSelRatio : function(postid) {
var x = this.hold['w'], y = this.hold['h'],
X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
if ( !src.attr('disabled') ) {
aspect = this.getAspect(postid);
if ( X && Y )
return X + ':' + Y;
if ( aspect != 0 )
$('#imgedit-scale-height-' + postid).val( (src.val() != '') ? this.intval( src.val() / aspect ) : '' );
}
},
if ( x && y )
return x + ':' + y;
scaleHeightChanged : function(postid) {
var src = $('#imgedit-scale-height-' + postid), aspect;
if ( !src.attr('disabled') ) {
aspect = this.getAspect(postid);
if ( aspect != 0 )
$('#imgedit-scale-width-' + postid).val( (src.val() != '') ? this.intval(src.val() * aspect) : '' );
}
},
setDefaultAspect : function(postid) {
var t = this, g, host = $('#image-preview-' + postid),
X = host.attr('width'), Y = host.attr('height');
while( (g = t.gcd(X, Y) ) > 1) {
X = t.intval( Math.ceil(X / g) );
Y = t.intval( Math.ceil(Y / g) );
}
if ( X > 10 && Y > 10 ) {
while ( X > 10 && Y > 10 ) {
X = t.intval( Math.ceil(X / 10) );
Y = t.intval( Math.ceil(Y / 10) );
}
while( ( g = t.gcd(X, Y) ) > 1) {
X = t.intval( Math.ceil(X / g) );
Y = t.intval( Math.ceil(Y / g) );
}
}
$('#imgedit-aspect-x-' + postid).val(X);
$('#imgedit-aspect-y-' + postid).val(Y);
return '1:1';
},
filterHistory : function(postid) {
// apply undo state to history
var history = $('#imgedit-history-' + postid).val(), pop;
var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
if ( history != '' ) {
history = JSON.parse(history);
pop = this.intval( $('#imgedit-undone-' + postid).val() );
if ( pop > 0 ) {
history = JSON.parse(history);
while ( pop > 0 ) {
history.pop();
pop--;
}
history = JSON.stringify(history);
}
if ( !history.length ) {
this.newDims(postid, this.hold['ow'], this.hold['oh']);
return '';
}
// restore
o = history[history.length - 1];
if ( o.hasOwnProperty('c') ) {
this.newDims(postid, o.c.fw, o.c.fh);
} else if ( o.hasOwnProperty('r') ) {
this.newDims(postid, o.r.fw, o.r.fh);
} else if ( o.hasOwnProperty('f') ) {
this.newDims(postid, o.f.fw, o.f.fh);
}
// filter the values
for ( n in history ) {
i = history[n];
if ( i.hasOwnProperty('c') ) {
op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } };
} else if ( i.hasOwnProperty('r') ) {
op[n] = { 'r': i.r.r };
} else if ( i.hasOwnProperty('f') ) {
op[n] = { 'f': i.f.f };
}
}
return JSON.stringify(op);
}
return history;
return '';
},
refreshEditor : function(postid, nonce, callback) {
var t = this, data, host;
var t = this, data, img;
t.toggleEditor(postid, 1);
data = {
'action': 'load-preview-image',
'action': 'imgedit-preview',
'_ajax_nonce': nonce,
'postid': postid,
'history': t.filterHistory(postid),
'rand': t.intval(Math.random() * 1000000)
};
host = $('<img id="image-preview-' + postid + '" />');
host.load( function() {
var parent = $('#imgedit-crop-' + postid);
img = $('<img id="image-preview-' + postid + '" />');
img.load( function() {
var parent = $('#imgedit-crop-' + postid), t = imageEdit;
parent.empty().append(host);
t.initCrop(postid, host, parent);
$('#imgedit-panel-' + postid).show();
parent.empty().append(img);
t.initCrop(postid, img, parent);
t.setCropSelection(postid, 0);
if ( (typeof callback != "unknown") && callback != null )
callback();
t.toggleEditor(postid, 0);
}).attr('src', ajaxurl + '?' + $.param(data));
},
save : function(postid, nonce) {
var t = this, fwidth = -1, fheight = -1, w, h, data,
scaled = t.isChecked( $('#imgedit-scale-switch-' + postid) ),
target = $('#imgedit-save-target-' + postid).val();
action : function(postid, nonce, action) {
var t = this, data, w, h, fw, fh;
if ( scaled ) {
w = $('#imgedit-scale-width-' + postid);
h = $('#imgedit-scale-height-' + postid);
fwidth = t.intval(w.val());
fheight = t.intval(h.val());
if ( t.notsaved(postid) )
return false;
if ( fwidth <= 0 ) {
data = {
'action': 'image-editor',
'_ajax_nonce': nonce,
'postid': postid
};
if ( 'scale' == action ) {
w = $('#imgedit-scale-width-' + postid),
h = $('#imgedit-scale-height-' + postid),
fw = t.intval(w.val()),
fh = t.intval(h.val());
if ( fw < 1 ) {
w.focus();
return;
} else if ( fheight <= 0 ) {
return false;;
} else if ( fh < 1 ) {
h.focus();
return;
return false;;
}
if ( fw == t.hold.ow || fh == t.hold.oh )
return false;
data['do'] = 'scale';
data['fwidth'] = fw;
data['fheight'] = fh;
} else if ( 'restore' == action ) {
data['do'] = 'restore';
} else {
return false;
}
t.toggleEditor(postid, 1);
data = {
'action': 'image-edit-save',
'_ajax_nonce': nonce,
'postid': postid,
'history': t.filterHistory(postid),
'target': target,
'fwidth': fwidth,
'fheight': fheight
};
$.post(ajaxurl, data, function(r) {
var fields = r.split('!'), pair, res, fw, fh, i, thumbnail;
for ( i = 0; i < fields.length; i++ ) {
pair = fields[i].split('=');
if ( pair.length == 2 ) {
switch ( pair[0] ) {
case 'full':
// update full size dimensions
res = pair[1].split('x');
if ( res.length == 2 ) {
fw = res[0];
fh = res[1];
$('#image-dims-' + postid).html( fw + '&nbsp;&times;&nbsp;' + fh );
}
// clear undo history, it's no longer valid since we changed the original full size image
$('#imgedit-history-' + postid).val('');
$('#imgedit-undone-' + postid).val(0);
t.setClass($('#image-undo-' + postid), false);
t.setClass($('#image-redo-' + postid), false);
break;
case 'thumbnail':
// force a reload of the thumbnail ??
thumbnail = $('#media-item-' + postid);
if ( thumbnail.length == 0 ) {
// when the flash uploader is employed media items are named 'media-item-SWFUpload_n_n' with n >= 0
// we therefore try to locate a known element and navigate up to the image-item-info div object
thumbnail = $('#media-dims-' + postid).closest('.media-item-info');
}
thumbnail = thumbnail.find('.thumbnail');
thumbnail.attr('src', pair[1]);
break;
case 'error':
$('#imgedit-panel-' + postid).html(pair[1]);
}
}
}
$('#image-editor-' + postid).empty().append(r);
t.toggleEditor(postid, 0);
});
},
save : function(postid, nonce) {
var data, target = this.getTarget(postid), history = this.filterHistory(postid);
if ( '' == history )
return false;
this.toggleEditor(postid, 1);
data = {
'action': 'image-editor',
'_ajax_nonce': nonce,
'postid': postid,
'history': history,
'target': target,
'do': 'save'
};
$.post(ajaxurl, data, function(r) {
var ret = JSON.parse(r);
if ( ret.error ) {
$('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p><div>');
imageEdit.close(postid);
return;
}
if ( ret.fw && ret.fh )
$('#media-dims-' + postid).html( ret.fw + ' &times; ' + ret.fh );
if ( ret.thumbnail )
$('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail);
if ( ret.msg )
$('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>');
imageEdit.close(postid);
});
},
open : function(postid, nonce) {
var t = this, data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('img');
btn.attr('disabled', 'disabled');
spin.css('visibility', 'visible');
data = {
'action': 'open-image-editor',
'action': 'image-editor',
'_ajax_nonce': nonce,
'postid': postid
'postid': postid,
'do': 'open'
};
elem.load(ajaxurl, data, function() {
elem.fadeIn('fast');
head.fadeOut('fast', function(){
btn.removeAttr('disabled');
spin.css('visibility', 'hidden');
});
t.toggleEditor(postid, 1);
$('#image-preview-' + postid).load(function(){
var t = imageEdit, parent = $('#imgedit-crop-' + postid);
t.initCrop(postid, this, parent);
t.setDefaultAspect(postid);
t.toggleEditor(postid, 0);
});
});
},
imgLoaded : function(postid) {
var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid);
this.initCrop(postid, img, parent);
this.setCropSelection(postid, 0);
this.toggleEditor(postid, 0);
},
initCrop : function(postid, image, parent) {
var t = this;
var t = this, selW = $('#imgedit-sel-width-' + postid),
selH = $('#imgedit-sel-height-' + postid);
t.iasapi = $(image).imgAreaSelect({
parent: parent,
instance: true,
handles: true,
keys: true,
minHeight: 5,
minWidth: 5,
minWidth: 3,
minHeight: 3,
onInit: function(img, c) {
parent.children().mousedown(function(e){
var sel, ratio = false, X = t.intval( $('#imgedit-aspect-x-' + postid).val() ),
Y = t.intval( $('#imgedit-aspect-y-' + postid).val() );
defRatio = ( X && Y ) ? X + ':' + Y : '1:1';
var ratio = false, sel, defRatio;
if ( e.shiftKey ) {
sel = t.iasapi.getSelection();
ratio = ( sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio;
defRatio = t.getSelRatio(postid);
ratio = ( sel && sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio;
}
t.iasapi.setOptions({
@ -288,18 +313,72 @@ imageEdit = {
});
},
onSelectStart: function(img, c) {
imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1);
},
onSelectEnd: function(img, c) {
var sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
$('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
imageEdit.setCropSelection(postid, c);
},
onSelectChange: function(img, c) {
var sizer = imageEdit.hold.sizer;
selW.val( imageEdit.round(c.width / sizer) );
selH.val( imageEdit.round(c.height / sizer) );
}
});
},
setCropSelection : function(postid, c) {
var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
sizer = this.hold['sizer'];
min = min.split(':');
c = c || 0;
if ( !c || ( c.width < 3 && c.height < 3 ) ) {
this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
this.setDisabled($('#imgedit-crop-sel-' + postid), 0);
$('#imgedit-sel-width-' + postid).val('');
$('#imgedit-sel-height-' + postid).val('');
$('#imgedit-selection-' + postid).val('');
return false;
}
if ( c.width < (min[0] * sizer) && c.height < (min[1] * sizer) ) {
this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
$('#imgedit-selection-' + postid).val('');
return false;
}
sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1);
$('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
},
close : function(postid) {
if ( this.notsaved(postid) )
return false;
this.iasapi = {};
this.hold = {};
$('#image-editor-' + postid).fadeOut('fast', function() {
$('#media-head-' + postid).fadeIn('fast');
$(this).empty();
});
},
notsaved : function(postid) {
var h = $('#imgedit-history-' + postid).val(),
history = (h != '') ? JSON.parse(h) : new Array(),
pop = this.intval( $('#imgedit-undone-' + postid).val() );
if ( pop < history.length ) {
if ( confirm( $('#imgedit-leaving-' + postid).html() ) )
return false;
return true;
}
return false;
},
addStep : function(op, postid, nonce) {
var t = this, elem = $('#imgedit-history-' + postid),
@ -317,26 +396,47 @@ imageEdit = {
elem.val( JSON.stringify(history) );
t.refreshEditor(postid, nonce, function() {
t.setClass($('#image-undo-' + postid), true);
t.setClass($('#image-redo-' + postid), false);
t.setDisabled($('#image-undo-' + postid), true);
t.setDisabled($('#image-redo-' + postid), false);
});
},
rotate : function(angle, postid, nonce) {
this.addStep({ 'r': angle }, postid, nonce);
rotate : function(angle, postid, nonce, t) {
if ( $(t).hasClass('disabled') )
return false;
this.addStep({ 'r': { 'r': angle, 'fw': this.hold['h'], 'fh': this.hold['w'] }}, postid, nonce);
},
flip : function (axis, postid, nonce) {
this.addStep({ 'f': axis }, postid, nonce);
flip : function (axis, postid, nonce, t) {
if ( $(t).hasClass('disabled') )
return false;
this.addStep({ 'f': { 'f': axis, 'fw': this.hold['w'], 'fh': this.hold['h'] }}, postid, nonce);
},
crop : function (postid, nonce) {
// w, h are the new full size dims
newDims : function(postid, w, h) {
var max = Math.max( w, h ), s;
s = max > 400 ? 400 / max : 1;
this.hold['sizer'] = s;
this.hold['w'] = w;
this.hold['h'] = h;
return s;
},
crop : function (postid, nonce, t) {
var sel = $('#imgedit-selection-' + postid).val();
if ( sel != '' ) {
sel = JSON.parse(sel);
if ( sel.w > 0 && sel.h > 0 )
this.addStep({ 'c': sel }, postid, nonce);
if ( $(t).hasClass('disabled') || sel == '' )
return false;
sel = JSON.parse(sel);
if ( sel.w > 0 && sel.h > 0 ) {
sel['fw'] = this.intval( $('#imgedit-sel-width-' + postid).val() );
sel['fh'] = this.intval( $('#imgedit-sel-height-' + postid).val() );
this.addStep({ 'c': sel }, postid, nonce);
}
},
@ -352,8 +452,8 @@ imageEdit = {
var elem = $('#imgedit-history-' + postid),
history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array();
t.setClass($('#image-redo-' + postid), true);
t.setClass(button, pop < history.length);
t.setDisabled($('#image-redo-' + postid), true);
t.setDisabled(button, pop < history.length);
});
},
@ -366,27 +466,98 @@ imageEdit = {
elem.val(pop);
t.refreshEditor(postid, nonce, function() {
t.setClass($('#image-undo-' + postid), true);
t.setClass(button, pop > 0);
t.setDisabled($('#image-undo-' + postid), true);
t.setDisabled(button, pop > 0);
});
},
scaleSwitched : function(postid) {
var enable = this.isChecked( $('#imgedit-scale-switch-' + postid) );
setNumSelection : function(postid) {
var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid),
x = this.intval( elX.val() ), y = this.intval( elY.val() ),
img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
sizer = this.hold['sizer'], x1, y1, x2, y2, ias = this.iasapi;
this.setState($('#imgedit-scale-width-' + postid), enable);
this.setState($('#imgedit-scale-height-' + postid), enable);
// this.setClass($('#imgedit-scale-values-' + postid), !enable);
this.scaleWidthChanged(postid);
if ( x < 1 ) {
elX.val('');
return false;
}
if ( y < 1 ) {
elY.val('');
return false;
}
if ( x && y && ( sel = ias.getSelection() ) ) {
x2 = sel.x1 + Math.round( x * sizer );
y2 = sel.y1 + Math.round( y * sizer );
x1 = sel.x1;
y1 = sel.y1;
if ( x2 > imgw ) {
x1 = 0;
x2 = imgw;
elX.val( Math.round( x2 / sizer ) );
}
if ( y2 > imgh ) {
y1 = 0;
y2 = imgh;
elY.val( Math.round( y2 / sizer ) );
}
ias.setSelection( x1, y1, x2, y2 );
ias.update();
this.setCropSelection(postid, ias.getSelection());
}
},
round : function(num) {
var s;
num = Math.round(num);
if ( this.hold.sizer > 0.6 )
return num;
s = num.toString().slice(-1);
if ( '1' == s )
return num - 1;
else if ( '9' == s )
return num + 1;
return num;
},
targetChanged : function(postid) {
var target = $('#imgedit-save-target-' + postid).val(),
enable = (target == 'full' || target == 'all');
setRatioSelection : function(postid, n, el) {
var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ),
y = this.intval( $('#imgedit-crop-height-' + postid).val() ),
h = $('#image-preview-' + postid).height();
this.setState($('#imgedit-scale-switch-' + postid), enable);
this.setClass($('#imgedit-scale-' + postid), !enable);
this.scaleSwitched(postid);
if ( !this.intval( $(el).val() ) ) {
$(el).val('');
return;
}
if ( x && y ) {
this.iasapi.setOptions({
aspectRatio: x + ':' + y
});
if ( sel = this.iasapi.getSelection(true) ) {
r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) );
if ( r > h ) {
r = h;
if ( n )
$('#imgedit-crop-height-' + postid).val('');
else
$('#imgedit-crop-width-' + postid).val('');
}
this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r );
this.iasapi.update();
}
}
}
}
})(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -1292,8 +1292,7 @@ strong .post-com-count {
clear: both;
}
.form-table td,
#wpbody-content .describe td {
.form-table td {
margin-bottom: 9px;
padding: 8px 10px;
line-height: 20px;
@ -1306,8 +1305,7 @@ strong .post-com-count {
text-shadow: rgba(255,255,255,1) 0 1px 0;
}
.form-table th,
#wpbody-content .describe th {
.form-table th {
vertical-align: top;
text-align: left;
padding: 10px;
@ -2834,6 +2832,13 @@ table .inline-edit-row fieldset ul.cat-hover {
padding: 5px;
}
#wpbody-content .describe th {
vertical-align: top;
text-align: left;
padding: 10px;
width: 140px;
}
#wpbody-content .describe .media-item-info tr {
background-color: transparent;
}
@ -2842,8 +2847,8 @@ table .inline-edit-row fieldset ul.cat-hover {
padding: 4px 10px 0;
}
#wpbody-content .describe .media-item-info .A1B1 {
padding-bottom: 8px;
.describe .media-item-info .A1B1 {
padding: 0 15px 8px 0;
}
#wpbody-content .filename {
@ -2917,6 +2922,11 @@ abbr.required {
width: 100%;
}
#wpbody-content .media-single .media-item {
border-bottom-style: none;
border-bottom-width: 0;
}
#wpbody-content #media-items {
border-style: solid solid none;
border-width: 1px;
@ -3343,15 +3353,41 @@ label,
top: -3px;
}
.describe .image-editor {
vertical-align: top;
}
.imgedit-wrap {
position: relative;
min-height: 500px;
}
.imgedit-settings p {
margin: 8px 0;
}
.describe .imgedit-wrap table td {
vertical-align: top;
padding-top: 0;
}
.imgedit-wrap p,
.describe .imgedit-wrap table td {
font-size: 11px;
line-height: 18px;
}
.describe .imgedit-wrap table td.imgedit-settings {
padding: 0 5px;
}
td.imgedit-settings input {
vertical-align: middle;
}
.imgedit-wait {
position: absolute;
top: 0;
background: #FFFFFF url(images/wpspin_light.gif) no-repeat scroll 200px 75px;
background: #FFFFFF url(images/wpspin_light.gif) no-repeat scroll 22px 10px;
opacity: 0.7;
filter: alpha(opacity=70);
width: 100%;
@ -3359,7 +3395,8 @@ label,
display: none;
}
.media-disabled {
.media-disabled,
.imgedit-settings .disabled {
color: grey;
}
@ -3370,7 +3407,8 @@ label,
}
.imgedit-menu {
margin: 5px 0;
margin: 0 0 12px;
min-width: 315px;
}
.imgedit-menu div {
@ -3385,6 +3423,10 @@ label,
border-style: solid;
}
.imgedit-crop-wrap {
position: relative;
}
.imgedit-crop {
background: transparent url(images/imgedit.gif) no-repeat scroll -62px 2px;
margin: 0 8px 0 0;
@ -3421,3 +3463,71 @@ label,
}
.imgedit-applyto img {
margin: 0 8px 0 0;
}
.imgedit-group-top {
margin: 5px 0;
}
.imgedit-applyto .imgedit-label {
padding: 2px 0 0;
display: block;
}
.imgedit-help {
display: none;
font-style: italic;
margin-bottom: 8px;
}
.imgedit-help ul li {
font-size: 11px;
}
a.imgedit-help-toggle {
text-decoration: none;
}
#wpbody-content .imgedit-response div {
width: 600px;
margin: 8px;
}
.form-table td.imgedit-response {
padding: 0;
}
.imgedit-submit {
margin: 8px 0;
}
.imgedit-submit-btn {
margin-left: 20px;
}
.imgedit-wrap .nowrap {
white-space: nowrap;
}
span.imgedit-scale-warn {
color: red;
font-size: 20px;
font-style: normal;
visibility: hidden;
vertical-align: middle;
}
.imgedit-group {
border-width: 1px;
border-style: solid;
-moz-border-radius: 8px;
-khtml-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
margin-bottom: 8px;
padding: 2px 10px;
}

View File

@ -2575,7 +2575,8 @@ function wp_delete_attachment($post_id) {
delete_post_meta($post_id, '_wp_trash_meta_status');
delete_post_meta($post_id, '_wp_trash_meta_time');
$meta = wp_get_attachment_metadata( $post_id, false, false );
$meta = wp_get_attachment_metadata( $post_id );
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
$file = get_attached_file( $post_id );
do_action('delete_attachment', $post_id);
@ -2609,14 +2610,11 @@ function wp_delete_attachment($post_id) {
}
}
if ( isset($meta['sizes']) && is_array($meta['sizes']) ) {
foreach ( array_keys($meta['sizes']) as $size ) {
if ( preg_match('/backup-[0-9]+/', $size) ) { // make sure this is a backup
if ( $del = image_get_intermediate_size($post_id, $size) ) {
$del_file = apply_filters('wp_delete_file', $del['path']);
@ unlink( path_join($uploadpath['basedir'], $del_file) );
}
}
if ( is_array($backup_sizes) ) {
foreach ( $backup_sizes as $size ) {
$del_file = path_join( dirname($meta['file']), $size['file'] );
$del_file = apply_filters('wp_delete_file', $del_file);
@ unlink( path_join($uploadpath['basedir'], $del_file) );
}
}
@ -2639,21 +2637,13 @@ function wp_delete_attachment($post_id) {
* @param bool $unfiltered Optional, default is false. If true, filters are not run.
* @return string|bool Attachment meta field. False on failure.
*/
function wp_get_attachment_metadata( $post_id, $unfiltered = false, $remove_backups = true ) {
function wp_get_attachment_metadata( $post_id, $unfiltered = false ) {
$post_id = (int) $post_id;
if ( !$post =& get_post( $post_id ) )
return false;
$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
if ( $remove_backups && isset($data['sizes']) && is_array($data['sizes']) ) {
$sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') );
foreach ( $data['sizes'] as $size => $val ) {
if ( !in_array( $size, $sizes, true ) )
unset($data['sizes'][$size]);
}
}
if ( $unfiltered )
return $data;

View File

@ -405,7 +405,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'codepress', '/wp-includes/js/codepress/codepress.js', false, '0.9.6' );
$scripts->add_data( 'codepress', 'group', 1 );
$scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090831' );
$scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090922' );
$scripts->add_data( 'image-edit', 'group', 1 );
}
}
@ -442,12 +442,12 @@ function wp_default_styles( &$styles ) {
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' );
// all colors stylesheets need to have the same query strings (cache manifest compat)
$colors_version = '20090824';
$colors_version = '20090922';
$styles->add( 'wp-admin', "/wp-admin/wp-admin$suffix.css", array(), '20090824' );
$styles->add_data( 'wp-admin', 'rtl', "/wp-admin/rtl$suffix.css" );
$styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20090824' );
$styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20090922' );
$styles->add_data( 'ie', 'conditional', 'lte IE 7' );
// Register "meta" stylesheet for admin colors. All colors-* style sheets should have the same version string.
@ -460,7 +460,7 @@ function wp_default_styles( &$styles ) {
$styles->add_data( 'colors-classic', 'rtl', true );
$styles->add( 'global', "/wp-admin/css/global$suffix.css", array(), '20090630' );
$styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20090612' );
$styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20090922' );
$styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array(), '20090603' );
$styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css", array(), '20090514' );
$styles->add( 'install', "/wp-admin/css/install$suffix.css", array(), '20090514' );