summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/index.php93
-rw-r--r--web/static/style.css44
2 files changed, 123 insertions, 14 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
diff --git a/web/static/style.css b/web/static/style.css
index 47bf506..a84bdc6 100644
--- a/web/static/style.css
+++ b/web/static/style.css
@@ -1,6 +1,7 @@
:root {
--primary-color: #e2e9d9;
- --calendar-border: black;
+ --table-border: #a8a8a8;
+ --message-alt-background: #eeeeee;
}
* {
@@ -8,6 +9,10 @@
padding: 0;
}
+body {
+ padding: 8px;
+}
+
.calendar-wrapper {
display: flex;
flex-direction: row;
@@ -15,31 +20,48 @@
gap: 16px;
}
-.calendar {
- border: var(--calendar-border) solid 1px;
+table {
+ border: var(--table-border) solid 1px;
border-spacing: 0;
}
-.calendar>caption {
- border: var(--calendar-border) solid 1px;
+table caption {
+ border: var(--table-border) solid 1px;
border-bottom: none;
background: var(--primary-color);
}
-.calendar td,
-.calendar th {
- border: var(--calendar-border) solid 1px;
+table td,
+table th {
+ border: var(--table-border) solid 1px;
border-left: unset;
border-top: unset;
padding: 2px;
+}
+
+table.calendar td,
+table.calendar th {
text-align: center;
}
-.calendar td:last-child,
-.calendar th:last-child {
+table td:last-child,
+table th:last-child {
border-right: unset;
}
-.calendar tr:last-child td {
+table tr:last-child td {
border-bottom: unset;
+}
+
+.message {
+ font-size: 16px;
+ font-family: monospace;
+}
+
+.message:nth-child(even) {
+ background: var(--message-alt-background);
+}
+
+.message .nick {
+ text-align: right;
} \ No newline at end of file