2021-12-02 11:16:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2022-12-29 17:02:20 +01:00
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
2021-12-02 11:16:10 +01:00
|
|
|
* @link http://zwiicms.fr/
|
|
|
|
*/
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
class page extends common
|
|
|
|
{
|
2021-12-02 11:16:10 +01:00
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'add' => self::GROUP_MODERATOR,
|
|
|
|
'delete' => self::GROUP_MODERATOR,
|
|
|
|
'edit' => self::GROUP_MODERATOR,
|
2022-03-04 10:15:24 +01:00
|
|
|
'duplicate' => self::GROUP_MODERATOR,
|
|
|
|
'jsEditor' => self::GROUP_MODERATOR,
|
|
|
|
'cssEditor' => self::GROUP_MODERATOR
|
2021-12-02 11:16:10 +01:00
|
|
|
];
|
|
|
|
public static $pagesNoParentId = [
|
|
|
|
'' => 'Aucune'
|
|
|
|
];
|
|
|
|
public static $pagesBarId = [
|
|
|
|
'' => 'Aucune'
|
|
|
|
];
|
|
|
|
public static $moduleIds = [];
|
|
|
|
|
|
|
|
public static $typeMenu = [
|
|
|
|
'text' => 'Texte',
|
|
|
|
'icon' => 'Icône',
|
|
|
|
'icontitle' => 'Icône avec bulle de texte'
|
|
|
|
];
|
|
|
|
// Position du module
|
|
|
|
public static $modulePosition = [
|
2022-10-14 10:20:29 +02:00
|
|
|
'bottom' => 'Après le contenu de la page',
|
2023-02-10 15:26:06 +01:00
|
|
|
'top' => 'Avant le contenu de la page',
|
|
|
|
'free' => 'À l\'emplacement du mot clé [MODULE] dans la page'
|
2021-12-02 11:16:10 +01:00
|
|
|
];
|
|
|
|
public static $pageBlocks = [
|
2023-02-10 15:26:06 +01:00
|
|
|
'12' => 'Page standard',
|
|
|
|
'bar' => 'Barre latérale',
|
|
|
|
'4-8' => 'Barre 1/3 - page 2/3',
|
|
|
|
'8-4' => 'Page 2/3 - barre 1/3',
|
|
|
|
'3-9' => 'Barre 1/4 - page 3/4',
|
|
|
|
'9-3' => 'Page 3/4 - barre 1/4',
|
2021-12-02 11:16:10 +01:00
|
|
|
'3-6-3' => 'Barre 1/4 - page 1/2 - barre 1/4',
|
2022-10-14 10:20:29 +02:00
|
|
|
'2-7-3' => 'Barre 2/12 - page 7/12 - barre 3/12',
|
|
|
|
'3-7-2' => 'Barre 3/12 - page 7/12 - barre 2/12',
|
2021-12-02 11:16:10 +01:00
|
|
|
];
|
|
|
|
public static $displayMenu = [
|
2023-02-10 15:26:06 +01:00
|
|
|
'none' => 'Aucun menu',
|
|
|
|
'parents' => 'Le menu horizontal intégral',
|
|
|
|
'children' => 'Le sous-menu de la page parente'
|
2021-12-02 11:16:10 +01:00
|
|
|
];
|
2022-02-12 16:55:41 +01:00
|
|
|
public static $extraPosition = [
|
2023-02-10 15:26:06 +01:00
|
|
|
false => 'Menu standard',
|
|
|
|
true => 'Menu accessoire'
|
2022-02-12 16:55:41 +01:00
|
|
|
];
|
2021-12-02 11:16:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Duplication
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function duplicate()
|
|
|
|
{
|
2021-12-02 11:16:10 +01:00
|
|
|
// Adresse sans le token
|
2022-09-29 08:45:59 +02:00
|
|
|
$url = explode('&', $this->getUrl(2));
|
2021-12-02 11:16:10 +01:00
|
|
|
// La page n'existe pas
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $url[0]]) === null) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
} // Jeton incorrect
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif (!isset($_GET['csrf'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Jeton invalide')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
2022-09-29 08:45:59 +02:00
|
|
|
} elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Duplication de la page
|
2022-09-29 08:45:59 +02:00
|
|
|
$pageTitle = $this->getData(['page', $url[0], 'title']);
|
2021-12-02 11:16:10 +01:00
|
|
|
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
|
|
|
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
|
|
|
$pageId = helper::increment($pageId, self::$moduleIds);
|
|
|
|
$data = $this->getData([
|
|
|
|
'page',
|
|
|
|
$url[0]
|
|
|
|
]);
|
|
|
|
// Ecriture
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData(['page', $pageId, $data]);
|
2022-10-11 10:33:44 +02:00
|
|
|
$notification = helper::translate('Page dupliquée');
|
2021-12-02 11:16:10 +01:00
|
|
|
// Duplication du module présent
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $url[0], 'moduleId'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$data = $this->getData([
|
|
|
|
'module',
|
|
|
|
$url[0]
|
|
|
|
]);
|
|
|
|
// Ecriture
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData(['module', $pageId, $data]);
|
2022-10-11 10:33:44 +02:00
|
|
|
$notification = helper::translate('Page et module dupliqués');
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $pageId,
|
|
|
|
'notification' => $notification,
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Création
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function add()
|
|
|
|
{
|
2021-12-02 11:16:10 +01:00
|
|
|
$pageTitle = 'Nouvelle page';
|
|
|
|
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
|
|
|
$this->setData([
|
|
|
|
'page',
|
|
|
|
$pageId,
|
|
|
|
[
|
|
|
|
'typeMenu' => 'text',
|
|
|
|
'iconUrl' => '',
|
2022-09-29 08:45:59 +02:00
|
|
|
'disable' => false,
|
2023-02-10 15:26:06 +01:00
|
|
|
'content' => $pageId . '.html',
|
2021-12-02 11:16:10 +01:00
|
|
|
'hideTitle' => false,
|
|
|
|
'breadCrumb' => false,
|
|
|
|
'metaDescription' => '',
|
|
|
|
'metaTitle' => '',
|
|
|
|
'moduleId' => '',
|
|
|
|
'parentPageId' => '',
|
|
|
|
'modulePosition' => 'bottom',
|
|
|
|
'position' => 0,
|
|
|
|
'group' => self::GROUP_VISITOR,
|
|
|
|
'targetBlank' => false,
|
|
|
|
'title' => $pageTitle,
|
2022-04-13 14:48:57 +02:00
|
|
|
'shortTitle' => $pageTitle,
|
2021-12-02 11:16:10 +01:00
|
|
|
'block' => '12',
|
|
|
|
'barLeft' => '',
|
|
|
|
'barRight' => '',
|
|
|
|
'displayMenu' => '0',
|
|
|
|
'hideMenuSide' => false,
|
|
|
|
'hideMenuHead' => false,
|
2022-03-08 08:54:43 +01:00
|
|
|
'hideMenuChildren' => false,
|
|
|
|
'js' => '',
|
|
|
|
'css' => ''
|
2021-12-02 11:16:10 +01:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
// Creation du contenu de la page
|
2022-09-02 18:45:55 +02:00
|
|
|
if (!is_dir(self::DATA_DIR . self::$i18nContent . '/content')) {
|
|
|
|
mkdir(self::DATA_DIR . self::$i18nContent . '/content', 0755);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2022-09-02 18:45:55 +02:00
|
|
|
//file_put_contents(self::DATA_DIR . self::$i18nContent . '/content/' . $pageId . '.html', '<p>Contenu de votre nouvelle page.</p>');
|
|
|
|
$this->setPage($pageId, '<p>Contenu de votre nouvelle page.</p>', self::$i18nContent);
|
2023-03-26 09:31:42 +02:00
|
|
|
|
|
|
|
// Met à jour le sitemap
|
|
|
|
$this->updateSitemap();
|
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $pageId,
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Nouvelle page créée'),
|
2021-12-02 11:16:10 +01:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function delete()
|
|
|
|
{
|
2021-12-02 11:16:10 +01:00
|
|
|
// $url prend l'adresse sans le token
|
2022-09-29 08:45:59 +02:00
|
|
|
$url = explode('&', $this->getUrl(2));
|
2021-12-02 11:16:10 +01:00
|
|
|
// La page n'existe pas
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $url[0]]) === null) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
2023-02-10 15:26:06 +01:00
|
|
|
} // Jeton incorrect
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif (!isset($_GET['csrf'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Jeton invalide')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
2022-09-29 08:45:59 +02:00
|
|
|
} elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page d'accueil
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'homePageId'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-02-10 15:26:06 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page de recherche affectée
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'searchPageId'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2023-02-10 15:26:06 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page des mentions légales affectée
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'legalPageId'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page des mentions légales affectée
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'page404'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page des mentions légales affectée
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'page403'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer la page des mentions légales affectée
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($url[0] === $this->getData(['locale', 'page302'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Suppression interdite, page active dans la configuration du site')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Jeton incorrect
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif (!isset($_GET['csrf'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2023-02-10 15:26:06 +01:00
|
|
|
'notification' => helper::translate('Jeton invalide')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
2022-09-29 08:45:59 +02:00
|
|
|
} elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2023-02-10 15:26:06 +01:00
|
|
|
'notification' => helper::translate('Suppression interdite')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Impossible de supprimer une page contenant des enfants
|
2022-09-29 08:45:59 +02:00
|
|
|
elseif ($this->getHierarchy($url[0], null)) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
2023-02-10 15:26:06 +01:00
|
|
|
'notification' => helper::translate('Impossible de supprimer une page contenant des pages enfants')
|
2021-12-02 11:16:10 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Suppression
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Effacer le dossier du module
|
2022-09-29 08:45:59 +02:00
|
|
|
$moduleId = $this->getData(['page', $url[0], 'moduleId']);
|
2021-12-02 11:16:10 +01:00
|
|
|
$modulesData = helper::getModules();
|
2022-09-29 08:45:59 +02:00
|
|
|
if (
|
|
|
|
array_key_exists($moduleId, $modulesData)
|
2023-02-10 15:26:06 +01:00
|
|
|
&& is_dir($modulesData[$moduleId]['dataDirectory'] . $url[0])
|
2022-02-09 15:32:04 +01:00
|
|
|
) {
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->removeDir($modulesData[$moduleId]['dataDirectory'] . $url[0]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
// Effacer la page
|
|
|
|
$this->deleteData(['page', $url[0]]);
|
2022-09-02 18:45:55 +02:00
|
|
|
if (file_exists(self::DATA_DIR . self::$i18nContent . '/content/' . $url[0] . '.html')) {
|
|
|
|
unlink(self::DATA_DIR . self::$i18nContent . '/content/' . $url[0] . '.html');
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
$this->deleteData(['module', $url[0]]);
|
2023-03-26 09:31:42 +02:00
|
|
|
|
|
|
|
// Met à jour le sitemap
|
|
|
|
$this->updateSitemap();
|
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl(false),
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Page supprimée'),
|
2021-12-02 11:16:10 +01:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Édition
|
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function edit()
|
|
|
|
{
|
2021-12-02 11:16:10 +01:00
|
|
|
// La page n'existe pas
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $this->getUrl(2)]) === null) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// La page existe
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->isPost()) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Si le Title n'est pas vide, premier test pour positionner la notification du champ obligatoire
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getInput('pageEditTitle', helper::FILTER_ID, true) !== null && $this->getInput('pageEditTitle') !== '') {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Génére l'ID si le titre de la page a changé
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getInput('pageEditTitle') !== $this->getData(['page', $this->getUrl(2), 'title'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$pageId = $this->getInput('pageEditTitle', helper::FILTER_ID, true);
|
|
|
|
} else {
|
|
|
|
$pageId = $this->getUrl(2);
|
|
|
|
}
|
|
|
|
// un dossier existe du même nom (erreur en cas de redirection)
|
|
|
|
if (file_exists($pageId)) {
|
|
|
|
$pageId = uniqid($pageId);
|
|
|
|
}
|
|
|
|
// Si l'id a changée
|
|
|
|
if ($pageId !== $this->getUrl(2)) {
|
|
|
|
// Incrémente le nouvel id de la page
|
2022-09-29 08:45:59 +02:00
|
|
|
$pageId = helper::increment($pageId, $this->getData(['page']));
|
|
|
|
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
|
|
|
$pageId = helper::increment($pageId, self::$moduleIds);
|
2021-12-02 11:16:10 +01:00
|
|
|
// Met à jour les enfants
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($this->getHierarchy($this->getUrl(2), null) as $childrenPageId) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$this->setData(['page', $childrenPageId, 'parentPageId', $pageId]);
|
|
|
|
}
|
|
|
|
// Change l'id de page dans les données des modules
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(2)]) !== null) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$this->setData(['module', $pageId, $this->getData(['module', $this->getUrl(2)])]);
|
|
|
|
$this->deleteData(['module', $this->getUrl(2)]);
|
|
|
|
// Renommer le dossier du module
|
2022-09-29 08:45:59 +02:00
|
|
|
$moduleId = $this->getData(['page', $this->getUrl(2), 'moduleId']);
|
2021-12-02 11:16:10 +01:00
|
|
|
$modulesData = helper::getModules();
|
2022-09-29 08:45:59 +02:00
|
|
|
if (is_dir($modulesData[$moduleId]['dataDirectory'] . $this->getUrl(2))) {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Placer la feuille de style dans un dossier au nom de la nouvelle instance
|
2022-09-29 08:45:59 +02:00
|
|
|
mkdir($modulesData[$moduleId]['dataDirectory'] . $pageId, 0755);
|
|
|
|
copy($modulesData[$moduleId]['dataDirectory'] . $this->getUrl(2), $modulesData[$moduleId]['dataDirectory'] . $pageId);
|
|
|
|
$this->removeDir($modulesData[$moduleId]['dataDirectory'] . $this->getUrl(2));
|
2021-12-02 11:16:10 +01:00
|
|
|
// Mettre à jour le nom de la feuille de style
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData(['module', $pageId, 'theme', 'style', $modulesData[$moduleId]['dataDirectory'] . $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Si la page correspond à la page d'accueil, change l'id dans la configuration du site
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['locale', 'homePageId']) === $this->getUrl(2)) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$this->setData(['locale', 'homePageId', $pageId]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Supprime les données du module en cas de changement de module
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getInput('pageEditModuleId') !== $this->getData(['page', $this->getUrl(2), 'moduleId'])) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$this->deleteData(['module', $pageId]);
|
|
|
|
}
|
|
|
|
// Supprime l'ancienne page si l'id a changée
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($pageId !== $this->getUrl(2)) {
|
2021-12-02 11:16:10 +01:00
|
|
|
$this->deleteData(['page', $this->getUrl(2)]);
|
2022-09-02 18:45:55 +02:00
|
|
|
if (file_exists(self::DATA_DIR . self::$i18nContent . '/content/' . $this->getUrl(2) . '.html')) {
|
2022-09-29 08:45:59 +02:00
|
|
|
unlink(self::DATA_DIR . self::$i18nContent . '/content/' . $this->getUrl(2) . '.html');
|
2022-02-10 08:03:52 +01:00
|
|
|
}
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
// Traitement des pages spéciales affectées dans la config :
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getUrl(2) === $this->getData(['locale', 'legalPageId'])) {
|
|
|
|
$this->setData(['locale', 'legalPageId', $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getUrl(2) === $this->getData(['locale', 'searchPageId'])) {
|
|
|
|
$this->setData(['locale', 'searchPageId', $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getUrl(2) === $this->getData(['locale', 'page404'])) {
|
|
|
|
$this->setData(['locale', 'page404', $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getUrl(2) === $this->getData(['locale', 'page403'])) {
|
|
|
|
$this->setData(['locale', 'page403', $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getUrl(2) === $this->getData(['locale', 'page302'])) {
|
|
|
|
$this->setData(['locale', 'page302', $pageId]);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
// Si la page est une page enfant, actualise les positions des autres enfants du parent, sinon actualise les pages sans parents
|
|
|
|
$lastPosition = 1;
|
|
|
|
$hierarchy = $this->getInput('pageEditParentPageId') ? $this->getHierarchy($this->getInput('pageEditParentPageId')) : array_keys($this->getHierarchy());
|
|
|
|
$position = $this->getInput('pageEditPosition', helper::FILTER_INT);
|
2022-03-09 09:15:47 +01:00
|
|
|
$extraPosition = $this->getinput('pageEditExtraPosition', helper::FILTER_BOOLEAN);
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($hierarchy as $hierarchyPageId) {
|
2022-03-08 13:46:55 +01:00
|
|
|
|
2022-03-09 09:15:47 +01:00
|
|
|
// Ne traite que les pages du menu sélectionné
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $hierarchyPageId, 'extraPosition']) === $extraPosition) {
|
2022-03-09 09:15:47 +01:00
|
|
|
// Ignore la page en cours de modification
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($hierarchyPageId === $this->getUrl(2)) {
|
2022-03-09 09:15:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
2022-03-08 13:46:55 +01:00
|
|
|
// Incrémente de +1 pour laisser la place à la position de la page en cours de modification
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($lastPosition === $position) {
|
2022-03-08 13:46:55 +01:00
|
|
|
$lastPosition++;
|
|
|
|
}
|
|
|
|
// Change la position
|
|
|
|
$this->setData(['page', $hierarchyPageId, 'position', $lastPosition]);
|
|
|
|
// Incrémente pour la prochaine position
|
2021-12-02 11:16:10 +01:00
|
|
|
$lastPosition++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($this->getinput('pageEditBlock') !== 'bar') {
|
|
|
|
$barLeft = $this->getinput('pageEditBarLeft');
|
|
|
|
$barRight = $this->getinput('pageEditBarRight');
|
|
|
|
$hideTitle = $this->getInput('pageEditHideTitle', helper::FILTER_BOOLEAN);
|
|
|
|
} else {
|
|
|
|
// Une barre ne peut pas avoir de barres
|
|
|
|
$barLeft = "";
|
|
|
|
$barRight = "";
|
|
|
|
// Une barre est masquée
|
|
|
|
$position = 0;
|
|
|
|
$hideTitle = true;
|
|
|
|
}
|
2022-01-11 13:35:26 +01:00
|
|
|
// Une page parent devient orpheline, les pages enfants le devienne pour éviter une incohérence
|
2022-09-29 08:45:59 +02:00
|
|
|
if (
|
2022-01-11 13:35:26 +01:00
|
|
|
$position === 0 &&
|
2023-02-10 15:26:06 +01:00
|
|
|
$position !== $this->getData(['page', $this->getUrl(2), 'position']) &&
|
2022-01-11 13:35:26 +01:00
|
|
|
$this->getinput('pageEditBlock') !== 'bar'
|
2022-09-29 08:45:59 +02:00
|
|
|
) {
|
|
|
|
foreach ($this->getHierarchy($pageId) as $parentId => $childId) {
|
|
|
|
if ($this->getData(['page', $childId, 'parentPageId']) === $pageId) {
|
|
|
|
$this->setData(['page', $childId, 'position', 0]);
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
}
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// La page est une barre latérale qui a été renommée : changer le nom de la barre dans les pages qui l'utilisent
|
|
|
|
if ($this->getinput('pageEditBlock') === 'bar') {
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($this->getHierarchy() as $eachPageId => $parentId) {
|
|
|
|
if ($this->getData(['page', $eachPageId, 'barRight']) === $this->getUrl(2)) {
|
|
|
|
$this->setData(['page', $eachPageId, 'barRight', $pageId]);
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $eachPageId, 'barLeft']) === $this->getUrl(2)) {
|
|
|
|
$this->setData(['page', $eachPageId, 'barLeft', $pageId]);
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
|
|
|
foreach ($parentId as $childId) {
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $childId, 'barRight']) === $this->getUrl(2)) {
|
|
|
|
$this->setData(['page', $childId, 'barRight', $pageId]);
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->getData(['page', $childId, 'barLeft']) === $this->getUrl(2)) {
|
|
|
|
$this->setData(['page', $childId, 'barLeft', $pageId]);
|
2022-01-11 13:35:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 15:51:12 +01:00
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Modifie la page ou en crée une nouvelle si l'id a changé
|
|
|
|
$this->setData([
|
|
|
|
'page',
|
|
|
|
$pageId,
|
|
|
|
[
|
|
|
|
'typeMenu' => $this->getinput('pageTypeMenu'),
|
|
|
|
'iconUrl' => $this->getinput('pageIconUrl'),
|
2022-09-29 08:45:59 +02:00
|
|
|
'disable' => $this->getinput('pageEditDisable', helper::FILTER_BOOLEAN),
|
2021-12-02 11:16:10 +01:00
|
|
|
'content' => $pageId . '.html',
|
|
|
|
'hideTitle' => $hideTitle,
|
|
|
|
'breadCrumb' => $this->getInput('pageEditbreadCrumb', helper::FILTER_BOOLEAN),
|
|
|
|
'metaDescription' => $this->getInput('pageEditMetaDescription', helper::FILTER_STRING_LONG),
|
|
|
|
'metaTitle' => $this->getInput('pageEditMetaTitle'),
|
|
|
|
'moduleId' => $this->getInput('pageEditModuleId'),
|
2022-05-06 18:55:14 +02:00
|
|
|
'modulePosition' => $this->getInput('pageModulePosition'),
|
2021-12-02 11:16:10 +01:00
|
|
|
'parentPageId' => $this->getInput('pageEditParentPageId'),
|
|
|
|
'position' => $position,
|
|
|
|
'group' => $this->getinput('pageEditBlock') !== 'bar' ? $this->getInput('pageEditGroup', helper::FILTER_INT) : 0,
|
|
|
|
'targetBlank' => $this->getInput('pageEditTargetBlank', helper::FILTER_BOOLEAN),
|
|
|
|
'title' => $this->getInput('pageEditTitle', helper::FILTER_STRING_SHORT),
|
|
|
|
'shortTitle' => $this->getInput('pageEditShortTitle', helper::FILTER_STRING_SHORT, true),
|
|
|
|
'block' => $this->getinput('pageEditBlock'),
|
|
|
|
'barLeft' => $barLeft,
|
|
|
|
'barRight' => $barRight,
|
|
|
|
'displayMenu' => $this->getinput('pageEditDisplayMenu'),
|
|
|
|
'hideMenuSide' => $this->getinput('pageEditHideMenuSide', helper::FILTER_BOOLEAN),
|
|
|
|
'hideMenuHead' => $this->getinput('pageEditHideMenuHead', helper::FILTER_BOOLEAN),
|
|
|
|
'hideMenuChildren' => $this->getinput('pageEditHideMenuChildren', helper::FILTER_BOOLEAN),
|
2022-03-08 08:54:43 +01:00
|
|
|
'extraPosition' => $this->getinput('pageEditExtraPosition', helper::FILTER_BOOLEAN),
|
2023-02-16 11:52:40 +01:00
|
|
|
'css' => $this->getData(['page', $this->getUrl(2), 'css']) == null ? '' : $this->getData(['page', $this->getUrl(2), 'css']),
|
|
|
|
'js' => $this->getData(['page', $this->getUrl(2), 'js']) == null ? '' : $this->getData(['page', $this->getUrl(2), 'js']),
|
2021-12-02 11:16:10 +01:00
|
|
|
]
|
|
|
|
]);
|
2022-01-11 13:35:26 +01:00
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Creation du contenu de la page
|
2022-09-02 18:45:55 +02:00
|
|
|
if (!is_dir(self::DATA_DIR . self::$i18nContent . '/content')) {
|
|
|
|
mkdir(self::DATA_DIR . self::$i18nContent . '/content', 0755);
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
|
|
|
$content = empty($this->getInput('pageEditContent', null)) ? '<p></p>' : str_replace('<p></p>', '<p> </p>', $this->getInput('pageEditContent', null));
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setPage($pageId, $content, self::$i18nContent);
|
2022-01-11 13:35:26 +01:00
|
|
|
|
2023-03-26 09:31:42 +02:00
|
|
|
// Met à jour le sitemap
|
|
|
|
$this->updateSitemap();
|
2022-03-25 09:19:45 +01:00
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Redirection vers la configuration
|
2022-09-29 08:45:59 +02:00
|
|
|
if (
|
2022-01-11 13:35:26 +01:00
|
|
|
$this->getInput('pageEditModuleRedirect', helper::FILTER_BOOLEAN)
|
2022-09-29 08:45:59 +02:00
|
|
|
) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $pageId . '/config',
|
|
|
|
'state' => true
|
|
|
|
]);
|
2022-01-11 13:35:26 +01:00
|
|
|
// Redirection vers la page
|
2022-09-29 08:45:59 +02:00
|
|
|
} else {
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $pageId,
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
2021-12-02 11:16:10 +01:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-10 15:26:06 +01:00
|
|
|
// Construction du formulaire
|
|
|
|
|
2023-02-10 15:52:49 +01:00
|
|
|
// Création du sélecteur de modules
|
2023-02-10 15:26:06 +01:00
|
|
|
self::$moduleIds = [];
|
|
|
|
foreach (helper::getModules() as $key => $values) {
|
|
|
|
self::$moduleIds[$key] = $values['realName'] . ' (' . $key . ')';
|
|
|
|
}
|
|
|
|
self::$moduleIds = array_merge(['' => 'Aucun'], self::$moduleIds);
|
|
|
|
|
|
|
|
// Pages sans parent
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($this->getHierarchy() as $parentPageId => $childrenPageIds) {
|
|
|
|
if ($parentPageId !== $this->getUrl(2)) {
|
2021-12-02 11:16:10 +01:00
|
|
|
self::$pagesNoParentId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Pages barre latérales
|
2022-09-29 08:45:59 +02:00
|
|
|
foreach ($this->getHierarchy(null, false, true) as $parentPageId => $childrenPageIds) {
|
|
|
|
if (
|
|
|
|
$parentPageId !== $this->getUrl(2) &&
|
|
|
|
$this->getData(['page', $parentPageId, 'block']) === 'bar'
|
|
|
|
) {
|
|
|
|
self::$pagesBarId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
|
|
|
}
|
2021-12-02 11:16:10 +01:00
|
|
|
}
|
2023-03-02 14:26:45 +01:00
|
|
|
|
2021-12-02 11:16:10 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => $this->getData(['page', $this->getUrl(2), 'title']),
|
|
|
|
'vendor' => [
|
2022-03-25 09:53:42 +01:00
|
|
|
'tinymce'
|
2021-12-02 11:16:10 +01:00
|
|
|
],
|
|
|
|
'view' => 'edit'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 10:15:24 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-19 10:26:39 +02:00
|
|
|
* Éditeur de feuille de style
|
2022-03-04 10:15:24 +01:00
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function cssEditor()
|
|
|
|
{
|
2022-03-04 10:15:24 +01:00
|
|
|
// Soumission du formulaire
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->isPost()) {
|
2023-03-14 15:04:43 +01:00
|
|
|
$css = $this->getInput('pageCssEditorContent', helper::FILTER_STRING_LONG) === null ? '' : $this->getInput('pageCssEditorContent', helper::FILTER_STRING_LONG);
|
2022-03-04 10:15:24 +01:00
|
|
|
// Enregistre le CSS
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData([
|
2023-02-10 15:26:06 +01:00
|
|
|
'page', $this->getUrl(2),
|
|
|
|
'css',
|
2022-11-16 15:51:12 +01:00
|
|
|
$css
|
2022-04-14 23:16:44 +02:00
|
|
|
]);
|
2022-03-04 10:15:24 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
2022-03-04 10:15:24 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $this->getUrl(2),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-10-02 10:59:42 +02:00
|
|
|
'title' => helper::translate('Éditeur CSS'),
|
2022-03-04 10:15:24 +01:00
|
|
|
'vendor' => [
|
|
|
|
'codemirror'
|
|
|
|
],
|
|
|
|
'view' => 'cssEditor'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-09-29 08:45:59 +02:00
|
|
|
/**
|
2022-09-19 10:26:39 +02:00
|
|
|
* Éditeur de feuille de style
|
2022-03-04 10:15:24 +01:00
|
|
|
*/
|
2022-09-29 08:45:59 +02:00
|
|
|
public function jsEditor()
|
|
|
|
{
|
2022-03-04 10:15:24 +01:00
|
|
|
// Soumission du formulaire
|
2022-09-29 08:45:59 +02:00
|
|
|
if ($this->isPost()) {
|
2023-03-14 15:04:43 +01:00
|
|
|
$js = $this->getInput('pageJsEditorContent', helper::FILTER_STRING_LONG) === null ? '' : $this->getInput('pageJsEditorContent', helper::FILTER_STRING_LONG);
|
2022-03-04 10:15:24 +01:00
|
|
|
// Enregistre le JS
|
2022-09-29 08:45:59 +02:00
|
|
|
$this->setData([
|
2023-02-10 15:26:06 +01:00
|
|
|
'page', $this->getUrl(2),
|
|
|
|
'js',
|
2022-11-16 15:51:12 +01:00
|
|
|
$js
|
2022-04-14 23:16:44 +02:00
|
|
|
]);
|
2022-03-04 10:15:24 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
2022-03-04 10:15:24 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'page/edit/' . $this->getUrl(2),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-10-02 10:59:42 +02:00
|
|
|
'title' => helper::translate('Éditeur Js'),
|
2022-03-04 10:15:24 +01:00
|
|
|
'vendor' => [
|
|
|
|
'codemirror'
|
|
|
|
],
|
|
|
|
'view' => 'jsEditor'
|
|
|
|
]);
|
|
|
|
}
|
2023-03-19 09:59:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne les informations sur les pages en omettant les clés CSS et JS qui occasionnent des bugs d'affichage dans l'éditeur de page
|
|
|
|
* @return array tableau associatif des pages dans le menu
|
|
|
|
*/
|
|
|
|
public function getPageInfo() {
|
|
|
|
$p = $this->getData(['page']);
|
|
|
|
$d = array_map(function($d) {
|
|
|
|
unset($d["css"], $d["js"]);
|
|
|
|
return $d;
|
|
|
|
}, $p);
|
|
|
|
return json_encode($d);
|
|
|
|
|
|
|
|
}
|
2023-02-10 15:26:06 +01:00
|
|
|
}
|