diff --git a/config/functions_site.php b/config/functions_site.php index e9aeb3d..09dd189 100644 --- a/config/functions_site.php +++ b/config/functions_site.php @@ -29,16 +29,37 @@ function site_info(PDO $pdo, ?int $gym_id = null): array { return $row; } +/** Whether the home page renders section $sec for $gym (same data checks as site/index.php). */ +function site_section_has_content(array $gym, string $sec): bool { + $pdo = $GLOBALS['pdo'] ?? null; + $gid = (int) $gym['id']; + if (!$pdo && $sec !== 'galeria') return true; + return match ($sec) { + 'modalidades' => (bool) site_modalidades($pdo, $gid), + 'equipa' => (bool) site_team_active($pdo, $gid), + 'horario' => (bool) site_horario($pdo, '', $gid), + 'mensalidades' => (bool) site_memberships($pdo, $gid), + 'galeria' => !empty($gym['gallery_id']) && preg_grep('/\.(jpe?g|png|gif|webp|jxl)$/i', + glob(dirname(__DIR__) . '/uploads/gallery/' . (int) $gym['gallery_id'] . '/*') ?: []), + default => true, + }; +} + +/** Team members shown on the site (status «ativo»). */ +function site_team_active(PDO $pdo, ?int $gym_id = null): array { + return array_values(array_filter(site_team($pdo, $gym_id), fn($d) => ($d['status'] ?? '') === 'ativo')); +} + // Top navigation (label => absolute URL): anchors on the gym's own page, only -// for the sections that gym shows, plus its CrossFit page when it has one. +// for the sections that gym shows and has content for, plus its CrossFit page when it has one. function site_navbar(?array $gym = null): array { $gym = $gym ?? current_gym(); $items = ['Home' => ['#home', null]]; - foreach (['Modalidades' => 'modalidades', 'Equipa' => 'equipa', 'Horário' => 'horario', + foreach (['Galeria' => 'galeria', 'Modalidades' => 'modalidades', 'Equipa' => 'equipa', 'Horário' => 'horario', 'Mensalidades' => 'mensalidades', 'Contactos' => 'contactos'] as $label => $sec) { if (!gym_section_on($gym, $sec)) continue; - // No active plans → the section isn't rendered, so no link to it either. - if ($sec === 'mensalidades' && !empty($GLOBALS['pdo']) && !site_memberships($GLOBALS['pdo'], (int) $gym['id'])) continue; + // A section with nothing to show isn't rendered, so no link to it either. + if (!site_section_has_content($gym, $sec)) continue; $items[$label] = ['#' . $sec, $sec]; } $nav = []; diff --git a/site/index.php b/site/index.php index 16c30fc..915546d 100644 --- a/site/index.php +++ b/site/index.php @@ -27,7 +27,7 @@ require __DIR__ . '/_open.php'; // resolves $gym (404 if unknown / not visible $gid = (int) $gym['id']; $on = fn(string $key) => gym_section_on($gym, $key); $offer = $on('oferta') ? site_offer($pdo, $gid) : []; -$team = $on('equipa') ? site_team($pdo, $gid) : []; +$team = $on('equipa') ? site_team_active($pdo, $gid) : []; $modalidades = $on('modalidades') ? site_modalidades($pdo, $gid) : []; $horario = $on('horario') ? site_horario($pdo, '', $gid) : []; $whours = $on('workhours') ? site_work_hours($pdo, $gid) : []; @@ -121,7 +121,7 @@ $gallery_files = ($on('galeria') && $gallery_path !== '') ? preg_grep('/\.(jpe?g if ($gallery_files && count($gallery_files) > 0): $gallery_h2 = 'Conhece as nossas instalações'; ?> -