]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/image-edit.php
WordPress 3.8.3
[autoinstalls/wordpress.git] / wp-admin / includes / image-edit.php
index 01bce7bd97208134a9b0ad121d3d362f24f054e6..f25546e5e7ed6b95ee118ee52da0506536a2752a 100644 (file)
@@ -13,7 +13,7 @@ function wp_image_editor($post_id, $msg = false) {
        $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
        $note = '';
 
-       if ( is_array($meta) && isset($meta['width']) )
+       if ( isset( $meta['width'], $meta['height'] ) )
                $big = max( $meta['width'], $meta['height'] );
        else
                die( __('Image data does not exist. Please re-upload the image.') );
@@ -21,8 +21,9 @@ function wp_image_editor($post_id, $msg = false) {
        $sizer = $big > 400 ? 400 / $big : 1;
 
        $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
-       $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig'])
-               && $backup_sizes['full-orig']['file'] != basename($meta['file']);
+       $can_restore = false;
+       if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) )
+               $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
 
        if ( $msg ) {
                if ( isset($msg->error) )
@@ -63,8 +64,8 @@ function wp_image_editor($post_id, $msg = false) {
        <input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
        <input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
        <input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
-       <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width']; ?>" />
-       <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height']; ?>" />
+       <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
+       <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
 
        <div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
        <img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" />
@@ -81,10 +82,12 @@ function wp_image_editor($post_id, $msg = false) {
        <div class="imgedit-group-top">
                <a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Scale Image'); ?></strong></a>
                <div class="imgedit-help">
-               <p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?></p>
+               <p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that images can only be scaled down, not up.'); ?></p>
+               <?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
                <p><?php printf( __('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height'] ); ?></p>
+               <?php endif ?>
                <div class="imgedit-submit">
-               <span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo $meta['width']; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo $meta['height']; ?>" />
+               <span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />&times;<input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
                <span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span>
                <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
                </div>
@@ -256,6 +259,7 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
 
                switch ( $mime_type ) {
                        case 'image/jpeg':
+                               /** This filter is documented in wp-includes/class-wp-image-editor.php */
                                return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
                        case 'image/png':
                                return imagepng( $image, $filename );
@@ -454,7 +458,7 @@ function stream_preview_image( $post_id ) {
     if ( is_wp_error( $img ) )
         return false;
 
-       $changes = !empty($_REQUEST['history']) ? json_decode( stripslashes($_REQUEST['history']) ) : null;
+       $changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null;
        if ( $changes )
                $img = image_edit_apply_changes( $img, $changes );
 
@@ -464,8 +468,8 @@ function stream_preview_image( $post_id ) {
        $h = $size['height'];
 
        $ratio = _image_get_preview_ratio( $w, $h );
-       $w2 = $w * $ratio;
-       $h2 = $h * $ratio;
+       $w2 = max ( 1, $w * $ratio );
+       $h2 = max ( 1, $h * $ratio );
 
        if ( is_wp_error( $img->resize( $w2, $h2 ) ) )
                return false;
@@ -496,10 +500,11 @@ function wp_restore_image($post_id) {
                        if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
                                // delete only if it's edited image
                                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
+                                       /** This filter is documented in wp-admin/custom-header.php */
                                        $delpath = apply_filters('wp_delete_file', $file);
                                        @unlink($delpath);
                                }
-                       } else {
+                       } elseif ( isset( $meta['width'], $meta['height'] ) ) {
                                $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
                        }
                }
@@ -519,6 +524,7 @@ function wp_restore_image($post_id) {
                                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
                                        // delete only if it's edited image
                                        if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
+                                               /** This filter is documented in wp-admin/custom-header.php */
                                                $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
                                                @unlink($delpath);
                                        }
@@ -587,7 +593,7 @@ function wp_save_image( $post_id ) {
                        return $return;
                }
        } elseif ( !empty($_REQUEST['history']) ) {
-               $changes = json_decode( stripslashes($_REQUEST['history']) );
+               $changes = json_decode( wp_unslash($_REQUEST['history']) );
                if ( $changes )
                        $img = image_edit_apply_changes($img, $changes);
        } else {
@@ -719,6 +725,7 @@ function wp_save_image( $post_id ) {
        }
 
        if ( $delete ) {
+               /** This filter is documented in wp-admin/custom-header.php */
                $delpath = apply_filters('wp_delete_file', $new_path);
                @unlink( $delpath );
        }