mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
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:
@@ -1,17 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* fichiers-fragment.php (admin)
|
||||
*
|
||||
* Admin-gated HTMX fragment: returns the combined Format(s) + Fichiers block
|
||||
* for the admin add/edit forms. Wraps the shared logic in fichiers-fragment.php
|
||||
* after enforcing authentication.
|
||||
* Admin fragment: Format(s) + Fichiers block (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/fichiers.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
App::boot();
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
$_POST['admin_mode'] = '1';
|
||||
|
||||
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
|
||||
require_once __DIR__ . '/fragments/fichiers.php';
|
||||
|
||||
@@ -1,57 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* format-website-fragment.php (admin)
|
||||
*
|
||||
* Admin-gated HTMX fragment: returns the Site web URL fieldset for the
|
||||
* admin edit form when "Site web" is among the selected format checkboxes.
|
||||
* Uses id="edit-website-url-fieldset" to avoid collision with the partage form.
|
||||
* Admin fragment: Site web format fieldset (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/format-website.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
App::boot();
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
$stmt = $db->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
|
||||
$stmt->execute(['Site web']);
|
||||
$websiteFormatId = $stmt->fetchColumn();
|
||||
|
||||
if (!$websiteFormatId) {
|
||||
echo '<fieldset id="edit-website-url-fieldset" style="display:none"></fieldset>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
|
||||
? array_map('intval', $_POST['formats'])
|
||||
: [];
|
||||
|
||||
if (!in_array((int)$websiteFormatId, $selectedFormats, true)) {
|
||||
echo '<fieldset id="edit-website-url-fieldset" style="display:none"></fieldset>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$websiteUrl = htmlspecialchars($_POST['website_url'] ?? '');
|
||||
$websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
?>
|
||||
<fieldset id="edit-website-url-fieldset">
|
||||
<legend>Site web</legend>
|
||||
<div class="admin-form-group">
|
||||
<label for="website_url">URL du site :</label>
|
||||
<div class="admin-file-input">
|
||||
<input type="url" id="website_url" name="website_url"
|
||||
value="<?= $websiteUrl ?>"
|
||||
placeholder="https://mon-tfe.erg.be">
|
||||
<small>Si le TFE est un site web, entrez son URL ici. Il sera affiché comme un site embarqué sur la page du TFE.</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-form-group">
|
||||
<label for="website_label">Légende :</label>
|
||||
<input type="text" id="website_label" name="website_label"
|
||||
value="<?= $websiteLabel ?>"
|
||||
placeholder="Description du site (optionnel)"
|
||||
class="admin-file-label-input"
|
||||
style="max-width:400px;">
|
||||
</div>
|
||||
</fieldset>
|
||||
require_once __DIR__ . '/fragments/format-website.php';
|
||||
|
||||
13
app/public/admin/fragments/fichiers.php
Normal file
13
app/public/admin/fragments/fichiers.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: Format(s) + Fichiers block (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
App::boot();
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
$_POST['admin_mode'] = '1';
|
||||
|
||||
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
|
||||
29
app/public/admin/fragments/format-website.php
Normal file
29
app/public/admin/fragments/format-website.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: Site web format fieldset (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
App::boot();
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/FragmentRenderer.php';
|
||||
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
$stmt = $db->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
|
||||
$stmt->execute(['Site web']);
|
||||
$websiteFormatId = $stmt->fetchColumn();
|
||||
|
||||
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
|
||||
? array_map('intval', $_POST['formats'])
|
||||
: [];
|
||||
|
||||
FragmentRenderer::render('form/_format-website', [
|
||||
'fieldsetId' => 'edit-website-url-fieldset',
|
||||
'selectedFormats' => $selectedFormats,
|
||||
'websiteFormatId' => $websiteFormatId,
|
||||
'websiteUrl' => $_POST['website_url'] ?? '',
|
||||
'websiteLabel' => $_POST['website_label'] ?? '',
|
||||
]);
|
||||
9
app/public/admin/fragments/language-autre.php
Normal file
9
app/public/admin/fragments/language-autre.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: language-autre asterisk toggle (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/language-autre-fragment.php';
|
||||
10
app/public/admin/fragments/language-search.php
Normal file
10
app/public/admin/fragments/language-search.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: language search (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
App::boot();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/language-search-fragment.php';
|
||||
23
app/public/admin/fragments/licence.php
Normal file
23
app/public/admin/fragments/licence.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: licence section (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/FragmentRenderer.php';
|
||||
|
||||
$licenseTypes = Database::getInstance()->getAllLicenseTypes();
|
||||
|
||||
FragmentRenderer::render('form/_licence', [
|
||||
'adminMode' => true,
|
||||
'accessTypeId' => $_POST['access_type_id'] ?? '',
|
||||
'licenseId' => $_POST['license_id'] ?? '',
|
||||
'licenseCustom' => $_POST['license_custom'] ?? '',
|
||||
'cc2r' => !empty($_POST['cc2r']),
|
||||
'wantLicense' => !empty($_POST['want_license']),
|
||||
'hxPost' => '/admin/fragments/licence.php',
|
||||
'licenseTypes' => $licenseTypes,
|
||||
]);
|
||||
10
app/public/admin/fragments/tag-search.php
Normal file
10
app/public/admin/fragments/tag-search.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: tag search (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
App::boot();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/tag-search-fragment.php';
|
||||
9
app/public/admin/fragments/validate-file.php
Normal file
9
app/public/admin/fragments/validate-file.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin fragment: file validation (HTMX partial).
|
||||
*/
|
||||
require_once __DIR__ . '/../../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/Controllers/validate-file-fragment-shared.php';
|
||||
@@ -1,17 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* language-autre-fragment.php (admin)
|
||||
*
|
||||
* HTMX fragment: returns the "Autre(s) langue(s)" input row.
|
||||
* Called from the shared form partial when a language checkbox changes.
|
||||
*
|
||||
* Expected POST:
|
||||
* languages[] — selected language IDs (may be absent)
|
||||
* language_autre — current free-text value (for repopulation)
|
||||
* Admin fragment: language-autre asterisk toggle (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/language-autre.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/language-autre-fragment.php';
|
||||
require_once __DIR__ . '/fragments/language-autre.php';
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* language-search-fragment.php (admin)
|
||||
*
|
||||
* HTMX fragment: returns matching language suggestions for the
|
||||
* "Autre(s) langue(s)" interactive search input. Admin-auth gated wrapper.
|
||||
* Admin fragment: language search (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/language-search.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
App::boot();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/language-search-fragment.php';
|
||||
require_once __DIR__ . '/fragments/language-search.php';
|
||||
|
||||
@@ -1,109 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* HTMX fragment (admin): renders the licence section with conditional options.
|
||||
*
|
||||
* POST: access_type_id, license_id, license_custom, cc2r, want_license
|
||||
*
|
||||
* Libre (1): CC2r checkbox + licence select/custom (at least one required)
|
||||
* Interne (2): opt-in "Je souhaite appliquer une licence" → CC2r + licence select/custom
|
||||
* Interdit (3): no licence options
|
||||
* Admin fragment: licence section (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/licence.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
$accessTypeId = $_POST['access_type_id'] ?? '';
|
||||
$licenseId = $_POST['license_id'] ?? '';
|
||||
$licenseCustom = $_POST['license_custom'] ?? '';
|
||||
$cc2r = !empty($_POST['cc2r']);
|
||||
$wantLicense = !empty($_POST['want_license']);
|
||||
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
$db = Database::getInstance();
|
||||
$licenseTypes = $db->getAllLicenseTypes();
|
||||
?>
|
||||
|
||||
<div class="licence-license-choice">
|
||||
<?php if ($accessTypeId === '1'): ?>
|
||||
<fieldset class="licence-options-fieldset">
|
||||
<legend>Options de licence</legend>
|
||||
<p class="licence-note">J'autorise que mon TFE soit disponible en libre accès. Je suis conscient·e des responsabilités légales.</p>
|
||||
|
||||
<div class="admin-form-group">
|
||||
<label class="admin-checkbox-label">
|
||||
<input type="checkbox" name="cc2r" value="1"
|
||||
<?= $cc2r ? 'checked' : '' ?>>
|
||||
J'accepte les conditions collectives de réutilisation (CC2r)
|
||||
</label>
|
||||
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
|
||||
</div>
|
||||
|
||||
<div class="licence-or-separator"><span>et / ou</span></div>
|
||||
|
||||
<?php
|
||||
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
|
||||
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
|
||||
include APP_ROOT . '/templates/partials/form/select-field.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
|
||||
$value = htmlspecialchars($licenseCustom);
|
||||
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
|
||||
include APP_ROOT . '/templates/partials/form/text-field.php';
|
||||
?>
|
||||
</fieldset>
|
||||
|
||||
<?php elseif ($accessTypeId === '2'): ?>
|
||||
<fieldset class="licence-options-fieldset">
|
||||
<legend>Options de licence</legend>
|
||||
<p class="licence-note">Mon TFE est accessible sur place et sur la plateforme xamxam par la communauté erg. J'autorise une (ré-)utilisation dans un contexte académique au sein de l'erg.</p>
|
||||
|
||||
<div class="admin-form-group">
|
||||
<label class="admin-checkbox-label">
|
||||
<input type="checkbox" name="want_license" value="1"
|
||||
hx-post="/admin/licence-fragment.php"
|
||||
hx-target=".licence-license-choice"
|
||||
hx-swap="outerHTML"
|
||||
hx-include="closest fieldset"
|
||||
<?= $wantLicense ? 'checked' : '' ?>>
|
||||
<strong>Je souhaite appliquer une licence sur mon TFE</strong>
|
||||
</label>
|
||||
<small>Par défaut, aucune licence spécifique n'est appliquée. Cochez pour en choisir une.</small>
|
||||
</div>
|
||||
|
||||
<?php if ($wantLicense): ?>
|
||||
<div class="admin-form-group">
|
||||
<label class="admin-checkbox-label">
|
||||
<input type="checkbox" name="cc2r" value="1"
|
||||
<?= $cc2r ? 'checked' : '' ?>>
|
||||
J'accepte les conditions collectives de réutilisation (CC2r)
|
||||
</label>
|
||||
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
|
||||
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
|
||||
include APP_ROOT . '/templates/partials/form/select-field.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
|
||||
$value = htmlspecialchars($licenseCustom);
|
||||
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
|
||||
include APP_ROOT . '/templates/partials/form/text-field.php';
|
||||
?>
|
||||
|
||||
<p class="licence-note"><em>Je suis conscient·e des obligations légales venant avec la licence choisie et acquiesce avoir lu la documentation prévue à cet effet par l'erg, ainsi qu'avoir discuté des enjeux des licences avec l'équipe pédagogique.</em></p>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
|
||||
<?php elseif ($accessTypeId === '3'): ?>
|
||||
<fieldset class="licence-options-fieldset">
|
||||
<legend>Options de licence</legend>
|
||||
<p class="licence-note">Mon TFE n'est pas disponible en physique ni sur le site. Une note descriptive est visible publiquement.</p>
|
||||
<p class="licence-note"><em>Aucune licence n'est applicable.</em></p>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
require_once __DIR__ . '/fragments/licence.php';
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* tag-search-fragment.php (admin)
|
||||
*
|
||||
* HTMX fragment: returns matching tag suggestions for the mot-clé
|
||||
* interactive search input. Admin-auth gated wrapper.
|
||||
* Admin fragment: tag search (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/tag-search.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
|
||||
AdminAuth::requireLogin();
|
||||
App::boot();
|
||||
|
||||
require_once APP_ROOT . '/public/partage/tag-search-fragment.php';
|
||||
require_once __DIR__ . '/fragments/tag-search.php';
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* validate-file-fragment.php (admin)
|
||||
*
|
||||
* Admin-gated HTMX fragment: validates uploaded file MIME type and size.
|
||||
* Wraps the shared validation logic.
|
||||
* Admin fragment: file validation (HTMX partial).
|
||||
* @deprecated Use /admin/fragments/validate-file.php instead.
|
||||
*/
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/Controllers/validate-file-fragment-shared.php';
|
||||
require_once __DIR__ . '/fragments/validate-file.php';
|
||||
|
||||
Reference in New Issue
Block a user