WordPress.org

Make WordPress Core

Ticket #21285: pings.diff

File pings.diff, 5.2 KB (added by wonderboymusic, 3 years ago)
  • wp-includes/comment.php

     
    16701670 */ 
    16711671function do_all_pings() { 
    16721672        global $wpdb; 
    1673  
    16741673        // Do pingbacks 
    16751674        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")) { 
    16761675                delete_metadata_by_mid( 'post', $ping->meta_id ); 
     
    17761775 
    17771776        $pung = get_pung($post_ID); 
    17781777 
    1779         // Variables 
    1780         $ltrs = '\w'; 
    1781         $gunk = '/#~:.?+=&%@!\-'; 
    1782         $punc = '.:?\-'; 
    1783         $any = $ltrs . $gunk . $punc; 
    1784  
    17851778        // Step 1 
    17861779        // Parsing the post, external links (if any) are stored in the $post_links array 
    17871780        // This regexp comes straight from phpfreaks.com 
    17881781        // 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 ); 
    17901783 
    17911784        // Step 2. 
    17921785        // Walking thru the links array 
     
    17971790        // http://dummy-weblog.org/post.php 
    17981791        // We don't wanna ping first and second types, even if they have a valid <link/> 
    17991792 
    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                 
    18121802        do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post_ID ) ); 
    18131803 
    18141804        foreach ( (array) $post_links as $pagelinkedto ) { 
  • wp-includes/functions.php

     
    393393} 
    394394 
    395395/** 
     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 */ 
     403function 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 */ 
     421function 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/** 
    396434 * Check content for video and audio links to add as enclosures. 
    397435 * 
    398436 * Will not add enclosures that have already been added and will 
     
    416454        $post_links = array(); 
    417455 
    418456        $pung = get_enclosed( $post_ID ); 
     457        $post_links_temp = parse_content_for_ping_urls( $content ); 
    419458 
    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  
    427459        foreach ( $pung as $link_test ) { 
    428460                if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post 
    429461                        $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 ) . '%') ); 
     
    432464                } 
    433465        } 
    434466 
    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                 
    447471        foreach ( (array) $post_links as $url ) { 
    448472                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 ) . '%' ) ) ) { 
    449473