summaryrefslogtreecommitdiff
path: root/public/catalogue.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-18 13:34:08 +0500
committerilotterytea <iltsu@alright.party>2025-06-18 13:34:08 +0500
commit01b4d8ac76a2a6a7ee57dd173f3894022977d2cb (patch)
treefa35eb8093b12aa18030d834ceabeccabaedae1f /public/catalogue.php
parent1a97ab8f9fbaf93ba100ea22533ba48f524821bf (diff)
feat: file catalogue
Diffstat (limited to 'public/catalogue.php')
-rw-r--r--public/catalogue.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/public/catalogue.php b/public/catalogue.php
new file mode 100644
index 0000000..756675a
--- /dev/null
+++ b/public/catalogue.php
@@ -0,0 +1,83 @@
+<?php
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/alert.php';
+
+session_start();
+
+if (!isset($_SESSION['is_moderator']) && !FILE_CATALOG_PUBLIC) {
+ http_response_code(403);
+ exit;
+}
+
+$db = new PDO(DB_URL, DB_USER, DB_PASS);
+
+$page = max(intval($_GET['p'] ?? '1') - 1, 0);
+$limit = 20;
+
+// counting max pages
+$stmt = $db->query('SELECT COUNT(id) AS all_files FROM files');
+$stmt->execute();
+
+$max_pages = ceil(($stmt->fetch(PDO::FETCH_ASSOC)['all_files'] ?: 0) / $limit);
+$page = min($page, $max_pages - 1);
+
+// getting files
+$offset = $page * $limit;
+
+$stmt = $db->query("SELECT f.id, f.mime, f.extension
+ FROM files f
+ ORDER BY f.uploaded_at DESC
+ LIMIT $limit OFFSET $offset
+");
+$stmt->execute();
+
+$files = $stmt->fetchAll();
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title>File Catalogue &lpar;Page <?= $page + 1 ?>/<?= $max_pages ?>&rpar; - <?= INSTANCE_NAME ?></title>
+ <link rel="stylesheet" href="/static/style.css">
+ <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
+</head>
+
+<body>
+ <main>
+ <?php html_mini_navbar('Page ' . ($page + 1) . '/' . $max_pages) ?>
+
+ <section class="row align-center">
+ <?php if ($page - 1 >= 0): ?>
+ <a href="/catalogue.php?p=<?= $page ?>">&larr; Previous page</a>
+ <?php endif; ?>
+ <?php if ($page + 2 <= $max_pages): ?>
+ <a href="/catalogue.php?p=<?= $page + 2 ?>" style="margin-left:auto">&rarr; Next page</a>
+ <?php endif; ?>
+ </section>
+
+ <section class="wall">
+ <?php foreach ($files as $file): ?>
+ <div class="brick">
+ <a href="/<?= sprintf('%s.%s', $file['id'], $file['extension']) ?>">
+ <i>
+ <?php if (str_starts_with($file['mime'], 'image/') || str_starts_with($file['mime'], 'video/')): ?>
+ <img src="<?= sprintf('%s/%s.webp', FILE_THUMBNAIL_DIRECTORY_PREFIX, $file['id']) ?>"
+ alt="No thumbnail.">
+ <?php elseif (str_starts_with($file['mime'], 'audio/')): ?>
+ <img src="/static/img/icons/file_audio.png" alt="No thumbnail.">
+ <?php elseif (str_starts_with($file['mime'], 'text/')): ?>
+ <img src="/static/img/icons/file_text.png" alt="No thumbnail.">
+ <?php else: ?>
+ <img src="/static/img/icons/file.png" alt="No thumbnail.">
+ <?php endif; ?>
+ </i>
+ </a>
+ </div>
+ <?php endforeach; ?>
+ </section>
+ </main>
+</body>
+
+</html> \ No newline at end of file