Less home code more F3
This commit is contained in:
@@ -20,11 +20,11 @@ class PostController extends BaseController
|
||||
{
|
||||
$this->verifyCsrf();
|
||||
|
||||
$media = new Media($this->db);
|
||||
$media = new Media();
|
||||
$input = $this->postInput();
|
||||
|
||||
try {
|
||||
(new Post($this->db))->create($input, $media);
|
||||
(new Post())->create($input, $media);
|
||||
$this->flash('success', 'Article créé.');
|
||||
$this->f3->reroute('@dashboard');
|
||||
} catch (RuntimeException $e) {
|
||||
@@ -34,7 +34,7 @@ class PostController extends BaseController
|
||||
|
||||
public function edit(): void
|
||||
{
|
||||
$post = (new Post($this->db))->findForEdit((int) $this->f3->get('PARAMS.id'));
|
||||
$post = (new Post())->findForEdit((int) $this->f3->get('PARAMS.id'));
|
||||
if ($post === null) {
|
||||
$this->f3->error(404, 'Article introuvable.');
|
||||
return;
|
||||
@@ -47,12 +47,12 @@ class PostController extends BaseController
|
||||
{
|
||||
$this->verifyCsrf();
|
||||
|
||||
$media = new Media($this->db);
|
||||
$media = new Media();
|
||||
$id = (int) $this->f3->get('PARAMS.id');
|
||||
$input = $this->postInput() + ['id' => $id];
|
||||
|
||||
try {
|
||||
$updated = (new Post($this->db))->updatePost($id, $input, $media);
|
||||
$updated = (new Post())->updatePost($id, $input, $media);
|
||||
if (!$updated) {
|
||||
$this->f3->error(404, 'Article introuvable.');
|
||||
return;
|
||||
@@ -70,7 +70,7 @@ class PostController extends BaseController
|
||||
$this->verifyCsrf();
|
||||
|
||||
try {
|
||||
(new Post($this->db))->delete((int) $this->f3->get('PARAMS.id'));
|
||||
(new Post())->delete((int) $this->f3->get('PARAMS.id'));
|
||||
$this->flash('success', 'Article supprimé.');
|
||||
} catch (RuntimeException $e) {
|
||||
$this->flash('error', $e->getMessage());
|
||||
@@ -81,7 +81,7 @@ class PostController extends BaseController
|
||||
|
||||
private function renderForm(string $pageTitle, string $formAction, array $post, ?string $error = null, ?Media $media = null): void
|
||||
{
|
||||
$media ??= new Media($this->db);
|
||||
$media ??= new Media();
|
||||
|
||||
$coverPreview = null;
|
||||
if (!empty($post['cover_media_id'])) {
|
||||
@@ -90,7 +90,7 @@ class PostController extends BaseController
|
||||
|
||||
$mediaItems = $media->latest(self::MEDIA_PICKER_LIMIT);
|
||||
$mediaCount = $media->count();
|
||||
$flash = $error !== null ? ['type' => 'error', 'message' => $error] : null;
|
||||
$flash = $error !== null ? [['type' => 'error', 'message' => $error]] : [];
|
||||
|
||||
$this->render('admin/post_form.html', [
|
||||
'pageTitle' => $pageTitle,
|
||||
@@ -109,9 +109,17 @@ class PostController extends BaseController
|
||||
|
||||
private function postInput(): array
|
||||
{
|
||||
$title = (string) ($this->f3->get('POST.title') ?? '');
|
||||
$excerpt = (string) ($this->f3->get('POST.excerpt') ?? '');
|
||||
|
||||
// scrub() supprime les tags HTML/PHP — défense en profondeur
|
||||
// pour les champs rendus en texte brut dans les templates.
|
||||
$this->f3->scrub($title);
|
||||
$this->f3->scrub($excerpt);
|
||||
|
||||
return [
|
||||
'title' => trim((string) ($this->f3->get('POST.title') ?? '')),
|
||||
'excerpt' => trim((string) ($this->f3->get('POST.excerpt') ?? '')),
|
||||
'title' => trim($title),
|
||||
'excerpt' => trim($excerpt),
|
||||
'cover_media_id' => (string) ($this->f3->get('POST.cover_media_id') ?? ''),
|
||||
'body_markdown' => trim((string) ($this->f3->get('POST.body_markdown') ?? '')),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user