Supprimer la gestion des données des modules
This commit is contained in:
parent
edc7a0b323
commit
2758ec5f1b
@ -21,12 +21,6 @@ class plugin extends common
|
|||||||
'index' => self::GROUP_ADMIN,
|
'index' => self::GROUP_ADMIN,
|
||||||
'delete' => self::GROUP_ADMIN,
|
'delete' => self::GROUP_ADMIN,
|
||||||
'save' => self::GROUP_ADMIN,
|
'save' => self::GROUP_ADMIN,
|
||||||
// Sauvegarde le module dans un fichier ZIP ou dans le gestionnaire
|
|
||||||
'dataExport' => self::GROUP_ADMIN,
|
|
||||||
// Fonction muette d'exportation
|
|
||||||
'dataImport' => self::GROUP_ADMIN,
|
|
||||||
// les données d'un module
|
|
||||||
'dataDelete' => self::GROUP_ADMIN,
|
|
||||||
'store' => self::GROUP_ADMIN,
|
'store' => self::GROUP_ADMIN,
|
||||||
'item' => self::GROUP_ADMIN,
|
'item' => self::GROUP_ADMIN,
|
||||||
// détail d'un objet
|
// détail d'un objet
|
||||||
@ -630,216 +624,4 @@ class plugin extends common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Détacher un module d'une page en supprimant les données du module
|
|
||||||
* 2 : i18n id
|
|
||||||
* 3 : moduleId
|
|
||||||
* 4 : pageId
|
|
||||||
* 5 : CSRF
|
|
||||||
*/
|
|
||||||
public function dataDelete()
|
|
||||||
{
|
|
||||||
// Action interdite
|
|
||||||
if ($this->getUser('permission', __CLASS__, __FUNCTION__) !== true) {
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'access' => false
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$this->setData(['page', $this->getUrl(4), 'moduleId', '']);
|
|
||||||
$this->deleteData(['module', $this->getUrl(4)]);
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'redirect' => helper::baseUrl() . 'plugin',
|
|
||||||
'notification' => sprintf(helper::translate('Le module %s de la page %s a été supprimé'), $this->getUrl(3), $this->getUrl(4)),
|
|
||||||
'state' => true
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Export des données d'un module
|
|
||||||
* Structure de l'adresse reçue
|
|
||||||
* 2 : i18n id
|
|
||||||
* 3 : moduleId
|
|
||||||
* 4 : pageId
|
|
||||||
*/
|
|
||||||
public function dataExport()
|
|
||||||
{
|
|
||||||
// Action interdite
|
|
||||||
if ($this->getUser('permission', __CLASS__, __FUNCTION__) !== true) {
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'access' => false
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
// Créer un dossier temporaire
|
|
||||||
$tmpFolder = self::TEMP_DIR . uniqid();
|
|
||||||
if (!is_dir($tmpFolder)) {
|
|
||||||
mkdir($tmpFolder, 0755);
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = $this->getUrl(2);
|
|
||||||
$lang = $this->getUrl(3);
|
|
||||||
$moduleId = $this->getUrl(4);
|
|
||||||
$pageId = $this->getUrl(5);
|
|
||||||
|
|
||||||
// DOnnèes du module de la page sélectionnée
|
|
||||||
$moduleData = $this->getData(['module', $pageId]);
|
|
||||||
|
|
||||||
// Descripteur du module
|
|
||||||
$infoModules = helper::getModules();
|
|
||||||
$infoModule = $infoModules[$moduleId];
|
|
||||||
|
|
||||||
// Copier les données et le descripteur
|
|
||||||
$success = file_put_contents($tmpFolder . '/module.json', json_encode($moduleData, JSON_UNESCAPED_UNICODE)) === false ? false : true;
|
|
||||||
|
|
||||||
$success = $success || is_int(file_put_contents($tmpFolder . '/enum.json', json_encode([$moduleId => $infoModule], JSON_UNESCAPED_UNICODE)));
|
|
||||||
// Le dossier du module s'il existe
|
|
||||||
if (is_dir(self::DATA_DIR . $moduleId . '/' . $pageId)) {
|
|
||||||
// Copier le dossier des données
|
|
||||||
$success = $success || $this->copyDir(self::DATA_DIR . '/' . $moduleId . '/' . $pageId, $tmpFolder . '/dataDirectory');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Création du zip
|
|
||||||
$fileName = $lang . '-' . $moduleId . '-' . $pageId . '.zip';
|
|
||||||
$this->makeZip(self::TEMP_DIR . $fileName, $tmpFolder);
|
|
||||||
|
|
||||||
// Gestion de l'action
|
|
||||||
if ($success) {
|
|
||||||
switch ($action) {
|
|
||||||
case 'filemanager':
|
|
||||||
if (!file_exists(self::FILE_DIR . 'source/modules')) {
|
|
||||||
mkdir(self::FILE_DIR . 'source/modules');
|
|
||||||
}
|
|
||||||
if (file_exists(self::TEMP_DIR . $fileName)) {
|
|
||||||
$success = $success || copy(self::TEMP_DIR . $fileName, self::FILE_DIR . 'source/modules/data' . $moduleId . '.zip');
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'redirect' => helper::baseUrl() . 'plugin',
|
|
||||||
'notification' => $success ? helper::translate('Données copiées dans le dossier Module du gestionnaire de fichier') : helper::translate('Erreur de copie'),
|
|
||||||
'state' => $success
|
|
||||||
]);
|
|
||||||
// Nettoyage
|
|
||||||
unlink(self::TEMP_DIR . $fileName);
|
|
||||||
$this->deleteDir($tmpFolder);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'download':
|
|
||||||
default:
|
|
||||||
if (file_exists(self::TEMP_DIR . $fileName)) {
|
|
||||||
// Téléchargement du ZIP
|
|
||||||
header('Content-Description: File Transfer');
|
|
||||||
header('Content-Type: application/octet-stream');
|
|
||||||
header('Content-Transfer-Encoding: binary');
|
|
||||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
||||||
header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName));
|
|
||||||
readfile(self::TEMP_DIR . $fileName);
|
|
||||||
// Nettoyage du dossier
|
|
||||||
unlink(self::TEMP_DIR . $fileName);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'redirect' => helper::baseUrl() . 'plugin',
|
|
||||||
'notification' => helper::translate('Erreur inconnue'),
|
|
||||||
'state' => false
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Importer des données d'un module externes ou interne à module.json
|
|
||||||
*/
|
|
||||||
public function dataImport()
|
|
||||||
{
|
|
||||||
// Soumission du formulaire d'importation du module dans une page libre
|
|
||||||
if (
|
|
||||||
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
|
|
||||||
$this->isPost()
|
|
||||||
) {
|
|
||||||
// Récupérer le fichier et le décompacter
|
|
||||||
$zipFilename = $this->getInput('pluginImportFile', helper::FILTER_STRING_SHORT, true);
|
|
||||||
$pageId = $this->getInput('pluginImportPage', null, true);
|
|
||||||
$tmpFolder = uniqid();
|
|
||||||
|
|
||||||
// Extraction dans un dossier temporaire
|
|
||||||
mkdir(self::TEMP_DIR . $tmpFolder, 0755);
|
|
||||||
$zip = new ZipArchive();
|
|
||||||
if ($zip->open(self::FILE_DIR . 'source/' . $zipFilename) === TRUE) {
|
|
||||||
$zip->extractTo(self::TEMP_DIR . $tmpFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lire le descripteur
|
|
||||||
$descripteur = json_decode(file_get_contents(self::TEMP_DIR . $tmpFolder . '/enum.json'), true);
|
|
||||||
$moduleId = array_key_first($descripteur);
|
|
||||||
|
|
||||||
// Lecture des données du module
|
|
||||||
$moduleData = json_decode(file_get_contents(self::TEMP_DIR . $tmpFolder . '/module.json'), true);
|
|
||||||
|
|
||||||
// Chargement des données du module importé
|
|
||||||
$this->setData(['module', $pageId, $moduleData]);
|
|
||||||
|
|
||||||
// Intégration des données du module importé dans la page
|
|
||||||
$this->setData(['page', $pageId, 'moduleId', $moduleId]);
|
|
||||||
|
|
||||||
// Copie des fichiers d'accompagnement
|
|
||||||
// Le dossier du module s'il existe
|
|
||||||
if (is_dir($tmpFolder . '/dataDirectory')) {
|
|
||||||
// Copier le dossier des données
|
|
||||||
$this->copyDir($tmpFolder . '/dataDirectory', self::DATA_DIR . '/' . $moduleId . '/' . $pageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer le dossier temporaire
|
|
||||||
$this->deleteDir(self::TEMP_DIR . $tmpFolder);
|
|
||||||
$zip->close();
|
|
||||||
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'redirect' => helper::baseUrl() . 'plugin',
|
|
||||||
'state' => true,
|
|
||||||
'notification' => helper::translate('Données importées')
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
// Bouton d'importation des données d'un module spécifique
|
|
||||||
if (count(explode('/', $this->getUrl())) === 6) {
|
|
||||||
// Traitement
|
|
||||||
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'redirect' => helper::baseUrl() . 'plugin',
|
|
||||||
'state' => true,
|
|
||||||
'notification' => helper::translate('Données importées')
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Liste des pages sans module
|
|
||||||
* et ne sont pas des barres latérales
|
|
||||||
*/
|
|
||||||
self::$pagesList = $this->getHierarchy();
|
|
||||||
foreach (self::$pagesList as $page => $value) {
|
|
||||||
if (
|
|
||||||
$this->getData(['page', $page, 'block']) === 'bar' ||
|
|
||||||
//$this->getData(['page',$page,'disable']) === true ||
|
|
||||||
$this->getData(['page', $page, 'moduleId']) !== ''
|
|
||||||
) {
|
|
||||||
unset(self::$pagesList[$page]);
|
|
||||||
} else {
|
|
||||||
self::$pagesList[$page] = $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'title' => helper::translate('Importer des données de module'),
|
|
||||||
'view' => 'dataImport'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,18 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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>
|
|
||||||
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
|
||||||
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
|
||||||
* @link http://zwiicms.fr/
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** NE PAS EFFACER
|
|
||||||
* admin.css
|
|
||||||
*/
|
|
@ -1,37 +0,0 @@
|
|||||||
<?php echo template::formOpen('pluginImportForm'); ?>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col1">
|
|
||||||
<?php echo template::button('pluginImportBack', [
|
|
||||||
'class' => 'buttonGrey',
|
|
||||||
'href' => helper::baseUrl() . 'plugin',
|
|
||||||
'value' => template::ico('left')
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
<div class="col2 offset9">
|
|
||||||
<?php echo template::submit('pluginImportSubmit', [
|
|
||||||
'value' => 'Appliquer'
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col12">
|
|
||||||
<div class="block">
|
|
||||||
<h4><?php echo helper::translate('Installer les données d\'un module'); ?>
|
|
||||||
</h4>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col6">
|
|
||||||
<?php echo template::file('pluginImportFile', [
|
|
||||||
'language' => $this->getData(['user', $this->getUser('id'), 'language']),
|
|
||||||
'label' => 'Archive ZIP',
|
|
||||||
'type' => 2
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
<div class="col6">
|
|
||||||
<?php echo template::select('pluginImportPage', $module::$pagesList, [
|
|
||||||
'label' => 'Importer dans' . template::flag('selected', '20px')
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -17,31 +17,3 @@
|
|||||||
* admin.css
|
* admin.css
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Style the tab */
|
|
||||||
.tab {
|
|
||||||
margin-top: 1.8em;
|
|
||||||
overflow: hidden;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tab ~ .tabContent {
|
|
||||||
margin-top: -10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttonTab {
|
|
||||||
display: inline-block;
|
|
||||||
transition: 0.3s;
|
|
||||||
border-radius: 10px 10px 0px 0px;
|
|
||||||
width: 200px;
|
|
||||||
margin: 0 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttonTab:hover {
|
|
||||||
filter: saturate(200%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.activeButton {
|
|
||||||
background-color: #00BFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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>
|
|
||||||
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
|
||||||
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
|
||||||
* @link http://zwiicms.fr/
|
|
||||||
*/
|
|
||||||
function setCookie(name,value,days){var expires="";if(days){var date=new Date;date.setTime(date.getTime()+24*days*60*60*1e3),expires="; expires="+date.toUTCString()}document.cookie=name+"="+(value||"")+expires+"; path=/; samesite=lax"}function getCookie(name){for(var nameEQ=name+"=",ca=document.cookie.split(";"),i=0;i<ca.length;i++){for(var c=ca[i];" "==c.charAt(0);)c=c.substring(1,c.length);if(0==c.indexOf(nameEQ))return c.substring(nameEQ.length,c.length)}return null}function capitalizeFirstLetter(string){return string.charAt(0).toUpperCase()+string.slice(1)}$(document).ready((function(){var pluginLayout=getCookie("pluginLayout");null==pluginLayout&&(pluginLayout="module",setCookie("pluginLayout","module")),console.log(pluginLayout),$("#moduleContainer").hide(),$("#dataContainer").hide(),$("#"+pluginLayout+"Container").show(),$("#plugin"+capitalizeFirstLetter(pluginLayout)+"Button").addClass("activeButton")})),$(".moduleDelete").on("click",(function(){var _this=$(this),message_delete="<?php echo helper::translate('Confirmer la désinstallation du module'); ?>";return core.confirm(message_delete,(function(){$(location).attr("href",_this.attr("href"))}))})),$(".dataDelete").on("click",(function(){var _this=$(this),message_unlink="<?php echo helper::translate('Confirmer la dissociation du module de cette page'); ?>";return core.confirm(message_unlink,(function(){$(location).attr("href",_this.attr("href"))}))})),$("#pluginModuleButton").on("click",(function(){$("#dataContainer").hide(),$("#moduleContainer").show(),$("#pluginModuleButton").addClass("activeButton"),$("#pluginDataButton").removeClass("activeButton"),setCookie("pluginLayout","module")})),$("#pluginDataButton").on("click",(function(){$("#moduleContainer").hide(),$("#dataContainer").show(),$("#pluginModuleButton").removeClass("activeButton"),$("#pluginDataButton").addClass("activeButton"),setCookie("pluginLayout","data")}));
|
|
@ -8,12 +8,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col1">
|
<div class="col1">
|
||||||
<?php /**echo template::button('pluginHelp', [
|
<?php /**echo template::button('pluginHelp', [
|
||||||
'href' => 'https://doc.zwiicms.fr/gestion-des-modules',
|
'href' => 'https://doc.zwiicms.fr/gestion-des-modules',
|
||||||
'target' => '_blank',
|
'target' => '_blank',
|
||||||
'value' => template::ico('help'),
|
'value' => template::ico('help'),
|
||||||
'class' => 'buttonHelp',
|
'class' => 'buttonHelp',
|
||||||
'help' => 'Consulter l\'aide en ligne'
|
'help' => 'Consulter l\'aide en ligne'
|
||||||
]);*/ ?>
|
]);*/?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col1 offset8">
|
<div class="col1 offset8">
|
||||||
<?php echo template::button('pluginModulesStore', [
|
<?php echo template::button('pluginModulesStore', [
|
||||||
@ -30,70 +30,31 @@
|
|||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab">
|
<?php if ($module::$modulesInstalled): ?>
|
||||||
<?php echo template::button('pluginModuleButton', [
|
<div class="row">
|
||||||
'value' => 'Modules installés',
|
<div class="col12">
|
||||||
'class' => ' buttonTab'
|
<div class="block">
|
||||||
]); ?>
|
<h4>
|
||||||
<?php echo template::button('pluginDataButton', [
|
<?php echo helper::translate('Sauvegarde'); ?>
|
||||||
'value' => 'Données des modules',
|
</h4>
|
||||||
'class' => 'buttonTab'
|
<?php echo template::table([2, 2, 1, 5, 1, 1], $module::$modulesInstalled, ['Module', 'Identifiant', 'Version', '', '', '']); ?>
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
<div class="tabContent" id="moduleContainer">
|
|
||||||
<?php if ($module::$modulesInstalled) : ?>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col12">
|
|
||||||
<div class="block">
|
|
||||||
<h4><?php echo helper::translate('Sauvegarde'); ?>
|
|
||||||
</h4>
|
|
||||||
<?php echo template::table([2, 2, 1, 5, 1, 1], $module::$modulesInstalled, ['Module', 'Identifiant', 'Version', '', '', '']); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
</div>
|
||||||
<?php echo template::speech('Aucun module installé.'); ?>
|
<?php else: ?>
|
||||||
<?php endif; ?>
|
<?php echo template::speech('Aucun module installé.'); ?>
|
||||||
<?php if ($module::$modulesOrphan) : ?>
|
<?php endif; ?>
|
||||||
<div class="row">
|
<?php if ($module::$modulesOrphan): ?>
|
||||||
<div class="col12">
|
<div class="row">
|
||||||
<div class="block">
|
<div class="col12">
|
||||||
<h4><?php echo helper::translate('Modules orphelins'); ?>
|
<div class="block">
|
||||||
</h4>
|
<h4>
|
||||||
<?php echo template::table([2, 2, 1, 6, 1], $module::$modulesOrphan, ['Module', 'Identifiant', 'Version', '', '']); ?>
|
<?php echo helper::translate('Modules orphelins'); ?>
|
||||||
</div>
|
</h4>
|
||||||
|
<?php echo template::table([2, 2, 1, 6, 1], $module::$modulesOrphan, ['Module', 'Identifiant', 'Version', '', '']); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
</div>
|
||||||
<?php echo template::speech('Aucun module orphelin.'); ?>
|
<?php else: ?>
|
||||||
<?php endif; ?>
|
<?php echo template::speech('Aucun module orphelin.'); ?>
|
||||||
</div>
|
<?php endif; ?>
|
||||||
<div class="tabContent displayNone" id="dataContainer">
|
|
||||||
<?php if ($module::$modulesData) : ?>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col12">
|
|
||||||
<div class="block">
|
|
||||||
<h4>
|
|
||||||
<?php echo helper::translate('Modules configurés'); ?>
|
|
||||||
</h4>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col1 offset11">
|
|
||||||
<?php echo template::button('configModuledataImport', [
|
|
||||||
'href' => helper::baseUrl() . 'plugin/dataImport',
|
|
||||||
'value' => template::ico('upload'),
|
|
||||||
"help" => 'Importer des données de module dans une page libre'
|
|
||||||
]); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col12">
|
|
||||||
<?php echo template::table([4, 1, 4, 1, 1, 1], $module::$modulesData, ['Module', 'Version', 'Page associée', '', '', '']); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php else : ?>
|
|
||||||
<?php echo template::speech('Aucune donnée de module.'); ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue
Block a user