Ticket #22768: 22768.5.diff
File 22768.5.diff, 4.7 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/image.php
299 299 300 300 if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 301 301 $caption = trim( $iptc['2#120'][0] ); 302 if ( empty( $meta['title'] ) ) {303 mbstring_binary_safe_encoding();304 $caption_length = strlen( $caption );305 reset_mbstring_encoding();306 302 303 mbstring_binary_safe_encoding(); 304 $caption_length = strlen( $caption ); 305 reset_mbstring_encoding(); 306 307 if ( empty( $meta['title'] ) && $caption_length < 80 ) { 307 308 // Assume the title is stored in 2:120 if it's short. 308 if ( $caption_length < 80 ) { 309 $meta['title'] = $caption; 310 } else { 311 $meta['caption'] = $caption; 312 } 313 } elseif ( $caption != $meta['title'] ) { 314 $meta['caption'] = $caption; 309 $meta['title'] = $caption; 315 310 } 311 312 $meta['caption'] = $caption; 316 313 } 317 314 318 315 if ( ! empty( $iptc['2#110'][0] ) ) // credit … … 346 343 if ( empty( $meta['title'] ) && $description_length < 80 ) { 347 344 // Assume the title is stored in ImageDescription 348 345 $meta['title'] = trim( $exif['ImageDescription'] ); 349 if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) { 350 $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); 351 } 352 } elseif ( empty( $meta['caption'] ) && trim( $exif['ImageDescription'] ) != $meta['title'] ) { 346 } 347 348 if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) { 349 $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); 350 } 351 352 if ( empty( $meta['caption'] ) ) { 353 353 $meta['caption'] = trim( $exif['ImageDescription'] ); 354 354 } 355 } elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title']) {355 } elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) { 356 356 $meta['caption'] = trim( $exif['Comments'] ); 357 357 } 358 358 -
src/wp-admin/includes/media.php
280 280 $file = $file['file']; 281 281 $title = $name; 282 282 $content = ''; 283 $excerpt = ''; 283 284 284 285 if ( preg_match( '#^audio#', $type ) ) { 285 286 $meta = wp_read_audio_metadata( $file ); 286 287 287 if ( ! empty( $meta['title'] ) ) 288 if ( ! empty( $meta['title'] ) ) { 288 289 $title = $meta['title']; 290 } 289 291 290 $content = '';291 292 292 if ( ! empty( $title ) ) { 293 293 294 294 if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { … … 335 335 336 336 // Use image exif/iptc data for title and caption defaults if possible. 337 337 } elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = @wp_read_image_metadata( $file ) ) { 338 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) 338 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { 339 339 $title = $image_meta['title']; 340 if ( trim( $image_meta['caption'] ) ) 341 $content = $image_meta['caption']; 340 } 341 342 if ( trim( $image_meta['caption'] ) ) { 343 $excerpt = $image_meta['caption']; 344 } 342 345 } 343 346 344 347 // Construct the attachment array … … 348 351 'post_parent' => $post_id, 349 352 'post_title' => $title, 350 353 'post_content' => $content, 354 'post_excerpt' => $excerpt, 351 355 ), $post_data ); 352 356 353 357 // This should never be set as it would then overwrite an existing attachment. -
tests/phpunit/tests/media.php
540 540 ); 541 541 $this->assertEquals( $expected, $filetype ); 542 542 } 543 544 /** 545 * @ticket 22768 546 */ 547 public function test_media_handle_upload_sets_post_excerpt() { 548 $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; 549 550 // Make a copy of this file as it gets moved during the file upload 551 $tmp_name = wp_tempnam( $iptc_file ); 552 553 copy( $iptc_file, $tmp_name ); 554 555 $_FILES['upload'] = array( 556 'tmp_name' => $tmp_name, 557 'name' => 'test-image-iptc.jpg', 558 'type' => 'image/jpeg', 559 'error' => 0, 560 'size' => filesize( $iptc_file ) 561 ); 562 563 $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_iptc_upload', 'test_form' => false ) ); 564 565 unset( $_FILES['upload'] ); 566 567 $post = get_post( $post_id ); 568 569 $this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $post->post_excerpt ); 570 } 571 543 572 }