This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcomment.php
246 lines (192 loc) · 9.33 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
<?php
/*
+------------------------------------------------
| TBDev.net BitTorrent Tracker PHP
| =============================================
| by CoLdFuSiOn
| (c) 2003 - 2011 TBDev.Net
| http://www.tbdev.net
| =============================================
| svn: http://sourceforge.net/projects/tbdevnet/
| Licence Info: GPL
+------------------------------------------------
| $Date$
| $Revision$
| $Author$
| $URL$
+------------------------------------------------
*/
require_once "include/bittorrent.php";
require_once "include/user_functions.php";
require_once "include/html_functions.php";
$action = $_GET["action"];
dbconn(false);
loggedinorreturn();
$lang = array_merge( load_language('global'), load_language('comment') );
if ($action == "add")
{
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$torrentid = 0 + $_POST["tid"];
if (!is_valid_id($torrentid))
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
$res = @mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_array($res,MYSQL_NUM);
if (!$arr)
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_torrent']}");
$text = trim($_POST["body"]);
if (!$text)
stderr("{$lang['comment_error']}", "{$lang['comment_body']}");
@mysql_query("INSERT INTO comments (user, torrent, added, text, ori_text) VALUES (" .
$CURUSER["id"] . ",$torrentid, " . TIME_NOW . ", " . sqlesc($text) .
"," . sqlesc($text) . ")");
$newid = mysql_insert_id();
@mysql_query("UPDATE torrents SET comments = comments + 1 WHERE id = $torrentid");
header("Refresh: 0; url=details.php?id=$torrentid&viewcomm=$newid#comm$newid");
die;
}
$torrentid = 0 + $_GET["tid"];
if (!is_valid_id($torrentid))
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
$res = mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_assoc($res);
if (!$arr)
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_torrent']}");
$HTMLOUT = '';
$js = "<script type='text/javascript' src='scripts/bbcode2text.js'></script>";
$HTMLOUT .= "<div class='cblock'>
<div class='cblock-header'>{$lang['comment_add']}\"" . htmlsafechars($arr["name"]) . "\"</div>
<div class='cblock-content'>
<form name='bbcode2text' method='post' action='comment.php?action=add'>
<input type='hidden' name='tid' value='{$torrentid}'/>";
$HTMLOUT .= bbcode2textarea( );
$HTMLOUT .= " <div align='center'>
<input type='submit' name='comment' value='{$lang['comment_doit']}' class='' />
</div>
</form>
</div>
</div>";
$res = mysql_query("SELECT comments.id, text, comments.added, comments.editedby, comments.editedat, username, users.id as user, users.title, users.avatar, users.av_w, users.av_h, users.class, users.donor, users.warned 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_assoc($res))
$allrows[] = $row;
if (count($allrows)) {
require_once "include/comment_functions.php";
//require_once "include/html_functions.php";
require_once "include/bbcode_functions.php";
$HTMLOUT .= "<h2>{$lang['comment_recent']}</h2>\n";
$HTMLOUT .= commenttable($allrows);
}
print stdhead("{$lang['comment_add']}\"{$arr["name"]}\"", $js) . $HTMLOUT . stdfoot();
die;
}
elseif ($action == "edit")
{
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
$res = mysql_query("SELECT c.*, t.name 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_assoc($res);
if (!$arr)
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}.");
if ($arr["user"] != $CURUSER["id"] && get_user_class() < UC_MODERATOR)
stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$text = $_POST['body'];
$returnto = htmlsafechars($_POST["returnto"]);
if ($text == "")
stderr("{$lang['comment_error']}", "{$lang['comment_body']}");
$text = sqlesc($text);
$editedat = TIME_NOW;
mysql_query("UPDATE comments SET text=$text, editedat=$editedat, editedby={$CURUSER['id']} WHERE id=$commentid") or sqlerr(__FILE__, __LINE__);
if ($returnto)
header("Location: $returnto");
else
header("Location: {$TBDEV['baseurl']}/"); // change later ----------------------
die;
}
$returnto = htmlsafechars($_SERVER["HTTP_REFERER"]);
$js = "<script type='text/javascript' src='scripts/bbcode2text.js'></script>";
$HTMLOUT = '';
$HTMLOUT .= "
<div class='cblock'>
<div class='cblock-header'>{$lang['comment_edit']}\"" . htmlsafechars($arr["name"]) . "\"</div>
<div class='cblock-content'>
<form name='bbcode2text' method='post' action='comment.php?action=edit&cid=$commentid'>
<input type='hidden' name='returnto' value='{$returnto}' />
<input type='hidden' name='cid' value='$commentid' />";
$HTMLOUT .= bbcode2textarea( 'body', htmlsafechars($arr["text"]) );
$HTMLOUT .= " <div align='center'>
<input type='submit' name='comment' value='{$lang['comment_doit']}' class='' />
</div>
</form>
</div>
</div>";
print stdhead("{$lang['comment_edit']}\"{$arr["name"]}\"", $js) . $HTMLOUT . stdfoot();
die;
}
elseif ($action == "delete")
{
if (get_user_class() < UC_MODERATOR)
stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
$sure = isset($_GET["sure"]) ? (int)$_GET["sure"] : false;
if (!$sure)
{
$referer = $_SERVER["HTTP_REFERER"];
stderr("{$lang['comment_delete']}", "{$lang['comment_about_delete']}\n" .
"<a href='comment.php?action=delete&cid=$commentid&sure=1" .
($referer ? "&returnto=" . urlencode($referer) : "") .
"'>here</a> {$lang['comment_delete_sure']}");
}
$res = mysql_query("SELECT torrent FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysql_fetch_assoc($res);
if ($arr)
$torrentid = $arr["torrent"];
@mysql_query("DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
if ($torrentid && mysql_affected_rows() > 0)
mysql_query("UPDATE torrents SET comments = comments - 1 WHERE id = $torrentid");
$returnto = $_GET["returnto"];
if ($returnto)
header("Location: $returnto");
else
header("Location: {$TBDEV['baseurl']}/"); // change later ----------------------
die;
}
elseif ($action == "vieworiginal")
{
if (get_user_class() < UC_MODERATOR)
stderr("{$lang['comment_error']}", "{$lang['comment_denied']}");
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']}");
$res = mysql_query("SELECT c.*, t.name 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_assoc($res);
if (!$arr)
stderr("{$lang['comment_error']}", "{$lang['comment_invalid_id']} $commentid.");
$HTMLOUT = '';
$HTMLOUT .= "
<div class='cblock'>
<div class='cblock-header'>{$lang['comment_original_contents']}#$commentid</div>
<div class='cblock-content'>
<table width='500' border='1' cellspacing='0' cellpadding='5'>
<tr>
<td class='comment'>".htmlsafechars($arr["ori_text"])."</td>
</tr>
</table><br />
</div>
</div>";
$returnto = htmlsafechars(filter_var($_SERVER['HTTP_REFERER'], FILTER_SANITIZE_STRING));
// $returnto = "details.php?id=$torrentid&viewcomm=$commentid#$commentid";
if ($returnto)
$HTMLOUT .= "<span class='btn'><a href='$returnto'>{$lang['comment_back']}</a></span>\n";
print stdhead("{$lang['comment_original']}") . $HTMLOUT . stdfoot();
die;
}
else
stderr("{$lang['comment_error']}", "{$lang['comment_unknown']}");
die;
?>