/index.php et la coquille * (header/nav/footer) est écrite une seule fois ici. */ declare(strict_types=1); require __DIR__ . '/inc/site.php'; /* ───────────────────────── route ───────────────────────── */ function fws_site_current_route(): string { $raw = ''; $qs = (string) ($_SERVER['QUERY_STRING'] ?? ''); if ($qs !== '') { if (str_starts_with($qs, 'p=')) { $raw = substr($qs, 2); } elseif (str_starts_with($qs, 'p/')) { $raw = substr($qs, 2); } } if ($raw === '' && isset($_GET['p'])) { $raw = (string) $_GET['p']; } if ($raw === '') { /* Forme chemin : /p/dl/ (directement sous la base URL). En sous-dossier (WAMP), REQUEST_URI commence par /FWS-Website/ : on retire la base pour retrouver le début de la route. */ $path = trim((string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/'), '/'); if ($path !== '') { $base = ltrim(fws_base_url() . '/', '/'); if ($base !== '' && str_starts_with($path, $base)) { $path = substr($path, strlen($base)); $path = trim(preg_replace('/^\\/+|\\/+$/', '', $path) ?? ''); } } if ($path !== '' && !str_contains($path, '.') && str_starts_with($path, 'p/')) { $raw = substr($path, 2); } } $raw = strtolower(trim($raw)); $raw = trim(preg_replace('/^\/+|\/+$/', '', $raw) ?? ''); if ($raw === '' || $raw === 'home' || $raw === 'accueil' || $raw === 'index') { return 'index'; } return $raw; } $route = fws_site_current_route(); /* Résolution du corps de page : index, dl, paquets, paquets/N, equipe, contact. */ $pageFile = null; $detailId = 0; if (preg_match('/^paquets\/(\d+)$/', $route, $m)) { $detailId = max(1, (int) $m[1]); $route = 'paquets/_detail'; $pageFile = __DIR__ . '/p/paquets/detail.php'; } else { $known = ['index', 'dl', 'paquets', 'equipe', 'contact', 'mentions-legales', 'conditions', 'confidentialite']; if (in_array($route, $known, true)) { $pageFile = __DIR__ . '/p/' . $route . '/index.php'; } } $is404 = $pageFile === null || !is_file($pageFile); /* Erreurs Apache « douces » : les 403/404 déroutés ici via ErrorDocument * (voir .htaccess) rendent la page 404 du site — jamais de page Apache * brute, jamais de détail technique. */ if (in_array((int) ($_GET['__e'] ?? 0), [403, 404], true)) { $pageFile = null; $is404 = true; header('Access-Control-Allow-Origin: *'); header('Cache-Control: no-store'); /* Chemins API : JSON pour curl/scripts, page visuelle pour un navigateur * (négociation via Accept, comme inc/errors.php). */ $reqPath = (string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/'); if (str_starts_with($reqPath, '/api') && fws_error_wants_json()) { http_response_code(404); header('Content-Type: application/json; charset=utf-8'); header('X-Content-Type-Options: nosniff'); exit(json_encode(['ok' => false, 'error' => 'Ressource introuvable.'], JSON_UNESCAPED_UNICODE)); } } /* Paquets : une seule lecture DB + cache Gitea pour toute la page (le corps ET la nav déroulante les consomment). */ $packages = fws_site_packages(); /* ───────────────────────── corps de page ───────────────────────── */ /* Le corps est rendu d'abord : il peut définir $title, $description, $canonical, $extraCss[] et $extraJs[] (données issues de la DB / API). */ /* NB : pas de null pour title/description — isset(null) est false et les gardes des pages incluses (« isset($title, …) ») échoueraient. */ $title = ''; $description = ''; $canonical = null; $extraCss = []; $extraJs = []; define('FWS_PAGE_SHELL', 1); /* les corps inclus peuvent vérifier qu'ils ne sont pas exécutés en accès direct */ ob_start(); if ($is404) { http_response_code(404); include __DIR__ . '/p/404.php'; } else { include $pageFile; } $body = ob_get_clean(); if ($title === null) { $labels = [ 'index' => 'Accueil', 'dl' => 'Téléchargements', 'paquets' => 'Paquets', 'paquets/_detail' => 'Paquet', 'equipe' => "L'équipe", 'contact' => 'Contact', 'mentions-legales' => 'Mentions légales', 'conditions' => "Conditions d'utilisation", 'confidentialite' => 'Confidentialité', ]; $label = $labels[$route] ?? 'FWS Linux'; $title = $label . ' | FWS Linux'; } if ($description === null) { $description = 'FWS Linux — distribution open-source basée sur Arch Linux. Installation simplifiée, léger, respectueux de la vie privée, compatible Windows grâce à Wine et Winboat.'; } if ($canonical === null) { $canonRoute = $route === 'paquets/_detail' ? 'paquets/' . $detailId : $route; /* Portabilité : hôte courant + base URL (sous-dossier WAMP inclus), au lieu du domaine de production codé en dur. */ $fwsScheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https') ? 'https' : 'http'; $fwsHost = trim((string) ($_SERVER['HTTP_HOST'] ?? '')) !== '' ? (string) $_SERVER['HTTP_HOST'] : 'fwslinux.fr'; $canonical = $fwsScheme . '://' . $fwsHost . fws_url('/?p/' . ($canonRoute === 'index' ? 'index' : $canonRoute) . '/'); } function fws_site_active(string $route, string $prefix): string { return $route === $prefix || str_starts_with($route, $prefix . '/') ? ' aria-current="page"' : ''; } ?>