summaryrefslogtreecommitdiffstats
path: root/includes/chats.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/chats.php')
-rw-r--r--includes/chats.php91
1 files changed, 81 insertions, 10 deletions
diff --git a/includes/chats.php b/includes/chats.php
index 7db4c58..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;
@@ -44,19 +46,23 @@ function addChat($userID, $message) {
$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;
- $array = array();
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");
- $res = $mysqli->query("
+ if ($res = $mysqli->query("
SELECT
chat.ID, chat.userID, chat.message, chat.dateSent,
users.displayName,
@@ -68,7 +74,77 @@ function getChat($startID = 0) {
LEFT JOIN `users`
ON chat.userID = users.ID
WHERE chat.ID > '$startID'
- ORDER BY chat.ID ASC
+ 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) {
@@ -77,20 +153,15 @@ function getChat($startID = 0) {
}
while ($response = $res->fetch_assoc()) {
$array[] = $response;
- $lastID = $response['ID'];
}
$res->close();
-
- if (count($array) < 1) return false;
-
- //Turnicate messages.
- $deleteFromID = $lastID - CHAT_ROWS_TO_KEEP;
- $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
$mysqli->close();
+ if (count($array) < 1) return false;
return $array;
}
+
function filterStringForBadLanguage($chat) {
//cuss words
$chat = str_ireplace("fuck you", "i am moron", $chat);