-
Notifications
You must be signed in to change notification settings - Fork 8
/
blacklist.php
288 lines (279 loc) · 8.04 KB
/
blacklist.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
global $ir, $userid, $h;
require_once('globals.php');
if ($ir['donatordays'] == 0)
{
echo 'This feature is for donators only.';
$h->endpage();
exit;
}
echo '<h3>Black List</h3>';
if (!isset($_GET['action']))
{
$_GET['action'] = '';
}
switch ($_GET['action'])
{
case 'add':
add_enemy();
break;
case 'remove':
remove_enemy();
break;
case 'ccomment':
change_comment();
break;
default:
black_list();
break;
}
/**
* @return void
*/
function black_list(): void
{
global $db, $ir, $userid;
echo "
<a href='blacklist.php?action=add'>> Add an Enemy</a><br />
These are the people on your black list.
<br />
{$ir['enemy_count']} people have added you to their list.
<br />
Most hated: [";
$q2r =
$db->query(
'SELECT `username`, `userid` FROM `users` ORDER BY `enemy_count` DESC LIMIT 5');
$r = 0;
while ($r2r = $db->fetch_row($q2r))
{
$r++;
if ($r > 1)
{
echo ' | ';
}
echo "<a href='viewuser.php?u={$r2r['userid']}'>{$r2r['username']}</a>";
}
$db->free_result($q2r);
echo ']
<table width="90%" class="table" cellspacing="1">
<tr style="background:gray">
<th>ID</th>
<th>Name</th>
<th>Mail</th>
<th>Attack</th>
<th>Remove</th>
<th>Comment</th>
<th>Change Comment</th>
<th>Online?</th>
</tr>
';
$q =
$db->query(
"SELECT `bl`.`bl_COMMENT`, `bl_ID`,
`u`.`laston`, `donatordays`, `username`, `userid`
FROM `blacklist` AS `bl`
LEFT JOIN `users` AS `u` ON `bl`.`bl_ADDED` = `u`.`userid`
WHERE `bl`.`bl_ADDER` = $userid
ORDER BY `u`.`username` ASC");
while ($r = $db->fetch_row($q))
{
$on =
($r['laston'] >= (($_SERVER['REQUEST_TIME'] - 15) * 60))
? '<font color="green"><b>Online</b></font>'
: '<font color="red"><b>Offline</b></font>';
$d = '';
if ($r['donatordays'])
{
$r['username'] = "<font color=red>{$r['username']}</font>";
$d =
"<img src='donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />";
}
if (empty($r['bl_COMMENT']))
{
$r['bl_COMMENT'] = 'N/A';
}
echo "
<tr>
<td>{$r['userid']}</td>
<td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> $d</td>
<td><a href='mailbox.php?action=compose&ID={$r['userid']}'>Mail</a></td>
<td><a href='attack.php?ID={$r['userid']}'>Attack</a></td>
<td><a href='blacklist.php?action=remove&b={$r['bl_ID']}'>Remove</a></td>
<td>" . strip_tags($r['bl_COMMENT'])
. "</td> <td><a href='blacklist.php?action=ccomment&b={$r['bl_ID']}'>Change</a></td>
<td>$on</td>
</tr>
";
}
$db->free_result($q);
echo '</table>';
}
/**
* @return void
*/
function add_enemy(): void
{
global $db, $userid;
$_POST['ID'] =
(isset($_POST['ID']) && is_numeric($_POST['ID']))
? abs(intval($_POST['ID'])) : '';
$_POST['comment'] =
(isset($_POST['comment']) && is_string($_POST['comment']))
? $db->escape(strip_tags(stripslashes($_POST['comment'])))
: '';
if ($_POST['ID'])
{
$qc =
$db->query(
"SELECT COUNT(`bl_ADDER`) FROM `blacklist` WHERE `bl_ADDER` = $userid AND `bl_ADDED` = {$_POST['ID']}");
$q =
$db->query(
"SELECT `username` FROM `users` WHERE `userid` = {$_POST['ID']}");
$dupe_count = $db->fetch_single($qc);
$db->free_result($qc);
if ($dupe_count > 0)
{
echo 'You cannot add the same person twice.';
}
elseif ($userid == $_POST['ID'])
{
echo 'You cannot be so lonely that you have to try and add yourself.';
}
elseif ($db->num_rows($q) == 0)
{
echo "Oh no, you're trying to add a ghost.";
}
else
{
$db->query(
"INSERT INTO `blacklist` VALUES(NULL, $userid, {$_POST['ID']}, '{$_POST['comment']}')");
$r = $db->fetch_row($q);
$db->free_result($q);
$db->query(
"UPDATE `users` SET `enemy_count` = `enemy_count` + 1 WHERE `userid` = {$_POST['ID']}");
echo "{$r['username']} was added to your black list.<br />
<a href='blacklist.php'>> Back</a>";
}
}
else
{
$_GET['ID'] =
(isset($_GET['ID']) && is_numeric($_GET['ID']))
? abs(intval($_GET['ID'])) : '';
echo "
Adding an enemy!
<form action='blacklist.php?action=add' method='post'>
Enemy's ID: <input type='text' name='ID' value='{$_GET['ID']}' /><br />
Comment (optional): <br />
<textarea name='comment' rows='7' cols='40'></textarea><br />
<input type='submit' value='Add Enemy' />
</form>
";
}
}
/**
* @return void
*/
function remove_enemy(): void
{
global $db, $userid, $h;
$_GET['b'] =
(isset($_GET['b']) && is_numeric($_GET['b']))
? abs(intval($_GET['b'])) : '';
if (empty($_GET['b']))
{
echo '
You didn\'t select a real enemy.<br />
> <a href="blacklist.php">Back</a>
';
$h->endpage();
exit;
}
$q =
$db->query(
"SELECT `bl_ADDED` FROM `blacklist` WHERE `bl_ID` = {$_GET['b']} AND `bl_ADDER` = $userid");
if ($db->num_rows($q) == 0)
{
echo 'Listing doesn\'t exist.';
$h->endpage();
exit;
}
$r = $db->fetch_row($q);
$db->free_result($q);
$db->query(
"DELETE FROM `blacklist` WHERE `bl_ID` = {$_GET['b']} AND `bl_ADDER` = $userid");
$db->query(
"UPDATE `users` SET `enemy_count` = `enemy_count` - 1 WHERE `userid` = {$r['bl_ADDED']}");
echo "
Black list entry removed!<br />
<a href='blacklist.php'>> Back</a>
";
}
/**
* @return void
*/
function change_comment(): void
{
global $db, $userid, $h;
$_POST['b'] =
(isset($_POST['b']) && is_numeric($_POST['b']))
? abs(intval($_POST['b'])) : '';
$_POST['comment'] =
(isset($_POST['comment']) && is_string($_POST['comment']))
? $db->escape(strip_tags(stripslashes($_POST['comment'])))
: '';
if (!empty($_POST['comment']) && !empty($_POST['b']))
{
$db->query(
"UPDATE `blacklist` SET `bl_COMMENT` = '{$_POST['comment']}' WHERE `bl_ID` = {$_POST['b']} AND `bl_ADDER` = $userid");
echo "
Comment for enemy changed!<br />
<a href='blacklist.php'>> Back</a>
";
}
else
{
$_GET['b'] =
(isset($_GET['b']) && is_numeric($_GET['b']))
? abs(intval($_GET['b'])) : '';
if (empty($_GET['b']))
{
echo "
Invalid enemy.<br />
<a href='blacklist.php'>> Back</a>
";
$h->endpage();
exit;
}
$q =
$db->query(
"SELECT `bl_COMMENT` FROM `blacklist` WHERE `bl_ID` = {$_GET['b']} AND `bl_ADDER` = $userid");
if ($db->num_rows($q) > 0)
{
$r = $db->fetch_row($q);
$comment = stripslashes(strip_tags($r['bl_COMMENT']));
echo "
Changing a comment.
<form action='blacklist.php?action=ccomment' method='post'>
<input type='hidden' name='b' value='{$_GET['b']}' /><br />
Comment: <br />
<textarea rows='7' cols='40' name='comment'>$comment</textarea><br />
<input type='submit' value='Change Comment' />
</form>
";
}
else
{
echo 'It would be impossible to edit something which isn\'t yours.<br /> > <a href="index.php">Go Home</a>';
}
$db->free_result($q);
}
}
$h->endpage();