From 82b0dfbb723b9e32cb6d12faa1f2a3e4c6088042 Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 30 Dec 2009 07:36:17 +0000 Subject: [PATCH] Attempt to detect the correct post enclosure mime type, props josephscott, fixes #11668 git-svn-id: http://svn.automattic.com/wordpress/trunk@12580 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 6cb67c97f..48712cfa7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1160,10 +1160,25 @@ function do_enclose( $content, $post_ID ) { foreach ( (array) $post_links as $url ) { 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 . '%' ) ) ) { + if ( $headers = wp_get_http_headers( $url) ) { $len = (int) $headers['content-length']; $type = $headers['content-type']; $allowed_types = array( 'video', 'audio' ); + + // Check to see if we can figure out the mime type from + // the extension + $url_parts = parse_url( $url ); + $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); + if ( !empty( $extension ) ) { + foreach ( get_allowed_mime_types( ) as $exts => $mime ) { + if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { + $type = $mime; + break; + } + } + } + if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { $meta_value = "$url\n$len\n$type\n"; $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );