From 7d72c03fb8effaaf61ba298f9d8f5970ece40a0b Mon Sep 17 00:00:00 2001 From: Matt Mullenweg Date: Mon, 22 Dec 2003 02:46:40 +0000 Subject: [PATCH] Trackback on edit done. git-svn-id: https://develop.svn.wordpress.org/trunk@636 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/edit-form.php | 26 ++++++++++- wp-admin/post.php | 82 +++++++++++++++++++++------------ wp-admin/upgrade-072-to-080.php | 5 ++ wp-includes/functions.php | 72 +++++++++++++---------------- wp-trackback.php | 2 +- 5 files changed, 114 insertions(+), 73 deletions(-) diff --git a/wp-admin/edit-form.php b/wp-admin/edit-form.php index 1c5c6120d7..7ba6dad91e 100644 --- a/wp-admin/edit-form.php +++ b/wp-admin/edit-form.php @@ -26,8 +26,16 @@ switch($action) { $form_pingback = ''; } if ($use_trackback) { - $form_trackback = '

(Separate multiple URLs with commas.)
+ $form_trackback = '

(Separate multiple URLs with spaces.)

'; + if ('' != $pinged) { + $form_trackback .= '

Already pinged:

'; + } } else { $form_trackback = ''; } @@ -42,7 +50,21 @@ switch($action) { $colspan = 2; $form_pingback = ''; $form_prevstatus = ''; - $form_trackback = ''; + if ($use_trackback) { + $form_trackback = '

+ (Separate multiple URLs with spaces.)
+

'; + if ('' != $pinged) { + $form_trackback .= '

Already pinged:

