Template
Root-absolute asset paths and ?p= links broke when the site is served from a subfolder (WAMP). Screenshots from the database and avatars from creators.json go through fws_url() as well.
122 lines
5.1 KiB
PHP
122 lines
5.1 KiB
PHP
<?php
|
|
/**
|
|
* FWS Linux — page Paquets (liste) : rendu serveur depuis la base SQLite
|
|
* (avec releases Gitea fusionnées). Remplace packages.js.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
if (!defined('FWS_PAGE_SHELL')) {
|
|
/* Accès direct (/p/paquets/…) : on délègue au front controller. */
|
|
require __DIR__ . '/../../page.php';
|
|
exit;
|
|
}
|
|
|
|
$title = 'Paquets | FWS Linux';
|
|
$description = 'Les outils développés pour FWS Linux — historique de chaque paquet, captures d\'écran et liens utiles.';
|
|
$extraJs[] = fws_url('/p/assets/js/packages-ui.js');
|
|
|
|
function fws_packages_empty(string $message): string
|
|
{
|
|
return '<p class="paquet-empty">' . e($message) . '</p>';
|
|
}
|
|
|
|
/**
|
|
* Historique du paquet. En liste ($limited) : seules les 3 dernières
|
|
* versions sont visibles, un bouton « Voir plus » affiche les autres.
|
|
*/
|
|
function fws_packages_changelog(array $pkg, bool $limited = false): string
|
|
{
|
|
$html = '<div class="paquet-changelog"><h3>Historique</h3>';
|
|
if (empty($pkg['changelog'])) {
|
|
$html .= fws_packages_empty('Historique en cours de rédaction.') . '</div>';
|
|
return $html;
|
|
}
|
|
$entries = array_values($pkg['changelog']);
|
|
$total = count($entries);
|
|
$extraCount = 0;
|
|
if ($limited && $total > 3) {
|
|
$extraCount = $total - 3;
|
|
}
|
|
$html .= '<ol class="paquet-timeline"';
|
|
if ($extraCount > 0) {
|
|
$html .= ' data-expandable';
|
|
}
|
|
$html .= '>';
|
|
foreach ($entries as $idx => $entry) {
|
|
$html .= '<li class="paquet-timeline-item' . ($idx >= 3 ? ' paquet-timeline-extra' : '') . '">'
|
|
. '<strong class="paquet-timeline-version">' . e((string) ($entry['version'] ?? '—')) . '</strong>'
|
|
. '<time class="paquet-timeline-date"' . (empty($entry['date']) ? '' : ' datetime="' . e((string) $entry['date']) . '"') . '>'
|
|
. e(fws_format_date(isset($entry['date']) ? (string) $entry['date'] : null)) . '</time>'
|
|
. (!empty($entry['notes']) ? '<span class="paquet-timeline-notes">' . e((string) $entry['notes']) . '</span>' : '')
|
|
. '</li>';
|
|
}
|
|
$html .= '</ol>';
|
|
if ($extraCount > 0) {
|
|
$html .= '<button type="button" class="paquet-more" data-toggle-timeline data-label="Voir plus (' . $extraCount . ')">Voir plus (' . $extraCount . ')</button>';
|
|
}
|
|
$html .= '</div>';
|
|
return $html;
|
|
}
|
|
|
|
/* Les captures d'écran ne s'affichent que sur la page détail
|
|
(« Voir en grand ») : la liste reste compacte. */
|
|
|
|
function fws_packages_links(array $pkg): string
|
|
{
|
|
$html = '<div class="paquet-links"><h3>Liens utiles</h3>';
|
|
if (empty($pkg['links'])) {
|
|
$html .= fws_packages_empty('Aucun lien pour le moment.') . '</div>';
|
|
return $html;
|
|
}
|
|
foreach ($pkg['links'] as $link) {
|
|
$url = (string) ($link['url'] ?? '');
|
|
$external = (bool) preg_match('/^https?:\/\//i', $url);
|
|
$html .= '<a class="button button-secondary" href="' . e($url) . '"'
|
|
. ($external ? ' target="_blank" rel="noopener noreferrer"' : '') . '>'
|
|
. e((string) ($link['label'] ?? '') !== '' ? (string) $link['label'] : $url) . '</a>';
|
|
}
|
|
$html .= '</div>';
|
|
return $html;
|
|
}
|
|
|
|
function fws_packages_card(array $pkg, int $position): string
|
|
{
|
|
$latest = $pkg['latest'] ?? null;
|
|
$latestText = ($latest !== null && ($latest['name'] ?? '') !== '')
|
|
? 'Dernière release : ' . $latest['name'] . (!empty($latest['date']) ? ' — ' . fws_format_date((string) $latest['date']) : '')
|
|
: 'Aucune release publiée pour le moment.';
|
|
|
|
/* En liste : pas d'images (elles ne s'affichent que sur la page
|
|
« Voir en grand »), et seules les 3 dernières versions. */
|
|
$html = '<article class="paquet-card" id="paquet-' . e((string) $pkg['id']) . '">'
|
|
. '<header class="paquet-head"><div class="paquet-title-row">'
|
|
. '<h2>' . e($pkg['name']) . '</h2>'
|
|
. '<span class="paquet-since" title="' . (!empty($pkg['since']) ? e('Depuis le ' . fws_format_date((string) $pkg['since'])) : '') . '">'
|
|
. e($pkg['sinceLabel'] !== '' ? $pkg['sinceLabel'] : 'FWS') . '</span>'
|
|
. '<a class="paquet-detail-link" href="' . e(fws_url('/?p/paquets/' . $position . '/')) . '">Voir en grand</a>'
|
|
. '</div>'
|
|
. (!empty($pkg['tagline']) ? '<p class="paquet-tagline">' . e($pkg['tagline']) . '</p>' : '')
|
|
. '<p class="paquet-latest">' . e($latestText) . '</p>'
|
|
. (!empty($pkg['description']) ? '<p class="paquet-description">' . e($pkg['description']) . '</p>' : '')
|
|
. '</header>'
|
|
. '<div class="paquet-body">' . fws_packages_changelog($pkg, true) . fws_packages_links($pkg) . '</div>'
|
|
. '</article>';
|
|
return $html;
|
|
}
|
|
?>
|
|
<section class="paquets-hero">
|
|
<h1>Paquets</h1>
|
|
<p>Tous les outils développés pour FWS Linux, leur historique, leurs captures d'écran et les liens utiles.</p>
|
|
</section>
|
|
|
|
<section class="paquets-list" aria-label="Liste des paquets FWS">
|
|
<?php if ($packages === []): ?>
|
|
<?= fws_packages_empty('Aucun paquet pour le moment. Revenez bientôt !') ?>
|
|
<?php else: ?>
|
|
<?php foreach ($packages as $i => $pkg): ?>
|
|
<?= fws_packages_card($pkg, max($i + 1, (int) ($pkg['dbId'] ?? 0))) . "\n" ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</section>
|