v1.0.0.1
StocketBase
- <?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/product-card.php';
- require_once __DIR__ . '/includes/tags.php';
-
- UserAuth::boot();
-
- $db = Database::site();
- $settings = SiteFront::settings();
-
- $slug = trim((string) ($_GET['slug'] ?? ''));
- $tag = ProductTags::isEnabled() ? ProductTags::findBySlug($slug) : null;
-
- if ($tag === null) {
- http_response_code(404);
- $pageTitle = Language::get('page_title_not_found', 'Not found') . ' - ' . $settings['site_name'];
- 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 products p JOIN product_tags l ON l.product_id = p.id WHERE l.tag_id = :tag AND p.status = 'published'"
- );
- $totalStatement->execute(['tag' => $tagId]);
- $totalProducts = (int) $totalStatement->fetchColumn();
-
- $isStaticProductLoading = ($settings['product_loading_mode'] ?? 'scroll') === 'static';
- $perPage = $isStaticProductLoading
- ? max(1, $totalProducts)
- : max(1, (int) $settings['products_per_page_category']);
- $totalPages = Pagination::totalPages($totalProducts, $perPage);
- $currentPage = $isStaticProductLoading ? 1 : min(Pagination::currentPage(), $totalPages);
- $offset = Pagination::offset($currentPage, $perPage);
-
- $productsStatement = $db->prepare(
- "SELECT p.*, c.name AS category_name, c.slug AS category_slug
- FROM products p
- JOIN product_tags l ON l.product_id = p.id
- LEFT JOIN categories c ON c.id = p.category_id
- WHERE l.tag_id = :tag AND p.status = 'published'
- ORDER BY p.published_at DESC
- LIMIT :limit OFFSET :offset"
- );
- $productsStatement->bindValue('tag', $tagId, PDO::PARAM_INT);
- $productsStatement->bindValue('limit', $perPage, PDO::PARAM_INT);
- $productsStatement->bindValue('offset', $offset, PDO::PARAM_INT);
- $productsStatement->execute();
- $products = $productsStatement->fetchAll();
-
- $heading = str_replace('{name}', (string) $tag['name'], Language::get('tag_page_title', 'Tagged: {name}'));
- $pageTitle = $heading . ' - ' . $settings['site_name'];
- $pageDescription = '';
- $pageType = 'category';
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <h1 class="category-title"><?= htmlspecialchars($heading) ?></h1>
-
- <div class="article-grid" id="article-list">
- <?php foreach ($products as $product): ?>
- <?= renderProductCard($product) ?>
- <?php endforeach; ?>
- <?php if (empty($products)): ?>
- <p><?= htmlspecialchars(Language::get('tag_no_products', 'No published products with this tag yet.')) ?></p>
- <?php endif; ?>
- </div>
-
- <div id="pagination-container">
- <?= $isStaticProductLoading ? '' : Pagination::render('numbered', 'tag.php', $currentPage, $totalPages, ['slug' => $slug], 'article-list') ?>
- </div>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>
-