Media: Fix handling of multibyte exif description metadata.
The exif standards expect the UserComment field to be used as a substitute for ImageDescription if multibyte characters are needed. WordPress media only mapped the ImageDescription field and did not correctly handle descriptions with multibyte characters. Fix metadata saving to better handle media with multibyte characters in metadata and update unit tests. Props fotodrachen, antpb, joedolson, mikinc860, azaozz, nicolefurlan. Fixes #58082. Built from https://develop.svn.wordpress.org/trunk@57267 git-svn-id: http://core.svn.wordpress.org/trunk@56773 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1d2e7fd49d
commit
bcb0f74678
|
@ -863,22 +863,51 @@ function wp_read_image_metadata( $file ) {
|
||||||
$exif = array();
|
$exif = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$exif_description = '';
|
||||||
|
$exif_usercomment = '';
|
||||||
if ( ! empty( $exif['ImageDescription'] ) ) {
|
if ( ! empty( $exif['ImageDescription'] ) ) {
|
||||||
mbstring_binary_safe_encoding();
|
$exif_description = trim( $exif['ImageDescription'] );
|
||||||
$description_length = strlen( $exif['ImageDescription'] );
|
}
|
||||||
reset_mbstring_encoding();
|
|
||||||
|
|
||||||
|
if ( ! empty( $exif['COMPUTED']['UserComment'] ) ) {
|
||||||
|
$exif_usercomment = trim( $exif['COMPUTED']['UserComment'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $exif_description ) {
|
||||||
|
mbstring_binary_safe_encoding();
|
||||||
|
$description_length = strlen( $exif_description );
|
||||||
|
reset_mbstring_encoding();
|
||||||
if ( empty( $meta['title'] ) && $description_length < 80 ) {
|
if ( empty( $meta['title'] ) && $description_length < 80 ) {
|
||||||
// Assume the title is stored in ImageDescription.
|
// Assume the title is stored in ImageDescription.
|
||||||
$meta['title'] = trim( $exif['ImageDescription'] );
|
$meta['title'] = $exif_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) {
|
// If both user comments and description are present.
|
||||||
$meta['caption'] = trim( $exif['COMPUTED']['UserComment'] );
|
if ( empty( $meta['caption'] ) && $exif_description && $exif_usercomment ) {
|
||||||
|
if ( ! empty( $meta['title'] ) && $exif_description === $meta['title'] ) {
|
||||||
|
$caption = $exif_usercomment;
|
||||||
|
} else {
|
||||||
|
if ( $exif_description === $exif_usercomment ) {
|
||||||
|
$caption = $exif_description;
|
||||||
|
} else {
|
||||||
|
$caption = trim( $exif_description . ' ' . $exif_usercomment );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$meta['caption'] = $caption;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $meta['caption'] ) && $exif_usercomment ) {
|
||||||
|
$meta['caption'] = $exif_usercomment;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $meta['caption'] ) ) {
|
if ( empty( $meta['caption'] ) ) {
|
||||||
$meta['caption'] = trim( $exif['ImageDescription'] );
|
$meta['caption'] = $exif_description;
|
||||||
|
}
|
||||||
|
} elseif ( empty( $meta['caption'] ) && $exif_usercomment ) {
|
||||||
|
$meta['caption'] = $exif_usercomment;
|
||||||
|
$description_length = strlen( $exif_usercomment );
|
||||||
|
if ( empty( $meta['title'] ) && $description_length < 80 ) {
|
||||||
|
$meta['title'] = trim( $exif_usercomment );
|
||||||
}
|
}
|
||||||
} elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) {
|
} elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) {
|
||||||
$meta['caption'] = trim( $exif['Comments'] );
|
$meta['caption'] = trim( $exif['Comments'] );
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.5-alpha-57266';
|
$wp_version = '6.5-alpha-57267';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue