From 7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc Mon Sep 17 00:00:00 2001 From: donncha Date: Fri, 4 Apr 2008 16:44:15 +0000 Subject: Merged with WordPress 2.5, unstable, only for testing git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1218 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/custom-header.php | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'wp-admin/custom-header.php') diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index 8d60565..c5e5d20 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -169,7 +169,7 @@ Event.observe( window, 'load', hide_text ); - + @@ -183,7 +183,7 @@ Event.observe( window, 'load', hide_text );

- +

@@ -211,6 +211,7 @@ Event.observe( window, 'load', hide_text ); die( $file['error'] ); $url = $file['url']; + $type = $file['type']; $file = $file['file']; $filename = basename($file); @@ -218,19 +219,20 @@ Event.observe( window, 'load', hide_text ); $object = array( 'post_title' => $filename, 'post_content' => $url, - 'post_mime_type' => 'import', + 'post_mime_type' => $type, 'guid' => $url); // Save the data $id = wp_insert_attachment($object, $file); - $upload = array('file' => $file, 'id' => $id); - list($width, $height, $type, $attr) = getimagesize( $file ); if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { + // Add the meta-data + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + set_theme_mod('header_image', clean_url($url)); - $header = apply_filters('wp_create_file_in_uploads', $file, $id); // For replication + do_action('wp_create_file_in_uploads', $file, $id); // For replication return $this->finished(); } elseif ( $width > HEADER_IMAGE_WIDTH ) { $oitar = $width / HEADER_IMAGE_WIDTH; @@ -264,7 +266,7 @@ Event.observe( window, 'load', hide_text ); - +

@@ -281,22 +283,34 @@ Event.observe( window, 'load', hide_text ); $_POST['height'] = $_POST['height'] * $_POST['oitar']; } - $header = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); - $header = apply_filters('wp_create_file_in_uploads', $header); // For replication + $original = get_attached_file( $_POST['attachment_id'] ); - $parent = get_post($_POST['attachment_id']); + $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); + $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication + $parent = get_post($_POST['attachment_id']); $parent_url = $parent->guid; + $url = str_replace(basename($parent_url), basename($cropped), $parent_url); + + // Construct the object array + $object = array( + 'ID' => $_POST['attachment_id'], + 'post_title' => basename($cropped), + 'post_content' => $url, + 'post_mime_type' => 'image/jpeg', + 'guid' => $url + ); - $url = str_replace(basename($parent_url), basename($header), $parent_url); + // Update the attachment + wp_insert_attachment($object, $cropped); + wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); set_theme_mod('header_image', $url); // cleanup - $file = get_attached_file( $_POST['attachment_id'] ); - $medium = str_replace(basename($file), 'midsize-'.basename($file), $file); + $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); @unlink( apply_filters( 'wp_delete_file', $medium ) ); - wp_delete_attachment( $_POST['attachment_id'] ); + @unlink( apply_filters( 'wp_delete_file', $original ) ); return $this->finished(); } -- cgit