diff --git src/wp-admin/async-upload.php src/wp-admin/async-upload.php
index add6164..9a326ac 100644
|
|
|
|
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | | * Accepts file uploads from swfupload or other asynchronous upload methods. |
| | 3 | * Server-side file upload handler from wp-plupload, swfupload or other asynchronous upload methods. |
| 4 | 4 | * |
| 5 | 5 | * @package WordPress |
| 6 | 6 | * @subpackage Administration |
diff --git src/wp-includes/js/plupload/wp-plupload.js src/wp-includes/js/plupload/wp-plupload.js
index b13db43..09a37ce 100644
|
|
|
window.wp = window.wp || {};
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | | * An object that helps create a WordPress uploader using plupload. |
| | 13 | * A WordPress uploader. |
| 14 | 14 | * |
| 15 | | * @param options - object - The options passed to the new plupload instance. |
| 16 | | * Accepts the following parameters: |
| 17 | | * - container - The id of uploader container. |
| 18 | | * - browser - The id of button to trigger the file select. |
| 19 | | * - dropzone - The id of file drop target. |
| 20 | | * - plupload - An object of parameters to pass to the plupload instance. |
| 21 | | * - params - An object of parameters to pass to $_POST when uploading the file. |
| 22 | | * Extends this.plupload.multipart_params under the hood. |
| | 15 | * The Plupload library provides cross-browser uploader UI integration. |
| | 16 | * This object bridges the Plupload API to integrate uploads into the |
| | 17 | * WordPress back-end and the WordPress media experience. |
| 23 | 18 | * |
| 24 | | * @param attributes - object - Attributes and methods for this specific instance. |
| | 19 | * @param {object} options The options passed to the new plupload instance. |
| | 20 | * @param {object} options.container The id of uploader container. |
| | 21 | * @param {object} options.browser The id of button to trigger the file select. |
| | 22 | * @param {object} options.dropzone The id of file drop target. |
| | 23 | * @param {object} options.plupload An object of parameters to pass to the plupload instance. |
| | 24 | * @param {object} options.params An object of parameters to pass to $_POST when uploading the file. |
| | 25 | * Extends this.plupload.multipart_params under the hood. |
| 25 | 26 | */ |
| 26 | 27 | Uploader = function( options ) { |
| 27 | 28 | var self = this, |
| … |
… |
window.wp = window.wp || {};
|
| 43 | 44 | return; |
| 44 | 45 | } |
| 45 | 46 | |
| | 47 | // Arguments to send to pluplad.Uploader(). |
| 46 | 48 | // Use deep extend to ensure that multipart_params and other objects are cloned. |
| 47 | 49 | this.plupload = $.extend( true, { multipart_params: {} }, Uploader.defaults ); |
| 48 | 50 | this.container = document.body; // Set default container. |
| 49 | 51 | |
| 50 | | // Extend the instance with options |
| | 52 | // Extend the instance with options. |
| 51 | 53 | // |
| 52 | 54 | // Use deep extend to allow options.plupload to override individual |
| 53 | 55 | // default plupload keys. |
| … |
… |
window.wp = window.wp || {};
|
| 60 | 62 | } |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | | // Ensure all elements are jQuery elements and have id attributes |
| 64 | | // Then set the proper plupload arguments to the ids. |
| | 65 | // Ensure all elements are jQuery elements and have id attributes, |
| | 66 | // then set the proper plupload arguments to the ids. |
| 65 | 67 | for ( key in elements ) { |
| 66 | 68 | if ( ! this[ key ] ) { |
| 67 | 69 | continue; |
| … |
… |
window.wp = window.wp || {};
|
| 94 | 96 | this.plupload.required_features.send_binary_string = true; |
| 95 | 97 | } |
| 96 | 98 | |
| | 99 | // Initialize the plupload instance. |
| 97 | 100 | this.uploader = new plupload.Uploader( this.plupload ); |
| 98 | 101 | delete this.plupload; |
| 99 | 102 | |
| … |
… |
window.wp = window.wp || {};
|
| 101 | 104 | this.param( this.params || {} ); |
| 102 | 105 | delete this.params; |
| 103 | 106 | |
| | 107 | /** |
| | 108 | * Custom error callback. |
| | 109 | * |
| | 110 | * Add a new error to the errors collection, so other modules can track |
| | 111 | * and display errors. @see wp.Uploader.errors. |
| | 112 | * |
| | 113 | * @param {string} message |
| | 114 | * @param {object} data |
| | 115 | * @param {plupload.File} file File that was uploaded. |
| | 116 | */ |
| 104 | 117 | error = function( message, data, file ) { |
| 105 | 118 | if ( file.attachment ) { |
| 106 | 119 | file.attachment.destroy(); |
| … |
… |
window.wp = window.wp || {};
|
| 115 | 128 | self.error( message, data, file ); |
| 116 | 129 | }; |
| 117 | 130 | |
| | 131 | /** |
| | 132 | * After the Uploader has been initialized, initialize some behaviors for the dropzone. |
| | 133 | * |
| | 134 | * @param {plupload.Uploader} uploader Uploader instance. |
| | 135 | */ |
| 118 | 136 | this.uploader.bind( 'init', function( uploader ) { |
| 119 | 137 | var timer, active, dragdrop, |
| 120 | 138 | dropzone = self.dropzone; |
| … |
… |
window.wp = window.wp || {};
|
| 132 | 150 | return dropzone.unbind('.wp-uploader'); |
| 133 | 151 | } |
| 134 | 152 | |
| 135 | | // 'dragenter' doesn't fire correctly, |
| 136 | | // simulate it with a limited 'dragover' |
| | 153 | // 'dragenter' doesn't fire correctly, simulate it with a limited 'dragover'. |
| 137 | 154 | dropzone.bind( 'dragover.wp-uploader', function() { |
| 138 | 155 | if ( timer ) { |
| 139 | 156 | clearTimeout( timer ); |
| … |
… |
window.wp = window.wp || {};
|
| 152 | 169 | // being quickly removed and re-added when elements inside the |
| 153 | 170 | // dropzone are repositioned. |
| 154 | 171 | // |
| 155 | | // See https://core.trac.wordpress.org/ticket/21705 |
| | 172 | // @see https://core.trac.wordpress.org/ticket/21705 |
| 156 | 173 | timer = setTimeout( function() { |
| 157 | 174 | active = false; |
| 158 | 175 | dropzone.trigger('dropzone:leave').removeClass('drag-over'); |
| 159 | 176 | }, 0 ); |
| 160 | 177 | }); |
| 161 | | |
| | 178 | |
| 162 | 179 | self.ready = true; |
| 163 | 180 | $(self).trigger( 'uploader:ready' ); |
| 164 | 181 | }); |
| … |
… |
window.wp = window.wp || {};
|
| 173 | 190 | $('#' + this.uploader.id + '_html5_container').hide(); |
| 174 | 191 | } |
| 175 | 192 | |
| | 193 | /** |
| | 194 | * After files were filtered and added to the queue, create a model for each. |
| | 195 | * |
| | 196 | * @event FilesAdded |
| | 197 | * @param {plupload.Uploader} uploader Uploader instance. |
| | 198 | * @param {Array} files Array of file objects that were added to queue by the user. |
| | 199 | */ |
| 176 | 200 | this.uploader.bind( 'FilesAdded', function( up, files ) { |
| 177 | 201 | _.each( files, function( file ) { |
| 178 | 202 | var attributes, image; |
| … |
… |
window.wp = window.wp || {};
|
| 195 | 219 | // Handle early mime type scanning for images. |
| 196 | 220 | image = /(?:jpe?g|png|gif)$/i.exec( file.name ); |
| 197 | 221 | |
| 198 | | // Did we find an image? |
| | 222 | // For images set the model's type and subtype attributes. |
| 199 | 223 | if ( image ) { |
| 200 | 224 | attributes.type = 'image'; |
| 201 | 225 | |
| … |
… |
window.wp = window.wp || {};
|
| 204 | 228 | attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0]; |
| 205 | 229 | } |
| 206 | 230 | |
| 207 | | // Create the `Attachment`. |
| | 231 | // Create a model for the attachment, and add it to the Upload queue collection |
| | 232 | // so listeners to the upload queue can track and display upload progress. |
| 208 | 233 | file.attachment = wp.media.model.Attachment.create( attributes ); |
| 209 | | |
| 210 | 234 | Uploader.queue.add( file.attachment ); |
| 211 | 235 | |
| 212 | 236 | self.added( file.attachment ); |
| … |
… |
window.wp = window.wp || {};
|
| 221 | 245 | self.progress( file.attachment ); |
| 222 | 246 | }); |
| 223 | 247 | |
| | 248 | /** |
| | 249 | * After a file is successfully uploaded, update its model. |
| | 250 | * |
| | 251 | * @param {plupload.Uploader} uploader Uploader instance. |
| | 252 | * @param {plupload.File} file File that was uploaded. |
| | 253 | * @param {Object} response Object with response properties. |
| | 254 | * @return {mixed} |
| | 255 | */ |
| 224 | 256 | this.uploader.bind( 'FileUploaded', function( up, file, response ) { |
| 225 | 257 | var complete; |
| 226 | 258 | |
| … |
… |
window.wp = window.wp || {};
|
| 252 | 284 | self.success( file.attachment ); |
| 253 | 285 | }); |
| 254 | 286 | |
| | 287 | /** |
| | 288 | * When plupload surfaces an error, send it to the error handler. |
| | 289 | * |
| | 290 | * @param {plupload.Uploader} uploader Uploader instance. |
| | 291 | * @param {Object} error Contains code, message and sometimes file and other details. |
| | 292 | */ |
| 255 | 293 | this.uploader.bind( 'Error', function( up, pluploadError ) { |
| 256 | 294 | var message = pluploadL10n.default_error, |
| 257 | 295 | key; |
| … |
… |
window.wp = window.wp || {};
|
| 283 | 321 | |
| 284 | 322 | Uploader.uuid = 0; |
| 285 | 323 | |
| | 324 | // Map Plupload error codes to user friendly error messages. |
| 286 | 325 | Uploader.errorMap = { |
| 287 | 326 | 'FAILED': pluploadL10n.upload_failed, |
| 288 | 327 | 'FILE_EXTENSION_ERROR': pluploadL10n.invalid_filetype, |
| … |
… |
window.wp = window.wp || {};
|
| 324 | 363 | } |
| 325 | 364 | }, |
| 326 | 365 | |
| | 366 | /** |
| | 367 | * Make a few internal event callbacks available on the wp.Uploader object |
| | 368 | * to change the Uploader internals if absolutely necessary. |
| | 369 | */ |
| 327 | 370 | init: function() {}, |
| 328 | 371 | error: function() {}, |
| 329 | 372 | success: function() {}, |
| … |
… |
window.wp = window.wp || {};
|
| 370 | 413 | } |
| 371 | 414 | }); |
| 372 | 415 | |
| | 416 | // Create a collection of attachments in the upload queue, |
| | 417 | // so that other modules can track and display upload progress. |
| 373 | 418 | Uploader.queue = new wp.media.model.Attachments( [], { query: false }); |
| | 419 | |
| | 420 | // Create a collection to collect errors incurred while attempting upload. |
| 374 | 421 | Uploader.errors = new Backbone.Collection(); |
| 375 | 422 | |
| 376 | 423 | exports.Uploader = Uploader; |