summaryrefslogtreecommitdiff
path: root/web/index.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-10-14 15:36:31 +0500
committerilotterytea <iltsu@alright.party>2025-10-14 15:36:31 +0500
commit33fd114a314212b8759b525fb9e08d4ff4ca8869 (patch)
tree7abbb155a7515148f355b30978e3a0fa77913fd1 /web/index.php
parentd6196a61348dbd0040e332147ef4a34ade64b309 (diff)
feat: web frontend
Diffstat (limited to 'web/index.php')
-rw-r--r--web/index.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/web/index.php b/web/index.php
new file mode 100644
index 0000000..88c9711
--- /dev/null
+++ b/web/index.php
@@ -0,0 +1,103 @@
+<?php
+include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/partials.php';
+
+$db = new PDO(DB_URL, DB_USER, DB_PASS);
+
+$channel = $_GET['c'] ?? null;
+$user = $_GET['u'] ?? null;
+
+if (isset($channel, $user)) {
+ $stmt = $db->prepare('SELECT w.name, SUM(cw.usage_count) AS usage_count
+ FROM channel_words cw
+ INNER JOIN words w ON w.id = cw.word_id
+ INNER JOIN channels c ON c.alias_name = ?
+ INNER JOIN users u ON u.alias_name = ?
+ WHERE cw.channel_id = c.id AND cw.user_id = u.id
+ GROUP BY cw.word_id
+ ORDER BY usage_count DESC
+ LIMIT 100
+ ');
+ $stmt->execute([$channel, $user]);
+} else if (isset($channel)) {
+ $stmt = $db->prepare('SELECT w.name, SUM(cw.usage_count) AS usage_count
+ FROM channel_words cw
+ INNER JOIN words w ON w.id = cw.word_id
+ INNER JOIN channels c ON c.alias_name = ?
+ WHERE cw.channel_id = c.id
+ GROUP BY cw.word_id
+ ORDER BY usage_count DESC
+ LIMIT 100
+ ');
+ $stmt->execute([$channel]);
+} else if (isset($user)) {
+ $stmt = $db->prepare('SELECT w.name, SUM(cw.usage_count) AS usage_count
+ FROM channel_words cw
+ INNER JOIN words w ON w.id = cw.word_id
+ INNER JOIN users u ON u.alias_name = ?
+ WHERE cw.user_id = u.id
+ GROUP BY cw.word_id
+ ORDER BY usage_count DESC
+ LIMIT 100
+ ');
+ $stmt->execute([$user]);
+} else {
+ $stmt = $db->prepare('SELECT w.name, SUM(cw.usage_count) AS usage_count
+ FROM channel_words cw
+ INNER JOIN words w ON w.id = cw.word_id
+ GROUP BY cw.word_id
+ ORDER BY usage_count DESC
+ LIMIT 100
+ ');
+ $stmt->execute();
+}
+
+$words = $stmt->fetchAll(PDO::FETCH_ASSOC);
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title><?= INSTANCE_NAME ?></title>
+ <link rel="stylesheet" href="/static/style.css">
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
+</head>
+
+<body>
+ <?php html_header(); ?>
+ <main class="row gap-8">
+ <form action="/" method="get">
+ <div class="box">
+ <div class="tab">Search</div>
+ <div class="content">
+ <input type="text" name="c" placeholder="Enter Twitch channel..." value="<?= $channel ?>">
+ <input type="text" name="u" placeholder="Enter Twitch user..." value="<?= $user ?>">
+ <button type="submit">Search</button>
+ </div>
+ </div>
+ </form>
+ <section class="column gap-8 grow">
+ <div class="scoreboard-showcase">
+ <div class="box">
+ <p class="tab">
+ <img src="/static/img/icons/word.png" alt=""> Words
+ </p>
+ <div class="content scoreboard">
+ <?php if (empty($words)): ?>
+ <p><i>No words.</i></p>
+ <?php endif; ?>
+ <?php foreach ($words as $i => $word): ?>
+ <div class="scoreboard-item">
+ <p class="scoreboard-place"><?= $i + 1 ?>.</p>
+ <p class="scoreboard-name"><?= $word['name'] ?></p>
+ <p class="scoreboard-counter"><?= $word['usage_count'] ?></p>
+ </div>
+ <?php endforeach; ?>
+ </div>
+ </div>
+ </div>
+ </section>
+ </main>
+</body>
+
+</html> \ No newline at end of file