Ticket #9417: 9417.4.patch
| File 9417.4.patch, 5.1 KB (added by SergeyBiryukov, 11 months ago) |
|---|
-
wp-admin/includes/image.php
253 253 254 254 // headline, "A brief synopsis of the caption." 255 255 if ( ! empty( $iptc['2#105'][0] ) ) 256 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) );256 $meta['title'] = _maybe_utf8_encode( trim( $iptc['2#105'][0] ) ); 257 257 // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 258 258 elseif ( ! empty( $iptc['2#005'][0] ) ) 259 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) );259 $meta['title'] = _maybe_utf8_encode( trim( $iptc['2#005'][0] ) ); 260 260 261 261 if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 262 $caption = utf8_encode( trim( $iptc['2#120'][0] ) );262 $caption = _maybe_utf8_encode( trim( $iptc['2#120'][0] ) ); 263 263 if ( empty( $meta['title'] ) ) { 264 264 // Assume the title is stored in 2:120 if it's short. 265 265 if ( strlen( $caption ) < 80 ) … … 272 272 } 273 273 274 274 if ( ! empty( $iptc['2#110'][0] ) ) // credit 275 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0]));275 $meta['credit'] = _maybe_utf8_encode( trim( $iptc['2#110'][0] ) ); 276 276 elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline 277 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0]));277 $meta['credit'] = _maybe_utf8_encode( trim( $iptc['2#080'][0] ) ); 278 278 279 279 if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time 280 280 $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] ); 281 281 282 282 if ( ! empty( $iptc['2#116'][0] ) ) // copyright 283 $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) );283 $meta['copyright'] = _maybe_utf8_encode( trim( $iptc['2#116'][0] ) ); 284 284 } 285 285 } 286 286 … … 289 289 $exif = @exif_read_data( $file ); 290 290 291 291 if ( !empty( $exif['Title'] ) ) 292 $meta['title'] = utf8_encode( trim( $exif['Title'] ) );292 $meta['title'] = _maybe_utf8_encode( trim( $exif['Title'] ) ); 293 293 294 294 if ( ! empty( $exif['ImageDescription'] ) ) { 295 295 if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) { 296 296 // Assume the title is stored in ImageDescription 297 $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) );297 $meta['title'] = _maybe_utf8_encode( trim( $exif['ImageDescription'] ) ); 298 298 if ( ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) 299 $meta['caption'] = utf8_encode( trim( $exif['COMPUTED']['UserComment'] ) );299 $meta['caption'] = _maybe_utf8_encode( trim( $exif['COMPUTED']['UserComment'] ) ); 300 300 } elseif ( trim( $exif['ImageDescription'] ) != $meta['title'] ) { 301 $meta['caption'] = utf8_encode( trim( $exif['ImageDescription'] ) );301 $meta['caption'] = _maybe_utf8_encode( trim( $exif['ImageDescription'] ) ); 302 302 } 303 303 } elseif ( ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title'] ) { 304 $meta['caption'] = utf8_encode( trim( $exif['Comments'] ) );304 $meta['caption'] = _maybe_utf8_encode( trim( $exif['Comments'] ) ); 305 305 } 306 306 307 307 if ( ! empty( $exif['Artist'] ) ) 308 $meta['credit'] = utf8_encode( trim( $exif['Artist'] ) );308 $meta['credit'] = _maybe_utf8_encode( trim( $exif['Artist'] ) ); 309 309 elseif ( ! empty($exif['Author'] ) ) 310 $meta['credit'] = utf8_encode( trim( $exif['Author'] ) );310 $meta['credit'] = _maybe_utf8_encode( trim( $exif['Author'] ) ); 311 311 312 312 if ( ! empty( $exif['Copyright'] ) ) 313 $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) );313 $meta['copyright'] = _maybe_utf8_encode( trim( $exif['Copyright'] ) ); 314 314 if ( ! empty($exif['FNumber'] ) ) 315 315 $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); 316 316 if ( ! empty($exif['Model'] ) ) 317 $meta['camera'] = utf8_encode( trim( $exif['Model'] ) );317 $meta['camera'] = _maybe_utf8_encode( trim( $exif['Model'] ) ); 318 318 if ( ! empty($exif['DateTimeDigitized'] ) ) 319 319 $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] ); 320 320 if ( ! empty($exif['FocalLength'] ) ) 321 321 $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] ); 322 322 if ( ! empty($exif['ISOSpeedRatings'] ) ) { 323 323 $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings']; 324 $meta['iso'] = utf8_encode( trim( $meta['iso'] ) );324 $meta['iso'] = _maybe_utf8_encode( trim( $meta['iso'] ) ); 325 325 } 326 326 if ( ! empty($exif['ExposureTime'] ) ) 327 327 $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); … … 332 332 } 333 333 334 334 /** 335 * Encode IPTC data to UTF-8. 336 * 337 * a) If the data is valid UTF-8 then there is nothing to do. 338 * b) If not, assume ISO-8859-1 and encode it to UTF-8. 339 * 340 * @since 3.5 341 * 342 * @param string $itpc raw IRB value returned by iptcparse() 343 * @return string utf8 encoded value 344 */ 345 function _maybe_utf8_encode( $itpc ) { 346 347 if ( ! seems_utf8( $itpc ) ) 348 $itpc = utf8_encode( $itpc ); 349 350 return $itpc; 351 } 352 353 /** 335 354 * Validate that file is an image. 336 355 * 337 356 * @since 2.5.0
