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';
-
- UserAuth::boot();
-
- $db = Database::site();
- $settings = SiteFront::settings();
-
- $slug = trim((string) ($_GET['slug'] ?? ''));
-
- $categoryStatement = $db->prepare('SELECT * FROM categories WHERE slug = :slug LIMIT 1');
- $categoryStatement->execute(['slug' => $slug]);
- $category = $categoryStatement->fetch();
- if ($category) {
- $category = Languages::categories([$category])[0];
- }
-
- if (!$category) {
- 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('category_not_found', 'We couldn’t find this category.')) . '</p>';
- require __DIR__ . '/includes/front-footer.php';
- exit;
- }
-
- $currentPage = Pagination::currentPage();
- $totalStatement = $db->prepare("SELECT COUNT(*) AS c FROM articles a WHERE a.status = 'published' AND a.category_id = :category_id" . Languages::articleFilterSql('a'));
- $totalStatement->execute(['category_id' => $category['id']]);
- $totalArticles = (int) $totalStatement->fetch()['c'];
- $isStaticArticleLoading = ($settings['article_loading_mode'] ?? 'scroll') === 'static';
- $perPage = $isStaticArticleLoading
- ? max(1, $totalArticles)
- : max(1, (int) $settings['articles_per_page_category']);
- $currentPage = $isStaticArticleLoading ? 1 : $currentPage;
- $offset = Pagination::offset($currentPage, $perPage);
- $totalPages = Pagination::totalPages($totalArticles, $perPage);
-
- $articlesStatement = $db->prepare(
- "SELECT a.* FROM articles a WHERE a.status = 'published' AND a.category_id = :category_id" . Languages::articleFilterSql('a') . " ORDER BY a.published_at DESC LIMIT :limit OFFSET :offset"
- );
- $articlesStatement->bindValue('category_id', $category['id'], PDO::PARAM_INT);
- $articlesStatement->bindValue('limit', $perPage, PDO::PARAM_INT);
- $articlesStatement->bindValue('offset', $offset, PDO::PARAM_INT);
- $articlesStatement->execute();
- $articles = Languages::articles($articlesStatement->fetchAll());
-
- $pageTitle = $category['name'] . ' - ' . $settings['site_name'];
- $pageDescription = $category['description'] ?? '';
- $showBanner = false;
- $pageType = 'category';
- $rssFeedUrl = $settings['sitemap_rss_enabled'] === '1' && $settings['rss_category_feeds_enabled'] === '1'
- ? 'rss.php?category=' . rawurlencode((string) $category['slug'])
- : null;
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <h1 class="category-title"><?= htmlspecialchars($category['name']) ?></h1>
- <?php if (!empty($category['description'])): ?>
- <p class="category-description"><?= htmlspecialchars($category['description']) ?></p>
- <?php endif; ?>
- <?php if ($rssFeedUrl !== null): ?>
- <a href="<?= htmlspecialchars($rssFeedUrl, ENT_QUOTES) ?>" class="category-rss-link">
- <svg class="icon icon-sm" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 11a9 9 0 0 1 9 9"/><path d="M4 4a16 16 0 0 1 16 16"/><circle cx="5" cy="19" r="1"/></svg>
- <?= htmlspecialchars(Language::get('category_rss', 'RSS feed for this category')) ?>
- </a>
- <?php endif; ?>
-
- <?= SiteFront::renderAds('category-top') ?>
-
- <div class="article-grid" id="article-list" data-pagination-source="category" data-category-slug="<?= htmlspecialchars($slug, ENT_QUOTES) ?>">
- <?php $inFeedAds = SiteFront::activeAds('in-feed'); ?>
- <?php foreach ($articles as $inFeedIndex => $article): ?>
- <?= renderArticleCard($article) ?>
- <?php if ($inFeedIndex === 2 && !empty($inFeedAds)): ?>
- <?php foreach ($inFeedAds as $inFeedAd): ?>
- <?= SiteFront::renderAd($inFeedAd) ?>
- <?php endforeach; ?>
- <?php endif; ?>
- <?php endforeach; ?>
- <?php if (empty($articles)): ?>
- <p><?= htmlspecialchars(Language::get('category_no_articles', 'No articles in this category yet.')) ?></p>
- <?php endif; ?>
- </div>
-
- <div id="pagination-container">
- <?= $isStaticArticleLoading ? '' : Pagination::render($settings['pagination_style'], 'category.php', $currentPage, $totalPages, ['slug' => $slug], 'article-list') ?>
- </div>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>