2003-12-10 19:22:36 -05:00
|
|
|
<?php
|
2004-09-18 18:47:43 -04:00
|
|
|
|
2004-10-14 03:26:41 -04:00
|
|
|
function add_magic_quotes($array) {
|
|
|
|
foreach ($array as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$array[$k] = add_magic_quotes($v);
|
|
|
|
} else {
|
|
|
|
$array[$k] = addslashes($v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_magic_quotes_gpc()) {
|
|
|
|
$_GET = add_magic_quotes($_GET);
|
|
|
|
$_POST = add_magic_quotes($_POST);
|
|
|
|
$_COOKIE = add_magic_quotes($_COOKIE);
|
|
|
|
}
|
|
|
|
|
2004-12-07 20:00:12 -05:00
|
|
|
if (empty($doing_trackback)) {
|
|
|
|
$doing_trackback = true;
|
2004-09-18 18:47:43 -04:00
|
|
|
require('wp-blog-header.php');
|
|
|
|
}
|
|
|
|
|
2004-09-06 22:34:12 -04: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 08:27:52 -04:00
|
|
|
die();
|
2004-09-06 22:34:12 -04:00
|
|
|
} else {
|
|
|
|
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
|
|
|
|
echo "<response>\n";
|
|
|
|
echo "<error>0</error>\n";
|
|
|
|
echo "</response>";
|
|
|
|
}
|
|
|
|
}
|
2003-12-21 22:10:54 -05:00
|
|
|
|
|
|
|
// trackback is done by a POST
|
|
|
|
$request_array = 'HTTP_POST_VARS';
|
2004-09-06 22:34:12 -04:00
|
|
|
if (!$tb_id) {
|
|
|
|
$tb_id = explode('/', $_SERVER['REQUEST_URI']);
|
|
|
|
$tb_id = intval($tb_id[count($tb_id)-1]);
|
|
|
|
}
|
2004-04-20 18:56:47 -04:00
|
|
|
$tb_url = $_POST['url'];
|
|
|
|
$title = $_POST['title'];
|
|
|
|
$excerpt = $_POST['excerpt'];
|
|
|
|
$blog_name = $_POST['blog_name'];
|
2004-10-04 04:03:52 -04:00
|
|
|
$charset = $_POST['charset'];
|
|
|
|
|
|
|
|
if ($charset)
|
|
|
|
$charset = strtoupper( trim($charset) );
|
|
|
|
else
|
|
|
|
$charset = 'auto';
|
|
|
|
|
|
|
|
if ( function_exists('mb_convert_encoding') ) {
|
|
|
|
$title = mb_convert_encoding($title, get_settings('blog_charset'), $charset);
|
|
|
|
$excerpt = mb_convert_encoding($excerpt, get_settings('blog_charset'), $charset);
|
|
|
|
$blog_name = mb_convert_encoding($blog_name, get_settings('blog_charset'), $charset);
|
|
|
|
}
|
2003-12-21 22:10:54 -05:00
|
|
|
|
2004-09-06 22:34:12 -04:00
|
|
|
if ( is_single() )
|
2004-02-05 15:55:50 -05:00
|
|
|
$tb_id = $posts[0]->ID;
|
2004-09-06 22:34:12 -04:00
|
|
|
|
|
|
|
if ( !$tb_id)
|
|
|
|
trackback_response(1, 'I really need an ID for this to work.');
|
2003-12-21 22:10:54 -05:00
|
|
|
|
|
|
|
if (empty($title) && empty($tb_url) && empty($blog_name)) {
|
|
|
|
// If it doesn't look like a trackback at all...
|
|
|
|
header('Location: ' . get_permalink($tb_id));
|
2004-09-06 22:34:12 -04:00
|
|
|
exit;
|
2003-12-10 19:22:36 -05:00
|
|
|
}
|
|
|
|
|
2004-09-06 22:34:12 -04:00
|
|
|
if ( !empty($tb_url) && !empty($title) && !empty($tb_url) ) {
|
|
|
|
header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
|
2003-12-10 19:22:36 -05:00
|
|
|
|
2004-05-24 04:22:18 -04:00
|
|
|
$pingstatus = $wpdb->get_var("SELECT ping_status FROM $wpdb->posts WHERE ID = $tb_id");
|
2003-12-10 19:22:36 -05:00
|
|
|
|
|
|
|
if ('closed' == $pingstatus)
|
|
|
|
trackback_response(1, 'Sorry, trackbacks are closed for this item.');
|
|
|
|
|
2004-12-12 15:41:19 -05:00
|
|
|
$title = wp_specialchars( strip_tags( $title ) );
|
2004-09-06 22:34:12 -04:00
|
|
|
$title = (strlen($title) > 250) ? substr($title, 0, 250) . '...' : $title;
|
2003-12-10 19:22:36 -05:00
|
|
|
$excerpt = strip_tags($excerpt);
|
2004-09-06 22:34:12 -04:00
|
|
|
$excerpt = (strlen($excerpt) > 255) ? substr($excerpt, 0, 252) . '...' : $excerpt;
|
2004-12-12 15:41:19 -05:00
|
|
|
$blog_name = wp_specialchars($blog_name);
|
2004-09-06 22:34:12 -04:00
|
|
|
$blog_name = (strlen($blog_name) > 250) ? substr($blog_name, 0, 250) . '...' : $blog_name;
|
2003-12-10 19:22:36 -05:00
|
|
|
|
2004-09-22 15:44:35 -04:00
|
|
|
$comment_post_ID = $tb_id;
|
|
|
|
$comment_author = $blog_name;
|
2004-09-06 22:34:12 -04:00
|
|
|
$comment_author_email = '';
|
2003-12-10 19:22:36 -05:00
|
|
|
$comment_author_url = $tb_url;
|
2004-09-06 22:34:12 -04:00
|
|
|
$comment_content = "<strong>$title</strong>\n\n$excerpt";
|
|
|
|
$comment_type = 'trackback';
|
2003-12-10 19:22:36 -05:00
|
|
|
|
2004-09-22 15:44:35 -04:00
|
|
|
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
|
2003-12-10 19:22:36 -05:00
|
|
|
|
2004-09-06 22:34:12 -04:00
|
|
|
wp_new_comment($commentdata);
|
2003-12-10 19:22:36 -05:00
|
|
|
|
2004-09-06 22:34:12 -04:00
|
|
|
trackback_response(0);
|
|
|
|
do_action('trackback_post', $wpdb->insert_id);
|
2003-12-10 19:22:36 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
?>
|