/** * Render the div full of chat messages. * @param $chatlength Essentially the limit on the number of messages. **/ function render_chat_messages($chatlength, $show_elipsis = null) { // Eventually there might be a reason to abstract out get_chats(); $sql = new DBAccess(); $sql->Query("SELECT sender_id, uname, message, age(now(), date) as ago FROM chat join players on chat.sender_id = player_id ORDER BY chat_id DESC LIMIT {$chatlength}"); // Pull messages $chats = $sql->fetchAll(); $message_rows = ''; $messageCount = $sql->QueryItem("select count(*) from chat"); if (!isset($show_elipsis) && $messageCount > $chatlength) { $show_elipsis = true; } $res = "<div class='chatMessages'>"; $previous_date = null; $skip_interval = 3; // minutes foreach ($chats as $messageData) { $l_ago = time_ago($messageData['ago'], $previous_date); $message_rows .= "<li><<a href='player.php?player_id={$messageData['sender_id']}'\n\t\t target='main'>{$messageData['uname']}</a>> " . out($messageData['message']) . " <span class='chat-time'>{$l_ago}</span></li>"; $previous_date = $messageData['ago']; // Store just prior date. } $res .= $message_rows; if ($show_elipsis) { // to indicate there are more chats available $res .= ".<br>.<br>.<br>"; } $res .= "</div>"; return $res; }