diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php
index 0f03e2c..a729715 100644
|
a
|
b
|
function wp_exif_date2ts( $str ) { |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| | 340 | * Convert the EXIF geographical longitude and latitude from degrees, minutes |
| | 341 | * and seconds to degrees format. |
| | 342 | * |
| | 343 | * @since 5.0.0 |
| | 344 | * |
| | 345 | * @param string $coordinate The coordinate to convert to degrees format. |
| | 346 | * @return float Coordinate in degrees format. |
| | 347 | */ |
| | 348 | function wp_exif_gps_convert( $coordinate ) { |
| | 349 | @list( $degree, $minute, $second ) = $coordinate; |
| | 350 | $float = wp_exif_frac2dec( $degree ) + ( wp_exif_frac2dec( $minute ) / 60 ) + ( wp_exif_frac2dec( $second ) / 3600 ); |
| | 351 | |
| | 352 | return ( ( is_float( $float ) || ( is_int( $float ) && $degree == $float ) ) && ( abs( $float ) <= 180 ) ) ? $float : 999; |
| | 353 | } |
| | 354 | |
| | 355 | /** |
| 340 | 356 | * Get extended image metadata, exif or iptc as available. |
| 341 | 357 | * |
| 342 | 358 | * Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso |
| 343 | | * created_timestamp, focal_length, shutter_speed, and title. |
| | 359 | * created_timestamp, focal_length, shutter_speed, title, and location |
| | 360 | * (latitude & longitude). |
| 344 | 361 | * |
| 345 | 362 | * The IPTC metadata that is retrieved is APP13, credit, byline, created date |
| 346 | 363 | * and time, caption, copyright, and title. Also includes FNumber, Model, |
| … |
… |
function wp_read_image_metadata( $file ) { |
| 501 | 518 | if ( ! empty( $exif['Orientation'] ) ) { |
| 502 | 519 | $meta['orientation'] = $exif['Orientation']; |
| 503 | 520 | } |
| | 521 | |
| | 522 | /** |
| | 523 | * Filters whether geographical EXIF data should parsed and stored in |
| | 524 | * meta. |
| | 525 | * |
| | 526 | * @param bool true Default is to parse geographical data. |
| | 527 | */ |
| | 528 | $process_geo_data = (bool) apply_filters( 'wp_read_image_geo_data', true ); |
| | 529 | |
| | 530 | if ( $process_geo_data ) { |
| | 531 | $meta['location'] = array( |
| | 532 | 'longitude' => '', |
| | 533 | 'latitude' => '', |
| | 534 | ); |
| | 535 | |
| | 536 | if ( ! empty( $exif['GPSLongitude'] ) && count( $exif['GPSLongitude'] ) == 3 && ! empty( $exif['GPSLongitudeRef'] ) ) { |
| | 537 | $meta['location']['longitude'] = round( ( $exif['GPSLongitudeRef'] == 'W' ? - 1 : 1 ) * wp_exif_gps_convert( $exif['GPSLongitude'] ), 7 ); |
| | 538 | } |
| | 539 | if ( ! empty( $exif['GPSLatitude'] ) && count( $exif['GPSLatitude'] ) == 3 && ! empty( $exif['GPSLatitudeRef'] ) ) { |
| | 540 | $meta['location']['latitude'] = round( ( $exif['GPSLatitudeRef'] == 'S' ? - 1 : 1 ) * wp_exif_gps_convert( $exif['GPSLatitude'] ), 7 ); |
| | 541 | } |
| | 542 | } |
| 504 | 543 | } |
| 505 | 544 | |
| 506 | 545 | foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) { |
diff --git a/src/wp-includes/css/media-views.css b/src/wp-includes/css/media-views.css
index d86c2bd..f0de45c 100644
|
a
|
b
|
|
| 889 | 889 | max-height: 100%; |
| 890 | 890 | } |
| 891 | 891 | |
| | 892 | .wp-core-ui .attachment-preview.gps-location:after { |
| | 893 | content: "\f230"; |
| | 894 | font: normal 20px/1 dashicons; |
| | 895 | speak: none; |
| | 896 | vertical-align: middle; |
| | 897 | -webkit-font-smoothing: antialiased; |
| | 898 | -moz-osx-font-smoothing: grayscale; |
| | 899 | display: block; |
| | 900 | position: absolute; |
| | 901 | top: 0; |
| | 902 | right: 0; |
| | 903 | margin: 0; |
| | 904 | padding: .2em; |
| | 905 | background: rgba(200, 200, 200, .5) |
| | 906 | } |
| | 907 | |
| 892 | 908 | .wp-core-ui .attachment .thumbnail:after { |
| 893 | 909 | content: ""; |
| 894 | 910 | display: block; |
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
index 0dbba58..f05d6c2 100644
|
a
|
b
|
function wp_print_media_templates() { |
| 375 | 375 | <# } #> |
| 376 | 376 | <# } #> |
| 377 | 377 | |
| | 378 | <# if ( data.longitude && data.latitude ) { #> |
| | 379 | <div class="location"><strong><?php _e( 'GPS coordinates:' ); ?></strong> {{ data.longitude }},{{ data.latitude }}</div> |
| | 380 | <# } #> |
| | 381 | |
| 378 | 382 | <# if ( data.fileLength ) { #> |
| 379 | 383 | <div class="file-length"><strong><?php _e( 'Length:' ); ?></strong> {{ data.fileLength }}</div> |
| 380 | 384 | <# } #> |
| … |
… |
function wp_print_media_templates() { |
| 473 | 477 | </script> |
| 474 | 478 | |
| 475 | 479 | <script type="text/html" id="tmpl-attachment"> |
| 476 | | <div class="attachment-preview js--select-attachment type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}"> |
| | 480 | <div class="attachment-preview js--select-attachment type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }} {{ data.gpsClass }}"> |
| 477 | 481 | <div class="thumbnail"> |
| 478 | 482 | <# if ( data.uploading ) { #> |
| 479 | 483 | <div class="media-progress-bar"><div style="width: {{ data.percent }}%"></div></div> |
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index 8965da9..8321bdc 100644
|
a
|
b
|
function wp_prepare_attachment_for_js( $attachment ) { |
| 3207 | 3207 | $attachment_url = wp_get_attachment_url( $attachment->ID ); |
| 3208 | 3208 | $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
| 3209 | 3209 | |
| | 3210 | $gps_class = ''; |
| | 3211 | if ( isset( $meta['image_meta']['location']['longitude'] ) && isset( $meta['image_meta']['location']['latitude'] ) ) { |
| | 3212 | $gps_class = 'gps-location'; |
| | 3213 | } |
| | 3214 | |
| 3210 | 3215 | $response = array( |
| 3211 | 3216 | 'id' => $attachment->ID, |
| 3212 | 3217 | 'title' => $attachment->post_title, |
| … |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
| 3228 | 3233 | 'subtype' => $subtype, |
| 3229 | 3234 | 'icon' => wp_mime_type_icon( $attachment->ID ), |
| 3230 | 3235 | 'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ), |
| | 3236 | 'longitude' => $meta['image_meta']['location']['longitude'], |
| | 3237 | 'latitude' => $meta['image_meta']['location']['latitude'], |
| | 3238 | 'gpsClass' => $gps_class, |
| 3231 | 3239 | 'nonces' => array( |
| 3232 | 3240 | 'update' => false, |
| 3233 | 3241 | 'delete' => false, |
| … |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
| 3289 | 3297 | if ( current_user_can( 'delete_post', $attachment->ID ) ) { |
| 3290 | 3298 | $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
| 3291 | 3299 | } |
| 3292 | | |
| | 3300 | |
| 3293 | 3301 | if ( $meta && ( 'image' === $type || ! empty( $meta['sizes'] ) ) ) { |
| 3294 | 3302 | $sizes = array(); |
| 3295 | 3303 | |
diff --git a/tests/phpunit/tests/image/meta.php b/tests/phpunit/tests/image/meta.php
index 0d791b9..b688881 100644
|
a
|
b
|
class Tests_Image_Meta extends WP_UnitTestCase { |
| 31 | 31 | $this->assertEquals( 400, $out['iso'] ); |
| 32 | 32 | $this->assertEquals( 1 / 40, $out['shutter_speed'] ); |
| 33 | 33 | $this->assertEquals( '', $out['title'] ); |
| | 34 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | function test_exif_d70_mf() { |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 47 | 48 | $this->assertEquals( 0, $out['iso'] ); // interesting - a Nikon bug? |
| 48 | 49 | $this->assertEquals( 1 / 500, $out['shutter_speed'] ); |
| 49 | 50 | $this->assertEquals( '', $out['title'] ); |
| | 51 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 50 | 52 | #$this->assertEquals(array('Flowers'), $out['keywords']); |
| 51 | 53 | } |
| 52 | 54 | |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 64 | 66 | $this->assertEquals( 200, $out['iso'] ); |
| 65 | 67 | $this->assertEquals( 1 / 25, $out['shutter_speed'] ); |
| 66 | 68 | $this->assertEquals( 'IPTC Headline', $out['title'] ); |
| | 69 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 67 | 70 | } |
| 68 | 71 | |
| 69 | 72 | function test_exif_fuji() { |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 80 | 83 | $this->assertEquals( 64, $out['iso'] ); |
| 81 | 84 | $this->assertEquals( 1 / 320, $out['shutter_speed'] ); |
| 82 | 85 | $this->assertEquals( '', $out['title'] ); |
| 83 | | |
| | 86 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 84 | 87 | } |
| 85 | 88 | |
| 86 | 89 | /** |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 102 | 105 | $this->assertEquals( 0, $out['iso'] ); |
| 103 | 106 | $this->assertEquals( 0, $out['shutter_speed'] ); |
| 104 | 107 | $this->assertEquals( '', $out['title'] ); |
| | 108 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 105 | 109 | } |
| 106 | 110 | |
| 107 | 111 | function test_exif_no_data() { |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 118 | 122 | $this->assertEquals( 0, $out['iso'] ); |
| 119 | 123 | $this->assertEquals( 0, $out['shutter_speed'] ); |
| 120 | 124 | $this->assertEquals( '', $out['title'] ); |
| | 125 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | /** |
| … |
… |
class Tests_Image_Meta extends WP_UnitTestCase { |
| 160 | 165 | $this->assertEquals( 'Photoshop Document Ttitle', $out['title'] ); |
| 161 | 166 | $this->assertEquals( 1, $out['orientation'] ); |
| 162 | 167 | $this->assertEquals( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'] ); |
| | 168 | $this->assertEquals( array( 'longitude' => '', 'latitude' => '' ), $out['location'] ); |
| 163 | 169 | } |
| 164 | 170 | |
| | 171 | /** |
| | 172 | * @ticket 9257 |
| | 173 | */ |
| | 174 | function test_exif_location() { |
| | 175 | $out = wp_read_image_metadata( DIR_TESTDATA . '/images/test-gps-location.jpg' ); |
| | 176 | |
| | 177 | $this->assertEquals( '39.0058333', $out['location']['longitude'] ); |
| | 178 | $this->assertEquals( '-69.0028333', $out['location']['latitude'] ); |
| | 179 | } |
| 165 | 180 | } |