Make WordPress Core

Ticket #39667: 39667-3.diff

File 39667-3.diff, 4.6 KB (added by milindmore22, 6 years ago)

Fixed notices and added regular expression for validation

  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index ee214e9..2534960 100644
    function size_format( $bytes, $decimals = 0 ) { 
    274274}
    275275
    276276/**
     277 * Function will return duration/ file length in human readable format.
     278 * This will be used for making readable string from duration.
     279 * @since 4.8
     280 * @param string $filelength duration will be in string format (HH:ii:ss) OR (ii:ss).
     281 * @return boolean | string return human readable string, false otherwise.
     282 */
     283function duration_format( $filelength='' ){
     284    // return false if filelenght is empty or not in format
     285    if( empty( $filelength ) && ( (bool) preg_match( '/^([01]?[0-9]|2[0-3])\:+[0-5][0-9]\:+[0-5][0-9]$/', $filelength ) || (bool) preg_match( '/^([01]?[0-9]|2[0-3])\:+[0-5][0-9]$/', $filelength ) ) ){
     286       
     287        return false;
     288    }
     289   
     290    $human_readable_duration=false;
     291    // Extract duration
     292    $durations      = array_reverse ( explode ( ':', $filelength ) );
     293    $duration_count = count( $durations );
     294   
     295    // extract hours, minutes and seconds elseif extract minutes and senconds
     296    if( 3 === $duration_count ){
     297       
     298        list ( $second, $minute, $hour ) = $durations;
     299       
     300    }elseif( 2 === $duration_count ){
     301       
     302        list ( $second, $minute ) = $durations;
     303       
     304    }else{
     305       
     306        return false;
     307    }
     308   
     309    if( !empty( $hour ) && is_numeric( $hour ) ){
     310        /* translators: Time duration in hour or hours*/
     311        $human_readable_duration .= sprintf( _n( '%s hour', '%s hours', $hour ), $hour ).' ';
     312    }
     313   
     314    if( !empty( $minute) && is_numeric( $minute ) ){
     315        /* translators: Time duration in minute or minutes*/
     316        $human_readable_duration .= sprintf( _n( '%s minute', '%s minutes', $minute ), $minute ).' ';
     317    }
     318   
     319    if( !empty( $second ) && is_numeric( $second ) ){
     320        /* translators: Time duration in second or seconds*/
     321        $human_readable_duration .= sprintf( _n( '%s second', '%s seconds', $second ), $second );
     322    }
     323    // return human readable duration
     324    return $human_readable_duration;
     325 
     326}
     327
     328/**
    277329 * Get the week start and end from the datetime or date string from MySQL.
    278330 *
    279331 * @since 0.71
  • src/wp-includes/media-template.php

    diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php
    index 7f59935..aa3f2b4 100644
    function wp_print_media_templates() { 
    344344                                <div class="file-size"><strong><?php _e( 'File size:' ); ?></strong> {{ data.filesizeHumanReadable }}</div>
    345345                                <# if ( 'image' === data.type && ! data.uploading ) { #>
    346346                                        <# if ( data.width && data.height ) { #>
    347                                                 <div class="dimensions"><strong><?php _e( 'Dimensions:' ); ?></strong> {{ data.width }} &times; {{ data.height }}</div>
     347                                                <div class="dimensions"><strong><?php _e( 'Dimensions:' ); ?></strong>
     348                                                    <?php
     349                                                        /* translators: 1: a number of pixels wide, 2: a number of pixels tall */
     350                                                        printf( __( '%1$s by %2$s pixels' ),'{{ data.width }}', '{{ data.height }}' );
     351                                                    ?>
     352                                                </div>
    348353                                        <# } #>
    349354                                <# } #>
    350355
    351356                                <# if ( data.fileLength ) { #>
    352                                         <div class="file-length"><strong><?php _e( 'Length:' ); ?></strong> {{ data.fileLength }}</div>
     357                                        <div class="file-length"><strong><?php _e( 'Length:' ); ?></strong>
     358                                            <span aria-label="{{ data.fileLengthHumanReadable }}">{{ data.fileLength }}</span>
     359                                        </div>
    353360                                <# } #>
    354361
    355362                                <# if ( 'audio' === data.type && data.meta.bitrate ) { #>
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 0c83725..71e94e3 100644
    function wp_prepare_attachment_for_js( $attachment ) { 
    32193219        }
    32203220
    32213221        if ( $meta && ( 'audio' === $type || 'video' === $type ) ) {
    3222                 if ( isset( $meta['length_formatted'] ) )
    3223                         $response['fileLength'] = $meta['length_formatted'];
     3222                if ( isset( $meta['length_formatted'] ) ){
     3223                        $response['fileLength']              = $meta['length_formatted'];
     3224                       $response['fileLengthHumanReadable'] = duration_format( $meta['length_formatted'] );
     3225                }   
    32243226
    32253227                $response['meta'] = array();
    32263228                foreach ( wp_get_attachment_id3_keys( $attachment, 'js' ) as $key => $label ) {