<!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>[12163] trunk: Fix image meta after editing image,
  disable the Save button when no changes, fixes #11115</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12163">12163</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2009-11-11 11:24:01 +0000 (Wed, 11 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix image meta after editing image, disable the Save button when no changes, fixes <a href="http://trac.wordpress.org/ticket/11115">#11115</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesimageeditphp">trunk/wp-admin/includes/image-edit.php</a></li>
<li><a href="#trunkwpadminincludesimagephp">trunk/wp-admin/includes/image.php</a></li>
<li><a href="#trunkwpadminjsimageeditdevjs">trunk/wp-admin/js/image-edit.dev.js</a></li>
<li><a href="#trunkwpadminjsimageeditjs">trunk/wp-admin/js/image-edit.js</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesimageeditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image-edit.php (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image-edit.php        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-admin/includes/image-edit.php        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -68,7 +68,7 @@
</span><span class="cx"> 
</span><span class="cx">         &lt;div class=&quot;imgedit-submit&quot;&gt;
</span><span class="cx">                 &lt;input type=&quot;button&quot; onclick=&quot;imageEdit.close(&lt;?php echo $post_id; ?&gt;, 1)&quot; class=&quot;button&quot; value=&quot;&lt;?php echo esc_attr__( 'Cancel' ); ?&gt;&quot; /&gt;
</span><del>-                &lt;input type=&quot;button&quot; onclick=&quot;imageEdit.save(&lt;?php echo &quot;$post_id, '$nonce'&quot;; ?&gt;)&quot; class=&quot;button-primary imgedit-submit-btn&quot; value=&quot;&lt;?php echo esc_attr__( 'Save' ); ?&gt;&quot; /&gt;
</del><ins>+                &lt;input type=&quot;button&quot; onclick=&quot;imageEdit.save(&lt;?php echo &quot;$post_id, '$nonce'&quot;; ?&gt;)&quot; disabled=&quot;disabled&quot; class=&quot;button-primary imgedit-submit-btn&quot; value=&quot;&lt;?php echo esc_attr__( 'Save' ); ?&gt;&quot; /&gt;
</ins><span class="cx">         &lt;/div&gt;
</span><span class="cx">         &lt;/td&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -92,7 +92,12 @@
</span><span class="cx">         &lt;div class=&quot;imgedit-group-top&quot;&gt;
</span><span class="cx">                 &lt;a class=&quot;imgedit-help-toggle&quot; onclick=&quot;imageEdit.toggleHelp(this);return false;&quot; href=&quot;#&quot;&gt;&lt;strong&gt;&lt;?php _e('Restore Original Image'); ?&gt;&lt;/strong&gt;&lt;/a&gt;
</span><span class="cx">                 &lt;div class=&quot;imgedit-help&quot;&gt;
</span><del>-                &lt;p&gt;&lt;?php _e('Discard any changes and restore the original image. Previously edited copies of the image will not be deleted.'); ?&gt;&lt;/p&gt;
</del><ins>+                &lt;p&gt;&lt;?php _e('Discard any changes and restore the original image.'); 
+
+                if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE )
+                        _e(' Previously edited copies of the image will not be deleted.');
+
+                ?&gt;&lt;/p&gt;
</ins><span class="cx">                 &lt;div class=&quot;imgedit-submit&quot;&gt;
</span><span class="cx">                 &lt;input type=&quot;button&quot; onclick=&quot;imageEdit.action(&lt;?php echo &quot;$post_id, '$nonce'&quot;; ?&gt;, 'restore')&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php echo esc_attr__( 'Restore image' ); ?&gt;&quot; &lt;?php echo $can_restore; ?&gt; /&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><span class="lines">@@ -409,6 +414,7 @@
</span><span class="cx"> 
</span><span class="cx"> function wp_restore_image($post_id) {
</span><span class="cx">         $meta = wp_get_attachment_metadata($post_id);
</span><ins>+        $file = get_attached_file($post_id);
</ins><span class="cx">         $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
</span><span class="cx">         $restored = false;
</span><span class="cx">         $msg = '';
</span><span class="lines">@@ -418,49 +424,51 @@
</span><span class="cx">                 return $msg;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        $parts = pathinfo($meta['file']);
</del><ins>+        $parts = pathinfo($file);
</ins><span class="cx">         $suffix = time() . rand(100, 999);
</span><span class="cx">         $default_sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') );
</span><del>-        $default_sizes[] = 'full';
</del><span class="cx"> 
</span><ins>+        if ( isset($backup_sizes['full-orig']) &amp;&amp; is_array($backup_sizes['full-orig']) ) {
+                $data = $backup_sizes['full-orig'];
+
+                if ( $parts['basename'] != $data['file'] ) {
+                        if ( defined('IMAGE_EDIT_OVERWRITE') &amp;&amp; IMAGE_EDIT_OVERWRITE ) {
+                                // delete only if it's edited image
+                                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
+                                        $delpath = apply_filters('wp_delete_file', $file);
+                                        @unlink($delpath);
+                                }
+                        } else {
+                                $backup_sizes[&quot;full-$suffix&quot;] = array('width' =&gt; $meta['width'], 'height' =&gt; $meta['height'], 'file' =&gt; $parts['basename']);
+                        }
+                }
+
+                $restored_file = path_join($parts['dirname'], $data['file']);
+                $restored = update_attached_file($post_id, $restored_file);
+
+                $meta['file'] = _wp_relative_upload_path( $restored_file );
+                $meta['width'] = $data['width'];
+                $meta['height'] = $data['height'];
+                list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']);
+                $meta['hwstring_small'] = &quot;height='$uheight' width='$uwidth'&quot;;
+        }
+
</ins><span class="cx">         foreach ( $default_sizes as $default_size ) {
</span><span class="cx">                 if ( isset($backup_sizes[&quot;$default_size-orig&quot;]) ) {
</span><span class="cx">                         $data = $backup_sizes[&quot;$default_size-orig&quot;];
</span><del>-                        if ( 'full' == $default_size ) {
-                                if ( $parts['basename'] != $data['file'] ) {
-                                        if ( defined('IMAGE_EDIT_OVERWRITE') &amp;&amp; IMAGE_EDIT_OVERWRITE ) {
-                                                // delete only if it's edited image
-                                                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
-                                                        $delpath = apply_filters('wp_delete_file', $meta['file']);
-                                                        @unlink($delpath);
-                                                }
-                                        } else {
-                                                $backup_sizes[&quot;full-$suffix&quot;] = array('width' =&gt; $meta['width'], 'height' =&gt; $meta['height'], 'file' =&gt; $parts['basename']);
</del><ins>+                        if ( isset($meta['sizes'][$default_size]) &amp;&amp; $meta['sizes'][$default_size]['file'] != $data['file'] ) {
+                                if ( defined('IMAGE_EDIT_OVERWRITE') &amp;&amp; IMAGE_EDIT_OVERWRITE ) {
+                                        // delete only if it's edited image
+                                        if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
+                                                $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
+                                                @unlink($delpath);
</ins><span class="cx">                                         }
</span><ins>+                                } else {
+                                        $backup_sizes[&quot;$default_size-{$suffix}&quot;] = $meta['sizes'][$default_size];
</ins><span class="cx">                                 }
</span><ins>+                        }
</ins><span class="cx"> 
</span><del>-                                $meta['file'] = path_join($parts['dirname'], $data['file']);
-                                $meta['width'] = $data['width'];
-                                $meta['height'] = $data['height'];
-
-                                list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']);
-                                $meta['hwstring_small'] = &quot;height='$uheight' width='$uwidth'&quot;;
-                                $restored = update_attached_file($post_id, $meta['file']);
-                        } else {
-                                if ( isset($meta['sizes'][$default_size]) &amp;&amp; $meta['sizes'][$default_size]['file'] != $data['file'] ) {
-                                        if ( defined('IMAGE_EDIT_OVERWRITE') &amp;&amp; IMAGE_EDIT_OVERWRITE ) {
-                                                // delete only if it's edited image
-                                                if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
-                                                        $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
-                                                        @unlink($delpath);
-                                                }
-                                        } else {
-                                                $backup_sizes[&quot;$default_size-{$suffix}&quot;] = $meta['sizes'][$default_size];
-                                        }
-                                }
-
-                                $meta['sizes'][$default_size] = $data;
-                        }
</del><ins>+                        $meta['sizes'][$default_size] = $data;
</ins><span class="cx">                 } else {
</span><span class="cx">                         unset($meta['sizes'][$default_size]);
</span><span class="cx">                 }
</span><span class="lines">@@ -580,7 +588,8 @@
</span><span class="cx">                         $backup_sizes[$tag] = array('width' =&gt; $meta['width'], 'height' =&gt; $meta['height'], 'file' =&gt; $path_parts['basename']);
</span><span class="cx"> 
</span><span class="cx">                 $success = update_attached_file($post_id, $new_path);
</span><del>-                $meta['file'] = get_attached_file($post_id, true); // get the path unfiltered
</del><ins>+
+                $meta['file'] = _wp_relative_upload_path($new_path);
</ins><span class="cx">                 $meta['width'] = imagesx($img);
</span><span class="cx">                 $meta['height'] = imagesy($img);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesimagephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image.php (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image.php        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-admin/includes/image.php        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -88,35 +88,27 @@
</span><span class="cx"> 
</span><span class="cx">         $metadata = array();
</span><span class="cx">         if ( preg_match('!^image/!', get_post_mime_type( $attachment )) &amp;&amp; file_is_displayable_image($file) ) {
</span><del>-                $full_path_file = $file;
-                $imagesize = getimagesize( $full_path_file );
</del><ins>+                $imagesize = getimagesize( $file );
</ins><span class="cx">                 $metadata['width'] = $imagesize[0];
</span><span class="cx">                 $metadata['height'] = $imagesize[1];
</span><span class="cx">                 list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
</span><span class="cx">                 $metadata['hwstring_small'] = &quot;height='$uheight' width='$uwidth'&quot;;
</span><span class="cx"> 
</span><span class="cx">                 // Make the file path relative to the upload dir
</span><del>-                if ( ($uploads = wp_upload_dir()) &amp;&amp; false === $uploads['error'] ) { // Get upload directory
-                        if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
-                                $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
-                                $file = ltrim($file, '/');
-                        }
-                }
-                $metadata['file'] = $file;
</del><ins>+                $metadata['file'] = _wp_relative_upload_path($file);
</ins><span class="cx"> 
</span><span class="cx">                 // make thumbnails and other intermediate sizes
</span><del>-                $sizes = array('thumbnail', 'medium', 'large');
-                $sizes = apply_filters('intermediate_image_sizes', $sizes);
</del><ins>+                $sizes = apply_filters( 'intermediate_image_sizes', array('thumbnail', 'medium', 'large') );
</ins><span class="cx"> 
</span><span class="cx">                 foreach ($sizes as $size) {
</span><del>-                        $resized = image_make_intermediate_size( $full_path_file, get_option(&quot;{$size}_size_w&quot;), get_option(&quot;{$size}_size_h&quot;), get_option(&quot;{$size}_crop&quot;) );
</del><ins>+                        $resized = image_make_intermediate_size( $file, get_option(&quot;{$size}_size_w&quot;), get_option(&quot;{$size}_size_h&quot;), get_option(&quot;{$size}_crop&quot;) );
</ins><span class="cx">                         if ( $resized )
</span><span class="cx">                                 $metadata['sizes'][$size] = $resized;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // fetch additional metadata from exif/iptc
</span><del>-                $image_meta = wp_read_image_metadata( $full_path_file );
-                if ($image_meta)
</del><ins>+                $image_meta = wp_read_image_metadata( $file );
+                if ( $image_meta )
</ins><span class="cx">                         $metadata['image_meta'] = $image_meta;
</span><span class="cx"> 
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpadminjsimageeditdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/image-edit.dev.js (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/image-edit.dev.js        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-admin/js/image-edit.dev.js        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -175,6 +175,11 @@
</span><span class="cx">                         if ( (typeof callback != &quot;unknown&quot;) &amp;&amp; callback != null )
</span><span class="cx">                                 callback();
</span><span class="cx"> 
</span><ins>+                        if ( $('#imgedit-history-' + postid).val() &amp;&amp; $('#imgedit-undone-' + postid).val() == 0 )
+                                $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
+                        else
+                                $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).attr('disabled', 'disabled');
+
</ins><span class="cx">                         t.toggleEditor(postid, 0);
</span><span class="cx">                 }).attr('src', ajaxurl + '?' + $.param(data));
</span><span class="cx">         },
</span></span></pre></div>
<a id="trunkwpadminjsimageeditjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/image-edit.js (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/image-edit.js        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-admin/js/image-edit.js        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -1 +1 @@
</span><del>-var imageEdit;(function(a){imageEdit={iasapi:{},hold:{},postid:&quot;&quot;,intval:function(b){return b|0},setDisabled:function(c,b){if(b){c.removeClass(&quot;disabled&quot;);a(&quot;input&quot;,c).removeAttr(&quot;disabled&quot;)}else{c.addClass(&quot;disabled&quot;);a(&quot;input&quot;,c).attr(&quot;disabled&quot;,&quot;disabled&quot;)}},init:function(g,e){var d=this,c=a(&quot;#image-editor-&quot;+d.postid),b=d.intval(a(&quot;#imgedit-x-&quot;+g).val()),f=d.intval(a(&quot;#imgedit-y-&quot;+g).val());if(d.postid!=g&amp;&amp;c.length){d.close(d.postid)}d.hold.w=d.hold.ow=b;d.hold.h=d.hold.oh=f;d.hold.xy_ratio=b/f;d.hold.sizer=parseFloat(a(&quot;#imgedit-sizer-&quot;+g).val());d.postid=g;a(&quot;#imgedit-response-&quot;+g).empty();a('input[type=&quot;text&quot;]',&quot;#imgedit-panel-&quot;+g).keypress(function(i){var h=i.keyCode;if(36&lt;h&amp;&amp;h&lt;41){a(this).blur()}if(13==h){i.preventDefault();i.stopPropagation();return false}})},toggleEditor:function(d,b){var c=a(&quot;#imgedit-wait-&quot;+d);if(b){c.height(a(&quot;#imgedit-panel-&quot;+d).height()).fadeIn(&quot;fast&quot;)}else{c.fadeOut(&quot;fast&quot;)}},toggleHelp:function(b){a(b).siblings(&quot;.imgedit-help&quot;).slideToggle(&quot;fast&quot;);return false},getTarget:function(b){return a(&quot;input[name=imgedit-target-&quot;+b+&quot;]:checked&quot;,&quot;#imgedit-save-target-&quot;+b).val()||&quot;full&quot;},scaleChanged:function(i,b){var d=a(&quot;#imgedit-scale-width-&quot;+i),f=a(&quot;#imgedit-scale-height-&quot;+i),g=a(&quot;#imgedit-scale-warn-&quot;+i),c=&quot;&quot;,e=&quot;&quot;;if(b){e=(d.val()!=&quot;&quot;)?this.intval(d.val()/this.hold.xy_ratio):&quot;&quot;;f.val(e)}else{c=(f.val()!=&quot;&quot;)?this.intval(f.val()*this.hold.xy_ratio):&quot;&quot;;d.val(c)}if((e&amp;&amp;e&gt;this.hold.oh)||(c&amp;&amp;c&gt;this.hold.ow)){g.css(&quot;visibility&quot;,&quot;visible&quot;)}else{g.css(&quot;visibility&quot;,&quot;hidden&quot;)}},getSelRatio:function(f){var b=this.hold.w,e=this.hold.h,d=this.intval(a(&quot;#imgedit-crop-width-&quot;+f).val()),c=this.intval(a(&quot;#imgedit-crop-height-&quot;+f).val());if(d&amp;&amp;c){return d+&quot;:&quot;+c}if(b&amp;&amp;e){return b+&quot;:&quot;+e}return&quot;1:1&quot;},filterHistory:function(j,f){var d=a(&quot;#imgedit-history-&quot;+j).val(),b,h,e,c,g=[];if(d!=&quot;&quot;){d=JSON.parse(d);b=this.intval(a(&quot;#imgedit-undone-&quot;+j).val());if(b&gt;0){while(b&gt;0){d.pop();b--}}if(f){if(!d.length){this.hold.w=this.hold.ow;this.hold.h=this.hold.oh;return&quot;&quot;}e=d[d.length-1];e=e.c||e.r||e.f||false;if(e){this.hold.w=e.fw;this.hold.h=e.fh}}for(h in d){c=d[h];if(c.hasOwnProperty(&quot;c&quot;)){g[h]={c:{x:c.c.x,y:c.c.y,w:c.c.w,h:c.c.h}}}else{if(c.hasOwnProperty(&quot;r&quot;)){g[h]={r:c.r.r}}else{if(c.hasOwnProperty(&quot;f&quot;)){g[h]={f:c.f.f}}}}}return JSON.stringify(g)}return&quot;&quot;},refreshEditor:function(g,d,f){var c=this,e,b;c.toggleEditor(g,1);e={action:&quot;imgedit-preview&quot;,_ajax_nonce:d,postid:g,history:c.filterHistory(g,1),rand:c.intval(Math.random()*1000000)};b=a('&lt;img id=&quot;image-preview-'+g+'&quot; /&gt;');b.load(function(){var i,h,k=a(&quot;#imgedit-crop-&quot;+g),j=imageEdit;k.empty().append(b);i=Math.max(j.hold.w,j.hold.h);h=Math.max(a(b).width(),a(b).height());j.hold.sizer=i&gt;h?h/i:1;j.initCrop(g,b,k);j.setCropSelection(g,0);if((typeof f!=&quot;unknown&quot;)&amp;&amp;f!=null){f()}j.toggleEditor(g,0)}).attr(&quot;src&quot;,ajaxurl+&quot;?&quot;+a.param(e))},action:function(b,g,c){var j=this,e,i,f,d,k;if(j.notsaved(b)){return false}e={action:&quot;image-editor&quot;,_ajax_nonce:g,postid:b};if(&quot;scale&quot;==c){i=a(&quot;#imgedit-scale-width-&quot;+b),f=a(&quot;#imgedit-scale-height-&quot;+b),d=j.intval(i.val()),k=j.intval(f.val());if(d&lt;1){i.focus();return false}else{if(k&lt;1){f.focus();return false}}if(d==j.hold.ow||k==j.hold.oh){return false}e[&quot;do&quot;]=&quot;scale&quot;;e.fwidth=d;e.fheight=k}else{if(&quot;restore&quot;==c){e[&quot;do&quot;]=&quot;restore&quot;}else{return false}}j.toggleEditor(b,1);a.post(ajaxurl,e,function(h){a(&quot;#image-editor-&quot;+b).empty().append(h);j.toggleEditor(b,0)})},save:function(f,b){var c,e=this.getTarget(f),d=this.filterHistory(f,0);if(&quot;&quot;==d){return false}this.toggleEditor(f,1);c={action:&quot;image-editor&quot;,_ajax_nonce:b,postid:f,history:d,target:e,&quot;do&quot;:&quot;save&quot;};a.post(ajaxurl,c,function(h){var g=JSON.parse(h);if(g.error){a(&quot;#imgedit-response-&quot;+f).html('&lt;div class=&quot;error&quot;&gt;&lt;p&gt;'+g.error+&quot;&lt;/p&gt;&lt;div&gt;&quot;);imageEdit.close(f);return}if(g.fw&amp;&amp;g.fh){a(&quot;#media-dims-&quot;+f).html(g.fw+&quot; &amp;times; &quot;+g.fh)}if(g.thumbnail){a(&quot;.thumbnail&quot;,&quot;#thumbnail-head-&quot;+f).attr(&quot;src&quot;,&quot;&quot;+g.thumbnail)}if(g.msg){a(&quot;#imgedit-response-&quot;+f).html('&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;'+g.msg+&quot;&lt;/p&gt;&lt;/div&gt;&quot;)}imageEdit.close(f)})},open:function(h,d){var f,e=a(&quot;#image-editor-&quot;+h),c=a(&quot;#media-head-&quot;+h),b=a(&quot;#imgedit-open-btn-&quot;+h),g=b.siblings(&quot;img&quot;);b.attr(&quot;disabled&quot;,&quot;disabled&quot;);g.css(&quot;visibility&quot;,&quot;visible&quot;);f={action:&quot;image-editor&quot;,_ajax_nonce:d,postid:h,&quot;do&quot;:&quot;open&quot;};e.load(ajaxurl,f,function(){e.fadeIn(&quot;fast&quot;);c.fadeOut(&quot;fast&quot;,function(){b.removeAttr(&quot;disabled&quot;);g.css(&quot;visibility&quot;,&quot;hidden&quot;)})})},imgLoaded:function(d){var b=a(&quot;#image-preview-&quot;+d),c=a(&quot;#imgedit-crop-&quot;+d);this.initCrop(d,b,c);this.setCropSelection(d,0);this.toggleEditor(d,0)},initCrop:function(g,e,c){var b=this,d=a(&quot;#imgedit-sel-width-&quot;+g),f=a(&quot;#imgedit-sel-height-&quot;+g);b.iasapi=a(e).imgAreaSelect({parent:c,instance:true,handles:true,keys:true,minWidth:3,minHeight:3,onInit:function(h,i){c.children().mousedown(function(m){var k=false,l,j;if(m.shiftKey){l=b.iasapi.getSelection();j=b.getSelRatio(g);k=(l&amp;&amp;l.width&amp;&amp;l.height)?l.width+&quot;:&quot;+l.height:j}b.iasapi.setOptions({aspectRatio:k})})},onSelectStart:function(h,i){imageEdit.setDisabled(a(&quot;#imgedit-crop-sel-&quot;+g),1)},onSelectEnd:function(h,i){imageEdit.setCropSelection(g,i)},onSelectChange:function(h,j){var i=imageEdit.hold.sizer;d.val(imageEdit.round(j.width/i));f.val(imageEdit.round(j.height/i))}})},setCropSelection:function(g,f){var e,b=a(&quot;#imgedit-minthumb-&quot;+g).val()||&quot;128:128&quot;,d=this.hold.sizer;b=b.split(&quot;:&quot;);f=f||0;if(!f||(f.width&lt;3&amp;&amp;f.height&lt;3)){this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),0);this.setDisabled(a(&quot;#imgedit-crop-sel-&quot;+g),0);a(&quot;#imgedit-sel-width-&quot;+g).val(&quot;&quot;);a(&quot;#imgedit-sel-height-&quot;+g).val(&quot;&quot;);a(&quot;#imgedit-selection-&quot;+g).val(&quot;&quot;);return false}if(f.width&lt;(b[0]*d)&amp;&amp;f.height&lt;(b[1]*d)){this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),0);a(&quot;#imgedit-selection-&quot;+g).val(&quot;&quot;);return false}e={x:f.x1,y:f.y1,w:f.width,h:f.height};this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),1);a(&quot;#imgedit-selection-&quot;+g).val(JSON.stringify(e))},close:function(c,b){b=b||false;if(b&amp;&amp;this.notsaved(c)){return false}this.iasapi={};this.hold={};a(&quot;#image-editor-&quot;+c).fadeOut(&quot;fast&quot;,function(){a(&quot;#media-head-&quot;+c).fadeIn(&quot;fast&quot;);a(this).empty()})},notsaved:function(e){var c=a(&quot;#imgedit-history-&quot;+e).val(),d=(c!=&quot;&quot;)?JSON.parse(c):new Array(),b=this.intval(a(&quot;#imgedit-undone-&quot;+e).val());if(b&lt;d.length){if(confirm(a(&quot;#imgedit-leaving-&quot;+e).html())){return false}return true}return false},addStep:function(i,h,d){var c=this,e=a(&quot;#imgedit-history-&quot;+h),g=(e.val()!=&quot;&quot;)?JSON.parse(e.val()):new Array(),f=a(&quot;#imgedit-undone-&quot;+h),b=c.intval(f.val());while(b&gt;0){g.pop();b--}f.val(0);g.push(i);e.val(JSON.stringify(g));c.refreshEditor(h,d,function(){c.setDisabled(a(&quot;#image-undo-&quot;+h),true);c.setDisabled(a(&quot;#image-redo-&quot;+h),false)})},rotate:function(d,e,c,b){if(a(b).hasClass(&quot;disabled&quot;)){return false}this.addStep({r:{r:d,fw:this.hold.h,fh:this.hold.w}},e,c)},flip:function(d,e,c,b){if(a(b).hasClass(&quot;disabled&quot;)){return false}this.addStep({f:{f:d,fw:this.hold.w,fh:this.hold.h}},e,c)},crop:function(g,e,c){var f=a(&quot;#imgedit-selection-&quot;+g).val(),b=this.intval(a(&quot;#imgedit-sel-width-&quot;+g).val()),d=this.intval(a(&quot;#imgedit-sel-height-&quot;+g).val());if(a(c).hasClass(&quot;disabled&quot;)||f==&quot;&quot;){return false}f=JSON.parse(f);if(f.w&gt;0&amp;&amp;f.h&gt;0&amp;&amp;b&gt;0&amp;&amp;d&gt;0){f.fw=b;f.fh=d;this.addStep({c:f},g,e)}},undo:function(g,e){var d=this,c=a(&quot;#image-undo-&quot;+g),f=a(&quot;#imgedit-undone-&quot;+g),b=d.intval(f.val())+1;if(c.hasClass(&quot;disabled&quot;)){return}f.val(b);d.refreshEditor(g,e,function(){var h=a(&quot;#imgedit-history-&quot;+g),i=(h.val()!=&quot;&quot;)?JSON.parse(h.val()):new Array();d.setDisabled(a(&quot;#image-redo-&quot;+g),true);d.setDisabled(c,b&lt;i.length)})},redo:function(g,e){var d=this,c=a(&quot;#image-redo-&quot;+g),f=a(&quot;#imgedit-undone-&quot;+g),b=d.intval(f.val())-1;if(c.hasClass(&quot;disabled&quot;)){return}f.val(b);d.refreshEditor(g,e,function(){d.setDisabled(a(&quot;#image-undo-&quot;+g),true);d.setDisabled(c,b&gt;0)})},setNumSelection:function(c){var g,k=a(&quot;#imgedit-sel-width-&quot;+c),j=a(&quot;#imgedit-sel-height-&quot;+c),o=this.intval(k.val()),m=this.intval(j.val()),i=a(&quot;#image-preview-&quot;+c),p=i.height(),h=i.width(),b=this.hold.sizer,f,n,e,l,d=this.iasapi;if(o&lt;1){k.val(&quot;&quot;);return false}if(m&lt;1){j.val(&quot;&quot;);return false}if(o&amp;&amp;m&amp;&amp;(g=d.getSelection())){e=g.x1+Math.round(o*b);l=g.y1+Math.round(m*b);f=g.x1;n=g.y1;if(e&gt;h){f=0;e=h;k.val(Math.round(e/b))}if(l&gt;p){n=0;l=p;j.val(Math.round(l/b))}d.setSelection(f,n,e,l);d.update();this.setCropSelection(c,d.getSelection())}},round:function(b){var c;b=Math.round(b);if(this.hold.sizer&gt;0.6){return b}c=b.toString().slice(-1);if(&quot;1&quot;==c){return b-1}else{if(&quot;9&quot;==c){return b+1}}return b},setRatioSelection:function(j,i,d){var f,e,b=this.intval(a(&quot;#imgedit-crop-width-&quot;+j).val()),g=this.intval(a(&quot;#imgedit-crop-height-&quot;+j).val()),c=a(&quot;#image-preview-&quot;+j).height();if(!this.intval(a(d).val())){a(d).val(&quot;&quot;);return}if(b&amp;&amp;g){this.iasapi.setOptions({aspectRatio:b+&quot;:&quot;+g});if(f=this.iasapi.getSelection(true)){e=Math.ceil(f.y1+((f.x2-f.x1)/(b/g)));if(e&gt;c){e=c;if(i){a(&quot;#imgedit-crop-height-&quot;+j).val(&quot;&quot;)}else{a(&quot;#imgedit-crop-width-&quot;+j).val(&quot;&quot;)}}this.iasapi.setSelection(f.x1,f.y1,f.x2,e);this.iasapi.update()}}}}})(jQuery);
</del><span class="cx">\ No newline at end of file
</span><ins>+var imageEdit;(function(a){imageEdit={iasapi:{},hold:{},postid:&quot;&quot;,intval:function(b){return b|0},setDisabled:function(c,b){if(b){c.removeClass(&quot;disabled&quot;);a(&quot;input&quot;,c).removeAttr(&quot;disabled&quot;)}else{c.addClass(&quot;disabled&quot;);a(&quot;input&quot;,c).attr(&quot;disabled&quot;,&quot;disabled&quot;)}},init:function(g,e){var d=this,c=a(&quot;#image-editor-&quot;+d.postid),b=d.intval(a(&quot;#imgedit-x-&quot;+g).val()),f=d.intval(a(&quot;#imgedit-y-&quot;+g).val());if(d.postid!=g&amp;&amp;c.length){d.close(d.postid)}d.hold.w=d.hold.ow=b;d.hold.h=d.hold.oh=f;d.hold.xy_ratio=b/f;d.hold.sizer=parseFloat(a(&quot;#imgedit-sizer-&quot;+g).val());d.postid=g;a(&quot;#imgedit-response-&quot;+g).empty();a('input[type=&quot;text&quot;]',&quot;#imgedit-panel-&quot;+g).keypress(function(i){var h=i.keyCode;if(36&lt;h&amp;&amp;h&lt;41){a(this).blur()}if(13==h){i.preventDefault();i.stopPropagation();return false}})},toggleEditor:function(d,b){var c=a(&quot;#imgedit-wait-&quot;+d);if(b){c.height(a(&quot;#imgedit-panel-&quot;+d).height()).fadeIn(&quot;fast&quot;)}else{c.fadeOut(&quot;fast&quot;)}},toggleHelp:function(b){a(b).siblings(&quot;.imgedit-help&quot;).slideToggle(&quot;fast&quot;);return false},getTarget:function(b){return a(&quot;input[name=imgedit-target-&quot;+b+&quot;]:checked&quot;,&quot;#imgedit-save-target-&quot;+b).val()||&quot;full&quot;},scaleChanged:function(i,b){var d=a(&quot;#imgedit-scale-width-&quot;+i),f=a(&quot;#imgedit-scale-height-&quot;+i),g=a(&quot;#imgedit-scale-warn-&quot;+i),c=&quot;&quot;,e=&quot;&quot;;if(b){e=(d.val()!=&quot;&quot;)?this.intval(d.val()/this.hold.xy_ratio):&quot;&quot;;f.val(e)}else{c=(f.val()!=&quot;&quot;)?this.intval(f.val()*this.hold.xy_ratio):&quot;&quot;;d.val(c)}if((e&amp;&amp;e&gt;this.hold.oh)||(c&amp;&amp;c&gt;this.hold.ow)){g.css(&quot;visibility&quot;,&quot;visible&quot;)}else{g.css(&quot;visibility&quot;,&quot;hidden&quot;)}},getSelRatio:function(f){var b=this.hold.w,e=this.hold.h,d=this.intval(a(&quot;#imgedit-crop-width-&quot;+f).val()),c=this.intval(a(&quot;#imgedit-crop-height-&quot;+f).val());if(d&amp;&amp;c){return d+&quot;:&quot;+c}if(b&amp;&amp;e){return b+&quot;:&quot;+e}return&quot;1:1&quot;},filterHistory:function(j,f){var d=a(&quot;#imgedit-history-&quot;+j).val(),b,h,e,c,g=[];if(d!=&quot;&quot;){d=JSON.parse(d);b=this.intval(a(&quot;#imgedit-undone-&quot;+j).val());if(b&gt;0){while(b&gt;0){d.pop();b--}}if(f){if(!d.length){this.hold.w=this.hold.ow;this.hold.h=this.hold.oh;return&quot;&quot;}e=d[d.length-1];e=e.c||e.r||e.f||false;if(e){this.hold.w=e.fw;this.hold.h=e.fh}}for(h in d){c=d[h];if(c.hasOwnProperty(&quot;c&quot;)){g[h]={c:{x:c.c.x,y:c.c.y,w:c.c.w,h:c.c.h}}}else{if(c.hasOwnProperty(&quot;r&quot;)){g[h]={r:c.r.r}}else{if(c.hasOwnProperty(&quot;f&quot;)){g[h]={f:c.f.f}}}}}return JSON.stringify(g)}return&quot;&quot;},refreshEditor:function(g,d,f){var c=this,e,b;c.toggleEditor(g,1);e={action:&quot;imgedit-preview&quot;,_ajax_nonce:d,postid:g,history:c.filterHistory(g,1),rand:c.intval(Math.random()*1000000)};b=a('&lt;img id=&quot;image-preview-'+g+'&quot; /&gt;');b.load(function(){var i,h,k=a(&quot;#imgedit-crop-&quot;+g),j=imageEdit;k.empty().append(b);i=Math.max(j.hold.w,j.hold.h);h=Math.max(a(b).width(),a(b).height());j.hold.sizer=i&gt;h?h/i:1;j.initCrop(g,b,k);j.setCropSelection(g,0);if((typeof f!=&quot;unknown&quot;)&amp;&amp;f!=null){f()}if(a(&quot;#imgedit-history-&quot;+g).val()&amp;&amp;a(&quot;#imgedit-undone-&quot;+g).val()==0){a(&quot;input.imgedit-submit-btn&quot;,&quot;#imgedit-panel-&quot;+g).removeAttr(&quot;disabled&quot;)}else{a(&quot;input.imgedit-submit-btn&quot;,&quot;#imgedit-panel-&quot;+g).attr(&quot;disabled&quot;,&quot;disabled&quot;)}j.toggleEditor(g,0)}).attr(&quot;src&quot;,ajaxurl+&quot;?&quot;+a.param(e))},action:function(b,g,c){var j=this,e,i,f,d,k;if(j.notsaved(b)){return false}e={action:&quot;image-editor&quot;,_ajax_nonce:g,postid:b};if(&quot;scale&quot;==c){i=a(&quot;#imgedit-scale-width-&quot;+b),f=a(&quot;#imgedit-scale-height-&quot;+b),d=j.intval(i.val()),k=j.intval(f.val());if(d&lt;1){i.focus();return false}else{if(k&lt;1){f.focus();return false}}if(d==j.hold.ow||k==j.hold.oh){return false}e[&quot;do&quot;]=&quot;scale&quot;;e.fwidth=d;e.fheight=k}else{if(&quot;restore&quot;==c){e[&quot;do&quot;]=&quot;restore&quot;}else{return false}}j.toggleEditor(b,1);a.post(ajaxurl,e,function(h){a(&quot;#image-editor-&quot;+b).empty().append(h);j.toggleEditor(b,0)})},save:function(f,b){var c,e=this.getTarget(f),d=this.filterHistory(f,0);if(&quot;&quot;==d){return false}this.toggleEditor(f,1);c={action:&quot;image-editor&quot;,_ajax_nonce:b,postid:f,history:d,target:e,&quot;do&quot;:&quot;save&quot;};a.post(ajaxurl,c,function(h){var g=JSON.parse(h);if(g.error){a(&quot;#imgedit-response-&quot;+f).html('&lt;div class=&quot;error&quot;&gt;&lt;p&gt;'+g.error+&quot;&lt;/p&gt;&lt;div&gt;&quot;);imageEdit.close(f);return}if(g.fw&amp;&amp;g.fh){a(&quot;#media-dims-&quot;+f).html(g.fw+&quot; &amp;times; &quot;+g.fh)}if(g.thumbnail){a(&quot;.thumbnail&quot;,&quot;#thumbnail-head-&quot;+f).attr(&quot;src&quot;,&quot;&quot;+g.thumbnail)}if(g.msg){a(&quot;#imgedit-response-&quot;+f).html('&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;'+g.msg+&quot;&lt;/p&gt;&lt;/div&gt;&quot;)}imageEdit.close(f)})},open:function(h,d){var f,e=a(&quot;#image-editor-&quot;+h),c=a(&quot;#media-head-&quot;+h),b=a(&quot;#imgedit-open-btn-&quot;+h),g=b.siblings(&quot;img&quot;);b.attr(&quot;disabled&quot;,&quot;disabled&quot;);g.css(&quot;visibility&quot;,&quot;visible&quot;);f={action:&quot;image-editor&quot;,_ajax_nonce:d,postid:h,&quot;do&quot;:&quot;open&quot;};e.load(ajaxurl,f,function(){e.fadeIn(&quot;fast&quot;);c.fadeOut(&quot;fast&quot;,function(){b.removeAttr(&quot;disabled&quot;);g.css(&quot;visibility&quot;,&quot;hidden&quot;)})})},imgLoaded:function(d){var b=a(&quot;#image-preview-&quot;+d),c=a(&quot;#imgedit-crop-&quot;+d);this.initCrop(d,b,c);this.setCropSelection(d,0);this.toggleEditor(d,0)},initCrop:function(g,e,c){var b=this,d=a(&quot;#imgedit-sel-width-&quot;+g),f=a(&quot;#imgedit-sel-height-&quot;+g);b.iasapi=a(e).imgAreaSelect({parent:c,instance:true,handles:true,keys:true,minWidth:3,minHeight:3,onInit:function(h,i){c.children().mousedown(function(m){var k=false,l,j;if(m.shiftKey){l=b.iasapi.getSelection();j=b.getSelRatio(g);k=(l&amp;&amp;l.width&amp;&amp;l.height)?l.width+&quot;:&quot;+l.height:j}b.iasapi.setOptions({aspectRatio:k})})},onSelectStart:function(h,i){imageEdit.setDisabled(a(&quot;#imgedit-crop-sel-&quot;+g),1)},onSelectEnd:function(h,i){imageEdit.setCropSelection(g,i)},onSelectChange:function(h,j){var i=imageEdit.hold.sizer;d.val(imageEdit.round(j.width/i));f.val(imageEdit.round(j.height/i))}})},setCropSelection:function(g,f){var e,b=a(&quot;#imgedit-minthumb-&quot;+g).val()||&quot;128:128&quot;,d=this.hold.sizer;b=b.split(&quot;:&quot;);f=f||0;if(!f||(f.width&lt;3&amp;&amp;f.height&lt;3)){this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),0);this.setDisabled(a(&quot;#imgedit-crop-sel-&quot;+g),0);a(&quot;#imgedit-sel-width-&quot;+g).val(&quot;&quot;);a(&quot;#imgedit-sel-height-&quot;+g).val(&quot;&quot;);a(&quot;#imgedit-selection-&quot;+g).val(&quot;&quot;);return false}if(f.width&lt;(b[0]*d)&amp;&amp;f.height&lt;(b[1]*d)){this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),0);a(&quot;#imgedit-selection-&quot;+g).val(&quot;&quot;);return false}e={x:f.x1,y:f.y1,w:f.width,h:f.height};this.setDisabled(a(&quot;.imgedit-crop&quot;,&quot;#imgedit-panel-&quot;+g),1);a(&quot;#imgedit-selection-&quot;+g).val(JSON.stringify(e))},close:function(c,b){b=b||false;if(b&amp;&amp;this.notsaved(c)){return false}this.iasapi={};this.hold={};a(&quot;#image-editor-&quot;+c).fadeOut(&quot;fast&quot;,function(){a(&quot;#media-head-&quot;+c).fadeIn(&quot;fast&quot;);a(this).empty()})},notsaved:function(e){var c=a(&quot;#imgedit-history-&quot;+e).val(),d=(c!=&quot;&quot;)?JSON.parse(c):new Array(),b=this.intval(a(&quot;#imgedit-undone-&quot;+e).val());if(b&lt;d.length){if(confirm(a(&quot;#imgedit-leaving-&quot;+e).html())){return false}return true}return false},addStep:function(i,h,d){var c=this,e=a(&quot;#imgedit-history-&quot;+h),g=(e.val()!=&quot;&quot;)?JSON.parse(e.val()):new Array(),f=a(&quot;#imgedit-undone-&quot;+h),b=c.intval(f.val());while(b&gt;0){g.pop();b--}f.val(0);g.push(i);e.val(JSON.stringify(g));c.refreshEditor(h,d,function(){c.setDisabled(a(&quot;#image-undo-&quot;+h),true);c.setDisabled(a(&quot;#image-redo-&quot;+h),false)})},rotate:function(d,e,c,b){if(a(b).hasClass(&quot;disabled&quot;)){return false}this.addStep({r:{r:d,fw:this.hold.h,fh:this.hold.w}},e,c)},flip:function(d,e,c,b){if(a(b).hasClass(&quot;disabled&quot;)){return false}this.addStep({f:{f:d,fw:this.hold.w,fh:this.hold.h}},e,c)},crop:function(g,e,c){var f=a(&quot;#imgedit-selection-&quot;+g).val(),b=this.intval(a(&quot;#imgedit-sel-width-&quot;+g).val()),d=this.intval(a(&quot;#imgedit-sel-height-&quot;+g).val());if(a(c).hasClass(&quot;disabled&quot;)||f==&quot;&quot;){return false}f=JSON.parse(f);if(f.w&gt;0&amp;&amp;f.h&gt;0&amp;&amp;b&gt;0&amp;&amp;d&gt;0){f.fw=b;f.fh=d;this.addStep({c:f},g,e)}},undo:function(g,e){var d=this,c=a(&quot;#image-undo-&quot;+g),f=a(&quot;#imgedit-undone-&quot;+g),b=d.intval(f.val())+1;if(c.hasClass(&quot;disabled&quot;)){return}f.val(b);d.refreshEditor(g,e,function(){var h=a(&quot;#imgedit-history-&quot;+g),i=(h.val()!=&quot;&quot;)?JSON.parse(h.val()):new Array();d.setDisabled(a(&quot;#image-redo-&quot;+g),true);d.setDisabled(c,b&lt;i.length)})},redo:function(g,e){var d=this,c=a(&quot;#image-redo-&quot;+g),f=a(&quot;#imgedit-undone-&quot;+g),b=d.intval(f.val())-1;if(c.hasClass(&quot;disabled&quot;)){return}f.val(b);d.refreshEditor(g,e,function(){d.setDisabled(a(&quot;#image-undo-&quot;+g),true);d.setDisabled(c,b&gt;0)})},setNumSelection:function(c){var g,k=a(&quot;#imgedit-sel-width-&quot;+c),j=a(&quot;#imgedit-sel-height-&quot;+c),o=this.intval(k.val()),m=this.intval(j.val()),i=a(&quot;#image-preview-&quot;+c),p=i.height(),h=i.width(),b=this.hold.sizer,f,n,e,l,d=this.iasapi;if(o&lt;1){k.val(&quot;&quot;);return false}if(m&lt;1){j.val(&quot;&quot;);return false}if(o&amp;&amp;m&amp;&amp;(g=d.getSelection())){e=g.x1+Math.round(o*b);l=g.y1+Math.round(m*b);f=g.x1;n=g.y1;if(e&gt;h){f=0;e=h;k.val(Math.round(e/b))}if(l&gt;p){n=0;l=p;j.val(Math.round(l/b))}d.setSelection(f,n,e,l);d.update();this.setCropSelection(c,d.getSelection())}},round:function(b){var c;b=Math.round(b);if(this.hold.sizer&gt;0.6){return b}c=b.toString().slice(-1);if(&quot;1&quot;==c){return b-1}else{if(&quot;9&quot;==c){return b+1}}return b},setRatioSelection:function(j,i,d){var f,e,b=this.intval(a(&quot;#imgedit-crop-width-&quot;+j).val()),g=this.intval(a(&quot;#imgedit-crop-height-&quot;+j).val()),c=a(&quot;#image-preview-&quot;+j).height();if(!this.intval(a(d).val())){a(d).val(&quot;&quot;);return}if(b&amp;&amp;g){this.iasapi.setOptions({aspectRatio:b+&quot;:&quot;+g});if(f=this.iasapi.getSelection(true)){e=Math.ceil(f.y1+((f.x2-f.x1)/(b/g)));if(e&gt;c){e=c;if(i){a(&quot;#imgedit-crop-height-&quot;+j).val(&quot;&quot;)}else{a(&quot;#imgedit-crop-width-&quot;+j).val(&quot;&quot;)}}this.iasapi.setSelection(f.x1,f.y1,f.x2,e);this.iasapi.update()}}}}})(jQuery);
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-includes/post.php        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -68,16 +68,33 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         $file = apply_filters( 'update_attached_file', $file, $attachment_id );
</span><ins>+        $file = _wp_relative_upload_path($file);
</ins><span class="cx"> 
</span><del>-        // Make the file path relative to the upload dir
-        if ( ($uploads = wp_upload_dir()) &amp;&amp; false === $uploads['error'] ) { // Get upload directory
-                if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
-                                $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
-                                $file = ltrim($file, '/');
</del><ins>+        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
+}
+
+/**
+ * Return relative path to an uploaded file.
+ *
+ * The path is relative to the current upload dir.
+ *
+ * @since 2.9
+ * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
+ *
+ * @param string $path Full path to the file
+ * @return string relative path on success, unchanged path on failure.
+ */
+function _wp_relative_upload_path( $path ) {
+        $new_path = $path;
+
+        if ( ($uploads = wp_upload_dir()) &amp;&amp; false === $uploads['error'] ) {
+                if ( 0 === strpos($new_path, $uploads['basedir']) ) {
+                                $new_path = str_replace($uploads['basedir'], '', $new_path);
+                                $new_path = ltrim($new_path, '/');
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
</del><ins>+        return apply_filters( '_wp_relative_upload_path', $new_path, $path );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (12162 => 12163)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2009-11-10 10:38:19 UTC (rev 12162)
+++ trunk/wp-includes/script-loader.php        2009-11-11 11:24:01 UTC (rev 12163)
</span><span class="lines">@@ -369,7 +369,7 @@
</span><span class="cx">                 $scripts-&gt;add( 'codepress', '/wp-includes/js/codepress/codepress.js', false, '0.9.6' );
</span><span class="cx">                 $scripts-&gt;add_data( 'codepress', 'group', 1 );
</span><span class="cx"> 
</span><del>-                $scripts-&gt;add( 'image-edit', &quot;/wp-admin/js/image-edit$suffix.js&quot;, array('jquery', 'json2', 'imgareaselect'), '20090929' );
</del><ins>+                $scripts-&gt;add( 'image-edit', &quot;/wp-admin/js/image-edit$suffix.js&quot;, array('jquery', 'json2', 'imgareaselect'), '20091111' );
</ins><span class="cx">                 $scripts-&gt;add_data( 'image-edit', 'group', 1 );
</span><span class="cx"> 
</span><span class="cx">                 $scripts-&gt;add( 'set-post-thumbnail', &quot;/wp-admin/js/set-post-thumbnail$suffix.js&quot;, array( 'jquery' ), '20091021' );
</span></span></pre>
</div>
</div>

</body>
</html>