From 3a4570b0fc8b3d6339bef71d17d7701554e0bbf7 Mon Sep 17 00:00:00 2001 From: donncha Date: Fri, 12 Oct 2007 16:21:15 +0000 Subject: Merge with WP 2.3 - testing use only! Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1069 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/includes/upload.php | 381 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100644 wp-admin/includes/upload.php (limited to 'wp-admin/includes/upload.php') diff --git a/wp-admin/includes/upload.php b/wp-admin/includes/upload.php new file mode 100644 index 0000000..61b042b --- /dev/null +++ b/wp-admin/includes/upload.php @@ -0,0 +1,381 @@ +post_content )); + + $class = 'text'; + $innerHTML = get_attachment_innerHTML( $id, false, $dims ); + if ( $image_src = get_attachment_icon_src() ) { + $image_rel = wp_make_link_relative($image_src); + $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); + $class = 'image'; + } + + $src_base = wp_get_attachment_url(); + $src = wp_make_link_relative( $src_base ); + $src_base = str_replace($src, '', $src_base); + + $r = ''; + + if ( $href ) + $r .= "\n"; + if ( $href || $image_src ) + $r .= "\t\t\t$innerHTML"; + if ( $href ) + $r .= "\n"; + $r .= "\t\t\t\t".size_format(filesize($filesystem_path))."\n"; + $r .= "\n\t\t
\n\t\t\t

\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + + if ( !$thumb_base = wp_get_attachment_thumb_url() ) + $thumb_base = wp_mime_type_icon(); + if ( $thumb_base ) { + $thumb_rel = wp_make_link_relative( $thumb_base ); + $thumb_base = str_replace( $thumb_rel, '', $thumb_base ); + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + } + + $r .= "\t\t\t\t\n"; + + if ( isset($width) ) { + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + } + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t

\n\t\t
\n"; + return $r; +} + +function wp_upload_view() { + global $style, $post_id, $style; + $id = get_the_ID(); + $attachment_data = wp_get_attachment_metadata( $id ); +?> +
+
+

"; + the_title(); + if ( !isset($attachment_data['width']) && 'inline' != $style ) + echo ''; + ?>

+ ' . __('view') . ''; + echo ' | '; + echo '' . __('edit') . ''; + echo ' | '; + echo '' . __('cancel') . ''; + echo ' ]'; ?> +
+ +
+"; + echo wp_upload_display( array(171, 128) ); + if ( isset($attachment_data['width']) && 'inline' != $style ) + echo ''; ?> +
+ +
+\n"; +} + +function wp_upload_form() { + $id = get_the_ID(); + global $post_id, $tab, $style; + $enctype = $id ? '' : ' enctype="multipart/form-data"'; + $post_id = (int) $post_id; +?> + id="upload-file" method="post" action=""> + +
+

"; + the_title(); + if ( !isset($attachment_data['width']) && 'inline' != $style ) + echo ''; + ?>

+ ' . __('view') . ''; + echo ' | '; + echo '' . __('links') . ''; + echo ' | '; + echo '' . __('cancel') . ''; + echo ' ]'; ?> +
+ +
+"; + echo wp_upload_display( array(171, 128) ); + if ( isset($attachment_data['width']) && 'inline' != $style ) + echo ''; ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +

+ + + + + + + + + +
+ +
+
+ +Buy more'; // open in new window in case they have a post open + + /* + if( $space < 10000 ) { + $buymore = 'Buy more space'; // open in new window in case they have a post open + if( get_option( 'use_upgraded_upload_filetypes' ) != '1' ) { $buymore .= __( " and you can upload " ) . str_replace( " ", ", ", get_site_option( "upgraded_upload_filetypes" ) ) . __(" files");} + } + */ + if( $space > 1000 ) { + $space = number_format( $space / 1024 ); + $space .= "GB"; + } else { + $space .= "MB"; + } + ?> + Used: % of + " + . __('Browse Files') . '' + ); + + $overrides = array('action'=>'upload'); + + $file = wp_handle_upload($_FILES['image'], $overrides); + + if ( isset($file['error']) ) + wp_die($file['error'] . "
" . __('Back to Image Uploading') . '' + ); + + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; + $filename = basename($file); + + // Construct the attachment array + $attachment = array( + 'post_title' => $post_title, + 'post_content' => $post_content, + 'post_type' => 'attachment', + 'post_parent' => $post_id, + 'post_mime_type' => $type, + 'guid' => $url + ); + + // Save the data + $id = wp_insert_attachment($attachment, $file, $post_id); + + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id"); + die; + break; + + case 'save' : + global $from_tab, $post_id, $style; + if ( !$from_tab ) + $from_tab = 'upload'; + check_admin_referer( 'inlineuploading' ); + + wp_update_post($_POST); + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id"); + die; + break; + + case 'delete' : + global $ID, $post_id, $from_tab, $style; + if ( !$from_tab ) + $from_tab = 'upload'; + + check_admin_referer( 'inlineuploading' ); + + if ( !current_user_can('edit_post', (int) $ID) ) + wp_die( __('You are not allowed to delete this attachment.') + . " " + . __('Go back') . '' + ); + + wp_delete_attachment($ID); + + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id" ); + die; + break; + + endswitch; +} + +add_action( 'upload_files_upload', 'wp_upload_tab_upload_action' ); + +function wp_upload_grab_attachments( $obj ) { + $obj->is_attachment = true; +} + +function wp_upload_posts_where( $where ) { + global $post_id; + return $where . " AND post_parent = '" . (int) $post_id . "'"; +} + +function wp_upload_tab_browse() { + global $action, $paged; + $old_vars = compact( 'paged' ); + + switch ( $action ) : + case 'edit' : + case 'view' : + global $ID; + $attachments = query_posts("attachment_id=$ID"); + if ( have_posts() ) : while ( have_posts() ) : the_post(); + 'edit' == $action ? wp_upload_form() : wp_upload_view(); + endwhile; endif; + break; + default : + global $tab, $post_id, $style; + add_action( 'pre_get_posts', 'wp_upload_grab_attachments' ); + if ( 'browse' == $tab && $post_id ) + add_filter( 'posts_where', 'wp_upload_posts_where' ); + $attachments = query_posts("what_to_show=posts&post_status=any&posts_per_page=10&paged=$paged"); + + echo "\n\n"; + + echo "
\n"; + break; + endswitch; + + extract($old_vars); + + echo "
"; +} + + +function wp_upload_tab_browse_action() { + global $style; + if ( 'inline' == $style ) + wp_enqueue_script('upload'); +} + +add_action( 'upload_files_browse', 'wp_upload_tab_browse_action' ); +add_action( 'upload_files_browse-all', 'wp_upload_tab_browse_action' ); + +function wp_upload_admin_head() { + wp_admin_css( 'css/upload' ); + if ( 'inline' == @$_GET['style'] ) { + echo ""; + } +} + +?> -- cgit