diff options
Diffstat (limited to 'web/index.php')
| -rw-r--r-- | web/index.php | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/web/index.php b/web/index.php index b71e61b..b6657c5 100644 --- a/web/index.php +++ b/web/index.php @@ -4,8 +4,52 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; $db = new PDO(DB_URL, DB_USER, DB_PASS); $room = $_GET['r'] ?: null; +$date = $_GET['d'] ?: null; -if (isset($room)) { +$limit = min(abs(intval($_GET['l'] ?? '500')), 500); +$page = abs(intval($_GET['p'] ?? '1') - 1); +$offset = $limit * $page; + +if (isset($room, $date)) { + $room = urldecode($room); + $date = urldecode($date); + $stmt = $db->prepare('SELECT id, `name`, joined_at, departed_at FROM rooms WHERE `name` = ?'); + $stmt->execute([$room]); + + $room = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; + if (!$room) { + http_response_code(404); + exit("No room found."); + } + $room['encoded'] = urlencode($room['name']); + + $stmt = $db->prepare("SELECT m.id, u.nick, m.command, m.params, m.tags, m.sent_at + FROM messages m + JOIN rooms r ON r.id = m.room_id + JOIN users u ON u.id = m.user_id + WHERE m.room_id = ? + AND m.sent_at BETWEEN ? AND DATE_ADD(?, INTERVAL 1 DAY) + ORDER BY sent_at DESC + LIMIT $limit OFFSET $offset + "); + $stmt->execute([$room['id'], $date, $date]); + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // searching for previous message day + $stmt = $db->prepare('SELECT m.sent_at AS d + FROM messages m + JOIN rooms r ON r.id = m.room_id + JOIN users u ON u.id = m.user_id + WHERE m.room_id = ? + AND DATE(m.sent_at) = ( + SELECT MAX(DATE(sent_at)) + FROM messages + WHERE DATE(sent_at) < ? + ) + '); + $stmt->execute([$room['id'], $date]); + $previous_day = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; +} else if (isset($room)) { $room = urldecode($room); $stmt = $db->prepare('SELECT id, `name`, joined_at, departed_at FROM rooms WHERE `name` = ?'); $stmt->execute([$room]); @@ -56,7 +100,9 @@ if (isset($room)) { <html> <head> - <?php if (isset($room)): ?> + <?php if (isset($room, $date)): ?> + <title><?= sprintf('Log for %s, %s - %s', $room['name'], $date, INSTANCE_NAME) ?></title> + <?php elseif (isset($room)): ?> <title><?= $room['name'] ?> - <?= INSTANCE_NAME ?></title> <?php else: ?> <title>Index - <?= INSTANCE_NAME ?></title> @@ -66,7 +112,30 @@ if (isset($room)) { </head> <body> - <?php if (isset($room)): ?> + <?php if (isset($room, $date)): ?> + <h1><?= sprintf('Log for %s, %s', $room['name'], $date) ?></h1> + <?php if (empty($messages)): ?> + <p>No messages.</p> + <?php else: ?> + <p>Showing <?= count($messages) ?> messages on Page <?= $page + 1 ?></p> + <table> + <tr> + <th>Time</th> + <th>Nick</th> + <th>Message</th> + </tr> + <?php foreach ($messages as $m): ?> + <tr class="message" data-irc-tags="<?= $m['tags'] ?>" id="msgid=<?= $m['id'] ?>"> + <td class="datetime"><a + href="/?r=<?= urlencode($room['name']) ?>&d=<?= urlencode($date) ?>#msgid=<?= $m['id'] ?>"><?= date('H:i', strtotime($m['sent_at'])) ?></a> + </td> + <td class="nick"><?= $m['nick'] ?></td> + <td class="content"><?= $m['params'] ?></td> + </tr> + <?php endforeach; ?> + </table> + <?php endif; ?> + <?php elseif (isset($room)): ?> <h1><a href="/"><?= INSTANCE_NAME ?></a> - Index of <?= $room['name'] ?></h1> <div class="calendar-wrapper"> <?php foreach ($dates as $year => $months): ?> @@ -135,4 +204,22 @@ if (isset($room)) { <?php endif; ?> </body> +<?php if (isset($room, $date)): ?> + <script> + const messages = document.querySelectorAll(".message"); + for (const m of messages) { + let tags = m.getAttribute("data-irc-tags"); + + const nickElement = m.querySelector(".nick"); + + for (const tag of tags.split(";")) { + const p = tag.split("="); + if (p[0] == "color") { + nickElement.style.color = p[1]; + } + } + } + </script> +<?php endif; ?> + </html>
\ No newline at end of file |
