<?php 
   
header('Content-Type: text/xml');

include("engine/core/misc.php");
include("engine/core/db.php");
include("engine/shards/cl_trackback.php");

// this function has been stripped out of the cl_trackback.php class
// partly to avoid the OO overhead.  We simply need to print some XML
// on error or failure.
function receive_trackback($success = false, $err_response = "")
{ 
	// Default error response in case of problems...
    if (!$success && empty($err_response))
	{
		$err_response = "An error occured while tring to log your trackback...";
    } 
    // Start response to trackbacker...
    $return = '<?xml version="1.0" encoding="' . "UTF-8" . '"?>' . "\n";
    $return .= "<response> \n"; 
    // Send back response...
    if ($success)
	{
		// Trackback received successfully...
        $return .= "	<error>0</error> \n";
	}
	else
	{
		// Something went wrong...
		$return .= "	<error>1</error> \n";
        $return .= "	<message>" . htmlspecialchars($err_response, ENT_QUOTES) . "</message>\n";
	} 
    // End response to trackbacker...
    $return .= "</response>";
    return $return;
} 









$refID = $_GET['id'];
$tb_url = '';
$tb_title = '';
$tb_excerpt = '';
$tb_blogname = '';

if (isset($_POST['url']))
{
	$tb_url = $_POST['url'];
} 
if (isset($_POST['title']))
{
	$tb_title = $_POST['title'];
} 
if (isset($_POST['excerpt']))
{
	$tb_excerpt = $_POST['excerpt'];
} 
if (isset($_POST['blog_name']))
{
	$tb_blogname = $_POST['blog_name'];
} 

//
// Do whatever to log the trackback (save in DB, flatfile, etc...)
//
connectMysql();
$result = mysql_query("insert into trackbacks (refID, title, excerpt, url, blog_name)
								VALUES
								('$refID', '$tb_title', '$tb_excerpt', '$tb_url', '$tb_blogname')") 
								or DIE(mysql_error());
mysql_close();

if( $result != FALSE )
	receive_trackback( true );
else
	receive_trackback( false , "Storage of your TrackBack failed on the remote server" );

?>
