WordPress.org

Make WordPress Core

Ticket #18206: jacobwg-gsoc2011-patch01.diff

File jacobwg-gsoc2011-patch01.diff, 17.0 KB (added by jacobwg, 7 years ago)

Initial patch on latest WP trunk (r18463)

  • wp-admin/includes/file.php

     
    322322                return call_user_func($upload_error_handler, $file, $uploads['error'] );
    323323
    324324        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
     325       
     326        // Temporary file for fixing EXIF rotation and performing scaling (if requested)
     327        $tmp_file = wp_tempnam($filename);
    325328
    326329        // Move the file to the uploads dir
    327         $new_file = $uploads['path'] . "/$filename";
    328         if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
     330        if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) )
    329331                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
    330332
     333        // If a resize was requested, perform the resize.
     334        if ($resize) {
     335                $old_temp = $tmp_file;
     336                $tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized');
     337                if ( ! is_wp_error($tmp_file) ) {
     338                        unlink($old_temp);
     339                }
     340        }
     341
     342        // Copy the temporary file into its destination
     343        $new_file = $uploads['path'] . "/$filename";
     344        copy( $tmp_file, $new_file );
     345        unlink($tmp_file);
     346       
    331347        // Set correct file permissions
    332348        $stat = stat( dirname( $new_file ));
    333349        $perms = $stat['mode'] & 0000666;
  • wp-admin/includes/media.php

     
    14371437function media_upload_form( $errors = null ) {
    14381438        global $type, $tab, $pagenow;
    14391439
    1440         $flash_action_url = admin_url('async-upload.php');
     1440        $upload_action_url = admin_url('async-upload.php');
    14411441
    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);
    14481442        $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
    14491443
    14501444        $upload_size_unit = $max_upload_size =  wp_max_upload_size();
     
    14581452                $upload_size_unit = (int) $upload_size_unit;
    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">
    14721457<?php if (isset($errors['upload_notice']) ) { ?>
     
    14871472
    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(
    14951478                "post_id" => $post_id,
     
    15001483                "tab" => $tab,
    15011484                "short" => "1",
    15021485);
    1503 $post_params = apply_filters( 'swfupload_post_params', $post_params );
     1486$post_params = apply_filters( 'upload_post_params', $post_params );
    15041487$p = array();
    15051488foreach ( $post_params as $param => $val )
    15061489        $p[] = "\t\t'$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_mode = false;
     1496var resize_height = <?php echo get_option('large_size_h'); ?>,
     1497        resize_width = <?php echo get_option('large_size_w'); ?>;
     1498
     1499jQuery(function($) {
     1500        window.uploader = new plupload.Uploader({
     1501                runtimes: '<?php echo apply_filters('plupload_runtimes', 'html5,silverlight,flash,html4'); ?>',
     1502                browse_button: 'plupload-browse-button',
     1503                container: 'plupload-upload-ui',
     1504                drop_element: 'wpwrap',
     1505                file_data_name: 'async-upload',
     1506                max_file_size: '<?php echo $max_upload_size / 1024; ?>kb',
     1507                url: '<?php echo esc_attr( $upload_action_url ); ?>',
     1508                plupload_swf_url: '<?php echo includes_url('js/plupload/plupload.plupload.swf'); ?>',
     1509                silverlight_xap_url: '<?php echo includes_url('js/plupload/plupload.silverlight.xap'); ?>',
     1510                filters: [
     1511                        {title: "Allowed files", extensions: "<?php echo apply_filters('upload_file_glob', '*'); ?>"}
     1512                ],
     1513                multipart: true,
     1514                multipart_params : {
     1515                        <?php echo $post_params_str; ?>
     1516                }
     1517        });
     1518       
     1519        resize_mode = getUserSetting('resize_mode') == 'true';
     1520        setResize(resize_mode)
     1521        $('#image_resize').bind('change', function() {
     1522                setResize($(this).prop('checked'));
     1523        });
     1524
     1525        uploader.init();
     1526
     1527        uploader.bind('FilesAdded', function(up, files) {
     1528                $.each(files, function(i, file) {
     1529                        fileQueued(file);
     1530                });
     1531       
     1532                up.refresh();
     1533                up.start();
     1534        });
     1535
     1536        uploader.bind('BeforeUpload', function(up, file) {
     1537                uploadStart(file);
     1538        });
     1539       
     1540        uploader.bind('UploadProgress', function(up, file) {
     1541                uploadProgress(file, file.loaded, file.size);
     1542        });
     1543       
     1544        uploader.bind('Error', function(up, err) {
     1545                uploadError(err.file, err.code, err.message);
     1546       
     1547                up.refresh();
     1548        });
     1549
     1550        uploader.bind('FileUploaded', function(up, file, response) {
     1551                <?php echo apply_filters( 'plupload_success_handler', 'uploadSuccess' ); ?>(file, response.response);
     1552        });
     1553
     1554});
    15591555//]]>
    15601556</script>
    15611557
    1562 <div id="flash-upload-ui" class="hide-if-no-js">
    1563 <?php do_action('pre-flash-upload-ui'); ?>
     1558<div id="plupload-upload-ui" class="hide-if-no-js">
     1559<?php do_action('pre-plupload-upload-ui'); ?>
    15641560
    15651561        <div>
    15661562        <?php _e( 'Choose files to upload' ); ?>
    1567         <div id="flash-browse-button"></div>
     1563        <span id="plupload-browse-button" class="button"><?php _e('Select Files'); ?></span>
    15681564        <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
    15691565        </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>
     1566<?php do_action('post-plupload-upload-ui'); ?>
    15731567</div>
    1574 <?php endif; // $flash ?>
    15751568
    1576 <div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>
     1569<?php if ( !IFRAME_REQUEST ): ?>
     1570<div id="html-upload-ui" class="hide-if-js">
    15771571<?php do_action('pre-html-upload-ui'); ?>
    15781572        <p id="async-upload-wrap">
    15791573                <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
    15801574                <input type="file" name="async-upload" id="async-upload" />
    15811575                <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>
    1582                 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
     1576                <a href="<?php echo admin_url('upload.php'); ?>"><?php _e('Cancel'); ?></a>
    15831577        </p>
    15841578        <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); ?>
     1579<?php do_action('post-html-upload-ui', $plupload); ?>
    15901580</div>
     1581<?php endif; ?>
     1582
     1583<input name="image_resize" type="checkbox" id="image_resize" value="1" />
     1584<label for="image_resize"><?php printf( __( 'Resize images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label>
     1585<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
     1586<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
     1587
    15911588<?php do_action('post-upload-ui'); ?>
    15921589<?php
    15931590}
     
    22722269/**
    22732270 * {@internal Missing Short Description}}
    22742271 *
    2275  * Support a GET parameter for disabling the flash uploader.
    2276  *
    22772272 * @since 2.6.0
    2278  *
    2279  * @param unknown_type $flash
    2280  * @return unknown
    22812273 */
    2282 function media_upload_use_flash($flash) {
    2283         if ( array_key_exists('flash', $_REQUEST) )
    2284                 $flash = !empty($_REQUEST['flash']);
    2285         return $flash;
     2274function media_upload_max_image_resize() {
     2275?>
     2276<input name="image_resize" type="checkbox" id="image_resize" value="1" />
     2277<label for="image_resize"><?php printf( __( 'Resize images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label>
     2278<?php
    22862279}
    22872280
    2288 add_filter('flash_uploader', 'media_upload_use_flash');
     2281add_action('post-upload-ui', 'media_upload_max_image_resize');
    22892282
    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');
    2337 
    23382283add_filter('async_upload_image', 'get_media_item', 10, 2);
    23392284add_filter('async_upload_audio', 'get_media_item', 10, 2);
    23402285add_filter('async_upload_video', 'get_media_item', 10, 2);
  • wp-admin/media-upload.php

     
    1818if (!current_user_can('upload_files'))
    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' );
    2525wp_enqueue_style('imgareaselect');
  • wp-includes/script-loader.php

     
    206206
    207207        $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113');
    208208
    209         $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", false, '2.2');
    210209
    211         $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2201-20110113');
    212         $scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
    213         $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
    214         $scripts->add( 'swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
     210        $scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', false, '1.4.3.2');
     211        $scripts->add( 'plupload-html5', '/wp-includes/js/plupload/plupload.html5.js', array('plupload'), '1.4.3.2');
     212        $scripts->add( 'plupload-flash', '/wp-includes/js/plupload/plupload.flash.js', array('plupload'), '1.4.3.2');
     213        $scripts->add( 'plupload-silverlight', '/wp-includes/js/plupload/plupload.silverlight.js', array('plupload'), '1.4.3.2');
     214        $scripts->add( 'plupload-gears', '/wp-includes/js/plupload/plupload.gears.js', array('plupload'), '1.4.3.2');
     215        $scripts->add( 'plupload-html4', '/wp-includes/js/plupload/plupload.html4.js', array('plupload'), '1.4.3.2');
    215216
    216         if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
     217        // TODO: find out if we can use the plupload.full.js (it does load browserplus)
     218        $scripts->add( 'plupload-full', false, array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-gears', 'plupload-html4'), '1.4.3.2');
     219
     220        $scripts->add( 'plupload-handlers', '/wp-includes/js/plupload/handlers.js', array('plupload-full', 'jquery'), '1.4.3.2');
     221       
     222        // TODO: find out if we really need this debug clause with plupload
     223        /*if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
    217224                // queue all SWFUpload scripts that are used by default
    218225                $scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
    219226        } else {
    220                 $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201a');
    221         }
     227                $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201');
     228        }*/
    222229
    223         $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
    224230        $max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post;
    225231        if ( empty($max_upload_size) )
    226232                $max_upload_size = __('not configured');
    227233        // these error messages came from the sample swfupload js, they might need changing.
    228         $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
    229                         'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
     234        $scripts->localize( 'plupload-handlers', 'pluploadL10n', array(
    230235                        'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'),
    231236                        'zero_byte_file' => __('This file is empty. Please try another.'),
    232237                        'invalid_filetype' => __('This file type is not allowed. Please try another.'),
     238                        'not_an_image' => __('This file is not an image. Please try another.'),
     239                        'image_memory_exceeded' => __('Memery exceeded. Please try another smaller file.'),
     240                        'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'),
    233241                        'default_error' => __('An error occurred in the upload. Please try again later.'),
    234242                        'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
    235243                        'upload_limit_exceeded' => __('You may only upload 1 file.'),
     
    243251                        'crunching' => __('Crunching&hellip;'),
    244252                        'deleted' => __('moved to the trash.'),
    245253                        'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error'),
    246                         'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};',
     254                        'l10n_print_after' => 'try{convertEntities(pluploadL10n);}catch(e){};',
    247255        ) );
    248256
    249257        $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');