Make WordPress Core

Ticket #20672: 20672.3.diff

File 20672.3.diff, 3.4 KB (added by wonderboymusic, 10 years ago)
  • src/wp-admin/includes/class-wp-media-list-table.php

     
    6464                        if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
    6565                                $class = ' class="current"';
    6666                        if ( !empty( $num_posts[$mime_type] ) )
    67                                 $type_links[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
     67                                $type_links[$mime_type] = '<a href="upload.php?post_mime_type=' . urlencode( $mime_type ) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
    6868                }
    6969                $type_links['detached'] = '<a href="upload.php?detached=1"' . ( $this->detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
    7070
  • src/wp-includes/post.php

     
    23292329 * @param string|array $real_mime_types post_mime_type values
    23302330 * @return array array(wildcard=>array(real types))
    23312331 */
    2332 function wp_match_mime_types($wildcard_mime_types, $real_mime_types) {
     2332function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
    23332333        $matches = array();
    2334         if ( is_string($wildcard_mime_types) )
    2335                 $wildcard_mime_types = array_map('trim', explode(',', $wildcard_mime_types));
    2336         if ( is_string($real_mime_types) )
    2337                 $real_mime_types = array_map('trim', explode(',', $real_mime_types));
     2334        if ( is_string( $wildcard_mime_types ) ) {
     2335                $wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) );
     2336        }
     2337        if ( is_string( $real_mime_types ) ) {
     2338                $real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) );
     2339        }
     2340
     2341        $patternses = array();
    23382342        $wild = '[-._a-z0-9]*';
     2343
    23392344        foreach ( (array) $wildcard_mime_types as $type ) {
    2340                 $type = str_replace('*', $wild, $type);
    2341                 $patternses[1][$type] = "^$type$";
     2345                $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $type ) ) );
     2346                $patternses[1][$type] = "^$regex$";
    23422347                if ( false === strpos($type, '/') ) {
    2343                         $patternses[2][$type] = "^$type/";
    2344                         $patternses[3][$type] = $type;
     2348                        $patternses[2][$type] = "^$regex/";
     2349                        $patternses[3][$type] = $regex;
    23452350                }
    23462351        }
    2347         asort($patternses);
    2348         foreach ( $patternses as $patterns )
    2349                 foreach ( $patterns as $type => $pattern )
    2350                         foreach ( (array) $real_mime_types as $real )
    2351                                 if ( preg_match("#$pattern#", $real) && ( empty($matches[$type]) || false === array_search($real, $matches[$type]) ) )
     2352        asort( $patternses );
     2353
     2354        foreach ( $patternses as $patterns ) {
     2355                foreach ( $patterns as $type => $pattern ) {
     2356                        foreach ( (array) $real_mime_types as $real ) {
     2357                                if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[$type] ) || false === array_search( $real, $matches[$type] ) ) ) {
    23522358                                        $matches[$type][] = $real;
     2359                                }
     2360                        }
     2361                }
     2362        }
    23532363        return $matches;
    23542364}
    23552365