Make WordPress Core


Ignore:
Timestamp:
09/15/2011 05:30:58 AM (13 years ago)
Author:
azaozz
Message:

Improve handling of plupload init and add a filter, stop including cookies in the init (not needed with plupload), see #18206

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r18596 r18674  
    14711471do_action('pre-upload-ui');
    14721472
    1473 // Set the post params, which plupload will post back with the file, and pass
    1474 // them through a filter.
    14751473$post_params = array(
    14761474        "post_id" => $post_id,
    1477         "auth_cookie" => (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]),
    1478         "logged_in_cookie" => $_COOKIE[LOGGED_IN_COOKIE],
    14791475        "_wpnonce" => wp_create_nonce('media-form'),
    14801476        "type" => $type,
     
    14841480
    14851481$post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params'
    1486 $p = array();
    1487 
    1488 foreach ( $post_params as $param => $val ) {
    1489     $val = esc_js( $val );
    1490     $p[] = "'$param' : '$val'";
    1491 }
    1492 
    1493 $post_params_str = implode( ',', $p ). "\n";
     1482
     1483$plupload_init = array(
     1484    'runtimes' => 'html5,silverlight,flash,html4',
     1485    'browse_button' => 'plupload-browse-button',
     1486    'container' => 'plupload-upload-ui',
     1487    'drop_element' => 'wpwrap',
     1488    'file_data_name' => 'async-upload',
     1489    'multiple_queues' => true,
     1490    'max_file_size' => round( (int) $max_upload_size / 1024 ) . 'kb',
     1491    'url' => $upload_action_url,
     1492    'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
     1493    'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
     1494    'filters' => array( array('title' => __( 'Allowed Files' ), 'extensions' => '*') ),
     1495    'multipart' => true,
     1496    'urlstream_upload' => true,
     1497    'multipart_params' => $post_params
     1498);
     1499
     1500$plupload_init = apply_filters( 'plupload_init', $plupload_init );
    14941501
    14951502?>
     1503
    14961504<script type="text/javascript">
    1497 //<![CDATA[
    1498 var resize_height = <?php echo get_option('large_size_h', 1024); ?>,
    1499     resize_width = <?php echo get_option('large_size_w', 1024); ?>;
    1500 
    1501 jQuery(document).ready(function($) {
    1502     window.uploader = new plupload.Uploader({
    1503         runtimes: '<?php echo apply_filters('plupload_runtimes', 'html5,silverlight,flash,html4'); ?>',
    1504         browse_button: 'plupload-browse-button',
    1505         container: 'plupload-upload-ui',
    1506         drop_element: 'media-upload',
    1507         file_data_name: 'async-upload',
    1508         max_file_size: '<?php echo round( (int) $max_upload_size / 1024 ); ?>kb',
    1509         url: '<?php echo esc_js( $upload_action_url ); ?>',
    1510         flash_swf_url: '<?php echo esc_js( includes_url('js/plupload/plupload.flash.swf') ); ?>',
    1511         silverlight_xap_url: '<?php echo esc_js( includes_url('js/plupload/plupload.silverlight.xap') ); ?>',
    1512         filters: [
    1513             {title: '<?php echo esc_js( __( 'Allowed Files' ) ); ?>', extensions: '<?php echo esc_js( apply_filters('uploader_allowed_extensions', '*') ); ?>'}
    1514         ],
    1515         multipart: true,
    1516         urlstream_upload: true,
    1517         multipart_params : {
    1518             <?php echo $post_params_str; ?>
    1519         }
    1520     });
    1521 
    1522     setResize( getUserSetting('upload_resize', false) );
    1523    
    1524     $('#image_resize').bind('change', function() {
    1525         var arg = $(this).prop('checked');
    1526 
    1527         setResize( arg );
    1528 
    1529         if ( arg )
    1530             setUserSetting('upload_resize', 1);
    1531         else
    1532             deleteUserSetting('upload_resize');
    1533     });
    1534 
    1535     uploader.init();
    1536 
    1537     uploader.bind('FilesAdded', function(up, files) {
    1538         $.each(files, function(i, file) {
    1539             fileQueued(file);
    1540         });
    1541 
    1542         up.refresh();
    1543         up.start();
    1544     });
    1545 
    1546     uploader.bind('BeforeUpload', function(up, file) {
    1547         uploadStart(file);
    1548     });
    1549    
    1550     uploader.bind('UploadProgress', function(up, file) {
    1551         uploadProgress(file, file.loaded, file.size);
    1552     });
    1553    
    1554     uploader.bind('Error', function(up, err) {
    1555         uploadError(err.file, err.code, err.message);
    1556    
    1557         up.refresh();
    1558     });
    1559 
    1560     uploader.bind('FileUploaded', function(up, file, response) {
    1561         <?php echo apply_filters( 'plupload_success_handler', 'uploadSuccess' ); ?>(file, response.response);
    1562     });
    1563    
    1564     if ( uploader.runtime == 'html5' )
    1565         $('.dragdrop-info').show();
    1566 });
    1567 //]]>
     1505var resize_height = <?php echo get_option('large_size_h', 1024); ?>,
     1506resize_width = <?php echo get_option('large_size_w', 1024); ?>,
     1507wpUploaderInit = <?php echo json_encode($plupload_init); ?>;
    15681508</script>
    15691509
     
    15711511<?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?>
    15721512
    1573     <div>
     1513    <p>
    15741514    <?php _e( 'Choose files to upload' ); ?>
    15751515    <input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" />
    15761516    <input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" />
    1577     </div>
    1578     <p class="dragdrop-info howto"><?php _e('Or you can drop the files into this window.'); ?></p>
     1517    </p>
     1518    <p class="dragdrop-info"><?php _e('Or you can drop the files into this window.'); ?></p>
    15791519<?php do_action('post-plupload-upload-ui'); // hook change, old name: 'post-flash-upload-ui' ?>
    15801520</div>
     
    15891529    </p>
    15901530    <div class="clear"></div>
    1591 <?php do_action('post-html-upload-ui', $plupload); ?>
     1531<?php do_action('post-html-upload-ui'); ?>
    15921532</div>
    15931533
     
    15951535<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
    15961536
    1597 <?php do_action('post-upload-ui'); ?>
    15981537<?php
     1538    do_action('post-upload-ui');
    15991539}
    16001540
     
    22822222 */
    22832223function media_upload_max_image_resize() {
     2224    $checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
    22842225?>
    2285 <label>
    2286 <input name="image_resize" type="checkbox" id="image_resize" value="true" />
     2226<p class="hide-if-no-js"><label>
     2227<input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
    22872228<?php printf( __( 'Scale images to max width %1$dpx or max height %2$dpx' ), (int) get_option( 'large_size_w' ), (int) get_option( 'large_size_h' ) ); ?>
    2288 </label>
     2229</label></p>
    22892230<?php
    22902231}
Note: See TracChangeset for help on using the changeset viewer.