WordPress.org

Make WordPress Core

Changeset 28553


Ignore:
Timestamp:
05/22/2014 09:35:36 PM (6 years ago)
Author:
wonderboymusic
Message:

Fix parsing in wp_match_mime_types() to allow some mime-types with + in them to appear in the list of filter links shown above the list table on upload.php.

Props _duck.
Fixes #20672.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r28497 r28553  
    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>';
  • trunk/src/wp-includes/post.php

    r28471 r28553  
    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;
    2345         }
    2346     }
    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]) ) )
     2348            $patternses[2][$type] = "^$regex/";
     2349            $patternses[3][$type] = $regex;
     2350        }
     2351    }
     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}
Note: See TracChangeset for help on using the changeset viewer.