Ticket #19629: 19629.4.diff
File 19629.4.diff, 5.1 KB (added by , 10 years ago) |
---|
-
wp-admin/includes/deprecated.php
diff --git wp-admin/includes/deprecated.php wp-admin/includes/deprecated.php index 36b4ca2..9bcd36c 100644
function wp_dashboard_secondary_control() {} 1188 1188 function _relocate_children( $old_ID, $new_ID ) { 1189 1189 _deprecated_function( __FUNCTION__, '3.9' ); 1190 1190 } 1191 1192 1193 /** 1194 * Download an image from the specified URL and attach it to a post. 1195 * This was once used by Press This 1196 * 1197 * @since 2.6.0 1198 * @todo add deprecated as of version 1199 * 1200 * @param string $file The URL of the image to download 1201 * @param int $post_id The post ID the media is to be associated with 1202 * @param string $desc Optional. Description of the image 1203 * @return string|WP_Error Populated HTML img tag on success 1204 */ 1205 function media_sideload_image($file, $post_id, $desc = null) { 1206 _deprecated_function( __FUNCTION__, '3.9' ); 1207 return wp_get_attachment_image( media_handle_sideload( $file, $post_id, $desc ), 'full' ); 1208 } -
wp-admin/includes/media.php
diff --git wp-admin/includes/media.php wp-admin/includes/media.php index 06cd1c1..0cf6420 100644
function media_handle_upload($file_id, $post_id, $post_data = array(), $override 353 353 * 354 354 * @since 2.6.0 355 355 * 356 * @param array $file_array Array similar to a {@link $_FILES} upload array356 * @param string|array $file A URL as a string, or an array similar to a {@link $_FILES} upload array 357 357 * @param int $post_id The post ID the media is associated with 358 358 * @param string $desc Description of the sideloaded file 359 359 * @param array $post_data allows you to overwrite some of the attachment 360 360 * @return int|object The ID of the attachment or a WP_Error on failure 361 361 */ 362 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 362 function media_handle_sideload( $file, $post_id, $desc = null, $post_data = array()) { 363 $downloading_url = is_string( $file ); 364 365 if ( $downloading_url ) { 366 // Download file to temp location 367 $tmp = download_url( $file ); 368 369 if ( is_wp_error( $tmp ) ) 370 return $tmp; 371 372 $file_array = array( 373 'name' => preg_replace( '/\?.*/', '', $file ), // Strip query string (might need to be better) 374 'tmp_name' => $tmp, 375 ); 376 } 377 363 378 $overrides = array('test_form'=>false); 364 379 365 380 $time = current_time( 'mysql' ); … … function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = 369 384 } 370 385 371 386 $file = wp_handle_sideload( $file_array, $overrides, $time ); 372 if ( isset($file['error']) ) 387 if ( isset( $file['error'] ) ) { 388 if ( $downloading_url ) 389 @unlink( $tmp ); 373 390 return new WP_Error( 'upload_error', $file['error'] ); 391 } 374 392 375 393 $url = $file['url']; 376 394 $type = $file['type']; … … function wp_media_upload_handler() { 791 809 } 792 810 793 811 /** 794 * Download an image from the specified URL and attach it to a post.795 *796 * @since 2.6.0797 *798 * @param string $file The URL of the image to download799 * @param int $post_id The post ID the media is to be associated with800 * @param string $desc Optional. Description of the image801 * @return string|WP_Error Populated HTML img tag on success802 */803 function media_sideload_image($file, $post_id, $desc = null) {804 if ( ! empty($file) ) {805 // Download file to temp location806 $tmp = download_url( $file );807 808 // Set variables for storage809 // fix file filename for query strings810 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );811 $file_array['name'] = basename($matches[0]);812 $file_array['tmp_name'] = $tmp;813 814 // If error storing temporarily, unlink815 if ( is_wp_error( $tmp ) ) {816 @unlink($file_array['tmp_name']);817 $file_array['tmp_name'] = '';818 }819 820 // do the validation and storage stuff821 $id = media_handle_sideload( $file_array, $post_id, $desc );822 // If error storing permanently, unlink823 if ( is_wp_error($id) ) {824 @unlink($file_array['tmp_name']);825 return $id;826 }827 828 $src = wp_get_attachment_url( $id );829 }830 831 // Finally check to make sure the file has been saved, then return the html832 if ( ! empty($src) ) {833 $alt = isset($desc) ? esc_attr($desc) : '';834 $html = "<img src='$src' alt='$alt' />";835 return $html;836 }837 }838 839 /**840 812 * {@internal Missing Short Description}} 841 813 * 842 814 * @since 2.5.0 -
wp-admin/press-this.php
diff --git wp-admin/press-this.php wp-admin/press-this.php index 1becc48..6c34282 100644
function press_it() { 43 43 // see if files exist in content - we don't want to upload non-used selected files. 44 44 if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) { 45 45 $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : ''; 46 $upload = media_sideload_image($image, $post_ID, $desc); 47 46 $upload = wp_get_attachment_image( media_handle_sideload( $image, $post_id, $desc ), 'full' ); 48 47 // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes 49 if ( ! is_wp_error($upload) )48 if ( ! empty($upload) ) { 50 49 $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content); 50 } 51 51 52 } 52 53 } 53 54 }