Template
- /api/bugs/ et tout chemin inconnu sous /api/ : 404 JSON propre - 403/404 Apache : ErrorDocument vers page.php, sans page Apache brute - fichiers internes (inc/, corps de pages, db.php, init.php...) : 404 - erreurs PHP : display_errors off, handlers exception/fatal, réponses JSON ou HTML discrètes, journalisation locale gitignorée
266 lines
10 KiB
PHP
266 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* FWS Linux — point d'entrée unique du site (rendu 100 % serveur).
|
|
*
|
|
* Les URLs restent identiques : /?p/index/, /?p/dl/, /?p/paquets/,
|
|
* /?p/paquets/1/… (les deux formes « ?p=route » et « ?p/route » marchent).
|
|
* Chaque page inclut son corps depuis p/<route>/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 racine). */
|
|
$path = trim((string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_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'];
|
|
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 : réponse JSON (jamais de HTML ni de détail technique). */
|
|
$reqPath = (string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/');
|
|
if (str_starts_with($reqPath, '/api')) {
|
|
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',
|
|
];
|
|
$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;
|
|
$canonical = 'https://fwslinux.fr/?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"' : '';
|
|
}
|
|
?><!doctype html>
|
|
<html lang="fr">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title><?= e($title) ?></title>
|
|
<meta name="description" content="<?= e($description) ?>" />
|
|
<meta name="robots" content="index, follow" />
|
|
<link rel="canonical" href="<?= e($canonical) ?>" />
|
|
|
|
<!-- Open Graph -->
|
|
<meta property="og:type" content="website" />
|
|
<meta property="og:title" content="<?= e($title) ?>" />
|
|
<meta property="og:description" content="<?= e($description) ?>" />
|
|
<meta property="og:image" content="/p/assets/img/logo.png" />
|
|
<meta property="og:locale" content="fr_FR" />
|
|
|
|
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/styles.css')) ?>" />
|
|
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/paquets.css')) ?>" />
|
|
<?php foreach ($extraCss as $css): ?>
|
|
<link rel="stylesheet" href="<?= e(fws_asset($css)) ?>" />
|
|
<?php endforeach; ?>
|
|
<link rel="icon" type="image/png" href="/p/assets/img/logo.png" />
|
|
|
|
<!-- Réseau : releases des paquets (Gitea) et de l'ISO (GitHub) -->
|
|
<link rel="preconnect" href="https://gitea.nocode-var.tech" crossorigin />
|
|
<link rel="dns-prefetch" href="https://gitea.nocode-var.tech" />
|
|
<link rel="preconnect" href="https://api.github.com" crossorigin />
|
|
<link rel="dns-prefetch" href="https://api.github.com" />
|
|
<link rel="dns-prefetch" href="https://github.com" />
|
|
<link rel="dns-prefetch" href="https://objects.githubusercontent.com" />
|
|
</head>
|
|
|
|
<body>
|
|
<a class="skip-link" href="#app-main">Aller au contenu principal</a>
|
|
|
|
<div class="page-shell">
|
|
<header class="site-header" role="banner">
|
|
<div class="header-brand-block">
|
|
<a class="brand" href="/?p/index/" aria-label="FWS Linux — Retour à l'accueil">
|
|
<img class="brand-mark" src="/p/assets/img/logo.png" alt="" width="44" height="44" />
|
|
<span class="brand-text">
|
|
<strong>FWS Linux</strong>
|
|
</span>
|
|
</a>
|
|
|
|
<nav class="site-nav" aria-label="Navigation principale">
|
|
<a href="/?p/index/"<?= fws_site_active($route, 'index') ?>>Accueil</a>
|
|
<a href="/?p/dl/"<?= fws_site_active($route, 'dl') ?>>Téléchargements</a>
|
|
|
|
<div class="nav-dropdown" data-nav-dropdown>
|
|
<button type="button" class="nav-dropdown-toggle" aria-expanded="false" aria-haspopup="true" aria-controls="nav-paquets-panel"<?= fws_site_active($route, 'paquets') ?>>
|
|
Paquets
|
|
<span class="nav-dropdown-caret" aria-hidden="true"></span>
|
|
</button>
|
|
<div class="nav-dropdown-panel" id="nav-paquets-panel" role="group" aria-label="Liste des paquets">
|
|
<div class="nav-dropdown-panel-inner">
|
|
<?php if ($packages === []): ?>
|
|
<p class="nav-dropdown-error">Aucun paquet pour le moment.</p>
|
|
<?php else: ?>
|
|
<?php foreach ($packages as $i => $pkg): ?>
|
|
<?php $navThumb = (string) ($pkg['screens'][0]['src'] ?? ''); ?>
|
|
<a class="nav-dropdown-item<?= $navThumb !== '' ? ' has-thumb' : '' ?>" href="/?p/paquets/<?= max($i + 1, (int) $pkg['dbId']) ?>/">
|
|
<?php if ($navThumb !== ''): ?>
|
|
<img class="nav-dropdown-thumb" src="<?= e($navThumb) ?>" alt="" loading="lazy" width="30" height="30">
|
|
<?php endif; ?>
|
|
<span class="nav-dropdown-text">
|
|
<strong><?= e($pkg['name']) ?><?php if (!empty($pkg['latest']['name'])): ?><span class="nav-dropdown-version"><?= e($pkg['latest']['name']) ?></span><?php endif; ?></strong>
|
|
<small><?= e($pkg['tagline'] ?? '') ?></small>
|
|
</span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<a class="nav-dropdown-all" href="/?p/paquets/">Voir tous les paquets →</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
</header>
|
|
|
|
<main id="app-main" class="site-main">
|
|
<?= $body ?>
|
|
</main>
|
|
|
|
<footer class="site-footer" role="contentinfo">
|
|
<div class="footer-content">
|
|
<div class="footer-brand-row">
|
|
<div class="footer-brand-block">
|
|
<img class="footer-brand-mark" src="/p/assets/img/logo.png" alt="" width="40" height="40" />
|
|
<div>
|
|
<strong>FWS Linux</strong>
|
|
<p>Un système léger, libre et compatible</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer-links-grid">
|
|
<nav aria-label="Navigation secondaire">
|
|
<h2>Navigation</h2>
|
|
<a href="/?p/index/">Accueil</a>
|
|
<a href="/?p/dl/">Téléchargements</a>
|
|
<a href="/?p/paquets/">Paquets</a>
|
|
<a href="/?p/equipe/">Équipe</a>
|
|
</nav>
|
|
|
|
<section>
|
|
<h2>Contact</h2>
|
|
<a href="/?p/contact/">Page de contact</a>
|
|
<a href="/?p/equipe/">Équipe</a>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Réseaux</h2>
|
|
<a href="https://github.com/You-re-like-Windows-a-bitch/ISO" target="_blank" rel="noopener noreferrer">GitHub</a>
|
|
<a href="https://discord.gg/6mnpPr2jq4" target="_blank" rel="noopener noreferrer">Discord</a>
|
|
</section>
|
|
</div>
|
|
|
|
<div class="footer-bottom">
|
|
<p>© <?= date('Y') ?> FWS Linux</p>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</div>
|
|
|
|
<script src="<?= e(fws_asset('/p/assets/main-nav/nav.js')) ?>"></script>
|
|
<?php foreach ($extraJs as $js): ?>
|
|
<script src="<?= e(fws_asset($js)) ?>"></script>
|
|
<?php endforeach; ?>
|
|
</body>
|
|
|
|
</html>
|