diff --git a/wp-admin/async-upload.php b/wp-admin/async-upload.php new file mode 100644 index 000000000..24a68e8b1 --- /dev/null +++ b/wp-admin/async-upload.php @@ -0,0 +1,28 @@ +'.wp_specialchars($id->get_error_message()).''; + exit; +} + +$type = $_REQUEST['type']; +echo apply_filters("async_upload_{$type}", $id); + +?> diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index a281ad539..7313b9197 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -41,6 +41,7 @@ form.media-upload-form { display:block; font-weight: bold; margin-bottom: 0.5em; + margin: 0 0 0.5em 0; } .media-upload-form label.form-help { @@ -58,9 +59,11 @@ form.media-upload-form { } .media-upload-form fieldset { + width: 100%; border: none; text-align: justify; - margin-bottom: 1em; + margin: 0 0 1em 0; + padding: 0; } .media-upload-form button.button-ok { @@ -83,7 +86,8 @@ form.media-upload-form { /* specific to the image upload form */ .media-upload-form fieldset#image-align label { display: inline; - padding: 0 28px; + padding: 0 0 0 28px; + margin: 0 0; } #image-align-none-label { @@ -100,4 +104,88 @@ form.media-upload-form { #image-align-right-label { background: url(../images/align-right.png) no-repeat center left; -} \ No newline at end of file +} + +.pinkynail { + max-width: 40px; + max-height: 40px; +} + +#multimedia-items { + border: 1px solid #c0c0c0; + border-bottom: none; + width: 623px; +} +.multimedia-item { + border-bottom: 1px solid #d0d0d0; + width: 623px; + position: relative; +} +span.filename { + position: absolute; + left: 46px; + top: 0px; + line-height: 36px; + z-index: 2; +} +.progress { + width: 623px; + height: 36px; +} +.bar { + width: 0px; + height: 36px; + background-color: #e8e8e8; + border-right: 3px solid #99d; +} +.multimedia-item .thumbnail { + +} +.multimedia-item .pinkynail { + position: absolute; + top: 3px; + left: 3px; + max-width: 40px; + max-height: 40px; +} +.describe { + display: none; + border-top: 1px solid #d0d0d0; + padding: 5px; +} +.describe fieldset { + width: 470px; + float: right; +} +.describe img { + float: left; +} +.describe input[type="text"], .describe textarea { + width: 450px; +} +.describe label { + padding-right: 1em; +} + +a.delete { + clear: both; +} +.describe-toggle-on, .describe-toggle-off { + line-height: 36px; + z-index: 2; + position: absolute; + top: 0px; + right: 20px; +} +.describe-toggle-off { + display: none; +} +.clickmask { + background: transparent; + position: absolute; + top: 0px; + left: 0px; + cursor: pointer; + border: none; + z-index: 10; +} diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index e98e4dba8..3a2fba8b2 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -14,7 +14,8 @@ function image_upload_form( $action_url, $values = array(), $error = null ) { $image_url = attribute_escape( @$values['image-url'] ); $image_title = attribute_escape( @$values['image-title'] ); $image_align = @$values['image-url']; - + $post_id = $_GET['post_id']; + ?>

Add Image

