Upload media from the Media Library page.

git-svn-id: http://svn.automattic.com/wordpress/trunk@8998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2008-09-27 08:17:55 +00:00
parent 6d59ab95b0
commit a6f7c12d48
10 changed files with 177 additions and 47 deletions

View File

@ -26,7 +26,12 @@ if ( !current_user_can('upload_files') )
// just fetch the detail form for that attachment
if ( ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
if ( 2 == $_REQUEST['fetch'] ) {
add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
echo get_media_item($id, array( 'send' => false, 'delete' => false ));
} else {
echo get_media_item($id);
}
exit;
}

View File

@ -62,7 +62,8 @@ li.widget-list-control-item h4.widget-title a,
li.widget-list-control-item, div.nav, .tablenav, #dashboard-widgets p.dashboard-widget-links,
ul.view-switch li.current, .form-table tr, #poststuff h3, #replyhandle,
.login form, h3.info-box-title, #post-status-info, #edit-settings-wrap {
.login form, h3.info-box-title, #post-status-info, #edit-settings-wrap,
#wpbody-content .describe tr {
background-color: #cfebf7;
}
@ -146,7 +147,10 @@ ul#widget-list li.widget-list-item h4.widget-title {
border-color: #c6d9e9;
}
.form-table td, .form-table th {
.form-table td,
.form-table th,
#wpbody-content .describe td,
#wpbody-content .describe th {
border-bottom-color: #fff;
}

View File

@ -62,7 +62,8 @@ li.widget-list-control-item h4.widget-title a,
li.widget-list-control-item, div.nav, .tablenav, #dashboard-widgets p.dashboard-widget-links,
ul.view-switch li.current, .form-table tr, #poststuff h3, #replyhandle,
.login form, h3.info-box-title, #post-status-info, #edit-settings-wrap {
.login form, h3.info-box-title, #post-status-info, #edit-settings-wrap,
#wpbody-content .describe tr {
background-color: #eaf3fa;
}
@ -146,7 +147,10 @@ ul#widget-list li.widget-list-item h4.widget-title {
border-color: #c6d9e9;
}
.form-table td, .form-table th {
.form-table td,
.form-table th,
#wpbody-content .describe td,
#wpbody-content .describe th {
border-bottom-color: #fff;
}

View File

