public function chatHeartbeat() { $m = new PrivateChatModel(); $chat = $m->GetFromChat($this->player->playerId); $items = ""; $chatBoxes = array(); while ($chat->next()) { if (!isset($_SESSION['openChatBoxes'][$chat->row['from']]) && isset($_SESSION['chatHistory'][$chat->row['from']])) { } $chat->row['message'] = $this->sanitize($chat->row['message']); $items .= "\t\t\t\t\t\t {\r\n\t\t\t\t\"s\": \"0\",\r\n\t\t\t\t\"f\": \"{$chat->row['from']}\",\r\n\t\t\t\t\"img\": \"{$chat->row['from_img']}\",\r\n\t\t\t\t\"id\": \"{$chat->row['from_id']}\",\r\n\t\t\t\t\"m\": \"{$chat->row['message']}\"\r\n\t\t },"; if (!isset($_SESSION['chatHistory'][$chat->row['from']])) { $_SESSION['chatHistory'][$chat->row['from']] = ""; } $_SESSION['chatHistory'][$chat->row['from']] .= "\t\t\t\t\t\t\t {\r\n\t\t\t\t\"s\": \"0\",\r\n\t\t\t\t\"f\": \"{$chat->row['from']}\",\r\n\t\t\t\t\"img\": \"{$chat->row['from_img']}\",\r\n\t\t\t\t\"id\": \"{$chat->row['from_id']}\",\r\n\t\t\t\t\"m\": \"{$chat->row['message']}\"\r\n\t\t },"; unset($this->tsChatBoxes[$chat->row['from']]); $_SESSION['openChatBoxes'][$chat->row['from']] = $chat->row['sent']; } $m->dispose(); if (!empty($_SESSION['openChatBoxes'])) { foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) { if (!isset($_SESSION['tsChatBoxes'][$chatbox])) { $now = time() - strtotime($time); $time = date("g:iA M dS", strtotime($time)); $message = "Sent at {$time}"; if (180 < $now) { $items .= "\t{\r\n\t\"s\": \"2\",\r\n\t\"f\": \"{$chatbox}\",\r\n\t\"img\": \"{$chat->row[$chatbox . "_img"]}\",\r\n\t\"id\": \"{$chat->row[$chatbox . "_id"]}\",\r\n\t\"m\": \"{$message}\"\r\n\t},"; if (!isset($_SESSION['chatHistory'][$chatbox])) { $_SESSION['chatHistory'][$chatbox] = ""; } $_SESSION['chatHistory'][$chatbox] .= "\t\t\t{\r\n\t\"s\": \"2\",\r\n\t\"f\": \"{$chatbox}\",\r\n\t\"img\": \"{$chat->row[$chatbox . "_img"]}\",\r\n\t\"id\": \"{$chat->row[$chatbox . "_id"]}\",\r\n\t\"m\": \"{$message}\"\r\n\t},"; $_SESSION['tsChatBoxes'][$chatbox] = 1; } } } } if ($items != "") { $items = substr($items, 0, 0 - 1); } header("Content-type: application/json"); echo "\t{\r\n\t\t\t\"items\": [\r\n\t\t\t\t"; echo $items; echo "\t\t\t]\r\n\t}\r\n\t\r\n\t"; exit(0); }
function chatHeartbeat() { $m = new PrivateChatModel(); $chat = $m->GetFromChat($this->player->playerId); $items = ''; $chatBoxes = array(); while ($chat->next()) { if (!isset($_SESSION['openChatBoxes'][$chat->row['from']]) && isset($_SESSION['chatHistory'][$chat->row['from']])) { } $chat->row['message'] = $this->sanitize($chat->row['message']); $items .= '' . ' { "s": "0", "f": "' . $chat->row['from'] . '", "img": "' . $chat->row['from_img'] . '", "id": "' . $chat->row['from_id'] . '", "m": "' . $chat->row['message'] . '" },'; if (!isset($_SESSION['chatHistory'][$chat->row['from']])) { $_SESSION['chatHistory'][$chat->row['from']] = ''; } $_SESSION['chatHistory']->{$chat}->row['from'] .= '' . ' { "s": "0", "f": "' . $chat->row['from'] . '", "img": "' . $chat->row['from_img'] . '", "id": "' . $chat->row['from_id'] . '", "m": "' . $chat->row['message'] . '" },'; unset($_SESSION['tsChatBoxes'][$chat->row['from']]); $_SESSION['openChatBoxes'][$chat->row['from']] = $chat->row['sent']; } $m->dispose(); if (!empty($_SESSION['openChatBoxes'])) { foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) { if (!isset($_SESSION['tsChatBoxes'][$chatbox])) { $now = time() - strtotime($time); $time = date('g:iA M dS', strtotime($time)); $message = '' . 'Sent at ' . $time; if (180 < $now) { $items .= '' . ' { "s": "2", "f": "' . $chatbox . '", "img": "' . $chat->row[$chatbox . '_img'] . '", "id": "' . $chat->row[$chatbox . '_id'] . '", "m": "' . $message . '" },'; if (!isset($_SESSION['chatHistory'][$chatbox])) { $_SESSION['chatHistory'][$chatbox] = ''; } $_SESSION['chatHistory']->{$chatbox} .= '' . ' { "s": "2", "f": "' . $chatbox . '", "img": "' . $chat->row[$chatbox . '_img'] . '", "id": "' . $chat->row[$chatbox . '_id'] . '", "m": "' . $message . '" },'; $_SESSION['tsChatBoxes'][$chatbox] = 1; continue; } continue; } } } if ($items != '') { $items = substr($items, 0, 0 - 1); } header('Content-type: application/json'); echo ' { "items": [ '; echo $items; echo ' ] } '; exit(0); }