New asyncronous ping method. fixes #2048

git-svn-id: http://svn.automattic.com/wordpress/trunk@3317 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-16 03:04:33 +00:00
parent c98cc7da09
commit 97cd7143da
5 changed files with 30 additions and 24 deletions

View File

@ -6,7 +6,6 @@
</p>
</div>
<?php check_for_pings(); ?>
<?php do_action('admin_footer', ''); ?>
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
</body>

View File

@ -1,10 +1,6 @@
<?php
require_once('admin.php');
require_once('../wp-config.php');
if ( ! current_user_can('edit_posts') )
die (__("Cheatin' uh?"));
echo '/* No Styles Here */';
register_shutdown_function('execute_all_pings');
//execute_all_pings();
@ -14,7 +10,7 @@ function execute_all_pings() {
if($pings = $wpdb->get_results("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme';")) {
foreach($pings as $ping) {
pingback($ping->post_content, $ping->ID);
//echo "Pingback: $ping->post_title : $ping->ID<br/>";
echo "Pingback: $ping->post_title : $ping->ID<br/>";
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
}
}
@ -22,16 +18,19 @@ function execute_all_pings() {
if($enclosures = $wpdb->get_results("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme';")) {
foreach($enclosures as $enclosure) {
do_enclose($enclosure->post_content, $enclosure->ID);
//echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>";
echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>";
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
}
}
// Do Trackbacks
if($trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft'")) {
foreach($trackbacks as $trackback) {
//echo "trackback : $trackback->ID<br/>";
echo "Trackback : $trackback->ID<br/>";
do_trackbacks($trackback->ID);
}
}
}
_e('Done.');
?>

View File

@ -639,7 +639,7 @@ function pingback($content, $post_ID) {
$pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
if ($pingback_server_url) {
set_time_limit( 60 );
@ set_time_limit( 60 );
// Now, the RPC call
debug_fwrite($log, "Page Linked To: $pagelinkedto \n");
debug_fwrite($log, 'Page Linked From: ');

View File

@ -181,20 +181,21 @@ function wp_insert_post($postarr = array()) {
if ($post_status == 'publish') {
do_action('publish_post', $post_ID);
if ($post_pingback && !defined('WP_IMPORTING'))
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_pingme','1')
");
if ( !defined('WP_IMPORTING') )
if ( !defined('WP_IMPORTING') ) {
if ( $post_pingback )
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_pingme','1')
");
$result = $wpdb->query("
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','_encloseme','1')
");
//register_shutdown_function('do_trackbacks', $post_ID);
} else if ($post_status == 'static') {
spawn_pinger();
}
} else if ($post_status == 'static') {
generate_page_rewrite_rules();
if ( !empty($page_template) )
@ -702,6 +703,8 @@ function do_trackbacks($post_id) {
if ( !in_array($tb_ping, $pinged) ) {
trackback($tb_ping, $post_title, $excerpt, $post_id);
$pinged[] = $tb_ping;
} else {
$wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'");
}
endforeach; endif;
}

View File

@ -860,7 +860,7 @@ function trackback($trackback_url, $title, $excerpt, $ID) {
$tb_url = addslashes( $tb_url );
$wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");
return $wpdb->query("UPDATE $wpdb->posts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'");
return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'");
}
function make_url_footnote($content) {
@ -937,7 +937,7 @@ function debug_fclose($fp) {
}
}
function check_for_pings() {
function spawn_pinger() {
global $wpdb;
$doping = false;
if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
@ -946,8 +946,13 @@ function check_for_pings() {
if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
$doping = true;
if ( $doping )
echo '<iframe id="pingcheck" src="' . get_settings('siteurl') .'/wp-admin/execute-pings.php?time=' . time() . '" style="border:none;width:1px;height:1px;"></iframe>';
if ( $doping ) {
$ping_url = get_settings('siteurl') .'/wp-admin/execute-pings.php';
$parts = parse_url($ping_url);
$argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);
if ( $argyle )
fputs($argyle, "GET {$parts['path']}?time=".time()." HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n");
}
}
function do_enclose( $content, $post_ID ) {