Gestion des pieces jointes dans edition + SEO par article
This commit is contained in:
+42
-20
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user