summaryrefslogtreecommitdiffstats
path: root/includes/chats.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/chats.php')
-rw-r--r--includes/chats.php77
1 files changed, 74 insertions, 3 deletions
diff --git a/includes/chats.php b/includes/chats.php
index f55ce35..0e48ecf 100644
--- a/includes/chats.php
+++ b/includes/chats.php
@@ -32,6 +32,8 @@ function muteUser($userID, $numMinutes) {
return;
}
+
+
function addChat($userID, $message) {
global $mysqli;
if ($message == '') return;
@@ -48,7 +50,6 @@ function addChat($userID, $message) {
//Turnicate messages.
$deleteFromID = $ID - CHAT_ROWS_TO_KEEP;
$mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
- $mysqli->close();
return $ID;
}
@@ -61,7 +62,7 @@ function getChat($startID = 0) {
//Not sure why this happens; but just return nothing..
if (!is_object($mysqli)) die("mysqli is not an object");
- $res = $mysqli->query("
+ if ($res = $mysqli->query("
SELECT
chat.ID, chat.userID, chat.message, chat.dateSent,
users.displayName,
@@ -74,6 +75,76 @@ function getChat($startID = 0) {
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
+ ");
+ $stmt->bind_param('ii', $userID, $channel);
+ $stmt->execute();
+ $stmt->close();
+ 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;
+}
+
+//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,
+ chatUsers.dateEntered,
+ chatUsers.dateLastActive,
+ chatUsers.isAdmin,
+ chatUsers.isMod,
+
+ users.displayName,
+ users.displayColor,
+ users.wallColor,
+ users.wallEmblem,
+ users.wallOrientation
+ FROM `chatUsers`
+ LEFT JOIN `users`
+ ON chatUsers.userID = users.ID
+ ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered DESC
");
$array = array();
if ($res->num_rows == 0) {
@@ -87,10 +158,10 @@ function getChat($startID = 0) {
$mysqli->close();
if (count($array) < 1) return false;
-
return $array;
}
+
function filterStringForBadLanguage($chat) {
//cuss words
$chat = str_ireplace("fuck you", "i am moron", $chat);