From 263d9c7f3325869c767e779625c53a521f2b1b99 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 23 Mar 2014 23:44:20 +0000 Subject: [PATCH] Plupload: switch to urlstream upload method when the 'flash' runtime is used in non IE browsers. This ensures cookies are sent but limits the maximum file size that flash can handle. By default only IE9 and older use flash so this change is mostly for completeness. It would affect only the (extremely rare) cases where a plugin disables the html5 runtime. git-svn-id: https://develop.svn.wordpress.org/trunk@27662 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/media.php | 2 +- src/wp-includes/js/plupload/handlers.js | 13 ++++++++++++- src/wp-includes/js/plupload/wp-plupload.js | 9 +++++++++ src/wp-includes/media.php | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 678df7921b..04295dabd6 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -1760,7 +1760,7 @@ $post_params = array( $post_params = apply_filters( 'upload_post_params', $post_params ); $plupload_init = array( - 'runtimes' => 'html5,silverlight,flash,html4', + 'runtimes' => 'html5,flash,silverlight,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', diff --git a/src/wp-includes/js/plupload/handlers.js b/src/wp-includes/js/plupload/handlers.js index b7d77dc7bf..2140f0f5df 100644 --- a/src/wp-includes/js/plupload/handlers.js +++ b/src/wp-includes/js/plupload/handlers.js @@ -400,6 +400,16 @@ jQuery(document).ready(function($){ // init and set the uploader uploader_init = function() { + var isIE = navigator.userAgent.indexOf('Trident/') != -1 || navigator.userAgent.indexOf('MSIE ') != -1; + + // Make sure flash sends cookies (seems in IE it does whitout switching to urlstream mode) + if ( ! isIE && 'flash' === plupload.predictRuntime( wpUploaderInit ) && + ( ! wpUploaderInit.required_features || ! wpUploaderInit.required_features.hasOwnProperty( 'send_binary_string' ) ) ) { + + wpUploaderInit.required_features = wpUploaderInit.required_features || {}; + wpUploaderInit.required_features.send_binary_string = true; + } + uploader = new plupload.Uploader(wpUploaderInit); $('#image_resize').bind('change', function() { @@ -430,8 +440,9 @@ jQuery(document).ready(function($){ $('#drag-drop-area').unbind('.wp-uploader'); } - if ( up.runtime == 'html4' ) + if ( up.runtime === 'html4' ) { $('.upload-flash-bypass').hide(); + } }); uploader.init(); diff --git a/src/wp-includes/js/plupload/wp-plupload.js b/src/wp-includes/js/plupload/wp-plupload.js index d8476caffd..9f7262c241 100644 --- a/src/wp-includes/js/plupload/wp-plupload.js +++ b/src/wp-includes/js/plupload/wp-plupload.js @@ -25,6 +25,7 @@ window.wp = window.wp || {}; */ Uploader = function( options ) { var self = this, + isIE = navigator.userAgent.indexOf('Trident/') != -1 || navigator.userAgent.indexOf('MSIE ') != -1, elements = { container: 'container', browser: 'browse_button', @@ -85,6 +86,14 @@ window.wp = window.wp || {}; return; } + // Make sure flash sends cookies (seems in IE it does whitout switching to urlstream mode) + if ( ! isIE && 'flash' === plupload.predictRuntime( this.plupload ) && + ( ! this.plupload.required_features || ! this.plupload.required_features.hasOwnProperty( 'send_binary_string' ) ) ) { + + this.plupload.required_features = this.plupload.required_features || {}; + this.plupload.required_features.send_binary_string = true; + } + this.uploader = new plupload.Uploader( this.plupload ); delete this.plupload; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index f038c39838..23fdbc0bcc 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2176,7 +2176,7 @@ function wp_plupload_default_settings() { $max_upload_size = wp_max_upload_size(); $defaults = array( - 'runtimes' => 'html5,silverlight,flash,html4', + 'runtimes' => 'html5,flash,silverlight,html4', 'file_data_name' => 'async-upload', // key passed to $_FILE. 'url' => admin_url( 'async-upload.php', 'relative' ), 'flash_swf_url' => includes_url( 'js/plupload/Moxie.swf' ),