2344 | | if ( !$post =& get_post( $mime ) ) |
2345 | | return false; |
2346 | | $post_id = (int) $post->ID; |
2347 | | $mime = $post->post_mime_type; |
2348 | | $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid); |
| 2345 | if ( $post =& get_post( $mime ) ) { |
| 2346 | $post_id = (int) $post->ID; |
| 2347 | $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid); |
| 2348 | if ( !empty($ext) ) |
| 2349 | $post_mimes[] = $ext; |
| 2350 | $mime = $post->post_mime_type; |
| 2351 | } else { |
| 2352 | $mime = 0; |
| 2353 | } |
| 2354 | } else { |
| 2355 | $post_mimes[] = $mime; |
2350 | | |
2351 | | $types = array(); |
2352 | | |
2353 | | if ( !empty($ext) ) |
2354 | | $types[] = $ext; |
2355 | | |
2356 | | $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' ); |
2357 | | $icon_dir_uri = apply_filters( 'icon_dir_uri', get_template_directory_uri() . '/images' ); |
2358 | | $image_dir = apply_filters( 'image_dir', ABSPATH . WPINC . '/images' ); |
2359 | | $image_dir_uri = apply_filters( 'image_dir', get_option('siteurl') . '/' . WPINC . '/images' ); |
2360 | | $dirs = array($icon_dir => $icon_dir_uri, $image_dir => $image_dir_uri); |
2361 | | |
2362 | | |
2363 | | if ( ! empty($mime) ) { |
2364 | | $types[] = substr($mime, 0, strpos($mime, '/')); |
2365 | | $types[] = substr($mime, strpos($mime, '/') + 1); |
2366 | | $types[] = str_replace('/', '_', $mime); |
2367 | | } |
2368 | | |
2369 | | $types[] = 'default'; |
2370 | | |
2371 | | $exts = array('png', 'gif', 'jpg'); |
2373 | | foreach ( $types as $type ) { |
2374 | | foreach ( $exts as $ext ) { |
2375 | | foreach ( $dirs as $dir => $uri ) { |
2376 | | $src_file = "$dir/$type.$ext"; |
2377 | | if ( file_exists($src_file) ) { |
2378 | | $icon = "$uri/$type.$ext"; |
2379 | | break 3; |
| 2358 | $icon_files = wp_cache_get('icon_files'); |
| 2359 | |
| 2360 | if ( !is_array($icon_files) ) { |
| 2361 | $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images' ); |
| 2362 | $icon_dir_uri = apply_filters( 'icon_dir_uri', trailingslashit(get_option('siteurl')) . WPINC . '/images' ); |
| 2363 | $dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) ); |
| 2364 | $icon_files = array(); |
| 2365 | foreach ( $dirs as $dir => $uri) { |
| 2366 | if ( $dh = opendir($dir) ) { |
| 2367 | while ( false !== $file = readdir($dh) ) { |
| 2368 | $file = basename($file); |
| 2369 | if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { |
| 2370 | if ( is_dir($file) ) |
| 2371 | $dirs["$dir/$file"] = "$uri/$file"; |
| 2372 | continue; |
| 2373 | } |
| 2374 | $icon_files["$dir/$file"] = "$uri/$file"; |
| 2381 | |
| 2382 | // Icon basename - extension = MIME wildcard |
| 2383 | foreach ( $icon_files as $file => $uri ) |
| 2384 | $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; |
| 2385 | |
| 2386 | if ( ! empty($mime) ) { |
| 2387 | $post_mimes[] = substr($mime, 0, strpos($mime, '/')); |
| 2388 | $post_mimes[] = substr($mime, strpos($mime, '/') + 1); |
| 2389 | $post_mimes[] = str_replace('/', '_', $mime); |
| 2390 | } |
| 2391 | |
| 2392 | $post_mimes[] = 'default'; |
| 2393 | |
| 2394 | $matches = wp_match_mime_types(array_keys($types), $post_mimes); |
| 2395 | |
| 2396 | foreach ( $matches as $match => $wilds ) { |
| 2397 | if ( isset($types[$wilds[0]])) { |
| 2398 | $icon = $types[$wilds[0]]; |
| 2399 | if ( !is_numeric($mime) ) |
| 2400 | wp_cache_set("mime_type_icon_$mime", $icon); |
| 2401 | break; |
| 2402 | } |
| 2403 | } |