Fix HomePageId

This commit is contained in:
Fred Tempez 2023-09-30 13:35:20 +02:00
parent 54087cec56
commit 589da60177
10 changed files with 73 additions and 24 deletions

View File

@ -33,7 +33,7 @@ class layout extends common
$item .= '<p>' . $this->getData(['config', 'cookies', 'mainLabel']) . '</p>';
// Formulaire de réponse
if (
$this->getData(['config', 'homePageId']) === $this->getUrl(0)
$this->homePageId() === $this->getUrl(0)
) {
$item .= '<form method="POST" action="' . helper::baseUrl(false) . '" id="cookieForm">';
} else {
@ -790,7 +790,7 @@ class layout extends common
echo '<title>' . $this->core->output['metaTitle'] . '</title>';
echo '<meta property="og:title" content="' . $this->core->output['metaTitle'] . '" />';
if (
$this->getData(['config', 'homePageId']) === $this->getUrl(0)
$this->homePageId() === $this->getUrl(0)
) {
echo '<link rel="canonical" href="' . helper::baseUrl(false) . '" />';
} else {

View File

@ -536,7 +536,7 @@ class core extends common
) {
$access = true;
} else {
if ($this->getUrl(0) === $this->getData(['config', 'homePageId'])) {
if ($this->getUrl(0) === $this->homePageId()) {
$access = 'login';
} else {
$access = false;

View File

@ -401,7 +401,7 @@ class common
if ($url = $_SERVER['QUERY_STRING']) {
$this->url = $url;
} else {
$this->url = $this->getData(['config', 'homePageId']);
$this->url = $this->homePageId();
}
}
@ -1051,7 +1051,7 @@ class common
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
if ($this->getData(['page', $parentPageId, 'disable']) !== true) {
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($parentPageId !== $this->getData(['config', 'homePageId'])) ? $parentPageId : '';
$pageId = ($parentPageId !== $this->homePageId()) ? $parentPageId : '';
$sitemap->addUrl('/' . $pageId, $datetime);
}
// Articles du blog
@ -1072,7 +1072,7 @@ class common
continue;
}
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($childKey !== $this->getData(['config', 'homePageId'])) ? $childKey : '';
$pageId = ($childKey !== $this->homePageId()) ? $childKey : '';
$sitemap->addUrl('/' . $childKey, $datetime);
// La sous-page est un blog
@ -1369,6 +1369,21 @@ class common
$zip->close();
}
/**
* Retourne l'id de la page d'accueil
* @return string pageId
*/
public function homePageId()
{
switch (self::$siteContent) {
case 'home':
return ($this->getData(['config', 'homePageId']));
default:
return ($this->getData(['course', self::$siteContent, 'homePageId']));
}
}
/**
* Journalisation

View File

@ -46,7 +46,7 @@
<div class="col4">
<?php echo template::select('configLocaleHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil',
'selected' => $this->getData(['config', 'homePageId']),
'selected' => $this->homePageId(),
'help' => 'La première page que vos visiteurs verront.'
]); ?>
</div>

View File

@ -48,18 +48,20 @@ class course extends common
public static $swapMessage = [];
public static $pagesList = [];
public function index()
{
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle');
ksort($courseIdShortTitle);
foreach ($courseIdShortTitle as $courseId => $courseTitle) {
$categorieUrl = helper::baseUrl(!helper::checkRewrite()) . 'course/swap/' . $courseId ;
$categorieUrl = helper::baseUrl(!helper::checkRewrite()) . 'course/swap/' . $courseId;
self::$courses[] = [
$courseTitle,
$this->getData(['course', $courseId, 'author']),
$this->getData(['course', $courseId, 'description']),
'<a href="' . $categorieUrl .'" target="_blank">' . $categorieUrl . '</a>',
'<a href="' . $categorieUrl . '" target="_blank">' . $categorieUrl . '</a>',
template::button('courseEdit' . $courseId, [
'href' => helper::baseUrl() . 'course/edit/' . $courseId,
'value' => template::ico('pencil'),
@ -94,14 +96,15 @@ class course extends common
$this->isPost()
) {
$courseId = uniqid();
$author = $this->getInput('courseAddAuthor');
$this->setData([
'course',
$courseId,
[
'title' => $this->getInput('courseAddTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseAddShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $author,
'author' => $this->getInput('courseAddAuthor'),
'homePageId' => $this->getInput('courseAddHomePageId'),
'category' => $this->getInput('courseAddCategories'),
'description' => $this->getInput('courseAddDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseAddAccess', helper::FILTER_INT),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
@ -144,6 +147,17 @@ class course extends common
// Liste des catégories de cours
self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Ajouter un cours'),
@ -163,14 +177,15 @@ class course extends common
$this->isPost()
) {
$courseId = $this->getUrl(2);
$author = $this->getInput('courseAddAuthor');
$this->setData([
'course',
$courseId,
[
'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $author,
'author' => $this->getInput('courseEditAuthor'),
'homePageId' => $this->getInput('courseEditHomePageId'),
'category' => $this->getInput('courseEditCategories'),
'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseEditAccess', helper::FILTER_INT),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
@ -199,6 +214,17 @@ class course extends common
// Liste des catégories de cours
self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Editer un cours'),

View File

@ -37,10 +37,14 @@
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [
<div class="col6">
<?php echo template::select('courseaDDHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil du cours',
]); ?>
</div>
<div class="col6">
<?php echo template::select('courseaDDCategories', $module::$courseCategories, [
'label' => 'Catégorie',
'value' => $this->getdata(['course', $this->getUrl(2), 'category'])
]); ?>
</div>
</div>

View File

@ -40,8 +40,14 @@
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [
<div class="col6">
<?php echo template::select('courseEditHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil du cours',
'selected' => $this->getdata(['course', $this->getUrl(2), 'homePageId']),
]); ?>
</div>
<div class="col6">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [
'label' => 'Catégorie',
'value' => $this->getdata(['course', $this->getUrl(2), 'category'])
]); ?>
@ -66,7 +72,7 @@
<?php echo template::date('courseOpeningDate', [
'type' => 'datetime-local',
'label' => 'Ouverture',
'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' :floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60
'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' : floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60
]); ?>
</div>
<div class="col4">

View File

@ -682,7 +682,6 @@ class init extends common
'disable' => false,
'content' => 'accueil.html',
'hideTitle' => false,
'homePageId' => true,
'breadCrumb' => false,
'metaDescription' => '',
'metaTitle' => '',
@ -984,7 +983,6 @@ class init extends common
'disable' => false,
'content' => 'accueil.html',
'hideTitle' => false,
'homePageId' => true,
'breadCrumb' => false,
'metaDescription' => '',
'metaTitle' => '',

View File

@ -211,7 +211,7 @@ class page extends common
]);
}
// Impossible de supprimer la page d'accueil
elseif ($page === $this->getData(['config', 'homePageId'])) {
elseif ($page === $this->homePageId()) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'config',

View File

@ -30,7 +30,7 @@ class sitemap extends common
foreach ($this->getHierarchy(null, true, null) as $parentId => $childIds) {
$items .= ' <li>';
if ($this->getData(['page', $parentId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$pageUrl = ($parentId !== $this->getData(['config', 'homePageId'])) ? helper::baseUrl() . $parentId : helper::baseUrl(false);
$pageUrl = ($parentId !== $this->homePageId()) ? helper::baseUrl() . $parentId : helper::baseUrl(false);
$items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $parentId, 'title']) . '</a>';
} else {
// page désactivée
@ -67,7 +67,7 @@ class sitemap extends common
// Sous-page
$items .= ' <li>';
if ($this->getData(['page', $childId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$pageUrl = ($childId !== $this->getData(['config', 'homePageId'])) ? helper::baseUrl() . $childId : helper::baseUrl(false);
$pageUrl = ($childId !== $this->homePageId()) ? helper::baseUrl() . $childId : helper::baseUrl(false);
$items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $childId, 'title']) . '</a>';
} else {
// page désactivée