v2.0.0.1
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/block-editor.php';
- require_once __DIR__ . '/includes/pagination.php';
- require_once __DIR__ . '/includes/article-card.php';
- require_once __DIR__ . '/includes/featured-banner.php';
-
- UserAuth::boot();
-
- $db = Database::site();
- $settings = SiteFront::settings();
-
- // With the short home address on, /index.php moves to / (and /pl/index.php to /pl/).
- $requestPath = (string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? ''), PHP_URL_PATH);
- if (SiteFront::cleanHomeUrl() && ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'GET' && str_ends_with($requestPath, '/index.php')) {
- $requestQuery = (string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? ''), PHP_URL_QUERY);
- header('Location: ' . SiteFront::homeUrl() . ($requestQuery !== '' ? '?' . $requestQuery : ''), true, 301);
- exit;
- }
-
- $latestForBanner = $db->query(
- "SELECT id, title, slug, cover_image_path FROM articles a WHERE status = 'published'" . Languages::articleFilterSql('a') . " ORDER BY published_at DESC LIMIT 6"
- )->fetchAll();
- $latestForBanner = Languages::articles($latestForBanner);
-
- $featuredBannerArticles = Languages::articles(Languages::onlyTranslated(featuredBannerArticles($db, $settings)));
- $excludedIds = featuredExcludedIds($settings, $featuredBannerArticles);
- $excludeSql = (empty($excludedIds) ? '' : ' AND a.id NOT IN (' . implode(',', $excludedIds) . ')') . Languages::articleFilterSql('a');
-
- $currentPage = Pagination::currentPage();
- $totalArticles = (int) $db->query("SELECT COUNT(*) AS c FROM articles a WHERE a.status = 'published'" . $excludeSql)->fetch()['c'];
- $isStaticArticleLoading = ($settings['article_loading_mode'] ?? 'scroll') === 'static';
- $perPage = $isStaticArticleLoading
- ? max(1, $totalArticles)
- : max(1, (int) $settings['articles_per_page_home']);
- $currentPage = $isStaticArticleLoading ? 1 : $currentPage;
- $offset = Pagination::offset($currentPage, $perPage);
- $totalPages = Pagination::totalPages($totalArticles, $perPage);
-
- $featuredStatement = $db->prepare(
- "SELECT a.*, c.name AS category_name, c.slug AS category_slug FROM articles a LEFT JOIN categories c ON c.id = a.category_id WHERE a.status = 'published'" . $excludeSql . " ORDER BY a.published_at DESC LIMIT :limit OFFSET :offset"
- );
- $featuredStatement->bindValue('limit', $perPage, PDO::PARAM_INT);
- $featuredStatement->bindValue('offset', $offset, PDO::PARAM_INT);
- $featuredStatement->execute();
- $featuredArticles = Languages::articles($featuredStatement->fetchAll());
-
- SiteFront::setAdContext('home');
- $homepageSource = (string) ($settings['homepage_blocks'] ?? '');
- if (Languages::current() !== '') {
- $homeTranslation = Languages::translation('home', 1, Languages::current());
- if ($homeTranslation !== null && trim((string) $homeTranslation['title']) !== '' && trim((string) $homeTranslation['content_blocks']) !== '') {
- $homepageSource = (string) $homeTranslation['content_blocks'];
- }
- }
- $homepageBlocks = BlockEditor::homepageBlocks(['homepage_blocks' => $homepageSource]);
- $homeSections = [];
- foreach ($homepageBlocks as $homeBlock) {
- if (in_array($homeBlock['type'], BlockEditor::HOME_SYSTEM_TYPES, true)) {
- $homeSections[] = $homeBlock['type'];
- continue;
- }
- $lastSection = count($homeSections) - 1;
- if ($lastSection >= 0 && is_array($homeSections[$lastSection])) {
- $homeSections[$lastSection][] = $homeBlock;
- } else {
- $homeSections[] = [$homeBlock];
- }
- }
-
- if (in_array('contact_form', array_column($homepageBlocks, 'type'), true)) {
- header('Cache-Control: private, no-store');
- }
-
- $pageTitle = $settings['seo_title'] !== '' ? $settings['seo_title'] : $settings['site_name'];
- $pageDescription = $settings['seo_description'] !== '' ? $settings['seo_description'] : $settings['site_description'];
- $showBanner = true;
- $pageType = 'index';
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <?php if (!empty($settings['site_description'])): ?>
- <section class="hero-section">
- <div class="hero-eyebrow"><?= htmlspecialchars(Language::get('nav_home', 'Home')) ?></div>
- <h1 class="hero-title"><?= htmlspecialchars($settings['site_name']) ?></h1>
- <p class="hero-subtitle"><?= htmlspecialchars($settings['site_description']) ?></p>
- </section>
- <?php endif; ?>
-
- <?php foreach (SiteFront::activeAds('homepage-top') as $homepageTopAd): ?>
- <?= SiteFront::renderAd($homepageTopAd) ?>
- <?php endforeach; ?>
-
- <?php foreach ($homeSections as $homeSection): ?>
- <?php if (is_array($homeSection)): ?>
- <div class="article-content home-blocks">
- <?= BlockEditor::render(json_encode(['blocks' => $homeSection], JSON_UNESCAPED_UNICODE)) ?>
- </div>
- <?php elseif ($homeSection === 'home_featured'): ?>
- <?php if (($settings['featured_banner_enabled'] ?? '0') === '1'): ?>
- <div class="section-heading-row">
- <h2 class="section-heading"><?= htmlspecialchars(Language::get('home_featured', 'Featured')) ?></h2>
- </div>
-
- <?php if (!empty($featuredBannerArticles)): ?>
- <?= renderFeaturedBanner($featuredBannerArticles) ?>
- <?php endif; ?>
- <?php endif; ?>
- <?php elseif ($homeSection === 'home_articles'): ?>
- <div class="article-grid" id="article-list" data-pagination-source="home">
- <?php $inFeedAds = SiteFront::activeAds('in-feed'); ?>
- <?php foreach ($featuredArticles 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($featuredArticles)): ?>
- <p><?= htmlspecialchars(Language::get('home_no_articles', 'No articles yet. Check back soon.')) ?></p>
- <?php endif; ?>
- </div>
-
- <div id="pagination-container">
- <?= $isStaticArticleLoading ? '' : Pagination::render($settings['pagination_style'], SiteFront::homeUrl(), $currentPage, $totalPages, [], 'article-list') ?>
- </div>
- <?php endif; ?>
- <?php endforeach; ?>
-
- <?= SiteFront::renderAds('homepage-bottom') ?>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>