Clean code
This commit is contained in:
@@ -56,15 +56,13 @@ function app_media_url(string $fileName): string
|
||||
|
||||
// ── Texte ───────────────────────────────────────────────────────────
|
||||
|
||||
function app_slugify(string $value): string
|
||||
{
|
||||
$slug = Web::instance()->slug(trim($value));
|
||||
return $slug !== '' ? $slug : 'article';
|
||||
}
|
||||
|
||||
function app_unique_slug(string $value, callable $exists): string
|
||||
{
|
||||
$base = app_slugify($value);
|
||||
$base = Web::instance()->slug(trim($value));
|
||||
if ($base === '') {
|
||||
$base = 'article';
|
||||
}
|
||||
|
||||
if (!$exists($base)) {
|
||||
return $base;
|
||||
}
|
||||
@@ -97,35 +95,18 @@ function app_format_datetime_fr(string $value): string
|
||||
|
||||
$date = $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
if (class_exists('IntlDateFormatter')) {
|
||||
$formatter ??= new IntlDateFormatter(
|
||||
'fr_FR',
|
||||
IntlDateFormatter::LONG,
|
||||
IntlDateFormatter::SHORT,
|
||||
date_default_timezone_get(),
|
||||
IntlDateFormatter::GREGORIAN,
|
||||
"d MMMM yyyy 'à' HH:mm"
|
||||
);
|
||||
|
||||
$formatted = $formatter->format($date);
|
||||
if (is_string($formatted) && $formatted !== '') {
|
||||
return $formatted;
|
||||
}
|
||||
}
|
||||
|
||||
$months = [
|
||||
1 => 'janvier', 2 => 'février', 3 => 'mars', 4 => 'avril',
|
||||
5 => 'mai', 6 => 'juin', 7 => 'juillet', 8 => 'août',
|
||||
9 => 'septembre', 10 => 'octobre', 11 => 'novembre', 12 => 'décembre',
|
||||
];
|
||||
|
||||
return sprintf(
|
||||
'%d %s %d à %s',
|
||||
(int) $date->format('j'),
|
||||
$months[(int) $date->format('n')] ?? $date->format('F'),
|
||||
(int) $date->format('Y'),
|
||||
$date->format('H:i')
|
||||
$formatter ??= new IntlDateFormatter(
|
||||
'fr_FR',
|
||||
IntlDateFormatter::LONG,
|
||||
IntlDateFormatter::SHORT,
|
||||
date_default_timezone_get(),
|
||||
IntlDateFormatter::GREGORIAN,
|
||||
"d MMMM yyyy 'à' HH:mm"
|
||||
);
|
||||
|
||||
$formatted = $formatter->format($date);
|
||||
|
||||
return is_string($formatted) && $formatted !== '' ? $formatted : $value;
|
||||
} catch (Throwable) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user