'; + } + } else { + $form_trackback = ''; + } break; case "editcomment": $submitbutton_text = 'Edit this!'; diff --git a/wp-admin/post.php b/wp-admin/post.php index b26737c493..b0ef0a265c 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -62,6 +62,9 @@ switch($action) { $ping_status = $HTTP_POST_VARS['ping_status']; $post_password = addslashes($HTTP_POST_VARS['post_password']); $post_name = sanitize_title($post_title); + $trackback = $HTTP_POST_VARS['trackback_url']; + // Format trackbacks + $trackback = preg_replace('|\s+|', '\n', $trackback); if ($user_level == 0) die ('Cheatin’ uh?'); @@ -86,15 +89,15 @@ switch($action) { if((get_settings('use_geo_positions')) && (strlen($latstr) > 2) && (strlen($lonstr) > 2) ) { $postquery ="INSERT INTO $tableposts - (ID, post_author, post_date, post_content, post_title, post_lat, post_lon, post_excerpt, post_status, comment_status, ping_status, post_password, post_name) + (ID, post_author, post_date, post_content, post_title, post_lat, post_lon, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping) VALUES - ('0', '$user_ID', '$now', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name') + ('0', '$user_ID', '$now', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback') "; } else { $postquery ="INSERT INTO $tableposts - (ID, post_author, post_date, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name) + (ID, post_author, post_date, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping) VALUES - ('0', '$user_ID', '$now', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name') + ('0', '$user_ID', '$now', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback') "; } $postquery = @@ -140,7 +143,8 @@ switch($action) { } if ('' != $HTTP_POST_VARS['save']) $location = "post.php?action=edit&post=$post_ID"; - header("Location: $location"); + + header("Location: $location"); if ($post_status == 'publish') { if((get_settings('use_geo_positions')) && ($post_latf != null) && ($post_lonf != null)) { @@ -153,19 +157,26 @@ switch($action) { pingback($content, $post_ID); } - if (!empty($HTTP_POST_VARS['trackback_url'])) { + // Time for trackbacks + $to_ping = $wpdb->get_var("SELECT to_ping FROM $tableposts WHERE ID = $post_ID"); + $pinged = $wpdb->get_var("SELECT pinged FROM $tableposts WHERE ID = $post_ID"); + $pinged = explode("\n", $pinged); + if ('' != $to_ping) { if (strlen($excerpt) > 0) { $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt) ; } else { $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content); } - $excerpt = stripslashes($the_excerpt); - $trackback_urls = explode(',', $HTTP_POST_VARS['trackback_url']); - foreach($trackback_urls as $tb_url) { - $tb_url = trim($tb_url); - trackback($tb_url, stripslashes($post_title), $excerpt, $post_ID); - } - } + $excerpt = stripslashes($the_excerpt); + $to_pings = explode("\n", $to_ping); + foreach ($to_pings as $tb_ping) { + $tb_ping = trim($tb_ping); + if (!in_array($tb_ping, $pinged)) { + trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID); + } + } + } + } // end if publish exit(); @@ -195,6 +206,8 @@ switch($action) { $comment_status = $postdata['comment_status']; $ping_status = $postdata['ping_status']; $post_password = $postdata['post_password']; + $to_ping = $postdata['to_ping']; + $pinged = $postdata['pinged']; include('edit-form.php'); } else { @@ -245,6 +258,9 @@ switch($action) { $ping_status = $HTTP_POST_VARS['ping_status']; $post_password = addslashes($HTTP_POST_VARS['post_password']); $post_name = sanitize_title($post_title); + $trackback = $HTTP_POST_VARS['trackback_url']; + // Format trackbacks + $trackback = preg_replace('|\s+|', '\n', $trackback); if (($user_level > 4) && (!empty($HTTP_POST_VARS['edit_date']))) { $aa = $HTTP_POST_VARS['aa']; @@ -273,7 +289,8 @@ switch($action) { comment_status = '$comment_status', ping_status = '$ping_status', post_password = '$post_password', - post_name = '$post_name' + post_name = '$post_name', + to_ping = '$trackback' WHERE ID = $post_ID "); @@ -301,21 +318,29 @@ switch($action) { if ((($prev_status == 'draft') || ($prev_status == 'private')) && ($post_status == 'publish')) { pingWeblogs($blog_ID); pingBlogs($blog_ID); - - if ($post_pingback) { - pingback($content, $post_ID); - } - - if (!empty($HTTP_POST_VARS['trackback_url'])) { - $excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content); - $excerpt = stripslashes($excerpt); - $trackback_urls = explode(',', $HTTP_POST_VARS['trackback_url']); - foreach($trackback_urls as $tb_url) { - $tb_url = trim($tb_url); - trackback($tb_url, stripslashes($post_title), $excerpt, $post_ID); - } - } + } // end if moving from draft/private to published + if ($post_status == 'publish') { + // Trackback time. + $to_ping = trim($wpdb->get_var("SELECT to_ping FROM $tableposts WHERE ID = $post_ID")); + $pinged = trim($wpdb->get_var("SELECT pinged FROM $tableposts WHERE ID = $post_ID")); + $pinged = explode("\n", $pinged); + if ('' != $to_ping) { + if (strlen($excerpt) > 0) { + $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt) ; + } else { + $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content); + } + $excerpt = stripslashes($the_excerpt); + $to_pings = explode("\n", $to_ping); + foreach ($to_pings as $tb_ping) { + $tb_ping = trim($tb_ping); + if (!in_array($tb_ping, $pinged)) { + trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID); + } + } + } } // end if publish + $location = "Location: post.php"; header ($location); @@ -357,7 +382,6 @@ switch($action) { sleep($sleep_after_edit); } - // pingWeblogs($blog_ID); $sendback = $HTTP_SERVER_VARS['HTTP_REFERER']; if (strstr($sendback, 'post.php')) $sendback = $siteurl .'/wp-admin/post.php'; header ('Location: ' . $sendback); diff --git a/wp-admin/upgrade-072-to-080.php b/wp-admin/upgrade-072-to-080.php index e1a4f0538f..aaf926c4c1 100644 --- a/wp-admin/upgrade-072-to-080.php +++ b/wp-admin/upgrade-072-to-080.php @@ -59,7 +59,12 @@ $wpdb->hide_errors(); $wpdb->query("ALTER TABLE `$tableposts` ADD INDEX (`post_name`)"); $wpdb->show_errors(); +// Create ping status fields +$query = "ALTER TABLE $tableposts ADD `to_ping` TEXT NOT NULL"; +maybe_add_column($tableposts, 'to_ping', $query); +$query = "ALTER TABLE $tableposts ADD `pinged` TEXT NOT NULL"; +maybe_add_column($tableposts, 'pinged', $query); // Create category_nicename field $query = "ALTER TABLE `$tablecategories` ADD `category_nicename` VARCHAR(200) NOT NULL"; diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 22d8447cfe..9af5ffb8cf 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -588,7 +588,9 @@ function get_postdata($postid) { 'post_status' => $post->post_status, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, - 'post_password' => $post->post_password + 'post_password' => $post->post_password, + 'to_ping' => $post->to_ping, + 'pinged' => $post->pinged ); return $postdata; } @@ -887,50 +889,38 @@ function pingBlogs($blog_ID="1") { } -// trackback - send +// Send a Trackback function trackback($trackback_url, $title, $excerpt, $ID) { - global $siteurl, $blogfilename, $blogname; - global $querystring_start, $querystring_equal; - $title = urlencode($title); + global $blogname, $wpdb, $tableposts; + $title = urlencode(stripslashes($title)); $excerpt = urlencode(stripslashes($excerpt)); - $blog_name = urlencode($blogname); - $url = urlencode($siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal.$ID); + $blog_name = urlencode(stripslashes($blogname)); + $tb_url = $trackback_url; + $url = urlencode(get_permalink($ID)); $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt"; - if (strstr($trackback_url, '?')) { - $trackback_url .= "&".$query_string;; - $fp = @fopen($trackback_url, 'r'); - $result = @fread($fp, 4096); - @fclose($fp); -/* debug code - $debug_file = 'trackback.log'; - $fp = fopen($debug_file, 'a'); - fwrite($fp, "\n*****\nTrackback URL query:\n\n$trackback_url\n\nResponse:\n\n"); - fwrite($fp, $result); - fwrite($fp, "\n\n"); - fclose($fp); -*/ - } else { - $trackback_url = parse_url($trackback_url); - $http_request = 'POST '.$trackback_url['path']." HTTP/1.0\r\n"; - $http_request .= 'Host: '.$trackback_url['host']."\r\n"; - $http_request .= 'Content-Type: application/x-www-form-urlencoded'."\r\n"; - $http_request .= 'Content-Length: '.strlen($query_string)."\r\n"; - $http_request .= "\r\n"; - $http_request .= $query_string; - $fs = @fsockopen($trackback_url['host'], 80); - @fputs($fs, $http_request); -/* debug code - $debug_file = 'trackback.log'; - $fp = fopen($debug_file, 'a'); - fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"); - while(!@feof($fs)) { - fwrite($fp, @fgets($fs, 4096)); - } - fwrite($fp, "\n\n"); - fclose($fp); -*/ - @fclose($fs); + $trackback_url = parse_url($trackback_url); + $http_request = 'POST '.$trackback_url['path']." HTTP/1.0\r\n"; + $http_request .= 'Host: '.$trackback_url['host']."\r\n"; + $http_request .= 'Content-Type: application/x-www-form-urlencoded'."\r\n"; + $http_request .= 'Content-Length: '.strlen($query_string)."\r\n"; + $http_request .= "\r\n"; + $http_request .= $query_string; + $fs = @fsockopen($trackback_url['host'], 80); + @fputs($fs, $http_request); +/* + $debug_file = 'trackback.log'; + $fp = fopen($debug_file, 'a'); + fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"); + while(!@feof($fs)) { + fwrite($fp, @fgets($fs, 4096)); } + fwrite($fp, "\n\n"); + fclose($fp); +*/ + @fclose($fs); + + $wpdb->query("UPDATE $tableposts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = $ID"); + $wpdb->query("UPDATE $tableposts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = $ID"); return $result; } diff --git a/wp-trackback.php b/wp-trackback.php index 963ee9e8c4..82cb980813 100644 --- a/wp-trackback.php +++ b/wp-trackback.php @@ -41,7 +41,7 @@ if ((strlen(''.$tb_id)) && (empty($HTTP_GET_VARS['__mode'])) && (strlen(''.$tb_u $comment = ''; $comment .= "$title\n$excerpt"; - $author = addslashes($blog_name); + $author = addslashes(stripslashes(stripslashes($blog_name))); $email = ''; $original_comment = $comment; $comment_post_ID = $tb_id;