Ticket #2092: future-pings.diff

File future-pings.diff, 6.3 KB (added by skeltoac, 7 years ago)

3330

  • wp-includes/functions-post.php

     
    182182                do_action('publish_post', $post_ID); 
    183183 
    184184                if ( !defined('WP_IMPORTING') ) { 
    185                         if ( $post_pingback ) 
    186                                 $result = $wpdb->query(" 
    187                                         INSERT INTO $wpdb->postmeta  
    188                                         (post_id,meta_key,meta_value)  
    189                                         VALUES ('$post_ID','_pingme','1') 
    190                                 "); 
    191                         $result = $wpdb->query(" 
    192                                 INSERT INTO $wpdb->postmeta  
    193                                 (post_id,meta_key,meta_value)  
    194                                 VALUES ('$post_ID','_encloseme','1') 
    195                         "); 
     185                        if ( $post_pingback ) { 
     186                                $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE ID = $post_ID AND meta_key = '_pingme'"); 
     187                                $result = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_ID','_pingme','$post_date_gmt')"); 
     188                        } 
     189                        $result = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_ID','_encloseme','1')"); 
    196190                        spawn_pinger(); 
    197191                } 
     192        } elseif ( $previous_status == 'publish' ) { 
     193                // Remove scheduled pings (in case you unpublish a future post) 
     194                $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE ID = $post_ID AND meta_key = '_pingme'"); 
    198195        } else if ($post_status == 'static') { 
    199196                generate_page_rewrite_rules(); 
    200197 
  • wp-includes/classes.php

     
    670670 
    671671                update_post_caches($this->posts); 
    672672 
     673                if ( have_pings_in_cache() ) 
     674                        spawn_pinger(1); 
     675 
    673676                $this->posts = apply_filters('the_posts', $this->posts); 
    674677                $this->post_count = count($this->posts); 
    675678                if ($this->post_count > 0) { 
  • wp-includes/functions.php

     
    980980        } 
    981981} 
    982982 
    983 function spawn_pinger() { 
    984         global $wpdb; 
    985         $doping = false; 
    986         if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") ) 
     983function have_pings_in_cache() { 
     984        global $post_cache, $post_meta_cache; 
     985 
     986        $ping = false; 
     987 
     988        if ( count($post_cache) ) { 
     989                foreach ($post_cache as $post) 
     990                        if ( (trim($post->to_ping) != '') && (strtotime($post->post_date_gmt) <= gmdate('U')) ) { 
     991                                $ping = true; 
     992                                break; 
     993                        } 
     994 
     995                reset($post_cache); 
     996        } 
     997 
     998        if ( count($post_meta_cache) ) { 
     999                foreach ($post_meta_cache as $meta) 
     1000                        if ( isset($meta['_pingme']) && (strtotime($meta['_pingme']) <= gmdate('U')) ) { 
     1001                                $ping = true; 
     1002                                break; 
     1003                        } 
     1004 
     1005                reset($post_meta_cache); 
     1006        } 
     1007 
     1008        return $ping; 
     1009} 
     1010 
     1011function spawn_pinger($doping = false) { 
     1012        global $wpdb, $spawned_pinger; 
     1013 
     1014        if ( $spawned_pinger > $doping ) 
     1015                return; 
     1016 
     1017        $now = gmdate('Y-m-d H:i:59'); 
     1018 
     1019        if ( !$doping && $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_date_gmt <= '$now' LIMIT 1") ) 
    9871020                $doping = true; 
    9881021 
    989         if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") ) 
     1022        if ( !$doping && $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = '_pingme' AND meta_value <= '$now') OR meta_key = '_encloseme' LIMIT 1") ) 
    9901023                $doping = true; 
    9911024 
    9921025        if ( $doping ) { 
    9931026                $ping_url = get_settings('siteurl') .'/wp-admin/execute-pings.php'; 
    9941027                $parts = parse_url($ping_url); 
    9951028                $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01); 
     1029 
    9961030                if ( $argyle ) 
    9971031                        fputs($argyle, "GET {$parts['path']}?time=".time()." HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n"); 
     1032 
     1033                ++$spawned_pinger; 
    9981034       } 
    9991035} 
    10001036 
  • wp-admin/execute-pings.php

     
    11<?php 
     2 
     3ignore_user_abort(true); 
     4 
    25require_once('../wp-config.php'); 
    36 
    4 register_shutdown_function('execute_all_pings'); 
    5 //execute_all_pings(); 
     7$now = gmdate('Y-m-d H:i:59'); 
    68 
    7 function execute_all_pings() { 
    8         global $wpdb; 
    9         // Do pingbacks 
    10         while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { 
    11                 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); 
    12                 pingback($ping->post_content, $ping->ID); 
    13                 echo "Pingback: $ping->post_title : $ping->ID<br/>"; 
    14         } 
    15         // Do Enclosures 
    16         while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { 
    17                 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';"); 
    18                 do_enclose($enclosure->post_content, $enclosure->ID); 
    19                 echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>"; 
    20         } 
    21         // Do Trackbacks 
    22         while ($trackback = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft' LIMIT 1")) { 
    23                 echo "Trackback : $trackback->ID<br/>"; 
    24                 do_trackbacks($trackback->ID); 
    25         } 
     9// Do pingbacks 
     10while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' AND {$wpdb->postmeta}.meta_value <= '$now' LIMIT 1")) { 
     11        $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); 
     12        pingback($ping->post_content, $ping->ID); 
     13        echo "Pingback: $ping->post_title : $ping->ID<br/>"; 
    2614} 
    2715 
    28 _e('Done.'); 
     16// Do Enclosures 
     17while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { 
     18        $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';"); 
     19        do_enclose($enclosure->post_content, $enclosure->ID); 
     20        echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>"; 
     21} 
    2922 
     23// Do Trackbacks 
     24while ($trackback = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft' ANT post_date_gmt <= '$now' LIMIT 1")) { 
     25        echo "Trackback : $trackback->ID<br/>"; 
     26        do_trackbacks($trackback->ID); 
     27} 
     28 
    3029?>