-
Notifications
You must be signed in to change notification settings - Fork 2
/
trackback.php
executable file
·244 lines (212 loc) · 6.46 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
header('content-type: text/html; charset=utf-8');
/**
* Set root folder, you can overwrite this value by including this script from another script and defining the variable $root in the other script
*/
if(!$root){
$root = getcwd();
}
/**
* include configuration
*/
require_once($root . "/xt/includes/config.inc.php");
if(function_exists("zend_loader_install_license")){
@zend_loader_install_license(LICENCES_DIR . $GLOBALS['cfg']->get("system","order_nr") . "_ch.iframe.snode.core.zl",1);
}
/**
* start output buffering
*/
$GLOBALS['cfg']->get("system","compression") ? ob_start("ob_gzhandler") : ob_start();
/**
* set locales
*/
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
/**
* Enable pear compatibility
*/
ini_set("include_path", (CLASS_DIR . "PEAR" . PATH_SEPARATOR . ini_get("include_path")));
/**
* include classes
*/
require_once(CLASS_DIR . "logger.class.php"); // load logging class
require_once(CLASS_DIR . 'xt.class.php'); // load core api class
require_once(CLASS_DIR . 'user.class.php'); // load user handling class
require_once(CLASS_DIR . 'application.class.php'); // load application class
/**
* load includes
*/
require_once(INCLUDE_DIR . "compatibility.inc.php"); // Compatibility for PHP < 5.0
require_once(INCLUDE_DIR . "db.inc.php"); // database connection
require_once(INCLUDE_DIR . "auth.inc.php"); // authentication
/**
* load permission class
*/
require(CLASS_DIR . 'perm.class.php');
/**
* Create permission object
*/
global $perm;
$GLOBALS['perm'] = new XT_Perm();
/**
* load language stuff
*/
require_once(INCLUDE_DIR . "lang.inc.php"); // multilanguage
global $ajaxmode;
$GLOBALS['ajaxmode'] = true;
/**
* Set default theme values
*/
if(@$_GET['theme'] != ''){
$_SESSION['theme'] = addslashes($_GET['theme']);
} else {
if(!isset($_SESSION['theme']) || $_SESSION['theme'] == ''){
$_SESSION['theme'] = $GLOBALS['cfg']->get("system", "theme");
}
}
global $relations;
/**
* load template engine
*/
require_once(INCLUDE_DIR . "template.inc.php"); // embedded template engine
/**
* declare global variables
*/
global $logger; // logger
global $usr; // user object
global $tpl_id; // template id
/**
* create objects
*/
$GLOBALS['logger'] = new XT_Logger();
$GLOBALS['usr'] = new XT_User();
// Initialize content stack
global $pagecontents;
$GLOBALS['pagecontents'] = array();
// Get all post values
$url = $_POST['url'];
$title = $_POST['title'];
$excerpt = $_POST['excerpt'];
$blog_name = $_POST['blog_name'];
$charset = $_POST['charset'];
// Get all values for our system
$cid = $_REQUEST['cid'];
$ctype = $_REQUEST['ctype'];
$maildata = array();
$maildata['url'] = $url;
$maildata['title'] = $title;
$maildata['excerpt'] = $excerpt;
$maildata['blog_name'] = $blog_name;
$maildata['charset'] = $charset;
if ($charset){
$charset = strtoupper( trim($charset) );
} else {
$charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
}
if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
$title = mb_convert_encoding($title, 'UTF-8', $charset);
$excerpt = mb_convert_encoding($excerpt, 'UTF-8', $charset);
$blog_name = mb_convert_encoding($blog_name, 'UTF-8', $charset);
}
if ( !$cid || !$ctype ){
trackback_response(1, 'missing content id or conten type');
} else {
if (empty($title) && empty($url) && empty($blog_name)) {
// If it doesn't look like a trackback at all...
header('Location: ' . getenv("HTTP_REFERER"));
exit;
}
// Remove html
$title = strip_tags( $title );
$excerpt = strip_tags($excerpt);
$sql = "SELECT
*
FROM " . $GLOBALS['cfg']->get("database","prefix") . "comments_trackback_incomming
WHERE
content_id = " . $cid . " AND
content_type = " . $ctype . " AND
source_url = '" . $url . "'
";
$result = $GLOBALS['db']->query($sql);
$row = $result->FetchRow();
if(is_array($row)){
trackback_response(1, 'there is still a ping');
} else {
$sql = "INSERT INTO
" . $GLOBALS['cfg']->get("database","prefix") . "comments_trackback_incomming
(
active,
ip_long,
status,
content_id,
content_type,
source_url,
title,
excerpt,
blog_name,
date
) VALUES (
0,
" . ip2long($_SERVER['REMOTE_ADDR']) . ",
0,
" . $cid . ",
" . $ctype . ",
'" . $url . "',
'" . $title . "',
'" . $excerpt . "',
'" . $blog_name . "',
" . time() . "
);";
$GLOBALS['db']->query($sql);
trackback_response();
// Get last insert id
$result = XT::query("
SELECT id FROM " . $GLOBALS['cfg']->get("database","prefix") . "comments_trackback_incomming ORDER BY id DESC LIMIT 1", __FILE__,__LINE__);
while($row = $result->FetchRow()){
$maildata['id'] = $row['id'];
}
// Send moderation email
require_once(CLASS_DIR . "/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Encoding = '7bit';
$mail->SetLanguage(XT::getLang(),CLASS_DIR . "/phpmailer/language/");
$mail->FromName = $maildata['blog_name'];
$mail->From = $_SERVER['SERVER_NAME'];
$mail->Host = $GLOBALS['cfg']->get('smtp','Host');
$mail->SMTPAuth = $GLOBALS['cfg']->get('smtp','SMTPAuth');
if($GLOBALS['cfg']->get('smtp','SMTPAuth')){
$mail->Username = $GLOBALS['cfg']->get('smtp','Username');
$mail->Password = $GLOBALS['cfg']->get('smtp','Password');
}
$mail->AddAddress($GLOBALS['cfg']->get('system','email'));
$mail->Subject = "New Trackback at " . $_SERVER['SERVER_NAME'] .": ". $maildata['title'];
XT::assign("MAIL_DATA",$maildata);
if(is_file(TEMPLATE_DIR . $_SESSION['theme'] . '/ch.iframe.snode.comment/moderate_mail.tpl')){
$mail->Body = $GLOBALS['tpl']->fetch( TEMPLATE_DIR . $_SESSION['theme'] . '/ch.iframe.snode.blog/mail/moderate_trackback.tpl');
}else {
$mail->Body = $GLOBALS['tpl']->fetch( TEMPLATE_DIR . 'default//ch.iframe.snode.blog/mail/moderate_trackback.tpl');
}
if(!$mail->Send()){
echo $mail->ErrorInfo;
XT::log($mail->ErrorInfo,__FILE__,__LINE__,XT_ERROR);
}
}
}
function trackback_response($error = 0, $error_message = '') {
header('Content-Type: text/xml; charset=utf-8');
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>";
die();
} else {
echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
echo "<response>\n";
echo "<error>0</error>\n";
echo "</response>";
}
}
?>