Ajouter les pages personnalisées au site public
This commit is contained in:
parent
9e05196440
commit
21ee1bec36
17 changed files with 428 additions and 65 deletions
|
|
@ -13,8 +13,8 @@ final class PublicSiteController
|
|||
if ($path === '/site' || str_starts_with($path, '/site/')) {
|
||||
return true;
|
||||
}
|
||||
return self::usesRoot() &&
|
||||
in_array(
|
||||
if (!self::usesRoot()) return false;
|
||||
if (in_array(
|
||||
$path,
|
||||
[
|
||||
'/',
|
||||
|
|
@ -28,7 +28,9 @@ final class PublicSiteController
|
|||
'/logo-association',
|
||||
],
|
||||
true,
|
||||
);
|
||||
)) return true;
|
||||
return (bool) preg_match('#^/[a-z0-9-]+$#', $path)
|
||||
&& PublicPageService::findBySlug(trim($path, '/')) !== null;
|
||||
}
|
||||
public static function url(string $page = 'home', array $query = []): string
|
||||
{
|
||||
|
|
@ -43,8 +45,10 @@ final class PublicSiteController
|
|||
'legal' => $root ? '/mentions-legales' : '/site/mentions-legales',
|
||||
'privacy' => $root ? '/confidentialite' : '/site/confidentialite',
|
||||
'logo' => $root ? '/logo-association' : '/site/logo',
|
||||
'custom' => ($root ? '/' : '/site/page/') . PublicPageService::normalizeSlug((string) ($query['slug'] ?? '')),
|
||||
default => $root ? '/' : '/site',
|
||||
};
|
||||
unset($query['slug']);
|
||||
return $path . ($query ? '?' . http_build_query($query) : '');
|
||||
}
|
||||
public static function dispatch(string $path): void
|
||||
|
|
@ -59,6 +63,10 @@ final class PublicSiteController
|
|||
self::logo();
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/site/page/([a-z0-9-]+)$#', $path, $match)) {
|
||||
self::customPage($match[1]);
|
||||
return;
|
||||
}
|
||||
match ($path) {
|
||||
'/site', '/site/' => self::home(),
|
||||
'/site/animaux' => self::animals(),
|
||||
|
|
@ -73,7 +81,7 @@ final class PublicSiteController
|
|||
}
|
||||
private static function normalize(string $path): string
|
||||
{
|
||||
return match ($path) {
|
||||
$normalized = match ($path) {
|
||||
'/' => '/site',
|
||||
'/animaux' => '/site/animaux',
|
||||
'/adoption' => '/site/animal',
|
||||
|
|
@ -85,6 +93,11 @@ final class PublicSiteController
|
|||
'/logo-association' => '/site/logo',
|
||||
default => $path,
|
||||
};
|
||||
if ($normalized === $path && self::usesRoot() && preg_match('#^/([a-z0-9-]+)$#', $path, $match)
|
||||
&& PublicPageService::findBySlug($match[1]) !== null) {
|
||||
return '/site/page/' . $match[1];
|
||||
}
|
||||
return $normalized;
|
||||
}
|
||||
private static function home(): void
|
||||
{
|
||||
|
|
@ -160,6 +173,20 @@ final class PublicSiteController
|
|||
'kind' => 'about',
|
||||
]);
|
||||
}
|
||||
private static function customPage(string $slug): void
|
||||
{
|
||||
$page = PublicPageService::findBySlug($slug);
|
||||
if (!$page) {
|
||||
self::notFound();
|
||||
return;
|
||||
}
|
||||
self::render('public_site_text.php', [
|
||||
'title' => $page['title'],
|
||||
'content' => $page['content'],
|
||||
'kind' => 'custom',
|
||||
'customPage' => $page,
|
||||
]);
|
||||
}
|
||||
private static function legal(): void
|
||||
{
|
||||
self::render('public_site_text.php', [
|
||||
|
|
@ -262,6 +289,7 @@ final class PublicSiteController
|
|||
extract($vars, EXTR_SKIP);
|
||||
$settings = AppSettings::all();
|
||||
$publicSpecies = self::species();
|
||||
$publicPages = PublicPageService::all(true);
|
||||
require dirname(__DIR__) . '/Views/public_site_layout.php';
|
||||
}
|
||||
private static function notFound(): void
|
||||
|
|
|
|||
Loading…
Reference in a new issue