v2.0.0.0
Publisium
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/user-auth.php';
- require_once __DIR__ . '/includes/language.php';
- require_once __DIR__ . '/includes/site-front.php';
- require_once __DIR__ . '/includes/pagination.php';
- require_once __DIR__ . '/includes/article-card.php';
- require_once __DIR__ . '/includes/tags.php';
-
- UserAuth::boot();
-
- $db = Database::site();
- $settings = SiteFront::settings();
-
- $slug = trim((string) ($_GET['slug'] ?? ''));
- $tag = ArticleTags::isEnabled() ? ArticleTags::findBySlug($slug) : null;
-
- if ($tag === null) {
- http_response_code(404);
- $pageTitle = Language::get('not_found_title', 'Not found') . ' - ' . $settings['site_name'];
- $showBanner = false;
- require __DIR__ . '/includes/front-header.php';
- echo '<p>' . htmlspecialchars(Language::get('tag_not_found', 'Tag not found.')) . '</p>';
- require __DIR__ . '/includes/front-footer.php';
- exit;
- }
-
- $tagId = (int) $tag['id'];
-
- $totalStatement = $db->prepare(
- "SELECT COUNT(*) FROM articles a JOIN article_tags l ON l.article_id = a.id WHERE l.tag_id = :tag AND a.status = 'published'" . Languages::articleFilterSql('a')
- );
- $totalStatement->execute(['tag' => $tagId]);
- $totalArticles = (int) $totalStatement->fetchColumn();
-
- $isStaticArticleLoading = ($settings['article_loading_mode'] ?? 'scroll') === 'static';
- $perPage = $isStaticArticleLoading
- ? max(1, $totalArticles)
- : max(1, (int) $settings['articles_per_page_category']);
- $totalPages = Pagination::totalPages($totalArticles, $perPage);
- $currentPage = $isStaticArticleLoading ? 1 : min(Pagination::currentPage(), $totalPages);
- $offset = Pagination::offset($currentPage, $perPage);
-
- $articlesStatement = $db->prepare(
- "SELECT a.*, c.name AS category_name, c.slug AS category_slug
- FROM articles a
- JOIN article_tags l ON l.article_id = a.id
- LEFT JOIN categories c ON c.id = a.category_id
- WHERE l.tag_id = :tag AND a.status = 'published'" . Languages::articleFilterSql('a') . "
- ORDER BY a.published_at DESC
- LIMIT :limit OFFSET :offset"
- );
- $articlesStatement->bindValue('tag', $tagId, PDO::PARAM_INT);
- $articlesStatement->bindValue('limit', $perPage, PDO::PARAM_INT);
- $articlesStatement->bindValue('offset', $offset, PDO::PARAM_INT);
- $articlesStatement->execute();
- $articles = Languages::articles($articlesStatement->fetchAll());
-
- $heading = str_replace('{name}', (string) $tag['name'], Language::get('tag_page_title', 'Tagged: {name}'));
- $pageTitle = $heading . ' - ' . $settings['site_name'];
- $pageDescription = '';
- $showBanner = false;
- $pageType = 'category';
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <h1 class="category-title"><?= htmlspecialchars($heading) ?></h1>
-
- <div class="article-grid" id="article-list">
- <?php foreach ($articles as $article): ?>
- <?= renderArticleCard($article) ?>
- <?php endforeach; ?>
- <?php if (empty($articles)): ?>
- <p><?= htmlspecialchars(Language::get('tag_no_articles', 'No published articles with this tag yet.')) ?></p>
- <?php endif; ?>
- </div>
-
- <div id="pagination-container">
- <?= $isStaticArticleLoading ? '' : Pagination::render('numbered', 'tag.php', $currentPage, $totalPages, ['slug' => $slug], 'article-list') ?>
- </div>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>
-