Ticket #31050: 31050.3.patch
File 31050.3.patch, 7.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/image.php
78 78 79 79 $metadata = array(); 80 80 $support = false; 81 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { 81 $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf', 'video/avi' ) ); 82 $mime_type = get_post_mime_type( $attachment ); 83 84 if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image($file) ) { 82 85 $imagesize = getimagesize( $file ); 83 86 $metadata['width'] = $imagesize[0]; 84 87 $metadata['height'] = $imagesize[1]; … … 133 136 134 137 } elseif ( wp_attachment_is( 'video', $attachment ) ) { 135 138 $metadata = wp_read_video_metadata( $file ); 136 $support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );137 139 } elseif ( wp_attachment_is( 'audio', $attachment ) ) { 138 140 $metadata = wp_read_audio_metadata( $file ); 139 $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );140 141 } 141 142 142 if ( $support &&! empty( $metadata['image']['data'] ) ) {143 if ( ! empty( $metadata['image']['data'] ) ) { 143 144 // Check for existing cover. 144 145 $hash = md5( $metadata['image']['data'] ); 145 146 $posts = get_posts( array( … … 191 192 update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id ); 192 193 } 193 194 } 194 }195 195 196 // Remove the blob of binary data from the array. 197 if ( $metadata ) { 196 // Remove the blob of binary data from the array. 198 197 unset( $metadata['image']['data'] ); 199 198 } 199 else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) ) { 200 $editor = wp_get_image_editor( $file ); 201 $sizes = array( 202 'thumbnail' => array( 203 'width' => get_option( "thumbnail_size_w" ), 204 'height' => get_option( "thumbnail_size_h" ), 205 'crop' => get_option( "thumbnail_crop" ) 206 ) 207 ); 200 208 209 if ( ! is_wp_error( $editor ) ) { // No support for this type of file 210 $uploaded = $editor->save( $file . '.jpg' ); 211 212 if ( ! is_wp_error( $uploaded ) ) { 213 unset( $uploaded['path'] ); 214 215 $metadata = array_merge( $metadata, $uploaded ); 216 217 $metadata['sizes'] = $editor->multi_resize( $sizes ); 218 $metadata['sizes']['full'] = $uploaded; 219 } 220 } 221 } 222 201 223 /** 202 224 * Filter the generated attachment meta data. 203 225 * -
src/wp-admin/includes/media.php
2753 2753 2754 2754 echo wp_video_shortcode( $attr ); 2755 2755 2756 else : 2757 $image = wp_get_attachment_image( $attachment_id, 'full', false, array( 'style' => 'max-width:100%' ) ); 2758 2759 if ( $image ) { 2760 echo '<div class="wp_attachment_image wp-clearfix" id="media-head-' . $attachment_id . '">'; 2761 echo '<p id="thumbnail-head-<?php echo $attachment_id; ?>">' . $image . '</p>'; 2762 echo '</div>'; 2763 } 2764 2756 2765 endif; ?> 2757 2766 </div> 2758 2767 <div class="wp_attachment_details edit-form-section"> -
src/wp-includes/media-template.php
290 290 <div class="thumbnail thumbnail-{{ data.type }}"> 291 291 <# if ( data.uploading ) { #> 292 292 <div class="media-progress-bar"><div></div></div> 293 <# } else if ( 'image' === data.type &&data.sizes && data.sizes.large ) { #>293 <# } else if ( data.sizes && data.sizes.large ) { #> 294 294 <img class="details-image" src="{{ data.sizes.large.url }}" draggable="false" alt="" /> 295 <# } else if ( 'image' === data.type &&data.sizes && data.sizes.full ) { #>295 <# } else if ( data.sizes && data.sizes.full ) { #> 296 296 <img class="details-image" src="{{ data.sizes.full.url }}" draggable="false" alt="" /> 297 297 <# } else if ( -1 === jQuery.inArray( data.type, [ 'audio', 'video' ] ) ) { #> 298 298 <img class="details-image icon" src="{{ data.icon }}" draggable="false" alt="" /> … … 450 450 <div class="centered"> 451 451 <img src="{{ data.size.url }}" draggable="false" alt="" /> 452 452 </div> 453 <# } else if ( data.sizes ) { #> 454 <div class="centered"> 455 <img src="{{ data.sizes.full.url }}" draggable="false" alt="" /> 456 </div> 453 457 <# } else { #> 454 458 <div class="centered"> 455 459 <# if ( data.image && data.image.src && data.image.src !== data.icon ) { #> -
src/wp-includes/media.php
163 163 * the image is an intermediate size. False on failure. 164 164 */ 165 165 function image_downsize( $id, $size = 'medium' ) { 166 $is_image = wp_attachment_is_image( $id ); 166 167 167 if ( !wp_attachment_is_image($id) ) 168 if ( $is_image ) { 169 /** 170 * Filter whether to preempt the output of image_downsize(). 171 * 172 * Passing a truthy value to the filter will effectively short-circuit 173 * down-sizing the image, returning that value as output instead. 174 * 175 * @since 2.5.0 176 * 177 * @param bool $downsize Whether to short-circuit the image downsize. Default false. 178 * @param int $id Attachment ID for image. 179 * @param array|string $size Size of image. Image size or array of width and height values (in that order). 180 * Default 'medium'. 181 */ 182 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { 183 return $out; 184 } 185 } 186 187 $meta = wp_get_attachment_metadata($id); 188 189 if ( ! $meta || empty( $meta['sizes'] ) ) { 168 190 return false; 169 170 /**171 * Filter whether to preempt the output of image_downsize().172 *173 * Passing a truthy value to the filter will effectively short-circuit174 * down-sizing the image, returning that value as output instead.175 *176 * @since 2.5.0177 *178 * @param bool $downsize Whether to short-circuit the image downsize. Default false.179 * @param int $id Attachment ID for image.180 * @param array|string $size Size of image. Image size or array of width and height values (in that order).181 * Default 'medium'.182 */183 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) {184 return $out;185 191 } 186 192 187 193 $img_url = wp_get_attachment_url($id); 188 $meta = wp_get_attachment_metadata($id);189 194 $width = $height = 0; 190 195 $is_intermediate = false; 191 196 $img_url_basename = wp_basename($img_url); … … 206 211 $is_intermediate = true; 207 212 } 208 213 } 214 209 215 if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { 210 216 // any other type: use the real image 211 217 $width = $meta['width']; … … 1006 1012 */ 1007 1013 $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 1008 1014 1009 if ( empty( $image_meta[' sizes'] ) ) {1015 if ( empty( $image_meta['file'] ) || empty( $image_meta['sizes'] ) ) { 1010 1016 return false; 1011 1017 } 1012 1018 … … 3147 3153 } 3148 3154 3149 3155 $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); 3150 } elseif ( $meta && 'video' === $type ) { 3156 } 3157 elseif ( isset( $meta['sizes'] ) ) { 3158 $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); 3159 3160 foreach ( $meta['sizes'] as $size => $data ) { 3161 $response['sizes'][ $size ] = array( 3162 'height' => $data['height'], 3163 'width' => $data['width'], 3164 'url' => $base_url . $data['file'], 3165 'orientation' => $data['height'] > $data['width'] ? 'portrait' : 'landscape', 3166 ); 3167 } 3168 } 3169 3170 if ( $meta && 'video' === $type ) { 3151 3171 if ( isset( $meta['width'] ) ) 3152 3172 $response['width'] = (int) $meta['width']; 3153 3173 if ( isset( $meta['height'] ) )