<?php
/*
+--------------------------------------------------------+
| O-BLOG - PHP Blog System                               |
| Copyright (c) 2004 phpBlog.CN                          |
| Support : http://www.phpBlog.cn                        |
| Author : ShiShiRui (shishirui@163.com)                 |
|--------------------------------------------------------+
*/
error_reporting(7);

require('config.php');
if (!$allow_trackback)
{
	die('trackback closed');
}

header('Content-type: text/xml');

$id = @intval($_GET['id']);
$encode = @checkPost(trim($_GET['encode']));

if(!isset($_POST['url'])){
	$url = trim(checkPost($_GET['url']));
	$title = trim(checkPost($_GET['title']));
	$excerpt = trim(checkPost($_GET['excerpt']));
	$blog_name = trim(checkPost($_GET['blog_name']));
} else {
	$url = trim(checkPost($_POST['url']));
	$title = trim(checkPost($_POST['title']));
	$excerpt = trim(checkPost($_POST['excerpt']));
	$blog_name = trim(checkPost($_POST['blog_name']));
}

$error = 1;

if(empty($url) OR substr($url,0,7)!='http://') {
	$msg='Invalid Parameter!';
} elseif(empty($id)){
	$msg='TrackBack info is missing!';
} elseif(empty($encode)) {
	$msg='Character encoding is null!';
} else {
	
	if(strtolower($encode) == 'gb2312')
	{
		$Encode = new Chinese("GB2312","UTF8",$title);
		$title = $Encode->ConvertIT();
		unset($Encode);
		$Encode = new Chinese("GB2312","UTF8",$excerpt);
		$excerpt = $Encode->ConvertIT();
		unset($Encode);
		$Encode = new Chinese("GB2312","UTF8",$blog_name);
		$blog_name = $Encode->ConvertIT();
		unset($Encode);
	}
	
	$insert_sql = "INSERT INTO `".$mysql_prefix."trackback` (`adddate` , `title` , `url` , `excerpt` , `blogname` , `inblog` ) VALUES ('".time()."', '".$title."', '".$url."', '".$excerpt."', '".$blog_name."', '".$id."')";
	if($DB->query($insert_sql)) {
		if($makehtml) {
			require('admin/class/build.php');
			$html = new build;
			$html->make($id);
		}
		$error=0;
	} else {
		$msg='Could not save trackback data, possibly because of mysql database!';
	}
}

echo '<?xml version="1.0" encoding="'.$charset.'"?>';
if($error) {
	echo '<response><error>1</error><message>'.$msg.'</message></response>';
} else {
	echo '<response><error>0</error></response>';
}
?>