Make WordPress Core

Changeset 18482


Ignore:
Timestamp:
07/29/2011 08:59:35 AM (15 years ago)
Author:
azaozz
Message:

Pluploader take 1, props jacobwg, see #18206

Location:
trunk
Files:
13 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/wp-admin.dev.css

    r18453 r18482  
    33073307------------------------------------------------------------------------------*/
    33083308
     3309div.plupload input {
     3310        cursor: pointer;
     3311}
     3312
    33093313.find-box {
    33103314        width: 500px;
  • trunk/wp-admin/includes/file.php

    r18447 r18482  
    324324        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
    325325
     326        $tmp_file = wp_tempnam($filename);
     327
    326328        // Move the file to the uploads dir
     329        if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) )
     330                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
     331
     332        // If a resize was requested, perform the resize.
     333        $do_resize = apply_filters( 'wp_upload_resize', isset( $_REQUEST['image_resize'] ) );
     334        $size = @getimagesize( $tmp_file );
     335        if ( $do_resize && $size ) {
     336                $old_temp = $tmp_file;
     337                $tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized');
     338                if ( ! is_wp_error($tmp_file) ) {
     339                        unlink($old_temp);
     340                } else {
     341                        $tmp_file = $old_temp;
     342                }
     343        }
     344
     345        // Copy the temporary file into its destination
    327346        $new_file = $uploads['path'] . "/$filename";
    328         if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
    329                 return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
    330 
     347        copy( $tmp_file, $new_file );
     348        unlink($tmp_file);
     349       
    331350        // Set correct file permissions
    332351        $stat = stat( dirname( $new_file ));
  • trunk/wp-admin/includes/media.php

    r18460 r18482  
    14381438        global $type, $tab, $pagenow;
    14391439
    1440         $flash_action_url = admin_url('async-upload.php');
    1441 
    1442         // If Mac and mod_security, no Flash. :(
    1443         $flash = true;
    1444         if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') )
    1445                 $flash = false;
    1446 
    1447         $flash = apply_filters('flash_uploader', $flash);
     1440        $upload_action_url = admin_url('async-upload.php');
     1441
    14481442        $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
    14491443
    … …  
    14591453        }
    14601454?>
    1461 <script type="text/javascript">
    1462 //<![CDATA[
    1463 var uploaderMode = 0;
    1464 jQuery(document).ready(function($){
    1465         uploaderMode = getUserSetting('uploader');
    1466         $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
    1467         $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
    1468 });
    1469 //]]>
    14701455</script>
    14711456<div id="media-upload-notice">
    … …  
    14881473do_action('pre-upload-ui');
    14891474
    1490 if ( $flash ) :
    1491 
    1492 // Set the post params, which SWFUpload will post back with the file, and pass
     1475// Set the post params, which plupload will post back with the file, and pass
    14931476// them through a filter.
    14941477$post_params = array(
    … …  
    15011484                "short" => "1",
    15021485);
    1503 $post_params = apply_filters( 'swfupload_post_params', $post_params );
     1486$post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params'
    15041487$p = array();
    15051488foreach ( $post_params as $param => $val )
    … …  
    15071490$post_params_str = implode( ", \n", $p );
    15081491
    1509 // #8545. wmode=transparent cannot be used with SWFUpload
    1510 if ( 'media-new.php' == $pagenow ) {
    1511         $upload_image_path = get_user_option( 'admin_color' );
    1512         if ( 'classic' != $upload_image_path )
    1513                 $upload_image_path = 'fresh';
    1514         $upload_image_path = admin_url( 'images/upload-' . $upload_image_path . '.png?ver=20101205' );
    1515 } else {
    1516         $upload_image_path = includes_url( 'images/upload.png?ver=20100531' );
    1517 }
    1518 
    15191492?>
    15201493<script type="text/javascript">
    15211494//<![CDATA[
    1522 var swfu;
    1523 SWFUpload.onload = function() {
    1524         var settings = {
    1525                         button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>',
    1526                         button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }',
    1527                         button_height: "23",
    1528                         button_width: "132",
    1529                         button_text_top_padding: 3,
    1530                         button_image_url: '<?php echo $upload_image_path; ?>',
    1531                         button_placeholder_id: "flash-browse-button",
    1532                         upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
    1533                         flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
    1534                         file_post_name: "async-upload",
    1535                         file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
    1536                         post_params : {
    1537                                 <?php echo $post_params_str; ?>
    1538                         },
    1539                         file_size_limit : "<?php echo $max_upload_size; ?>b",
    1540                         file_dialog_start_handler : fileDialogStart,
    1541                         file_queued_handler : fileQueued,
    1542                         upload_start_handler : uploadStart,
    1543                         upload_progress_handler : uploadProgress,
    1544                         upload_error_handler : uploadError,
    1545                         upload_success_handler : <?php echo apply_filters( 'swfupload_success_handler', 'uploadSuccess' ); ?>,
    1546                         upload_complete_handler : uploadComplete,
    1547                         file_queue_error_handler : fileQueueError,
    1548                         file_dialog_complete_handler : fileDialogComplete,
    1549                         swfupload_pre_load_handler: swfuploadPreLoad,
    1550                         swfupload_load_failed_handler: swfuploadLoadFailed,
    1551                         custom_settings : {
    1552                                 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
    1553                                 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
    1554                         },
    1555                         debug: false
    1556                 };
    1557                 swfu = new SWFUpload(settings);
    1558 };
     1495var resize_height = <?php echo get_option('large_size_h'); ?>,
     1496        resize_width = <?php echo get_option('large_size_w'); ?>;
     1497
     1498jQuery(document).ready(function($) {
     1499        window.uploader = new plupload.Uploader({
     1500                runtimes: '<?php echo apply_filters('plupload_runtimes', 'html5,silverlight,flash,html4'); ?>',
     1501                browse_button: 'plupload-browse-button',
     1502                container: 'plupload-upload-ui',
     1503                drop_element: 'media-upload',
     1504                file_data_name: 'async-upload',
     1505                max_file_size: '<?php echo $max_upload_size / 1024; ?>kb',
     1506                url: '<?php echo esc_attr( $upload_action_url ); ?>',
     1507                flash_swf_url: '<?php echo includes_url('js/plupload/plupload.flash.swf'); ?>',
     1508                silverlight_xap_url: '<?php echo includes_url('js/plupload/plupload.silverlight.xap'); ?>',
     1509                filters: [
     1510                        {title: '<?php _e( 'Allowed Files' ); ?>', extensions: '<?php echo apply_filters('upload_file_glob', '*'); ?>'}
     1511                ],
     1512                multipart: true,
     1513                urlstream_upload: true,
     1514                multipart_params : {
     1515                        <?php echo $post_params_str; ?>
     1516                }
     1517        });
     1518
     1519        setResize( getUserSetting('upload_resize', false) );
     1520       
     1521        $('#image_resize').bind('change', function() {
     1522                var arg = $(this).prop('checked');
     1523
     1524                setResize( arg );
     1525
     1526                if ( arg )
     1527                        setUserSetting('upload_resize', 1);
     1528                else
     1529                        deleteUserSetting('upload_resize');
     1530        });
     1531
     1532        uploader.init();
     1533
     1534console.debug(uploader);
     1535console.debug(uploader.runtime)
     1536
     1537
     1538        uploader.bind('FilesAdded', function(up, files) {
     1539                $.each(files, function(i, file) {
     1540                        fileQueued(file);
     1541                });
     1542
     1543                up.refresh();
     1544                up.start();
     1545        });
     1546
     1547        uploader.bind('BeforeUpload', function(up, file) {
     1548                uploadStart(file);
     1549        });
     1550       
     1551        uploader.bind('UploadProgress', function(up, file) {
     1552                uploadProgress(file, file.loaded, file.size);
     1553        });
     1554       
     1555        uploader.bind('Error', function(up, err) {
     1556                uploadError(err.file, err.code, err.message);
     1557       
     1558                up.refresh();
     1559        });
     1560
     1561        uploader.bind('FileUploaded', function(up, file, response) {
     1562                <?php echo apply_filters( 'plupload_success_handler', 'uploadSuccess' ); ?>(file, response.response);
     1563        });
     1564       
     1565        if ( uploader.runtime == 'html5' )
     1566                $('.dragdrop-info').show();
     1567
     1568});
    15591569//]]>
    15601570</script>
    15611571
    1562 <div id="flash-upload-ui" class="hide-if-no-js">
    1563 <?php do_action('pre-flash-upload-ui'); ?>
     1572<div id="plupload-upload-ui" class="hide-if-no-js">
     1573<?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?>
    15641574
    15651575        <div>
    15661576        <?php _e( 'Choose files to upload' ); ?>
    1567         <div id="flash-browse-button"></div>
    1568         <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
     1577        <input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" />
     1578        <input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" />
    15691579        </div>
    1570         <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
    1571 <?php do_action('post-flash-upload-ui'); ?>
    1572         <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
     1580        <p class="dragdrop-info howto"><?php _e('Or you can drop the files into this window.'); ?></p>
     1581<?php do_action('post-plupload-upload-ui'); // hook change, old name: 'post-flash-upload-ui' ?>
    15731582</div>
    1574 <?php endif; // $flash ?>
    1575 
    1576 <div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>
     1583
     1584<div id="html-upload-ui" class="hide-if-js">
    15771585<?php do_action('pre-html-upload-ui'); ?>
    15781586        <p id="async-upload-wrap">
    … …  
    15831591        </p>
    15841592        <div class="clear"></div>
    1585         <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
    1586         <?php if ( is_lighttpd_before_150() ): ?>
    1587         <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.'); ?></p>
    1588         <?php endif;?>
    1589 <?php do_action('post-html-upload-ui', $flash); ?>
     1593<?php do_action('post-html-upload-ui', $plupload); ?>
    15901594</div>
     1595
     1596<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
     1597<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
     1598
    15911599<?php do_action('post-upload-ui'); ?>
    15921600<?php
    … …  
    22732281 * {@internal Missing Short Description}}
    22742282 *
    2275  * Support a GET parameter for disabling the flash uploader.
    2276  *
    22772283 * @since 2.6.0
    2278  *
    2279  * @param unknown_type $flash
    2280  * @return unknown
    2281  */
    2282 function media_upload_use_flash($flash) {
    2283         if ( array_key_exists('flash', $_REQUEST) )
    2284                 $flash = !empty($_REQUEST['flash']);
    2285         return $flash;
    2286 }
    2287 
    2288 add_filter('flash_uploader', 'media_upload_use_flash');
    2289 
    2290 /**
    2291  * {@internal Missing Short Description}}
    2292  *
    2293  * @since 2.6.0
    2294  */
    2295 function media_upload_flash_bypass() {
    2296         echo '<p class="upload-flash-bypass">';
    2297         printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
    2298         echo '</p>';
    2299 }
    2300 
    2301 /**
    2302  * {@internal Missing Short Description}}
    2303  *
    2304  * @since 2.6.0
    2305  */
    2306 function media_upload_html_bypass($flash = true) {
    2307         echo '<p class="upload-html-bypass hide-if-no-js">';
    2308         _e('You are using the Browser uploader.');
    2309         if ( $flash ) {
    2310                 // the user manually selected the browser uploader, so let them switch back to Flash
    2311                 echo ' ';
    2312                 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
    2313         }
    2314         echo "</p>\n";
    2315 }
    2316 
    2317 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
    2318 add_action('post-html-upload-ui', 'media_upload_html_bypass');
    2319 
    2320 /**
    2321  * {@internal Missing Short Description}}
    2322  *
    2323  * Make sure the GET parameter sticks when we submit a form.
    2324  *
    2325  * @since 2.6.0
    2326  *
    2327  * @param unknown_type $url
    2328  * @return unknown
    2329  */
    2330 function media_upload_bypass_url($url) {
    2331         if ( array_key_exists('flash', $_REQUEST) )
    2332                 $url = add_query_arg('flash', intval($_REQUEST['flash']));
    2333         return $url;
    2334 }
    2335 
    2336 add_filter('media_upload_form_url', 'media_upload_bypass_url');
     2284 */
     2285function media_upload_max_image_resize() {
     2286?>
     2287<input name="image_resize" type="checkbox" id="image_resize" value="1" />
     2288<label for="image_resize"><?php printf( __( 'Scale images to max width %1$dpx or max height %2$dpx'), get_option('large_size_w'), get_option('large_size_h') ); ?></label>
     2289<?php
     2290}
     2291
     2292add_action('post-upload-ui', 'media_upload_max_image_resize');
    23372293
    23382294add_filter('async_upload_image', 'get_media_item', 10, 2);
  • trunk/wp-admin/media-upload.php

    r17748 r18482  
    1919        wp_die(__('You do not have permission to upload files.'));
    2020
    21 wp_enqueue_script('swfupload-all');
    22 wp_enqueue_script('swfupload-handlers');
     21wp_enqueue_script('plupload-full');
     22wp_enqueue_script('plupload-handlers');
    2323wp_enqueue_script('image-edit');
    2424wp_enqueue_script('set-post-thumbnail' );
  • trunk/wp-includes/js/thickbox/thickbox.css

    r10428 r18482  
    5050        z-index: 102;
    5151        color:#000000;
    52         display:none;
     52        visibility: hidden;
    5353        text-align:left;
    5454        top:50%;
  • trunk/wp-includes/js/thickbox/thickbox.js

    r18070 r18482  
    270270function tb_showIframe(){
    271271        jQuery("#TB_load").remove();
    272         jQuery("#TB_window").css({display:"block"});
     272        jQuery("#TB_window").css({'visibility':'visible'});
    273273}
    274274
  • trunk/wp-includes/script-loader.php

    r18479 r18482  
    199199        $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113');
    200200
    201         $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", false, '2.2');
    202 
    203         $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2201-20110113');
    204         $scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
    205         $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
    206         $scripts->add( 'swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
    207 
    208         if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
     201
     202        $scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', false, '1.4.3.2');
     203        $scripts->add( 'plupload-html5', '/wp-includes/js/plupload/plupload.html5.js', array('plupload'), '1.4.3.2');
     204        $scripts->add( 'plupload-flash', '/wp-includes/js/plupload/plupload.flash.js', array('plupload'), '1.4.3.2');
     205        $scripts->add( 'plupload-silverlight', '/wp-includes/js/plupload/plupload.silverlight.js', array('plupload'), '1.4.3.2');
     206        $scripts->add( 'plupload-gears', '/wp-includes/js/plupload/plupload.gears.js', array('plupload'), '1.4.3.2');
     207        $scripts->add( 'plupload-html4', '/wp-includes/js/plupload/plupload.html4.js', array('plupload'), '1.4.3.2');
     208
     209        // TODO: find out if we can use the plupload.full.js (it does load browserplus)
     210        $scripts->add( 'plupload-full', false, array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-gears', 'plupload-html4'), '1.4.3.2');
     211
     212        $scripts->add( 'plupload-handlers', '/wp-includes/js/plupload/handlers.js', array('plupload-full', 'jquery'), '1.4.3.2');
     213       
     214        // TODO: find out if we really need this debug clause with plupload
     215        /*if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
    209216                // queue all SWFUpload scripts that are used by default
    210217                $scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
    211218        } else {
    212                 $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201a');
    213         }
    214 
    215         $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
     219                $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201');
     220        }*/
     221
    216222        $max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post;
    217223        if ( empty($max_upload_size) )
    218224                $max_upload_size = __('not configured');
    219         // these error messages came from the sample swfupload js, they might need changing.
    220         $scripts->add_script_data( 'swfupload-handlers', 'swfuploadL10n', array(
    221                         'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
     225
     226        $scripts->add_script_data( 'plupload-handlers', 'pluploadL10n', array(
    222227                        'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'),
    223228                        'zero_byte_file' => __('This file is empty. Please try another.'),
    224229                        'invalid_filetype' => __('This file type is not allowed. Please try another.'),
     230                        'not_an_image' => __('This file is not an image. Please try another.'),
     231                        'image_memory_exceeded' => __('Memery exceeded. Please try another smaller file.'),
     232                        'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'),
    225233                        'default_error' => __('An error occurred in the upload. Please try again later.'),
    226234                        'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
    … …  
    235243                        'crunching' => __('Crunching&hellip;'),
    236244                        'deleted' => __('moved to the trash.'),
    237                         'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error')
     245                        'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error'),
    238246        ) );
    239247
Note: See TracChangeset for help on using the changeset viewer.