diff options
| -rw-r--r-- | lib/partials.php | 19 | ||||
| -rw-r--r-- | public/catalogue.php | 83 | ||||
| -rw-r--r-- | public/mod.php | 86 | ||||
| -rw-r--r-- | public/static/style.css | 21 |
4 files changed, 125 insertions, 84 deletions
diff --git a/lib/partials.php b/lib/partials.php index 6c69c62..24e6e70 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -15,6 +15,11 @@ function html_big_navbar() <a href="/"> <button>Home</button> </a> + <?php if (FILE_CATALOG_PUBLIC || isset($_SESSION['is_moderator'])): ?> + <a href="/catalogue.php"> + <button>Catalogue</button> + </a> + <?php endif; ?> <?php if (FILE_CATALOG_RANDOM): ?> <a href="/?random"> <button>I'm Feeling Lucky</button> @@ -33,19 +38,29 @@ function html_big_navbar() <?php ; } -function html_mini_navbar() +function html_mini_navbar(string|null $subtitle = null) { echo '' ?> <section class="row align-center gap-8 navbar"> <a href="/" class="row gap-8 align-bottom" style="text-decoration:none;color:inherit;"> <img src="/static/img/brand/mini.webp" alt=""> - <h2><?= INSTANCE_NAME ?></h2> + <div class="column"> + <?php if ($subtitle): ?> + <p class="font-small"><?= $subtitle ?></p> + <?php endif; ?> + <h2><?= INSTANCE_NAME ?></h2> + </div> </a> <div class="row gap-8 align-bottom" style="height: 100%"> <a href="/"> <button>Home</button> </a> + <?php if (FILE_CATALOG_PUBLIC || isset($_SESSION['is_moderator'])): ?> + <a href="/catalogue.php"> + <button>Catalogue</button> + </a> + <?php endif; ?> <?php if (FILE_CATALOG_RANDOM): ?> <a href="/?random"> <button>I'm Feeling Lucky</button> 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 (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>
\ No newline at end of file diff --git a/public/mod.php b/public/mod.php index 2d45e76..de789ce 100644 --- a/public/mod.php +++ b/public/mod.php @@ -6,6 +6,8 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/alert.php'; session_start(); +$db = new PDO(DB_URL, DB_USER, DB_PASS); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['password'])) { generate_alert('/mod.php', 'No password set!', 400, null); @@ -38,34 +40,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { generate_alert('/mod.php', 'Authorized!', 200, null); exit(); } - -$files = []; - -$page = intval($_GET['fp'] ?? '1'); -$max_pages = 0; - -if (isset($_SESSION['is_moderator'])) { - $quantity = 10; - - $filelist = glob(FILE_UPLOAD_DIRECTORY . '/*.*'); - usort($filelist, function ($a, $b) { - return filemtime($b) - filemtime($a); - }); - - $selected_files = array_slice($filelist, ($page - 1) * $quantity, $quantity); - - $max_pages = ceil(count($filelist) / $quantity); - - foreach ($selected_files as $f) { - $name = basename($f); - $id = explode('.', $name); - array_push($files, [ - 'name' => $name, - 'id' => $id[0], - 'extension' => $id[1] - ]); - } -} ?> <html> @@ -80,60 +54,8 @@ if (isset($_SESSION['is_moderator'])) { <?php html_mini_navbar() ?> <?php display_alert() ?> <?php if (isset($_SESSION['is_moderator'])): ?> - <?php if (!empty($files)): ?> - <section class="column gap-8"> - <h2>Files (Page <?= $page ?> / <?= $max_pages ?>)</h2> - <hr> - <table class="left"> - <tr> - <?php if (FILE_THUMBNAILS): ?> - <th style="width: 10%;"></th> - <?php endif; ?> - <th>File</th> - <th>Age</th> - <th>Actions</th> - </tr> - <?php foreach ($files as $f): ?> - <tr> - <td> - <?php if (FILE_THUMBNAILS): ?> - <img src="<?= sprintf('%s/%s.webp', FILE_THUMBNAIL_DIRECTORY_PREFIX, $f['id']) ?>" alt="" - height="24"> - <?php endif; ?> - </td> - <td> - <a href="/<?= $f['name'] ?>" target="_blank"><?= $f['name'] ?></a> - </td> - <td> - <?= format_timestamp(time() - filemtime(sprintf('%s/%s', FILE_UPLOAD_DIRECTORY, $f['name']))) ?> - </td> - <td> - <a href="/delete.php?f=<?= $f['name'] ?>&r=/mod.php"> - <button> - <img src="/static/img/icons/delete.png" alt="Delete"> - </button> - </a> - </td> - </tr> - <?php endforeach; ?> - </table> - - <div class="row gap-8"> - <?php if ($page - 1 >= 1): ?> - <a href="/mod.php?fp=<?= $page - 1 ?>"> - <button>Previous</button> - </a> - <?php endif; ?> - <?php if ($page + 1 <= $max_pages): ?> - <a href="/mod.php?fp=<?= $page + 1 ?>"> - <button>Next</button> - </a> - <?php endif; ?> - </div> - </section> - <?php else: ?> - <p><i>No files to moderate...</i></p> - <?php endif; ?> + <h1>Now you can access moderator related panels!</h1> + <p><i>TODO: add more mod features here</i></p> <?php else: ?> <h1>Log in to the moderation system</h1> <hr> diff --git a/public/static/style.css b/public/static/style.css index 53c246e..7298fcb 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -271,6 +271,27 @@ button[type=submit]:hover { align-self: flex-end; } +/** FILE CATALOG (WALL) */ +.wall { + display: flex; + flex-wrap: wrap; + gap: 16px; +} + +.wall .brick { + display: flex; + align-items: center; + justify-content: center; + + width: 128px; + height: 128px; +} + +.brick img { + min-width: 100%; + height: auto; +} + /** SHORTCUTS */ .column { display: flex; |
