WordPress.org

Make WordPress Core

Ticket #9417: 9417.2.patch

File 9417.2.patch, 2.1 KB (added by hakre, 9 years ago)

existing UTF8 encoding of IPTC blocks preserved

  • wp-admin/includes/image.php

     
    258258                if ( !empty($info['APP13']) ) {
    259259                        $iptc = iptcparse($info['APP13']);
    260260                        if ( !empty($iptc['2#110'][0]) ) // credit
    261                                 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0]));
     261                                $meta['credit'] = wp_iptc_utf8_encode(trim($iptc['2#110'][0]));
    262262                        elseif ( !empty($iptc['2#080'][0]) ) // byline
    263                                 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0]));
     263                                $meta['credit'] = wp_iptc_utf8_encode(trim($iptc['2#080'][0]));
    264264                        if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date and time
    265265                                $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
    266266                        if ( !empty($iptc['2#120'][0]) ) // caption
    267                                 $meta['caption'] = utf8_encode(trim($iptc['2#120'][0]));
     267                                $meta['caption'] = wp_iptc_utf8_encode(trim($iptc['2#120'][0]));
    268268                        if ( !empty($iptc['2#116'][0]) ) // copyright
    269                                 $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0]));
     269                                $meta['copyright'] = wp_iptc_utf8_encode(trim($iptc['2#116'][0]));
    270270                        if ( !empty($iptc['2#005'][0]) ) // title
    271                                 $meta['title'] = utf8_encode(trim($iptc['2#005'][0]));
     271                                $meta['title'] = wp_iptc_utf8_encode(trim($iptc['2#005'][0]));
    272272                 }
    273273        }
    274274
     
    294294}
    295295
    296296/**
     297 * UTF8 encode IPTC data
     298 *
     299 * this is a simple implementation ignoring IPTC documentation:
     300 *   a) if the data is valid utf8 then there is nothing to do
     301 *   b) if not, assume ISO-8859-1 and encode it to utf-8
     302 *
     303 *
     304 * @link http://de2.php.net/manual/en/function.iptcparse.php
     305 * @link http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
     306 *
     307 * @since 2.8.0
     308 *
     309 * @param string $itpc raw IRB value returned by iptcparse()
     310 * @return string utf8 encoded value
     311 */
     312function wp_iptc_utf8_encode($itpc) {
     313       
     314        if ( false == seems_utf8($itpc) )
     315                $itpc = utf8_encode($itpc);
     316       
     317        return $itpc;
     318}
     319
     320/**
    297321 * Validate that file is an image.
    298322 *
    299323 * @since 2.5.0