Ticket #35218: 35218.diff
File 35218.diff, 4.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/media.php
3075 3075 $metadata['audio'] = $data['audio']; 3076 3076 } 3077 3077 3078 if ( empty( $metadata['created_timestamp'] ) ) { 3079 $metadata['created_timestamp'] = wp_get_media_creation_timestamp( $data ); 3080 } 3081 3078 3082 wp_add_id3_tag_data( $metadata, $data ); 3079 3083 3080 3084 return $metadata; … … 3126 3130 } 3127 3131 3128 3132 /** 3133 * Attempt to parse a date out of ID3 data. 3134 * 3135 * The getID3 library doesn't have a standard method for getting creation dates, 3136 * so the location of this data can vary based on the MIME type. 3137 * 3138 * @since 4.9.0 3139 * 3140 * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt 3141 * 3142 * @param array $metadata The metadata returned by getID3::analyze(). 3143 * @return int|bool A UNIX timestamp for the media's creation date if available 3144 * or a boolean FALSE if a timestamp could not be determined. 3145 */ 3146 function wp_get_media_creation_timestamp( $metadata ) { 3147 $creation_date = false; 3148 3149 if ( empty( $metadata['fileformat'] ) ) { 3150 return $creation_date; 3151 } 3152 3153 switch ( $metadata['fileformat'] ) { 3154 case 'asf': 3155 if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { 3156 $creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; 3157 } 3158 break; 3159 3160 case 'matroska': 3161 if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) { 3162 $creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] ); 3163 } 3164 break; 3165 3166 case 'quicktime': 3167 case 'mp4': 3168 if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'] ) ) { 3169 $creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix']; 3170 } 3171 break; 3172 3173 } 3174 3175 return $creation_date; 3176 } 3177 3178 /** 3129 3179 * Encapsulate logic for Attach/Detach actions 3130 3180 * 3131 3181 * @since 4.2.0 -
tests/phpunit/tests/media.php
2062 2062 $attachment_id = wp_insert_attachment( $data, '', 0 ); 2063 2063 $this->assertSame( 0, $attachment_id ); 2064 2064 } 2065 2066 /** 2067 * @ticket 35218 2068 */ 2069 function test_wp_get_media_creation_timestamp_video_asf() { 2070 $metadata = array( 2071 'fileformat' => 'asf', 2072 'asf' => array( 2073 'file_properties_object' => array( 2074 'creation_date_unix' => 123, 2075 ), 2076 ), 2077 ); 2078 2079 $this->assertEquals( 123, wp_get_media_creation_timestamp( $metadata ) ); 2080 } 2081 2082 /** 2083 * @ticket 35218 2084 */ 2085 function test_wp_get_media_creation_timestamp_video_matroska() { 2086 $metadata = array( 2087 'fileformat' => 'matroska', 2088 'matroska' => array( 2089 'comments' => array( 2090 'creation_time' => array( 2091 '2015-12-24T17:40:09Z' 2092 ), 2093 ), 2094 ), 2095 ); 2096 2097 $this->assertEquals( 1450978809, wp_get_media_creation_timestamp( $metadata ) ); 2098 } 2099 2100 /** 2101 * @ticket 35218 2102 */ 2103 function test_wp_get_media_creation_timestamp_video_quicktime() { 2104 $video = DIR_TESTDATA . '/videos/mp4.m4v'; 2105 $metadata = wp_read_video_metadata( $video ); 2106 2107 $metadata = array( 2108 'fileformat' => 'quicktime', 2109 'quicktime' => array( 2110 'moov' => array( 2111 'subatoms' => array( 2112 array( 2113 'creation_time_unix' => 1450978805, 2114 ), 2115 ), 2116 ), 2117 ), 2118 ); 2119 2120 $this->assertEquals( 1450978805, wp_get_media_creation_timestamp( $metadata ) ); 2121 } 2122 2123 /** 2124 * @ticket 35218 2125 */ 2126 function test_wp_read_video_metadata_adds_creation_date_with_quicktime() { 2127 $video = DIR_TESTDATA . '/videos/quicktime.mov'; 2128 $metadata = wp_read_video_metadata( $video ); 2129 2130 $this->assertEquals( 1450978957, $metadata['created_timestamp'] ); 2131 } 2132 2133 /** 2134 * @ticket 35218 2135 */ 2136 function test_wp_read_video_metadata_adds_creation_date_with_mp4() { 2137 $video = DIR_TESTDATA . '/videos/mp4.m4v'; 2138 $metadata = wp_read_video_metadata( $video ); 2139 2140 $this->assertEquals( 1450978805, $metadata['created_timestamp'] ); 2141 } 2142 2143 /** 2144 * @ticket 35218 2145 */ 2146 function test_wp_read_video_metadata_adds_creation_date_with_mkv() { 2147 $video = DIR_TESTDATA . '/videos/mkv.mkv'; 2148 $metadata = wp_read_video_metadata( $video ); 2149 2150 $this->assertNotEquals( false, $metadata['created_timestamp'] ); 2151 } 2065 2152 } 2066 2153 2067 2154 /**