forked from yunasc/tbdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.php
331 lines (265 loc) · 13.1 KB
/
comment.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?
/*
// +--------------------------------------------------------------------------+
// | Project: TBDevYSE - TBDev Yuna Scatari Edition |
// +--------------------------------------------------------------------------+
// | This file is part of TBDevYSE. TBDevYSE is based on TBDev, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | TBDevYSE is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | TBDevYSE is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with TBDevYSE; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
require_once("include/bittorrent.php");
$action = $_GET["action"];
dbconn(false);
loggedinorreturn();
parked();
if ($action == "add")
{
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$torrentid = intval($_POST["tid"]);
if (!is_valid_id($torrentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$res = sql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if (!$arr)
stderr($tracker_lang['error'], $tracker_lang['no_torrent_with_such_id']);
$name = $arr[0];
$text = trim($_POST["text"]);
if (!$text)
stderr($tracker_lang['error'], $tracker_lang['comment_cant_be_empty']);
sql_query("INSERT INTO comments (user, torrent, added, text, ori_text, ip) VALUES (" .
$CURUSER["id"] . ",$torrentid, '" . get_date_time() . "', " . sqlesc($text) .
"," . sqlesc($text) . "," . sqlesc(getip()) . ")");
$newid = mysql_insert_id();
sql_query('INSERT INTO comments_parsed (cid, text_hash, text_parsed) VALUES ('.implode(', ', array_map('sqlesc', array($newid, md5($text), format_comment($text)))).')') or sqlerr(__FILE__,__LINE__);
sql_query("UPDATE torrents SET comments = comments + 1 WHERE id = $torrentid");
/////////////////ÑËÅÆÅÍÈÅ ÇÀ ÊÎÌÌÅÍÒÀÌÈ/////////////////
/*$res3 = sql_query("SELECT * FROM checkcomm WHERE checkid = $torrentid AND torrent = 1") or sqlerr(__FILE__,__LINE__);
$subject = sqlesc("Íîâûé êîììåíòàðèé");
while ($arr3 = mysql_fetch_array($res3)) {
$msg = sqlesc("Äëÿ òîððåíòà [url=details.php?id=$torrentid&viewcomm=$newid#comm$newid]".$name."[/url] äîáàâèëñÿ íîâûé êîììåíòàðèé.");
if ($CURUSER[id] != $arr3[userid])
sql_query("INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES (0, $arr3[userid], NOW(), $msg, 0, $subject)") or sqlerr(__FILE__,__LINE__);
}*/
/*$subject = "Íîâûé êîììåíòàðèé";
$msg = "Äëÿ òîððåíòà [url=details.php?id=$torrentid&viewcomm=$newid#comm$newid]".$name."[/url] äîáàâèëñÿ íîâûé êîììåíòàðèé.";
send_pm(0, $userid, get_date_time(), $subject, $msg);*/
//sql_query("INSERT INTO messages (sender, receiver, added, msg, poster, subject) SELECT 0, userid, NOW(), $msg, 0, $subject FROM checkcomm WHERE checkid = $torrentid AND torrent = 1 AND userid != $CURUSER[id]") or sqlerr(__FILE__,__LINE__);
/////////////////ÑËÅÆÅÍÈÅ ÇÀ ÊÎÌÌÅÍÒÀÌÈ/////////////////
header("Refresh: 0; url=details.php?id=$torrentid&viewcomm=$newid#comm$newid");
die;
}
$torrentid = intval($_GET["tid"]);
if (!is_valid_id($torrentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$res = sql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if (!$arr)
stderr($tracker_lang['error'], $tracker_lang['no_torrent_with_such_id']);
stdhead("Äîáëåíèå êîììåíòàðèÿ ê \"" . $arr["name"] . "\"");
print("<p><form name=\"comment\" method=\"post\" action=\"comment.php?action=add\">\n");
print("<input type=\"hidden\" name=\"tid\" value=\"$torrentid\"/>\n");
?>
<table class=main border=0 cellspacing=0 cellpadding=3>
<tr>
<td class="colhead">
<?
print("".$tracker_lang['add_comment']." ê \"" . htmlspecialchars_uni($arr["name"]) . "\"");
?>
</td>
</tr>
<tr>
<td>
<?
textbbcode("comment","text","");
?>
</td></tr></table>
<?
//print("<textarea name=\"text\" rows=\"10\" cols=\"60\"></textarea></p>\n");
print("<p><input type=\"submit\" value=\"Äîáàâèòü\" /></p></form>\n");
$res = sql_query("SELECT comments.id, text, comments.ip, comments.added, username, title, class, users.id as user, users.avatar, users.donor, users.enabled, users.warned, users.parked FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = $torrentid ORDER BY comments.id DESC LIMIT 5");
$allrows = array();
while ($row = mysql_fetch_array($res))
$allrows[] = $row;
if (count($allrows)) {
print("<h2>Ïîñëåäíèå êîììåíòàðèè, â îáðàòíîì ïîðÿäêå</h2>\n");
commenttable($allrows);
}
stdfoot();
die;
}
elseif ($action == "quote")
{
$commentid = intval($_GET["cid"]);
if (!is_valid_id($commentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$res = sql_query("SELECT c.*, t.name, t.id AS tid, u.username FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id JOIN users AS u ON c.user = u.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if (!$arr)
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
stdhead("Äîáàâëåíèÿ êîììåíòàðèÿ ê \"" . $arr["name"] . "\"");
$text = "[quote=$arr[username]]" . $arr["text"] . "[/quote]\n";
print("<form method=\"post\" name=\"comment\" action=\"comment.php?action=add\">\n");
print("<input type=\"hidden\" name=\"tid\" value=\"$arr[tid]\" />\n");
?>
<table class=main border=0 cellspacing=0 cellpadding=3>
<tr>
<td class="colhead">
<?
print("Äîáàâëåíèÿ êîììåíòàðèÿ ê \"" . htmlspecialchars_uni($arr["name"]) . "\"");
?>
</td>
</tr>
<tr>
<td>
<?
textbbcode("comment","text",htmlspecialchars_uni($text));
?>
</td></tr></table>
<?
print("<p><input type=\"submit\" value=\"Äîáàâèòü\" /></p></form>\n");
stdfoot();
}
elseif ($action == "edit")
{
$commentid = intval($_GET["cid"]);
if (!is_valid_id($commentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$res = sql_query("SELECT c.*, t.name, t.id AS tid FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if (!$arr)
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
if ($arr["user"] != $CURUSER["id"] && get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$text = $_POST["text"];
$returnto = $_POST["returnto"];
if ($text == "")
stderr($tracker_lang['error'], $tracker_lang['comment_cant_be_empty']);
$orig_text = $text;
$text = sqlesc($text);
$editedat = sqlesc(get_date_time());
sql_query("UPDATE comments SET text=$text, editedat=$editedat, editedby=$CURUSER[id] WHERE id=$commentid") or sqlerr(__FILE__, __LINE__);
sql_query('REPLACE INTO comments_parsed (cid, text_hash, text_parsed) VALUES ('.implode(', ', array_map('sqlesc', array($commentid, md5($orig_text), format_comment($orig_text)))).')') or sqlerr(__FILE__,__LINE__);
if ($returnto)
header("Location: $returnto");
else
header("Location: $DEFAULTBASEURL/"); // change later ----------------------
die;
}
stdhead("Ðåäàêòèðîâàíèå êîììåíòàðèÿ ê \"" . $arr["name"] . "\"");
print("<form method=\"post\" name=\"comment\" action=\"comment.php?action=edit&cid=$commentid\">\n");
print("<input type=\"hidden\" name=\"returnto\" value=\"details.php?id={$arr["tid"]}&viewcomm=$commentid#comm$commentid\" />\n");
print("<input type=\"hidden\" name=\"cid\" value=\"$commentid\" />\n");
?>
<table class=main border=0 cellspacing=0 cellpadding=3>
<tr>
<td class="colhead">
<?
print("Ðåäàêòèðîâàíèå êîììåíòàðèÿ ê \"" . htmlspecialchars_uni($arr["name"]) . "\"");
?>
</td>
</tr>
<tr>
<td>
<?
textbbcode("comment","text",htmlspecialchars_uni($arr["text"]));
?>
</td></tr></table>
<?
print("<p><input type=\"submit\" value=\"Îòðåäàêòèðîâàòü\" /></p></form>\n");
stdfoot();
die;
}
/////////////////ÑËÅÆÅÍÈÅ ÇÀ ÊÎÌÌÅÍÒÀÌÈ/////////////////
elseif ($action == "check" || $action == "checkoff")
{
$tid = intval($_GET["tid"]);
if (!is_valid_id($tid))
stderr($tracker_lang['error'], "Íåâåðíûé èäåíòèôèêàòîð $tid.");
$docheck = mysql_fetch_array(sql_query("SELECT COUNT(*) FROM checkcomm WHERE checkid = " . $tid . " AND userid = " . $CURUSER["id"] . " AND torrent = 1"));
if ($docheck[0] > 0 && $action=="check")
stderr($tracker_lang['error'], "<p>Âû óæå ïîäïèñàíû íà ýòîò òîððåíò.</p><a href=details.php?id=$tid#startcomments>Íàçàä</a>");
if ($action == "check") {
sql_query("INSERT INTO checkcomm (checkid, userid, torrent) VALUES ($tid, $CURUSER[id], 1)") or sqlerr(__FILE__,__LINE__);
stderr($tracker_lang['success'], "<p>Òåïåðü âû ñëåäèòå çà êîììåíòàðèÿìè ê ýòîìó òîððåíòó.</p><a href=details.php?id=$tid#startcomments>Íàçàä</a>");
}
else {
sql_query("DELETE FROM checkcomm WHERE checkid = $tid AND userid = $CURUSER[id] AND torrent = 1") or sqlerr(__FILE__,__LINE__);
stderr($tracker_lang['success'], "<p>Òåïåðü âû íå ñëåäèòå çà êîììåíòàðèÿìè ê ýòîìó òîððåíòó.</p><a href=details.php?id=$tid#startcomments>Íàçàä</a>");
}
}
/////////////////ÑËÅÆÅÍÈÅ ÇÀ ÊÎÌÌÅÍÒÀÌÈ/////////////////
elseif ($action == "delete")
{
if (get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
$commentid = intval($_GET["cid"]);
if (!is_valid_id($commentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$sure = $_GET["sure"];
if (!$sure)
{
stderr($tracker_lang['delete']." ".$tracker_lang['comment'], sprintf($tracker_lang['you_want_to_delete_x_click_here'],$tracker_lang['comment'],"?action=delete&cid=$commentid&sure=1"));
}
$res = sql_query("SELECT torrent FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if ($arr)
$torrentid = $arr["torrent"];
sql_query("DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
if ($torrentid && mysql_affected_rows() > 0)
sql_query("UPDATE torrents SET comments = comments - 1 WHERE id = $torrentid");
list($commentid) = mysql_fetch_row(sql_query("SELECT id FROM comments WHERE torrent = $torrentid ORDER BY added DESC LIMIT 1"));
$returnto = "details.php?id=$torrentid&viewcomm=$commentid#comm$commentid";
if ($returnto)
header("Location: $returnto");
else
header("Location: $DEFAULTBASEURL/"); // change later ----------------------
die;
}
elseif ($action == "vieworiginal")
{
if (get_user_class() < UC_MODERATOR)
stderr($tracker_lang['error'], $tracker_lang['access_denied']);
$commentid = intval($_GET["cid"]);
if (!is_valid_id($commentid))
stderr($tracker_lang['error'], $tracker_lang['invalid_id']);
$res = sql_query("SELECT c.*, t.name, t.id AS tid FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res);
if (!$arr)
stderr($tracker_lang['error'], "Íåâåðíûé èäåíòèôèêàòîð $commentid.");
stdhead("Ïðîñìîòð îðèãèíàëà");
print("<h1>Îðèãèíàëüíîå ñîäåðæàíèå êîììåíòàðèÿ ¹$commentid</h1><p>\n");
print("<table width=500 border=1 cellspacing=0 cellpadding=5>");
print("<tr><td class=comment>\n");
echo htmlspecialchars_uni($arr["ori_text"]);
print("</td></tr></table>\n");
$returnto = "details.php?id={$arr["tid"]}&viewcomm=$commentid#comm$commentid";
// $returnto = "details.php?id=$torrentid&viewcomm=$commentid#$commentid";
if ($returnto)
print("<p><font size=small><a href=$returnto>Íàçàä</a></font></p>\n");
stdfoot();
die;
}
else
stderr($tracker_lang['error'], "Unknown action");
die;
?>