@ -758,7 +758,7 @@ function get_media_items( $post_id, $errors ) {
function get_media_item( $attachment_id, $args = null ) {
global $redir_tab;
$default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true );
$default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
$args = wp_parse_args( $args, $default_args );
extract( $args, EXTR_SKIP );
@ -805,7 +805,7 @@ function get_media_item( $attachment_id, $args = null ) {
}
$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
$display_title = wp_html_excerpt($display_title, 60);
$display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : '';
$gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
$order = '';
@ -826,7 +826,7 @@ function get_media_item( $attachment_id, $args = null ) {
$type
$toggle_links
$order
<div class='filename new'>$display_title</div>
$display_title
<table class='slidetoggle describe $class'>
<thead class='media-item-info'>
<tr>

View File

@ -11,6 +11,10 @@
/** Load WordPress Administration Bootstrap */
require_once('admin.php');
if (!current_user_can('upload_files'))
wp_die(__('You do not have permission to upload files.'));
wp_enqueue_script('swfupload');
wp_enqueue_script('swfupload-degrade');
wp_enqueue_script('swfupload-queue');
@ -18,9 +22,6 @@ wp_enqueue_script('swfupload-handlers');
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
if (!current_user_can('upload_files'))
wp_die(__('You do not have permission to upload files.'));
// IDs should be integers
$ID = isset($ID) ? (int) $ID : 0;
$post_id = isset($post_id)? (int) $post_id : 0;
@ -29,24 +30,82 @@ $post_id = isset($post_id)? (int) $post_id : 0;
if ( isset($action) && $action == 'edit' && !$ID )
wp_die(__("You are not allowed to be here"));
// upload type: image, video, file, ..?
if ( isset($_GET['type']) )
if ( isset($_GET['inline']) ) {
if ( isset($_GET['upload-page-form']) ) {
$errors = media_upload_form_handler();
$location = 'upload.php';
if ( $errors )
$location .= '?message=3';
wp_redirect( admin_url($location) );
}
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
$id = false;
}
}
$title = __('Upload Media');
$parent_file = 'edit.php';
require_once('admin-header.php'); ?>
<div class="wrap">
<h2><?php _e('Upload Media') ?></h2>
<form enctype="multipart/form-data" method="post" action="media-upload.php?inline=&upload-page-form=" class="media-upload-form type-form validate" id="file-form">
<?php media_upload_form(); ?>
<script type="text/javascript">
jQuery(function($){
var preloaded = $(".media-item.preloaded");
if ( preloaded.length > 0 ) {
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
}
updateMediaForm();
post_id = 0;
shortform = 1;
$('body:last div:has(embed), body:last div:has(object)').css({'visibility':'hidden','marginTop':'-1px'});
});
</script>
<input type="hidden" name="post_id" id="post_id" value="0" />
<?php wp_nonce_field('media-form'); ?>
<div id="media-items"> </div>
<p>
<input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
</p>
</form>
</div>
<?php
include('admin-footer.php');
} else {
// upload type: image, video, file, ..?
if ( isset($_GET['type']) )
$type = strval($_GET['type']);
else
else
$type = apply_filters('media_upload_default_type', 'file');
// tab: gallery, library, or type-specific
if ( isset($_GET['tab']) )
// tab: gallery, library, or type-specific
if ( isset($_GET['tab']) )
$tab = strval($_GET['tab']);
else
else
$tab = apply_filters('media_upload_default_tab', 'type');
$body_id = 'media-upload';
$body_id = 'media-upload';
// let the action code decide how to handle the request
if ( $tab == 'type' )
// let the action code decide how to handle the request
if ( $tab == 'type' )
do_action("media_upload_$type");
else
else
do_action("media_upload_$tab");
}
?>

View File

@ -24,12 +24,6 @@ case 'editattachment' :
$errors = media_upload_form_handler();
check_admin_referer('media-form');
if ( !current_user_can('edit_post', $attachment_id) )
wp_die ( __('You are not allowed to edit this attachment.') );
if ( empty($errors) ) {
$location = 'media.php';
if ( $referer = wp_get_original_referer() ) {
@ -92,9 +86,9 @@ case 'edit' :
<h2><?php _e( 'Edit Media' ); ?></h2>
<form method="post" action="<?php echo clean_url( remove_query_arg( 'message' ) ); ?>" class="media-upload-form" id="media-single-form">
<div id="media-items" class="media-single">
<div class="media-single">
<div id='media-item-<?php echo $att_id; ?>' class='media-item'>
<?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'errors' => $errors ) ); ?>
<?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'show_title' => false, 'errors' => $errors ) ); ?>
</div>
</div>

View File

@ -49,7 +49,7 @@ $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', 'wp-menu-open' );
$submenu['edit.php'][25] = array( __('Categories'), 'manage_categories', 'categories.php' );
$menu[10] = array( __('Media'), 'upload_files', 'upload.php' );
$submenu['upload.php'][5] = array( __('Upload New'), 'upload_files', 'media-upload.php');
$submenu['upload.php'][5] = array( __('Upload New'), 'upload_files', 'media-upload.php?inline');
$submenu['upload.php'][10] = array( __('View All'), 'upload_files', 'upload.php');
$menu[15] = array( __('Links'), 'manage_links', 'link-manager.php' );

View File

