Ticket #18206: jacobwg-gsoc2011-patch02.diff
File jacobwg-gsoc2011-patch02.diff, 16.8 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/file.php
323 323 324 324 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 325 325 326 $tmp_file = wp_tempnam($filename); 327 326 328 // Move the file to the uploads dir 327 $new_file = $uploads['path'] . "/$filename"; 328 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 329 if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) ) 329 330 return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 330 331 332 // If a resize was requested, perform the resize. 333 $do_resize = apply_filters( 'wp_upload_resize', isset( $_REQUEST['image_resize'] ) ); 334 if ($do_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 } else { 340 $tmp_file = $old_temp; 341 } 342 } 343 344 // Copy the temporary file into its destination 345 $new_file = $uploads['path'] . "/$filename"; 346 copy( $tmp_file, $new_file ); 347 unlink($tmp_file); 348 331 349 // Set correct file permissions 332 350 $stat = stat( dirname( $new_file )); 333 351 $perms = $stat['mode'] & 0000666; -
wp-admin/includes/media.php
1437 1437 function media_upload_form( $errors = null ) { 1438 1438 global $type, $tab, $pagenow; 1439 1439 1440 $ flash_action_url = admin_url('async-upload.php');1440 $upload_action_url = admin_url('async-upload.php'); 1441 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);1448 1442 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; 1449 1443 1450 1444 $upload_size_unit = $max_upload_size = wp_max_upload_size(); … … 1458 1452 $upload_size_unit = (int) $upload_size_unit; 1459 1453 } 1460 1454 ?> 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 //]]>1470 1455 </script> 1471 1456 <div id="media-upload-notice"> 1472 1457 <?php if (isset($errors['upload_notice']) ) { ?> … … 1487 1472 1488 1473 do_action('pre-upload-ui'); 1489 1474 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 1493 1476 // them through a filter. 1494 1477 $post_params = array( 1495 1478 "post_id" => $post_id, … … 1500 1483 "tab" => $tab, 1501 1484 "short" => "1", 1502 1485 ); 1503 $post_params = apply_filters( ' swfupload_post_params', $post_params );1486 $post_params = apply_filters( 'upload_post_params', $post_params ); 1504 1487 $p = array(); 1505 1488 foreach ( $post_params as $param => $val ) 1506 1489 $p[] = "\t\t'$param' : '$val'"; 1507 1490 $post_params_str = implode( ", \n", $p ); 1508 1491 1509 // #8545. wmode=transparent cannot be used with SWFUpload1510 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 1519 1492 ?> 1520 1493 <script type="text/javascript"> 1521 1494 //<![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 }; 1495 var resize_mode = false; 1496 var resize_height = <?php echo get_option('large_size_h'); ?>, 1497 resize_width = <?php echo get_option('large_size_w'); ?>; 1498 1499 jQuery(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 }); 1559 1555 //]]> 1560 1556 </script> 1561 1557 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'); ?> 1564 1560 1565 1561 <div> 1566 1562 <?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> 1568 1564 <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span> 1569 1565 </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'); ?> 1573 1567 </div> 1574 <?php endif; // $flash ?>1575 1568 1576 <div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>1569 <div id="html-upload-ui" class="hide-if-js"> 1577 1570 <?php do_action('pre-html-upload-ui'); ?> 1578 1571 <p id="async-upload-wrap"> 1579 1572 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> 1580 1573 <input type="file" name="async-upload" id="async-upload" /> 1581 1574 <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> 1582 <a href=" #" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>1575 <a href="<?php echo admin_url('upload.php'); ?>"><?php _e('Cancel'); ?></a> 1583 1576 </p> 1584 1577 <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); ?> 1578 <?php do_action('post-html-upload-ui', $plupload); ?> 1590 1579 </div> 1580 1581 <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> 1582 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p> 1583 1591 1584 <?php do_action('post-upload-ui'); ?> 1592 1585 <?php 1593 1586 } … … 2272 2265 /** 2273 2266 * {@internal Missing Short Description}} 2274 2267 * 2275 * Support a GET parameter for disabling the flash uploader.2276 *2277 2268 * @since 2.6.0 2278 *2279 * @param unknown_type $flash2280 * @return unknown2281 2269 */ 2282 function media_upload_use_flash($flash) { 2283 if ( array_key_exists('flash', $_REQUEST) ) 2284 $flash = !empty($_REQUEST['flash']); 2285 return $flash; 2270 function media_upload_max_image_resize() { 2271 ?> 2272 <input name="image_resize" type="checkbox" id="image_resize" value="1" /> 2273 <label for="image_resize"><?php printf( __( 'Scale images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label> 2274 <?php 2286 2275 } 2287 2276 2288 add_ filter('flash_uploader', 'media_upload_use_flash');2277 add_action('post-upload-ui', 'media_upload_max_image_resize'); 2289 2278 2290 /**2291 * {@internal Missing Short Description}}2292 *2293 * @since 2.6.02294 */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.02305 */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 Flash2311 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.02326 *2327 * @param unknown_type $url2328 * @return unknown2329 */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 2338 2279 add_filter('async_upload_image', 'get_media_item', 10, 2); 2339 2280 add_filter('async_upload_audio', 'get_media_item', 10, 2); 2340 2281 add_filter('async_upload_video', 'get_media_item', 10, 2); -
wp-admin/media-upload.php
18 18 if (!current_user_can('upload_files')) 19 19 wp_die(__('You do not have permission to upload files.')); 20 20 21 wp_enqueue_script(' swfupload-all');22 wp_enqueue_script(' swfupload-handlers');21 wp_enqueue_script('plupload-full'); 22 wp_enqueue_script('plupload-handlers'); 23 23 wp_enqueue_script('image-edit'); 24 24 wp_enqueue_script('set-post-thumbnail' ); 25 25 wp_enqueue_style('imgareaselect'); -
wp-includes/script-loader.php
198 198 199 199 $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113'); 200 200 201 $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", false, '2.2');202 201 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'); 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'); 207 208 208 if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) { 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 ) { 209 216 // queue all SWFUpload scripts that are used by default 210 217 $scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201'); 211 218 } else { 212 $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201 a');213 } 219 $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201'); 220 }*/ 214 221 215 $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');216 222 $max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post; 217 223 if ( empty($max_upload_size) ) 218 224 $max_upload_size = __('not configured'); 219 225 // 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.'), 226 $scripts->localize( 'plupload-handlers', 'pluploadL10n', array( 222 227 'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'), 223 228 'zero_byte_file' => __('This file is empty. Please try another.'), 224 229 '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.'), 225 233 'default_error' => __('An error occurred in the upload. Please try again later.'), 226 234 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 227 235 'upload_limit_exceeded' => __('You may only upload 1 file.'), … … 234 242 'dismiss' => __('Dismiss'), 235 243 'crunching' => __('Crunching…'), 236 244 'deleted' => __('moved to the trash.'), 237 'error_uploading' => __('“%s” has failed to upload due to an error') 245 'error_uploading' => __('“%s” has failed to upload due to an error'), 246 'l10n_print_after' => 'try{convertEntities(pluploadL10n);}catch(e){};', 238 247 ) ); 239 248 240 249 $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');