2003-12-11 01:22:36 +01:00
|
|
|
<?php
|
2004-09-19 00:47:43 +02:00
|
|
|
|
2005-06-11 01:15:13 +02:00
|
|
|
if (empty($wp)) {
|
|
|
|
require_once('wp-config.php');
|
|
|
|
wp('tb=1');
|
2004-09-19 00:47:43 +02:00
|
|
|
}
|
|
|
|
|
2004-09-07 04:34:12 +02:00
|
|
|
function trackback_response($error = 0, $error_message = '') {
|
|
|
|
header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
|
|
|
|
if ($error) {
|
|
|
|
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
|
|
|
|
echo "<response>\n";
|
|
|
|
echo "<error>1</error>\n";
|
|
|
|
echo "<message>$error_message</message>\n";
|
|
|
|
echo "</response>";
|
2004-09-23 14:27:52 +02:00
|
|
|
die();
|
2004-09-07 04:34:12 +02:00
|
|
|
} else {
|
|
|
|
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
|
|
|
|
echo "<response>\n";
|
|
|
|
echo "<error>0</error>\n";
|
|
|
|
echo "</response>";
|
|
|
|
}
|
|
|
|
}
|
2003-12-22 04:10:54 +01:00
|
|
|
|
|
|
|
// trackback is done by a POST
|
|
|
|
$request_array = 'HTTP_POST_VARS';
|
2004-12-16 03:57:05 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !$_GET['tb_id'] ) {
|
2004-09-07 04:34:12 +02:00
|
|
|
$tb_id = explode('/', $_SERVER['REQUEST_URI']);
|
2005-04-20 05:37:23 +02:00
|
|
|
$tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
|
2004-09-07 04:34:12 +02:00
|
|
|
}
|
2004-12-16 03:57:05 +01:00
|
|
|
|
|
|
|
$tb_url = $_POST['url'];
|
|
|
|
$title = $_POST['title'];
|
|
|
|
$excerpt = $_POST['excerpt'];
|
2004-04-21 00:56:47 +02:00
|
|
|
$blog_name = $_POST['blog_name'];
|
2004-12-16 03:57:05 +01:00
|
|
|
$charset = $_POST['charset'];
|
2004-10-04 10:03:52 +02:00
|
|
|
|
|
|
|
if ($charset)
|
|
|
|
$charset = strtoupper( trim($charset) );
|
|
|
|
else
|
2005-04-21 00:06:28 +02:00
|
|
|
$charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
|
2004-10-04 10:03:52 +02:00
|
|
|
|
2004-12-16 03:57:05 +01:00
|
|
|
if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
|
2006-08-30 23:46:31 +02:00
|
|
|
$title = mb_convert_encoding($title, get_option('blog_charset'), $charset);
|
|
|
|
$excerpt = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
|
|
|
|
$blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
|
2004-10-04 10:03:52 +02:00
|
|
|
}
|
2003-12-22 04:10:54 +01:00
|
|
|
|
2005-01-25 01:23:57 +01:00
|
|
|
if ( is_single() || is_page() )
|
2004-02-05 21:55:50 +01:00
|
|
|
$tb_id = $posts[0]->ID;
|
2004-09-07 04:34:12 +02:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( !intval( $tb_id ) )
|
2004-09-07 04:34:12 +02:00
|
|
|
trackback_response(1, 'I really need an ID for this to work.');
|
2003-12-22 04:10:54 +01:00
|
|
|
|
|
|
|
if (empty($title) && empty($tb_url) && empty($blog_name)) {
|
|
|
|
// If it doesn't look like a trackback at all...
|
2006-06-27 07:38:56 +02:00
|
|
|
wp_redirect(get_permalink($tb_id));
|
2004-09-07 04:34:12 +02:00
|
|
|
exit;
|
2003-12-11 01:22:36 +01:00
|
|
|
}
|
|
|
|
|
2004-09-07 04:34:12 +02:00
|
|
|
if ( !empty($tb_url) && !empty($title) && !empty($tb_url) ) {
|
|
|
|
header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2004-05-24 10:22:18 +02:00
|
|
|
$pingstatus = $wpdb->get_var("SELECT ping_status FROM $wpdb->posts WHERE ID = $tb_id");
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2005-04-20 05:37:23 +02:00
|
|
|
if ( 'open' != $pingstatus )
|
2003-12-11 01:22:36 +01:00
|
|
|
trackback_response(1, 'Sorry, trackbacks are closed for this item.');
|
|
|
|
|
2004-12-12 21:41:19 +01:00
|
|
|
$title = wp_specialchars( strip_tags( $title ) );
|
2003-12-11 01:22:36 +01:00
|
|
|
$excerpt = strip_tags($excerpt);
|
2005-12-28 02:06:57 +01:00
|
|
|
if ( function_exists('mb_strcut') ) { // For international trackbacks
|
2006-08-30 23:46:31 +02:00
|
|
|
$excerpt = mb_strcut($excerpt, 0, 252, get_option('blog_charset')) . '...';
|
|
|
|
$title = mb_strcut($title, 0, 250, get_option('blog_charset')) . '...';
|
2005-11-16 10:38:54 +01:00
|
|
|
} else {
|
2005-11-14 11:14:43 +01:00
|
|
|
$excerpt = (strlen($excerpt) > 255) ? substr($excerpt, 0, 252) . '...' : $excerpt;
|
2005-11-16 10:38:54 +01:00
|
|
|
$title = (strlen($title) > 250) ? substr($title, 0, 250) . '...' : $title;
|
|
|
|
}
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2004-09-22 21:44:35 +02:00
|
|
|
$comment_post_ID = $tb_id;
|
|
|
|
$comment_author = $blog_name;
|
2004-09-07 04:34:12 +02:00
|
|
|
$comment_author_email = '';
|
2003-12-11 01:22:36 +01:00
|
|
|
$comment_author_url = $tb_url;
|
2004-09-07 04:34:12 +02:00
|
|
|
$comment_content = "<strong>$title</strong>\n\n$excerpt";
|
|
|
|
$comment_type = 'trackback';
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2005-01-11 03:56:43 +01:00
|
|
|
$dupe = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_author_url = '$comment_author_url'");
|
|
|
|
if ( $dupe )
|
2006-08-30 18:40:17 +02:00
|
|
|
trackback_response(1, 'We already have a ping from that URL for this post.');
|
2005-01-11 03:56:43 +01:00
|
|
|
|
2004-09-22 21:44:35 +02:00
|
|
|
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2004-09-07 04:34:12 +02:00
|
|
|
wp_new_comment($commentdata);
|
2003-12-11 01:22:36 +01:00
|
|
|
|
2004-09-07 04:34:12 +02:00
|
|
|
do_action('trackback_post', $wpdb->insert_id);
|
2005-02-12 08:30:21 +01:00
|
|
|
trackback_response(0);
|
2003-12-11 01:22:36 +01:00
|
|
|
}
|
|
|
|
?>
|