From 0d6d43381cc2b0139e7d2a9ffcdeae5624073e90 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 14 Apr 2023 09:00:15 +0200 Subject: [PATCH] nouveau initData --- core/core.php | 52 ++++++++----------- core/module/install/ressource/defaultdata.php | 9 ++-- core/module/translate/translate.php | 23 ++------ 3 files changed, 30 insertions(+), 54 deletions(-) diff --git a/core/core.php b/core/core.php index 36868c7b..b13741cd 100644 --- a/core/core.php +++ b/core/core.php @@ -592,60 +592,50 @@ class common /** * Initialisation des données - * @param array $module : nom du module à générer + * @param string $module : nom du module à générer + * @param string $lang la langue à créer + * @param bool $sampleSite créer un site exemple en FR * choix valides : core config user theme page module */ public function initData($module, $lang, $sampleSite = false) { - // Tableau avec les données vierges require_once('core/module/install/ressource/defaultdata.php'); - // Stockage dans un sous-dossier localisé + // Création des sous-dossiers if (!file_exists(self::DATA_DIR . $lang)) { mkdir(self::DATA_DIR . $lang, 0755); + } + if (!file_exists(self::DATA_DIR . $lang . '/content')) { mkdir(self::DATA_DIR . $lang . '/content', 0755); } - if ($lang == 'fr_FR') { - // Stockage dans un sous-dossier localisé - - $db = $this->dataFiles[$module]; - - if ($sampleSite === true) { - file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$siteTemplate[$langFolder][$module]])); - } else { - file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$defaultDataI18n[$langFolder][$module]])); - } - + // Site en français avec site exemple + if ($lang == 'fr_FR' && $sampleSite === true) { + file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$siteTemplate[$module]])); // Créer le jeu de pages du site de test if ($module === 'page') { - $langFolder = $lang . '/content/'; // Site de test ou page simple - if ($sampleSite === true) { - foreach (init::$siteContent as $key => $value) { - // Creation du contenu de la page - if (!empty($this->getData(['page', $key, 'content']))) { - file_put_contents(self::DATA_DIR . $langFolder . $this->getData(['page', $key, 'content']), $value); - } + foreach (init::$siteContent as $key => $value) { + // Creation du contenu de la page + if (!empty($this->getData(['page', $key, 'content']))) { + file_put_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $key, 'content']), $value); } - } else { - // Créer la page d'accueil - file_put_contents(self::DATA_DIR . $langFolder . 'accueil.html', '

Contenu de votre nouvelle page.

'); } } + + // Version en langue étrangère ou fr_FR sans site de test } else { // En_EN si le contenu localisé n'est pas traduit + $langDefault = $lang ; if (!isset(init::$defaultDataI18n[$lang])) { - $langFolder = 'default'; + $langDefault = 'default'; } - - file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$defaultDataI18n[$langFolder][$module]])); - + file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$defaultDataI18n[$langDefault][$module]])); // Créer la page d'accueil - $pageId = init::$defaultDataI18n[$langFolder]['locale']['homePageId']; - $content = init::$defaultDataI18n[$langFolder]['html']; - file_put_contents(self::DATA_DIR . $lang . '/content/' . init::$defaultDataI18n[$langFolder]['page'][$pageId]['content'], $content); + $pageId = init::$defaultDataI18n[$langDefault]['locale']['homePageId']; + $content = init::$defaultDataI18n[$langDefault]['html']; + file_put_contents(self::DATA_DIR . $lang . '/content/' . init::$defaultDataI18n[$langDefault]['page'][$pageId]['content'], $content); } } diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index 861f7229..cb7a53da 100644 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -427,7 +427,7 @@ class init extends common ] ]; public static $defaultDataI18n = [ - 'fr' => [ + 'fr_FR' => [ 'locale' => [ 'homePageId' => 'accueil', 'page302' => 'none', @@ -479,6 +479,7 @@ class init extends common ] ], 'module' => [], + 'html' => '

Bienvenue sur votre nouveau site Zwii !

' ], 'es' => [ 'locale' => [ @@ -531,7 +532,8 @@ class init extends common 'js' => '' ] ], - 'html' => '¡Bienvenido a ZwiiCMS, felicidades, esta es su primera página!' + 'module' => [], + 'html' => '

¡Bienvenido a ZwiiCMS, felicidades, esta es su primera página!

' ], 'default' => [ 'locale' => [ @@ -584,7 +586,8 @@ class init extends common 'js' => '' ] ], - 'html' => 'Welcome in this ZwiiCMS, congratulations this is you first page !' + 'module' => [], + 'html' => '

Welcome in this ZwiiCMS, congratulations this is you first page !

' ] ]; diff --git a/core/module/translate/translate.php b/core/module/translate/translate.php index cc76b770..7bf681f2 100644 --- a/core/module/translate/translate.php +++ b/core/module/translate/translate.php @@ -307,27 +307,10 @@ class translate extends common // Création du contenu $lang = $this->getInput('translateAddContent'); - require_once('core/module/install/ressource/defaultdata.php'); - // Stockage dans un sous-dossier localisé - if (!file_exists(self::DATA_DIR . $lang)) { - mkdir(self::DATA_DIR . $lang, 0755); - mkdir(self::DATA_DIR . $lang . '/content', 0755); - } - - // En_EN si le contenu localisé n'est pas traduit - if (!isset(init::$defaultDataI18n[$lang])) { - $langSource = 'default'; - } - - file_put_contents(self::DATA_DIR . $lang . '/locale.json', json_encode(['locale' => init::$defaultDataI18n[$langSource]['locale']])); - file_put_contents(self::DATA_DIR . $lang . '/page.json', json_encode(['page' => init::$defaultDataI18n[$langSource]['page']])); - file_put_contents(self::DATA_DIR . $lang . '/module.json', json_encode(['module' => []])); - - // Créer la page d'accueil - $pageId = init::$defaultDataI18n[$langSource]['locale']['homePageId']; - $content = init::$defaultDataI18n[$langSource]['html']; - file_put_contents(self::DATA_DIR . $lang . '/content/' . init::$defaultDataI18n[$langSource]['page'][$pageId]['content'], $content); + $this->initData('page', $lang); + $this->initData('module', $lang); + $this->initData('locale', $lang); // Valeurs en sortie $this->addOutput([