aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Views/gallery/index.php
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-21 22:55:13 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-21 22:55:13 +0100
commitf9ad3f4dc05252839457579303a4e0a0f94d8b80 (patch)
treec78b8b5ce41f1a1dc1a8b5e6bbda2643729d7c4e /src/app/Views/gallery/index.php
parentec77d2f77b96488b1bc170ced2abab12b3c19416 (diff)
downloadcamagru-f9ad3f4dc05252839457579303a4e0a0f94d8b80.tar.gz
camagru-f9ad3f4dc05252839457579303a4e0a0f94d8b80.zip
Add likes, comments, email notifications, and pagination to gallery
Diffstat (limited to 'src/app/Views/gallery/index.php')
-rw-r--r--src/app/Views/gallery/index.php64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/app/Views/gallery/index.php b/src/app/Views/gallery/index.php
index 62fd7f3..5269d74 100644
--- a/src/app/Views/gallery/index.php
+++ b/src/app/Views/gallery/index.php
@@ -1,6 +1,9 @@
-<?php // Gallery: public feed of all posts with pagination.?>
+<?php // Gallery: public feed of all posts with likes, comments, and pagination.?>
<div class="gallery-page">
<h1>Gallery</h1>
+ <?php include __DIR__ . '/../partials/flash.php'; ?>
+
+ <?php include __DIR__ . '/../partials/pagination.php'; ?>
<?php if (empty($posts)): ?>
<p class="hint">No posts yet. Be the first!</p>
@@ -8,33 +11,52 @@
<div class="gallery-feed">
<?php foreach ($posts as $post): ?>
- <article class="gallery-post">
+ <article class="gallery-post" id="post-<?= $post['id'] ?>">
<div class="post-header">
<strong><?= htmlspecialchars($post['username']) ?></strong>
<time><?= date('M j, Y', strtotime($post['created_at'])) ?></time>
</div>
<img src="/<?= htmlspecialchars($post['image_path']) ?>" alt="Post by <?= htmlspecialchars($post['username']) ?>">
+
+ <div class="post-actions">
+ <?php if (isset($_SESSION['user_id'])): ?>
+ <form method="POST" action="/gallery/<?= $post['id'] ?>/like" class="like-form">
+ <?= \App\Csrf::field() ?>
+ <input type="hidden" name="page" value="<?= $page ?>">
+ <button type="submit" class="like-btn <?= $post['user_liked'] ? 'liked' : '' ?>">
+ <?= $post['user_liked'] ? '&#9829;' : '&#9825;' ?>
+ </button>
+ </form>
+ <?php else: ?>
+ <span class="like-btn">&#9825;</span>
+ <?php endif; ?>
+ <span class="like-count"><?= $post['like_count'] ?> <?= $post['like_count'] === 1 ? 'like' : 'likes' ?></span>
+ </div>
+
+ <div class="comments-section">
+ <?php if (!empty($post['comments'])): ?>
+ <div class="comments-list">
+ <?php foreach ($post['comments'] as $comment): ?>
+ <div class="comment">
+ <strong><?= htmlspecialchars($comment['username']) ?></strong>
+ <?= htmlspecialchars($comment['content']) ?>
+ </div>
+ <?php endforeach; ?>
+ </div>
+ <?php endif; ?>
+
+ <?php if (isset($_SESSION['user_id'])): ?>
+ <form method="POST" action="/gallery/<?= $post['id'] ?>/comment" class="comment-form">
+ <?= \App\Csrf::field() ?>
+ <input type="hidden" name="page" value="<?= $page ?>">
+ <input type="text" name="content" placeholder="Add a comment..." maxlength="500" required>
+ <button type="submit">Post</button>
+ </form>
+ <?php endif; ?>
+ </div>
</article>
<?php endforeach; ?>
</div>
- <?php if ($totalPages > 1): ?>
- <nav class="pagination">
- <?php if ($page > 1): ?>
- <a href="/gallery?page=<?= $page - 1 ?>">&laquo; Previous</a>
- <?php endif; ?>
-
- <?php for ($i = 1; $i <= $totalPages; $i++): ?>
- <?php if ($i === $page): ?>
- <span class="current-page"><?= $i ?></span>
- <?php else: ?>
- <a href="/gallery?page=<?= $i ?>"><?= $i ?></a>
- <?php endif; ?>
- <?php endfor; ?>
-
- <?php if ($page < $totalPages): ?>
- <a href="/gallery?page=<?= $page + 1 ?>">Next &raquo;</a>
- <?php endif; ?>
- </nav>
- <?php endif; ?>
+ <?php include __DIR__ . '/../partials/pagination.php'; ?>
</div>