From bb66b9f0b684306a8b11ea65c864e435b51df513 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 14 Apr 2008 23:09:50 +0000 Subject: [PATCH] Workaround response truncation by reducing size of response after uploading with flash uploader. Props tellyworth. fixes #6713 for 2.5 git-svn-id: https://develop.svn.wordpress.org/branches/2.5@7683 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/async-upload.php | 17 +++++++++++++++-- wp-admin/includes/media.php | 3 ++- wp-includes/js/swfupload/handlers.js | 14 ++++++++++++-- wp-includes/script-loader.php | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/wp-admin/async-upload.php b/wp-admin/async-upload.php index c6350aa08..1a37dceb9 100644 --- a/wp-admin/async-upload.php +++ b/wp-admin/async-upload.php @@ -20,13 +20,26 @@ if ( !current_user_can('upload_files') ) wp_die(__('You do not have permission to upload files.')); +// just fetch the detail form for that attachment +if ( ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) { + echo get_media_item($id); + exit; +} + $id = media_handle_upload('async-upload', $_REQUEST['post_id']); if (is_wp_error($id)) { echo '
'.wp_specialchars($id->get_error_message()).'
'; exit; } -$type = $_REQUEST['type']; -echo apply_filters("async_upload_{$type}", $id); +if ( $_REQUEST['short'] ) { + // short form response - attachment ID only + echo $id; +} +else { + // long form response - big chunk o html + $type = $_REQUEST['type']; + echo apply_filters("async_upload_{$type}", $id); +} ?> diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index ffc289066..26da42174 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -801,7 +801,8 @@ function media_upload_form( $errors = null ) { "post_id" : "", "auth_cookie" : "", "type" : "", - "tab" : "" + "tab" : "", + "short" : "1" }, file_size_limit : "b", swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available diff --git a/wp-includes/js/swfupload/handlers.js b/wp-includes/js/swfupload/handlers.js index 2c39d7291..92eb8ac88 100644 --- a/wp-includes/js/swfupload/handlers.js +++ b/wp-includes/js/swfupload/handlers.js @@ -35,8 +35,18 @@ function prepareMediaItem(fileObj, serverData) { jQuery('#media-item-' + fileObj.id + ' .bar').remove(); jQuery('#media-item-' + fileObj.id + ' .progress').hide(); - // Append the HTML returned by the server -- thumbnail and form inputs - jQuery('#media-item-' + fileObj.id).append(serverData); + // Old style: Append the HTML returned by the server -- thumbnail and form inputs + if ( isNaN(serverData) || !serverData ) { + jQuery('#media-item-' + fileObj.id).append(serverData); + prepareMediaItemInit(fileObj); + } + // 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()}); + } +} + +function prepareMediaItemInit(fileObj) { // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index c0dab2758..eadbb2c43 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -87,7 +87,7 @@ function default_scripts() { 'is_lighttpd_before_150' => is_lighttpd_before_150(), ) ); $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); - $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080331'); + $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407'); // these error messages came from the sample swfupload js, they might need changing. $this->localize( 'swfupload-handlers', 'swfuploadL10n', array( 'queue_limit_exceeded' => __('You have attempted to queue too many files.'),