<!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, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { 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>[11984] trunk: Image Editor: add load and save image filters,
fix backup sizes meta, see #10528</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11984">11984</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2009-09-30 08:38:32 +0000 (Wed, 30 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Image Editor: add load and save image filters, fix backup sizes meta, see <a href="http://trac.wordpress.org/ticket/10528">#10528</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesimageeditphp">trunk/wp-admin/includes/image-edit.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="#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 (11983 => 11984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image-edit.php        2009-09-29 10:28:08 UTC (rev 11983)
+++ trunk/wp-admin/includes/image-edit.php        2009-09-30 08:38:32 UTC (rev 11984)
</span><span class="lines">@@ -10,21 +10,23 @@
</span><span class="cx">         $nonce = wp_create_nonce("image_editor-$post_id");
</span><span class="cx">         $meta = wp_get_attachment_metadata($post_id);
</span><span class="cx">         $thumb = image_get_intermediate_size($post_id, 'thumbnail');
</span><ins>+        $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
</ins><span class="cx">         $note = '';
</span><span class="cx">
</span><span class="cx">         if ( is_array($meta) && isset($meta['width']) )
</span><span class="cx">                 $big = max( $meta['width'], $meta['height'] );
</span><span class="cx">         else
</span><del>-                wp_die( __('Image data does not exist. Please re-upload the image.') );
</del><ins>+                die( __('Image data does not exist. Please re-upload the image.') );
</ins><span class="cx">
</span><span class="cx">         $sizer = $big > 400 ? 400 / $big : 1;
</span><span class="cx">
</span><span class="cx">         $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
</span><del>-        $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']);
</del><ins>+        $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig'])
+                && $backup_sizes['full-orig']['file'] != basename($meta['file']);
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">         // temp convert backup sizes
</span><del>-        if ( isset($meta['sizes']) && is_array($meta['sizes']) ) {
</del><ins>+        if ( $sub_sizes ) {
</ins><span class="cx">                 $update = false;
</span><span class="cx">                 foreach ( $meta['sizes'] as $name => $val ) {
</span><span class="cx">                         if ( strpos($name, 'backup-') === 0 ) {
</span><span class="lines">@@ -46,7 +48,6 @@
</span><span class="cx">         }
</span><span class="cx">         // end temp
</span><span class="cx">
</span><del>-
</del><span class="cx">         if ( $msg ) {
</span><span class="cx">                 if ( isset($msg->error) )
</span><span class="cx">                         $note = "<div class='error'><p>$msg->error</p></div>";
</span><span class="lines">@@ -168,7 +169,7 @@
</span><span class="cx">         </p>
</span><span class="cx">         </div>
</span><span class="cx">
</span><del>-        <?php if ( $thumb ) {
</del><ins>+        <?php if ( $thumb && $sub_sizes ) {
</ins><span class="cx">                 $thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
</span><span class="cx">         ?>
</span><span class="cx">
</span><span class="lines">@@ -211,28 +212,36 @@
</span><span class="cx"> <?php
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function load_image_to_edit($post, $size = 'full') {
-        $filename = get_attached_file($post->ID);
</del><ins>+function load_image_to_edit($post_id, $mime_type, $size = 'full') {
+        $filepath = get_attached_file($post_id);
</ins><span class="cx">
</span><del>-        if ( 'full' != $size && ( $data = image_get_intermediate_size($post->ID, $size) ) )
-                $filename = path_join( dirname($filename), $data['file'] );
</del><ins>+        if ( $filepath && file_exists($filepath) ) {
+                if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) )
+                        $filepath = path_join( dirname($filepath), $data['file'] );
+        } elseif ( function_exists('fopen') ) {
+                $filepath = wp_get_attachment_url($post_id);
+        }
</ins><span class="cx">
</span><del>-        switch ( $post->post_mime_type ) {
</del><ins>+        $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
+        if ( empty($filepath) )
+                return false;
+
+        switch ( $mime_type ) {
</ins><span class="cx">                 case 'image/jpeg':
</span><del>-                        $image = imagecreatefromjpeg($filename);
</del><ins>+                        $image = imagecreatefromjpeg($filepath);
</ins><span class="cx">                         break;
</span><span class="cx">                 case 'image/png':
</span><del>-                        $image = imagecreatefrompng($filename);
</del><ins>+                        $image = imagecreatefrompng($filepath);
</ins><span class="cx">                         break;
</span><span class="cx">                 case 'image/gif':
</span><del>-                        $image = imagecreatefromgif($filename);
</del><ins>+                        $image = imagecreatefromgif($filepath);
</ins><span class="cx">                         break;
</span><span class="cx">                 default:
</span><span class="cx">                         $image = false;
</span><span class="cx">                         break;
</span><span class="cx">         }
</span><span class="cx">         if ( is_resource($image) ) {
</span><del>-                $image = apply_filters('load_image_to_edit', $image, $post->ID, $size);
</del><ins>+                $image = apply_filters('load_image_to_edit', $image, $post_id, $size);
</ins><span class="cx">                 if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
</span><span class="cx">                         imagealphablending($image, false);
</span><span class="cx">                         imagesavealpha($image, true);
</span><span class="lines">@@ -241,8 +250,8 @@
</span><span class="cx">         return $image;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function wp_stream_image($image, $mime_type, $post_id = 0, $intermediate_size = '') {
-        $image = apply_filters('image_save_pre', $image, $post->ID, $intermediate_size);
</del><ins>+function wp_stream_image($image, $mime_type, $post_id) {
+        $image = apply_filters('image_save_pre', $image, $post_id);
</ins><span class="cx">
</span><span class="cx">         switch ( $mime_type ) {
</span><span class="cx">                 case 'image/jpeg':
</span><span class="lines">@@ -259,8 +268,11 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function wp_save_image_file($filename, $image, $mime_type, $post_id = 0, $intermediate_size = '') {
-        $image = apply_filters('image_save_pre', $image, $post->ID, $intermediate_size);
</del><ins>+function wp_save_image_file($filename, $image, $mime_type, $post_id) {
+        $image = apply_filters('image_save_pre', $image, $post_id);
+        $saved = apply_filters('wp_save_image_file', null, $filename, $image, $mime_type, $post_id);
+        if ( null !== $saved )
+                return $saved;
</ins><span class="cx">
</span><span class="cx">         switch ( $mime_type ) {
</span><span class="cx">                 case 'image/jpeg':
</span><span class="lines">@@ -394,7 +406,7 @@
</span><span class="cx"> function stream_preview_image($post_id) {
</span><span class="cx">         $post = get_post($post_id);
</span><span class="cx">         @ini_set('memory_limit', '256M');
</span><del>-        $img = load_image_to_edit( $post, array(400, 400) );
</del><ins>+        $img = load_image_to_edit( $post_id, $post->post_mime_type, array(400, 400) );
</ins><span class="cx">
</span><span class="cx">         if ( !is_resource($img) )
</span><span class="cx">                 return false;
</span><span class="lines">@@ -439,7 +451,8 @@
</span><span class="cx">                 if ( isset($backup_sizes["$default_size-orig"]) ) {
</span><span class="cx">                         $data = $backup_sizes["$default_size-orig"];
</span><span class="cx">                         if ( 'full' == $default_size ) {
</span><del>-                                $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
</del><ins>+                                if ( $parts['basename'] != $data['file'] )
+                                        $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
</ins><span class="cx">
</span><span class="cx">                                 $meta['file'] = path_join($parts['dirname'], $data['file']);
</span><span class="cx">                                 $meta['width'] = $data['width'];
</span><span class="lines">@@ -449,11 +462,13 @@
</span><span class="cx">                                 $meta['hwstring_small'] = "height='$uheight' width='$uwidth'";
</span><span class="cx">                                 $restored = update_attached_file($post_id, $meta['file']);
</span><span class="cx">                         } else {
</span><del>-                                if ( isset($meta['sizes'][$default_size]) )
</del><ins>+                                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] )
</ins><span class="cx">                                         $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
</span><span class="cx">
</span><span class="cx">                                 $meta['sizes'][$default_size] = $data;
</span><span class="cx">                         }
</span><ins>+                } else {
+                        unset($meta['sizes'][$default_size]);
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -475,7 +490,7 @@
</span><span class="cx">         $success = $delete = $scaled = $nocrop = false;
</span><span class="cx">         $post = get_post($post_id);
</span><span class="cx">         @ini_set('memory_limit', '256M');
</span><del>-        $img = load_image_to_edit($post);
</del><ins>+        $img = load_image_to_edit($post_id, $post->post_mime_type);
</ins><span class="cx">
</span><span class="cx">         if ( !is_resource($img) ) {
</span><span class="cx">                 $return->error = esc_js( __('Unable to create new image.') );
</span><span class="lines">@@ -549,10 +564,18 @@
</span><span class="cx">                 return $return;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ( 'nothumb' == $target || 'all' == $target || $scaled ) {
-                $tag = !isset($backup_sizes['full-orig']) ? 'full-orig' : "full-$suffix";
-                $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
</del><ins>+        if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) {
+                $tag = false;
+                if ( isset($backup_sizes['full-orig']) ) {
+                        if ( $backup_sizes['full-orig']['file'] != $path_parts['basename'] )
+                                $tag = "full-$suffix";
+                } else {
+                        $tag = 'full-orig';
+                }
</ins><span class="cx">
</span><ins>+                if ( $tag )
+                        $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
+
</ins><span class="cx">                 $success = update_attached_file($post_id, $new_path);
</span><span class="cx">                 $meta['file'] = get_attached_file($post_id, true); // get the path unfiltered
</span><span class="cx">                 $meta['width'] = imagesx($img);
</span><span class="lines">@@ -576,9 +599,17 @@
</span><span class="cx">
</span><span class="cx">         if ( isset($sizes) ) {
</span><span class="cx">                 foreach ( $sizes as $size ) {
</span><ins>+                        $tag = false;
</ins><span class="cx">                         if ( isset($meta['sizes'][$size]) ) {
</span><del>-                                $tag = !isset($backup_sizes["$size-orig"]) ? "$size-orig" : "$size-$suffix";
-                                $backup_sizes[$tag] = $meta['sizes'][$size];
</del><ins>+                                if ( isset($backup_sizes["$size-orig"]) ) {
+                                        if ( $backup_sizes["$size-orig"]['file'] != $meta['sizes'][$size]['file'] )
+                                                $tag = "$size-$suffix";
+                                } else {
+                                        $tag = "$size-orig";
+                                }
+
+                                if ( $tag )
+                                        $backup_sizes[$tag] = $meta['sizes'][$size];
</ins><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         $crop = $nocrop ? false : get_option("{$size}_crop");
</span><span class="lines">@@ -595,7 +626,7 @@
</span><span class="cx">                 wp_update_attachment_metadata($post_id, $meta);
</span><span class="cx">                 update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes);
</span><span class="cx">
</span><del>-                if ( $target == 'thumbnail' || $target == 'all' ) {
</del><ins>+                if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) {
</ins><span class="cx">                         if ( $thumb = $meta['sizes']['thumbnail'] ) {
</span><span class="cx">                                 $file_url = wp_get_attachment_url($post_id);
</span><span class="cx">                                 $return->thumbnail = path_join( dirname($file_url), $thumb['file'] );
</span></span></pre></div>
<a id="trunkwpadminjsimageeditdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/image-edit.dev.js (11983 => 11984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/image-edit.dev.js        2009-09-29 10:28:08 UTC (rev 11983)
+++ trunk/wp-admin/js/image-edit.dev.js        2009-09-30 08:38:32 UTC (rev 11984)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx">         },
</span><span class="cx">
</span><span class="cx">         getTarget : function(postid) {
</span><del>-                return $('input:checked', '#imgedit-save-target-' + postid).val() || 'all';
</del><ins>+                return $('input[name=imgedit-target-' + postid + ']:checked', '#imgedit-save-target-' + postid).val() || 'full';
</ins><span class="cx">         },
</span><span class="cx">
</span><span class="cx">         scaleChanged : function(postid, x) {
</span></span></pre></div>
<a id="trunkwpadminjsimageeditjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/image-edit.js (11983 => 11984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/image-edit.js        2009-09-29 10:28:08 UTC (rev 11983)
+++ trunk/wp-admin/js/image-edit.js        2009-09-30 08:38:32 UTC (rev 11984)
</span><span class="lines">@@ -1 +1 @@
</span><del>-var imageEdit;(function(a){imageEdit={iasapi:{},hold:{},postid:"",intval:function(b){return b|0},setDisabled:function(c,b){if(b){c.removeClass("disabled");a("input",c).removeAttr("disabled")}else{c.addClass("disabled");a("input",c).attr("disabled","disabled")}},init:function(g,e){var d=this,c=a("#image-editor-"+d.postid),b=d.intval(a("#imgedit-x-"+g).val()),f=d.intval(a("#imgedit-y-"+g).val());if(d.postid!=g&&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("#imgedit-sizer-"+g).val());d.postid=g;a("#imgedit-response-"+g).empty();a('input[type="text"]',"#imgedit-panel-"+g).keypress(function(i){var h=i.keyCode;if(36<h&&h<41){a(this).blur()}if(13==h){i.preventDefault();i.stopPropagation();return false}})},toggleEditor:function(d,b){var c=a("#imgedit-wait-"+d);if(b){c.height(a("#imgedit-panel-"+d).height()).fadeIn("fast")}else{c.fadeOut("fast")}},toggleHelp:function(b){a(b).siblings(".imgedit-help").slideToggle("fast");return false},getTarget:function(b){return a("input:checked","#imgedit-save-target-"+b).val()||"all"},scaleChanged:function(i,b){var d=a("#imgedit-scale-width-"+i),f=a("#imgedit-scale-height-"+i),g=a("#imgedit-scale-warn-"+i),c="",e="";if(b){e=(d.val()!="")?this.intval(d.val()/this.hold.xy_ratio):"";f.val(e)}else{c=(f.val()!="")?this.intval(f.val()*this.hold.xy_ratio):"";d.val(c)}if((e&&e>this.hold.oh)||(c&&c>this.hold.ow)){g.css("visibility","visible")}else{g.css("visibility","hidden")}},getSelRatio:function(f){var b=this.hold.w,e=this.hold.h,d=this.intval(a("#imgedit-crop-width-"+f).val()),c=this.intval(a("#imgedit-crop-height-"+f).val());if(d&&c){return d+":"+c}if(b&&e){return b+":"+e}return"1:1"},filterHistory:function(j,f){var d=a("#imgedit-history-"+j).val(),b,h,e,c,g=[];if(d!=""){d=JSON.parse(d);b=this.intval(a("#imgedit-undone-"+j).val());if(b>0){while(b>0){d.pop();b--}}if(f){if(!d.length){this.hold.w=this.hold.ow;this.hold.h=this.hold.oh;return""}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("c")){g[h]={c:{x:c.c.x,y:c.c.y,w:c.c.w,h:c.c.h}}}else{if(c.hasOwnProperty("r")){g[h]={r:c.r.r}}else{if(c.hasOwnProperty("f")){g[h]={f:c.f.f}}}}}return JSON.stringify(g)}return""},refreshEditor:function(g,d,f){var c=this,e,b;c.toggleEditor(g,1);e={action:"imgedit-preview",_ajax_nonce:d,postid:g,history:c.filterHistory(g,1),rand:c.intval(Math.random()*1000000)};b=a('<img id="image-preview-'+g+'" />');b.load(function(){var i,h,k=a("#imgedit-crop-"+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>h?h/i:1;j.initCrop(g,b,k);j.setCropSelection(g,0);if((typeof f!="unknown")&&f!=null){f()}j.toggleEditor(g,0)}).attr("src",ajaxurl+"?"+a.param(e))},action:function(b,g,c){var j=this,e,i,f,d,k;if(j.notsaved(b)){return false}e={action:"image-editor",_ajax_nonce:g,postid:b};if("scale"==c){i=a("#imgedit-scale-width-"+b),f=a("#imgedit-scale-height-"+b),d=j.intval(i.val()),k=j.intval(f.val());if(d<1){i.focus();return false}else{if(k<1){f.focus();return false}}if(d==j.hold.ow||k==j.hold.oh){return false}e["do"]="scale";e.fwidth=d;e.fheight=k}else{if("restore"==c){e["do"]="restore"}else{return false}}j.toggleEditor(b,1);a.post(ajaxurl,e,function(h){a("#image-editor-"+b).empty().append(h);j.toggleEditor(b,0)})},save:function(f,b){var c,e=this.getTarget(f),d=this.filterHistory(f,0);if(""==d){return false}this.toggleEditor(f,1);c={action:"image-editor",_ajax_nonce:b,postid:f,history:d,target:e,"do":"save"};a.post(ajaxurl,c,function(h){var g=JSON.parse(h);if(g.error){a("#imgedit-response-"+f).html('<div class="error"><p>'+g.error+"</p><div>");imageEdit.close(f);return}if(g.fw&&g.fh){a("#media-dims-"+f).html(g.fw+" &times; "+g.fh)}if(g.thumbnail){a(".thumbnail","#thumbnail-head-"+f).attr("src",""+g.thumbnail)}if(g.msg){a("#imgedit-response-"+f).html('<div class="updated"><p>'+g.msg+"</p></div>")}imageEdit.close(f)})},open:function(h,d){var f,e=a("#image-editor-"+h),c=a("#media-head-"+h),b=a("#imgedit-open-btn-"+h),g=b.siblings("img");b.attr("disabled","disabled");g.css("visibility","visible");f={action:"image-editor",_ajax_nonce:d,postid:h,"do":"open"};e.load(ajaxurl,f,function(){e.fadeIn("fast");c.fadeOut("fast",function(){b.removeAttr("disabled");g.css("visibility","hidden")})})},imgLoaded:function(d){var b=a("#image-preview-"+d),c=a("#imgedit-crop-"+d);this.initCrop(d,b,c);this.setCropSelection(d,0);this.toggleEditor(d,0)},initCrop:function(g,e,c){var b=this,d=a("#imgedit-sel-width-"+g),f=a("#imgedit-sel-height-"+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&&l.width&&l.height)?l.width+":"+l.height:j}b.iasapi.setOptions({aspectRatio:k})})},onSelectStart:function(h,i){imageEdit.setDisabled(a("#imgedit-crop-sel-"+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("#imgedit-minthumb-"+g).val()||"128:128",d=this.hold.sizer;b=b.split(":");f=f||0;if(!f||(f.width<3&&f.height<3)){this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),0);this.setDisabled(a("#imgedit-crop-sel-"+g),0);a("#imgedit-sel-width-"+g).val("");a("#imgedit-sel-height-"+g).val("");a("#imgedit-selection-"+g).val("");return false}if(f.width<(b[0]*d)&&f.height<(b[1]*d)){this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),0);a("#imgedit-selection-"+g).val("");return false}e={x:f.x1,y:f.y1,w:f.width,h:f.height};this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),1);a("#imgedit-selection-"+g).val(JSON.stringify(e))},close:function(c,b){b=b||false;if(b&&this.notsaved(c)){return false}this.iasapi={};this.hold={};a("#image-editor-"+c).fadeOut("fast",function(){a("#media-head-"+c).fadeIn("fast");a(this).empty()})},notsaved:function(e){var c=a("#imgedit-history-"+e).val(),d=(c!="")?JSON.parse(c):new Array(),b=this.intval(a("#imgedit-undone-"+e).val());if(b<d.length){if(confirm(a("#imgedit-leaving-"+e).html())){return false}return true}return false},addStep:function(i,h,d){var c=this,e=a("#imgedit-history-"+h),g=(e.val()!="")?JSON.parse(e.val()):new Array(),f=a("#imgedit-undone-"+h),b=c.intval(f.val());while(b>0){g.pop();b--}f.val(0);g.push(i);e.val(JSON.stringify(g));c.refreshEditor(h,d,function(){c.setDisabled(a("#image-undo-"+h),true);c.setDisabled(a("#image-redo-"+h),false)})},rotate:function(d,e,c,b){if(a(b).hasClass("disabled")){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("disabled")){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("#imgedit-selection-"+g).val(),b=this.intval(a("#imgedit-sel-width-"+g).val()),d=this.intval(a("#imgedit-sel-height-"+g).val());if(a(c).hasClass("disabled")||f==""){return false}f=JSON.parse(f);if(f.w>0&&f.h>0&&b>0&&d>0){f.fw=b;f.fh=d;this.addStep({c:f},g,e)}},undo:function(g,e){var d=this,c=a("#image-undo-"+g),f=a("#imgedit-undone-"+g),b=d.intval(f.val())+1;if(c.hasClass("disabled")){return}f.val(b);d.refreshEditor(g,e,function(){var h=a("#imgedit-history-"+g),i=(h.val()!="")?JSON.parse(h.val()):new Array();d.setDisabled(a("#image-redo-"+g),true);d.setDisabled(c,b<i.length)})},redo:function(g,e){var d=this,c=a("#image-redo-"+g),f=a("#imgedit-undone-"+g),b=d.intval(f.val())-1;if(c.hasClass("disabled")){return}f.val(b);d.refreshEditor(g,e,function(){d.setDisabled(a("#image-undo-"+g),true);d.setDisabled(c,b>0)})},setNumSelection:function(c){var g,k=a("#imgedit-sel-width-"+c),j=a("#imgedit-sel-height-"+c),o=this.intval(k.val()),m=this.intval(j.val()),i=a("#image-preview-"+c),p=i.height(),h=i.width(),b=this.hold.sizer,f,n,e,l,d=this.iasapi;if(o<1){k.val("");return false}if(m<1){j.val("");return false}if(o&&m&&(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>h){f=0;e=h;k.val(Math.round(e/b))}if(l>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>0.6){return b}c=b.toString().slice(-1);if("1"==c){return b-1}else{if("9"==c){return b+1}}return b},setRatioSelection:function(j,i,d){var f,e,b=this.intval(a("#imgedit-crop-width-"+j).val()),g=this.intval(a("#imgedit-crop-height-"+j).val()),c=a("#image-preview-"+j).height();if(!this.intval(a(d).val())){a(d).val("");return}if(b&&g){this.iasapi.setOptions({aspectRatio:b+":"+g});if(f=this.iasapi.getSelection(true)){e=Math.ceil(f.y1+((f.x2-f.x1)/(b/g)));if(e>c){e=c;if(i){a("#imgedit-crop-height-"+j).val("")}else{a("#imgedit-crop-width-"+j).val("")}}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:"",intval:function(b){return b|0},setDisabled:function(c,b){if(b){c.removeClass("disabled");a("input",c).removeAttr("disabled")}else{c.addClass("disabled");a("input",c).attr("disabled","disabled")}},init:function(g,e){var d=this,c=a("#image-editor-"+d.postid),b=d.intval(a("#imgedit-x-"+g).val()),f=d.intval(a("#imgedit-y-"+g).val());if(d.postid!=g&&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("#imgedit-sizer-"+g).val());d.postid=g;a("#imgedit-response-"+g).empty();a('input[type="text"]',"#imgedit-panel-"+g).keypress(function(i){var h=i.keyCode;if(36<h&&h<41){a(this).blur()}if(13==h){i.preventDefault();i.stopPropagation();return false}})},toggleEditor:function(d,b){var c=a("#imgedit-wait-"+d);if(b){c.height(a("#imgedit-panel-"+d).height()).fadeIn("fast")}else{c.fadeOut("fast")}},toggleHelp:function(b){a(b).siblings(".imgedit-help").slideToggle("fast");return false},getTarget:function(b){return a("input[name=imgedit-target-"+b+"]:checked","#imgedit-save-target-"+b).val()||"full"},scaleChanged:function(i,b){var d=a("#imgedit-scale-width-"+i),f=a("#imgedit-scale-height-"+i),g=a("#imgedit-scale-warn-"+i),c="",e="";if(b){e=(d.val()!="")?this.intval(d.val()/this.hold.xy_ratio):"";f.val(e)}else{c=(f.val()!="")?this.intval(f.val()*this.hold.xy_ratio):"";d.val(c)}if((e&&e>this.hold.oh)||(c&&c>this.hold.ow)){g.css("visibility","visible")}else{g.css("visibility","hidden")}},getSelRatio:function(f){var b=this.hold.w,e=this.hold.h,d=this.intval(a("#imgedit-crop-width-"+f).val()),c=this.intval(a("#imgedit-crop-height-"+f).val());if(d&&c){return d+":"+c}if(b&&e){return b+":"+e}return"1:1"},filterHistory:function(j,f){var d=a("#imgedit-history-"+j).val(),b,h,e,c,g=[];if(d!=""){d=JSON.parse(d);b=this.intval(a("#imgedit-undone-"+j).val());if(b>0){while(b>0){d.pop();b--}}if(f){if(!d.length){this.hold.w=this.hold.ow;this.hold.h=this.hold.oh;return""}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("c")){g[h]={c:{x:c.c.x,y:c.c.y,w:c.c.w,h:c.c.h}}}else{if(c.hasOwnProperty("r")){g[h]={r:c.r.r}}else{if(c.hasOwnProperty("f")){g[h]={f:c.f.f}}}}}return JSON.stringify(g)}return""},refreshEditor:function(g,d,f){var c=this,e,b;c.toggleEditor(g,1);e={action:"imgedit-preview",_ajax_nonce:d,postid:g,history:c.filterHistory(g,1),rand:c.intval(Math.random()*1000000)};b=a('<img id="image-preview-'+g+'" />');b.load(function(){var i,h,k=a("#imgedit-crop-"+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>h?h/i:1;j.initCrop(g,b,k);j.setCropSelection(g,0);if((typeof f!="unknown")&&f!=null){f()}j.toggleEditor(g,0)}).attr("src",ajaxurl+"?"+a.param(e))},action:function(b,g,c){var j=this,e,i,f,d,k;if(j.notsaved(b)){return false}e={action:"image-editor",_ajax_nonce:g,postid:b};if("scale"==c){i=a("#imgedit-scale-width-"+b),f=a("#imgedit-scale-height-"+b),d=j.intval(i.val()),k=j.intval(f.val());if(d<1){i.focus();return false}else{if(k<1){f.focus();return false}}if(d==j.hold.ow||k==j.hold.oh){return false}e["do"]="scale";e.fwidth=d;e.fheight=k}else{if("restore"==c){e["do"]="restore"}else{return false}}j.toggleEditor(b,1);a.post(ajaxurl,e,function(h){a("#image-editor-"+b).empty().append(h);j.toggleEditor(b,0)})},save:function(f,b){var c,e=this.getTarget(f),d=this.filterHistory(f,0);if(""==d){return false}this.toggleEditor(f,1);c={action:"image-editor",_ajax_nonce:b,postid:f,history:d,target:e,"do":"save"};a.post(ajaxurl,c,function(h){var g=JSON.parse(h);if(g.error){a("#imgedit-response-"+f).html('<div class="error"><p>'+g.error+"</p><div>");imageEdit.close(f);return}if(g.fw&&g.fh){a("#media-dims-"+f).html(g.fw+" &times; "+g.fh)}if(g.thumbnail){a(".thumbnail","#thumbnail-head-"+f).attr("src",""+g.thumbnail)}if(g.msg){a("#imgedit-response-"+f).html('<div class="updated"><p>'+g.msg+"</p></div>")}imageEdit.close(f)})},open:function(h,d){var f,e=a("#image-editor-"+h),c=a("#media-head-"+h),b=a("#imgedit-open-btn-"+h),g=b.siblings("img");b.attr("disabled","disabled");g.css("visibility","visible");f={action:"image-editor",_ajax_nonce:d,postid:h,"do":"open"};e.load(ajaxurl,f,function(){e.fadeIn("fast");c.fadeOut("fast",function(){b.removeAttr("disabled");g.css("visibility","hidden")})})},imgLoaded:function(d){var b=a("#image-preview-"+d),c=a("#imgedit-crop-"+d);this.initCrop(d,b,c);this.setCropSelection(d,0);this.toggleEditor(d,0)},initCrop:function(g,e,c){var b=this,d=a("#imgedit-sel-width-"+g),f=a("#imgedit-sel-height-"+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&&l.width&&l.height)?l.width+":"+l.height:j}b.iasapi.setOptions({aspectRatio:k})})},onSelectStart:function(h,i){imageEdit.setDisabled(a("#imgedit-crop-sel-"+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("#imgedit-minthumb-"+g).val()||"128:128",d=this.hold.sizer;b=b.split(":");f=f||0;if(!f||(f.width<3&&f.height<3)){this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),0);this.setDisabled(a("#imgedit-crop-sel-"+g),0);a("#imgedit-sel-width-"+g).val("");a("#imgedit-sel-height-"+g).val("");a("#imgedit-selection-"+g).val("");return false}if(f.width<(b[0]*d)&&f.height<(b[1]*d)){this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),0);a("#imgedit-selection-"+g).val("");return false}e={x:f.x1,y:f.y1,w:f.width,h:f.height};this.setDisabled(a(".imgedit-crop","#imgedit-panel-"+g),1);a("#imgedit-selection-"+g).val(JSON.stringify(e))},close:function(c,b){b=b||false;if(b&&this.notsaved(c)){return false}this.iasapi={};this.hold={};a("#image-editor-"+c).fadeOut("fast",function(){a("#media-head-"+c).fadeIn("fast");a(this).empty()})},notsaved:function(e){var c=a("#imgedit-history-"+e).val(),d=(c!="")?JSON.parse(c):new Array(),b=this.intval(a("#imgedit-undone-"+e).val());if(b<d.length){if(confirm(a("#imgedit-leaving-"+e).html())){return false}return true}return false},addStep:function(i,h,d){var c=this,e=a("#imgedit-history-"+h),g=(e.val()!="")?JSON.parse(e.val()):new Array(),f=a("#imgedit-undone-"+h),b=c.intval(f.val());while(b>0){g.pop();b--}f.val(0);g.push(i);e.val(JSON.stringify(g));c.refreshEditor(h,d,function(){c.setDisabled(a("#image-undo-"+h),true);c.setDisabled(a("#image-redo-"+h),false)})},rotate:function(d,e,c,b){if(a(b).hasClass("disabled")){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("disabled")){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("#imgedit-selection-"+g).val(),b=this.intval(a("#imgedit-sel-width-"+g).val()),d=this.intval(a("#imgedit-sel-height-"+g).val());if(a(c).hasClass("disabled")||f==""){return false}f=JSON.parse(f);if(f.w>0&&f.h>0&&b>0&&d>0){f.fw=b;f.fh=d;this.addStep({c:f},g,e)}},undo:function(g,e){var d=this,c=a("#image-undo-"+g),f=a("#imgedit-undone-"+g),b=d.intval(f.val())+1;if(c.hasClass("disabled")){return}f.val(b);d.refreshEditor(g,e,function(){var h=a("#imgedit-history-"+g),i=(h.val()!="")?JSON.parse(h.val()):new Array();d.setDisabled(a("#image-redo-"+g),true);d.setDisabled(c,b<i.length)})},redo:function(g,e){var d=this,c=a("#image-redo-"+g),f=a("#imgedit-undone-"+g),b=d.intval(f.val())-1;if(c.hasClass("disabled")){return}f.val(b);d.refreshEditor(g,e,function(){d.setDisabled(a("#image-undo-"+g),true);d.setDisabled(c,b>0)})},setNumSelection:function(c){var g,k=a("#imgedit-sel-width-"+c),j=a("#imgedit-sel-height-"+c),o=this.intval(k.val()),m=this.intval(j.val()),i=a("#image-preview-"+c),p=i.height(),h=i.width(),b=this.hold.sizer,f,n,e,l,d=this.iasapi;if(o<1){k.val("");return false}if(m<1){j.val("");return false}if(o&&m&&(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>h){f=0;e=h;k.val(Math.round(e/b))}if(l>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>0.6){return b}c=b.toString().slice(-1);if("1"==c){return b-1}else{if("9"==c){return b+1}}return b},setRatioSelection:function(j,i,d){var f,e,b=this.intval(a("#imgedit-crop-width-"+j).val()),g=this.intval(a("#imgedit-crop-height-"+j).val()),c=a("#image-preview-"+j).height();if(!this.intval(a(d).val())){a(d).val("");return}if(b&&g){this.iasapi.setOptions({aspectRatio:b+":"+g});if(f=this.iasapi.getSelection(true)){e=Math.ceil(f.y1+((f.x2-f.x1)/(b/g)));if(e>c){e=c;if(i){a("#imgedit-crop-height-"+j).val("")}else{a("#imgedit-crop-width-"+j).val("")}}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="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (11983 => 11984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2009-09-29 10:28:08 UTC (rev 11983)
+++ trunk/wp-includes/script-loader.php        2009-09-30 08:38:32 UTC (rev 11984)
</span><span class="lines">@@ -405,7 +405,7 @@
</span><span class="cx">                 $scripts->add( 'codepress', '/wp-includes/js/codepress/codepress.js', false, '0.9.6' );
</span><span class="cx">                 $scripts->add_data( 'codepress', 'group', 1 );
</span><span class="cx">
</span><del>-                $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090925' );
</del><ins>+                $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090929' );
</ins><span class="cx">                 $scripts->add_data( 'image-edit', 'group', 1 );
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>