diff --git a/index.php b/index.php index d289549..f762b36 100644 --- a/index.php +++ b/index.php @@ -46,6 +46,14 @@ $activePhotoId = (int)($_GET['photo_id'] ?? 0); $activeTopicId = (int)($_GET['topic_id'] ?? 0); $welcomeText = settingGet('welcome_text', 'Добро пожаловать в галерею. Выберите раздел слева, чтобы посмотреть фотографии.'); +$hasVisibleSections = false; +foreach ($sections as $s) { + if ((int)($s['photos_count'] ?? 0) > 0) { + $hasVisibleSections = true; + break; + } +} + $photo = $activePhotoId > 0 ? photoById($activePhotoId) : null; if ($photo && $activeSectionId < 1) { $activeSectionId = (int)$photo['section_id']; @@ -56,6 +64,7 @@ $comments = $photo ? commentsByPhoto($activePhotoId) : []; $topics = []; $topicCounts = []; $topicTree = []; +$hasVisibleTopics = false; try { $topics = topicsAllForSelect(); if ($activeTopicId > 0) { @@ -66,12 +75,19 @@ try { } $topicCounts = topicPhotoCounts(null); $topicTree = buildTopicTreePublic($topics); + foreach ($topics as $topicItem) { + if ((int)($topicCounts[(int)$topicItem['id']] ?? 0) > 0) { + $hasVisibleTopics = true; + break; + } + } } catch (Throwable) { $topics = []; $topicCounts = []; $topicTree = []; $activeTopicId = 0; $filterMode = $activeSectionId > 0 ? 'section' : 'none'; + $hasVisibleTopics = false; } $photos = ($activeSectionId > 0 || $activeTopicId > 0) @@ -88,9 +104,11 @@ foreach ($sections as $s) { } $activeTopicName = ''; +$activeTopicShortName = ''; foreach ($topics as $t) { if ((int)$t['id'] === $activeTopicId) { $activeTopicName = (string)$t['full_name']; + $activeTopicShortName = (string)$t['name']; break; } } @@ -146,8 +164,9 @@ if ($photo) { } $hasMobilePhotoNav = $activePhotoId > 0 && $photo && $detailTotal > 0; +$hasMobileCatalogNav = !$photo && ($isTopicMode || $isSectionMode); $bodyClasses = [$isHomePage ? 'is-home' : 'is-inner']; -if ($hasMobilePhotoNav) { +if ($hasMobilePhotoNav || $hasMobileCatalogNav) { $bodyClasses[] = 'has-mobile-nav'; } @@ -158,6 +177,22 @@ if ($activeTopicId > 0 && $activeTopicName !== '') { $detailLocationLabel = 'в разделе «' . $sectionNames[$detailSectionId] . '»'; } +$pageHeading = ''; +if ($isTopicMode && $activeTopicShortName !== '') { + $pageHeading = $activeTopicShortName; +} elseif ($isSectionMode && isset($sectionNames[$activeSectionId])) { + $pageHeading = $sectionNames[$activeSectionId]; +} elseif ($photo && isset($sectionNames[$detailSectionId])) { + $pageHeading = $sectionNames[$detailSectionId]; +} + +$catalogLocationLabel = ''; +if ($isTopicMode && $activeTopicName !== '') { + $catalogLocationLabel = 'Тема: ' . $activeTopicName; +} elseif ($isSectionMode && isset($sectionNames[$activeSectionId])) { + $catalogLocationLabel = 'Раздел: ' . $sectionNames[$activeSectionId]; +} + function h(string $v): string { return htmlspecialchars($v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } function assetUrl(string $path): string { $f=__DIR__ . '/' . ltrim($path,'/'); $v=is_file($f)?(string)filemtime($f):(string)time(); return $path . '?v=' . rawurlencode($v); } function limitText(string $text, int $len): string { return function_exists('mb_substr') ? mb_substr($text, 0, $len) : substr($text, 0, $len); } @@ -291,6 +326,8 @@ function outputWatermarked(string $path, string $mime): never