Gestion des paramètres de site (accueil, titre, méta) par langue WIP

This commit is contained in:
fredtempez 2019-09-19 09:41:00 +02:00
parent a5d72705e0
commit bb867dbe63
4 changed files with 44 additions and 43 deletions

View File

@ -176,11 +176,11 @@ class common {
foreach (self::$dataStage as $stageId) { foreach (self::$dataStage as $stageId) {
$folder = $this->dirData ($stageId, 'fr'); $folder = $this->dirData ($stageId, 'fr');
if (file_exists($folder . $stageId .'.json') === false) { if (file_exists($folder . $stageId .'.json') === false) {
$this->iniData($stageId,'fr'); $this->initData($stageId,'fr');
common::$coreNotices [] = $stageId ; common::$coreNotices [] = $stageId ;
} }
} }
// Déterminer la langue du visiteur // Déterminer la langue du visiteur
// -------------------------------- // --------------------------------
// 1 Langue sélectionnée par l'utilisateur prioritaire // 1 Langue sélectionnée par l'utilisateur prioritaire
@ -200,11 +200,10 @@ class common {
// Sauvegarder la sélection // Sauvegarder la sélection
$this->seti18N($i18nFrontEnd); $this->seti18N($i18nFrontEnd);
// Mise à jour des données core // Mise à jour des données core
$this->update(); $this->update();
// Utilisateur connecté // Utilisateur connecté
if($this->user === []) { if($this->user === []) {
$this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]); $this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]);
@ -270,7 +269,7 @@ class common {
$this->url = $url; $this->url = $url;
} }
else { else {
$this->url = $this->getData(['config', 'homePageId']); $this->url = $this->getData(['page', 'homePageId']);
} }
} }
} }
@ -686,10 +685,10 @@ class common {
* @param $lang langue des pages * @param $lang langue des pages
* @return string du dossier à créer * @return string du dossier à créer
*/ */
public function dirData ($stageId, $lang) { public function dirData($id, $lang) {
// Sauf pour les pages et les modules // Sauf pour les pages et les modules
if ($stageId === 'page' || if ($id === 'page' ||
$stageId === 'module') { $id === 'module') {
$folder = self::DATA_DIR . $lang . '/' ; $folder = self::DATA_DIR . $lang . '/' ;
} else { } else {
$folder = self::DATA_DIR; $folder = self::DATA_DIR;
@ -854,8 +853,8 @@ class common {
$mail = new PHPMailer\PHPMailer\PHPMailer; $mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->CharSet = 'UTF-8'; $mail->CharSet = 'UTF-8';
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']); $host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title'])); $mail->setFrom('no-reply@' . $host, $this->getData(['page', 'title']));
$mail->addReplyTo('no-reply@' . $host, $this->getData(['config', 'title'])); $mail->addReplyTo('no-reply@' . $host, $this->getData(['page', 'title']));
if(is_array($to)) { if(is_array($to)) {
foreach($to as $userMail) { foreach($to as $userMail) {
$mail->addAddress($userMail); $mail->addAddress($userMail);
@ -928,7 +927,7 @@ class common {
* @param array $module : nom du module à générer * @param array $module : nom du module à générer
* choix valides : core config user theme page module * choix valides : core config user theme page module
*/ */
public function iniData($module, $lang = 'fr') { public function initData($module, $lang = 'fr') {
// 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');
@ -945,7 +944,7 @@ class common {
'dir' => $folder, 'dir' => $folder,
'template' => self::TEMP_DIR . 'data.template.json' 'template' => self::TEMP_DIR . 'data.template.json'
]); ]);
$db->set($module,initdata::$defaultData[$module]); $db->set($module,init::$defaultData[$module]);
$db->save; $db->save;
} }
@ -1001,26 +1000,22 @@ class common {
// Version 8.4.4 // Version 8.4.4
if($this->getData(['core', 'dataVersion']) < 844) { if($this->getData(['core', 'dataVersion']) < 844) {
$this->setData(['core', 'dataVersion', 844]); $this->setData(['core', 'dataVersion', 844]);
//$this->SaveData();
} }
// Version 8.4.6 // Version 8.4.6
if($this->getData(['core', 'dataVersion']) < 846) { if($this->getData(['core', 'dataVersion']) < 846) {
$this->setData(['config','itemsperPage',10]); $this->setData(['config','itemsperPage',10]);
$this->setData(['core', 'dataVersion', 846]); $this->setData(['core', 'dataVersion', 846]);
//$this->saveData();
} }
// Version 8.5.0 // Version 8.5.0
if($this->getData(['core', 'dataVersion']) < 850) { if($this->getData(['core', 'dataVersion']) < 850) {
$this->setData(['theme','menu','font','Open+Sans']); $this->setData(['theme','menu','font','Open+Sans']);
$this->setData(['core', 'dataVersion', 850]); $this->setData(['core', 'dataVersion', 850]);
//$this->saveData();
} }
// Version 8.5.1 // Version 8.5.1
if($this->getData(['core', 'dataVersion']) < 851) { if($this->getData(['core', 'dataVersion']) < 851) {
$this->setData(['config','itemsperPage',10]); $this->setData(['config','itemsperPage',10]);
$this->deleteData(['config','ItemsperPage']); $this->deleteData(['config','ItemsperPage']);
$this->setData(['core', 'dataVersion', 851]); $this->setData(['core', 'dataVersion', 851]);
//$this->saveData();
} }
// Version 9.0.0 // Version 9.0.0
if($this->getData(['core', 'dataVersion']) < 9000) { if($this->getData(['core', 'dataVersion']) < 9000) {
@ -1030,13 +1025,11 @@ class common {
} }
$this->setData(['theme', 'menu','fixed',false]); $this->setData(['theme', 'menu','fixed',false]);
$this->setData(['core', 'dataVersion', 9000]); $this->setData(['core', 'dataVersion', 9000]);
//$this->saveData();
} }
// Version 9.0.01 // Version 9.0.01
if($this->getData(['core', 'dataVersion']) < 9001) { if($this->getData(['core', 'dataVersion']) < 9001) {
$this->deleteData(['config', 'social', 'googleplusId']); $this->deleteData(['config', 'social', 'googleplusId']);
$this->setData(['core', 'dataVersion', 9001]); $this->setData(['core', 'dataVersion', 9001]);
//$this->saveData();
} }
// Version 9.0.08 // Version 9.0.08
if($this->getData(['core', 'dataVersion']) < 9008) { if($this->getData(['core', 'dataVersion']) < 9008) {
@ -1045,31 +1038,26 @@ class common {
$this->setData(['theme', 'footer', 'fontSize','.8em']); $this->setData(['theme', 'footer', 'fontSize','.8em']);
$this->setData(['theme', 'footer', 'font','Open+Sans']); $this->setData(['theme', 'footer', 'font','Open+Sans']);
$this->setData(['core', 'dataVersion', 9008]); $this->setData(['core', 'dataVersion', 9008]);
//$this->saveData();
} }
// Version 9.0.09 // Version 9.0.09
if($this->getData(['core', 'dataVersion']) < 9009) { if($this->getData(['core', 'dataVersion']) < 9009) {
$this->setData(['core', 'dataVersion', 9009]); $this->setData(['core', 'dataVersion', 9009]);
//$this->saveData();
} }
// Version 9.0.10 // Version 9.0.10
if($this->getData(['core', 'dataVersion']) < 9010) { if($this->getData(['core', 'dataVersion']) < 9010) {
$this->deleteData(['config', 'social', 'googleplusId']); $this->deleteData(['config', 'social', 'googleplusId']);
$this->setData(['core', 'dataVersion', 9010]); $this->setData(['core', 'dataVersion', 9010]);
//$this->saveData();
} }
// Version 9.0.11 // Version 9.0.11
if($this->getData(['core', 'dataVersion']) < 9011) { if($this->getData(['core', 'dataVersion']) < 9011) {
if ($this->getData(['theme','menu','position']) === 'body') if ($this->getData(['theme','menu','position']) === 'body')
$this->setData(['theme','menu','position','site']); $this->setData(['theme','menu','position','site']);
$this->setData(['core', 'dataVersion', 9011]); $this->setData(['core', 'dataVersion', 9011]);
//$this->saveData();
} }
// Version 9.0.17 // Version 9.0.17
if($this->getData(['core', 'dataVersion']) < 9017) { if($this->getData(['core', 'dataVersion']) < 9017) {
$this->setData(['theme','footer','displayVersion', true ]); $this->setData(['theme','footer','displayVersion', true ]);
$this->setData(['core', 'dataVersion', 9017]); $this->setData(['core', 'dataVersion', 9017]);
//$this->saveData();
} }
// Version 9.1.0 // Version 9.1.0
if($this->getData(['core', 'dataVersion']) < 9100) { if($this->getData(['core', 'dataVersion']) < 9100) {
@ -1077,7 +1065,6 @@ class common {
$this->setData(['theme','footer','displaySiteMap', true ]); $this->setData(['theme','footer','displaySiteMap', true ]);
$this->setData(['theme','footer','displayCopyright', true ]); $this->setData(['theme','footer','displayCopyright', true ]);
$this->setData(['core', 'dataVersion', 9100]); $this->setData(['core', 'dataVersion', 9100]);
//$this->saveData();
} }
// Version 9.2.00 // Version 9.2.00
if($this->getData(['core', 'dataVersion']) < 9200) { if($this->getData(['core', 'dataVersion']) < 9200) {
@ -1087,7 +1074,6 @@ class common {
$this->setData(['theme','footer','displaySearch', false ]); $this->setData(['theme','footer','displaySearch', false ]);
$this->setData(['config','social','githubId', '' ]); $this->setData(['config','social','githubId', '' ]);
$this->setData(['core', 'dataVersion', 9200]); $this->setData(['core', 'dataVersion', 9200]);
//$this->saveData();
} }
// Version 9.2.05 // Version 9.2.05
if($this->getData(['core', 'dataVersion']) < 9205) { if($this->getData(['core', 'dataVersion']) < 9205) {
@ -1104,13 +1090,19 @@ class common {
rmdir ('core/vendor/swiper/'); rmdir ('core/vendor/swiper/');
} }
$this->setData(['core', 'dataVersion', 9205]); $this->setData(['core', 'dataVersion', 9205]);
//$this->saveData();
} }
// Version 10.0.00 // Version 10.0.00
if($this->getData(['core', 'dataVersion']) < 10000) { if($this->getData(['core', 'dataVersion']) < 10000) {
$this->setData(['config','i18n','fr']); $this->setData(['config','i18n','fr']);
$this->setData(['core', 'dataVersion', 10000]); if ($this->getData(['config','homePageId']) !== NULL) {
//$this->saveData(); $this->setData(['page','homePageId',$this->getData(['config','homePageId'])]);
$this->setData(['page','title',$this->getData(['config','title'])]);
$this->setData(['page','metaDescription',$this->getData(['config','metaDescription'])]);
$this->deleteData(['config','homePageId']);
$this->deleteData(['config','title']);
$this->deleteData(['config','metaDescription']);
}
$this->setData(['core', 'dataVersion', 10000]);
} }
} }
@ -1714,6 +1706,9 @@ class helper {
*/ */
public static function arrayCollumn($array, $column, $sort = null) { public static function arrayCollumn($array, $column, $sort = null) {
$newArray = []; $newArray = [];
unset($array['homePageId']);
unset($array['metaDescription']);
unset($array['title']);
if(empty($array) === false) { if(empty($array) === false) {
$newArray = array_map(function($element) use($column) { $newArray = array_map(function($element) use($column) {
return $element[$column]; return $element[$column];

View File

@ -276,8 +276,6 @@ class config extends common {
'maintenance' => $this->getInput('configMaintenance', helper::FILTER_BOOLEAN), 'maintenance' => $this->getInput('configMaintenance', helper::FILTER_BOOLEAN),
'cookieConsent' => $this->getInput('configCookieConsent', helper::FILTER_BOOLEAN), 'cookieConsent' => $this->getInput('configCookieConsent', helper::FILTER_BOOLEAN),
'favicon' => $this->getInput('configFavicon'), 'favicon' => $this->getInput('configFavicon'),
'homePageId' => $this->getInput('configHomePageId', helper::FILTER_ID, true),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'social' => [ 'social' => [
'facebookId' => $this->getInput('configSocialFacebookId'), 'facebookId' => $this->getInput('configSocialFacebookId'),
'linkedinId' => $this->getInput('configSocialLinkedinId'), 'linkedinId' => $this->getInput('configSocialLinkedinId'),
@ -288,11 +286,19 @@ class config extends common {
'githubId' => $this->getInput('configSocialGithubId') 'githubId' => $this->getInput('configSocialGithubId')
], ],
'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true), 'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true),
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true),
'itemsperPage' => $this->getInput('itemsperPage', helper::FILTER_INT,true), 'itemsperPage' => $this->getInput('itemsperPage', helper::FILTER_INT,true),
'legalPageId' => $this->getInput('configLegalPageId') 'legalPageId' => $this->getInput('configLegalPageId')
] ]
]); ]);
$this->setData([
'page',
[
'homePageId' => $this->getInput('configHomePageId', helper::FILTER_ID, true),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true)
]
]);
if(self::$inputNotices === []) { if(self::$inputNotices === []) {
// Ecrire les fichiers de script // Ecrire les fichiers de script
file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null)); file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null));

View File

@ -18,22 +18,22 @@
<h4>Informations générales</h4> <h4>Informations générales</h4>
<div class="row"> <div class="row">
<div class="col4"> <div class="col4">
<?php echo template::select('configHomePageId', helper::arrayCollumn($this->getData(['page']), 'title', 'SORT_ASC'), [ <?php echo template::select('pageHomePageId', helper::arrayCollumn($this->getData(['page']), 'title', 'SORT_ASC'), [
'label' => 'Page d\'accueil', 'label' => 'Page d\'accueil',
'selected' => $this->getData(['config', 'homePageId']) 'selected' => $this->getData(['page', 'homePageId'])
]); ?> ]); ?>
</div> </div>
<div class="col8"> <div class="col8">
<?php echo template::text('configTitle', [ <?php echo template::text('pageTitle', [
'label' => 'Titre du site', 'label' => 'Titre du site',
'value' => $this->getData(['config', 'title']), 'value' => $this->getData(['page', 'title']),
'help' => 'Il apparaît dans la barre de titre et les partages sur les réseaux sociaux.' 'help' => 'Il apparaît dans la barre de titre et les partages sur les réseaux sociaux.'
]); ?> ]); ?>
</div> </div>
</div> </div>
<?php echo template::textarea('configMetaDescription', [ <?php echo template::textarea('pageMetaDescription', [
'label' => 'Description du site', 'label' => 'Description du site',
'value' => $this->getData(['config', 'metaDescription']), 'value' => $this->getData(['page', 'metaDescription']),
'help' => 'Elle apparaît dans les partages sur les réseaux sociaux.' 'help' => 'Elle apparaît dans les partages sur les réseaux sociaux.'
]); ?> ]); ?>
</div> </div>

View File

@ -1,5 +1,5 @@
<?php <?php
class initdata extends common { class init extends common {
public static $defaultData = [ public static $defaultData = [
'config' => [ 'config' => [
@ -7,9 +7,7 @@ class initdata extends common {
'autoBackup' => true, 'autoBackup' => true,
'cookieConsent' => true, 'cookieConsent' => true,
'favicon' => 'favicon.ico', 'favicon' => 'favicon.ico',
'homePageId' => 'accueil', 'maintenance' => false,
'maintenance' => false,
'metaDescription' => 'Zwii est un CMS sans base de données qui permet de créer et gérer facilement un site web sans aucune connaissance en programmation.',
'social' => [ 'social' => [
'facebookId' => 'facebook', 'facebookId' => 'facebook',
'instagramId' => '', 'instagramId' => '',
@ -19,17 +17,19 @@ class initdata extends common {
'githubId' => '' 'githubId' => ''
], ],
'timezone' => 'Europe/Paris', 'timezone' => 'Europe/Paris',
'title' => 'Zwii, votre site en quelques clics !',
'itemsperPage' => 10, 'itemsperPage' => 10,
'legalPageId' => '', 'legalPageId' => '',
'i18n' => 'fr' 'i18n' => 'fr'
], ],
'core' => [ 'core' => [
'dataVersion' => 0, 'dataVersion' => 1000,
'lastBackup' => 0, 'lastBackup' => 0,
'lastClearTmp' => 0 'lastClearTmp' => 0
], ],
'page' => [ 'page' => [
'homePageId' => 'accueil',
'metaDescription' => 'Zwii est un CMS sans base de données qui permet de créer et gérer facilement un site web sans aucune connaissance en programmation.',
'title' => 'Zwii, votre site en quelques clics !',
'accueil' => [ 'accueil' => [
'typeMenu' => 'text', 'typeMenu' => 'text',
'iconUrl' => '', 'iconUrl' => '',