diff --git a/public/index.php b/public/index.php index 90af0d6..ec3d9a8 100644 --- a/public/index.php +++ b/public/index.php @@ -26,19 +26,22 @@ switch ($action) { case 'create': requireAuth(); - $title = $_POST['title'] ?? ''; - $content = $_POST['content'] ?? ''; - $postSlug = $_POST['slug'] ?? ''; - $published = isset($_POST['published']); - $published_at = str_replace('T', ' ', $_POST['published_at'] ?? date('Y-m-d H:i:s')); - $errors = []; + $title = $_POST['title'] ?? ''; + $content = $_POST['content'] ?? ''; + $postSlug = $_POST['slug'] ?? ''; + $published = isset($_POST['published']); + $published_at = str_replace('T', ' ', $_POST['published_at'] ?? date('Y-m-d H:i:s')); + $seoTitle = $_POST['seo_title'] ?? ''; + $seoDescription = $_POST['seo_description'] ?? ''; + $ogImage = $_POST['og_image'] ?? ''; + $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($title) === '') { $errors[] = 'Le titre est obligatoire.'; } if (empty($errors)) { - $newUuid = $articles->create($title, $content, $published, $postSlug, $published_at, currentUserEmail() ?? ''); + $newUuid = $articles->create($title, $content, $published, $postSlug, $published_at, currentUserEmail() ?? '', $seoTitle, $seoDescription, $ogImage); foreach ($_FILES['files']['tmp_name'] ?? [] as $i => $tmpName) { if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) { @@ -105,13 +108,16 @@ switch ($action) { exit; } - $title = $_POST['title'] ?? $article['title']; - $content = $_POST['content'] ?? $article['content']; - $postSlug = $_POST['slug'] ?? $article['slug']; - $published = isset($_POST['published']) ? true : $article['published']; - $published_at = $_POST['published_at'] + $title = $_POST['title'] ?? $article['title']; + $content = $_POST['content'] ?? $article['content']; + $postSlug = $_POST['slug'] ?? $article['slug']; + $published = isset($_POST['published']) ? true : $article['published']; + $published_at = $_POST['published_at'] ?? date('Y-m-d\TH:i', strtotime((string)($article['published_at'] ?? 'now'))); - $errors = []; + $seoTitle = $_POST['seo_title'] ?? ($article['seo_title'] ?? ''); + $seoDescription = $_POST['seo_description'] ?? ($article['seo_description'] ?? ''); + $ogImage = $_POST['og_image'] ?? ($article['og_image'] ?? ''); + $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($title) === '') { @@ -125,7 +131,10 @@ switch ($action) { $published, $_POST['slug'] ?? '', str_replace('T', ' ', $_POST['published_at'] ?? ''), - $_POST['revision_comment'] ?? '' + $_POST['revision_comment'] ?? '', + $_POST['seo_title'] ?? '', + $_POST['seo_description'] ?? '', + $_POST['og_image'] ?? '' ); foreach ($_FILES['files']['tmp_name'] ?? [] as $i => $tmpName) { @@ -150,6 +159,15 @@ switch ($action) { include BASE_PATH . '/templates/post_form.php'; break; + case 'delete_file': + requireAuth(); + $fileName = basename($_POST['name'] ?? ''); + if ($uuid !== '' && $fileName !== '' && $fileName[0] !== '.') { + $articles->deleteFile($uuid, $fileName); + } + header('Location: /?action=edit&uuid=' . rawurlencode($uuid)); + exit; + case 'delete': requireAuth(); if ($uuid !== '') { diff --git a/src/ArticleManager.php b/src/ArticleManager.php index 6b72298..a85f58b 100644 --- a/src/ArticleManager.php +++ b/src/ArticleManager.php @@ -69,7 +69,7 @@ class ArticleManager // Écriture // ------------------------------------------------------------------ // - public function create(string $title, string $content, bool $published, string $slug = '', string $publishedAt = '', string $author = ''): string + public function create(string $title, string $content, bool $published, string $slug = '', string $publishedAt = '', string $author = '', string $seoTitle = '', string $seoDescription = '', string $ogImage = ''): string { $uuid = $this->generateUuid(); $slug = $slug !== '' ? $this->sanitizeSlug($slug) : $this->generateSlug($title); @@ -82,15 +82,18 @@ class ArticleManager mkdir($dir . '/files', 0755, true); $meta = [ - 'uuid' => $uuid, - 'slug' => $slug, - 'title' => $title, - 'author' => $author, - 'published' => $published, - 'published_at' => $publishedAt, - 'created_at' => $now, - 'updated_at' => $now, - 'revisions' => [], + 'uuid' => $uuid, + 'slug' => $slug, + 'title' => $title, + 'author' => $author, + 'published' => $published, + 'published_at' => $publishedAt, + 'created_at' => $now, + 'updated_at' => $now, + 'revisions' => [], + 'seo_title' => $seoTitle, + 'seo_description' => $seoDescription, + 'og_image' => $ogImage, ]; $this->writeMeta($dir, $meta); file_put_contents($dir . '/index.md', ltrim($content)); @@ -98,7 +101,7 @@ class ArticleManager return $uuid; } - public function update(string $uuid, string $title, string $content, bool $published, string $slug, string $publishedAt, string $revisionComment = ''): void + public function update(string $uuid, string $title, string $content, bool $published, string $slug, string $publishedAt, string $revisionComment = '', string $seoTitle = '', string $seoDescription = '', string $ogImage = ''): void { $article = $this->getByUuid($uuid); if (!$article) { @@ -113,15 +116,18 @@ class ArticleManager } $meta = [ - 'uuid' => $uuid, - 'slug' => $slug, - 'title' => $title, - 'author' => $article['author'] ?? '', - 'published' => $published, - 'published_at' => $publishedAt !== '' ? $publishedAt : ($article['published_at'] ?? date('Y-m-d H:i:s')), - 'created_at' => $article['created_at'] ?? date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - 'revisions' => $revisions, + 'uuid' => $uuid, + 'slug' => $slug, + 'title' => $title, + 'author' => $article['author'] ?? '', + 'published' => $published, + 'published_at' => $publishedAt !== '' ? $publishedAt : ($article['published_at'] ?? date('Y-m-d H:i:s')), + 'created_at' => $article['created_at'] ?? date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + 'revisions' => $revisions, + 'seo_title' => $seoTitle, + 'seo_description' => $seoDescription, + 'og_image' => $ogImage, ]; $dir = $this->dataDir . '/' . $uuid; $this->writeMeta($dir, $meta); @@ -173,6 +179,22 @@ class ArticleManager return $files; } + public function deleteFile(string $uuid, string $name): bool + { + if (!$this->isValidUuid($uuid)) { + return false; + } + $name = basename($name); + if ($name === '' || $name[0] === '.') { + return false; + } + $path = $this->dataDir . '/' . $uuid . '/files/' . $name; + if (!is_file($path)) { + return false; + } + return unlink($path); + } + public function addFile(string $uuid, array $uploadedFile): ?string { if (!$this->isValidUuid($uuid)) { diff --git a/templates/layout.php b/templates/layout.php index 03ef155..109b77b 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -2,25 +2,28 @@ - <?= htmlspecialchars($title ?? 'varlog') ?> + <?= htmlspecialchars(($seoTitle ?? '') ?: ($title ?? 'varlog')) ?> - + - - - + + + - + + + + diff --git a/templates/post_form.php b/templates/post_form.php index 021f61a..10190aa 100644 --- a/templates/post_form.php +++ b/templates/post_form.php @@ -73,14 +73,50 @@ $dateValue = isset($published_at)

Fichiers existants

- +
@@ -92,10 +128,70 @@ $dateValue = isset($published_at) +
+
+ +
+
+
+
+ + +
+ Idéal : 30–60 caractères + 0 / 60 +
+
+ +
+ + +
+ Idéal : 120–155 caractères + 0 / 155 +
+
+ +
+ + +
+
+
+
+ Annuler + + $f): ?> +
+ +
+ + +