Ticket #39875: 39875-major.diff
File 39875-major.diff, 4.4 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/image-edit.php
776 776 $new_path = $path; 777 777 } 778 778 } else { 779 while ( true ) { 780 $filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); 781 $filename .= "-e{$suffix}"; 782 $new_filename = "{$filename}.{$ext}"; 783 $new_path = "{$dirname}/$new_filename"; 784 if ( file_exists($new_path) ) { 785 $suffix++; 786 } else { 787 break; 788 } 789 } 779 $new_path = wp_generate_random_file_name( $path, $dirname, $ext, 'e', $suffix ); 790 780 } 791 781 792 782 // Save the full-size file, also needed to create sub-sizes. -
src/wp-admin/includes/image.php
251 251 $editor = wp_get_image_editor( $file ); 252 252 253 253 if ( ! is_wp_error( $editor ) ) { // No support for this type of file 254 $uploaded = $editor->save( $file, 'image/jpeg' ); 254 /* 255 * PDFs may have the same file filename as JPGs. 256 * Use a random string for the PDF preview image to prevent the original JPG from being overwritten. 257 */ 258 $dirname = pathinfo( $file, PATHINFO_DIRNAME ); 259 $suffix = time() . rand( 100, 999 ); 260 261 $preview_filename = wp_generate_random_file_name( $file, $dirname, 'jpg', 'pdf', $suffix ); 262 $uploaded = $editor->save( $preview_filename, 'image/jpeg' ); 263 255 264 unset( $editor ); 256 265 257 266 // Resize based on the full size image, rather than the source. -
src/wp-includes/functions.php
2098 2098 } 2099 2099 2100 2100 /** 2101 * Generates a random string for a filename. 2102 * 2103 * @param string $path File path. 2104 * @param string $dirname File directory name. 2105 * @param string $prefix Prefix for the file name. 2106 * @param string $suffix Suffix for the file name. 2107 * 2108 * @return string Generated unique file name. 2109 */ 2110 function wp_generate_random_file_name( $path, $dirname, $ext, $prefix = '', $suffix = '' ) { 2111 $file_name = ''; 2112 $suffix = time() . rand( 100, 999 ); 2113 $name_parts = array(); 2114 2115 if ( ! empty( $suffix ) ) { 2116 $name_parts[] = $suffix; 2117 } 2118 2119 if ( ! empty( $prefix ) ) { 2120 $name_parts[] = $prefix; 2121 } 2122 2123 while ( true ) { 2124 $new_filename = implode( '-', $name_parts ); 2125 $file_name = "{$new_filename}.{$ext}"; 2126 $new_path = "{$dirname}/$file_name"; 2127 2128 if ( file_exists( $new_path ) ) { 2129 $suffix++; 2130 } else { 2131 $file_name = $new_path; 2132 break; 2133 } 2134 } 2135 2136 return $file_name; 2137 } 2138 2139 /** 2101 2140 * Create a file in the upload folder with given content. 2102 2141 * 2103 2142 * If there is an error, then the key 'error' will exist with the error message. -
tests/phpunit/tests/image/functions.php
400 400 ); 401 401 402 402 $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); 403 $this->assertSame( $expected, $metadata ); 403 $this->assertArrayHasKey( 'sizes', $metadata, 'attachment should have size data' ); 404 $this->assertEquals( count( $expected['sizes'] ), count( $metadata['sizes'] ) ); 405 406 $this->assertContains( '-pdf', $metadata['sizes']['medium']['file'] ); 407 $this->assertEquals( $expected['sizes']['medium']['height'], $metadata['sizes']['medium']['height'] ); 408 409 $this->assertContains( '-pdf', $metadata['sizes']['large']['file'] ); 410 $this->assertEquals( $expected['sizes']['large']['width'], $metadata['sizes']['large']['width'] ); 404 411 405 412 unlink( $test_file ); 406 413 } … … 435 442 436 443 $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); 437 444 $this->assertTrue( isset( $metadata['sizes']['test-size'] ), 'The `test-size` was not added to the metadata.' ); 438 $this->assertSame( $metadata['sizes']['test-size'], $expected ); 445 $this->assertContains( '-pdf', $metadata['sizes']['test-size']['file'] ); 446 $this->assertEquals( $expected['height'], $metadata['sizes']['test-size']['height'] ); 439 447 440 448 remove_image_size( 'test-size' ); 441 449 remove_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10 );