Ticket #20417: 20417.2.diff
File 20417.2.diff, 11.2 KB (added by , 13 years ago) |
---|
-
wp-includes/post.php
2034 2034 $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); 2035 2035 2036 2036 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); 2037 if ( ! empty($comment_ids) ) { 2038 do_action( 'delete_comment', $comment_ids ); 2039 foreach ( $comment_ids as $comment_id ) 2040 wp_delete_comment( $comment_id, true ); 2041 do_action( 'deleted_comment', $comment_ids ); 2042 } 2037 foreach ( $comment_ids as $comment_id ) 2038 wp_delete_comment( $comment_id, true ); 2043 2039 2044 2040 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); 2045 if ( !empty($post_meta_ids) ) { 2046 do_action( 'delete_postmeta', $post_meta_ids ); 2047 $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'"; 2048 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" ); 2049 do_action( 'deleted_postmeta', $post_meta_ids ); 2050 } 2041 foreach ( $post_meta_ids as $mid ) 2042 delete_metadata_by_id( 'post', $mid ); 2051 2043 2052 2044 do_action( 'delete_post', $postid ); 2053 2045 $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); … … 3031 3023 * @param int $post_id Post ID. 3032 3024 * @return array List of enclosures 3033 3025 */ 3034 function get_enclosed($post_id) { 3035 $custom_fields = get_post_custom( $post_id ); 3026 function get_enclosed( $post_id ) { 3027 $enclosures = get_post_meta( $post_id, 'enclosure' ); 3028 3029 if ( empty( $enclosures ) ) 3030 return array(); 3031 3036 3032 $pung = array(); 3037 if ( !is_array( $custom_fields ) )3038 return $pung;3039 3033 3040 foreach ( $custom_fields as $key => $val ) { 3041 if ( 'enclosure' != $key || !is_array( $val ) ) 3042 continue; 3043 foreach( $val as $enc ) { 3044 $enclosure = explode( "\n", $enc ); 3045 $pung[] = trim( $enclosure[ 0 ] ); 3046 } 3034 foreach ( $enclosures as $value ) { 3035 $enclosure = explode( "\n", $value ); 3036 $pung[] = trim( $value[0] ); 3047 3037 } 3048 $pung = apply_filters('get_enclosed', $pung, $post_id); 3049 return $pung;3038 3039 return apply_filters( 'get_enclosed', $pung, $post_id ); 3050 3040 } 3051 3041 3052 3042 /** … … 3800 3790 wp_delete_object_term_relationships($post_id, array('category', 'post_tag')); 3801 3791 wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type)); 3802 3792 3803 $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_thumbnail_id' , 'meta_value' => $post_id ) );3793 delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts. 3804 3794 3805 3795 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); 3806 if ( ! empty( $comment_ids ) ) { 3807 do_action( 'delete_comment', $comment_ids ); 3808 foreach ( $comment_ids as $comment_id ) 3809 wp_delete_comment( $comment_id, true ); 3810 do_action( 'deleted_comment', $comment_ids ); 3811 } 3796 foreach ( $comment_ids as $comment_id ) 3797 wp_delete_comment( $comment_id, true ); 3812 3798 3813 3799 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); 3814 if ( !empty($post_meta_ids) ) { 3815 do_action( 'delete_postmeta', $post_meta_ids ); 3816 $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'"; 3817 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" ); 3818 do_action( 'deleted_postmeta', $post_meta_ids ); 3819 } 3800 foreach ( $post_meta_ids as $mid ) 3801 delete_metadata_by_id( 'post', $mid ); 3820 3802 3821 3803 do_action( 'delete_post', $post_id ); 3822 3804 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); … … 4564 4546 return; 4565 4547 4566 4548 $data = array( 'post_id' => $post_id, 'meta_value' => '1' ); 4567 if ( get_option('default_pingback_flag') ) { 4568 $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) ); 4569 do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 ); 4570 } 4571 $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) ); 4572 do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 ); 4549 if ( get_option('default_pingback_flag') ) 4550 add_post_meta( $post_id, '_pingme', '1' ); 4551 add_post_meta( $post_id, '_encloseme', '1' ); 4573 4552 4574 4553 wp_schedule_single_event(time(), 'do_pings'); 4575 4554 } -
wp-includes/comment.php
980 980 } 981 981 982 982 // Delete metadata 983 $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) ); 984 if ( !empty($meta_ids) ) { 985 do_action( 'delete_commentmeta', $meta_ids ); 986 $in_meta_ids = "'" . implode("', '", $meta_ids) . "'"; 987 $wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" ); 988 do_action( 'deleted_commentmeta', $meta_ids ); 989 } 983 $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) ); 984 foreach ( $meta_ids as $mid ) 985 delete_metadata_by_id( 'comment', $mid ); 990 986 991 987 if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) ) 992 988 return false; -
wp-includes/functions.php
410 410 function do_enclose( $content, $post_ID ) { 411 411 global $wpdb; 412 412 413 //TODO: Tidy this ghetto code up and make the debug code optional414 include_once( ABSPATH . WPINC . '/class-IXR.php' );415 416 413 $post_links = array(); 417 414 418 415 $pung = get_enclosed( $post_ID ); … … 422 419 $punc = '.:?\-'; 423 420 $any = $ltrs . $gunk . $punc; 424 421 425 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links _temp);422 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links ); 426 423 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 ); 434 430 } 435 431 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; 446 444 } 447 445 448 foreach ( (array) $post_links as $url ) { 449 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, like_escape( $url ) . '%' ) ) ) { 446 $new_links = array_unique( $new_links ); 450 447 451 if ( $headers = wp_get_http_headers( $url) ) { 452 $len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0; 453 $type = isset( $headers['content-type'] ) ? $headers['content-type'] : ''; 454 $allowed_types = array( 'video', 'audio' ); 448 foreach ( $new_links as $url ) { 449 if ( ! $headers = wp_get_http_headers( $url ) ) 450 continue; 455 451 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'] : ''; 470 454 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; 475 463 } 476 464 } 477 465 } 466 467 list( $type ) = explode( '/', $mime ); // Get first segment. 468 if ( 'video' == $type || 'audio' == $type ) 469 add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" ); 478 470 } 479 471 } 480 472 -
wp-includes/meta.php
223 223 224 224 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 225 225 226 // Old-style action. 226 227 if ( 'post' == $meta_type ) 227 228 do_action( 'delete_postmeta', $meta_ids ); 228 229 … … 243 244 244 245 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 245 246 247 // Old-style action. 246 248 if ( 'post' == $meta_type ) 247 249 do_action( 'deleted_postmeta', $meta_ids ); 248 250 … … 485 487 486 488 do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 487 489 488 if ( 'post' == $meta_type ) 489 do_action( 'delete_postmeta', $meta_id ); 490 // Old-style action. 491 if ( 'post' == $meta_type || 'comment' == $meta_type ) 492 do_action( "delete_{$meta_type}meta", $meta_id ); 490 493 491 494 // Run the query, will return true if deleted, false otherwise 492 495 $result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) ); … … 496 499 497 500 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 498 501 499 if ( 'post' == $meta_type ) 500 do_action( 'deleted_postmeta', $meta_id ); 502 // Old-style action. 503 if ( 'post' == $meta_type || 'comment' == $meta_type ) 504 do_action( "deleted_{$meta_type}meta", $meta_id ); 501 505 502 506 return $result; 503 507