nouveau initData

This commit is contained in:
Fred Tempez 2023-04-14 09:00:15 +02:00
parent a66bc7d948
commit 0d6d43381c
3 changed files with 30 additions and 54 deletions

View File

@ -592,60 +592,50 @@ class common
/** /**
* Initialisation des données * 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 * choix valides : core config user theme page module
*/ */
public function initData($module, $lang, $sampleSite = false) public function initData($module, $lang, $sampleSite = false)
{ {
// Tableau avec les données vierges // Tableau avec les données vierges
require_once('core/module/install/ressource/defaultdata.php'); 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)) { if (!file_exists(self::DATA_DIR . $lang)) {
mkdir(self::DATA_DIR . $lang, 0755); mkdir(self::DATA_DIR . $lang, 0755);
}
if (!file_exists(self::DATA_DIR . $lang . '/content')) {
mkdir(self::DATA_DIR . $lang . '/content', 0755); mkdir(self::DATA_DIR . $lang . '/content', 0755);
} }
if ($lang == 'fr_FR') { // Site en français avec site exemple
// Stockage dans un sous-dossier localisé if ($lang == 'fr_FR' && $sampleSite === true) {
file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$siteTemplate[$module]]));
$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]]));
}
// Créer le jeu de pages du site de test // Créer le jeu de pages du site de test
if ($module === 'page') { if ($module === 'page') {
$langFolder = $lang . '/content/';
// Site de test ou page simple // Site de test ou page simple
if ($sampleSite === true) { foreach (init::$siteContent as $key => $value) {
foreach (init::$siteContent as $key => $value) { // Creation du contenu de la page
// Creation du contenu de la page if (!empty($this->getData(['page', $key, 'content']))) {
if (!empty($this->getData(['page', $key, 'content']))) { file_put_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $key, 'content']), $value);
file_put_contents(self::DATA_DIR . $langFolder . $this->getData(['page', $key, 'content']), $value);
}
} }
} else {
// Créer la page d'accueil
file_put_contents(self::DATA_DIR . $langFolder . 'accueil.html', '<p>Contenu de votre nouvelle page.</p>');
} }
} }
// Version en langue étrangère ou fr_FR sans site de test
} else { } else {
// En_EN si le contenu localisé n'est pas traduit // En_EN si le contenu localisé n'est pas traduit
$langDefault = $lang ;
if (!isset(init::$defaultDataI18n[$lang])) { if (!isset(init::$defaultDataI18n[$lang])) {
$langFolder = 'default'; $langDefault = 'default';
} }
file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$defaultDataI18n[$langDefault][$module]]));
file_put_contents(self::DATA_DIR . $lang . '/' . $module . '.json', json_encode([$module => init::$defaultDataI18n[$langFolder][$module]]));
// Créer la page d'accueil // Créer la page d'accueil
$pageId = init::$defaultDataI18n[$langFolder]['locale']['homePageId']; $pageId = init::$defaultDataI18n[$langDefault]['locale']['homePageId'];
$content = init::$defaultDataI18n[$langFolder]['html']; $content = init::$defaultDataI18n[$langDefault]['html'];
file_put_contents(self::DATA_DIR . $lang . '/content/' . init::$defaultDataI18n[$langFolder]['page'][$pageId]['content'], $content); file_put_contents(self::DATA_DIR . $lang . '/content/' . init::$defaultDataI18n[$langDefault]['page'][$pageId]['content'], $content);
} }
} }

View File

@ -427,7 +427,7 @@ class init extends common
] ]
]; ];
public static $defaultDataI18n = [ public static $defaultDataI18n = [
'fr' => [ 'fr_FR' => [
'locale' => [ 'locale' => [
'homePageId' => 'accueil', 'homePageId' => 'accueil',
'page302' => 'none', 'page302' => 'none',
@ -479,6 +479,7 @@ class init extends common
] ]
], ],
'module' => [], 'module' => [],
'html' => '<h2>Bienvenue sur votre nouveau site Zwii !</h2>'
], ],
'es' => [ 'es' => [
'locale' => [ 'locale' => [
@ -531,7 +532,8 @@ class init extends common
'js' => '' 'js' => ''
] ]
], ],
'html' => '¡Bienvenido a ZwiiCMS, felicidades, esta es su primera página!' 'module' => [],
'html' => '<h2>¡Bienvenido a ZwiiCMS, felicidades, esta es su primera página!</h2>'
], ],
'default' => [ 'default' => [
'locale' => [ 'locale' => [
@ -584,7 +586,8 @@ class init extends common
'js' => '' 'js' => ''
] ]
], ],
'html' => 'Welcome in this ZwiiCMS, congratulations this is you first page !' 'module' => [],
'html' => '<h2>Welcome in this ZwiiCMS, congratulations this is you first page !</h2>'
] ]
]; ];

View File

@ -307,27 +307,10 @@ class translate extends common
// Création du contenu // Création du contenu
$lang = $this->getInput('translateAddContent'); $lang = $this->getInput('translateAddContent');
require_once('core/module/install/ressource/defaultdata.php');
// Stockage dans un sous-dossier localisé $this->initData('page', $lang);
if (!file_exists(self::DATA_DIR . $lang)) { $this->initData('module', $lang);
mkdir(self::DATA_DIR . $lang, 0755); $this->initData('locale', $lang);
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);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([