Make WordPress Core

Changeset 35325


Ignore:
Timestamp:
10/21/2015 02:02:59 PM (11 years ago)
Author:
DrewAPicture
Message:

Filesystem: Following the introduction of the KB|MB|GB|TB_IN_BYTES constants in [35286], use them in various places in core.

Props sudar.
Fixes #22405.

Location:
trunk/src
Files:
6 edited

Legend:

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

    r35182 r35325  
    2929
    3030        $file_size = filesize( $file['tmp_name'] );
    31         if ( $space_left < $file_size )
    32                 $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
    33         if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
    34                 $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
     31        if ( $space_left < $file_size ) {
     32                $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
     33        }
     34
     35        if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
     36                $file['error'] = sprintf( __( 'This file is too big. Files must be less than %1$s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
     37        }
     38
    3539        if ( upload_is_user_over_quota( false ) ) {
    3640                $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    3741        }
     42
    3843        if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
    3944                wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
     
    444449
    445450        if ( $space_allowed > 1000 ) {
    446                 $space = number_format( $space_allowed / 1024 );
     451                $space = number_format( $space_allowed / KB_IN_BYTES );
    447452                /* translators: Gigabytes */
    448453                $space .= __( 'GB' );
  • trunk/src/wp-includes/cache.php

    r34227 r35325  
    692692                echo '<ul>';
    693693                foreach ($this->cache as $group => $cache) {
    694                         echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
     694                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
    695695                }
    696696                echo '</ul>';
  • trunk/src/wp-includes/deprecated.php

    r35296 r35325  
    32853285
    32863286        $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
    3287         $log   = log( $bytes, 1024 );
     3287        $log   = log( $bytes, KB_IN_BYTES );
    32883288        $power = (int) $log;
    3289         $size  = pow( 1024, $log - $power );
     3289        $size  = pow( KB_IN_BYTES, $log - $power );
    32903290
    32913291        if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
  • trunk/src/wp-includes/functions.php

    r35288 r35325  
    211211function size_format( $bytes, $decimals = 0 ) {
    212212        $quant = array(
    213                 // ========================= Origin ====
    214                 'TB' => 1099511627776,  // pow( 1024, 4)
    215                 'GB' => 1073741824,     // pow( 1024, 3)
    216                 'MB' => 1048576,        // pow( 1024, 2)
    217                 'kB' => 1024,           // pow( 1024, 1)
    218                 'B'  => 1,              // pow( 1024, 0)
     213                'TB' => TB_IN_BYTES,
     214                'GB' => GB_IN_BYTES,
     215                'MB' => MB_IN_BYTES,
     216                'kB' => KB_IN_BYTES,
     217                'B'  => 1,
    219218        );
    220219
  • trunk/src/wp-includes/media.php

    r35289 r35325  
    26392639        $bytes = (int) $size;
    26402640        if ( strpos( $size, 'k' ) !== false )
    2641                 $bytes = intval( $size ) * 1024;
     2641                $bytes = intval( $size ) * KB_IN_BYTES;
    26422642        elseif ( strpos( $size, 'm' ) !== false )
    2643                 $bytes = intval($size) * 1024 * 1024;
     2643                $bytes = intval($size) * MB_IN_BYTES;
    26442644        elseif ( strpos( $size, 'g' ) !== false )
    2645                 $bytes = intval( $size ) * 1024 * 1024 * 1024;
     2645                $bytes = intval( $size ) * GB_IN_BYTES;
    26462646        return $bytes;
    26472647}
  • trunk/src/wp-includes/ms-functions.php

    r35189 r35325  
    18751875                return $upload;
    18761876
    1877         if ( strlen( $upload['bits'] )  > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
    1878                 return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ));
     1877        if ( strlen( $upload['bits'] )  > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
     1878                return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
     1879        }
    18791880
    18801881        return $upload;
     
    22792280        if ( false === $space_used ) {
    22802281                $upload_dir = wp_upload_dir();
    2281                 $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
     2282                $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
    22822283        }
    22832284
     
    23232324                $allowed = 0;
    23242325        }
    2325         $space_allowed = $allowed * 1024 * 1024;
     2326        $space_allowed = $allowed * MB_IN_BYTES;
    23262327        if ( get_site_option( 'upload_space_check_disabled' ) )
    23272328                return $space_allowed;
    23282329
    2329         $space_used = get_space_used() * 1024 * 1024;
     2330        $space_used = get_space_used() * MB_IN_BYTES;
    23302331
    23312332        if ( ( $space_allowed - $space_used ) <= 0 )
     
    23542355 */
    23552356function upload_size_limit_filter( $size ) {
    2356         $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
     2357        $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
    23572358        if ( get_site_option( 'upload_space_check_disabled' ) )
    23582359                return min( $size, $fileupload_maxk );
Note: See TracChangeset for help on using the changeset viewer.