Make WordPress Core

Changeset 22743


Ignore:
Timestamp:
11/21/2012 10:18:59 AM (14 years ago)
Author:
koopersmith
Message:

Media: Dynamically generate attachment filters using get_post_mime_types().

Moves get_post_mime_types() from wp-admin/includes/post.php to wp-includes/post.php.

fixes #22514, see #21390.

Location:
trunk
Files:
5 edited

Legend:

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

    r22653 r22743  
    877877
    878878/**
    879  * Get default post mime types
    880  *
    881  * @since 2.9.0
    882  *
    883  * @return array
    884  */
    885 function get_post_mime_types() {
    886         $post_mime_types = array(       //      array( adj, noun )
    887                 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
    888                 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
    889                 'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
    890         );
    891 
    892         return apply_filters('post_mime_types', $post_mime_types);
    893 }
    894 
    895 /**
    896879 * {@internal Missing Short Description}}
    897880 *
  • trunk/wp-includes/js/media-models.js

    r22737 r22743  
    672672                                // Correct any differing property names.
    673673                                _.each( props, function( value, prop ) {
     674                                        if ( _.isNull( value ) )
     675                                                return;
     676
    674677                                        args[ Query.propmap[ prop ] || prop ] = value;
    675678                                });
  • trunk/wp-includes/js/media-views.js

    r22741 r22743  
    27672767                },
    27682768
     2769                filters: (function() {
     2770                        var filters = {};
     2771
     2772                        _.each( media.view.settings.mimeTypes || {}, function( text, key ) {
     2773                                filters[ key ] = {
     2774                                        text: text,
     2775                                        props: {
     2776                                                type:   key,
     2777                                                parent: null
     2778                                        }
     2779                                };
     2780                        });
     2781
     2782                        filters.all = {
     2783                                text:  l10n.allMediaItems,
     2784                                props: {
     2785                                        type:   null,
     2786                                        parent: null
     2787                                },
     2788                                priority: 10
     2789                        };
     2790
     2791                        filters.uploaded = {
     2792                                text:  l10n.uploadedToThisPost,
     2793                                props: {
     2794                                        type:   null,
     2795                                        parent: media.view.settings.postId
     2796                                },
     2797                                priority: 20
     2798                        };
     2799
     2800                        return filters;
     2801                }()),
     2802
    27692803                initialize: function() {
    2770                         var els;
    2771 
    2772                         els = _.map({
    2773                                 all:      'allMediaItems',
    2774                                 uploaded: 'uploadedToThisPost',
    2775                                 image:    'images',
    2776                                 audio:    'audio',
    2777                                 video:    'videos'
    2778                         }, function( text, value ) {
    2779                                 return this.make( 'option', { value: value }, l10n[ text ] );
    2780                         }, this );
    2781 
    2782                         this.$el.html( els );
     2804                        // Build `<option>` elements.
     2805                        this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
     2806                                return {
     2807                                        el: this.make( 'option', { value: value }, filter.text ),
     2808                                        priority: filter.priority || 50
     2809                                };
     2810                        }, this ).sortBy('priority').pluck('el').value() );
    27832811
    27842812                        this.model.on( 'change', this.select, this );
    … …  
    27872815
    27882816                change: function( event ) {
    2789                         var model = this.model,
    2790                                 value = this.el.value,
    2791                                 type;
    2792 
    2793                         if ( 'all' === value || 'uploaded' === value )
    2794                                 model.unset('type');
    2795                         else if ( 'image' === value || 'audio' === value || 'video' === value )
    2796                                 model.set( 'type', value );
    2797 
    2798                         if ( 'uploaded' === value )
    2799                                 model.set( 'parent', media.view.settings.postId );
    2800                         else
    2801                                 model.unset('parent');
     2817                        var filter = this.filters[ this.el.value ];
     2818
     2819                        if ( filter )
     2820                                this.model.set( filter.props );
    28022821                },
    28032822
    28042823                select: function() {
    28052824                        var model = this.model,
     2825                                value = 'all',
    28062826                                type = model.get('type'),
    2807                                 value = 'all';
    2808 
    2809                         if ( model.get('parent') === media.view.settings.postId )
    2810                                 value = 'uploaded';
    2811                         else if ( 'image' === type )
    2812                                 value = 'image';
    2813                         else if ( 'audio' === type )
    2814                                 value = 'audio';
    2815                         else if ( 'video' === type )
    2816                                 value = 'video';
     2827                                parent = model.get('parent'),
     2828                                props = {
     2829                                        parent: _.isUndefined( parent ) ? null : parent,
     2830                                        type:   _.isUndefined( type ) ? null : type
     2831                                };
     2832
     2833                        _.find( this.filters, function( filter, key ) {
     2834                                if ( _.isEqual( filter.props, props ) )
     2835                                        return value = key;
     2836                        });
    28172837
    28182838                        this.$el.val( value );
  • trunk/wp-includes/media.php

    r22735 r22743  
    13231323
    13241324        $settings = array(
    1325                 'tabs'   => $tabs,
    1326                 'tabUrl' => add_query_arg( array(
    1327                         'chromeless' => true
    1328                 ), admin_url('media-upload.php') ),
     1325                'tabs'      => $tabs,
     1326                'tabUrl'    => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),
     1327                'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),
    13291328        );
    13301329
    … …  
    13551354
    13561355                // Library
    1357                 'mediaLibraryTitle' => __( 'Media Library' ),
    1358                 'createNewGallery'  => __( 'Create a new gallery' ),
    1359                 'insertIntoPost'    =>  $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
    1360                 'returnToLibrary'   => __( '&#8592; Return to library' ),
    1361 
     1356                'mediaLibraryTitle'  => __( 'Media Library' ),
     1357                'createNewGallery'   => __( 'Create a new gallery' ),
     1358                'returnToLibrary'    => __( '&#8592; Return to library' ),
    13621359                'allMediaItems'      => __( 'All media items' ),
     1360                'insertIntoPost'     => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
    13631361                'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
    1364                 'images'             => __( 'Images' ),
    1365                 'audio'              => __( 'Audio' ),
    1366                 'videos'             => __( 'Videos' ),
    13671362
    13681363                // Embed
  • trunk/wp-includes/post.php

    r22722 r22743  
    21812181
    21822182/**
     2183 * Get default post mime types
     2184 *
     2185 * @since 2.9.0
     2186 *
     2187 * @return array
     2188 */
     2189function get_post_mime_types() {
     2190        $post_mime_types = array(       //      array( adj, noun )
     2191                'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
     2192                'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
     2193                'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
     2194        );
     2195
     2196        return apply_filters('post_mime_types', $post_mime_types);
     2197}
     2198
     2199/**
    21832200 * Check a MIME-Type against a list.
    21842201 *
Note: See TracChangeset for help on using the changeset viewer.