/
shoutbox.php
367 lines (354 loc) · 18.7 KB
/
shoutbox.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
/**
* http://btdev.net:1337/svn/test/Installer09_Beta
* Licence Info: GPL
* Copyright (C) 2010 BTDev Installer v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn.
**/
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'bittorrent.php');
require_once(INCL_DIR . 'user_functions.php');
require_once(INCL_DIR . 'bbcode_functions.php');
dbconn(false);
loggedinorreturn();
$HTMLOUT = "";
// === added turn on / off shoutbox - sir snuggs
if ((isset($_GET['show_shout'])) && (($show_shout = $_GET['show']) !== $CURUSER['show_shout'])) {
sql_query("UPDATE users SET show_shout = " . sqlesc($_GET['show']) . " WHERE id = " . sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
header("Location: " . $_SERVER['HTTP_REFERER']);
}
unset($insert);
$insert = false;
$query = "";
$sb = array(
'charset' => 'UTF-8'
);
// Delete single shout
if (isset($_GET['del']) && $CURUSER['class'] >= UC_STAFF && is_valid_id($_GET['del'])) {
sql_query("DELETE FROM shoutbox WHERE id=" . sqlesc($_GET['del'])) or sqlerr(__FILE__, __LINE__);
}
// Empty shout - sysop
if (isset($_GET['delall']) && $CURUSER['class'] == UC_SYSOP) {
sql_query("TRUNCATE TABLE shoutbox") or sqlerr(__FILE__, __LINE__);
}
// Staff edit
if (isset($_GET['edit']) && $CURUSER['class'] >= UC_STAFF && is_valid_id($_GET['edit'])) {
$sql = sql_query('SELECT id, text FROM shoutbox WHERE id=' . sqlesc($_GET['edit'])) or sqlerr(__FILE__, __LINE__);
$res = mysqli_fetch_assoc($sql);
unset($sql);
$HTMLOUT .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Pragma' content='no-cache' />
<meta http-equiv='expires' content='-1' />
<html xmlns='http://www.w3.org/1999/xhtml'>
<meta http-equiv='Content-Type' content='text/html; charset={$sb['charset']}' />
<script type='text/javascript' src='./scripts/shout.js'></script>
<style type='text/css'>
#specialbox{
border: 1px solid gray;
width: 600px;
background: #FBFCFA;
font: 11px verdana, sans-serif;
color: #000000;
padding: 3px; outline: none;
}
#specialbox:focus{
border: 1px solid black;
}
.btn {
cursor:pointer;
border:outset 1px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 1px 2px;
background: #000000 repeat-x left top;
}
</style>
</head>
<body bgcolor='#F5F4EA' class='date'>
<form method='post' action='./shoutbox.php'>
<input type='hidden' name='id' value='" . (int) $res['id'] . "' />
<textarea name='text' rows='3' id='specialbox'>" . htmlspecialchars($res['text']) . "</textarea>
<input type='submit' name='save' value='save' class='btn' />
</form></body></html>";
echo $HTMLOUT;
die;
}
// Power Users+ can edit anyones single shouts //== pdq
if (isset($_GET['edit']) && ($_GET['user'] == $CURUSER['id']) && ($CURUSER['class'] >= UC_POWER_USER && $CURUSER['class'] <= UC_STAFF) && is_valid_id($_GET['edit'])) {
$sql = sql_query('SELECT id, text, userid FROM shoutbox WHERE userid =' . sqlesc($_GET['user']) . ' AND id=' . sqlesc($_GET['edit'])) or sqlerr(__FILE__, __LINE__);
$res = mysqli_fetch_array($sql);
$HTMLOUT .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Pragma' content='no-cache' />
<meta http-equiv='expires' content='-1' />
<html xmlns='http://www.w3.org/1999/xhtml'>
<meta http-equiv='Content-Type' content='text/html; charset={$sb['charset']}' />
<script type='text/javascript' src='./scripts/shout.js'></script>
<style type='text/css'>
.specialbox{
border: 1px solid gray;
width: 600px;
background: #FBFCFA;
font: 11px verdana, sans-serif;
color: #000000;
padding: 3px; outline: none;
}
.specialbox:focus{
border: 1px solid black;
}
.btn {
cursor:pointer;
border:outset 1px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 1px 2px;
background: #000000 repeat-x left top;
}
</style>
</head>
<body bgcolor='#F5F4EA' class='date'>
<form method='post' action='./shoutbox.php'>
<input type='hidden' name='id' value='" . (int) $res['id'] . "' />
<input type='hidden' name='user' value='" . (int) $res['userid'] . "' />
<textarea name='text' rows='3' id='specialbox'>" . htmlspecialchars($res['text']) . "</textarea>
<input type='submit' name='save' value='save' class='btn' />
</form></body></html>";
echo $HTMLOUT;
die;
}
// Staff shout edit
if (isset($_POST['text']) && $CURUSER['class'] >= UC_STAFF && is_valid_id($_POST['id'])) {
require_once(INCL_DIR . 'bbcode_functions.php');
$text = trim($_POST['text']);
$text_parsed = format_comment($text);
sql_query('UPDATE shoutbox SET text = ' . sqlesc($text) . ', text_parsed = ' . sqlesc($text_parsed) . ' WHERE id=' . sqlesc($_POST['id'])) or sqlerr(__FILE__, __LINE__);
unset($text, $text_parsed);
}
// Power User+ shout edit //==pdq
if (isset($_POST['text']) && (isset($_POST['user']) == $CURUSER['id']) && ($CURUSER['class'] >= UC_POWER_USER && $CURUSER['class'] < UC_STAFF) && is_valid_id($_POST['id'])) {
require_once(INCL_DIR . 'bbcode_functions.php');
$text = trim($_POST['text']);
$text_parsed = format_comment($text);
sql_query('UPDATE shoutbox SET text = ' . sqlesc($text) . ', text_parsed = ' . sqlesc($text_parsed) . ' WHERE userid=' . sqlesc($_POST['user']) . ' AND id=' . sqlesc($_POST['id'])) or sqlerr(__FILE__, __LINE__);
unset($text, $text_parsed);
}
//== begin main output
$HTMLOUT .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>ShoutBox</title>
<meta http-equiv='REFRESH' content='60; URL=./shoutbox.php' />
<script type='text/javascript' src='./scripts/shout.js'></script>
<meta http-equiv='Content-Type' content='text/html; charset={$sb['charset']}' />
<style type='text/css'>
A {color: #356AA0; font-weight: bold; font-size: 9pt; }
A:hover {color: #FF0000;}
.small {color: #ff0000; font-size: 9pt; font-family: arial; }
.date {color: #ff0000; font-size: 9pt;}
.error {
color: #990000;
background-color: #FFF0F0;
padding: 7px;
margin-top: 5px;
margin-bottom: 10px;
border: 1px dashed #990000;
}
A {color: #FFFFFF; font-weight: bold; }
A:hover {color: #FFFFFF;}
.small {font-size: 10pt; font-family: arial; }
.date {font-size: 8pt;}
span.size1 { font-size:0.75em; }
span.size2 { font-size:1em; }
span.size3 { font-size:1.25em; }
span.size4 { font-size:1.5em; }
span.size5 { font-size:1.75em; }
span.size6 { font-size:2em; }
span.size7 { font-size:2.25em; }
</style>";
//==Background colours begin
//== White
if ($CURUSER['shoutboxbg'] == 1) {
$HTMLOUT .= "<style type='text/css'>
A {color: #000000; font-weight: bold; }
A:hover {color: #FF273D;}
.small {font-size: 10pt; font-family: arial; }
.date {font-size: 8pt;}
</style>";
$bg = '#ffffff';
$fontcolor = '#000000';
$dtcolor = '#356AA0';
}
// == Grey
if ($CURUSER['shoutboxbg'] == 2) {
$HTMLOUT .= "<style type='text/css'>
A {color: #ffffff; font-weight: bold; }
A:hover {color: #FF273D;}
.small {font-size: 10pt; font-family: arial; }
.date {font-size: 8pt;}
</style>";
$bg = '#777777';
$fontcolor = '#000000';
$dtcolor = '#FFFFFF';
}
// == Black
if ($CURUSER['shoutboxbg'] == 3) {
$HTMLOUT .= "<style type='text/css'>
A {color: #FFFFFF; font-weight: bold; ; }
A:hover {color: #FFFFFF;}
.small {font-size: 10pt; font-family: arial; }
.date {font-size: 8pt;}
</style>";
$bg = '#1f1f1f';
$fontcolor = '#FFFFFF';
$dtcolor = '#FFFFFF';
}
$HTMLOUT .= "</head><body>";
//== Banned from shout ??
if ($CURUSER['chatpost'] == 0 || $CURUSER['chatpost'] > 1) {
$HTMLOUT .= "<div class='error' align='center'><br /><font color='red'>Sorry, you are not authorized to Shout.</font> (<a href=\"./rules.php\" target=\"_blank\"><font color='red'>Contact Site Admin For The Reason Why</font></a>)<br /><br /></div></body></html>";
echo $HTMLOUT;
exit;
}
//=End
if (isset($_GET['sent']) && ($_GET['sent'] == "yes")) {
require_once(INCL_DIR . 'bbcode_functions.php');
$limit = 5;
$userid = $CURUSER["id"];
$date = sqlesc(time());
$text = (trim($_GET["shbox_text"]));
$text_parsed = format_comment($text);
$system_pattern = '/(^\/system)\s([\w\W\s]+)/is';
if (preg_match($system_pattern, $text, $out) && $CURUSER["class"] >= UC_STAFF) {
$userid = $INSTALLER09['bot_id'];
$text = $out[2];
$text_parsed = format_comment($text);
}
// ///////////////////////shoutbox command system by putyn /////////////////////////////
$commands = array(
"\/EMPTY",
"\/GAG",
"\/UNGAG",
"\/WARN",
"\/UNWARN",
"\/DISABLE",
"\/ENABLE"
); // this / was replaced with \/ to work with the regex
$pattern = "/(" . implode("|", $commands) . "\w+)\s([a-zA-Z0-9_:\s(?i)]+)/";
//== private mode by putyn
$private_pattern = "/(^\/private)\s([a-zA-Z0-9]+)\s([\w\W\s]+)/";
if (preg_match($pattern, $text, $vars) && $CURUSER["class"] >= UC_STAFF) {
$command = $vars[1];
$user = $vars[2];
$c = sql_query("SELECT id, class, modcomment FROM users where username=" . sqlesc($user)) or sqlerr(__FILE__, __LINE__);
$a = mysqli_fetch_row($c);
if (mysqli_num_rows($c) == 1 && $CURUSER["class"] > $a[1]) {
switch ($command) {
case "/EMPTY":
$what = 'deleted all shouts';
$msg = "[b]" . $user . "'s[/b] shouts have been deleted";
$query = "DELETE FROM shoutbox where userid = " . sqlesc($a[0]);
break;
case "/GAG":
$what = 'gagged';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been gagged by " . $CURUSER["username"] . "\n" . $a[2];
$msg = "[b]" . $user . "[/b] - has been gagged by " . $CURUSER["username"];
$query = "UPDATE users SET chatpost='0', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
case "/UNGAG":
$what = 'ungagged';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been ungagged by " . $CURUSER["username"] . "\n" . sqlesc($a[2]);
$msg = "[b]" . $user . "[/b] - has been ungagged by " . $CURUSER["username"];
$query = "UPDATE users SET chatpost='1', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
case "/WARN":
$what = 'warned';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been warned by " . $CURUSER["username"] . "\n" . $a[2];
$msg = "[b]" . $user . "[/b] - has been warned by " . $CURUSER["username"];
$query = "UPDATE users SET warned='1', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
case "/UNWARN":
$what = 'unwarned';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been unwarned by " . $CURUSER["username"] . "\n" . $a[2];
$msg = "[b]" . $user . "[/b] - warning removed by " . $CURUSER["username"];
$query = "UPDATE users SET warned='0', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
case "/DISABLE":
$what = 'disabled';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been disabled by " . $CURUSER["username"] . "\n" . $a[2];
$msg = "[b]" . $user . "[/b] - has been disabled by " . $CURUSER["username"];
$query = "UPDATE users SET enabled='no', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
case "/ENABLE":
$what = 'enabled';
$modcomment = get_date(time(), 'DATE', 1) . " - [ShoutBox] User has been enabled by " . $CURUSER["username"] . "\n" . $a[2];
$msg = "[b]" . $user . "[/b] - has been enabled by " . $CURUSER["username"];
$query = "UPDATE users SET enabled='yes', modcomment = concat(" . sqlesc($modcomment) . ", modcomment) WHERE id = " . sqlesc($a[0]);
break;
}
if (sql_query($query))
autoshout($msg);
$HTMLOUT .= "<script type=\"text/javascript\">parent.document.forms[0].shbox_text.value='';</script>";
write_log("Shoutbox user " . $user . " has been " . $what . " by " . $CURUSER["username"]);
unset($text, $text_parsed, $query, $date, $modcomment, $what, $msg, $commands);
}
} elseif (preg_match($private_pattern, $text, $vars)) {
$to_user = 0;
$p_res = sql_query(sprintf('SELECT id FROM users WHERE username = %s', sqlesc($vars[2]))) or exit(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
if (mysqli_num_rows($p_res) == 1) {
$p_arr = mysqli_fetch_row($p_res);
$to_user = (int)$p_arr[0];
}
if ($to_user != 0 && $to_user != $CURUSER['id']) {
$text = $vars[2] . " - " . $vars[3];
$text_parsed = format_comment($text);
sql_query("INSERT INTO shoutbox (userid, date, text, text_parsed,to_user) VALUES (" . sqlesc($userid) . ", $date, " . sqlesc($text) . "," . sqlesc($text_parsed) . "," . sqlesc($to_user) . ")") or sqlerr(__FILE__, __LINE__);
}
$HTMLOUT .= "<script type=\"text/javascript\">parent.document.forms[0].shbox_text.value='';</script>";
} else {
$a = mysqli_fetch_row(sql_query("SELECT userid,date FROM shoutbox ORDER by id DESC LIMIT 1 ")) or print("First shout or an error :)");
if (empty($text) || strlen($text) == 1)
$HTMLOUT .= "<font class=\"small\" color=\"red\">Shout can't be empty</font>";
elseif ($a[0] == $userid && (time() - $a[1]) < $limit && $CURUSER['class'] < UC_STAFF)
$HTMLOUT .= "<font class=\"small\" color=\"red\">$limit seconds between shouts <font class=\"small\">Seconds Remaining : (" . ($limit - (time() - $a[1])) . ")</font></font>";
else {
sql_query("INSERT INTO shoutbox (id, userid, date, text, text_parsed) VALUES ('id'," . sqlesc($userid) . ", $date, " . sqlesc($text) . "," . sqlesc($text_parsed) . ")") or sqlerr(__FILE__, __LINE__);
$HTMLOUT .= "<script type=\"text/javascript\">parent.document.forms[0].shbox_text.value='';</script>";
}
}
}
// //////////////////////
$res = sql_query("SELECT s.id, s.userid, s.date , s.text,s.to_user, u.username, u.pirate, u.king, u.class, u.donor, u.warned, u.leechwarn, u.enabled, u.chatpost, (SELECT count(id) FROM messages WHERE receiver = " . sqlesc($CURUSER['id']) . " AND unread = 'yes') as pms FROM shoutbox as s LEFT JOIN users as u ON s.userid=u.id ORDER BY s.date DESC LIMIT 30") or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
$HTMLOUT .= "No shouts here";
else {
$HTMLOUT .= "<table border='0' cellspacing='0' cellpadding='2' width='100%' align='left' class='small'>\n";
$gotpm = 0;
while ($arr = mysqli_fetch_assoc($res)) {
if ($arr['pms'] > 0 && $gotpm == 0) {
$HTMLOUT .= '<tr><td align=\'center\'><a href=\'' . $INSTALLER09['baseurl'] . '/messages.php\' target=\'_parent\'><font color=\'blue\'>You have ' . $arr['pms'] . ' new message' . ($arr['pms'] > 1 ? 's' : '') . '</font></a></td></tr>';
$gotpm++;
}
if (($arr['to_user'] != $CURUSER['id'] && $arr['to_user'] != 0) && $arr['userid'] != $CURUSER['id'])
continue;
elseif ($arr['to_user'] == $CURUSER['id'] || ($arr['userid'] == $CURUSER['id'] && $arr['to_user'] != 0))
$private = "<a href=\"javascript:private_reply('" . htmlspecialchars($arr['username']) . "')\"><img src=\"{$INSTALLER09['pic_base_url']}private-shout.png\" alt=\"Private shout\" title=\"Private shout! click to reply to " . htmlspecialchars($arr['username']) . "\" width=\"16\" style=\"padding-left:2px;padding-right:2px;\" border=\"0\" /></a>";
else
$private = '';
$edit = ($CURUSER['class'] >= UC_STAFF || ($arr['userid'] == $CURUSER['id']) && ($CURUSER['class'] >= UC_POWER_USER && $CURUSER['class'] <= UC_STAFF) ? "<a href='{$INSTALLER09['baseurl']}/shoutbox.php?edit=" . intval($arr['id']) . "&user=" . intval($arr['userid']) . "'><img src='{$INSTALLER09['pic_base_url']}button_edit2.gif' border='0' alt=\"Edit Shout\" title=\"Edit Shout\" /></a> " : "");
$del = ($CURUSER['class'] >= UC_STAFF ? "<a href='./shoutbox.php?del=" . intval($arr['id']) . "'><img src='{$INSTALLER09['pic_base_url']}button_delete2.gif' border='0' alt=\"Delete Single Shout\" title=\"Delete Single Shout\" /></a> " : "");
$delall = ($CURUSER['class'] >= UC_SYSOP ? "<a href='./shoutbox.php?delall' onclick=\"confirm_delete(); return false;\"><img src='{$INSTALLER09['pic_base_url']}del.png' border='0' alt=\"Empty Shout\" title=\"Empty Shout\" /></a> " : "");
$pm = "<span class='date' style=\"color:$dtcolor\"><a target='_blank' href='./sendmessage.php?receiver=" . intval($arr['userid']) . "'><img src='{$INSTALLER09['pic_base_url']}button_pm2.gif' border='0' alt=\"Pm User\" title=\"Pm User\" /></a></span>\n";
$date = get_date($arr["date"], 0, 1);
$user_stuff = $arr;
$user_stuff['id'] = intval($arr['userid']);
$HTMLOUT .= "<tr style='background-color:$bg;'><td><span class='size1' style='color:$fontcolor; '>[$date]</span>\n$del $delall $edit $pm $private " . format_username($user_stuff) . "<span class='size2' style='color:$fontcolor;'> " . format_comment($arr["text"]) . "\n</span></td></tr>\n";
}
$HTMLOUT .= "</table>";
}
$HTMLOUT .= "</body></html>";
echo $HTMLOUT;