-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
333 lines (284 loc) · 14.5 KB
/
post.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
// Include config file
include "includes/config.php";
// Define required parameters
$post_slug = $_GET['post_slug'];
$post = Post::getPost($post_slug);
if (isset($_POST['movePost']) && isAdmin()) {
Post::movePost($_POST['board'], $post_slug);
}
if (isset($_POST['deletePost'])) {
if(Post::deletePost($post_slug)) {
header("location: " . SITE_URL . "/index.php");
}
}
if (isset($_POST['changeStatus']) && isAdmin()) {
Post::changeStatus($_POST['status'], $post_slug);
}
if (isset($_POST['postComment']) && isset($_POST['comment'])) {
Comment::newComment($post->post_id, $_POST['comment']);
}
if (isset($_POST['deleteComment'])) {
Comment::deleteComment($_POST['comment_id']);
}
?>
<!doctype html>
<html lang="en">
<?= Render::header(); ?>
<body class="bg-light">
<?= Render::navigation(); ?>
<div class="row mt-5">
<div class="col"></div>
<div class="col-md-6">
<!-- Page loader -->
<div class="card border-0 bg-transparent" id="loading">
<div class="card-body p-4 text-center">
Loading...
</div>
</div>
<!-- Post not found -->
<div class="card p-4 w-75 mx-auto" id="post-not-found">
<div class="card-body p-4">
<i class="h3 fas fa-exclamation-triangle text-warning mb-3"></i>
<h5>Post Not Found</h5>
<p>Sorry, we couldn't find a post located at the specified URL.</p>
<p class="fw-bold">It may have been moved, deleted, or may have never existed.</p>
<a href="<?= SITE_URL ?>" class="btn btn-accent">Go back
home</a>
</div>
</div>
<!-- Page content -->
<div id="page">
<p class="d-inline-block pe-0 text-muted mb-3">
<a href="<?= SITE_URL ?>"
class="text-accent text-decoration-none">Home</a>
<i class="fas fa-caret-right mx-2"></i>
</p>
<p class="d-inline pe-0 text-muted">
<a href="#" class="text-accent post-board text-decoration-none"></a>
<i class="fas fa-caret-right mx-2"></i>
</p>
<p class="d-inline-block pe-0 text-muted post-title"></p>
<p class="d-inline pe-0 text-muted board-name"></p>
<div class="card shadow round">
<div class="card-header bg-accent text-white p-5 round-top">
<div class="d-flex" id="post-wrapper">
<div class="me-1">
<div class="upvote">
<button class="btn border px-3">
<i class="fas fa-caret-up d-block"></i>
<p class="mb-0"></p>
</button>
</div>
</div>
<div>
<h4 style="font-weight:700" class="post-title"></h4>
<p class="small d-inline-block"><span class="post-date"></span></p>
<span id="post-status"></span>
<a href="#" class="mb-0 d-block text-reset text-decoration-none" id="user">
<img class="rounded-circle me-1" style="width:25px;height:25px;font-weight:700">
<span class="mb-0"></span>
</a>
</div>
</div>
</div>
<?php if(isAdmin() || (isset($user->id) && $post->user->id === $user->id)) { ?>
<div class="bg-light border-bottom px-5 py-3">
<div class="nav nav-pills d-flex justify-content-between">
<a href="<?= SITE_URL ?>/edit/<?= $post_slug ?>"
class="round nav-link small active">
<i class="far fa-pencil me-2"></i> Edit post
</a>
<div class="d-inline-flex">
<?php if (isAdmin()) { ?>
<button class="nav-link small mx-0 pe-2 round" data-bs-toggle="modal"
data-bs-target="#changeStatus">
<i class="far fa-tag fa-flip-horizontal me-2"></i> Status
</button>
<button class="nav-link small mx-0 pe-2 round" data-bs-toggle="modal"
data-bs-target="#movePost">
<i class="far fa-arrow-right-arrow-left me-2"></i> Move
</button>
<?php } ?>
<button class="nav-link small mx-0 pe-2 text-danger round"
data-bs-toggle="modal" data-bs-target="#deletePost">
<i class="far fa-trash-alt me-2"></i> Delete
</button>
</div>
</div>
</div>
<?php } else { ?>
<div class="mb-2"></div>
<?php } ?>
<?php if (isAdmin()) { ?>
<!-- Change status modal -->
<div class="modal fade" id="changeStatus">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content shadow">
<div class="modal-header border-0 pb-0">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body px-5">
<span class="fa-stack h6">
<i class="fa-solid fa-circle fa-stack-2x text-accent"></i>
<i class="far fa-tag fa-flip-horizontal fa-stack-1x text-white"></i>
</span>
<h5>Change status</h5>
<p class="small">Add a status to this post to add it to the feedback
roadmap.</p>
<form method="post">
<div class="form-check mb-2">
<input class="form-check-input" type="radio" name="status"
id="default_status"
value="0" <?= !isset(Post::getPost($_GET['post_slug'])->status->id) ? "checked" : "" ?>>
<label class="form-check-label" for="default_status">
No status
</label>
</div>
<?php foreach (Statuses::getStatuses() as $status) { ?>
<div class="form-check mb-2">
<input class="form-check-input" type="radio"
name="status"
id="status_<?= $status->status_id ?>"
value="<?= $status->status_id ?>" <?= isset(Post::getPost($_GET['post_slug'])->status->id) ? (($status->status_id === Post::getPost($_GET['post_slug'])->status->id) ? "checked" : "") : "" ?>>
<label class="form-check-label"
for="status_<?= $status->status_id ?>">
<?= $status->name ?>
</label>
</div>
<?php } ?>
<div class="my-4">
<button type="submit" name="changeStatus"
class="btn bg-accent text-white me-1 round">Change status
</button>
<button type="button" class="btn btn-white border round">Cancel
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Move post modal -->
<div class="modal fade" id="movePost">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content shadow">
<div class="modal-header border-0 pb-0">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body px-5">
<span class="fa-stack h6">
<i class="fa-solid fa-circle fa-stack-2x text-accent"></i>
<i class="far fa-arrow-right-arrow-left fa-stack-1x text-white"></i>
</span>
<h5>Move post</h5>
<p class="small">If this post was published to the wrong board, you can
move it to another and retain all post, upvote, and comment data.
The post URL will remain unchanged.</p>
<form method="post">
<?php foreach (Boards::getBoards() as $board) { ?>
<div class="form-check mb-2">
<input class="form-check-input" type="radio" name="board"
id="board_<?= $board->board_id ?>"
value="<?= $board->board_id ?>" <?= ($board->board_id === Post::getPost($_GET['post_slug'])->board->board_id) ? "checked" : "" ?>>
<label class="form-check-label"
for="board_<?= $board->board_id ?>">
<?= $board->name ?>
</label>
</div>
<?php } ?>
<div class="my-4">
<button type="submit" name="movePost"
class="btn bg-accent text-white me-1 round">Move to board
</button>
<button type="button" class="btn btn-white border round">Cancel
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- Delete post modal -->
<div class="modal fade" id="deletePost">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content shadow">
<div class="modal-header border-0 pb-0">
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body px-5">
<span class="fa-stack h6">
<i class="fa-solid fa-circle fa-stack-2x text-danger"></i>
<i class="far fa-trash-alt fa-stack-1x text-white"></i>
</span>
<h5>Delete this post?</h5>
<p class="small">Deleting a post is permanent and cannot be
reversed. All upvotes and comments will also be removed.</p>
<div class="mb-4">
<form method="post">
<button type="submit" name="deletePost"
class="btn btn-danger me-1 round">Delete forever
</button>
<button type="button" class="btn btn-white border round" data-bs-dismiss="modal">Cancel
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="card-body px-5">
<p class="fw-bold mb-2">Description</p>
<p class="post-content mb-3"></p>
<p class="fw-bold mb-2">Voters</p>
<div class="d-flex">
<div class="d-inline-block" id="voterList"></div>
<div style="width:30px;height:30px;line-height:30px"
class="bg-light other-upvotes rounded-circle text-center small border"></div>
</div>
</div>
<div id="commentList"></div>
<div class="bg-light border-top p-4 round-bottom">
<div class="toggle-co-area">
<div class="card"
id="leave-comment">
<div class="card-body text-muted py-2"
style="font-size:14px">
Leave a comment...
</div>
</div>
</div>
<div id="comment-area" style="display:none">
<form method="post">
<textarea class="form-control w-100 mb-3" name="comment"
placeholder="Leave a comment..."
autofocus></textarea>
<div class="float-end">
<button class="btn btn-light border toggle-co-area" type="button">
Cancel
</button>
<button class="btn btn-accent" type="submit" name="postComment">
Post comment
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col"></div>
</div>
<script>
let post_id = null;
let post_slug = '<?= $_GET['post_slug'] ?>';
let user = <?= $user_s ?? 'null' ?>;
</script>
<?= Render::footer(); ?>
<script src="<?= SITE_URL ?>/assets/js/post.js"></script>
</body>
</html>