Files
plugi/extensions/plugi-ext-blog/routes/savePost.php
T
deepDiverPaul e97d96c1f5 feat(ext-blog): Add Markdown support and featured images to Plugi Blog Extension
Updated README.md to document Markdown rendering and image authoring capabilities. Added PostContentRenderer class for safe Markdown parsing with XSS protection. Updated PostsRepository to fetch and resolve featured image data from the uploads table. Added UI controls in EditPost.php for selecting images and inserting inline Markdown. Updated views to display featured images on post cards and detail pages.
2026-12-02 10:20:36 +00:00

31 lines
1.3 KiB
PHP

<?php
phpb_requires_authenticated();
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
exit();
}
if (!phpb_validate_csrf()) {
http_response_code(403);
exit();
}
$postsRepository = new \Plugi\Extensions\Blog\PostsRepository();
$redirectUrl = phpb_url('website_manager', ['tab' => 'ext--blog', 'action' => 'posts']);
$fields = ['title', 'slug', 'excerpt', 'body', 'featured_image_id', 'category_id', 'status', 'published_at'];
$data = array_intersect_key($_POST, array_flip($fields));
try {
if (isset($_POST['id']) && is_string($_POST['id']) && ctype_digit($_POST['id']) && (int) $_POST['id'] > 0) {
$saved = $postsRepository->update(['id' => (int) $_POST['id']], $data);
} elseif (!isset($_POST['id'])) {
$saved = $postsRepository->create($data);
} else {
$saved = false;
}
$message = $saved ? ['message-type' => 'success', 'message' => 'Post saved.'] : ['message-type' => 'error', 'message' => 'The post could not be saved.'];
} catch (\InvalidArgumentException $exception) {
$message = ['message-type' => 'error', 'message' => $exception->getMessage()];
} catch (\Throwable) {
$message = ['message-type' => 'error', 'message' => 'The post could not be saved. Check that the slug is unique.'];
}
phpb_redirect($redirectUrl, $message);