mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
Fix image meta after editing image, disable the Save button when no changes, fixes #11115
git-svn-id: http://svn.automattic.com/wordpress/trunk@12163 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fb1bb44d60
commit
fb0d8b44ee
@ -68,7 +68,7 @@ function wp_image_editor($post_id, $msg = false) {
|
||||
|
||||
<div class="imgedit-submit">
|
||||
<input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" 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' ); ?>" />
|
||||
<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button-primary imgedit-submit-btn" value="<?php echo esc_attr__( 'Save' ); ?>" />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
@ -92,7 +92,12 @@ function wp_image_editor($post_id, $msg = false) {
|
||||
<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>
|
||||
<p><?php _e('Discard any changes and restore the original image.');
|
||||
|
||||
if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE )
|
||||
_e(' 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>
|
||||
@ -409,6 +414,7 @@ function stream_preview_image($post_id) {
|
||||
|
||||
function wp_restore_image($post_id) {
|
||||
$meta = wp_get_attachment_metadata($post_id);
|
||||
$file = get_attached_file($post_id);
|
||||
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
|
||||
$restored = false;
|
||||
$msg = '';
|
||||
@ -418,20 +424,18 @@ function wp_restore_image($post_id) {
|
||||
return $msg;
|
||||
}
|
||||
|
||||
$parts = pathinfo($meta['file']);
|
||||
$parts = pathinfo($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 ) {
|
||||
if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
|
||||
$data = $backup_sizes['full-orig'];
|
||||
|
||||
if ( $parts['basename'] != $data['file'] ) {
|
||||
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
|
||||
// delete only if it's edited image
|
||||
if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
|
||||
$delpath = apply_filters('wp_delete_file', $meta['file']);
|
||||
$delpath = apply_filters('wp_delete_file', $file);
|
||||
@unlink($delpath);
|
||||
}
|
||||
} else {
|
||||
@ -439,14 +443,19 @@ function wp_restore_image($post_id) {
|
||||
}
|
||||
}
|
||||
|
||||
$meta['file'] = path_join($parts['dirname'], $data['file']);
|
||||
$restored_file = path_join($parts['dirname'], $data['file']);
|
||||
$restored = update_attached_file($post_id, $restored_file);
|
||||
|
||||
$meta['file'] = _wp_relative_upload_path( $restored_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 {
|
||||
}
|
||||
|
||||
foreach ( $default_sizes as $default_size ) {
|
||||
if ( isset($backup_sizes["$default_size-orig"]) ) {
|
||||
$data = $backup_sizes["$default_size-orig"];
|
||||
if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
|
||||
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
|
||||
// delete only if it's edited image
|
||||
@ -460,7 +469,6 @@ function wp_restore_image($post_id) {
|
||||
}
|
||||
|
||||
$meta['sizes'][$default_size] = $data;
|
||||
}
|
||||
} else {
|
||||
unset($meta['sizes'][$default_size]);
|
||||
}
|
||||
@ -580,7 +588,8 @@ function wp_save_image($post_id) {
|
||||
$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
|
||||
|
||||
$meta['file'] = _wp_relative_upload_path($new_path);
|
||||
$meta['width'] = imagesx($img);
|
||||
$meta['height'] = imagesy($img);
|
||||
|
||||
|
@ -88,34 +88,26 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
|
||||
$metadata = array();
|
||||
if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
|
||||
$full_path_file = $file;
|
||||
$imagesize = getimagesize( $full_path_file );
|
||||
$imagesize = getimagesize( $file );
|
||||
$metadata['width'] = $imagesize[0];
|
||||
$metadata['height'] = $imagesize[1];
|
||||
list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
|
||||
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
|
||||
|
||||
// Make the file path relative to the upload dir
|
||||
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory
|
||||
if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
|
||||
$file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
|
||||
$file = ltrim($file, '/');
|
||||
}
|
||||
}
|
||||
$metadata['file'] = $file;
|
||||
$metadata['file'] = _wp_relative_upload_path($file);
|
||||
|
||||
// make thumbnails and other intermediate sizes
|
||||
$sizes = array('thumbnail', 'medium', 'large');
|
||||
$sizes = apply_filters('intermediate_image_sizes', $sizes);
|
||||
$sizes = apply_filters( 'intermediate_image_sizes', array('thumbnail', 'medium', 'large') );
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
$resized = image_make_intermediate_size( $full_path_file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") );
|
||||
$resized = image_make_intermediate_size( $file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") );
|
||||
if ( $resized )
|
||||
$metadata['sizes'][$size] = $resized;
|
||||
}
|
||||
|
||||
// fetch additional metadata from exif/iptc
|
||||
$image_meta = wp_read_image_metadata( $full_path_file );
|
||||
$image_meta = wp_read_image_metadata( $file );
|
||||
if ( $image_meta )
|
||||
$metadata['image_meta'] = $image_meta;
|
||||
|
||||
|
@ -175,6 +175,11 @@ imageEdit = {
|
||||
if ( (typeof callback != "unknown") && callback != null )
|
||||
callback();
|
||||
|
||||
if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 )
|
||||
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
|
||||
else
|
||||
$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).attr('disabled', 'disabled');
|
||||
|
||||
t.toggleEditor(postid, 0);
|
||||
}).attr('src', ajaxurl + '?' + $.param(data));
|
||||
},
|
||||
|
File diff suppressed because one or more lines are too long
@ -68,18 +68,35 @@ function update_attached_file( $attachment_id, $file ) {
|
||||
return false;
|
||||
|
||||
$file = apply_filters( 'update_attached_file', $file, $attachment_id );
|
||||
|
||||
// Make the file path relative to the upload dir
|
||||
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory
|
||||
if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
|
||||
$file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
|
||||
$file = ltrim($file, '/');
|
||||
}
|
||||
}
|
||||
$file = _wp_relative_upload_path($file);
|
||||
|
||||
return update_post_meta( $attachment_id, '_wp_attached_file', $file );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return relative path to an uploaded file.
|
||||
*
|
||||
* The path is relative to the current upload dir.
|
||||
*
|
||||
* @since 2.9
|
||||
* @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
|
||||
*
|
||||
* @param string $path Full path to the file
|
||||
* @return string relative path on success, unchanged path on failure.
|
||||
*/
|
||||
function _wp_relative_upload_path( $path ) {
|
||||
$new_path = $path;
|
||||
|
||||
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
|
||||
if ( 0 === strpos($new_path, $uploads['basedir']) ) {
|
||||
$new_path = str_replace($uploads['basedir'], '', $new_path);
|
||||
$new_path = ltrim($new_path, '/');
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( '_wp_relative_upload_path', $new_path, $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all children of the post parent ID.
|
||||
*
|
||||
|
@ -369,7 +369,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'), '20090929' );
|
||||
$scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20091111' );
|
||||
$scripts->add_data( 'image-edit', 'group', 1 );
|
||||
|
||||
$scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), '20091021' );
|
||||
|
Loading…
Reference in New Issue
Block a user