mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
some css changes
This commit is contained in:
@@ -21,16 +21,16 @@
|
||||
*/
|
||||
class SearchController
|
||||
{
|
||||
private const RATE_LIMIT_MAX = 30;
|
||||
private const RATE_LIMIT_WINDOW = 60; // seconds
|
||||
private const ITEMS_PER_PAGE = 30;
|
||||
private const RATE_LIMIT_MAX = 30;
|
||||
private const RATE_LIMIT_WINDOW = 60; // seconds
|
||||
private const ITEMS_PER_PAGE = 30;
|
||||
|
||||
private Database $db;
|
||||
private Database $db;
|
||||
private RateLimit $rateLimit;
|
||||
|
||||
public function __construct(Database $db, RateLimit $rateLimit)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->db = $db;
|
||||
$this->rateLimit = $rateLimit;
|
||||
}
|
||||
|
||||
@@ -42,10 +42,13 @@ class SearchController
|
||||
*/
|
||||
public static function create(): self
|
||||
{
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/RateLimit.php';
|
||||
require_once APP_ROOT . "/src/Database.php";
|
||||
require_once APP_ROOT . "/src/RateLimit.php";
|
||||
|
||||
$rateLimit = new RateLimit(self::RATE_LIMIT_MAX, self::RATE_LIMIT_WINDOW);
|
||||
$rateLimit = new RateLimit(
|
||||
self::RATE_LIMIT_MAX,
|
||||
self::RATE_LIMIT_WINDOW,
|
||||
);
|
||||
|
||||
if (!$rateLimit->check()) {
|
||||
self::sendRateLimitResponse($rateLimit);
|
||||
@@ -71,65 +74,74 @@ class SearchController
|
||||
*/
|
||||
public function handleSearch(): array
|
||||
{
|
||||
$searchParams = $this->collectSearchParams();
|
||||
$page = isset($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
|
||||
$offset = ($page - 1) * self::ITEMS_PER_PAGE;
|
||||
$searchParams = $this->collectSearchParams();
|
||||
$page = isset($_GET["page"]) ? max(1, (int) $_GET["page"]) : 1;
|
||||
$offset = ($page - 1) * self::ITEMS_PER_PAGE;
|
||||
$validationError = null;
|
||||
|
||||
$results = [];
|
||||
$totalItems = 0;
|
||||
$totalPages = 0;
|
||||
$years = [];
|
||||
$results = [];
|
||||
$totalItems = 0;
|
||||
$totalPages = 0;
|
||||
$years = [];
|
||||
$orientations = [];
|
||||
$apPrograms = [];
|
||||
$apPrograms = [];
|
||||
|
||||
try {
|
||||
$results = $this->db->searchTheses($searchParams, self::ITEMS_PER_PAGE, $offset);
|
||||
$results = $this->db->searchTheses(
|
||||
$searchParams,
|
||||
self::ITEMS_PER_PAGE,
|
||||
$offset,
|
||||
);
|
||||
$totalItems = $this->db->countSearchResults($searchParams);
|
||||
$totalPages = (int) ceil($totalItems / self::ITEMS_PER_PAGE);
|
||||
$years = $this->db->getAvailableYears();
|
||||
$years = $this->db->getAvailableYears();
|
||||
$orientations = $this->db->getAllOrientations();
|
||||
$apPrograms = $this->db->getAllAPPrograms();
|
||||
$apPrograms = $this->db->getAllAPPrograms();
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$validationError = $e->getMessage();
|
||||
} catch (Exception $e) {
|
||||
error_log('SearchController: ' . $e->getMessage());
|
||||
$validationError = 'Une erreur est survenue.';
|
||||
error_log("SearchController: " . $e->getMessage());
|
||||
$validationError = "Une erreur est survenue.";
|
||||
}
|
||||
|
||||
// Preserve all active params, strip 'page' (pagination partial adds it)
|
||||
$baseParams = array_diff_key($_GET, ['page' => '']);
|
||||
$baseParams = array_diff_key($_GET, ["page" => ""]);
|
||||
|
||||
$query = $_GET['query'] ?? '';
|
||||
$query = $_GET["query"] ?? "";
|
||||
|
||||
return [
|
||||
'searchParams' => $searchParams,
|
||||
'page' => $page,
|
||||
'totalItems' => $totalItems,
|
||||
'totalPages' => $totalPages,
|
||||
'results' => $results,
|
||||
'validationError' => $validationError,
|
||||
'baseParams' => $baseParams,
|
||||
"searchParams" => $searchParams,
|
||||
"page" => $page,
|
||||
"totalItems" => $totalItems,
|
||||
"totalPages" => $totalPages,
|
||||
"results" => $results,
|
||||
"validationError" => $validationError,
|
||||
"baseParams" => $baseParams,
|
||||
|
||||
// Filter dropdowns
|
||||
'years' => $years,
|
||||
'orientations' => $orientations,
|
||||
'apPrograms' => $apPrograms,
|
||||
"years" => $years,
|
||||
"orientations" => $orientations,
|
||||
"apPrograms" => $apPrograms,
|
||||
|
||||
// Page meta
|
||||
'searchBarValue' => $query,
|
||||
'pageTitle' => $query !== '' ? 'Recherche : ' . $query . ' – Posterg' : 'Recherche – Posterg',
|
||||
'metaDescription' => "Résultats de recherche dans le répertoire des TFE de l'erg.",
|
||||
'ogTags' => [
|
||||
'type' => 'website',
|
||||
'title' => 'Recherche – Posterg',
|
||||
'description' => "Résultats de recherche dans le répertoire des TFE de l'erg.",
|
||||
'url' => 'https://posterg.erg.be/search',
|
||||
'site_name' => 'Posterg – ERG',
|
||||
"searchBarValue" => $query,
|
||||
"pageTitle" =>
|
||||
$query !== ""
|
||||
? "Recherche : " . $query . " – Posterg"
|
||||
: "Recherche – Posterg",
|
||||
"metaDescription" =>
|
||||
"Résultats de recherche dans le répertoire des TFE de l'erg.",
|
||||
"ogTags" => [
|
||||
"type" => "website",
|
||||
"title" => "Recherche – Posterg",
|
||||
"description" =>
|
||||
"Résultats de recherche dans le répertoire des TFE de l'erg.",
|
||||
"url" => "https://posterg.erg.be/search",
|
||||
"site_name" => "Posterg – ERG",
|
||||
],
|
||||
'currentNav' => 'repertoire',
|
||||
'extraCss' => ['/assets/css/search.css'],
|
||||
'bodyClass' => 'search-body',
|
||||
"currentNav" => "repertoire",
|
||||
"extraCss" => ["/assets/css/repertoire.css"],
|
||||
"bodyClass" => "search-body",
|
||||
];
|
||||
}
|
||||
|
||||
@@ -141,9 +153,9 @@ class SearchController
|
||||
*/
|
||||
public function handleRepertoire(): array
|
||||
{
|
||||
$isHtmx = !empty($_SERVER['HTTP_HX_REQUEST']);
|
||||
$isHtmx = !empty($_SERVER["HTTP_HX_REQUEST"]);
|
||||
$activeFilters = $this->collectFilterParams();
|
||||
$repData = null;
|
||||
$repData = null;
|
||||
$validationError = null;
|
||||
|
||||
try {
|
||||
@@ -151,8 +163,8 @@ class SearchController
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$validationError = $e->getMessage();
|
||||
} catch (Exception $e) {
|
||||
error_log('SearchController: ' . $e->getMessage());
|
||||
$validationError = 'Une erreur est survenue.';
|
||||
error_log("SearchController: " . $e->getMessage());
|
||||
$validationError = "Une erreur est survenue.";
|
||||
}
|
||||
|
||||
// HTMX partial: render just the index div and exit
|
||||
@@ -161,25 +173,27 @@ class SearchController
|
||||
}
|
||||
|
||||
return [
|
||||
'repData' => $repData,
|
||||
'activeFilters' => $activeFilters,
|
||||
'isHtmx' => $isHtmx,
|
||||
'validationError' => $validationError,
|
||||
"repData" => $repData,
|
||||
"activeFilters" => $activeFilters,
|
||||
"isHtmx" => $isHtmx,
|
||||
"validationError" => $validationError,
|
||||
|
||||
// Page meta
|
||||
'searchBarValue' => '',
|
||||
'pageTitle' => 'Répertoire – Posterg',
|
||||
'metaDescription' => "Parcourez le répertoire des mémoires de fin d'études (TFE) de l'erg – École de Recherches Graphiques de Bruxelles.",
|
||||
'ogTags' => [
|
||||
'type' => 'website',
|
||||
'title' => 'Répertoire – Posterg',
|
||||
'description' => "Parcourez le répertoire des mémoires de fin d'études (TFE) de l'erg – École de Recherches Graphiques de Bruxelles.",
|
||||
'url' => 'https://posterg.erg.be/repertoire',
|
||||
'site_name' => 'Posterg – ERG',
|
||||
"searchBarValue" => "",
|
||||
"pageTitle" => "Répertoire – Posterg",
|
||||
"metaDescription" =>
|
||||
"Parcourez le répertoire des mémoires de fin d'études (TFE) de l'erg – École de Recherches Graphiques de Bruxelles.",
|
||||
"ogTags" => [
|
||||
"type" => "website",
|
||||
"title" => "Répertoire – Posterg",
|
||||
"description" =>
|
||||
"Parcourez le répertoire des mémoires de fin d'études (TFE) de l'erg – École de Recherches Graphiques de Bruxelles.",
|
||||
"url" => "https://posterg.erg.be/repertoire",
|
||||
"site_name" => "Posterg – ERG",
|
||||
],
|
||||
'currentNav' => 'repertoire',
|
||||
'extraCss' => ['/assets/css/search.css'],
|
||||
'bodyClass' => 'search-body',
|
||||
"currentNav" => "repertoire",
|
||||
"extraCss" => ["/assets/css/repertoire.css"],
|
||||
"bodyClass" => "search-body",
|
||||
];
|
||||
}
|
||||
|
||||
@@ -189,12 +203,14 @@ class SearchController
|
||||
* Render the repertoire index partial and exit (for HTMX swaps).
|
||||
* Never returns.
|
||||
*/
|
||||
private function renderRepertoirePartial(array $repData, array $activeFilters): never
|
||||
{
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
private function renderRepertoirePartial(
|
||||
array $repData,
|
||||
array $activeFilters,
|
||||
): never {
|
||||
header("Content-Type: text/html; charset=UTF-8");
|
||||
$isHtmx = true;
|
||||
include APP_ROOT . '/templates/partials/repertoire-index.php';
|
||||
exit;
|
||||
include APP_ROOT . "/templates/partials/repertoire-index.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,12 +222,14 @@ class SearchController
|
||||
*/
|
||||
private function collectFilterParams(): array
|
||||
{
|
||||
$sanitiseStrings = function(mixed $raw, int $maxLen = 100): array {
|
||||
if (!is_array($raw)) return [];
|
||||
$sanitiseStrings = function (mixed $raw, int $maxLen = 100): array {
|
||||
if (!is_array($raw)) {
|
||||
return [];
|
||||
}
|
||||
$out = [];
|
||||
foreach ($raw as $v) {
|
||||
$v = trim((string)$v);
|
||||
if ($v !== '' && strlen($v) <= $maxLen) {
|
||||
$v = trim((string) $v);
|
||||
if ($v !== "" && strlen($v) <= $maxLen) {
|
||||
$out[] = $v;
|
||||
}
|
||||
}
|
||||
@@ -219,20 +237,22 @@ class SearchController
|
||||
};
|
||||
|
||||
$years = [];
|
||||
if (!empty($_GET['fy']) && is_array($_GET['fy'])) {
|
||||
foreach ($_GET['fy'] as $y) {
|
||||
$y = (int)$y;
|
||||
if ($y >= 1900 && $y <= 2100) $years[] = $y;
|
||||
if (!empty($_GET["fy"]) && is_array($_GET["fy"])) {
|
||||
foreach ($_GET["fy"] as $y) {
|
||||
$y = (int) $y;
|
||||
if ($y >= 1900 && $y <= 2100) {
|
||||
$years[] = $y;
|
||||
}
|
||||
}
|
||||
$years = array_values(array_unique($years));
|
||||
}
|
||||
|
||||
return [
|
||||
'years' => $years,
|
||||
'ap' => $sanitiseStrings($_GET['ap'] ?? []),
|
||||
'or' => $sanitiseStrings($_GET['or'] ?? []),
|
||||
'fi' => $sanitiseStrings($_GET['fi'] ?? []),
|
||||
'kw' => $sanitiseStrings($_GET['kw'] ?? []),
|
||||
"years" => $years,
|
||||
"ap" => $sanitiseStrings($_GET["ap"] ?? []),
|
||||
"or" => $sanitiseStrings($_GET["or"] ?? []),
|
||||
"fi" => $sanitiseStrings($_GET["fi"] ?? []),
|
||||
"kw" => $sanitiseStrings($_GET["kw"] ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -245,20 +265,20 @@ class SearchController
|
||||
{
|
||||
$params = [];
|
||||
|
||||
if (!empty($_GET['query'])) {
|
||||
$params['query'] = trim((string) $_GET['query']);
|
||||
if (!empty($_GET["query"])) {
|
||||
$params["query"] = trim((string) $_GET["query"]);
|
||||
}
|
||||
if (!empty($_GET['year'])) {
|
||||
$params['year'] = (int) $_GET['year'];
|
||||
if (!empty($_GET["year"])) {
|
||||
$params["year"] = (int) $_GET["year"];
|
||||
}
|
||||
if (!empty($_GET['orientation'])) {
|
||||
$params['orientation'] = (string) $_GET['orientation'];
|
||||
if (!empty($_GET["orientation"])) {
|
||||
$params["orientation"] = (string) $_GET["orientation"];
|
||||
}
|
||||
if (!empty($_GET['ap_program'])) {
|
||||
$params['ap_program'] = (string) $_GET['ap_program'];
|
||||
if (!empty($_GET["ap_program"])) {
|
||||
$params["ap_program"] = (string) $_GET["ap_program"];
|
||||
}
|
||||
if (!empty($_GET['keyword'])) {
|
||||
$params['keyword'] = (string) $_GET['keyword'];
|
||||
if (!empty($_GET["keyword"])) {
|
||||
$params["keyword"] = (string) $_GET["keyword"];
|
||||
}
|
||||
|
||||
return $params;
|
||||
@@ -272,48 +292,48 @@ class SearchController
|
||||
private static function sendRateLimitResponse(RateLimit $rateLimit): never
|
||||
{
|
||||
http_response_code(429);
|
||||
header('Retry-After: ' . $rateLimit->getResetTime());
|
||||
header("Retry-After: " . $rateLimit->getResetTime());
|
||||
$retrySeconds = (int) $rateLimit->getResetTime();
|
||||
|
||||
echo <<<HTML
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Trop de requêtes – Posterg</title>
|
||||
<style>
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
background: #0d0d0d;
|
||||
color: #e0e0e0;
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
}
|
||||
.box { max-width: 520px; text-align: center; }
|
||||
.box__logo {
|
||||
font-size: 1.1rem; font-weight: 700;
|
||||
letter-spacing: .12em; text-transform: uppercase;
|
||||
color: #fff; margin-bottom: 2.5rem;
|
||||
}
|
||||
.box__title { font-size: 1.6rem; font-weight: 300; margin-bottom: 1rem; }
|
||||
.box__text { font-size: .95rem; color: #999; line-height: 1.7; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<div class="box__logo">POSTERG</div>
|
||||
<h1 class="box__title">Trop de requêtes</h1>
|
||||
<p class="box__text">Vous avez effectué trop de recherches en peu de temps.<br>
|
||||
Réessayez dans {$retrySeconds} secondes.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
exit;
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Trop de requêtes – Posterg</title>
|
||||
<style>
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
background: #0d0d0d;
|
||||
color: #e0e0e0;
|
||||
font-family: 'Helvetica Neue', Arial, sans-serif;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
}
|
||||
.box { max-width: 520px; text-align: center; }
|
||||
.box__logo {
|
||||
font-size: 1.1rem; font-weight: 700;
|
||||
letter-spacing: .12em; text-transform: uppercase;
|
||||
color: #fff; margin-bottom: 2.5rem;
|
||||
}
|
||||
.box__title { font-size: 1.6rem; font-weight: 300; margin-bottom: 1rem; }
|
||||
.box__text { font-size: .95rem; color: #999; line-height: 1.7; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<div class="box__logo">POSTERG</div>
|
||||
<h1 class="box__title">Trop de requêtes</h1>
|
||||
<p class="box__text">Vous avez effectué trop de recherches en peu de temps.<br>
|
||||
Réessayez dans {$retrySeconds} secondes.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user