운영 기능 및 GA4 대시보드 반영
This commit is contained in:
@@ -20,8 +20,8 @@ final class PostRepository
|
||||
{
|
||||
$statement = $this->db->prepare(
|
||||
"SELECT posts.id, posts.title, posts.slug, posts.category, posts.excerpt, posts.published_at,
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
FROM posts
|
||||
WHERE posts.status = 'published' AND posts.deleted_at IS NULL AND posts.published_at <= NOW()
|
||||
ORDER BY published_at DESC, id DESC
|
||||
@@ -48,8 +48,8 @@ final class PostRepository
|
||||
$offset = max(0, ($page - 1) * $perPage);
|
||||
$query = $this->db->prepare(
|
||||
"SELECT posts.id, posts.title, posts.slug, posts.category, posts.excerpt, posts.published_at,
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
FROM posts WHERE {$where}
|
||||
ORDER BY published_at DESC, id DESC
|
||||
LIMIT :limit OFFSET :offset"
|
||||
@@ -68,14 +68,34 @@ final class PostRepository
|
||||
{
|
||||
$statement = $this->db->prepare(
|
||||
"SELECT posts.id, posts.title, posts.slug, posts.category, posts.excerpt, posts.body, posts.author, posts.published_at,
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
(SELECT file_path FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_path,
|
||||
(SELECT alt_text FROM post_images WHERE post_id = posts.id AND caption NOT LIKE '@gtsit:inline:%' ORDER BY sort_order, id LIMIT 1) AS image_alt
|
||||
FROM posts
|
||||
WHERE posts.slug = :slug AND posts.status = 'published' AND posts.deleted_at IS NULL AND posts.published_at <= NOW()
|
||||
LIMIT 1"
|
||||
);
|
||||
$statement->execute(['slug' => $slug]);
|
||||
$post = $statement->fetch();
|
||||
return $post ?: null;
|
||||
return $post ? $this->withMedia($post) : null;
|
||||
}
|
||||
|
||||
public function withMedia(array $post): array
|
||||
{
|
||||
$statement = $this->db->prepare(
|
||||
'SELECT id, file_path, alt_text, caption, sort_order
|
||||
FROM post_images WHERE post_id = :post_id ORDER BY sort_order, id'
|
||||
);
|
||||
$statement->execute(['post_id' => $post['id']]);
|
||||
$post['gallery_images'] = [];
|
||||
$post['inline_images'] = [];
|
||||
foreach ($statement->fetchAll() as $image) {
|
||||
if (preg_match('/^@gtsit:inline:(\d+)$/', (string) $image['caption'], $matches) === 1) {
|
||||
$image['token'] = (int) $matches[1];
|
||||
$post['inline_images'][(int) $matches[1]] = $image;
|
||||
continue;
|
||||
}
|
||||
$post['gallery_images'][] = $image;
|
||||
}
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user