Make WordPress Core

Changeset 12580


Ignore:
Timestamp:
12/30/2009 07:36:17 AM (15 years ago)
Author:
azaozz
Message:

Attempt to detect the correct post enclosure mime type, props josephscott, fixes #11668

File:
1 edited

Legend:

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

    r12537 r12580  
    11611161    foreach ( (array) $post_links as $url ) {
    11621162        if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
     1163
    11631164            if ( $headers = wp_get_http_headers( $url) ) {
    11641165                $len = (int) $headers['content-length'];
    11651166                $type = $headers['content-type'];
    11661167                $allowed_types = array( 'video', 'audio' );
     1168
     1169                // Check to see if we can figure out the mime type from
     1170                // the extension
     1171                $url_parts = parse_url( $url );
     1172                $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
     1173                if ( !empty( $extension ) ) {
     1174                    foreach ( get_allowed_mime_types( ) as $exts => $mime ) {
     1175                        if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
     1176                            $type = $mime;
     1177                            break;
     1178                        }
     1179                    }
     1180                }
     1181
    11671182                if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    11681183                    $meta_value = "$url\n$len\n$type\n";
Note: See TracChangeset for help on using the changeset viewer.