From cdc53fcb86070c4ae202102bbbb8e06b13f64051 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 23 Jun 2008 21:16:39 +0000 Subject: [PATCH] Press This image linking fixes from noel. see #6813 git-svn-id: http://svn.automattic.com/wordpress/trunk@8172 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 19 ++++++++----------- wp-admin/press-this.php | 31 ++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 8d9029f72e..d6fdec20b4 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -151,11 +151,9 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = $id = wp_insert_attachment($attachment, $file, $post_parent); if ( !is_wp_error($id) ) { wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); - return $src; + return $url; } - return $id; - } @@ -321,21 +319,20 @@ function media_sideload_image($file, $post_id, $desc = null) { $desc = @$desc; $id = media_handle_sideload($file_array, $post_id, $desc); + $src = $id; + unset($file_array); - + if ( is_wp_error($id) ) { $errors['upload_error'] = $id; return $id; - } else { - $src = $id; } } - - if (!empty($src) && !strpos($src, '://') ) { - $src = "http://$src"; - $alt = @$desc; - } + if ( !empty($src) ) { + if ( !strpos($src, '://') ) + $src = "http://$src"; + $alt = @$desc; $html = "$alt"; return $html; } diff --git a/wp-admin/press-this.php b/wp-admin/press-this.php index b07a0a3e69..16990519d4 100644 --- a/wp-admin/press-this.php +++ b/wp-admin/press-this.php @@ -4,15 +4,19 @@ require_once('admin.php'); if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' )); ?> $data) { - #quote for matching - $quoted = str_replace('/', '\/', preg_quote($data)); - - # see if files exist in content - we don't want to upload non-used selected files. - preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); - if($matches[0]) - $upload = media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); - } $content = $_REQUEST['content']; + + foreach($_REQUEST['photo_src'] as $key => $image) { + #quote for matching + $quoted = preg_quote2($image); + + // see if files exist in content - we don't want to upload non-used selected files. + preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); + if($matches[0]) { + $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); + // Replace the POSTED content with correct uploaded ones. + if( !is_wp_error($upload) ) $content = preg_replace('/]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); + } + } + break; case "video":