Changeset 21387 for trunk/wp-admin/includes/ms.php
- Timestamp:
- 08/01/2012 01:52:06 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ms.php
r20952 r21387 26 26 return $file; 27 27 28 $space_allowed = 1048576 * get_space_allowed(); 29 $space_used = get_dirsize( BLOGUPLOADDIR ); 30 $space_left = $space_allowed - $space_used; 28 $space_left = get_upload_space_available(); 29 31 30 $file_size = filesize( $file['tmp_name'] ); 32 31 if ( $space_left < $file_size ) … … 311 310 return $space_allowed; 312 311 313 $dir_name = trailingslashit( BLOGUPLOADDIR ); 314 if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) ) 315 return $space_allowed; 316 317 $dir = dir( $dir_name ); 318 $size = 0; 319 320 while ( $file = $dir->read() ) { 321 if ( $file != '.' && $file != '..' ) { 322 if ( is_dir( $dir_name . $file) ) { 323 $size += get_dirsize( $dir_name . $file ); 324 } else { 325 $size += filesize( $dir_name . $file ); 326 } 327 } 328 } 329 $dir->close(); 330 331 if ( ( $space_allowed - $size ) <= 0 ) 312 $space_used = get_space_used() * 1024 * 1024; 313 314 if ( ( $space_allowed - $space_used ) <= 0 ) 332 315 return 0; 333 316 334 return $space_allowed - $size; 317 return $space_allowed - $space_used; 318 } 319 320 /** 321 * Check whether a blog has used its allotted upload space. 322 * 323 * @since MU 324 * 325 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. 326 * @return int 327 */ 328 function upload_is_user_over_quota( $echo = true ) { 329 if ( get_site_option( 'upload_space_check_disabled' ) ) 330 return false; 331 332 $space_allowed = get_space_allowed(); 333 if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) ) 334 $space_allowed = 10;// Default space allowed is 10 MB 335 336 $space_used = get_space_used(); 337 338 if ( ($space_allowed - $space_used ) < 0 ) { 339 if ( $echo ) 340 _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' ); 341 return true; 342 } else { 343 return false; 344 } 345 } 346 347 function get_space_used() { 348 // Allow for an alternative way of tracking storage space used 349 $space_used = apply_filters( 'pre_get_space_used', false ); 350 if ( false === $space_used ) 351 $space_used = get_dirsize( BLOGUPLOADDIR ); 352 353 return $space_used; 335 354 } 336 355 … … 353 372 354 373 function display_space_usage() { 355 $space = get_space_allowed();356 $ used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;357 358 $percent used = ( $used / $space) * 100;359 360 if ( $space > 1000 ) {361 $space = number_format( $space / 1024 );374 $space_allowed = get_space_allowed(); 375 $space_used = get_space_used(); 376 377 $percent_used = ( $space_used / $space_allowed ) * 100; 378 379 if ( $space_allowed > 1000 ) { 380 $space = number_format( $space_allowed / 1024 ); 362 381 /* translators: Gigabytes */ 363 382 $space .= __( 'GB' ); 364 383 } else { 384 $space = number_format( $space_allowed ); 365 385 /* translators: Megabytes */ 366 386 $space .= __( 'MB' ); 367 387 } 368 388 ?> 369 <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percent used ), $space ); ?></strong>389 <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percent_used ), $space ); ?></strong> 370 390 <?php 391 } 392 393 /** 394 * Get the remaining upload space for this blog. 395 * 396 * @since MU 397 * @uses upload_is_user_over_quota() 398 * @uses get_space_allowed() 399 * @uses get_upload_space_available() 400 * 401 * @param int $size Current max size in bytes 402 * @return int Max size in bytes 403 */ 404 function fix_import_form_size( $size ) { 405 if ( upload_is_user_over_quota( false ) == true ) 406 return 0; 407 408 $available = get_upload_space_available(); 409 return min( $size, $available); 371 410 } 372 411
Note: See TracChangeset
for help on using the changeset viewer.