-
Notifications
You must be signed in to change notification settings - Fork 1
/
trackback.php
91 lines (77 loc) · 2.87 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
include_once 'head.php';
foreach($_GET as $k => $v){
$$k = (!$v ? $$k : @htmlspecialchars($v));
}
if (is_array($_CUTE)){
foreach($_CUTE as $k => $v){
$$k = (!$static ? (!$v ? $$k : @htmlspecialchars($v)) : '');
}
}
function trackback_response($error = 0, $error_message = ''){
global $echo;
if ($error){
echo '<?xml version="1.0" encoding="'.$echo['charset'].'"?'.">\n";
echo "<response>\n";
echo "<error>1</error>\n";
echo "<message>$error_message</message>\n";
echo "</response>";
} else {
echo '<?xml version="1.0" encoding="'.$echo['charset'].'"?'.">\n";
echo "<response>\n";
echo "<error>0</error>\n";
echo "</response>";
}
exit;
}
if (eregi('([0-9]{2}):([0-9]{2}):([0-9]{2})', $time)){
$m_n = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
$time = explode(':', $time);
$time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}
$where = array();
if ($title){
$where[] = "url = $title";
} elseif ($time){
$where[] = "date = $time";
} elseif ($id){
$where[] = "id = $id";
}
$query = reset($query = $sql->select(array('table' => 'news', 'where' => $where)));
if (!$_POST){
trackback_response(1, 'XML-RPC server accepts POST requests only.');
} elseif (!is_array($query)){
trackback_response(1, 'Sorry, post not found.');
}
foreach($_POST as $k => $v){
$$k = (!$v ? $$k : @htmlspecialchars($v));
}
if (function_exists('mb_convert_encoding')){
$charset = ($charset ? $charset : 'auto');
$blog_name = mb_convert_encoding($blog_name, $echo['charset'], $charset);
$title = mb_convert_encoding($title, $echo['charset'], $charset);
$excerpt = mb_convert_encoding($excerpt, $echo['charset'], $charset);
} elseif (function_exists('iconv')){
$charset = ($charset ? $charset : 'utf-8');
$blog_name = iconv($charset, $echo['charset'], $blog_name);
$title = iconv($charset, $echo['charset'], $title);
$excerpt = iconv($charset, $echo['charset'], $excerpt);
}
$blog_name = ($blog_name ? $blog_name : 'no name');
$url = ($url ? $url : 'none');
$excerpt = ($excerpt ? $excerpt : 'ugly idiot');
$xfields = new XFieldsData();
$post = $xfields->fetch($query['id'], 'trackback');
$post[time()] = array(
'blog_name' => replace_comment('add', $blog_name),
'url' => str_replace('&', '&', $url),
'host' => $_SERVER['REMOTE_ADDR'],
'title' => replace_comment('add', $title),
'excerpt' => replace_comment('add', preg_replace("/(.*?)\n\n..../i", '\\1', $excerpt)),
'charset' => $charset
);
$xfields->set($post, $query['id'], 'trackback');
$xfields->save();
header('Content-Type: text/xml;');
trackback_response();
?>