WordPress.org

Make WordPress Core

Changeset 6910


Ignore:
Timestamp:
02/19/08 06:13:20 (6 years ago)
Author:
ryan
Message:

Media Library design updates from Andy. see #5911

Location:
trunk
Files:
1 added
6 edited

Legend:

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

    r6872 r6910  
    503503            ); 
    504504 
     505    $post_stati = apply_filters('post_stati', $post_stati); 
     506 
    505507    $avail_post_stati = get_available_post_statuses('post'); 
    506508 
     
    523525 
    524526    return array($post_stati, $avail_post_stati); 
     527} 
     528 
     529function get_available_post_mime_types($type = 'attachment') { 
     530    global $wpdb; 
     531 
     532    $types = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type)); 
     533    return $types; 
     534} 
     535 
     536function wp_edit_attachments_query( $q = false ) { 
     537    global $wpdb; 
     538    if ( false === $q ) 
     539        $q = $_GET; 
     540    $q['m']   = (int) $q['m']; 
     541    $q['cat'] = (int) $q['cat']; 
     542    $q['post_type'] = 'attachment'; 
     543    $q['post_status'] = 'any'; 
     544    $post_mime_types = array(   //  array( adj, noun ) 
     545                'image' => array(__('Images'), __('Manage Images'), __('Images (%s)')), 
     546                'audio' => array(__('Audio'), __('Manage Audio'), __('Audio (%s)')), 
     547                'video' => array(__('Video'), __('Manage Video'), __('Video (%s)')), 
     548            ); 
     549    $post_mime_types = apply_filters('post_mime_types', $post_mime_types); 
     550 
     551    $avail_post_mime_types = get_available_post_mime_types('attachment'); 
     552 
     553    if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) 
     554        unset($q['post_mime_type']); 
     555 
     556    wp($q); 
     557 
     558    return array($post_mime_types, $avail_post_mime_types); 
    525559} 
    526560 
  • trunk/wp-admin/includes/template.php

    r6904 r6910  
    303303    $posts_columns['status'] = __('Status'); 
    304304    $posts_columns = apply_filters('manage_posts_columns', $posts_columns); 
     305 
     306    return $posts_columns; 
     307} 
     308 
     309// define the columns to display, the syntax is 'internal name' => 'display name' 
     310function wp_manage_media_columns() { 
     311    $posts_columns = array(); 
     312    $posts_columns['cb'] = '<div style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" /></div>'; 
     313    $posts_columns['icon'] = ''; 
     314    $posts_columns['media'] = _c('Media|media column header'); 
     315    $posts_columns['desc'] = _c('Description|media column header'); 
     316    $posts_columns['date'] = _c('Date Added|media column header'); 
     317    $posts_columns['parent'] = _c('Appears with|media column header'); 
     318    $posts_columns['location'] = _c('Location|media column header'); 
     319    $posts_columns = apply_filters('manage_media_columns', $posts_columns); 
    305320 
    306321    return $posts_columns; 
  • trunk/wp-admin/upload.php

    r6782 r6910  
    22require_once('admin.php'); 
    33 
    4 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); 
    5  
    6 if (!current_user_can('upload_files')) 
    7     wp_die(__('You do not have permission to upload files.')); 
    8  
    9 wp_reset_vars(array('action', 'tab', 'from_tab', 'style', 'post_id', 'ID', 'paged', 'post_title', 'post_content', 'delete')); 
    10  
    11 // IDs should be integers 
    12 $ID = (int) $ID; 
    13 $post_id = (int) $post_id; 
    14  
    15 // Require an ID for the edit screen 
    16 if ( $action == 'edit' && !$ID ) 
    17     wp_die(__("You are not allowed to be here")); 
    18  
    19 require_once('includes/upload.php'); 
    20 if ( !$tab ) 
    21     $tab = 'browse-all'; 
    22  
    23 do_action( "upload_files_$tab" ); 
    24  
    25 $pid = 0; 
    26 if ( $post_id < 0 ) 
    27     $pid = $post_id; 
    28 elseif ( get_post( $post_id ) ) 
    29     $pid = $post_id; 
    30 $wp_upload_tabs = array(); 
    31 $all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'"); 
    32 $post_atts = 0; 
    33  
    34 if ( $pid ) { 
    35     // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args 
    36     $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0); 
    37     if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") ) 
    38         $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts); 
    39     if ( $post_atts < $all_atts ) 
    40         $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts); 
    41 } else 
    42     $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts); 
    43  
    44     $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() )); 
    45  
    46 if ( !is_callable($wp_upload_tabs[$tab][2]) ) { 
    47     $to_tab = isset($wp_upload_tabs['upload']) ? 'upload' : 'browse-all'; 
    48     wp_redirect( add_query_arg( 'tab', $to_tab ) ); 
    49     exit; 
    50 } 
    51  
    52 foreach ( $wp_upload_tabs as $t => $tab_array ) { 
    53     if ( !current_user_can( $tab_array[1] ) ) { 
    54         unset($wp_upload_tabs[$t]); 
    55         if ( $tab == $t ) 
    56             wp_die(__("You are not allowed to be here")); 
     4if (!current_user_can('upload_files'))  
     5    wp_die(__('You do not have permission to upload files.'));  
     6 
     7// Handle bulk deletes 
     8if ( isset($_GET['deleteit']) && isset($_GET['delete']) ) { 
     9    check_admin_referer('bulk-media'); 
     10    foreach( (array) $_GET['delete'] as $post_id_del ) { 
     11        $post_del = & get_post($post_id_del); 
     12 
     13        if ( !current_user_can('delete_post', $post_id_del) ) 
     14            wp_die( __('You are not allowed to delete this post.') ); 
     15 
     16        if ( $post_del->post_type == 'attachment' ) 
     17            if ( ! wp_delete_attachment($post_id_del) ) 
     18                wp_die( __('Error in deleting...') ); 
    5719    } 
    58 } 
    59  
    60 if ( 'inline' == $style ) : ?> 
    61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    62 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> 
    63 <head> 
    64 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 
    65 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; WordPress</title> 
    66 <?php  
    67 wp_admin_css( 'css/global' ); 
    68 wp_admin_css(); 
    69 ?> 
    70 <script type="text/javascript"> 
    71 //<![CDATA[ 
    72 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}} 
    73 //]]> 
    74 </script> 
    75 <?php do_action('admin_print_scripts'); wp_upload_admin_head(); ?> 
    76 </head> 
    77 <body> 
    78 <?php 
    79 else : 
    80     add_action( 'admin_head', 'wp_upload_admin_head' ); 
    81     include_once('admin-header.php'); 
    82 ?> 
    83     <div class='wrap'> 
    84     <h2><?php _e('Uploads'); ?></h2> 
    85 <?php 
    86 endif; 
    87  
    88 echo "<ul id='upload-menu'>\n"; 
    89 foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check 
    90     $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '', 'paged' => '') ); 
    91     if ( isset($tab_array[4]) && is_array($tab_array[4]) ) 
    92         $href = add_query_arg( $tab_array[4], $href ); 
    93     $_href = clean_url( $href); 
    94     $page_links = ''; 
    95     $class = 'upload-tab alignleft'; 
    96     if ( $tab == $t ) { 
    97         $class .= ' current'; 
    98         if ( $tab_array[3] ) { 
    99             if ( is_array($tab_array[3]) ) { 
    100                 $total = $tab_array[3][0]; 
    101                 $per = $tab_array[3][1]; 
    102             } else { 
    103                 $total = $tab_array[3]; 
    104                 $per = 10; 
    105             } 
    106             $page_links = paginate_links( array( 
    107                 'base' => add_query_arg( 'paged', '%#%' ), 
    108                 'format' => '', 
    109                 'total' => ceil($total / $per), 
    110                 'current' => $paged ? $paged : 1, 
    111                 'prev_text' => '&laquo;', 
    112                 'next_text' => '&raquo;' 
    113             )); 
    114             if ( $page_links ) 
    115                 $page_links = "<span id='current-tab-nav'>: $page_links</span>"; 
     20 
     21    $sendback = wp_get_referer(); 
     22    if (strpos($sendback, 'media.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/media.php'; 
     23    $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); 
     24 
     25    wp_redirect($sendback); 
     26    exit(); 
     27} elseif ( !empty($_GET['_wp_http_referer']) ) { 
     28    wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); 
     29    exit;  
     30} 
     31 
     32$title = __('Media Library'); 
     33$parent_file = 'edit.php'; 
     34wp_enqueue_script( 'admin-posts' ); 
     35wp_enqueue_script( 'admin-forms' ); 
     36if ( 1 == $_GET['c'] ) 
     37    wp_enqueue_script( 'admin-comments' ); 
     38 
     39require_once('admin-header.php'); 
     40 
     41add_filter( 'post_limits', $limit_filter = create_function( '$a', '$b = split(" ",$a); if ( !isset($b[2]) ) return $a; $start = intval(trim($b[1])) / 20 * 15; if ( !is_int($start) ) return $a; return "LIMIT $start, 20";' ) ); 
     42list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); 
     43$wp_query->max_num_pages = ceil( $wp_query->found_posts / 15 ); // We grab 20 but only show 15 ( 5 more for ajax extra ) 
     44 
     45if ( !isset( $_GET['paged'] ) ) 
     46    $_GET['paged'] = 1; 
     47 
     48?> 
     49 
     50<div class="wrap"> 
     51 
     52<form id="posts-filter" action="" method="get"> 
     53<h2><?php 
     54if ( is_single() ) { 
     55    printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title)); 
     56} else { 
     57    $post_mime_type_label = _c('Manage Media|manage media header'); 
     58    if ( isset($_GET['post_mime_type']) && in_array( $_GET['post_mime_type'], array_keys($post_mime_types) ) ) 
     59        $post_mime_type_label = $post_mime_types[$_GET['post_mime_type']][1]; 
     60    if ( $post_listing_pageable && !is_archive() && !is_search() ) 
     61        $h2_noun = is_paged() ? sprintf(__( 'Previous %s' ), $post_mime_type_label) : sprintf(__('Latest %s'), $post_mime_type_label); 
     62    else 
     63        $h2_noun = $post_mime_type_label; 
     64    // Use $_GET instead of is_ since they can override each other 
     65    $h2_author = ''; 
     66    $_GET['author'] = (int) $_GET['author']; 
     67    if ( $_GET['author'] != 0 ) { 
     68        if ( $_GET['author'] == '-' . $user_ID ) { // author exclusion 
     69            $h2_author = ' ' . __('by other authors'); 
     70        } else { 
     71            $author_user = get_userdata( get_query_var( 'author' ) ); 
     72            $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name )); 
    11673        } 
    11774    } 
    118  
    119     echo "\t<li class='$class'><a href='$_href' class='upload-tab-link' title='{$tab_array[0]}'>{$tab_array[0]}</a>$page_links</li>\n"; 
    120 } 
    121 unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class); 
    122 echo "</ul>\n\n"; 
    123  
    124 echo "<div id='upload-content' class='$tab'>\n"; 
    125  
    126 call_user_func( $wp_upload_tabs[$tab][2] ); 
    127  
    128 echo "</div>\n"; 
    129  
    130 if ( 'inline' != $style ) : 
    131     echo "<div class='clear'></div></div>"; 
    132     include_once('admin-footer.php'); 
    133 else : ?> 
    134 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> 
    135  
    136 </body> 
    137 </html> 
    138 <?php endif; ?> 
     75    $h2_search = isset($_GET['s'])   && $_GET['s']   ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( get_search_query() ) ) : ''; 
     76    $h2_cat    = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in &#8220;%s&#8221;'), single_cat_title('', false) ) : ''; 
     77    $h2_tag    = isset($_GET['tag']) && $_GET['tag'] ? ' ' . sprintf( __('tagged with &#8220;%s&#8221;'), single_tag_title('', false) ) : ''; 
     78    $h2_month  = isset($_GET['m'])   && $_GET['m']   ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : ''; 
     79    printf( _c( '%1$s%2$s%3$s%4$s%5$s%6$s|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: tagged with {s}, 6: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_tag, $h2_month ); 
     80} 
     81?></h2> 
     82 
     83<ul class="subsubsub"> 
     84<?php 
     85$status_links = array(); 
     86$_num_posts = (array) wp_count_attachments(); 
     87$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 
     88foreach ( $matches as $type => $reals ) 
     89    foreach ( $reals as $real ) 
     90        $num_posts[$type] += $_num_posts[$real]; 
     91foreach ( $post_mime_types as $mime_type => $label ) { 
     92    $class = ''; 
     93 
     94    if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) 
     95        continue; 
     96 
     97    if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) 
     98        $class = ' class="current"'; 
     99 
     100    $status_links[] = "<li><a href=\"upload.php?post_mime_type=$mime_type\"$class>" . 
     101    sprintf($label[2], $num_posts[$mime_type]) . '</a>'; 
     102} 
     103$class = empty($_GET['post_mime_type']) ? ' class="current"' : ''; 
     104$status_links[] = "<li><a href=\"upload.php\"$class>".__('All Types')."</a>"; 
     105echo implode(' |</li>', $status_links) . '</li>'; 
     106unset($status_links); 
     107?> 
     108</ul> 
     109 
     110<?php 
     111if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET['posted']; ?> 
     112<div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View post'); ?></a> | <a href="post.php?action=edit&amp;post=<?php echo $_GET['posted']; ?>"><?php _e('Edit post'); ?></a></p></div> 
     113<?php 
     114endif; 
     115?> 
     116 
     117<p id="post-search"> 
     118    <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" /> 
     119    <input type="submit" value="<?php _e( 'Search Media' ); ?>" /> 
     120</p> 
     121 
     122<?php do_action('restrict_manage_posts'); ?> 
     123 
     124<br style="clear:both;" /> 
     125 
     126<div class="tablenav"> 
     127 
     128<?php 
     129$page_links = paginate_links( array( 
     130    'base' => add_query_arg( 'paged', '%#%' ), 
     131    'format' => '', 
     132    'total' => ceil($wp_query->found_posts / 15), 
     133    'current' => $_GET['paged'] 
     134)); 
     135 
     136if ( $page_links ) 
     137    echo "<div class='tablenav-pages'>$page_links</div>"; 
     138?> 
     139 
     140<div style="float: left"> 
     141<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" /> 
     142<?php wp_nonce_field('bulk-posts'); ?> 
     143<?php 
     144 
     145$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC"; 
     146 
     147$arc_result = $wpdb->get_results( $arc_query ); 
     148 
     149$month_count = count($arc_result); 
     150 
     151if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> 
     152<select name='m'> 
     153<option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option> 
     154<?php 
     155foreach ($arc_result as $arc_row) { 
     156    if ( $arc_row->yyear == 0 ) 
     157        continue; 
     158    $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); 
     159     
     160    if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) 
     161        $default = ' selected="selected"'; 
     162    else 
     163        $default = ''; 
     164     
     165    echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>"; 
     166    echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear"; 
     167    echo "</option>\n"; 
     168} 
     169?> 
     170</select> 
     171<?php } ?> 
     172 
     173<input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button" /> 
     174 
     175</div> 
     176 
     177<br style="clear:both;" /> 
     178</div> 
     179 
     180<br style="clear:both;" /> 
     181 
     182<?php include( 'edit-attachment-rows.php' ); ?> 
     183 
     184</form> 
     185 
     186<form action="" method="post" id="get-extra-posts" class="add:the-extra-list:" style="display:none"> 
     187    <?php wp_nonce_field( 'add-post', '_ajax_nonce', false ); ?> 
     188</form> 
     189 
     190<div id="ajax-response"></div> 
     191 
     192<div class="tablenav"> 
     193 
     194<?php 
     195if ( $page_links ) 
     196    echo "<div class='tablenav-pages'>$page_links</div>"; 
     197?> 
     198<br style="clear:both;" /> 
     199</div> 
     200 
     201<?php 
     202 
     203if ( 1 == count($posts) && isset( $_GET['p'] ) ) { 
     204 
     205    $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved != 'spam' ORDER BY comment_date"); 
     206    if ($comments) { 
     207        // Make sure comments, post, and post_author are cached 
     208        update_comment_cache($comments); 
     209        $post = get_post($id); 
     210        $authordata = get_userdata($post->post_author); 
     211    ?> 
     212<h3 id="comments"><?php _e('Comments') ?></h3> 
     213<ol id="the-comment-list" class="list:comment commentlist"> 
     214<?php 
     215        $i = 0; 
     216        foreach ( $comments as $comment ) { 
     217            _wp_comment_list_item( $comment->comment_ID, ++$i ); 
     218        } 
     219    echo '</ol>'; 
     220    } // end if comments 
     221?> 
     222<?php } ?> 
     223</div> 
     224 
     225<?php include('admin-footer.php'); ?> 
  • trunk/wp-includes/classes.php

    r6858 r6910  
    44    var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots'); 
    55 
    6     var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id'); 
     6    var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type'); 
    77    var $extra_query_vars = array(); 
    88 
  • trunk/wp-includes/post.php

    r6808 r6910  
    808808 
    809809/** 
     810 * wp_count_attachments() - Count number of attachments 
     811 * 
     812 * {@internal Missing Long Description}} 
     813 * 
     814 * @package WordPress 
     815 * @subpackage Post 
     816 * @since 2.5 
     817 * 
     818 * @param string|array $post_mime_type Array or comma-separated list of MIME patterns 
     819 * @return array Number of posts for each post_mime_type 
     820 */ 
     821 
     822function wp_count_attachments( $mime_type = '' ) { 
     823    global $wpdb; 
     824 
     825    $and = wp_post_mime_type_where( $mime_type ); 
     826    $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' $and GROUP BY post_mime_type", ARRAY_A ); 
     827 
     828    $stats = array( ); 
     829    foreach( (array) $count as $row ) { 
     830        $stats[$row['post_mime_type']] = $row['num_posts']; 
     831    } 
     832 
     833    return (object) $stats; 
     834} 
     835 
     836/** 
     837 * wp_match_mime_type() - Check a MIME-Type against a list 
     838 * 
     839 * {@internal Missing Long Description}} 
     840 * 
     841 * @package WordPress 
     842 * @subpackage Post 
     843 * @since 2.5 
     844 * 
     845 * @param string|array $wildcard_mime_types e.g. audio/mpeg or image (same as image/*) or flash (same as *flash*) 
     846 * @param string|array $real_mime_types post_mime_type values 
     847 * @return array array(wildcard=>array(real types)) 
     848 */ 
     849function wp_match_mime_types($wildcard_mime_types, $real_mime_types) { 
     850    $matches = array(); 
     851    if ( is_string($wildcard_mime_types) ) 
     852        $wildcard_mime_types = array_map('trim', explode(',', $wildcard_mime_types)); 
     853    if ( is_string($real_mime_types) ) 
     854        $real_mime_types = array_map('trim', explode(',', $real_mime_types)); 
     855    $wild = '[-._a-z0-9]*'; 
     856    foreach ( (array) $wildcard_mime_types as $type ) { 
     857        $type = str_replace('*', $wild, $type); 
     858        $patternses[1][$type] = $type; 
     859        if ( false === strpos($type, '/') ) { 
     860            $patternses[2][$type] = "^$type/$wild$"; 
     861            $patternses[3][$type] = "$wild$type$wild"; 
     862        } 
     863    } 
     864    asort($patternses); 
     865    foreach ( $patternses as $patterns ) 
     866        foreach ( $patterns as $type => $pattern ) 
     867            foreach ( (array) $real_mime_types as $real ) 
     868                if ( preg_match("#$pattern#", $real) && ( empty($matches[$type]) || false === array_search($real, $matches[$type]) ) ) 
     869                    $matches[$type][] = $real; 
     870    return $matches; 
     871} 
     872 
     873/** 
     874 * wp_get_post_mime_type_where() - Convert MIME types into SQL 
     875 * 
     876 * @package WordPress 
     877 * @subpackage Post 
     878 * @since 2.5 
     879 * 
     880 * @param string|array $mime_types MIME types 
     881 * @return string SQL AND clause 
     882 */ 
     883function wp_post_mime_type_where($post_mime_types) { 
     884    $where = ''; 
     885    $wildcards = array('', '%', '%/%'); 
     886    if ( is_string($post_mime_types) ) 
     887        $post_mime_types = array_map('trim', explode(',', $post_mime_types)); 
     888    foreach ( (array) $post_mime_types as $mime_type ) { 
     889        $mime_type = preg_replace('/\s/', '', $mime_type); 
     890        $slashpos = strpos($mime_type, '/'); 
     891        if ( false !== $slashpos ) { 
     892            $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos)); 
     893            $mime_subgroup = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1)); 
     894            if ( empty($mime_subgroup) ) 
     895                $mime_subgroup = '*'; 
     896            else 
     897                $mime_subgroup = str_replace('/', '', $mime_subgroup); 
     898            $mime_pattern = "$mime_group/$mime_subgroup"; 
     899        } else { 
     900            $mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type); 
     901            if ( false === strpos($mime_pattern, '*') ) 
     902                $mime_pattern .= '/*'; 
     903        } 
     904 
     905        $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); 
     906 
     907        if ( in_array( $mime_type, $wildcards ) ) 
     908            return ''; 
     909 
     910        if ( false !== strpos($mime_pattern, '%') ) 
     911            $wheres[] = "post_mime_type LIKE '$mime_pattern'"; 
     912        else 
     913            $wheres[] = "post_mime_type = '$mime_pattern'"; 
     914    } 
     915    if ( !empty($wheres) ) 
     916        $where = ' AND (' . join(' OR ', $wheres) . ') '; 
     917    return $where; 
     918} 
     919 
     920/** 
    810921 * wp_delete_post() - Deletes a Post 
    811922 * 
  • trunk/wp-includes/query.php

    r6823 r6910  
    787787        $whichcat = ''; 
    788788        $whichauthor = ''; 
     789        $whichmimetype = ''; 
    789790        $where = ''; 
    790791        $limits = ''; 
     
    11521153        } 
    11531154 
    1154         $where .= $search.$whichcat.$whichauthor; 
     1155        // MIME-Type stuff for attachment browsing 
     1156 
     1157        if ( '' != $q['post_mime_type'] ) 
     1158            $whichmimetype = wp_post_mime_type_where($q['post_mime_type']); 
     1159 
     1160        $where .= $search.$whichcat.$whichauthor.$whichmimetype; 
    11551161 
    11561162        if ( empty($q['order']) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC')) ) 
Note: See TracChangeset for help on using the changeset viewer.