Make WordPress Core


Ignore:
Timestamp:
02/22/2008 05:53:47 AM (19 years ago)
Author:
ryan
Message:

Media library work from andy. see #5911

File:
1 edited

Legend:

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

    r6951 r6974  
    23032303function wp_mime_type_icon( $mime = 0 ) {
    23042304        $post_id = 0;
    2305         if ( is_numeric($mime) ) {
    2306                 $mime = (int) $mime;
    2307                 if ( !$post =& get_post( $mime ) )
    2308                         return false;
    2309                 $post_id = (int) $post->ID;
    2310                 $mime = $post->post_mime_type;
    2311         }
    2312 
    2313         if ( empty($mime) )
    2314                 return false;
    2315 
    2316         $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
    2317         $icon_dir_uri = apply_filters( 'icon_dir_uri', get_template_directory_uri() . '/images' );
    2318 
    2319         $types = array(
    2320                 substr($mime, 0, strpos($mime, '/')),
    2321                 substr($mime, strpos($mime, '/') + 1),
    2322                 str_replace('/', '_', $mime)
    2323         );
    2324 
    2325         $exts = array('jpg', 'gif', 'png');
    2326 
    2327         $src = false;
    2328 
    2329         foreach ( $types as $type ) {
    2330                 foreach ( $exts as $ext ) {
    2331                         $src_file = "$icon_dir/$type.$ext";
    2332                         if ( file_exists($src_file) ) {
    2333                                 $src = "$icon_dir_uri/$type.$ext";
    2334                                 break 2;
     2305
     2306        $icon = wp_cache_get('mime_type_icon');
     2307       
     2308        if ( empty($icon) ) {
     2309                if ( is_numeric($mime) ) {
     2310                        $mime = (int) $mime;
     2311                        if ( !$post =& get_post( $mime ) )
     2312                                return false;
     2313                        $post_id = (int) $post->ID;
     2314                        $mime = $post->post_mime_type;
     2315                        $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);
     2316                }
     2317       
     2318                $types = array();
     2319       
     2320                if ( !empty($ext) )
     2321                        $types[] = $ext;
     2322       
     2323                $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
     2324                $icon_dir_uri = apply_filters( 'icon_dir_uri', get_template_directory_uri() . '/images' );
     2325                $image_dir = apply_filters( 'image_dir', ABSPATH . WPINC . '/images' );
     2326                $image_dir_uri = apply_filters( 'image_dir', get_option('siteurl') . '/' . WPINC . '/images' );
     2327                $dirs = array($icon_dir => $icon_dir_uri, $image_dir => $image_dir_uri);
     2328       
     2329       
     2330                if ( ! empty($mime) ) {
     2331                        $types[] = substr($mime, 0, strpos($mime, '/'));
     2332                        $types[] = substr($mime, strpos($mime, '/') + 1);
     2333                        $types[] = str_replace('/', '_', $mime);
     2334                }
     2335       
     2336                $types[] = 'default';
     2337       
     2338                $exts = array('png', 'gif', 'jpg');
     2339
     2340                foreach ( $types as $type ) {
     2341                        foreach ( $exts as $ext ) {
     2342                                foreach ( $dirs as $dir => $uri ) {
     2343                                        $src_file = "$dir/$type.$ext";
     2344                                        if ( file_exists($src_file) ) {
     2345                                                $icon = "$uri/$type.$ext";
     2346                                                break 3;
     2347                                        }
     2348                                }
    23352349                        }
    23362350                }
    23372351        }
    23382352
    2339         return apply_filters( 'wp_mime_type_icon', $src, $mime, $post_id ); // Last arg is 0 if function pass mime type.
     2353        return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); // Last arg is 0 if function pass mime type.
    23402354}
    23412355
Note: See TracChangeset for help on using the changeset viewer.