WordPress.org

Make WordPress Core

Changeset 21905


Ignore:
Timestamp:
09/18/12 23:38:25 (19 months ago)
Author:
nacin
Message:

Avoid mangling UTF-8 strings that may be present in image metadata. props SergeyBiryukov for the unit tests [UT665]. fixes #9417.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/image.php

    r21808 r21905  
    238238            // headline, "A brief synopsis of the caption." 
    239239            if ( ! empty( $iptc['2#105'][0] ) ) 
    240                 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) ); 
     240                $meta['title'] = trim( $iptc['2#105'][0] ); 
    241241            // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 
    242242            elseif ( ! empty( $iptc['2#005'][0] ) ) 
    243                 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) ); 
     243                $meta['title'] = trim( $iptc['2#005'][0] ); 
    244244 
    245245            if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 
    246                 $caption = utf8_encode( trim( $iptc['2#120'][0] ) ); 
     246                $caption = trim( $iptc['2#120'][0] ); 
    247247                if ( empty( $meta['title'] ) ) { 
    248248                    // Assume the title is stored in 2:120 if it's short. 
     
    257257 
    258258            if ( ! empty( $iptc['2#110'][0] ) ) // credit 
    259                 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); 
     259                $meta['credit'] = trim( $iptc['2#110'][0] ); 
    260260            elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline 
    261                 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); 
     261                $meta['credit'] = trim( $iptc['2#080'][0] ); 
    262262 
    263263            if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time 
     
    265265 
    266266            if ( ! empty( $iptc['2#116'][0] ) ) // copyright 
    267                 $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) ); 
     267                $meta['copyright'] = trim( $iptc['2#116'][0] ); 
    268268         } 
    269269    } 
     
    274274 
    275275        if ( !empty( $exif['Title'] ) ) 
    276             $meta['title'] = utf8_encode( trim( $exif['Title'] ) ); 
     276            $meta['title'] = trim( $exif['Title'] ); 
    277277 
    278278        if ( ! empty( $exif['ImageDescription'] ) ) { 
    279279            if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) { 
    280280                // Assume the title is stored in ImageDescription 
    281                 $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) ); 
     281                $meta['title'] = trim( $exif['ImageDescription'] ); 
    282282                if ( ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) 
    283                     $meta['caption'] = utf8_encode( trim( $exif['COMPUTED']['UserComment'] ) ); 
     283                    $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); 
    284284            } elseif ( trim( $exif['ImageDescription'] ) != $meta['title'] ) { 
    285                 $meta['caption'] = utf8_encode( trim( $exif['ImageDescription'] ) ); 
     285                $meta['caption'] = trim( $exif['ImageDescription'] ); 
    286286            } 
    287287        } elseif ( ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title'] ) { 
    288             $meta['caption'] = utf8_encode( trim( $exif['Comments'] ) ); 
     288            $meta['caption'] = trim( $exif['Comments'] ); 
    289289        } 
    290290 
    291291        if ( ! empty( $exif['Artist'] ) ) 
    292             $meta['credit'] = utf8_encode( trim( $exif['Artist'] ) ); 
     292            $meta['credit'] = trim( $exif['Artist'] ); 
    293293        elseif ( ! empty($exif['Author'] ) ) 
    294             $meta['credit'] = utf8_encode( trim( $exif['Author'] ) ); 
     294            $meta['credit'] = trim( $exif['Author'] ); 
    295295 
    296296        if ( ! empty( $exif['Copyright'] ) ) 
    297             $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) ); 
     297            $meta['copyright'] = trim( $exif['Copyright'] ); 
    298298        if ( ! empty($exif['FNumber'] ) ) 
    299299            $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); 
    300300        if ( ! empty($exif['Model'] ) ) 
    301             $meta['camera'] = utf8_encode( trim( $exif['Model'] ) ); 
     301            $meta['camera'] = trim( $exif['Model'] ); 
    302302        if ( ! empty($exif['DateTimeDigitized'] ) ) 
    303303            $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] ); 
     
    306306        if ( ! empty($exif['ISOSpeedRatings'] ) ) { 
    307307            $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings']; 
    308             $meta['iso'] = utf8_encode( trim( $meta['iso'] ) ); 
     308            $meta['iso'] = trim( $meta['iso'] ); 
    309309        } 
    310310        if ( ! empty($exif['ExposureTime'] ) ) 
    311311            $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); 
     312    } 
     313 
     314    foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) { 
     315        if ( $meta[ $key ] && ! seems_utf8( $meta[ $key ] ) ) 
     316            $meta[ $key ] = utf8_encode( $meta[ $key ] ); 
    312317    } 
    313318 
Note: See TracChangeset for help on using the changeset viewer.