1184 | | if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post |
1185 | | $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') ); |
| 1190 | if ( !in_array( $link_test, $post_links ) ) { // link no longer in post |
| 1191 | $mid = $wpdb->get_col( $wpdb->prepare( |
| 1192 | "SELECT meta_id FROM `$wpdb->postmeta` WHERE `post_id` = %d AND `meta_key` = 'enclosure' AND `meta_value` LIKE (%s)", |
| 1193 | $post_id, |
| 1194 | like_escape( $link_test ) . '%' // Delete everything for which this URL is a prefix? |
| 1195 | ) ); |
1192 | | foreach ( (array) $post_links_temp[0] as $link_test ) { |
1193 | | if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already |
1194 | | $test = @parse_url( $link_test ); |
1195 | | if ( false === $test ) |
1196 | | continue; |
1197 | | if ( isset( $test['query'] ) ) |
1198 | | $post_links[] = $link_test; |
1199 | | elseif ( $test['path'] != '/' && $test['path'] != '' ) |
1200 | | $post_links[] = $link_test; |
1201 | | } |
1202 | | } |
| 1203 | do_action_ref_array( 'pre_enclose', array( &$post_links, &$pung ) ); |
1207 | | if ( $headers = wp_get_http_headers( $url) ) { |
1208 | | $len = (int) $headers['content-length']; |
1209 | | $type = $headers['content-type']; |
1210 | | $allowed_types = array( 'video', 'audio' ); |
| 1213 | // Done it or something like it |
| 1214 | if ( $wpdb->get_var( $wpdb->prepare( |
| 1215 | "SELECT `post_id` FROM `$wpdb->postmeta` WHERE `post_id` = %d AND `meta_key` = 'enclosure' AND `meta_value` LIKE (%s)", |
| 1216 | $post_id, |
| 1217 | like_escape( $url ) . '%' |
| 1218 | ) ) ) |
| 1219 | continue; |
1212 | | // Check to see if we can figure out the mime type from |
1213 | | // the extension |
1214 | | $url_parts = @parse_url( $url ); |
1215 | | if ( false !== $url_parts ) { |
1216 | | $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
1217 | | if ( !empty( $extension ) ) { |
1218 | | foreach ( get_allowed_mime_types( ) as $exts => $mime ) { |
1219 | | if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
1220 | | $type = $mime; |
1221 | | break; |
1222 | | } |
1223 | | } |
| 1221 | if ( !$headers = wp_get_http_headers( $url ) ) |
| 1222 | continue; |
| 1223 | |
| 1224 | $len = (int) $headers['content-length']; |
| 1225 | $type = $headers['content-type']; |
| 1226 | |
| 1227 | // Check to see if we can figure out the mime type from |
| 1228 | // the extension |
| 1229 | if ( false !== $url_parts ) { |
| 1230 | $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
| 1231 | if ( !empty( $extension ) ) { |
| 1232 | foreach ( $extension_map as $exts => $mime ) { |
| 1233 | if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
| 1234 | $type = $mime; |
| 1235 | break; |
1226 | | |
1227 | | if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { |
1228 | | $meta_value = "$url\n$len\n$type\n"; |
1229 | | $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) ); |
1230 | | do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value ); |
1231 | | } |
| 1240 | |
| 1241 | list( $type ) = explode( '/', $type, 2 ); |
| 1242 | |
| 1243 | if ( !in_array( $type, $allowed_types ) ) |
| 1244 | continue; |
| 1245 | |
| 1246 | $meta_value = "$url\n$len\n$type\n"; |
| 1247 | $wpdb->insert( $wpdb->postmeta, compact( 'post_id', 'meta_key', 'meta_value' ) ); |
| 1248 | do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $meta_key, $meta_value ); |
| 1253 | * Remove root URLs from the list of URLs to check for inclusion as enclosures. |
| 1254 | * |
| 1255 | * @package WordPress |
| 1256 | * @since 3.1 |
| 1257 | * |
| 1258 | * @param array $post_links Reference to array of URLs to check for inclusion as enclosures |
| 1259 | */ |
| 1260 | function dont_enclose_root_urls( &$post_links ) { |
| 1261 | $r = array(); |
| 1262 | foreach ( (array) $post_links as $post_link ) { |
| 1263 | // Only ping enclosures for URLs with a Query or Path - not Root URLs |
| 1264 | $path = parse_url( $post_link, PHP_URL_PATH ); |
| 1265 | if ( $path && '/' != $path ) |
| 1266 | $r[] = $post_link; |
| 1267 | else if ( parse_url( $post_link, PHP_URL_QUERY ) ) |
| 1268 | $r[] = $post_link; |
| 1269 | } |
| 1270 | $post_links = $r; |
| 1271 | } |
| 1272 | |
| 1273 | /** |