Ticket #6813: press-this-fixes-hotlinking-6-23-5pm.diff
| File press-this-fixes-hotlinking-6-23-5pm.diff, 2.9 kB (added by noel, 5 months ago) |
|---|
-
wp-admin/press-this.php
old new 4 4 if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' )); ?> 5 5 6 6 <?php 7 8 function preg_quote2($string) { 9 return str_replace('/', '\/', preg_quote($string)); 10 } 7 11 function press_it() { 8 #define some basic variables12 // define some basic variables 9 13 $quick['post_status'] = $_REQUEST['post_status']; 10 14 $quick['post_category'] = $_REQUEST['post_category']; 11 15 $quick['tags_input'] = $_REQUEST['tags_input']; 12 16 $quick['post_title'] = $_REQUEST['post_title']; 13 17 $quick['post_content'] = ''; 14 18 15 #insert the post with nothing in it, to get an ID19 // insert the post with nothing in it, to get an ID 16 20 $post_ID = wp_insert_post($quick, true); 17 21 18 22 $content = ''; … … 23 27 break; 24 28 25 29 case 'photo': 26 foreach($_REQUEST['photo_src'] as $key => $data) { 30 $content = $_REQUEST['content']; 31 32 foreach($_REQUEST['photo_src'] as $key => $image) { 27 33 #quote for matching 28 $quoted = str_replace('/', '\/', preg_quote($data));34 $quoted = preg_quote2($image); 29 35 30 #see if files exist in content - we don't want to upload non-used selected files.36 // see if files exist in content - we don't want to upload non-used selected files. 31 37 preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); 32 if($matches[0]) 33 $upload = media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); 38 if($matches[0]) { 39 $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); 40 // Replace the POSTED content <img> with correct uploaded ones. 41 if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); 42 } 34 43 } 35 $content = $_REQUEST['content'];44 36 45 break; 37 46 38 47 case "video": -
wp-admin/includes/media.php
old new 151 151 $id = wp_insert_attachment($attachment, $file, $post_parent); 152 152 if ( !is_wp_error($id) ) { 153 153 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 154 return $ src;154 return $url; 155 155 } 156 157 156 return $id; 158 159 157 } 160 158 161 159 … … 321 319 $desc = @$desc; 322 320 323 321 $id = media_handle_sideload($file_array, $post_id, $desc); 322 $src = $id; 323 324 324 unset($file_array); 325 325 326 326 if ( is_wp_error($id) ) { 327 327 $errors['upload_error'] = $id; 328 328 return $id; 329 } else {330 $src = $id;331 329 } 332 330 } 333 334 if (!empty($src) && !strpos($src, '://') ) { 335 $src = "http://$src"; 336 $alt = @$desc; 337 } 331 338 332 if ( !empty($src) ) { 333 if ( !strpos($src, '://') ) 334 $src = "http://$src"; 335 $alt = @$desc; 339 336 $html = "<img src='$src' alt='$alt' />"; 340 337 return $html; 341 338 }
