/
trackback.php
74 lines (63 loc) · 1.56 KB
/
trackback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?
require "core.php";
function errorExit($message)
{
header("Content-type: text/xml");
echo <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<response>
<error>1</error>
<message>{$message}</message>
</response>
EOF;
exit;
}
if(!isset($_GET['id']))
errorExit('I need the article ID');
if(!isset($_POST['url']))
errorExit('You must give a perma link to your article');
if(!isset($_POST['excerpt']))
errorExit('You must give a excerpt of your article');
if(!isset($_POST['blog_name']))
errorExit('You must give the name of your blog');
$id = $_GET['id'];
$url = htmlspecialchars($_POST['url']);
$excerpt = $_POST['excerpt'];
$blog_name = htmlspecialchars($_POST['blog_name']);
$comment = '';
if(strlen($excerpt) > 255)
{
$comment = '(...) ' . substr($excerpt, 0, 243) . ' (...)';
}
else
$comment = $excerpt;
$p = $Blog->getnewsbyid($id);
if(!$p) errorExit('Article not found');
$p = $p->fetch_object();
if(!$p) errorExit('Article not found');
$mytitle = $p->title;
$myurl = $Blog->rootpath.'/'.$p->id.'/'.$Blog->shorttext($mytitle);
##errorExit($myurl);
#if(strpos($comment, $myurl) !== false) errorExit('Go away, spammer');
$comment = strip_tags($comment);
$comment = nl2br($comment);
if(isset($_POST['title']))
{
$title = htmlspecialchars($_POST['title']);
$comment = "<strong>{$title}</strong><br />" . $comment;
}
if($Blog->save_comment($id, $blog_name, '', $url, $comment, false))
{
header("Content-type: text/xml");
echo <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<response>
<error>0</error>
</response>
EOF;
}
else
{
errorExit('Trackback cannot be saved');
}
?>