-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit.php
More file actions
40 lines (33 loc) · 840 Bytes
/
edit.php
File metadata and controls
40 lines (33 loc) · 840 Bytes
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
<?php
define('BASEPATH', __DIR__);
require_once 'templating.php';
require_once 'transactions.php';
require_once 'urls.php';
require_once 'auth.php';
requireLogin();
$id = $_GET['id'] ?? '';
if (empty($id)) {
flash('Post ID is required');
redirect(getHomeURL());
}
$post = getPost($id);
if (empty($post)) {
flash('Post not found');
redirect(getHomeURL());
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$content = $_POST['content'];
$isPinned = !empty($_POST['isPinned']);
if (empty($title) || empty($content)) {
flash('Title and content are required');
} else {
updatePost($id, $title, $content, $isPinned);
$post = getPost($id);
flash('Post updated');
}
}
renderTemplate('post_form', [
'title' => 'Edit',
'post' => $post,
]);