Ticket #22356: 22356.8.diff
File 22356.8.diff, 18.2 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/media.php
diff --git wp-admin/includes/media.php wp-admin/includes/media.php index 6cc1b63..4b921b1 100644
function get_media_item( $attachment_id, $args = null ) { 1122 1122 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); 1123 1123 1124 1124 $image_edit_button = ''; 1125 if ( gd_edit_image_support( $post->post_mime_type) ) {1125 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { 1126 1126 $nonce = wp_create_nonce( "image_editor-$post->ID" ); 1127 1127 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; 1128 1128 } … … function edit_form_image_editor() { 2254 2254 $att_url = wp_get_attachment_url( $post->ID ); 2255 2255 2256 2256 $image_edit_button = ''; 2257 if ( gd_edit_image_support( $post->post_mime_type) ) {2257 if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { 2258 2258 $nonce = wp_create_nonce( "image_editor-$post->ID" ); 2259 2259 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; 2260 2260 } -
wp-includes/class-wp-image-editor-gd.php
diff --git wp-includes/class-wp-image-editor-gd.php wp-includes/class-wp-image-editor-gd.php index ca76006..78e186e 100644
12 12 * @since 3.5.0 13 13 * @package WordPress 14 14 * @subpackage Image_Editor 15 * @uses WP_Image_Editor Extends class16 15 */ 17 16 class WP_Image_Editor_GD extends WP_Image_Editor { 17 18 18 protected $image = false; // GD Resource 19 19 20 20 function __destruct() { … … class WP_Image_Editor_GD extends WP_Image_Editor { 32 32 * 33 33 * @return boolean 34 34 */ 35 public static function test( $args = null) {35 public static function test( $args = array() ) { 36 36 if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) 37 37 return false; 38 38 39 if ( isset( $args['mime_type'] ) && !self::supports_mime_type( $args['mime_type'] ) ) 40 return false; 41 39 42 return true; 40 43 } 41 44 42 45 /** 46 * Checks to see if editor supports the mime-type specified. 47 * 48 * @since 3.5.0 49 * @access public 50 * 51 * @param string $mime_type 52 * @return boolean 53 */ 54 protected static function supports_mime_type( $mime_type ) { 55 $image_types = imagetypes(); 56 switch( $mime_type ) { 57 case 'image/jpeg': 58 return ($image_types & IMG_JPG) != 0; 59 case 'image/png': 60 return ($image_types & IMG_PNG) != 0; 61 case 'image/gif': 62 return ($image_types & IMG_GIF) != 0; 63 } 64 65 return false; 66 } 67 68 /** 43 69 * Loads image from $this->file into new GD Resource. 44 70 * 45 71 * @since 3.5.0 … … class WP_Image_Editor_GD extends WP_Image_Editor { 47 73 * 48 74 * @return boolean|\WP_Error 49 75 */ 50 p rotectedfunction load() {76 public function load() { 51 77 if ( $this->image ) 52 78 return true; 53 79 … … class WP_Image_Editor_GD extends WP_Image_Editor { 91 117 } 92 118 93 119 /** 94 * Checks to see if editor supports the mime-type specified.95 *96 * @since 3.5.097 * @access public98 *99 * @param string $mime_type100 * @return boolean101 */102 public static function supports_mime_type( $mime_type ) {103 $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' );104 105 return in_array( $mime_type, $allowed_mime_types );106 }107 108 /**109 120 * Resizes current image. 110 121 * Wraps _resize, since _resize returns a GD Resource. 111 122 * … … class WP_Image_Editor_GD extends WP_Image_Editor { 261 272 * @since 3.5.0 262 273 * @access public 263 274 * 264 * @param boolean $horz Horizon al Flip275 * @param boolean $horz Horizontal Flip 265 276 * @param boolean $vert Vertical Flip 266 277 * @returns boolean|WP_Error 267 278 */ … … class WP_Image_Editor_GD extends WP_Image_Editor { 369 380 return imagejpeg( $this->image, null, $this->quality ); 370 381 } 371 382 } 372 } 373 No newline at end of file 383 } -
wp-includes/class-wp-image-editor-imagick.php
diff --git wp-includes/class-wp-image-editor-imagick.php wp-includes/class-wp-image-editor-imagick.php index 601b99b..8f6feef 100644
12 12 * @since 3.5.0 13 13 * @package WordPress 14 14 * @subpackage Image_Editor 15 * @uses WP_Image_Editor Extends class16 15 */ 17 16 class WP_Image_Editor_Imagick extends WP_Image_Editor { 17 18 18 protected $image = null; // Imagick Object 19 19 20 20 function __destruct() { … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 36 36 * 37 37 * @return boolean 38 38 */ 39 public static function test( $args = null) {39 public static function test( $args = array() ) { 40 40 if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) ) 41 41 return false; 42 42 43 if ( isset( $args['mime_type'] ) && !self::supports_mime_type( $args['mime_type'] ) ) 44 return false; 45 43 46 return true; 44 47 } 45 48 46 49 /** 50 * Checks to see if editor supports the mime-type specified. 51 * 52 * @since 3.5.0 53 * @access public 54 * 55 * @param string $mime_type 56 * @return boolean 57 */ 58 protected static function supports_mime_type( $mime_type ) { 59 $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); 60 61 if ( ! $imagick_extension ) 62 return false; 63 64 try { 65 return ( (bool) Imagick::queryFormats( $imagick_extension ) ); 66 } 67 catch ( Exception $e ) { 68 return false; 69 } 70 } 71 72 /** 47 73 * Loads image from $this->file into new Imagick Object. 48 74 * 49 75 * @since 3.5.0 … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 51 77 * 52 78 * @return boolean|WP_Error True if loaded; WP_Error on failure. 53 79 */ 54 p rotectedfunction load() {80 public function load() { 55 81 if ( $this->image ) 56 82 return true; 57 83 … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 138 164 } 139 165 140 166 /** 141 * Checks to see if editor supports the mime-type specified.142 *143 * @since 3.5.0144 * @access public145 *146 * @param string $mime_type147 * @return boolean148 */149 public static function supports_mime_type( $mime_type ) {150 if ( ! $mime_type )151 return false;152 153 $imagick_extension = strtoupper( self::get_extension( $mime_type ) );154 155 try {156 return ( (bool) Imagick::queryFormats( $imagick_extension ) );157 }158 catch ( Exception $e ) {159 return false;160 }161 }162 163 /**164 167 * Resizes current image. 165 168 * 166 169 * @since 3.5.0 … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 312 315 * @since 3.5.0 313 316 * @access public 314 317 * 315 * @param boolean $horz Horizon al Flip318 * @param boolean $horz Horizontal Flip 316 319 * @param boolean $vert Vertical Flip 317 320 * @returns boolean|WP_Error 318 321 */ -
wp-includes/class-wp-image-editor.php
diff --git wp-includes/class-wp-image-editor.php wp-includes/class-wp-image-editor.php index 920e4a4..695d02a 100644
7 7 */ 8 8 9 9 /** 10 * Base WordPress Image Editor class for which Editorimplementations extend10 * Base image editor class from which implementations extend 11 11 * 12 12 * @since 3.5.0 13 13 */ 14 14 abstract class WP_Image_Editor { 15 15 16 protected $file = null; 16 17 protected $size = null; 17 protected $mime_type 18 protected $mime_type = null; 18 19 protected $default_mime_type = 'image/jpeg'; 19 20 protected $quality = 90; 20 21 21 protected function __construct( $filename ) {22 $this->file = $filename;23 }24 25 22 /** 26 * Returns a WP_Image_Editor instance and loads file into it. 23 * Checks to see if current environment supports the editor chosen. 24 * Must be overridden in a sub-class. 27 25 * 28 26 * @since 3.5.0 29 27 * @access public 28 * @abstract 30 29 * 31 * @param string $path Path to File to Load 32 * @param array $required_methods Methods to require in implementation 33 * @return WP_Image_Editor|WP_Error 30 * @param array $args 31 * @return boolean 34 32 */ 35 public final static function get_instance( $path = null, $required_methods = null ) { 36 $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $required_methods ), $path ); 37 38 if ( $implementation ) { 39 $editor = new $implementation( $path ); 40 $loaded = $editor->load(); 41 42 if ( is_wp_error( $loaded ) ) 43 return $loaded; 44 45 return $editor; 46 } 47 48 return new WP_Error( 'no_editor', __('No editor could be selected') ); 33 public static function test( $args = array() ) { 34 return false; 49 35 } 50 36 51 37 /** 52 * Tests which editors are capable of supporting the request. 53 * 54 * @since 3.5.0 55 * @access private 56 * 57 * @param array $required_methods String array of all methods required for implementation returned. 58 * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 38 * Each instance handles a single file. 59 39 */ 60 private final static function choose_implementation( $required_methods = null ) { 61 $request_order = apply_filters( 'wp_image_editors', 62 array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 63 64 if ( ! $required_methods ) 65 $required_methods = array(); 66 67 // Loop over each editor on each request looking for one which will serve this request's needs 68 foreach ( $request_order as $editor ) { 69 // Check to see if this editor is a possibility, calls the editor statically 70 if ( ! call_user_func( array( $editor, 'test' ) ) ) 71 continue; 72 73 // Make sure that all methods are supported by editor. 74 if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) 75 continue; 76 77 return $editor; 78 } 79 return false; 40 public function __construct( $file ) { 41 $this->file = $file; 80 42 } 81 43 82 44 /** … … abstract class WP_Image_Editor { 88 50 * 89 51 * @return boolean|WP_Error True if loaded; WP_Error on failure. 90 52 */ 91 abstract p rotectedfunction load();53 abstract public function load(); 92 54 93 55 /** 94 56 * Saves current image to file. … … abstract class WP_Image_Editor { 168 130 * @access public 169 131 * @abstract 170 132 * 171 * @param boolean $horz Horizon al Flip133 * @param boolean $horz Horizontal Flip 172 134 * @param boolean $vert Vertical Flip 173 135 * @return boolean|WP_Error 174 136 */ … … abstract class WP_Image_Editor { 187 149 abstract public function stream( $mime_type = null ); 188 150 189 151 /** 190 * Checks to see if current environment supports the editor chosen.191 * Must be overridden in a sub-class.192 *193 * @since 3.5.0194 * @access public195 * @abstract196 *197 * @param array $args198 * @return boolean199 */200 public static function test( $args = null ) {201 return false;202 }203 204 /**205 * Checks to see if editor supports the mime-type specified.206 * Must be overridden in a sub-class.207 *208 * @since 3.5.0209 * @access public210 * @abstract211 *212 * @param string $mime_type213 * @return boolean214 */215 public static function supports_mime_type( $mime_type ) {216 return false;217 }218 219 /**220 152 * Gets dimensions of image. 221 153 * 222 154 * @since 3.5.0 … … abstract class WP_Image_Editor { 451 383 return $extensions[0]; 452 384 } 453 385 } 386 -
wp-includes/deprecated.php
diff --git wp-includes/deprecated.php wp-includes/deprecated.php index 9e99614..6751458 100644
function _get_post_ancestors( &$post ) { 3210 3210 * 3211 3211 * @since 2.1.0 3212 3212 * @deprecated 3.5.0 3213 * @see WP_Image_Editor3213 * see wp_get_image_editor() 3214 3214 * 3215 3215 * @param string $file Filename of the image to load. 3216 3216 * @return resource The resulting image resource on success, Error string on failure. 3217 3217 */ 3218 3218 function wp_load_image( $file ) { 3219 _deprecated_function( __FUNCTION__, '3.5', ' WP_Image_Editor' );3219 _deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' ); 3220 3220 3221 3221 if ( is_numeric( $file ) ) 3222 3222 $file = get_attached_file( $file ); … … function wp_load_image( $file ) { 3250 3250 * 3251 3251 * @since 2.5.0 3252 3252 * @deprecated 3.5.0 3253 * @see WP_Image_Editor3253 * see wp_get_image_editor() 3254 3254 * 3255 3255 * @param string $file Image file path. 3256 3256 * @param int $max_w Maximum width to resize to. … … function wp_load_image( $file ) { 3262 3262 * @return mixed WP_Error on failure. String with new destination path. 3263 3263 */ 3264 3264 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) { 3265 _deprecated_function( __FUNCTION__, '3.5', ' WP_Image_Editor' );3265 _deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' ); 3266 3266 3267 $editor = WP_Image_Editor::get_instance( $file );3267 $editor = wp_get_image_editor( $file ); 3268 3268 if ( is_wp_error( $editor ) ) 3269 3269 return $editor; 3270 3270 $editor->set_quality( $jpeg_quality ); … … function user_pass_ok($user_login, $user_pass) { 3328 3328 * @since 2.3.0 3329 3329 * @deprecated 3.5.0 3330 3330 */ 3331 function _save_post_hook() {} 3332 No newline at end of file 3331 function _save_post_hook() {} 3332 3333 /** 3334 * Check if the installed version of GD supports particular image type 3335 * 3336 * @since 2.9.0 3337 * @deprecated 3.5.0 3338 * see wp_image_editor_supports() 3339 * 3340 * @param string $mime_type 3341 * @return bool 3342 */ 3343 function gd_edit_image_support($mime_type) { 3344 _deprecated_function( __FUNCTION__, '3.5', 'wp_image_editor_supports()' ); 3345 3346 if ( function_exists('imagetypes') ) { 3347 switch( $mime_type ) { 3348 case 'image/jpeg': 3349 return (imagetypes() & IMG_JPG) != 0; 3350 case 'image/png': 3351 return (imagetypes() & IMG_PNG) != 0; 3352 case 'image/gif': 3353 return (imagetypes() & IMG_GIF) != 0; 3354 } 3355 } else { 3356 switch( $mime_type ) { 3357 case 'image/jpeg': 3358 return function_exists('imagecreatefromjpeg'); 3359 case 'image/png': 3360 return function_exists('imagecreatefrompng'); 3361 case 'image/gif': 3362 return function_exists('imagecreatefromgif'); 3363 } 3364 } 3365 return false; 3366 } -
wp-includes/media.php
diff --git wp-includes/media.php wp-includes/media.php index d8475f1..3a1268f 100644
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal 383 383 */ 384 384 function image_make_intermediate_size( $file, $width, $height, $crop = false ) { 385 385 if ( $width || $height ) { 386 $editor = WP_Image_Editor::get_instance( $file );386 $editor = wp_get_image_editor( $file ); 387 387 388 388 if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) 389 389 return false; … … function get_taxonomies_for_attachments( $output = 'names' ) { 904 904 } 905 905 906 906 /** 907 * Check if the installed version of GD supports particular image type908 *909 * @since 2.9.0910 *911 * @param string $mime_type912 * @return bool913 */914 function gd_edit_image_support($mime_type) {915 if ( function_exists('imagetypes') ) {916 switch( $mime_type ) {917 case 'image/jpeg':918 return (imagetypes() & IMG_JPG) != 0;919 case 'image/png':920 return (imagetypes() & IMG_PNG) != 0;921 case 'image/gif':922 return (imagetypes() & IMG_GIF) != 0;923 }924 } else {925 switch( $mime_type ) {926 case 'image/jpeg':927 return function_exists('imagecreatefromjpeg');928 case 'image/png':929 return function_exists('imagecreatefrompng');930 case 'image/gif':931 return function_exists('imagecreatefromgif');932 }933 }934 return false;935 }936 937 /**938 907 * Create new GD image resource with transparency support 939 908 * @TODO: Deprecate if possible. 940 909 * … … function wp_max_upload_size() { 1171 1140 } 1172 1141 1173 1142 /** 1143 * Returns a WP_Image_Editor instance and loads file into it. 1144 * 1145 * @since 3.5.0 1146 * @access public 1147 * 1148 * @param string $path Path to file to load 1149 * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } 1150 * @return WP_Image_Editor|WP_Error 1151 */ 1152 function wp_get_image_editor( $path, $args = array() ) { 1153 $args['path'] = $path; 1154 1155 $implementation = apply_filters( 'wp_image_editor_class', _wp_image_editor_choose( $args ) ); 1156 1157 if ( $implementation ) { 1158 $editor = new $implementation( $path ); 1159 $loaded = $editor->load(); 1160 1161 if ( is_wp_error( $loaded ) ) 1162 return $loaded; 1163 1164 return $editor; 1165 } 1166 1167 return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); 1168 } 1169 1170 /** 1171 * Tests whether there is an editor that supports a given mime type or methods. 1172 * 1173 * @since 3.5.0 1174 * @access public 1175 * 1176 * @param string|array $args String path to image to check for support, or array of arguments. Accepts { 'path'=>string, 'mime_type'=>string, 'methods'=>{string, string, ...} } 1177 * @return boolean true if an eligible editor is found; false otherwise 1178 */ 1179 function wp_image_editor_supports( $args = array() ) { 1180 return (bool) _wp_image_editor_choose( $args ); 1181 } 1182 1183 /** 1184 * Tests which editors are capable of supporting the request. 1185 * 1186 * @since 3.5.0 1187 * @access private 1188 * 1189 * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } 1190 * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 1191 */ 1192 function _wp_image_editor_choose( $args = array() ) { 1193 require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; 1194 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; 1195 require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; 1196 1197 if ( !isset( $args['mime_type'] ) && isset( $args['path'] ) ) { 1198 $file_info = wp_check_filetype( $args['path'] ); 1199 1200 // If $file_info['type'] is false, then we let the editor attempt to 1201 // figure out the file type, rather than forcing a failure based on extension. 1202 if ( isset( $file_info ) && $file_info['type'] ) 1203 $args['mime_type'] = $file_info['type']; 1204 } 1205 1206 $implementations = apply_filters( 'wp_image_editors', 1207 array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 1208 1209 foreach ( $implementations as $implementation ) { 1210 if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) 1211 continue; 1212 1213 if ( isset( $args['methods'] ) && 1214 array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { 1215 continue; 1216 } 1217 1218 return $implementation; 1219 } 1220 1221 return false; 1222 } 1223 1224 /** 1174 1225 * Prints default plupload arguments. 1175 1226 * 1176 1227 * @since 3.4.0 -
wp-settings.php
diff --git wp-settings.php wp-settings.php index ac331c2..65485a8 100644
require( ABSPATH . WPINC . '/nav-menu.php' ); 143 143 require( ABSPATH . WPINC . '/nav-menu-template.php' ); 144 144 require( ABSPATH . WPINC . '/admin-bar.php' ); 145 145 146 require( ABSPATH . WPINC . '/class-wp-image-editor.php' );147 require( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );148 require( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );149 150 146 // Load multisite-specific files. 151 147 if ( is_multisite() ) { 152 148 require( ABSPATH . WPINC . '/ms-functions.php' );