WordPress.org

Make WordPress Core

Changeset 12163


Ignore:
Timestamp:
11/11/09 11:24:01 (4 years ago)
Author:
azaozz
Message:

Fix image meta after editing image, disable the Save button when no changes, fixes #11115

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/image-edit.php

    r12155 r12163  
    6969    <div class="imgedit-submit"> 
    7070        <input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button" value="<?php echo esc_attr__( 'Cancel' ); ?>" /> 
    71         <input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" class="button-primary imgedit-submit-btn" value="<?php echo esc_attr__( 'Save' ); ?>" /> 
     71        <input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button-primary imgedit-submit-btn" value="<?php echo esc_attr__( 'Save' ); ?>" /> 
    7272    </div> 
    7373    </td> 
     
    9393        <a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Restore Original Image'); ?></strong></a> 
    9494        <div class="imgedit-help"> 
    95         <p><?php _e('Discard any changes and restore the original image. Previously edited copies of the image will not be deleted.'); ?></p> 
     95        <p><?php _e('Discard any changes and restore the original image.');  
     96 
     97        if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) 
     98            _e(' Previously edited copies of the image will not be deleted.'); 
     99 
     100        ?></p> 
    96101        <div class="imgedit-submit"> 
    97102        <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'restore')" class="button-primary" value="<?php echo esc_attr__( 'Restore image' ); ?>" <?php echo $can_restore; ?> /> 
     
    410415function wp_restore_image($post_id) { 
    411416    $meta = wp_get_attachment_metadata($post_id); 
     417    $file = get_attached_file($post_id); 
    412418    $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); 
    413419    $restored = false; 
     
    419425    } 
    420426 
    421     $parts = pathinfo($meta['file']); 
     427    $parts = pathinfo($file); 
    422428    $suffix = time() . rand(100, 999); 
    423429    $default_sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') ); 
    424     $default_sizes[] = 'full'; 
     430 
     431    if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) { 
     432        $data = $backup_sizes['full-orig']; 
     433 
     434        if ( $parts['basename'] != $data['file'] ) { 
     435            if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { 
     436                // delete only if it's edited image 
     437                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) { 
     438                    $delpath = apply_filters('wp_delete_file', $file); 
     439                    @unlink($delpath); 
     440                } 
     441            } else { 
     442                $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); 
     443            } 
     444        } 
     445 
     446        $restored_file = path_join($parts['dirname'], $data['file']); 
     447        $restored = update_attached_file($post_id, $restored_file); 
     448 
     449        $meta['file'] = _wp_relative_upload_path( $restored_file ); 
     450        $meta['width'] = $data['width']; 
     451        $meta['height'] = $data['height']; 
     452        list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']); 
     453        $meta['hwstring_small'] = "height='$uheight' width='$uwidth'"; 
     454    } 
    425455 
    426456    foreach ( $default_sizes as $default_size ) { 
    427457        if ( isset($backup_sizes["$default_size-orig"]) ) { 
    428458            $data = $backup_sizes["$default_size-orig"]; 
    429             if ( 'full' == $default_size ) { 
    430                 if ( $parts['basename'] != $data['file'] ) { 
    431                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { 
    432                         // delete only if it's edited image 
    433                         if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) { 
    434                             $delpath = apply_filters('wp_delete_file', $meta['file']); 
    435                             @unlink($delpath); 
    436                         } 
    437                     } else { 
    438                         $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); 
     459            if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) { 
     460                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { 
     461                    // delete only if it's edited image 
     462                    if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) { 
     463                        $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) ); 
     464                        @unlink($delpath); 
    439465                    } 
     466                } else { 
     467                    $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size]; 
    440468                } 
    441  
    442                 $meta['file'] = path_join($parts['dirname'], $data['file']); 
    443                 $meta['width'] = $data['width']; 
    444                 $meta['height'] = $data['height']; 
    445  
    446                 list ( $uwidth, $uheight ) = wp_shrink_dimensions($meta['width'], $meta['height']); 
    447                 $meta['hwstring_small'] = "height='$uheight' width='$uwidth'"; 
    448                 $restored = update_attached_file($post_id, $meta['file']); 
    449             } else { 
    450                 if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) { 
    451                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { 
    452                         // delete only if it's edited image 
    453                         if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) { 
    454                             $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) ); 
    455                             @unlink($delpath); 
    456                         } 
    457                     } else { 
    458                         $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size]; 
    459                     } 
    460                 } 
    461  
    462                 $meta['sizes'][$default_size] = $data; 
    463469            } 
     470 
     471            $meta['sizes'][$default_size] = $data; 
    464472        } else { 
    465473            unset($meta['sizes'][$default_size]); 
     
    581589 
    582590        $success = update_attached_file($post_id, $new_path); 
    583         $meta['file'] = get_attached_file($post_id, true); // get the path unfiltered 
     591 
     592        $meta['file'] = _wp_relative_upload_path($new_path); 
    584593        $meta['width'] = imagesx($img); 
    585594        $meta['height'] = imagesy($img); 
  • trunk/wp-admin/includes/image.php

    r11911 r12163  
    8989    $metadata = array(); 
    9090    if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { 
    91         $full_path_file = $file; 
    92         $imagesize = getimagesize( $full_path_file ); 
     91        $imagesize = getimagesize( $file ); 
    9392        $metadata['width'] = $imagesize[0]; 
    9493        $metadata['height'] = $imagesize[1]; 
     
    9796 
    9897        // Make the file path relative to the upload dir 
    99         if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory 
    100             if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path 
    101                 $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path 
    102                 $file = ltrim($file, '/'); 
    103             } 
    104         } 
    105         $metadata['file'] = $file; 
     98        $metadata['file'] = _wp_relative_upload_path($file); 
    10699 
    107100        // make thumbnails and other intermediate sizes 
    108         $sizes = array('thumbnail', 'medium', 'large'); 
    109         $sizes = apply_filters('intermediate_image_sizes', $sizes); 
     101        $sizes = apply_filters( 'intermediate_image_sizes', array('thumbnail', 'medium', 'large') ); 
    110102 
    111103        foreach ($sizes as $size) { 
    112             $resized = image_make_intermediate_size( $full_path_file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") ); 
     104            $resized = image_make_intermediate_size( $file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") ); 
    113105            if ( $resized ) 
    114106                $metadata['sizes'][$size] = $resized; 
     
    116108 
    117109        // fetch additional metadata from exif/iptc 
    118         $image_meta = wp_read_image_metadata( $full_path_file ); 
    119         if ($image_meta) 
     110        $image_meta = wp_read_image_metadata( $file ); 
     111        if ( $image_meta ) 
    120112            $metadata['image_meta'] = $image_meta; 
    121113 
  • trunk/wp-admin/js/image-edit.dev.js

    r11984 r12163  
    176176                callback(); 
    177177 
     178            if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 ) 
     179                $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled'); 
     180            else 
     181                $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).attr('disabled', 'disabled'); 
     182 
    178183            t.toggleEditor(postid, 0); 
    179184        }).attr('src', ajaxurl + '?' + $.param(data)); 
  • trunk/wp-admin/js/image-edit.js

    r11984 r12163  
    1 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); 
     1var 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()}if(a("#imgedit-history-"+g).val()&&a("#imgedit-undone-"+g).val()==0){a("input.imgedit-submit-btn","#imgedit-panel-"+g).removeAttr("disabled")}else{a("input.imgedit-submit-btn","#imgedit-panel-"+g).attr("disabled","disabled")}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); 
  • trunk/wp-includes/post.php

    r12158 r12163  
    6969 
    7070    $file = apply_filters( 'update_attached_file', $file, $attachment_id ); 
    71  
    72     // Make the file path relative to the upload dir 
    73     if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory 
    74         if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path 
    75                 $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path 
    76                 $file = ltrim($file, '/'); 
    77         } 
    78     } 
     71    $file = _wp_relative_upload_path($file); 
    7972 
    8073    return update_post_meta( $attachment_id, '_wp_attached_file', $file ); 
     74} 
     75 
     76/** 
     77 * Return relative path to an uploaded file. 
     78 * 
     79 * The path is relative to the current upload dir. 
     80 * 
     81 * @since 2.9 
     82 * @uses apply_filters() Calls '_wp_relative_upload_path' on file path. 
     83 * 
     84 * @param string $path Full path to the file 
     85 * @return string relative path on success, unchanged path on failure. 
     86 */ 
     87function _wp_relative_upload_path( $path ) { 
     88    $new_path = $path; 
     89 
     90    if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { 
     91        if ( 0 === strpos($new_path, $uploads['basedir']) ) { 
     92                $new_path = str_replace($uploads['basedir'], '', $new_path); 
     93                $new_path = ltrim($new_path, '/'); 
     94        } 
     95    } 
     96 
     97    return apply_filters( '_wp_relative_upload_path', $new_path, $path ); 
    8198} 
    8299 
  • trunk/wp-includes/script-loader.php

    r12162 r12163  
    370370        $scripts->add_data( 'codepress', 'group', 1 ); 
    371371 
    372         $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20090929' ); 
     372        $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20091111' ); 
    373373        $scripts->add_data( 'image-edit', 'group', 1 ); 
    374374 
Note: See TracChangeset for help on using the changeset viewer.