Make WordPress Core

Ticket #19512: 19512.patch

File 19512.patch, 1.5 KB (added by kurtpayne, 14 years ago)

Checking caption to see if it's text

  • wp-admin/includes/image.php

     
    236236                                $meta['title'] = 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] ) );
    240                                 if ( empty( $meta['title'] ) ) {
    241                                         // Assume the title is stored in 2:120 if it's short.
    242                                         if ( strlen( $caption ) < 80 )
    243                                                 $meta['title'] = $caption;
    244                                         else
     239                               
     240                                // Check mimetype using fileinfo, if available
     241                                $str = $iptc['2#120'][0];
     242                                $mime_type = '';
     243                                if ( extension_loaded('fileinfo') ) {
     244                                        $finfo = new finfo();
     245                                        $mime_type = $finfo->buffer( $str, FILEINFO_MIME );
     246                                        unset( $finfo );
     247
     248                                // If fileinfo isn't available, check the caption for printable characters
     249                                } elseif ( ctype_print($str) ) {
     250                                        $mime_type = 'text/plain';
     251                                }
     252                               
     253                                if ( 'text' == substr( $mime_type, 0, 4 ) ) {
     254                                        $caption = utf8_encode( trim( $iptc['2#120'][0] ) );
     255                                        if ( empty( $meta['title'] ) ) {
     256                                                // Assume the title is stored in 2:120 if it's short.
     257                                                if ( strlen( $caption ) < 80 )
     258                                                        $meta['title'] = $caption;
     259                                                else
     260                                                        $meta['caption'] = $caption;
     261                                        } elseif ( $caption != $meta['title'] ) {
    245262                                                $meta['caption'] = $caption;
    246                                 } elseif ( $caption != $meta['title'] ) {
    247                                         $meta['caption'] = $caption;
     263                                        }
    248264                                }
    249265                        }
    250266