From cdcd6ffdf624cd41be914e7e3a1892d0ad2177b5 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 18 Jul 2008 03:19:12 +0000 Subject: [PATCH] Image sideload and wp_upload_dir() fixes from noel. fixes #7342 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@8369 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/press-this.php | 9 +++++---- wp-includes/functions.php | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/wp-admin/press-this.php b/wp-admin/press-this.php index 7c88ec4acc..044464ccc1 100644 --- a/wp-admin/press-this.php +++ b/wp-admin/press-this.php @@ -34,13 +34,14 @@ function press_it() { $content = $_REQUEST['content']; foreach( (array) $_REQUEST['photo_src'] as $key => $image) { - // escape quote for matching - $quoted = preg_quote2($image); - + // see if files exist in content - we don't want to upload non-used selected files. - if( strpos($_REQUEST['content'], $quoted) !== false ) { + if( strpos($_REQUEST['content'], $image) !== false ) { $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); + // Replace the POSTED content with correct uploaded ones. + // escape quote for matching + $quoted = preg_quote2($image); if( !is_wp_error($upload) ) $content = preg_replace('/]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 355e7d771f..42aedb62de 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1489,9 +1489,9 @@ function wp_upload_dir( $time = NULL ) { // $dir is absolute, $path is (maybe) relative to ABSPATH $dir = path_join( ABSPATH, $dir ); - + if ( !$url = get_option( 'upload_url_path' ) ) { - if ( empty($upload_path) ) + if ( empty($upload_path) or ( $upload_path == $dir ) ) $url = WP_CONTENT_URL . '/uploads'; else $url = trailingslashit( $siteurl ) . $upload_path; @@ -1523,8 +1523,9 @@ function wp_upload_dir( $time = NULL ) { $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir ); return array( 'error' => $message ); } - + $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ); + return apply_filters( 'upload_dir', $uploads ); }