1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?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 WHERE id NOT IN (SELECT id FROM file_bans)');
$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
WHERE f.id NOT IN (SELECT id FROM file_bans)
ORDER BY f.uploaded_at DESC
LIMIT $limit OFFSET $offset
");
$stmt->execute();
$files = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<title>File Catalogue (Page <?= $page + 1 ?>/<?= $max_pages ?>) - <?= 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 ?>">← Previous page</a>
<?php endif; ?>
<?php if ($page + 2 <= $max_pages): ?>
<a href="/catalogue.php?p=<?= $page + 2 ?>" style="margin-left:auto">→ 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>
|