mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: extract MediaController, wire into Dispatcher, delete media.php
This commit is contained in:
67
app/templates/partials/status-badge.php
Normal file
67
app/templates/partials/status-badge.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Status badge partial.
|
||||
*
|
||||
* Renders a single <span class="status-badge …"> with a decorative symbol,
|
||||
* an aria-label, and the visible label text.
|
||||
*
|
||||
* Variables (set before include):
|
||||
*
|
||||
* $badgeType (string) One of:
|
||||
* 'publish' — publish/pending state (uses $badgeValue as bool)
|
||||
* 'access' — access-type label (uses $badgeValue as string name)
|
||||
* 'ok' — generic green/yellow ok-or-warn (uses $badgeValue as bool)
|
||||
*
|
||||
* $badgeValue (mixed) Meaning depends on $badgeType (see above).
|
||||
*
|
||||
* $badgeOkLabel (string, optional) Label when ok/published/true. Default: 'Oui'
|
||||
* $badgeWarnLabel (string, optional) Label when warn/pending/false. Default: 'Non'
|
||||
* $badgeContext (string, optional) Prefix for aria-label, e.g. 'Statut'.
|
||||
* When empty the visible label is used directly.
|
||||
*
|
||||
* Example — publish badge:
|
||||
* <?php $badgeType = 'publish'; $badgeValue = $thesis['is_published']; include PARTIALS . '/status-badge.php'; ?>
|
||||
*
|
||||
* Example — access badge:
|
||||
* <?php $badgeType = 'access'; $badgeValue = $thesis['access_type']; include PARTIALS . '/status-badge.php'; ?>
|
||||
*
|
||||
* Example — generic ok badge:
|
||||
* <?php $badgeType = 'ok'; $badgeValue = $hasPassword; $badgeOkLabel = 'Active'; $badgeWarnLabel = 'Non configurée'; $badgeContext = ''; include PARTIALS . '/status-badge.php'; ?>
|
||||
*/
|
||||
|
||||
$badgeType = $badgeType ?? 'ok';
|
||||
$badgeValue = $badgeValue ?? false;
|
||||
$badgeOkLabel = $badgeOkLabel ?? 'Oui';
|
||||
$badgeWarnLabel = $badgeWarnLabel ?? 'Non';
|
||||
$badgeContext = $badgeContext ?? null; // null = use visible label as aria-label
|
||||
|
||||
if ($badgeType === 'publish') {
|
||||
$isOk = (bool) $badgeValue;
|
||||
$symbol = $isOk ? '●' : '◌';
|
||||
$cssClass = $isOk ? 'status-published' : 'status-pending';
|
||||
$visibleLabel = $isOk ? 'Publié' : 'En attente';
|
||||
$ariaLabel = 'Statut : ' . $visibleLabel;
|
||||
} elseif ($badgeType === 'access') {
|
||||
$accessName = (string) $badgeValue;
|
||||
$accessSlug = strtolower(preg_replace('/[^a-z]/i', '', $accessName));
|
||||
$symbols = ['libre' => '○', 'interne' => '◑', 'interdit' => '●'];
|
||||
$symbol = $symbols[$accessSlug] ?? '●';
|
||||
$cssClass = 'status-access status-access--' . $accessSlug;
|
||||
$visibleLabel = $accessName;
|
||||
$ariaLabel = 'Accès : ' . $visibleLabel;
|
||||
} else {
|
||||
// 'ok' — generic boolean badge
|
||||
$isOk = (bool) $badgeValue;
|
||||
$symbol = $isOk ? '●' : '◌';
|
||||
$cssClass = $isOk ? 'status-published' : 'status-pending';
|
||||
$visibleLabel = $isOk ? $badgeOkLabel : $badgeWarnLabel;
|
||||
$ariaLabel = $badgeContext !== null
|
||||
? ($badgeContext !== '' ? $badgeContext . ' : ' . $visibleLabel : $visibleLabel)
|
||||
: $visibleLabel;
|
||||
}
|
||||
?>
|
||||
<span class="status-badge <?= $cssClass ?>" aria-label="<?= htmlspecialchars($ariaLabel) ?>"><span aria-hidden="true"><?= $symbol ?> </span><?= htmlspecialchars($visibleLabel) ?></span>
|
||||
<?php
|
||||
// Clean up variables so they don't bleed into the including scope.
|
||||
unset($badgeType, $badgeValue, $badgeOkLabel, $badgeWarnLabel, $badgeContext,
|
||||
$isOk, $accessName, $accessSlug, $symbols, $symbol, $cssClass, $visibleLabel, $ariaLabel);
|
||||
Reference in New Issue
Block a user