@@ -24,13 +25,55 @@ function image_upload_form( $action_url, $values = array(), $error = null ) {
  • - -
    - get_error_message(); ?> -
    - +
    +get_error_message(); +} ?> +
    +
    -

    +

    + + +

    +

    @@ -57,7 +100,7 @@ function image_upload_form( $action_url, $values = array(), $error = null ) {

    - +
    $id, + 'post_title' => $_POST['image-title'], + 'post_content' => $_POST['image-alt'], + )); + } + else { + $id = image_upload_post(); + } // if the input was invalid, redisplay the form with its current values if ( is_wp_error($id) ) @@ -88,6 +144,45 @@ function image_upload_handler() { } } +// this returns html to include in the single image upload form when the async flash upload has finished +// i.e. show a thumb of the image, and include the attachment id as a hidden input +function async_image_callback($id) { + $thumb_url = wp_get_attachment_thumb_url($id); + if ( empty($thumb_url) ) + $thumb_url = wp_mime_type_icon($id); + + if ($thumb_url) { + $out = '

    ' + . ' ' + . basename(wp_get_attachment_url($id)).'

    '; + } + else { + $out = '

    ' + . basename(wp_get_attachment_url($id)).'

    '; + } + + $post = get_post($id); + $title = addslashes($post->post_title); + $alt = addslashes($post->post_content); + + // populate the input fields with post data (which in turn comes from exif/iptc) + $out .= << + + +EOF; + + return $out; +} + +add_filter('async_upload_image', 'async_image_callback'); + + function image_send_to_editor($id, $alt, $title, $align, $url='') { $img_src = wp_get_attachment_url($id); @@ -97,7 +192,7 @@ function image_send_to_editor($id, $alt, $title, $align, $url='') { if ( isset($meta['width'], $meta['height']) ) $hwstring = ' width="'.intval($meta['width']).'" height="'.intval($meta['height']).'"'; - $html = ''.attribute_escape($alt).''; + $html = ''.attribute_escape($alt).''; if ( $url ) $html = ''.$html.''; @@ -152,12 +247,51 @@ function image_upload_post() { if ( !is_wp_error($id) ) wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + return $id; +} + +// this handles the file upload POST itself, creating the attachment post +function media_handle_upload($file_id, $post_id, $post_data = array()) { + $overrides = array('test_form'=>false); + $file = wp_handle_upload($_FILES[$file_id], $overrides); + + if ( isset($file['error']) ) + return new wp_error( 'upload_error', $file['error'] ); + + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; + $title = preg_replace('/\.[^.]+$/', '', basename($file)); + $content = ''; + + // use image exif/iptc data for title and caption defaults if possible + if ( $image_meta = @wp_read_image_metadata($file) ) { + if ( trim($image_meta['title']) ) + $title = $image_meta['title']; + if ( trim($image_meta['caption']) ) + $content = $image_meta['caption']; + } + + // Construct the attachment array + $attachment = array_merge( array( + 'post_mime_type' => $type, + 'guid' => $url, + 'post_parent' => $post_id, + 'post_title' => $title, + 'post_content' => $content, + ), $post_data ); + + // Save the data + $id = wp_insert_attachment($attachment, $file, $post_parent); + if ( !is_wp_error($id) ) { + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + } + return $id; - wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id"); - } + // wrap iframe content (produced by $content_func) in a doctype, html head/body etc // any additional function args will be passed to content_func function wp_iframe($content_func /* ... */) { @@ -194,10 +328,13 @@ if ( is_string($content_func) ) function media_buttons() { // just a placeholder for now global $post_ID, $temp_ID; $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); - $uploading_iframe_src = wp_nonce_url("media-upload.php?type=image&&post_id=$uploading_iframe_ID", 'inlineuploading'); - $uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src); + $image_upload_iframe_src = wp_nonce_url("media-upload.php?type=image&post_id=$uploading_iframe_ID", 'inlineuploading'); + $image_upload_iframe_src = apply_filters('image_upload_iframe_src', $image_upload_iframe_src); + $multimedia_upload_iframe_src = wp_nonce_url("media-upload.php?type=multimedia&post_id=$uploading_iframe_ID", 'inlineuploading'); + $multimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src); $out = << +Multimedia + EOF; @@ -225,7 +362,214 @@ function media_admin_css() { wp_admin_css('css/media'); } +add_action('media_upload_multimedia', 'multimedia_upload_handler'); add_action('media_upload_image', 'image_upload_handler'); add_action('admin_head_image_upload_form', 'media_admin_css'); -?> \ No newline at end of file +function multimedia_upload_handler() { + if ( !current_user_can('upload_files') ) { + return new wp_error( 'upload_not_allowed', __('You are not allowed to upload files.') ); + } + + if ( empty($_POST) ) { + // no button click, we're just displaying the form + wp_iframe( 'multimedia_upload_form' ); + } elseif ( empty($_POST['upload-button']) ) { + // Insert multimedia button was clicked + check_admin_referer('multimedia-form'); + + if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { + $post = $_post = get_post($attachment_id, ARRAY_A); + $post['post_content'] = $attachment['post_content']; + $post['post_title'] = $attachment['post_title']; + if ( $post != $_post ) + wp_update_post($post); + + if ( $taxonomies = get_object_taxonomies('attachment') ) foreach ( $taxonomies as $t ) + if ( isset($attachment[$t]) ) + wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); + } + + media_send_to_editor('[gallery]'); + } else { + // Upload File button was clicked + + $id = media_handle_upload('async-upload', $_REQUEST['post_id']); + + wp_iframe( 'multimedia_upload_form' ); + } +} + +function get_multimedia_items( $post_id ) { + $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=\"menu_order ASC, ID ASC\""); + + if ( empty($attachments) ) + return ''; + + foreach ( $attachments as $id => $attachment ) { + $output .= "\n
    "; + $output .= get_multimedia_item($id); + $output .= "
    \n
    "; + } + + return $output; +} + +function get_multimedia_item( $attachment_id ) { + $thumb_url = wp_get_attachment_thumb_url( $attachment_id ); + if ( empty($thumb_url) ) + $thumb_url = wp_mime_type_icon( $attachment_id ); + + $title_label = __('Title'); + $description_label = __('Description'); + $tags_label = __('Tags'); + + $toggle_on = __('Describe »'); + $toggle_off = __('Describe «'); + + $post = get_post($attachment_id); + + $filename = basename($post->guid); + $title = attribute_escape($post->post_title); + $description = attribute_escape($post->post_content); + if ( $_tags = get_the_tags($attachment_id) ) { + foreach ( $_tags as $tag ) + $tags[] = $tag->name; + $tags = attribute_escape(join(', ', $tags)); + } + + $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id); + $delete = __('Delete'); + + $item = " + $toggle_on + $toggle_off + $filename +
    + +
    +

    +

    +"; + + if ( $taxonomies = get_object_taxonomies('attachment') ) foreach ( $taxonomies as $t ) { + $tax = get_taxonomy($t); + $t_title = !empty($tax->title) ? $tax->title : $t; + if ( false === $terms = get_object_term_cache( $attachment_id, $t ) ) + $_terms = wp_get_object_terms($attachment_id, $t); + if ( $_terms ) { + foreach ( $_terms as $term ) + $terms[] = $term->name; + $terms = join(', ', $terms); + } else + $terms = ''; + $item .= "

    \n"; + } + + $item .= " +
    +

    $delete

    +
    +"; + + return $item; +} + +function multimedia_upload_form( $error = null ) { + $flash_action_url = get_option('siteurl') . '/wp-admin/async-upload.php?type=multimedia'; + $form_action_url = get_option('siteurl') . '/wp-admin/media-upload.php?type=multimedia'; + + $post_id = intval($_REQUEST['post_id']); + +?> +
    +

    Add Images

    +
    +
    + + get_error_message(); ?> + +
    + + + +
    + +
    +

    + + +

    +

    + + +

    + +
    +
    + + + +
    + + + +
    + +

    + + +

    + + + +
    + + 'People')); + +?> diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 155a99b70..1e87fdd5e 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -745,10 +745,15 @@ function wp_convert_bytes_to_hr( $bytes ) { return $size . $units[$power]; } -function wp_import_upload_form( $action ) { +function wp_max_upload_size() { $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); - $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); + $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); + return $bytes; +} + +function wp_import_upload_form( $action ) { + $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); $size = wp_convert_bytes_to_hr( $bytes ); ?>
    diff --git a/wp-admin/media-upload.php b/wp-admin/media-upload.php index 361a99596..dddd5f1c1 100644 --- a/wp-admin/media-upload.php +++ b/wp-admin/media-upload.php @@ -1,5 +1,9 @@ \ No newline at end of file +?> diff --git a/wp-includes/js/swfupload/handlers.js b/wp-includes/js/swfupload/handlers.js new file mode 100644 index 000000000..dc1f57612 --- /dev/null +++ b/wp-includes/js/swfupload/handlers.js @@ -0,0 +1,298 @@ +function fileDialogStart() { + jQuery("#media-upload-error").empty(); +} + +// progress and success handlers for multimedia multi uploads +function fileQueuedMultimedia(fileObj) { + // Create a progress bar containing the filename + jQuery('#multimedia-items').append('
    ' + fileObj.name + '
    '); + + // Disable the submit button + jQuery('#insert-multimedia').attr('disabled', 'disabled'); +} + +function uploadProgressMultimedia(fileObj, bytesDone, bytesTotal) { + // Lengthen the progress bar + jQuery('#multimedia-item-' + fileObj.id + ' .bar').width(620*bytesDone/bytesTotal); +} + +function uploadSuccessMultimedia(fileObj, serverData) { + // if async-upload returned an error message, place it in the multimedia item div and return + if ( serverData.match('media-upload-error') ) { + jQuery('#multimedia-item-' + fileObj.id).html(serverData); + return; + } + + // Move the progress bar to 100% + jQuery('#multimedia-item-' + fileObj.id + ' .bar').remove(); + + // Append the HTML returned by the server -- thumbnail and form inputs + jQuery('#multimedia-item-' + fileObj.id).append(serverData); + + // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename + jQuery('#multimedia-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail').prependTo('#multimedia-item-' + fileObj.id); + + // Replace the original filename with the new (unique) one assigned during upload + jQuery('#multimedia-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#multimedia-item-' + fileObj.id + ' .filename.new')); + + // Bind toggle function to a new mask over the progress bar area + jQuery('#multimedia-item-' + fileObj.id + ' .progress').clone().empty().addClass('clickmask').bind('click', function(){jQuery(this).siblings('.slidetoggle').slideToggle(150);jQuery(this).siblings('.toggle').toggle();}).appendTo('#multimedia-item-' + fileObj.id); + + // Also bind toggle to the links + jQuery('#multimedia-item-' + fileObj.id + ' a.toggle').bind('click', function(){jQuery(this).siblings('.slidetoggle').slideToggle(150);jQuery(this).parent().eq(0).children('.toggle').toggle();jQuery(this).siblings('a.toggle').focus();return false;}); + + // Bind AJAX to the new Delete button + jQuery('#multimedia-item-' + fileObj.id + ' a.delete').bind('click',function(){jQuery.ajax({url:'admin-ajax.php',type:'post',data:{id:this.id.replace(/del/,''),action:'delete-post',_ajax_nonce:this.href.replace(/^.*wpnonce=/,'')}});jQuery(this).parents(".multimedia-item").eq(0).slideToggle(300, function(){jQuery(this).remove();});return false;}); +} + +function uploadCompleteMultimedia(fileObj) { + // If no more uploads queued, enable the submit button + if ( swfu.getStats().files_queued == 0 ) + jQuery('#insert-multimedia').attr('disabled', ''); +} + + +// progress and success handlers for single image upload + +function uploadLoadedImage() { + jQuery('#image-alt').attr('disabled', true); + jQuery('#image-url').attr('disabled', true); + jQuery('#image-title').attr('disabled', true); + jQuery('#image-add').attr('disabled', true); +} + +function fileQueuedImage(fileObj) { + jQuery('#flash-upload-ui').append('

    ' + fileObj.name + '

    '); +} + +function uploadProgressImage(fileObj, bytesDone, bytesTotal) { + jQuery('#image-progress .bar').width(450*bytesDone/bytesTotal); +} + +function uploadSuccessImage(fileObj, serverData) { + if ( serverData.match('media-upload-error') ) { + jQuery('#media-upload-error').replaceWith(serverData); + jQuery('#image-progress').replaceWith(''); + } + else { + jQuery('#media-upload-error').replaceWith(''); + jQuery('#flash-upload-ui').replaceWith(serverData); + } +} + +// wp-specific error handlers + +// generic message +function wpQueueError(message) { + jQuery('#media-upload-error').show().text(message); +} + +// file-specific message +function wpFileError(fileObj, message) { + jQuery('#media-upload-error-' + fileObj.id).show().text(message); +} + +function fileQueueError(fileObj, error_code, message) { + // Handle this error separately because we don't want to create a FileProgress element for it. + if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) { + wpQueueError(swfuploadL10n.queue_limit_exceeded); + } + else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) { + wpQueueError(swfuploadL10n.file_exceeds_size_limit); + } + else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) { + wpQueueError(swfuploadL10n.zero_byte_file); + } + else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) { + wpQueueError(swfuploadL10n.invalid_filetype); + } + else { + wpQueueError(swfuploadL10n.default_error); + } + +function fileQueued(fileObj) { + try { + var txtFileName = document.getElementById("txtFileName"); + txtFileName.value = fileObj.name; + } catch (e) { } + +} + +function fileDialogComplete(num_files_queued) { + try { + if (num_files_queued > 0) { + this.startUpload(); + } + } catch (ex) { + this.debug(ex); + } +} + +function uploadProgress(fileObj, bytesLoaded, bytesTotal) { + + try { + var percent = Math.ceil((bytesLoaded / bytesTotal) * 100) + + fileObj.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file + var progress = new FileProgress(fileObj, this.customSettings.progress_target); + progress.SetProgress(percent); + progress.SetStatus("Uploading..."); + } catch (e) { } +} + +function uploadSuccess(fileObj, server_data) { + try { + fileObj.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file + var progress = new FileProgress(fileObj, this.customSettings.progress_target); + progress.SetComplete(); + progress.SetStatus("Complete."); + progress.ToggleCancel(false); + + if (server_data === " ") { + this.customSettings.upload_successful = false; + } else { + this.customSettings.upload_successful = true; + document.getElementById("hidFileID").value = server_data; + } + + } catch (e) { } +} + +function uploadComplete(fileObj) { + try { + if (this.customSettings.upload_successful) { + document.getElementById("btnBrowse").disabled = "true"; + uploadDone(); + } else { + fileObj.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file + var progress = new FileProgress(fileObj, this.customSettings.progress_target); + progress.SetError(); + progress.SetStatus("File rejected"); + progress.ToggleCancel(false); + + var txtFileName = document.getElementById("txtFileName"); + txtFileName.value = ""; + //validateForm(); + + alert("There was a problem with the upload.\nThe server did not accept it."); + } + } catch (e) { } +} + +function uploadError(fileObj, error_code, message) { + + // first the file specific error + if ( error_code == SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL ) { + wpFileError(fileObj, swfuploadL10n.missing_upload_url); + } + else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED ) { + wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded); + } + else { + wpFileError(fileObj, swfuploadL10n.default_error); + } + + // not sure if this is needed + fileObj.id = "singlefile"; // This makes it so FileProgress only makes a single UI element, instead of one for each file + var progress = new FileProgress(fileObj, this.customSettings.progress_target); + progress.SetError(); + progress.ToggleCancel(false); + + // now the general upload status + if ( error_code == SWFUpload.UPLOAD_ERROR.HTTP_ERROR ) { + wpQueueError(swfuploadL10n.http_error); + } + else if ( error_code == SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED ) { + wpQueueError(swfuploadL10n.upload_failed); + } + else if ( error_code == SWFUpload.UPLOAD_ERROR.IO_ERROR ) { + wpQueueError(swfuploadL10n.io_error); + } + else if ( error_code == SWFUpload.UPLOAD_ERROR.SECURITY_ERROR ) { + wpQueueError(swfuploadL10n.security_error); + } + else if ( error_code == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED ) { + wpQueueError(swfuploadL10n.security_error); + } +} + + +/* ******************************************************** + * Utility for displaying the file upload information + * This is not part of SWFUpload, just part of the demo + * ******************************************************** */ +function FileProgress(fileObj, target_id) { + this.file_progress_id = fileObj.id; + + this.fileProgressElement = document.getElementById(this.file_progress_id); + if (!this.fileProgressElement) { + this.fileProgressElement = document.createElement("div"); + this.fileProgressElement.className = "progressContainer"; + this.fileProgressElement.id = this.file_progress_id; + + var progressCancel = document.createElement("a"); + progressCancel.className = "progressCancel"; + progressCancel.href = "#"; + progressCancel.style.visibility = "hidden"; + progressCancel.appendChild(document.createTextNode(" ")); + + var progressText = document.createElement("div"); + progressText.className = "progressName"; + progressText.appendChild(document.createTextNode(fileObj.name)); + + var progressBar = document.createElement("div"); + progressBar.className = "progressBarInProgress"; + + var progressStatus = document.createElement("div"); + progressStatus.className = "progressBarStatus"; + progressStatus.innerHTML = " "; + + this.fileProgressElement.appendChild(progressCancel); + this.fileProgressElement.appendChild(progressText); + this.fileProgressElement.appendChild(progressStatus); + this.fileProgressElement.appendChild(progressBar); + + document.getElementById(target_id).appendChild(this.fileProgressElement); + + } + +} +FileProgress.prototype.SetStart = function() { + this.fileProgressElement.className = "progressContainer"; + this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; + this.fileProgressElement.childNodes[3].style.width = ""; +} + +FileProgress.prototype.SetProgress = function(percentage) { + this.fileProgressElement.className = "progressContainer green"; + this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; + this.fileProgressElement.childNodes[3].style.width = percentage + "%"; +} +FileProgress.prototype.SetComplete = function() { + this.fileProgressElement.className = "progressContainer blue"; + this.fileProgressElement.childNodes[3].className = "progressBarComplete"; + this.fileProgressElement.childNodes[3].style.width = ""; + + +} +FileProgress.prototype.SetError = function() { + this.fileProgressElement.className = "progressContainer red"; + this.fileProgressElement.childNodes[3].className = "progressBarError"; + this.fileProgressElement.childNodes[3].style.width = ""; +} +FileProgress.prototype.SetCancelled = function() { + this.fileProgressElement.className = "progressContainer"; + this.fileProgressElement.childNodes[3].className = "progressBarError"; + this.fileProgressElement.childNodes[3].style.width = ""; +} +FileProgress.prototype.SetStatus = function(status) { + this.fileProgressElement.childNodes[2].innerHTML = status; +} + +FileProgress.prototype.ToggleCancel = function(show, upload_obj) { + this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden"; + if (upload_obj) { + var file_id = this.file_progress_id; + this.fileProgressElement.childNodes[0].onclick = function() { upload_obj.cancelUpload(file_id); return false; }; + } +} diff --git a/wp-includes/js/swfupload/plugins/swfupload.cookies.js b/wp-includes/js/swfupload/plugins/swfupload.cookies.js new file mode 100644 index 000000000..4d41612df --- /dev/null +++ b/wp-includes/js/swfupload/plugins/swfupload.cookies.js @@ -0,0 +1,50 @@ +/* + Cookie Plug-in + + This plug in automatically gets all the cookies for this site and adds them to the post_params. + Cookies are loaded only on initialization. The refreshCookies function can be called to update the post_params. + The cookies will override any other post params with the same name. +*/ + +var SWFUpload; +if (typeof(SWFUpload) === "function") { + SWFUpload.prototype.initSettings = function (old_initSettings) { + return function (init_settings) { + if (typeof(old_initSettings) === "function") { + old_initSettings.call(this, init_settings); + } + + this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point + }; + }(SWFUpload.prototype.initSettings); + + // refreshes the post_params and updates SWFUpload. The send_to_flash parameters is optional and defaults to True + SWFUpload.prototype.refreshCookies = function (send_to_flash) { + if (send_to_flash !== false) send_to_flash = true; + + // Get the post_params object + var post_params = this.getSetting("post_params"); + + // Get the cookies + var i, cookie_array = document.cookie.split(';'), ca_length = cookie_array.length, c, eq_index, name, value; + for(i = 0; i < ca_length; i++) { + c = cookie_array[i]; + + // Left Trim spaces + while (c.charAt(0) == " ") { + c = c.substring(1, c.length); + } + eq_index = c.indexOf("="); + if (eq_index > 0) { + name = c.substring(0, eq_index); + value = c.substring(eq_index+1); + post_params[name] = value; + } + } + + if (send_to_flash) { + this.setPostParams(post_params); + } + }; + +} diff --git a/wp-includes/js/swfupload/plugins/swfupload.documentready.js b/wp-includes/js/swfupload/plugins/swfupload.documentready.js new file mode 100644 index 000000000..a95bac54e --- /dev/null +++ b/wp-includes/js/swfupload/plugins/swfupload.documentready.js @@ -0,0 +1,102 @@ +/* + DocumentReady Plug-in + + This plugin loads SWFUpload as soon as the document is ready. You should not load SWFUpload inside window.onload using this plugin. + You can also chain other functions by calling SWFUpload.DocumentReady(your function). + + Warning: Embedded Ads or other scripts that overwrite window.onload or use their own document ready functions may interfer with this plugin. You + should not set window.onload when using this plugin. + + Usage Example: + + var swfu = new SWFUpload(your settings object); + SWFUpload.DocumentReady(function () { alert('Document Ready!'; }); + +*/ + +var SWFUpload; +if (typeof(SWFUpload) === "function") { + // Override iniSWFUpload so SWFUpload gets inited when the document is ready rather than immediately + SWFUpload.prototype.initSWFUpload = function (old_initSWFUpload) { + return function (init_settings) { + var self = this; + if (typeof(old_initSWFUpload) === "function") { + SWFUpload.DocumentReady(function () { + old_initSWFUpload.call(self, init_settings); + }); + } + } + + }(SWFUpload.prototype.initSWFUpload); + + + // The DocumentReady function adds the passed in function to + // the functions that will be executed when the document is ready/loaded + SWFUpload.DocumentReady = function (fn) { + // Add the function to the chain + SWFUpload.DocumentReady.InternalOnloadChain = function (previous_link_fn) { + return function () { + if (typeof(previous_link_fn) === "function") { + previous_link_fn(); + } + fn(); + }; + }(SWFUpload.DocumentReady.InternalOnloadChain); + }; + SWFUpload.DocumentReady.InternalOnloadChain = null; + SWFUpload.DocumentReady.Onload = function () { + // Execute the onload function chain + if (typeof(SWFUpload.DocumentReady.InternalOnloadChain) === "function") { + SWFUpload.DocumentReady.InternalOnloadChain(); + } + }; + SWFUpload.DocumentReady.SetupComplete = false; + + + /* ******************************************** + This portion of the code gets executed as soon it is loaded. + It binds the proper event for executing JavaScript is + early as possible. This is a per browser function and so + some browser sniffing is used. + + This solution still has the "exposed" issue (See the Global Delegation section at http://peter.michaux.ca/article/553 ) + + Base solution from http://dean.edwards.name/weblog/2006/06/again/ and http://dean.edwards.name/weblog/2005/09/busted/ + ******************************************** */ + if (!SWFUpload.DocumentReady.SetupComplete) { + // for Internet Explorer (using conditional comments) + /*@cc_on @*/ + /*@if (@_win32) + document.write("