From d6cd62e8304dc60e7d2005c82617882919e2b2ec Mon Sep 17 00:00:00 2001 From: Deltacms Date: Thu, 23 Mar 2023 18:40:03 +0100 Subject: [PATCH] sauvegarde themes --- core/module/theme/lang/en/lex_theme.php | 1 + core/module/theme/lang/fr/lex_theme.php | 1 + core/module/theme/theme.php | 60 +++++++++++++-------- core/module/theme/view/manage/manage.css | 2 +- core/module/theme/view/manage/manage.js.php | 8 ++- core/module/theme/view/manage/manage.php | 32 ++++++++--- 6 files changed, 71 insertions(+), 33 deletions(-) diff --git a/core/module/theme/lang/en/lex_theme.php b/core/module/theme/lang/en/lex_theme.php index b47ef69..5209a45 100644 --- a/core/module/theme/lang/en/lex_theme.php +++ b/core/module/theme/lang/en/lex_theme.php @@ -202,6 +202,7 @@ $text['core_theme_view']['manage'][12] = 'Site theme'; $text['core_theme_view']['manage'][13] = 'Administration theme'; $text['core_theme_view']['manage'][14] = "Are you sure you want to reset the site theme to its original state ?"; $text['core_theme_view']['manage'][15] = "Your custom.css file will be overwritten, you will be able to find it in the automatic backup that will be created, continue?"; +$text['core_theme_view']['manage'][16] = "Enter a name without extension (optional)"; $text['core_theme_view']['menu'][0] = 'Back'; $text['core_theme_view']['menu'][1] = 'Help'; $text['core_theme_view']['menu'][2] = 'Save'; diff --git a/core/module/theme/lang/fr/lex_theme.php b/core/module/theme/lang/fr/lex_theme.php index 455df67..123669d 100644 --- a/core/module/theme/lang/fr/lex_theme.php +++ b/core/module/theme/lang/fr/lex_theme.php @@ -202,6 +202,7 @@ $text['core_theme_view']['manage'][12] = 'Thème du site'; $text['core_theme_view']['manage'][13] = 'Thème de l\'administration'; $text['core_theme_view']['manage'][14] = "Êtes-vous sûr de vouloir réinitialiser à son état d\'origine le thème du site ?"; $text['core_theme_view']['manage'][15] = "Votre fichier custom.css va être écrasé, vous pourrez le retrouver dans la sauvegarde automatique qui va être créée, continuez ?"; +$text['core_theme_view']['manage'][16] = "Saisissez un nom sans extension (facultatif)"; $text['core_theme_view']['menu'][0] = 'Retour'; $text['core_theme_view']['menu'][1] = 'Aide'; $text['core_theme_view']['menu'][2] = 'Enregistrer'; diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index 571de12..efb419d 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -739,22 +739,31 @@ class theme extends common { include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); if($this->isPost() ) { - - $zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true); - $data = $this->import(self::FILE_DIR.'source/' . $zipFilename); - if ($data['success']) { - header("Refresh:0"); - // Régénérer theme.css et admin.css - if (file_exists(self::DATA_DIR . 'theme.css')) unlink(self::DATA_DIR . 'theme.css'); - //$this->setData(['admin', 'maj', true]); - } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => $data['notification'], - 'state' => $data['success'], - 'title' => $text['core_theme']['manage'][0], - 'view' => 'manage' - ]);; + if( isset( $_POST['themeSaveTheme'])){ + $this->save('theme',$this->getInput('themeSaveName')); + } elseif( isset( $_POST['themeSaveAdmin'])){ + $this->save('admin',$this->getInput('themeSaveName')); + } elseif( isset( $_POST['themeExportTheme'])){ + $this->export('theme',$this->getInput('themeExportName')); + } elseif( isset( $_POST['themeExportAdmin'])){ + $this->export('admin',$this->getInput('themeExportName')); + }else { + $zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true); + $data = $this->import(self::FILE_DIR.'source/' . $zipFilename); + if ($data['success']) { + header("Refresh:0"); + // Régénérer theme.css et admin.css + if (file_exists(self::DATA_DIR . 'theme.css')) unlink(self::DATA_DIR . 'theme.css'); + //$this->setData(['admin', 'maj', true]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'notification' => $data['notification'], + 'state' => $data['success'], + 'title' => $text['core_theme']['manage'][0], + 'view' => 'manage' + ]);; + } } } // Valeurs en sortie @@ -842,9 +851,9 @@ class theme extends common { /** * Export du thème */ - public function export() { + public function export($modele, $name) { // Make zip - $zipFilename = $this->zipTheme($this->getUrl(2)); + $zipFilename = $this->zipTheme($modele, $name); // Téléchargement du ZIP header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); @@ -860,11 +869,11 @@ class theme extends common { /** * Export du thème */ - public function save() { + public function save($modele, $name) { // Lexique include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); // Make zip - $zipFilename = $this->zipTheme($this->getUrl(2)); + $zipFilename = $this->zipTheme($modele, $name); // Téléchargement du ZIP if (!is_dir(self::FILE_DIR.'source/theme')) { mkdir(self::FILE_DIR.'source/theme', 0755); @@ -885,7 +894,7 @@ class theme extends common { */ public function sauve( $type ) { // Make zip - $zipFilename = $this->zipTheme( $type ); + $zipFilename = $this->zipTheme( $type, '' ); // Téléchargement du ZIP if (!is_dir(self::FILE_DIR.'source/theme')) { mkdir(self::FILE_DIR.'source/theme', 0755); @@ -900,9 +909,14 @@ class theme extends common { * construction du zip * @param string $modele theme ou admin */ - private function zipTheme($modele) { + private function zipTheme($modele, $name) { // Creation du dossier - $zipFilename = $modele . date('Y-m-d-H-i-s', time()) . '.zip'; + if( $name === '' || $name === null){ + $name = $modele . date('Y-m-d-H-i-s', time()) ; + } else { + $name = str_replace('.','',$name); + } + $zipFilename = $name . '.zip'; $zip = new ZipArchive(); if ($zip->open(self::TEMP_DIR . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) === TRUE) { switch ($modele) { diff --git a/core/module/theme/view/manage/manage.css b/core/module/theme/view/manage/manage.css index 3f283ea..9391b02 100644 --- a/core/module/theme/view/manage/manage.css +++ b/core/module/theme/view/manage/manage.css @@ -5,4 +5,4 @@ /** NE PAS EFFACER * admin.css -*/ \ No newline at end of file +*/ diff --git a/core/module/theme/view/manage/manage.js.php b/core/module/theme/view/manage/manage.js.php index 155b78b..bf691dc 100644 --- a/core/module/theme/view/manage/manage.js.php +++ b/core/module/theme/view/manage/manage.js.php @@ -19,4 +19,10 @@ $("#themeImportSubmit").on("click", function() { return core.confirm(textConfirm2, function() { $('#themeManageForm').submit(); }); -}); \ No newline at end of file +}); + +// Couleur des boutons submit de sauvegarde et d'export +var bgcolor = getData(['admin', 'backgroundColorButton' ]).'"'; ?>; +var color = getData(['admin', 'backgroundColorButton']))['text'].'"'; ?>; +$(".themeSave").css('background-color', bgcolor); +$(".themeSave").css('color', color); \ No newline at end of file diff --git a/core/module/theme/view/manage/manage.php b/core/module/theme/view/manage/manage.php index 04055e2..383b18f 100644 --- a/core/module/theme/view/manage/manage.php +++ b/core/module/theme/view/manage/manage.php @@ -56,20 +56,28 @@ echo template::formOpen('themeManageForm'); ?>
- helper::baseUrl() . 'theme/save/theme', + 'themeSave', 'ico' => 'download-cloud', 'value' => $text['core_theme_view']['manage'][9] ]); ?>
- helper::baseUrl() . 'theme/save/admin', + 'themeSave', 'ico' => 'download-cloud', 'value' => $text['core_theme_view']['manage'][10] ]); ?>
+
+
+ $text['core_theme_view']['manage'][16], + 'value' => '' + ]); ?> +
+
@@ -78,20 +86,28 @@ echo template::formOpen('themeManageForm'); ?>
- helper::baseUrl() . 'theme/export/theme', + 'themeSave', 'ico' => 'download', 'value' => $text['core_theme_view']['manage'][12] ]); ?>
- helper::baseUrl() . 'theme/export/admin', + 'themeSave', 'ico' => 'download', 'value' => $text['core_theme_view']['manage'][13] ]); ?>
+
+
+ $text['core_theme_view']['manage'][16], + 'value' => '' + ]); ?> +
+