<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13249] trunk/wp-admin/includes/image.php: Use utf8_encode()
  consistently in wp_read_image_metadata().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13249">13249</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-02-20 12:09:30 +0000 (Sat, 20 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use utf8_encode() consistently in wp_read_image_metadata(). Also add some whitespace. props miqrogroove, see <a href="http://trac.wordpress.org/ticket/11417">#11417</a>, see <a href="http://trac.wordpress.org/ticket/12095">#12095</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesimagephp">trunk/wp-admin/includes/image.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesimagephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image.php (13248 => 13249)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image.php        2010-02-20 11:56:00 UTC (rev 13248)
+++ trunk/wp-admin/includes/image.php        2010-02-20 12:09:30 UTC (rev 13249)
</span><span class="lines">@@ -226,10 +226,10 @@
</span><span class="cx">  * @return bool|array False on failure. Image metadata array on success.
</span><span class="cx">  */
</span><span class="cx"> function wp_read_image_metadata( $file ) {
</span><del>-        if ( !file_exists( $file ) )
</del><ins>+        if ( ! file_exists( $file ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        list(,,$sourceImageType) = getimagesize( $file );
</del><ins>+        list( , , $sourceImageType ) = getimagesize( $file );
</ins><span class="cx"> 
</span><span class="cx">         // exif contains a bunch of data we'll probably never need formatted in ways
</span><span class="cx">         // that are difficult to use. We'll normalize it and just extract the fields
</span><span class="lines">@@ -250,18 +250,20 @@
</span><span class="cx"> 
</span><span class="cx">         // read iptc first, since it might contain data not available in exif such
</span><span class="cx">         // as caption, description etc
</span><del>-        if ( is_callable('iptcparse') ) {
-                getimagesize($file, $info);
</del><ins>+        if ( is_callable( 'iptcparse' ) ) {
+                getimagesize( $file, $info );
</ins><span class="cx"> 
</span><del>-                if ( !empty($info['APP13']) ) {
-                        $iptc = iptcparse($info['APP13']);
</del><ins>+                if ( ! empty( $info['APP13'] ) ) {
+                        $iptc = iptcparse( $info['APP13'] );
</ins><span class="cx"> 
</span><del>-                        if ( ! empty($iptc['2#105'][0] ) ) // headline, &quot;A brief synopsis of the caption.&quot;
</del><ins>+                        // headline, &quot;A brief synopsis of the caption.&quot;
+                        if ( ! empty( $iptc['2#105'][0] ) )
</ins><span class="cx">                                 $meta['title'] = utf8_encode( trim( $iptc['2#105'][0] ) );
</span><del>-                        elseif ( !empty($iptc['2#005'][0]) ) // title, &quot;Many use the Title field to store the filename of the image, though the field may be used in many ways.&quot;
</del><ins>+                        // title, &quot;Many use the Title field to store the filename of the image, though the field may be used in many ways.&quot;
+                        elseif ( ! empty( $iptc['2#005'][0] ) )
</ins><span class="cx">                                 $meta['title'] = utf8_encode( trim( $iptc['2#005'][0] ) );
</span><span class="cx"> 
</span><del>-                        if ( !empty( $iptc['2#120'][0] ) ) { // description / legacy caption
</del><ins>+                        if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption
</ins><span class="cx">                                 $caption = utf8_encode( trim( $iptc['2#120'][0] ) );
</span><span class="cx">                                 if ( empty( $meta['title'] ) ) {
</span><span class="cx">                                         // Assume the title is stored in 2:120 if it's short.
</span><span class="lines">@@ -274,28 +276,28 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        if ( !empty($iptc['2#110'][0]) ) // credit
</del><ins>+                        if ( ! empty( $iptc['2#110'][0] ) ) // credit
</ins><span class="cx">                                 $meta['credit'] = utf8_encode(trim($iptc['2#110'][0]));
</span><del>-                        elseif ( !empty($iptc['2#080'][0]) ) // creator / legacy byline
</del><ins>+                        elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline
</ins><span class="cx">                                 $meta['credit'] = utf8_encode(trim($iptc['2#080'][0]));
</span><span class="cx"> 
</span><del>-                        if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created date and time
-                                $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
</del><ins>+                        if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time
+                                $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] );
</ins><span class="cx"> 
</span><del>-                        if ( !empty($iptc['2#116'][0]) ) // copyright
-                                $meta['copyright'] = utf8_encode(trim($iptc['2#116'][0]));
</del><ins>+                        if ( ! empty( $iptc['2#116'][0] ) ) // copyright
+                                $meta['copyright'] = utf8_encode( trim( $iptc['2#116'][0] ) );
</ins><span class="cx">                  }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // fetch additional info from exif if available
</span><del>-        if ( is_callable('exif_read_data') &amp;&amp; in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)) ) ) {
</del><ins>+        if ( is_callable( 'exif_read_data' ) &amp;&amp; in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) {
</ins><span class="cx">                 $exif = @exif_read_data( $file );
</span><span class="cx"> 
</span><span class="cx">                 if ( !empty( $exif['Title'] ) )
</span><span class="cx">                         $meta['title'] = utf8_encode( trim( $exif['Title'] ) );
</span><span class="cx"> 
</span><span class="cx">                 if ( ! empty( $exif['ImageDescription'] ) ) {
</span><del>-                        if ( empty($meta['title']) &amp;&amp; strlen( $exif['ImageDescription'] ) &lt; 80 ) {
</del><ins>+                        if ( empty( $meta['title'] ) &amp;&amp; strlen( $exif['ImageDescription'] ) &lt; 80 ) {
</ins><span class="cx">                                 // Assume the title is stored in ImageDescription
</span><span class="cx">                                 $meta['title'] = utf8_encode( trim( $exif['ImageDescription'] ) );
</span><span class="cx">                                 if ( ! empty( $exif['COMPUTED']['UserComment'] ) &amp;&amp; trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] )
</span><span class="lines">@@ -314,17 +316,17 @@
</span><span class="cx"> 
</span><span class="cx">                 if ( ! empty( $exif['Copyright'] ) )
</span><span class="cx">                         $meta['copyright'] = utf8_encode( trim( $exif['Copyright'] ) );
</span><del>-                if (!empty($exif['FNumber']))
</del><ins>+                if ( ! empty($exif['FNumber'] ) )
</ins><span class="cx">                         $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 );
</span><del>-                if (!empty($exif['Model']))
-                        $meta['camera'] = trim( $exif['Model'] );
-                if (!empty($exif['DateTimeDigitized']))
-                        $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
-                if (!empty($exif['FocalLength']))
</del><ins>+                if ( ! empty($exif['Model'] ) )
+                        $meta['camera'] = utf8_encode( trim( $exif['Model'] ) );
+                if ( ! empty($exif['DateTimeDigitized'] ) )
+                        $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] );
+                if ( ! empty($exif['FocalLength'] ) )
</ins><span class="cx">                         $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] );
</span><del>-                if (!empty($exif['ISOSpeedRatings']))
-                        $meta['iso'] = $exif['ISOSpeedRatings'];
-                if (!empty($exif['ExposureTime']))
</del><ins>+                if ( ! empty($exif['ISOSpeedRatings'] ) )
+                        $meta['iso'] = utf8_encode( trim( $exif['ISOSpeedRatings'] ) );
+                if ( ! empty($exif['ExposureTime'] ) )
</ins><span class="cx">                         $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] );
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>