427 | | foreach ( $pung as $link_test ) { |
428 | | if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post |
429 | | $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, like_escape( $link_test ) . '%') ); |
430 | | do_action( 'delete_postmeta', $mid ); |
431 | | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) ); |
432 | | do_action( 'deleted_postmeta', $mid ); |
433 | | } |
| 424 | // Remove enclosures that are no longer linked in the post. |
| 425 | $removed_links = array_diff( $pung, $post_links[0] ); |
| 426 | foreach ( $removed_links as $link ) { |
| 427 | $mids = $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, like_escape( $link ) . '%') ); |
| 428 | foreach ( $mids as $mid ) |
| 429 | delete_metadata_by_mid( 'post', $mid ); |
436 | | foreach ( (array) $post_links_temp[0] as $link_test ) { |
437 | | if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already |
438 | | $test = @parse_url( $link_test ); |
439 | | if ( false === $test ) |
440 | | continue; |
441 | | if ( isset( $test['query'] ) ) |
442 | | $post_links[] = $link_test; |
443 | | elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) ) |
444 | | $post_links[] = $link_test; |
445 | | } |
| 432 | $new_links = array(); |
| 433 | |
| 434 | // Find enclosures that are new to the post. |
| 435 | $added_links = array_diff( $post_links[0], $pung ); |
| 436 | foreach ( $added_links as $link ) { |
| 437 | $test = @parse_url( $link ); |
| 438 | if ( false === $test ) |
| 439 | continue; |
| 440 | if ( ! empty( $test['query'] ) ) |
| 441 | $new_links[] = $link; |
| 442 | elseif ( ! empty( $test['path'] ) && '/' != $test['path'] ) |
| 443 | $new_links[] = $link; |
456 | | // Check to see if we can figure out the mime type from |
457 | | // the extension |
458 | | $url_parts = @parse_url( $url ); |
459 | | if ( false !== $url_parts ) { |
460 | | $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
461 | | if ( !empty( $extension ) ) { |
462 | | foreach ( get_allowed_mime_types( ) as $exts => $mime ) { |
463 | | if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
464 | | $type = $mime; |
465 | | break; |
466 | | } |
467 | | } |
468 | | } |
469 | | } |
| 452 | $len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0; |
| 453 | $type = isset( $headers['content-type'] ) ? $headers['content-type'] : ''; |
471 | | if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { |
472 | | $meta_value = "$url\n$len\n$type\n"; |
473 | | $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) ); |
474 | | do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value ); |
| 455 | // Check to see if we can figure out the mime type from the extension |
| 456 | $url_parts = @parse_url( $url ); |
| 457 | if ( false !== $url_parts ) { |
| 458 | $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
| 459 | if ( !empty( $extension ) ) { |
| 460 | foreach ( get_allowed_mime_types() as $exts => $mime ) { |
| 461 | if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) |
| 462 | break; |