Ticket #2794: 2794.diff
File 2794.diff, 9.8 KB (added by , 19 years ago) |
---|
-
wp-includes/default-filters.php
114 114 // Misc filters 115 115 add_filter('option_ping_sites', 'privacy_ping_filter'); 116 116 117 // Attachments 118 add_filter('wp_thumbnail_attachment_image/jpeg', 'wp_image_thumbnail', 10, -1); 119 add_filter('wp_thumbnail_attachment_image/gif', 'wp_image_thumbnail', 10, -1); 120 add_filter('wp_thumbnail_attachment_image/png', 'wp_image_thumbnail', 10, -1); 121 117 122 // Actions 118 123 add_action('wp_head', 'rsd_link'); 119 124 add_action('publish_future_post', 'wp_publish_post', 10, 1); -
wp-includes/functions-post.php
355 355 356 356 clean_post_cache($post_ID); 357 357 358 if ( $update ) {358 if ( $update ) 359 359 do_action('edit_attachment', $post_ID); 360 } else {360 else 361 361 do_action('add_attachment', $post_ID); 362 }363 362 364 363 return $post_ID; 365 364 } 366 365 366 function wp_thumbnail_attachment( $post_ID ) { 367 $attachment =& get_post( $post_ID ); 368 $meta = get_post_meta( $post_ID, '_wp_attachment_metadata', true ); 369 $file = get_post_meta( $post_ID, '_wp_attached_file', true ); 370 371 $meta = apply_filters( 'wp_thumbnail_attachment_' . strtolower($attachment->post_mime_type), $meta, $post_ID, $file ); 372 373 if ( !$meta || is_wp_error( $meta ) ) 374 add_post_meta( $post_ID, '_wp_attachment_metadata', array() ); 375 else 376 add_post_meta( $post_ID, '_wp_attachment_metadata', $meta ); 377 return $meta; 378 } 379 367 380 function wp_delete_attachment($postid) { 368 381 global $wpdb; 369 382 $postid = (int) $postid; -
wp-admin/inline-uploading.php
71 71 ); 72 72 73 73 // Save the data 74 $id = wp_insert_attachment( $attachment, $file, $post);74 $id = wp_insert_attachment( $attachment, $file, $post ); 75 75 76 if ( preg_match('!^image/!', $attachment['post_mime_type']) ) { 77 // Generate the attachment's postmeta. 78 $imagesize = getimagesize($file); 79 $imagedata['width'] = $imagesize['0']; 80 $imagedata['height'] = $imagesize['1']; 81 list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); 82 $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; 83 $imagedata['file'] = $file; 76 $error = wp_thumbnail_attachment( $id ); 84 77 85 add_post_meta($id, '_wp_attachment_metadata', $imagedata); 86 87 if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { 88 if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) 89 $thumb = wp_create_thumbnail($file, 128); 90 elseif ( $imagedata['height'] > 96 ) 91 $thumb = wp_create_thumbnail($file, 96); 92 93 if ( @file_exists($thumb) ) { 94 $newdata = $imagedata; 95 $newdata['thumb'] = basename($thumb); 96 update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata); 97 } else { 98 $error = $thumb; 99 } 100 } 101 } else { 102 add_post_meta($id, '_wp_attachment_metadata', array()); 78 if ( is_wp_error( $error ) ) { 79 echo "<div class='error'>\n\t<ul>\n"; 80 foreach ( $error->get_error_messages() as $message ) 81 echo "\t\t<li>$message</li>\n"; 82 echo "\t</ul>\n\t<a href='" . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0". "'>" . __('Continue') . "</a>\n</div>\n"; 83 die(); 103 84 } 104 85 86 105 87 header("Location: " . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0"); 106 88 die(); 107 89 -
wp-admin/admin-functions.php
771 771 return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC"); 772 772 } 773 773 774 function wp_create_thumbnail($file, $max_side, $effect = '') { 774 function wp_image_thumbnail( $meta, $post_ID, $file ) { 775 $attachment =& get_post( $post_ID ); 775 776 776 // 1 = GIF, 2 = JPEG, 3 = PNG 777 if ( is_wp_error( $meta ) || isset($meta['thumb']) ) 778 return $meta; 779 if ( !is_array($meta) ) 780 $meta = array(); 777 781 778 if (file_exists($file)) { 779 $type = getimagesize($file); 782 if ( preg_match('!^image/!', $attachment->post_mime_type) ) { 783 // Generate the attachment's postmeta. 784 $imagesize = getimagesize($file); 785 $meta['width'] = $imagesize['0']; 786 $meta['height'] = $imagesize['1']; 787 list($uwidth, $uheight) = get_udims( $meta['width'], $meta['height'] ); 788 $meta['hwstring_small'] = "height='$uheight' width='$uwidth'"; 789 $meta['file'] = $file; 780 790 781 // if the associated function doesn't exist - then it's not 782 // handle. duh. i hope. 783 784 if (!function_exists('imagegif') && $type[2] == 1) { 785 $error = __('Filetype not supported. Thumbnail not created.'); 791 if ( $meta['width'] * $meta['height'] < 3 * 1024 * 1024 ) { 792 if ( $meta['width'] > 128 && $meta['width'] >= $meta['height'] * 4 / 3 ) 793 $thumb = wp_create_thumbnail( $file, 128 ); 794 elseif ( $meta['height'] > 96 ) 795 $thumb = wp_create_thumbnail( $file, 96 ); 796 if ( @file_exists($thumb) ) 797 $meta['thumb'] = basename($thumb); 798 else 799 return $thumb; 786 800 } 787 elseif (!function_exists('imagejpeg') && $type[2] == 2) { 788 $error = __('Filetype not supported. Thumbnail not created.'); 789 } 790 elseif (!function_exists('imagepng') && $type[2] == 3) { 791 $error = __('Filetype not supported. Thumbnail not created.'); 792 } else { 801 } 802 return $meta; 803 } 793 804 794 // create the initial copy from the original file 795 if ($type[2] == 1) { 796 $image = imagecreatefromgif($file); 797 } 798 elseif ($type[2] == 2) { 799 $image = imagecreatefromjpeg($file); 800 } 801 elseif ($type[2] == 3) { 802 $image = imagecreatefrompng($file); 803 } 805 function wp_create_thumbnail( $file, $max_side, $effect = '' ) { 806 if ( !file_exists($file) ) 807 return new WP_Error( 'thumbnail', __('File not found') ); 804 808 805 if (function_exists('imageantialias')) 806 imageantialias($image, TRUE); 809 $image_attr = getimagesize($file); 807 810 808 $image_attr = getimagesize($file); 811 // If the associated function doesn't exist - then it's not handled. 812 switch ( $image_attr[2] ) : // 1 = GIF, 2 = JPEG, 3 = PNG 813 case 1: 814 $image_func = 'imagegif'; 815 $image_create_func = 'imagecreatefromgif'; 816 break; 817 case 2: 818 $image_func = 'imagejpeg'; 819 $image_create_func = 'imagecreatefromjpeg'; 820 break; 821 case 3: 822 $image_func = 'imagepng'; 823 $image_create_func = 'imagecreatefrompng'; 824 break; 825 default: 826 return new WP_Error( 'thumbnail', __('Unknown filetype. Thumbnail not created.') ); 827 break; 828 endswitch; 809 829 810 // figure out the longest side 830 if ( !function_exists($image_func) ) 831 return new WP_Error( 'thumbnail', __('Filetype not supported. Thumbnail not created.') ); 811 832 812 if ($image_attr[0] > $image_attr[1]) { 813 $image_width = $image_attr[0]; 814 $image_height = $image_attr[1]; 815 $image_new_width = $max_side; 833 // create the initial copy from the original file 834 $image = $image_create_func($file); 816 835 817 $image_ratio = $image_width / $image_new_width; 818 $image_new_height = $image_height / $image_ratio; 819 //width is > height 820 } else { 821 $image_width = $image_attr[0]; 822 $image_height = $image_attr[1]; 823 $image_new_height = $max_side; 836 if ( function_exists('imageantialias') ) 837 imageantialias($image, TRUE); 824 838 825 $image_ratio = $image_height / $image_new_height; 826 $image_new_width = $image_width / $image_ratio; 827 //height > width 828 } 839 // figure out the longest side 840 if ( $image_attr[0] > $image_attr[1] ) { // width > height 841 $image_width = $image_attr[0]; 842 $image_height = $image_attr[1]; 843 $image_new_width = $max_side; 829 844 830 $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 831 @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 845 $image_ratio = $image_width / $image_new_width; 846 $image_new_height = $image_height / $image_ratio; 847 } else { // height > width 848 $image_width = $image_attr[0]; 849 $image_height = $image_attr[1]; 850 $image_new_height = $max_side; 832 851 833 // If no filters change the filename, we'll do a default transformation.834 if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )835 $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);852 $image_ratio = $image_height / $image_new_height; 853 $image_new_width = $image_width / $image_ratio; 854 } 836 855 837 $thumbpath = str_replace(basename($file), $thumb, $file); 856 $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 857 @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 838 858 839 // move the thumbnail to it's final destination 840 if ($type[2] == 1) { 841 if (!imagegif($thumbnail, $thumbpath)) { 842 $error = __("Thumbnail path invalid"); 843 } 844 } 845 elseif ($type[2] == 2) { 846 if (!imagejpeg($thumbnail, $thumbpath)) { 847 $error = __("Thumbnail path invalid"); 848 } 849 } 850 elseif ($type[2] == 3) { 851 if (!imagepng($thumbnail, $thumbpath)) { 852 $error = __("Thumbnail path invalid"); 853 } 854 } 859 // If no filters change the filename, we'll do a default transformation. 860 if ( basename($file) == $thumb = apply_filters( 'thumbnail_filename', basename($file) ) ) 861 $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1); 855 862 856 } 857 } else { 858 $error = __('File not found'); 859 } 863 $thumbpath = str_replace(basename($file), $thumb, $file); 860 864 861 if (!empty ($error)) {862 return $error;863 } else {864 return $thumbpath; 865 }865 // move the thumbnail to it's final destination 866 if ( !$image_func($thumbnail, $thumbpath) ) 867 return new WP_Error( 'thumbnail', __("Thumbnail path invalid") ); 868 869 return $thumbpath; 866 870 } 867 871 868 872 // Some postmeta stuff