アクセス許可管理

This commit is contained in:
2025-12-29 15:53:34 +09:00
parent decf69e8b4
commit 8c76fe2733
14 changed files with 127 additions and 12 deletions

View File

@@ -7,9 +7,11 @@ class BlogPost {
*
* @return array 投稿の配列
*/
public function getPosts(string $section): array {
public function getPosts(string $section, ?\stdClass $user): array {
$path = ROOT.$section;
$posts = [];
$isMember = $user !== NULL;
$isStaff = $user !== NULL && $user->role === 1;
if (!is_dir($path)) return $posts;
$files = glob($path.'/*.md');
@@ -51,7 +53,7 @@ class BlogPost {
'thumborient' => $metadata['thumborient'] ?? '',
'category' => $metadata['category'] ?? [],
'uuid' => $metadata['uuid'] ?? '',
'preview' => $preview,
'preview' => ((!$isMember && in_array('memberonly', $metadata['category'])) || (!$isStaff && in_array('staffonly', $metadata['category'])) ? '未許可' : $preview),
'slug' => $slug,
];
}