Databases language et font

This commit is contained in:
Fred Tempez 2023-03-01 15:50:41 +01:00
parent b9ce213df5
commit 1d158a3fde
17 changed files with 103 additions and 77 deletions

View File

@ -686,15 +686,15 @@ class template
'label' => '',
'name' => $nameId,
'selected' => '',
'fonts' => []
'font' => []
], $attributes);
// Traduction de l'aide et de l'étiquette
$attributes['label'] = helper::translate($attributes['label']);
$attributes['help'] = helper::translate($attributes['help']);
// Stocker les fontes et remettre à zéro le tableau des fontes transmis pour éviter une erreur de sprintAttributes
if (empty($attributes['fonts']) === false) {
$fonts = $attributes['fonts'];
$attributes['fonts'] = [];
if (empty($attributes['font']) === false) {
$fonts = $attributes['font'];
$attributes['font'] = [];
}
// Sauvegarde des données en cas d'erreur
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {

View File

@ -47,7 +47,7 @@ class common
const ACCESS_TIMER = 1800;
// Numéro de version et branche pour l'auto-update
const ZWII_VERSION = '12.3.00';
const ZWII_VERSION = '12.4.00';
const ZWII_DATAVERSION = 12300;
@ -225,13 +225,13 @@ class common
'blacklist' => '',
'config' => '',
'core' => '',
'fonts' => '',
'font' => '',
'module' => '',
'locale' => '',
'page' => '',
'theme' => '',
'user' => '',
'languages' => '',
'language' => '',
];
public static $fontsWebSafe = [
@ -643,10 +643,10 @@ class common
{
// Créer la base de données des langues
if ($module === 'languages') {
copy('core/module/install/ressource/i18n/languages.json', self::DATA_DIR . 'languages.json');
if ($module === 'language') {
copy('core/module/install/ressource/i18n/language.json', self::DATA_DIR . 'language.json');
$this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR);
unlink(self::I18N_DIR . 'languages.json');
unlink(self::I18N_DIR . 'language.json');
return;
}
@ -2507,8 +2507,8 @@ class core extends common
*/
// Fonts disponibles
$fontsAvailable['files'] = $this->getData(['fonts', 'files']);
$fontsAvailable['imported'] = $this->getData(['fonts', 'imported']);
$fontsAvailable['files'] = $this->getData(['font', 'files']);
$fontsAvailable['imported'] = $this->getData(['font', 'imported']);
$fontsAvailable['websafe'] = self::$fontsWebSafe;
// Fontes installées
@ -2549,8 +2549,8 @@ class core extends common
$fontFile = $gf ? '<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . $fontFile
: $fontFile;
// Enregistre la personnalisation
if (!is_dir(self::DATA_DIR . 'fonts')) {
mkdir(self::DATA_DIR . 'fonts');
if (!is_dir(self::DATA_DIR . 'font')) {
mkdir(self::DATA_DIR . 'font');
}
file_put_contents(self::DATA_DIR . 'fonts/fonts.html', $fontFile);
@ -2729,8 +2729,8 @@ class core extends common
$css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}';
// Enregistre les fontes
if (!is_dir(self::DATA_DIR . 'fonts')) {
mkdir(self::DATA_DIR . 'fonts');
if (!is_dir(self::DATA_DIR . 'font')) {
mkdir(self::DATA_DIR . 'font');
}
file_put_contents(self::DATA_DIR . 'fonts/fonts.html', $fontFile);
@ -2753,8 +2753,8 @@ class core extends common
$css = '/*' . md5(json_encode($this->getData(['admin']))) . '*/';
// Fonts disponibles
$fontsAvailable['files'] = $this->getData(['fonts', 'files']);
$fontsAvailable['imported'] = $this->getData(['fonts', 'imported']);
$fontsAvailable['files'] = $this->getData(['font', 'files']);
$fontsAvailable['imported'] = $this->getData(['font', 'imported']);
$fontsAvailable['websafe'] = self::$fontsWebSafe;
/**

View File

@ -25,4 +25,13 @@ if (file_exists('site/data/core.json')) {
}
sleep(2);
}
if ($version['core']['dataVersion'] < 12400) {
if (file_exists('core/module/install/ressource/i18n/languages.json'))
rename('core/module/install/ressource/i18n/languages.json', 'core/module/install/ressource/i18n/language.json');
if (file_exists('site/data/languages.json'))
rename('site/data/languages.json', 'site/data/language.json');
if (file_exists('site/data/fonts.json'))
rename('site/data/fonts.json', 'site/data/font.json');
}
}

View File

@ -68,7 +68,7 @@ class install extends common
// Liste des langues UI disponibles
if (is_dir(self::I18N_DIR)) {
foreach ($this->getData(['languages']) as $lang => $value) {
foreach ($this->getData(['language']) as $lang => $value) {
self::$i18nFiles[$lang] = self::$languages[$lang];
;
}
@ -201,8 +201,8 @@ class install extends common
unlink(self::TEMP_DIR . 'files.tar');
// Créer le dossier des fontes
if (!is_dir(self::DATA_DIR . 'fonts')) {
mkdir(self::DATA_DIR . 'fonts');
if (!is_dir(self::DATA_DIR . 'font')) {
mkdir(self::DATA_DIR . 'font');
}
// Installation du thème sélectionné
@ -227,9 +227,9 @@ class install extends common
}
// Créer la base de données des langues
copy('core/module/install/ressource/i18n/languages.json', self::DATA_DIR . 'languages.json');
copy('core/module/install/ressource/i18n/language.json', self::DATA_DIR . 'language.json');
$this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR);
unlink(self::I18N_DIR . 'languages.json');
unlink(self::I18N_DIR . 'language.json');
// Fixe l'adresse from pour les envois d'email
$this->setData(['config', 'smtp', 'from', 'no-reply@' . str_replace('www.', '', $_SERVER['HTTP_HOST'])]);
@ -384,16 +384,16 @@ class install extends common
*/
// Langues installées
$installedUI = $this->getData(['languages']);
$installedUI = $this->getData(['language']);
// Langues disponibles avec la mise à jour
$store = json_decode(file_get_contents('core/module/install/ressource/i18n/languages.json'), true);
$store = $store['languages'];
$store = json_decode(file_get_contents('core/module/install/ressource/i18n/language.json'), true);
$store = $store['language'];
foreach ($installedUI as $key => $value) {
if ($store[$key]['version'] > $value['version']) {
echo copy('core/module/install/ressource/i18n/' . $key . '.json', self::I18N_DIR . $key . '.json');
$this->setData(['languages', $key, $store[$key]]);
$this->setData(['language', $key, $store[$key]]);
}
}

View File

@ -70,7 +70,7 @@ class init extends common
'buttonValidLabel' => 'J\'ai compris'
]
],
'fonts' => [
'font' => [
'files' => [],
'imported' => [
'arimo' => [
@ -333,7 +333,7 @@ class init extends common
'borderBlockColor' => 'rgba(190, 202, 209, 1)'
],
'blacklist' => [],
'languages'=> [],
'language'=> [],
];
public static $defaultDataI18n = [
'en_EN' => [

View File

@ -602,8 +602,8 @@ class theme extends common
// Récupérer le détail des fontes installées
//$f = $this->getFonts();
$f['files'] = $this->getData(['fonts', 'files']);
$f['imported'] = $this->getData(['fonts', 'imported']);
$f['files'] = $this->getData(['font', 'files']);
$f['imported'] = $this->getData(['font', 'imported']);
$f['websafe'] = self::$fontsWebSafe;
// Parcourir les fontes disponibles et construire le tableau pour le formulaire
@ -669,12 +669,12 @@ class theme extends common
$fontFamilyName = str_replace('"', '\'', $fontFamilyName);
// Supprime la fonte si elle existe dans le type inverse
if (is_array($this->getData(['fonts', $typeFlip, $fontId]))) {
$this->deleteData(['fonts', $typeFlip, $fontId]);
if (is_array($this->getData(['font', $typeFlip, $fontId]))) {
$this->deleteData(['font', $typeFlip, $fontId]);
}
// Stocker la fonte
$this->setData([
'fonts',
'font',
$type,
$fontId, [
'name' => $fontName,
@ -734,12 +734,12 @@ class theme extends common
$fontFamilyName = str_replace('"', '\'', $fontFamilyName);
// Supprime la fonte si elle existe dans le type inverse
if (is_array($this->getData(['fonts', $typeFlip, $fontId]))) {
$this->deleteData(['fonts', $typeFlip, $fontId]);
if (is_array($this->getData(['font', $typeFlip, $fontId]))) {
$this->deleteData(['font', $typeFlip, $fontId]);
}
// Stocker les fontes
$this->setData([
'fonts',
'font',
$type,
$fontId, [
'name' => $fontName,
@ -786,7 +786,7 @@ class theme extends common
else {
// Effacer la fonte de la base
$this->deleteData(['fonts', $this->getUrl(2), $this->getUrl(3)]);
$this->deleteData(['font', $this->getUrl(2), $this->getUrl(3)]);
// Effacer le fichier existant
if (
@ -1078,8 +1078,8 @@ class theme extends common
$zip->addFile(self::DATA_DIR . 'admin.json', self::DATA_DIR . 'admin.json');
$zip->addFile(self::DATA_DIR . 'admin.css', self::DATA_DIR . 'admin.css');
// Ajoute les fontes
$zip->addEmptyDir(self::DATA_DIR . 'fonts');
$fonts = $this->getData(['fonts', 'files']);
$zip->addEmptyDir(self::DATA_DIR . 'font');
$fonts = $this->getData(['font', 'files']);
foreach ($fonts as $fontId => $fontName) {
$zip->addFile(self::DATA_DIR . 'fonts/' . $fontName, self::DATA_DIR . 'fonts/' . $fontName);
}
@ -1116,8 +1116,8 @@ class theme extends common
}
}
// Ajoute les fontes
$zip->addEmptyDir(self::DATA_DIR . 'fonts');
$fonts = $this->getData(['fonts', 'files']);
$zip->addEmptyDir(self::DATA_DIR . 'font');
$fonts = $this->getData(['font', 'files']);
foreach ($fonts as $fontId => $fontName) {
$zip->addFile(self::DATA_DIR . 'fonts/' . $fontName, self::DATA_DIR . 'fonts/' . $fontName);
}
@ -1197,8 +1197,8 @@ class theme extends common
* id - nom
* id - font-family - resource
*/
$f['files'] = $this->getData(['fonts', 'files']);
$f['imported'] = $this->getData(['fonts', 'imported']);
$f['files'] = $this->getData(['font', 'files']);
$f['imported'] = $this->getData(['font', 'imported']);
$f['websafe'] = self::$fontsWebSafe;
// Construit un tableau avec leur ID et leur famille
foreach (['websafe', 'imported', 'files'] as $type) {
@ -1240,8 +1240,8 @@ class theme extends common
*/
$gf = false;
$fileContent = '<!-- Fontes personnalisées -->';
if (!empty($this->getData(['fonts', 'imported']))) {
foreach ($this->getData(['fonts', 'imported']) as $fontId => $fontValue) {
if (!empty($this->getData(['font', 'imported']))) {
foreach ($this->getData(['font', 'imported']) as $fontId => $fontValue) {
if (
($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all'
@ -1265,8 +1265,8 @@ class theme extends common
* Fontes installées localement
*/
$fileContentCss = '';
if (!empty($this->getData(['fonts', 'files']))) {
foreach ($this->getData(['fonts', 'files']) as $fontId => $fontValue) {
if (!empty($this->getData(['font', 'files']))) {
foreach ($this->getData(['font', 'files']) as $fontId => $fontValue) {
if (
($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all'

View File

@ -133,7 +133,7 @@
<?php echo template::select('adminFontText', $module::$fonts['name'], [
'label' => 'Police du texte',
'selected' => $this->getData(['admin', 'fontText']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col4">
@ -146,7 +146,7 @@
<?php echo template::select('adminFontTitle', $module::$fonts['name'], [
'label' => 'Police des titres',
'selected' => $this->getData(['admin', 'fontTitle']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
</div>

View File

@ -51,7 +51,7 @@
<?php echo template::text('fontEditFontName', [
'autocomplete' => 'off',
'label' => 'Nom',
'value' => $this->getData(['fonts', $this->getUrl(2), $this->getUrl(3), 'name'])
'value' => $this->getData(['font', $this->getUrl(2), $this->getUrl(3), 'name'])
]); ?>
</div>
</div>
@ -60,7 +60,7 @@
<?php echo template::text('fontEditFontFamilyName', [
'autocomplete' => 'off',
'label' => 'Famille',
'value' => stripslashes($this->getData(['fonts', $this->getUrl(2), $this->getUrl(3), 'font-family']))
'value' => stripslashes($this->getData(['font', $this->getUrl(2), $this->getUrl(3), 'font-family']))
]); ?>
</div>
</div>
@ -69,7 +69,7 @@
<?php echo template::file('fontEditFile', [
'label' => 'Fichier de fonte (Format WOFF)',
'language' => $this->getData(['user', $this->getUser('id'), 'language']),
'value' => $this->getUrl(2) === 'files' ? $this->getData(['fonts', $this->getUrl(2), $this->getUrl(3), 'resource']) : ''
'value' => $this->getUrl(2) === 'files' ? $this->getData(['font', $this->getUrl(2), $this->getUrl(3), 'resource']) : ''
]); ?>
</div>
</div>
@ -77,7 +77,7 @@
<div class="col12">
<?php echo template::text('fontEditUrl', [
'label' => 'Url du fichier de fonte',
'value' => $this->getUrl(2) === 'imported' ? $this->getData(['fonts', $this->getUrl(2), $this->getUrl(3), 'resource']) : ''
'value' => $this->getUrl(2) === 'imported' ? $this->getData(['font', $this->getUrl(2), $this->getUrl(3), 'resource']) : ''
]); ?>
</div>
</div>

View File

@ -175,7 +175,7 @@
<?php echo template::select('themeFooterFont', $module::$fonts['name'], [
'label' => 'Fonte',
'selected' => $this->getData(['theme', 'footer', 'font']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col3">

View File

@ -112,7 +112,7 @@
<?php echo template::select('themeHeaderFont', $module::$fonts['name'], [
'label' => 'Fonte',
'selected' => $this->getData(['theme', 'header', 'font']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col4">

View File

@ -191,7 +191,7 @@
<?php echo template::select('themeMenuFont', $module::$fonts['name'], [
'label' => 'Fonte',
'selected' => $this->getData(['theme', 'menu', 'font']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col6">

View File

@ -166,7 +166,7 @@
echo template::select('themeTextFont', $module::$fonts['name'], [
'label' => 'Fonte',
'selected' => $this->getData(['theme', 'text', 'font']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col6">
@ -188,7 +188,7 @@
<?php echo template::select('themeTitleFont', $module::$fonts['name'], [
'label' => 'Fonte',
'selected' => $this->getData(['theme', 'title', 'font']),
'fonts' => $module::$fonts['family']
'font' => $module::$fonts['family']
]); ?>
</div>
<div class="col4">

View File

@ -84,12 +84,12 @@ class translate extends common
if ($response !== false) {
$response = file_put_contents(self::I18N_DIR . $lang . '.json', json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
// Mettre à jour le descripteur
$enumsStore = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true);
$enums = $this->getData(['languages']);
$enumsStore = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'language.json'), true);
$enums = $this->getData(['language']);
$enums = array_merge($enums, [
$lang => $enumsStore['languages'][$lang]
$lang => $enumsStore['language'][$lang]
]);
$response = (bool) $response && $this->setData(['languages', $enums]);
$response = (bool) $response && $this->setData(['language', $enums]);
}
// Valeurs en sortie
@ -173,15 +173,20 @@ class translate extends common
*/
// Langues installées
$installedUI = $this->getData(['languages']);
$installedUI = $this->getData(['language']);
// Langues disponibles avec la mise à jour
$store = json_decode(file_get_contents('core/module/install/ressource/i18n/languages.json'), true);
$store = $store['languages'];
$store = json_decode(file_get_contents('core/module/install/ressource/i18n/language.json'), true);
if (array_key_exists('languages', $store )) {
$store = $store['languages'];
}
if (array_key_exists('language', $store )) {
$store = $store['language'];
}
if ($installedUI) {
foreach($installedUI as $key => $value) {
if ($store[$key]['version'] > $value['version']) {
$this->setData(['languages', $key, $store[$key]]);
$this->setData(['language', $key, $store[$key]]);
}
}
}
@ -232,11 +237,23 @@ class translate extends common
}
// Langues installées
$installedUI = $this->getData(['languages']);
$installedUI = $this->getData(['language']);
if (array_key_exists('languages', $installedUI )) {
$installedUI = $installedUI['languages'];
}
if (array_key_exists('language', $installedUI )) {
$installedUI = $installedUI['language'];
}
// Langues disponibles en ligne
$storeUI = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true);
$storeUI = $storeUI['languages'];
$storeUI = is_null (json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'language.json'), true))
? json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true)
: json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'language.json'), true);
if (array_key_exists('languages', $storeUI )) {
$storeUI = $storeUI['languages'];
}
if (array_key_exists('language', $storeUI )) {
$storeUI = $storeUI['language'];
}
// Construction du tableau à partir des langues disponibles dans le store
foreach ($installedUI as $file => $value) {
@ -479,7 +496,7 @@ class translate extends common
// Mettre à jour le descripteur
$this->setData([
'languages',
'language',
$lang,
[
'version' => $this->getInput('translateEditVersion'),
@ -575,7 +592,7 @@ class translate extends common
$success = false;
// Effacement d'une langue de l'interface
if (file_exists(self::I18N_DIR . $lang . '.json') === true) {
$this->deleteData(['languages', $lang]);
$this->deleteData(['language', $lang]);
$success = unlink(self::I18N_DIR . $lang . '.json');
}
// Effacer la langue dans la base

View File

@ -21,14 +21,14 @@
<div class="col6">
<?php echo template::text('translateEditVersion', [
'label' => 'Version n°',
'value' => $this->getData(['languages', $this->getUrl(2), 'version'])
'value' => $this->getData(['language', $this->getUrl(2), 'version'])
]); ?>
</div>
<div class="col6">
<?php echo template::date('translateEditDate', [
'label' => 'Date de publication',
'type' => 'datetime-local',
'value' => $this->getData(['languages', $this->getUrl(2), 'date'])
'value' => $this->getData(['language', $this->getUrl(2), 'date'])
]); ?>
</div>
</div>

View File

@ -302,7 +302,7 @@ class user extends common
}
// Langues disponibles pour l'interface de l'utilisateur
self::$languagesInstalled = $this->getData(['languages']);
self::$languagesInstalled = $this->getData(['language']);
foreach (self::$languagesInstalled as $lang => $datas) {
self::$languagesInstalled[$lang] = self::$languages[$lang];
}

View File

@ -191,7 +191,7 @@ class imageLib {
private $captionBoxPositionArray = array();
private $fontDir = 'fonts';
private $fontDir = 'font';
private $cropFromTopPercent = 10;