From 2758ec5f1b8b4ae97e0f2a606588ab9cd8b496b3 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Wed, 13 Sep 2023 17:48:59 +0200 Subject: [PATCH] =?UTF-8?q?Supprimer=20la=20gestion=20des=20donn=C3=A9es?= =?UTF-8?q?=20des=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/module/plugin/plugin.php | 218 ------------------ .../plugin/view/dataImport/dataImport.css | 18 -- .../plugin/view/dataImport/dataImport.php | 37 --- core/module/plugin/view/index/index.css | 28 --- core/module/plugin/view/index/index.js.php | 13 -- core/module/plugin/view/index/index.php | 99 +++----- 6 files changed, 30 insertions(+), 383 deletions(-) delete mode 100644 core/module/plugin/view/dataImport/dataImport.css delete mode 100644 core/module/plugin/view/dataImport/dataImport.php delete mode 100644 core/module/plugin/view/index/index.js.php diff --git a/core/module/plugin/plugin.php b/core/module/plugin/plugin.php index 89a95200..9cbf7fcc 100644 --- a/core/module/plugin/plugin.php +++ b/core/module/plugin/plugin.php @@ -21,12 +21,6 @@ class plugin extends common 'index' => self::GROUP_ADMIN, 'delete' => 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, 'item' => self::GROUP_ADMIN, // 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' - ]); - } } \ No newline at end of file diff --git a/core/module/plugin/view/dataImport/dataImport.css b/core/module/plugin/view/dataImport/dataImport.css deleted file mode 100644 index ec846297..00000000 --- a/core/module/plugin/view/dataImport/dataImport.css +++ /dev/null @@ -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 - * @copyright Copyright (C) 2008-2018, Rémi Jean - * @author Frédéric Tempez - * @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 -*/ \ No newline at end of file diff --git a/core/module/plugin/view/dataImport/dataImport.php b/core/module/plugin/view/dataImport/dataImport.php deleted file mode 100644 index 96dc85c3..00000000 --- a/core/module/plugin/view/dataImport/dataImport.php +++ /dev/null @@ -1,37 +0,0 @@ - -
-
- 'buttonGrey', - 'href' => helper::baseUrl() . 'plugin', - 'value' => template::ico('left') - ]); ?> -
-
- 'Appliquer' - ]); ?> -
-
-
-
-
-

-

-
-
- $this->getData(['user', $this->getUser('id'), 'language']), - 'label' => 'Archive ZIP', - 'type' => 2 - ]); ?> -
-
- 'Importer dans' . template::flag('selected', '20px') - ]); ?> -
-
-
-
-
\ No newline at end of file diff --git a/core/module/plugin/view/index/index.css b/core/module/plugin/view/index/index.css index f67dcea5..e89398b1 100644 --- a/core/module/plugin/view/index/index.css +++ b/core/module/plugin/view/index/index.css @@ -17,31 +17,3 @@ * 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; -} - diff --git a/core/module/plugin/view/index/index.js.php b/core/module/plugin/view/index/index.js.php deleted file mode 100644 index f2780fd0..00000000 --- a/core/module/plugin/view/index/index.js.php +++ /dev/null @@ -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 - * @copyright Copyright (C) 2008-2018, Rémi Jean - * @author Frédéric Tempez - * @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";return core.confirm(message_delete,(function(){$(location).attr("href",_this.attr("href"))}))})),$(".dataDelete").on("click",(function(){var _this=$(this),message_unlink="";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")})); \ No newline at end of file diff --git a/core/module/plugin/view/index/index.php b/core/module/plugin/view/index/index.php index a4c5c977..13619d17 100644 --- a/core/module/plugin/view/index/index.php +++ b/core/module/plugin/view/index/index.php @@ -8,12 +8,12 @@
'https://doc.zwiicms.fr/gestion-des-modules', - 'target' => '_blank', - 'value' => template::ico('help'), - 'class' => 'buttonHelp', - 'help' => 'Consulter l\'aide en ligne' - ]);*/ ?> + 'href' => 'https://doc.zwiicms.fr/gestion-des-modules', + 'target' => '_blank', + 'value' => template::ico('help'), + 'class' => 'buttonHelp', + 'help' => 'Consulter l\'aide en ligne' + ]);*/?>
-
- 'Modules installés', - 'class' => ' buttonTab' - ]); ?> - 'Données des modules', - 'class' => 'buttonTab' - ]); ?> -
-
- -
-
-
-

-

- -
+ +
+
+
+

+ +

+
- - - - -
-
-
-

-

- -
+
+ + + + +
+
+
+

+ +

+
- - - -
-
- -
-
-
-

- -

-
-
- helper::baseUrl() . 'plugin/dataImport', - 'value' => template::ico('upload'), - "help" => 'Importer des données de module dans une page libre' - ]); ?> -
-
-
-
- -
-
-
-
-
- - - -
\ No newline at end of file +
+ + + \ No newline at end of file