Ticket #21285: pings.diff
File pings.diff, 5.2 KB (added by , 13 years ago) |
---|
-
wp-includes/comment.php
1670 1670 */ 1671 1671 function do_all_pings() { 1672 1672 global $wpdb; 1673 1674 1673 // Do pingbacks 1675 1674 while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { 1676 1675 delete_metadata_by_mid( 'post', $ping->meta_id ); … … 1776 1775 1777 1776 $pung = get_pung($post_ID); 1778 1777 1779 // Variables1780 $ltrs = '\w';1781 $gunk = '/#~:.?+=&%@!\-';1782 $punc = '.:?\-';1783 $any = $ltrs . $gunk . $punc;1784 1785 1778 // Step 1 1786 1779 // Parsing the post, external links (if any) are stored in the $post_links array 1787 1780 // This regexp comes straight from phpfreaks.com 1788 1781 // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php 1789 preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);1782 $post_links_temp = parse_content_for_ping_urls( $content ); 1790 1783 1791 1784 // Step 2. 1792 1785 // Walking thru the links array … … 1797 1790 // http://dummy-weblog.org/post.php 1798 1791 // We don't wanna ping first and second types, even if they have a valid <link/> 1799 1792 1800 foreach ( (array) $post_links_temp[0] as $link_test ) : 1801 if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself 1802 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. 1803 if ( $test = @parse_url($link_test) ) { 1804 if ( isset($test['query']) ) 1805 $post_links[] = $link_test; 1806 elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) 1807 $post_links[] = $link_test; 1808 } 1809 endif; 1810 endforeach; 1811 1793 foreach ( (array) $post_links_temp[0] as $link_test ) 1794 if ( !in_array( $link_test, $pung ) 1795 && ( url_to_postid( $link_test ) != $post_ID ) // If we haven't pung it already and it isn't a link to itself 1796 && !is_local_attachment( $link_test ) // Also, let's never ping local attachments. 1797 && check_ping_url( $link_test ) ) { 1798 1799 $post_links[] = $link_test; 1800 } 1801 1812 1802 do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post_ID ) ); 1813 1803 1814 1804 foreach ( (array) $post_links as $pagelinkedto ) { -
wp-includes/functions.php
393 393 } 394 394 395 395 /** 396 * Matches pingable URLs in content 397 * 398 * @since 3.5.0 399 * 400 * @param string $content Post content. 401 * @return array of URLs found in content 402 */ 403 function parse_content_for_ping_urls( $content ) { 404 $ltrs = '\w'; 405 $gunk = '/#~:.?+=&%@!\-'; 406 $punc = '.:?\-'; 407 $any = $ltrs . $gunk . $punc; 408 409 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp ); 410 return $post_links_temp; 411 } 412 413 /** 414 * Checks ping URLs 415 * 416 * @since 3.5.0 417 * 418 * @param string $url URL. 419 * @return bool|string False on failure and url if it passes tests. 420 */ 421 function check_ping_url( $url ) { 422 $siteurl = @parse_url( get_option( 'siteurl' ) ); 423 $test = @parse_url( $url ); 424 if ( $test && strstr( $test['host'], '.' ) && $test['host'] != $siteurl['host'] ) { // don't ping URLs (.-less vhosts) on localhost, HEAD requests will cause massive seg faults 425 if ( isset( $test['query'] ) ) 426 return $url; 427 elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) 428 return $url; 429 } 430 return false; 431 } 432 433 /** 396 434 * Check content for video and audio links to add as enclosures. 397 435 * 398 436 * Will not add enclosures that have already been added and will … … 416 454 $post_links = array(); 417 455 418 456 $pung = get_enclosed( $post_ID ); 457 $post_links_temp = parse_content_for_ping_urls( $content ); 419 458 420 $ltrs = '\w';421 $gunk = '/#~:.?+=&%@!\-';422 $punc = '.:?\-';423 $any = $ltrs . $gunk . $punc;424 425 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );426 427 459 foreach ( $pung as $link_test ) { 428 460 if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post 429 461 $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_test ) . '%') ); … … 432 464 } 433 465 } 434 466 435 foreach ( (array) $post_links_temp[0] as $link_test ) { 436 if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already 437 $test = @parse_url( $link_test ); 438 if ( false === $test ) 439 continue; 440 if ( isset( $test['query'] ) ) 441 $post_links[] = $link_test; 442 elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) ) 443 $post_links[] = $link_test; 444 } 445 } 446 467 foreach ( (array) $post_links_temp[0] as $link_test ) 468 if ( !in_array( $link_test, $pung ) && check_ping_url( $link_test ) ) // If we haven't pung it already 469 $post_links[] = $link_test; 470 447 471 foreach ( (array) $post_links as $url ) { 448 472 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 ) . '%' ) ) ) { 449 473