function heartbeat() { $response = array(); $messages = array(); global $userid; global $db; global $chatrooms_language; global $chatroomTimeout; global $lastMessages; global $cookiePrefix; $usertable = TABLE_PREFIX . DB_USERTABLE; $usertable_username = DB_USERTABLE_NAME; $usertable_userid = DB_USERTABLE_USERID; $time = getTimeStamp(); $chatroomList = array(); if (isset($_POST['popout']) && $_POST['popout'] == 0) { $_SESSION['cometchat']['cometchat_chatroomspopout'] = $time; } if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) { $sql = "insert into cometchat_chatrooms_users (userid,chatroomid,lastactivity) values ('" . mysql_real_escape_string($userid) . "','" . mysql_real_escape_string($_POST['currentroom']) . "','" . mysql_real_escape_string($time) . "') on duplicate key update chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "', lastactivity = '" . mysql_real_escape_string($time) . "'"; $query = mysql_query($sql); } if (empty($_SESSION['cometchat']['cometchat_chatroomslist']) || !empty($_POST['force']) || !empty($_SESSION['cometchat']['cometchat_chatroomslist']) && $time - $_SESSION['cometchat']['cometchat_chatroomslist'] > REFRESH_BUDDYLIST) { $sql = "select cometchat_chatrooms.id, cometchat_chatrooms.name, cometchat_chatrooms.type, cometchat_chatrooms.password, cometchat_chatrooms.lastactivity, cometchat_chatrooms.createdby, (SELECT count(userid) online FROM cometchat_chatrooms_users where cometchat_chatrooms_users.chatroomid = cometchat_chatrooms.id and '{$time}'-lastactivity<" . ONLINE_TIMEOUT . ") online from cometchat_chatrooms where (type <> 2 or type = 2 and createdby = '" . mysql_real_escape_string($userid) . "' )and (createdby = 0 OR (createdby <> 0 AND ('" . mysql_real_escape_string($time) . "'-lastactivity < {$chatroomTimeout}))) order by name asc"; $query = mysql_query($sql); while ($chatroom = mysql_fetch_array($query)) { $s = 0; if ($chatroom['createdby'] != $userid) { $chatroom['password'] = ''; } else { $s = 1; } $chatroomList[] = array('id' => $chatroom['id'], 'name' => $chatroom['name'], 'online' => $chatroom['online'], 'type' => $chatroom['type'], 'i' => $chatroom['password'], 's' => $s); } $_SESSION['cometchat']['cometchat_chatroomslist'] = $time; $ch = md5(serialize($chatroomList)); if (empty($_POST['clh']) || !empty($_POST['clh']) && $ch != $_POST['clh']) { if (!empty($chatroomList)) { $response['chatrooms'] = $chatroomList; } $response['clh'] = $ch; } } if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) { $sql = "select {$usertable}.{$usertable_userid} as userid, {$usertable}.{$usertable_username} as username from {$usertable}, cometchat_chatrooms_users where {$usertable}.{$usertable_userid} = cometchat_chatrooms_users.userid and chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and ('{$time}' - cometchat_chatrooms_users.lastactivity < " . ONLINE_TIMEOUT . ") order by {$usertable}.{$usertable_username} asc"; $query = mysql_query($sql); $users = array(); while ($chat = mysql_fetch_array($query)) { if (function_exists('processName')) { $chat['username'] = processName($chat['username']); } if ($userid == $chat['userid']) { $chat['userid'] = 0; } $users[] = array('id' => $chat['userid'], 'n' => $chat['username']); } $uh = md5(serialize($users)); if (empty($_POST['ulh']) || !empty($_POST['ulh']) && $uh != $_POST['ulh']) { $response['ulh'] = $uh; if (!empty($users)) { $response['users'] = $users; } } if (USE_COMET != 1 || COMET_CHATROOMS != 1) { $reverse = 1; $sql = "select cometchat_chatroommessages.id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, m.{$usertable_username} `from`, cometchat_chatroommessages.userid fromid, m.{$usertable_userid} userid from cometchat_chatroommessages, {$usertable} m where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and m.{$usertable_userid} = cometchat_chatroommessages.userid order by cometchat_chatroommessages.id desc limit {$lastMessages}"; if ($_POST['timestamp'] != 0) { $sql = "select cometchat_chatroommessages.id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, m.{$usertable_username} `from`, cometchat_chatroommessages.userid fromid, m.{$usertable_userid} userid from cometchat_chatroommessages, {$usertable} m where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and m.{$usertable_userid} = cometchat_chatroommessages.userid and cometchat_chatroommessages.id > '" . mysql_real_escape_string($_POST['timestamp']) . "' order by cometchat_chatroommessages.id desc"; $reverse = 0; } $query = mysql_query($sql); while ($chat = mysql_fetch_array($query)) { if (function_exists('processName')) { $chat['from'] = processName($chat['from']); } if ($userid == $chat['userid']) { $chat['from'] = $chatrooms_language[6]; $chat['fromid'] = 0; } else { if (!empty($_COOKIE[$cookiePrefix . 'lang'])) { $translated = translate($chat['message'], '', $_COOKIE[$cookiePrefix . 'lang']); if ($translated != '') { $chat['message'] = strip_tags($translated) . ' <span class="untranslatedtext">(' . $chat['message'] . ')</span>'; } } } array_unshift($messages, array('id' => $chat['id'], 'from' => $chat['from'], 'fromid' => $chat['fromid'], 'message' => $chat['message'], 'sent' => $chat['sent'] + $_SESSION['cometchat']['timedifference'])); } } else { if ($_POST['timestamp'] == 0) { $comet = new Comet(KEY_A, KEY_B); $history = $comet->history(array('channel' => md5('chatroom_' . $_POST['currentroom'] . KEY_A . KEY_B . KEY_C), 'limit' => $lastMessages)); $moremessages = array(); if (!empty($history)) { foreach ($history as $message) { $moremessages[] = array("id" => $message['sent'] . rand(0, 1000000), "from" => $message['from'], "fromid" => "0", "message" => $message['message'], "old" => 1, 'sent' => $message['sent'] + $_SESSION['cometchat']['timedifference']); } $messages = array_merge($messages, $moremessages); usort($messages, 'comparetime'); } } } if (!empty($messages)) { $response['messages'] = $messages; } $sql = "select password from cometchat_chatrooms where id = '" . mysql_real_escape_string($_POST['currentroom']) . "' limit 1"; $query = mysql_query($sql); $room = mysql_fetch_array($query); if (!empty($room['password']) && (empty($_POST['currentp']) || $room['password'] != $_POST['currentp'])) { $response['users'] = array(); $response['messages'] = array(); } } header('Content-type: application/json; charset=utf-8'); echo json_encode($response); exit; }
function heartbeat() { global $response; global $userid; global $db; global $chatrooms_language; global $chatroomTimeout; global $lastMessages; global $cookiePrefix; global $allowAvatar; global $moderatorUserIDs; global $guestsMode, $crguestsMode, $guestnamePrefix; $usertable = TABLE_PREFIX . DB_USERTABLE; $usertable_username = DB_USERTABLE_NAME; $usertable_userid = DB_USERTABLE_USERID; $time = getTimeStamp(); $chatroomList = array(); $cachedChatrooms = array(); if (isset($_POST['popout']) && $_POST['popout'] == 0) { $_SESSION['cometchat']['cometchat_chatroomspopout'] = $time; } if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) { $sql = "insert into cometchat_chatrooms_users (userid,chatroomid,lastactivity,isbanned) values ('" . mysql_real_escape_string($userid) . "','" . mysql_real_escape_string($_POST['currentroom']) . "','" . mysql_real_escape_string($time) . "','0') on duplicate key update chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "', lastactivity = '" . mysql_real_escape_string($time) . "'"; $query = mysql_query($sql); } if (empty($_SESSION['cometchat']['cometchat_chatroomslist']) || !empty($_POST['force']) || !empty($_SESSION['cometchat']['cometchat_chatroomslist']) && $time - $_SESSION['cometchat']['cometchat_chatroomslist'] > REFRESH_BUDDYLIST) { if ($cachedChatrooms = getCache($cookiePrefix . 'chatroom_list', 30)) { $cachedChatrooms = unserialize($cachedChatrooms); } else { $sql = "select DISTINCT cometchat_chatrooms.id, cometchat_chatrooms.name, cometchat_chatrooms.type, cometchat_chatrooms.password, cometchat_chatrooms.lastactivity, cometchat_chatrooms.createdby, (SELECT count(userid) online FROM cometchat_chatrooms_users where cometchat_chatrooms_users.chatroomid = cometchat_chatrooms.id and '{$time}'-lastactivity<" . ONLINE_TIMEOUT . " and isbanned<>'1') online from cometchat_chatrooms order by name asc"; $query = mysql_query($sql); while ($chatroom = mysql_fetch_array($query)) { $cachedChatrooms[$chatroom['id']] = array('id' => $chatroom['id'], 'name' => $chatroom['name'], 'online' => $chatroom['online'], 'type' => $chatroom['type'], 'password' => $chatroom['password'], 'lastactivity' => $chatroom['lastactivity'], 'createdby' => $chatroom['createdby']); } setCache($cookiePrefix . 'chatroom_list', serialize($cachedChatrooms), 30); } foreach ($cachedChatrooms as $key => $chatroom) { if ($chatroom['createdby'] == 0 || $chatroom['createdby'] != 0 && $chatroom['type'] != 2 && $time - $chatroom['lastactivity'] < $chatroomTimeout || $chatroom['createdby'] == $userid) { $s = 0; if ($chatroom['createdby'] != $userid) { if (!in_array($userid, $moderatorUserIDs)) { $chatroom['password'] = ''; } else { $s = 2; } } else { $s = 1; } $chatroomList[$chatroom['id']] = array('id' => $chatroom['id'], 'name' => $chatroom['name'], 'online' => $chatroom['online'], 'type' => $chatroom['type'], 'i' => $chatroom['password'], 's' => $s); } } $_SESSION['cometchat']['cometchat_chatroomslist'] = $time; $clh = md5(serialize($chatroomList)); if (empty($_POST['clh']) || !empty($_POST['clh']) && $clh != $_POST['clh']) { if (!empty($chatroomList)) { $response['chatrooms'] = $chatroomList; } $response['clh'] = $clh; } } if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) { $users = array(); $messages = array(); if ($cachedUsers = getCache($cookiePrefix . 'chatrooms_users' . $_POST['currentroom'], 30)) { $users = unserialize($cachedUsers); } else { $sql = "select DISTINCT " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " userid, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " username, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_LASTACTIVITY . " lastactivity, " . DB_AVATARFIELD . " avatar, cometchat_chatrooms_users.isbanned from " . TABLE_PREFIX . DB_USERTABLE . " left join cometchat_status on " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = cometchat_status.userid inner join cometchat_chatrooms_users on " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = cometchat_chatrooms_users.userid " . DB_AVATARTABLE . " where chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and ('" . mysql_real_escape_string($time) . "' - cometchat_chatrooms_users.lastactivity < " . ONLINE_TIMEOUT . ") order by username asc"; if ($guestsMode && $crguestsMode) { $sql = getChatroomGuests($_POST['currentroom'], $time, $sql); } $query = mysql_query($sql); while ($chat = mysql_fetch_array($query)) { if (function_exists('processName')) { $chat['username'] = processName($chat['username']); } $avatar = ''; if ($allowAvatar) { $avatar = getAvatar($chat['avatar']); } $users[] = array('id' => $chat['userid'], 'n' => $chat['username'], 'a' => $avatar, 'b' => $chat['isbanned']); } setCache($cookiePrefix . 'chatrooms_users' . $_POST['currentroom'], serialize($users), 30); } $ulh = md5(serialize($users)); if (empty($_POST['ulh']) || !empty($_POST['ulh']) && $ulh != $_POST['ulh']) { $response['ulh'] = $ulh; if (!empty($users)) { $response['users'] = $users; } } if (USE_COMET != 1 || COMET_CHATROOMS != 1) { $limit = $lastMessages; if ($lastMessages == 0) { $limit = 1; } $guestpart = ""; $limitClause = " limit " . $limit . " "; $timestampCondition = ""; if ($_POST['timestamp'] != 0) { $timestampCondition = " and cometchat_chatroommessages.id > '" . mysql_real_escape_string($_POST['timestamp']) . "' "; $limitClause = ""; } if ($guestsMode && $crguestsMode) { $guestpart = " UNION select DISTINCT cometchat_chatroommessages.id id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, CONCAT('" . $guestnamePrefix . "-',m.name) `from`, cometchat_chatroommessages.userid fromid, m.id userid from cometchat_chatroommessages join cometchat_guests m on m.id = cometchat_chatroommessages.userid where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and cometchat_chatroommessages.message not like 'banned_%' and cometchat_chatroommessages.message not like 'kicked_%' " . $timestampCondition; } $sql = "select DISTINCT cometchat_chatroommessages.id id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, m.{$usertable_username} `from`, cometchat_chatroommessages.userid fromid, m.{$usertable_userid} userid from cometchat_chatroommessages join {$usertable} m on m.{$usertable_userid} = cometchat_chatroommessages.userid where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and cometchat_chatroommessages.message not like 'banned_%' and cometchat_chatroommessages.message not like 'kicked_%' " . $timestampCondition . $guestpart . " order by id desc " . $limitClause; $query = mysql_query($sql); while ($chat = mysql_fetch_array($query)) { if (function_exists('processName')) { $chat['from'] = processName($chat['from']); } if ($lastMessages == 0 && $_POST['timestamp'] == 0) { $chat['message'] = ''; } if ($userid == $chat['userid']) { $chat['from'] = $chatrooms_language[6]; } else { if (!empty($_COOKIE[$cookiePrefix . 'lang']) && !(strpos($chat['message'], "CC^CONTROL_") > -1)) { $translated = text_translate($chat['message'], '', $_COOKIE[$cookiePrefix . 'lang']); if ($translated != '') { $chat['message'] = strip_tags($translated) . ' <span class="untranslatedtext">(' . $chat['message'] . ')</span>'; } } } array_unshift($messages, array('id' => $chat['id'], 'from' => $chat['from'], 'fromid' => $chat['fromid'], 'message' => $chat['message'], 'sent' => $chat['sent'] + $_SESSION['cometchat']['timedifference'])); } } else { if ($_POST['timestamp'] == 0) { $comet = new Comet(KEY_A, KEY_B); $history = $comet->history(array('channel' => md5('chatroom_' . $_POST['currentroom'] . KEY_A . KEY_B . KEY_C), 'limit' => $lastMessages + 5)); $moremessages = array(); $count_msg = 0; $i = 0; if (!empty($history)) { foreach ($history as $message) { if (strpos($message['message'], 'CC^CONTROL_') > -1) { continue; } $moremessages[$message['sent']] = array("id" => $message['sent'], "from" => $message['from'], "fromid" => "0", "message" => $message['message'], "old" => 1, 'sent' => round($message['sent'] / 1000) + $_SESSION['cometchat']['timedifference']); } $messages = array_merge($messages, $moremessages); $count_msg = count($messages); usort($messages, 'comparetime'); $messages = $lastMessages > $count_msg ? $messages : array_slice($messages, -$lastMessages); } } } if (!empty($messages)) { $response['messages'] = $messages; } $sql = "select password from cometchat_chatrooms where id = '" . mysql_real_escape_string($_POST['currentroom']) . "' limit 1"; $query = mysql_query($sql); $room = mysql_fetch_array($query); if (!empty($room['password']) && (empty($_POST['currentp']) || $room['password'] != $_POST['currentp'])) { $response['users'] = array(); $response['messages'] = array(); } } header('Content-type: application/json; charset=utf-8'); echo json_encode($response); }
function getChatboxData($id) { global $messages; global $userid; if (!empty($id) && USE_COMET == 1) { if (!empty($_SESSION['cometchat']['cometmessagesafter'])) { $key = KEY_A . KEY_B . KEY_C; $channel = md5($userid . $key); if (function_exists('mcrypt_encrypt')) { $channel = md5(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $userid, MCRYPT_MODE_CBC, md5(md5($key)))) . $key); } $comet = new Comet(KEY_A, KEY_B); $history = $comet->history(array('channel' => $channel, 'limit' => COMET_HISTORY_LIMIT)); if (!empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_merge($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } $moremessages = array(); $messagesafter = $_SESSION['cometchat']['cometmessagesafter']; if (!empty($_SESSION['cometchat']['cometchat_user_' . $id . '_clear']) && $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp'] > $_SESSION['cometchat']['cometmessagesafter']) { $messagesafter = $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp']; } if (!empty($history)) { foreach ($history as $key => $message) { if ($message['from'] == $id && $message['sent'] >= $messagesafter) { $moremessages['_' . $message['sent']] = array("id" => $message['sent'], "from" => $message['from'], "message" => $message['message'], "self" => $message['self'], "old" => 1, 'sent' => $message['sent'] / 1000); } } } $messages = array_merge($messages, $moremessages); usort($messages, 'comparetime'); } } else { if (!empty($id) && !empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_merge($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } } }
function getChatboxData($id) { global $messages; global $userid; if (!empty($id) && USE_COMET == 1) { if (!empty($_SESSION['cometchat']['cometmessagesafter'])) { $comet = new Comet(KEY_A, KEY_B); $history = $comet->history(array('channel' => md5($userid . KEY_A . KEY_B . KEY_C), 'limit' => COMET_HISTORY_LIMIT)); if (!empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_merge($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } $moremessages = array(); $messagesafter = $_SESSION['cometchat']['cometmessagesafter']; if (!empty($_SESSION['cometchat']['cometchat_user_' . $id . '_clear']) && $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp'] > $_SESSION['cometchat']['cometmessagesafter']) { $messagesafter = $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp']; } if (!empty($history)) { foreach ($history as $message) { if ($message['from'] == $id && $message['sent'] >= $messagesafter) { $moremessages[] = array("id" => $message['sent'] . rand(0, 1000000), "from" => $message['from'], "message" => $message['message'], "self" => $message['self'], "old" => 1, 'sent' => $message['sent'] + $_SESSION['cometchat']['timedifference']); } } } $messages = array_merge($messages, $moremessages); usort($messages, 'comparetime'); } } else { if (!empty($id) && !empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_merge($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } } }
function getChatboxData($id) { global $messages; global $userid; global $chromeReorderFix; global $prependLimit; if (empty($_REQUEST['prepend'])) { if (USE_COMET == 1) { if (!empty($_SESSION['cometchat']['cometmessagesafter']) || empty($id)) { $key = ''; if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) { $key = KEY_A . KEY_B . KEY_C; } $limit = COMET_HISTORY_LIMIT; if (!empty($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') { $limit = 10; } $channel = md5($userid . $key); $comet = new Comet(KEY_A, KEY_B); $history = $comet->history(array('channel' => $channel, 'limit' => $limit)); if (!empty($id) && !empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_replace($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } $moremessages = array(); if (!empty($_SESSION['cometchat']['cometmessagesafter'])) { $messagesafter = $_SESSION['cometchat']['cometmessagesafter']; } if (!empty($_SESSION['cometchat']['cometchat_user_' . $id . '_clear']) && $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp'] > $_SESSION['cometchat']['cometmessagesafter']) { $messagesafter = $_SESSION['cometchat']['cometchat_user_' . $id . '_clear']['timestamp']; } if (!empty($history)) { foreach ($history as $key => $message) { if ($message['from'] == $id && $message['sent'] >= $messagesafter || empty($id)) { $moremessages[$chromeReorderFix . $message['sent']] = array("id" => $message['sent'], "from" => $message['from'], "message" => $message['message'], "self" => $message['self'], "old" => 1, 'sent' => $message['sent'] / 1000); } } } if (!empty($id) && empty($_SESSION['cometchat']['cometchat_user_' . $id])) { getPrevMessages($id); } if (!empty($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') { $messages = $moremessages; } else { $messages = array_replace($messages, $moremessages); usort($messages, 'comparetime'); } } } else { if (!empty($id) && !empty($_SESSION['cometchat']['cometchat_user_' . $id])) { $messages = array_replace($messages, $_SESSION['cometchat']['cometchat_user_' . $id]); } if (!empty($id) && empty($_SESSION['cometchat']['cometchat_user_' . $id])) { getPrevMessages($id); $messages = array_reverse($messages); } } } else { if (USE_COMET == 1 && SAVE_LOGS == 0) { return; } $prelimit = intval($prependLimit); $messages = array(); if ($_REQUEST['prepend'] != '-1') { $prepend = bigintval($_REQUEST['prepend']); $sql = "select * from cometchat where ((cometchat.from = " . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . " and cometchat.to = " . $id . " and direction <>1) or ( cometchat.from = " . mysqli_real_escape_string($GLOBALS['dbh'], $id) . " and cometchat.to = " . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . " and direction <> 2)) and (cometchat.id < {$prepend}) order by cometchat.id desc limit {$prelimit};"; } else { $sql = "select * from cometchat where ((cometchat.from = " . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . " and cometchat.to = " . mysqli_real_escape_string($GLOBALS['dbh'], $id) . " and direction <>1) or ( cometchat.from = " . mysqli_real_escape_string($GLOBALS['dbh'], $id) . " and cometchat.to = " . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . " and direction <>2 )) order by cometchat.id desc limit {$prelimit};"; } $query = mysqli_query($GLOBALS['dbh'], $sql); if (defined('DEV_MODE') && DEV_MODE == '1') { echo mysqli_error($GLOBALS['dbh']); } while ($chat = mysqli_fetch_assoc($query)) { $self = 0; $old = 0; if ($chat['from'] == $userid) { $chat['from'] = $chat['to']; $self = 1; $old = 1; } if ($chat['read'] == 1) { $old = 1; } $messages[$chromeReorderFix . $chat['id']] = array('id' => $chat['id'], 'from' => $chat['from'], 'message' => $chat['message'], 'self' => $self, 'old' => $old, 'sent' => $chat['sent']); } $messages = array_reverse($messages); } }