| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /**
- * Showreel manager: upload, reorder and remove the portfolio images.
- * These are stored locally in public/media/ in full resolution.
- */
- require dirname(__DIR__, 2) . '/app/bootstrap.php';
- auth_require();
- $site = site_get();
- $reel = $site['showreel'] ?? [];
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- csrf_verify();
- $action = $_POST['action'] ?? '';
- if ($action === 'upload') {
- $count = 0;
- foreach ($_FILES['images']['name'] ?? [] as $i => $name) {
- $file = [
- 'name' => $name,
- 'tmp_name' => $_FILES['images']['tmp_name'][$i],
- 'error' => $_FILES['images']['error'][$i],
- ];
- $stored = media_store_upload($file);
- if ($stored !== null) {
- $reel[] = $stored;
- $count++;
- }
- }
- flash_set($count > 0 ? "$count image(s) added to the showreel." : 'No valid images uploaded.', $count > 0 ? 'ok' : 'error');
- }
- if ($action === 'delete') {
- $name = (string)($_POST['file'] ?? '');
- $reel = array_values(array_filter($reel, fn($f) => $f !== $name));
- media_delete($name);
- flash_set('Image removed.');
- }
- if ($action === 'move') {
- $i = (int)($_POST['index'] ?? -1);
- $dir = $_POST['dir'] === 'up' ? -1 : 1;
- $j = $i + $dir;
- if (isset($reel[$i], $reel[$j])) {
- [$reel[$i], $reel[$j]] = [$reel[$j], $reel[$i]];
- }
- }
- $site['showreel'] = array_values($reel);
- site_save($site);
- redirect('showreel.php');
- }
- admin_header('Showreel', 'showreel');
- flash_render();
- ?>
- <h1>Showreel</h1>
- <form method="post" enctype="multipart/form-data" class="card">
- <?= csrf_field() ?>
- <input type="hidden" name="action" value="upload">
- <label for="imgs">Add images</label>
- <input type="file" id="imgs" name="images[]" accept="image/*" multiple>
- <p class="help">
- Full resolution, unmodified. These upload through the webhost, so add a few
- at a time if your hosting has upload size limits.
- </p>
- <button type="submit">Upload</button>
- </form>
- <h2>Current order (<?= count($reel) ?>)</h2>
- <?php if (!$reel): ?>
- <p class="help">The showreel is empty.</p>
- <?php else: ?>
- <div class="card"><table>
- <tr><th></th><th>Image</th><th>File</th><th style="width:170px">Actions</th></tr>
- <?php foreach ($reel as $i => $file): ?>
- <tr>
- <td><?= $i + 1 ?></td>
- <td><img src="../media/<?= e(rawurlencode($file)) ?>" alt="" style="width:110px;height:74px;object-fit:cover;border-radius:4px"></td>
- <td><?= e($file) ?></td>
- <td>
- <form method="post" style="display:inline"><?= csrf_field() ?>
- <input type="hidden" name="action" value="move">
- <input type="hidden" name="index" value="<?= $i ?>">
- <input type="hidden" name="dir" value="up">
- <button class="btn-ghost" style="margin:0;padding:.3rem .7rem" <?= $i === 0 ? 'disabled' : '' ?>>↑</button>
- </form>
- <form method="post" style="display:inline"><?= csrf_field() ?>
- <input type="hidden" name="action" value="move">
- <input type="hidden" name="index" value="<?= $i ?>">
- <input type="hidden" name="dir" value="down">
- <button class="btn-ghost" style="margin:0;padding:.3rem .7rem" <?= $i === count($reel) - 1 ? 'disabled' : '' ?>>↓</button>
- </form>
- <form method="post" style="display:inline"
- onsubmit="return confirm('Remove this image from the showreel?')"><?= csrf_field() ?>
- <input type="hidden" name="action" value="delete">
- <input type="hidden" name="file" value="<?= e($file) ?>">
- <button class="btn-danger" style="margin:0;padding:.3rem .7rem">✕</button>
- </form>
- </td>
- </tr>
- <?php endforeach; ?>
- </table></div>
- <?php endif; ?>
- <?php admin_footer(); ?>
|