summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-08-05 19:07:23 +0500
committerilotterytea <iltsu@alright.party>2025-08-05 19:07:23 +0500
commitf249d69ea8359e54e70ff6e6ab26ab8e290fd740 (patch)
treedb8f21ae670552e58bcd0dbb02435183c2eaa71d
parent11e99a15810e6f66ce3e78232f026c08a0177b61 (diff)
feat: search by messages
-rw-r--r--web/index.php48
1 files changed, 36 insertions, 12 deletions
diff --git a/web/index.php b/web/index.php
index 78312d3..4a18320 100644
--- a/web/index.php
+++ b/web/index.php
@@ -6,6 +6,7 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS);
$room = $_GET['r'] ?: null;
$user = $_GET['u'] ?: null;
$date = $_GET['d'] ?: null;
+$message_query = $_GET['m'] ?: null;
$limit = min(abs(intval($_GET['l'] ?? '500')), 500);
$page = abs(intval($_GET['p'] ?? '1') - 1);
@@ -35,7 +36,24 @@ if (isset($room)) {
$room['encoded'] = urlencode($room['name']);
}
-if (isset($date)) {
+if (isset($message_query)) {
+ $user_id = $user ? $user['id'] : "m.user_id";
+ $room_id = $room ? $room['id'] : "m.room_id";
+ $room_column = !$room ? ", r.name AS room" : "";
+ $command = "PRIVMSG";
+
+ $stmt = $db->prepare("SELECT m.id, u.nick, m.command, m.params, m.tags, m.sent_at $room_column
+ 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 = $room_id AND m.user_id = $user_id
+ AND m.params LIKE ? AND m.command = ?
+ ORDER BY sent_at DESC
+ LIMIT $limit OFFSET $offset
+ ");
+ $stmt->execute([$message_query, $command]);
+ $messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
+} else if (isset($date)) {
$user_id = $user ? $user['id'] : "m.user_id";
$room_id = $room ? $room['id'] : "m.room_id";
$room_column = !$room ? ", r.name AS room" : "";
@@ -82,7 +100,21 @@ if (isset($date)) {
}
}
-$page_title = (isset($user) ? ($user['nick'] . (isset($room) ? ' in ' : '')) : '') . (isset($room) ? "{$room['name']}" : '');
+$page_title = match (true) {
+ isset($user, $room, $message_query) => "Searching for '$message_query' by {$user['nick']} in {$room['name']}",
+ isset($user, $message_query) => "Searching for '$message_query' by {$user['nick']}",
+ isset($room, $message_query) => "Searching for '$message_query' in {$room['name']}",
+ isset($message_query) => "Searching for '$message_query'",
+ isset($user, $room) => "{$user['nick']}'s logs in {$room['name']}",
+ isset($room) => "Logs of {$room['name']}",
+ isset($user) => "{$user['nick']}'s logs",
+ default => "Index"
+};
+
+if (isset($date)) {
+ $page_title .= ", $date";
+}
+
$link = match (true) {
isset($user, $room) => "r={$room['encoded']}&u={$user['nick']}",
isset($user) => "u={$user['nick']}",
@@ -100,20 +132,14 @@ if (!isset($user) && !isset($room)) {
<html>
<head>
- <?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>
- <?php endif; ?>
+ <title><?= "$page_title - " . INSTANCE_NAME ?></title>
<link rel="stylesheet" href="/static/style.css">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
+ <h1><a href="/"><?= INSTANCE_NAME ?></a> - <?= $page_title ?></h1>
<?php if (isset($messages)): ?>
- <h1><?= sprintf('Log for %s, %s', $page_title, $date) ?></h1>
<?php if (empty($messages)): ?>
<p>No messages.</p>
<?php else: ?>
@@ -145,7 +171,6 @@ if (!isset($user) && !isset($room)) {
</table>
<?php endif; ?>
<?php elseif (isset($dates)): ?>
- <h1><a href="/"><?= INSTANCE_NAME ?></a> - Index of <?= $page_title ?></h1>
<div class="calendar-wrapper">
<?php foreach ($dates as $year => $months): ?>
<?php foreach ($months as $month => $days): ?>
@@ -193,7 +218,6 @@ if (!isset($user) && !isset($room)) {
<?php endforeach; ?>
</div>
<?php elseif (isset($rooms)): ?>
- <h1>Index of <?= INSTANCE_NAME ?></h1>
<?php if (empty($rooms)): ?>
<p>There are no rooms. <a href="/mod/">Add one!</a></p>
<?php else: ?>