Page duplicate

This commit is contained in:
Fred Tempez 2023-06-20 20:04:30 +02:00
parent 3b8a2d5b03
commit adf0ac8f80
1 changed files with 8 additions and 14 deletions

View File

@ -72,44 +72,38 @@ class page extends common
public function duplicate() public function duplicate()
{ {
// Adresse sans le token // Adresse sans le token
$url = explode('&', $this->getUrl(2)); $page = $this->getUrl(2);
// La page n'existe pas // La page n'existe pas
if ($this->getData(['page', $url[0]]) === null) { if ($this->getData(['page', $page]) === null) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'access' => false 'access' => false
]); ]);
} // Jeton incorrect } // Jeton incorrect
elseif (!isset($_GET['csrf'])) { elseif ($this->checkCSRF()) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0], 'redirect' => helper::baseUrl() . 'page/edit/' . $page,
'notification' => helper::translate('Jeton invalide') 'notification' => helper::translate('Jeton invalide')
]); ]);
} elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
'notification' => helper::translate('Suppression interdite')
]);
} }
// Duplication de la page // Duplication de la page
$pageTitle = $this->getData(['page', $url[0], 'title']); $pageTitle = $this->getData(['page', $page, 'title']);
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page'])); $pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
$pageId = helper::increment($pageId, self::$coreModuleIds); $pageId = helper::increment($pageId, self::$coreModuleIds);
$pageId = helper::increment($pageId, self::$moduleIds); $pageId = helper::increment($pageId, self::$moduleIds);
$data = $this->getData([ $data = $this->getData([
'page', 'page',
$url[0] $page
]); ]);
// Ecriture // Ecriture
$this->setData(['page', $pageId, $data]); $this->setData(['page', $pageId, $data]);
$notification = helper::translate('Page dupliquée'); $notification = helper::translate('Page dupliquée');
// Duplication du module présent // Duplication du module présent
if ($this->getData(['page', $url[0], 'moduleId'])) { if ($this->getData(['page', $page, 'moduleId'])) {
$data = $this->getData([ $data = $this->getData([
'module', 'module',
$url[0] $page
]); ]);
// Ecriture // Ecriture
$this->setData(['module', $pageId, $data]); $this->setData(['module', $pageId, $data]);