-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomment.php
More file actions
227 lines (170 loc) · 7.23 KB
/
comment.php
File metadata and controls
227 lines (170 loc) · 7.23 KB
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
<?php
require_once("include/bittorrent.php");
require_once("include/secrets.php");
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
$con_link = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
if (!mkglobal("action"))
die();
if (@$id)
$id = 0 + $id;
//$action = @$_GET["action"];
//$action = @$_POST["action"];
dbconn(false);
loggedinorreturn();
if ($action == "add")
{
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$torrentid = 0 + $_POST["tid"];
if (!is_valid_id($torrentid))
site_error_message("Foutmelding", "Fout ID $torrentid.");
$res = mysqli_query($con_link, "SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysqli_fetch_array($res);
if (!$arr)
site_error_message("Foutmelding", "Geen torrent met ID $torrentid.");
$text = trim($_POST["text"]);
if (!$text)
site_error_message("Foutmelding", "Bericht mag niet leeg zijn!");
mysqli_query($con_link, "INSERT INTO comments (user, torrent, added, text, ori_text) VALUES (" .
$CURUSER["id"] . ",$torrentid, '" . get_date_time() . "', " . sqlesc($text) .
"," . sqlesc($text) . ")");
$newid = mysqli_insert_id($con_link);
mysqli_query($con_link, "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))
site_error_message("Foutmelding", "Foutief ID $torrentid.");
$res = mysqli_query($con_link, "SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
$arr = mysqli_fetch_array($res);
if (!$arr)
site_error_message("Foutmelding", "Geen torrent gevonden met ID $torrentid.");
site_header("Commentaar toeoegen \"" . $arr["name"] . "\"");
print("<h1>Commentaar toevoegen aan \"" . htmlspecialchars($arr["name"]) . "\"</h1>\n");
print("<p><form name=new_comment method=\"post\" action=\"comment.php?action=add\">\n");
print("<input type=\"hidden\" name=\"tid\" value=\"$torrentid\"/>\n");
print("<textarea name=\"text\" rows=\"12\" cols=\"90\"></textarea></p>\n");
print("<p><input type=\"submit\" class=btn value=\"Opslaan\" /></p></form>\n");
?>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
document.new_comment.text.focus();
//-->
</script>
<?php
$res = mysqli_query($con_link, "SELECT comments.id, text, comments.added, username, users.id as user, users.avatar FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = $torrentid ORDER BY comments.id DESC LIMIT 5");
$allrows = array();
while ($row = mysqli_fetch_array($res))
$allrows[] = $row;
if (count($allrows)) {
print("<h2>Laatste commentaren, in omgekeerde volgorde</h2>\n");
commenttable($allrows);
}
print "<br>";
site_footer();
die;
}
elseif ($action == "edit")
{
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
site_error_message("Foutmelding", "Foutief ID $commentid.");
$res = mysqli_query($con_link, "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 = mysqli_fetch_array($res);
if (!$arr)
site_error_message("Foutmelding", "Foutief ID $commentid.");
if ($arr["user"] != $CURUSER["id"] && get_user_class() < UC_MODERATOR)
site_error_message("Foutmelding", "Toegang geweigerd.");
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$text = @$_POST["text"];
$returnto = @$_POST["returnto"];
if ($text == "")
site_error_message("Foutmelding", "Bericht mag niet leeg zijn!");
$text = sqlesc($text);
$editedat = sqlesc(get_date_time());
mysqli_query($con_link, "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: $BASEURL/"); // change later ----------------------
die;
}
site_header("Commentaar bewerken \"" . $arr["name"] . "\"");
print("<h1>Bewerk het commentaar van \"" . htmlspecialchars($arr["name"]) . "\"</h1><p>\n");
print("<form name=edit_comment method=\"post\" action=\"comment.php?action=edit&cid=$commentid\">\n");
print("<input type=\"hidden\" name=\"returnto\" value=\"" . $_SERVER["HTTP_REFERER"] . "\" />\n");
print("<input type=\"hidden\" name=\"cid\" value=\"$commentid\" />\n");
print("<textarea name=\"text\" rows=\"12\" cols=\"90\">" . stripslashes(htmlspecialchars($arr["text"])) . "</textarea></p>\n");
print("<p><input type=\"submit\" class=btn value=\"Opslaan\" /></p></form>\n");
?>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
document.edit_comment.text.focus();
//-->
</script>
<?php
print "<br>";
site_footer();
die;
}
elseif ($action == "delete")
{
if (get_user_class() < UC_MODERATOR)
site_error_message("Foutmelding", "Toegang geweigerd.");
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
site_error_message("Foutmelding", "Foutief ID $commentid.");
$sure = @$_GET["sure"];
if (!$sure)
{
$referer = $_SERVER["HTTP_REFERER"];
site_error_message("Delete comment", "You are about to delete a comment. Click\n" .
"<a href=?action=delete&cid=$commentid&sure=1" .
($referer ? "&returnto=" . urlencode($referer) : "") .
">here</a> if you are sure.");
}
$res = mysqli_query($con_link, "SELECT torrent FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysqli_fetch_array($res);
if ($arr)
$torrentid = $arr["torrent"];
mysqli_query($con_link, "DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
if ($torrentid && mysqli_affected_rows($con_link) > 0)
mysqli_query($con_link, "UPDATE torrents SET comments = comments - 1 WHERE id = $torrentid");
$returnto = @$_GET["returnto"];
if ($returnto)
header("Location: $returnto");
else
header("Location: $BASEURL/"); // change later ----------------------
die;
}
elseif ($action == "vieworiginal")
{
if (get_user_class() < UC_MODERATOR)
site_error_message("Foutmelding", "Toegang geweigerd.");
$commentid = 0 + $_GET["cid"];
if (!is_valid_id($commentid))
site_error_message("Foutmelding", "Foutief ID $commentid.");
$res = mysqli_query($con_link, "SELECT c.*, t.name FROM comments AS c JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
$arr = mysqli_fetch_array($res);
if (!$arr)
site_error_message("Foutmelding", "Foutief ID $commentid.");
site_header("Original comment");
print("<h1>Original contents of comment #$commentid</h1><p>\n");
print("<table width=500 border=1 cellspacing=0 cellpadding=5>");
print("<tr><td class=comment>\n");
echo htmlspecialchars($arr["ori_text"]);
print("</td></tr></table>\n");
$returnto = $_SERVER["HTTP_REFERER"];
// $returnto = "details.php?id=$torrentid&viewcomm=$commentid#$commentid";
if ($returnto)
print("<p><font size=small>(<a href=$returnto>back</a>)</font></p>\n");
print "<br>";
site_footer();
die;
}
else
site_error_message("Foutmelding", "Onbekende aktie $action");
die;
?>