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
This commit is contained in:
ryan 2008-07-18 03:19:12 +00:00
parent 8f29cb96e7
commit cdcd6ffdf6
2 changed files with 9 additions and 7 deletions

View File

@ -34,13 +34,14 @@ function press_it() {
$content = $_REQUEST['content']; $content = $_REQUEST['content'];
foreach( (array) $_REQUEST['photo_src'] as $key => $image) { 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. // 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]); $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
// Replace the POSTED content <img> with correct uploaded ones. // Replace the POSTED content <img> with correct uploaded ones.
// escape quote for matching
$quoted = preg_quote2($image);
if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
} }
} }

View File

@ -1489,9 +1489,9 @@ function wp_upload_dir( $time = NULL ) {
// $dir is absolute, $path is (maybe) relative to ABSPATH // $dir is absolute, $path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $dir ); $dir = path_join( ABSPATH, $dir );
if ( !$url = get_option( 'upload_url_path' ) ) { if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) ) if ( empty($upload_path) or ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads'; $url = WP_CONTENT_URL . '/uploads';
else else
$url = trailingslashit( $siteurl ) . $upload_path; $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 ); $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir );
return array( 'error' => $message ); return array( 'error' => $message );
} }
$uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ); $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false );
return apply_filters( 'upload_dir', $uploads ); return apply_filters( 'upload_dir', $uploads );
} }