diff options
Diffstat (limited to 'src/app/Views/gallery/index.php')
| -rw-r--r-- | src/app/Views/gallery/index.php | 64 |
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'] ? '♥' : '♡' ?> + </button> + </form> + <?php else: ?> + <span class="like-btn">♡</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 ?>">« 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 »</a> - <?php endif; ?> - </nav> - <?php endif; ?> + <?php include __DIR__ . '/../partials/pagination.php'; ?> </div> |
