Refactor HTMX fragment architecture: DRY split into auth endpoints + shared templates

- Created templates/partials/form/_licence.php (shared HTML, no auth logic)
- Created templates/partials/form/_format-website.php (shared HTML, no auth logic)
- Created src/FragmentRenderer.php helper for clean fragment rendering
- Created public/{admin,partage}/fragments/ subdirectories
- Created thin fragment endpoint files: auth guard + data fetch + render template
- Updated all hx-post references in templates to new fragments/ paths
- Updated partage/index.php routing for new fragments subdirectory
- Kept old fragment files as thin delegates for backward compat
- Updated nginx config: added PHP handler in /partage/ location block
This commit is contained in:
Pontoporeia
2026-05-12 15:01:17 +02:00
parent 2632730fa0
commit da153fc604
38 changed files with 503 additions and 527 deletions

View File

@@ -0,0 +1,45 @@
<?php
/**
* Lightweight HTMX fragment renderer.
*
* Renders a shared template partial without wrapping it in full-page layout
* (no <html>, <head>, <body>, header, or footer).
*
* Usage:
*
* // public/admin/fragments/licence.php
* AdminAuth::requireLogin();
* FragmentRenderer::render('form/_licence', [
* 'accessTypeId' => $_POST['access_type_id'] ?? '',
* 'licenseId' => $_POST['license_id'] ?? '',
* 'licenseTypes' => Database::getInstance()->getAllLicenseTypes(),
* 'cc2r' => !empty($_POST['cc2r']),
* 'wantLicense' => !empty($_POST['want_license']),
* 'adminMode' => true,
* 'hxPost' => '/admin/fragments/licence.php',
* ]);
*
* The template receives all keys in $data as variables via extract().
*/
class FragmentRenderer
{
/**
* Render a template partial for an HTMX fragment response.
*
* @param string $template Path relative to APP_ROOT/templates/partials/ (without .php extension)
* @param array $data Variables to extract into template scope
*/
public static function render(string $template, array $data = []): void
{
// Prevent output buffering from any wrapping layout
if (ob_get_level() === 0) {
ob_start();
}
extract($data, EXTR_SKIP);
require APP_ROOT . '/templates/partials/' . $template . '.php';
ob_end_flush();
}
}