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
|
<?
/*
* addChat, getChat functions
*/
include_once('sqlEmbedded.php');
define('CHAT_ROWS_TO_KEEP', 75);
function isMuted($userID) {
global $mysqli;
$sql = "SELECT `dateChatGaggedUntil` FROM `users`
WHERE `ID` = ?
AND `dateChatGaggedUntil` > NOW()";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("i", $userID);
$stmt->execute();
$stmt->bind_result($date);
$stmt->fetch();
if ($date) return $date;
else return false;
}
function muteUser($userID, $numMinutes) {
global $mysqli;
$stmt = $mysqli->prepare("UPDATE `users`
SET `dateChatGaggedUntil` = ADDDATE(NOW(), INTERVAL ? MINUTE)
WHERE `ID` = ?");
$stmt->bind_param('ii', $numMinutes, $userID);
$stmt->execute();
return;
}
function addChat($userID, $message) {
global $mysqli;
if ($message == '') return;
$stmt = $mysqli->prepare("INSERT INTO `chat`
(`userID`, `message`)
VALUES (?, ?)");
$stmt->bind_param('is', $userID, $message);
$stmt->execute();
$ID = $stmt->insert_id;
$stmt->close();
//Turnicate messages.
$deleteFromID = $ID - CHAT_ROWS_TO_KEEP;
$mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
return $ID;
}
function getChat($startID = 0) {
global $mysqli;
if (!is_numeric($startID)) return false;
//Not sure why this happens; but just return nothing..
if (!is_object($mysqli)) die("mysqli is not an object");
if ($res = $mysqli->query("
SELECT
chat.ID, chat.userID, chat.message, chat.dateSent,
users.displayName,
users.displayColor,
users.wallColor,
users.wallEmblem,
users.wallOrientation
FROM `chat`
LEFT JOIN `users`
ON chat.userID = users.ID
WHERE chat.ID > '$startID'
ORDER BY chat.dateSent ASC, chat.ID ASC
")) {
$array = array();
if ($res->num_rows == 0) {
$res->close();
return false;
}
while ($response = $res->fetch_assoc()) {
$array[] = $response;
}
$res->close();
if (count($array) < 1) return false;
return $array;
} else {
printf("DError: %s\n", $mysqli->error);
return false;
}
}
//Enters a user into a channel
function enterChannel($userID, $channel = 1) {
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO `chatUsers`
(`userID`, `channel`, `dateEntered`, `isHere`)
VALUES (?, ?, NOW(), true)
ON DUPLICATE KEY UPDATE `isHere` = true, dateLastActive = NOW()
");
$stmt->bind_param('ii', $userID, $channel);
$stmt->execute();
$stmt->close();
cleanupChannel();
return;
}
//User leaves the channel
function exitChannel($userID, $channel = 1) {
global $mysqli;
$stmt = $mysqli->prepare("UPDATE `chatUsers`
SET `isHere` = false
WHERE `userID` = ? AND `channel` = ?");
$stmt->bind_param('ii', $userID, $channel);
$stmt->execute();
return;
}
//User leaves the channel
function cleanupChannel($channel = 1) {
global $mysqli;
$mysqli->query("DELETE FROM `chatUsers` WHERE TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) > 800");
return;
}
function channelListUpdated($timeStamp) {
global $mysqli;
$stmt = $mysqli->prepare("SELECT `value` FROM `settings`
WHERE `name` = 'Channel_Last_Update' AND
`value` < '?'"
);
$stmt->bind_param( "i", $timeStamp);
$stmt->execute();
$stmt->bind_result($value);
return $value;
}
//Get a list of users in channel
function getChannelList($channel = 1) {
global $mysqli;
if (!is_numeric($channel)) return false;
$res = $mysqli->query("
SELECT
chatUsers.userID as 'ID',
chatUsers.dateEntered,
TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as secFromLastActive,
TIME_TO_SEC(TIMEDIFF(NOW(), users.dateChatGaggedUntil)) as secSinceGagged,
chatUsers.isAdmin,
chatUsers.isMod,
users.displayName as 'display',
users.displayColor,
users.wallColor,
users.wallEmblem,
users.wallOrientation
FROM `chatUsers`
LEFT JOIN `users`
ON chatUsers.userID = users.ID
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) < 300
ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered ASC
");
$array = array();
if ($res->num_rows == 0) {
$res->close();
return false;
}
while ($response = $res->fetch_assoc()) {
$array['users'][] = $response;
}
$res->close();
$mysqli->close();
if (count($array) < 1) return false;
return $array;
}
function filterStringForBadLanguage($chat) {
//cuss words
$chat = str_ireplace("fuck you", "i am moron", $chat);
$chat = preg_replace("/[f]+\s*[uv]+\s*[h]*\s*[c\(k]+\s*(([i]*\s*[n]*\s*[g])|([e]*\s*[r]*))*/i", "dumb ", $chat); //fucker / fucking
$chat = preg_replace("/[^a-z]fag(g?[oi]t)?/i", " prince", $chat); //faggot
$chat = preg_replace("/^fag(g?[oi]t)?/i", "prince", $chat); //faggot (beginning of line)
$chat = preg_replace("/^suck\s*my.*(cock|dick|penis)/i", "join me in a riveting game of checkers", $chat); //suck my dick
$chat = str_ireplace("damn", "dumb", $chat);
$chat = str_ireplace("bull shit", "cow doodoo of the male variety", $chat);
$chat = str_ireplace("shit", "poo", $chat);
$chat = str_ireplace("sucks ass", "is dumb", $chat);
$chat = str_ireplace("suck ass", "are dumb", $chat);
$chat = str_ireplace("damnit", "do'h", $chat);
$chat = str_ireplace("sonuvabitch", "fiddlesticks", $chat);
$chat = str_ireplace("a bitch", "an engaging conversationalist", $chat);
$chat = str_ireplace("bitch", "engaging conversationalist", $chat);
$chat = str_ireplace("an asshole", "a pleasant person to be around", $chat);
$chat = str_ireplace("asshole", "pleasant person to be around", $chat);
$chat = str_ireplace("cock", "elbow", $chat);
$chat = str_ireplace("dick", "elbow", $chat);
$chat = str_ireplace("penis", "elbow", $chat);
$chat = str_ireplace("vagina", "femur bone", $chat);
$chat = str_ireplace("cunt", "femur bone", $chat);
//$chat = str_ireplace("hell", "the supermarket", $chat);
$chat = str_ireplace("whore", "entrepreneur", $chat);
$chat = str_ireplace("stfu", "be still my beating heart", $chat);
$chat = str_ireplace("omfg", "omg", $chat);
$chat = str_ireplace("4chan", "NEWT GINGRICH", $chat);
$chat = str_ireplace("nigger", "classy gentleman", $chat);
$chat = str_ireplace("pedophile", "Optimus Prime", $chat);
$chat = str_ireplace(" rape", " shake hands with", $chat);
//Easter Eggs
$chat = str_ireplace("i just pwned Snap", "Snap just totally pwned me ^^", $chat);
$chat = str_ireplace("i just pwned Blue", "Blue just epicly pwned me the with chat filter", $chat);
$chat = str_ireplace("language filter", "highly educated team of monkeys employed to filter bad language", $chat);
$chat = str_ireplace("chat filter", "highly educated team of monkeys employed to filter bad language", $chat);
return $chat;
}
?>
|