@ -8,7 +8,7 @@
/** WordPress Administration Bootstrap */
require_once('admin.php');
add_thickbox();
//add_thickbox();
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( 'wp-ajax-response' );
wp_enqueue_script( 'jquery-ui-draggable' );
@ -182,7 +182,7 @@ if ( isset($_GET['detached']) ) {
$h2_cat = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in &#8220;%s&#8221;'), single_cat_title('', false) ) : '';
$h2_tag = isset($_GET['tag']) && $_GET['tag'] ? ' ' . sprintf( __('tagged with &#8220;%s&#8221;'), single_tag_title('', false) ) : '';
$h2_month = isset($_GET['m']) && $_GET['m'] ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : '';
printf( _c( '%1$s%2$s%3$s%4$s%5$s%6$s (<a href="%7$s" class="thickbox">Add New</a>)|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: tagged with {s}, 6: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_tag, $h2_month, 'media-upload.php?library=false&TB_iframe=true' );
printf( _c( '%1$s%2$s%3$s%4$s%5$s%6$s (<a href="%7$s">Add New</a>)|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: tagged with {s}, 6: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_tag, $h2_month, 'media-upload.php?inline' );
}
?></h2>
@ -224,8 +224,9 @@ if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET
<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
endif;
$messages[1] = __('Media updated.');
$messages[1] = __('Media attachment updated.');
$messages[2] = __('Media deleted.');
$messages[3] = __('Error saving media attachment.');
if ( isset($_GET['message']) && (int) $_GET['message'] )
$message = $messages[$_GET['message']];

View File

@ -964,7 +964,8 @@ html, body {
margin-bottom: -8px;
}
.form-table td {
.form-table td,
#wpbody-content .describe td {
margin-bottom: 9px;
padding: 10px;
line-height: 20px;
@ -973,7 +974,8 @@ html, body {
font-size: 11px;
}
.form-table th {
.form-table th,
#wpbody-content .describe th {
vertical-align: top;
text-align: left;
padding: 10px;
@ -986,7 +988,10 @@ html, body {
width: auto;
}
.form-table input, .form-table textarea {
.form-table input,
.form-table textarea,
#wpbody-content .describe input,
#wpbody-content .describe textarea {
border-width: 1px;
border-style: solid;
}
@ -2344,7 +2349,18 @@ a.togbox {
}
/* Media library */
#wpbody-content .media-item-info tr {
#wpbody-content #media-items .describe {
border-collapse: collapse;
width: 100%;
border-top-style: solid;
border-top-width: 1px;
clear: both;
cursor: default;
padding: 5px;
width: 100%;
}
#wpbody-content .describe .media-item-info tr {
background-color: transparent;
}
@ -2369,16 +2385,62 @@ abbr.required {
text-decoration: none;
}
#wpbody-content .media-single input[type="text"],
#wpbody-content .media-single textarea {
#wpbody-content .describe input[type="text"],
#wpbody-content .describe textarea {
width: 460px;
}
#wpbody-content .media-upload-form p.help {
#wpbody-content .describe p.help {
margin: 0;
padding: 0;
}
.describe-toggle-on, .describe-toggle-off {
display: block;
line-height: 36px;
float: right;
margin-right: 20px;
}
.describe-toggle-off {
display: none;
}
#wpbody-content .media-item {
border-bottom-style: solid;
border-bottom-width: 1px;
min-height: 36px;
position: relative;
width: 100%;
}
#wpbody-content #media-items {
border-style: solid solid none;
border-width: 1px;
width: 670px;
}
#wpbody-content #media-items .filename {
float: left;
line-height: 36px;
margin-left: 10px;
max-width: 430px;
overflow: hidden;
}
.media-item .pinkynail {
float: left;
height: 32px;
margin: 2px;
max-width: 40px;
max-height: 40px;
}
.media-item .startopen,
.media-item .startclosed {
display: none;
}
/* find posts */
.find-box {
width: 400px;

View File

@ -35,6 +35,7 @@ function prepareMediaItem(fileObj, serverData) {
jQuery('#media-item-' + fileObj.id + ' .bar').remove();
jQuery('#media-item-' + fileObj.id + ' .progress').hide();
var f = ( typeof shortform == 'undefined' ) ? 1 : 2;
// Old style: Append the HTML returned by the server -- thumbnail and form inputs
if ( isNaN(serverData) || !serverData ) {
jQuery('#media-item-' + fileObj.id).append(serverData);
@ -42,7 +43,7 @@ function prepareMediaItem(fileObj, serverData) {
}
// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
else {
jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:1}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
}
}