WordPress.org

Make WordPress Core

Ticket #9417: 9417.3.patch

File 9417.3.patch, 5.2 KB (added by SergeyBiryukov, 2 years ago)
  • wp-admin/includes/image.php

     
    230230 
    231231                        // headline, "A brief synopsis of the caption." 
    232232                        if ( ! empty( $iptc['2#105'][0] ) ) 
    233                                 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) ); 
     233                                $meta['title'] = wp_iptc_utf8_encode( trim( $iptc['2#105'][0] ) ); 
    234234                        // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 
    235235                        elseif ( ! empty( $iptc['2#005'][0] ) ) 
    236                                 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) ); 
     236                                $meta['title'] = wp_iptc_utf8_encode( trim( $iptc['2#005'][0] ) ); 
    237237 
    238238                        if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 
    239                                 $caption = utf8_encode( trim( $iptc['2#120'][0] ) ); 
     239                                $caption = wp_iptc_utf8_encode( trim( $iptc['2#120'][0] ) ); 
    240240                                if ( empty( $meta['title'] ) ) { 
    241241                                        // Assume the title is stored in 2:120 if it's short. 
    242242                                        if ( strlen( $caption ) < 80 ) 
     
    249249                        } 
    250250 
    251251                        if ( ! empty( $iptc['2#110'][0] ) ) // credit 
    252                                 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); 
     252                                $meta['credit'] = wp_iptc_utf8_encode(trim($iptc['2#110'][0])); 
    253253                        elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline 
    254                                 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); 
     254                                $meta['credit'] = wp_iptc_utf8_encode(trim($iptc['2#080'][0])); 
    255255 
    256256                        if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time 
    257257                                $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] ); 
    258258 
    259259                        if ( ! empty( $iptc['2#116'][0] ) ) // copyright 
    260                                 $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) ); 
     260                                $meta['copyright'] = wp_iptc_utf8_encode( trim( $iptc['2#116'][0] ) ); 
    261261                 } 
    262262        } 
    263263 
     
    266266                $exif = @exif_read_data( $file ); 
    267267 
    268268                if ( !empty( $exif['Title'] ) ) 
    269                         $meta['title'] = utf8_encode( trim( $exif['Title'] ) ); 
     269                        $meta['title'] = wp_iptc_utf8_encode( trim( $exif['Title'] ) ); 
    270270 
    271271                if ( ! empty( $exif['ImageDescription'] ) ) { 
    272272                        if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) { 
    273273                                // Assume the title is stored in ImageDescription 
    274                                 $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) ); 
     274                                $meta['title'] = wp_iptc_utf8_encode( trim( $exif['ImageDescription'] ) ); 
    275275                                if ( ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) 
    276                                         $meta['caption'] = utf8_encode( trim( $exif['COMPUTED']['UserComment'] ) ); 
     276                                        $meta['caption'] = wp_iptc_utf8_encode( trim( $exif['COMPUTED']['UserComment'] ) ); 
    277277                        } elseif ( trim( $exif['ImageDescription'] ) != $meta['title'] ) { 
    278                                 $meta['caption'] = utf8_encode( trim( $exif['ImageDescription'] ) ); 
     278                                $meta['caption'] = wp_iptc_utf8_encode( trim( $exif['ImageDescription'] ) ); 
    279279                        } 
    280280                } elseif ( ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title'] ) { 
    281                         $meta['caption'] = utf8_encode( trim( $exif['Comments'] ) ); 
     281                        $meta['caption'] = wp_iptc_utf8_encode( trim( $exif['Comments'] ) ); 
    282282                } 
    283283 
    284284                if ( ! empty( $exif['Artist'] ) ) 
    285                         $meta['credit'] = utf8_encode( trim( $exif['Artist'] ) ); 
     285                        $meta['credit'] = wp_iptc_utf8_encode( trim( $exif['Artist'] ) ); 
    286286                elseif ( ! empty($exif['Author'] ) ) 
    287                         $meta['credit'] = utf8_encode( trim( $exif['Author'] ) ); 
     287                        $meta['credit'] = wp_iptc_utf8_encode( trim( $exif['Author'] ) ); 
    288288 
    289289                if ( ! empty( $exif['Copyright'] ) ) 
    290                         $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) ); 
     290                        $meta['copyright'] = wp_iptc_utf8_encode( trim( $exif['Copyright'] ) ); 
    291291                if ( ! empty($exif['FNumber'] ) ) 
    292292                        $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); 
    293293                if ( ! empty($exif['Model'] ) ) 
    294                         $meta['camera'] = utf8_encode( trim( $exif['Model'] ) ); 
     294                        $meta['camera'] = wp_iptc_utf8_encode( trim( $exif['Model'] ) ); 
    295295                if ( ! empty($exif['DateTimeDigitized'] ) ) 
    296296                        $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] ); 
    297297                if ( ! empty($exif['FocalLength'] ) ) 
    298298                        $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] ); 
    299299                if ( ! empty($exif['ISOSpeedRatings'] ) ) 
    300                         $meta['iso'] = utf8_encode( trim( $exif['ISOSpeedRatings'] ) ); 
     300                        $meta['iso'] = wp_iptc_utf8_encode( trim( $exif['ISOSpeedRatings'] ) ); 
    301301                if ( ! empty($exif['ExposureTime'] ) ) 
    302302                        $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); 
    303303        } 
     
    307307} 
    308308 
    309309/** 
     310 * UTF8 encode IPTC data 
     311 *  
     312 * this is a simple implementation ignoring IPTC documentation: 
     313 *   a) if the data is valid utf8 then there is nothing to do 
     314 *   b) if not, assume ISO-8859-1 and encode it to utf-8 
     315 *  
     316 *  
     317 * @link http://de2.php.net/manual/en/function.iptcparse.php 
     318 * @link http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf 
     319 *  
     320 * @since 3.2 
     321 * 
     322 * @param string $itpc raw IRB value returned by iptcparse() 
     323 * @return string utf8 encoded value 
     324 */ 
     325function wp_iptc_utf8_encode($itpc) { 
     326         
     327        if ( false == seems_utf8($itpc) ) 
     328                $itpc = utf8_encode($itpc); 
     329         
     330        return $itpc; 
     331} 
     332 
     333/** 
    310334 * Validate that file is an image. 
    311335 * 
    312336 * @since 2.5.0