blob: 5269d74da038e87fb67dcc6a5df782785d59365e (
plain)
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
|
<?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>
<?php endif; ?>
<div class="gallery-feed">
<?php foreach ($posts as $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 include __DIR__ . '/../partials/pagination.php'; ?>
</div>
|