select('message')
->where('user_id', $userId)
->orderByDesc('chat_id')
->limit(1)
->first();
if (!$last || ($last->message ?? '') !== $tekst) {
DB::table('chat')->insert([
'time' => now(),
'sender' => $username,
'user_id' => $userId,
'message' => $tekst,
]);
}
}
public function UpdateChatFile($chat_file, $num_rows)
{
$output = "
";
$chats = DB::table('chat')
->select('time', 'sender', 'message')
->orderByDesc('chat_id')
->limit((int)$num_rows ?: 8)
->get();
$x = 0;
foreach ($chats as $chat) {
$x++;
$add = ($x % 2 === 0) ? ' class="odd" ' : '';
$datetime = date("F jS @ H:i", strtotime($chat->time));
$message = wordwrap($chat->message, 20, " ", true);
$ime = wordwrap($chat->sender, 12, " ", true);
$output .= '- <';
$output .= '';
$output .= htmlspecialchars($ime, ENT_QUOTES, 'UTF-8');
$output .= '> ';
$output .= htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
$output .= '
';
}
$output .= '
';
@file_put_contents(base_path($chat_file), $output);
}
public function ShowOnline()
{
echo 'Loading...
';
}
public function ShowChat($num_rows = 10, $username = null)
{
echo 'Loading...
';
echo '';
if (!empty($_SESSION['web_login']['status'])) {
echo '
';
} else {
echo '
You should be logged in to join a chat!
';
}
echo '
';
}
}