Ticket #21903: image_caption_encoding.patch

File image_caption_encoding.patch, 2.0 KB (added by chenxing, 8 months ago)

tentative patch

  • wp-admin/includes/

    old new  
    253253 
    254254                        // headline, "A brief synopsis of the caption." 
    255255                        if ( ! empty( $iptc['2#105'][0] ) ) 
    256                                 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) ); 
     256                                $meta['title'] = trim( $iptc['2#105'][0] ); 
    257257                        // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." 
    258258                        elseif ( ! empty( $iptc['2#005'][0] ) ) 
    259                                 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) ); 
     259                                $meta['title'] = trim( $iptc['2#005'][0] ); 
    260260 
    261261                        if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption 
    262                                 $caption = utf8_encode( trim( $iptc['2#120'][0] ) ); 
     262                                $caption = trim( $iptc['2#120'][0] ); 
    263263                                if ( empty( $meta['title'] ) ) { 
    264264                                        // Assume the title is stored in 2:120 if it's short. 
    265265                                        if ( strlen( $caption ) < 80 ) 
     
    272272                        } 
    273273 
    274274                        if ( ! empty( $iptc['2#110'][0] ) ) // credit 
    275                                 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0])); 
     275                                $meta['credit'] = trim($iptc['2#110'][0]); 
    276276                        elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline 
    277                                 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0])); 
     277                                $meta['credit'] = trim($iptc['2#080'][0]); 
    278278 
    279279                        if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time 
    280280                                $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] ); 
    281281 
    282282                        if ( ! empty( $iptc['2#116'][0] ) ) // copyright 
    283                                 $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) ); 
     283                                $meta['copyright'] = trim( $iptc['2#116'][0] ); 
     284 
     285                        // If the encoding is not UTF-8, try to encode it! 
     286                        if ( ! isset( $iptc["1#090"] ) || $iptc["1#090"][0] != "\x1B%G" ) { 
     287                                $encode_list = array('title', 'caption', 'credit', 'copyright'); 
     288                                foreach ( $encode_list as $kname ) 
     289                                        if ( isset( $meta[$kname] ) ) 
     290                                                $meta[$kname] = utf8_encode($meta[$kname]); 
     291                        } 
    284292                 } 
    285293        } 
    286294