Theme reset csrf

This commit is contained in:
Fred Tempez 2023-06-20 20:14:57 +02:00
parent a68e30b52f
commit f4dfbbe8e0
1 changed files with 236 additions and 205 deletions

View File

@ -105,7 +105,8 @@ class theme extends common
'2.4vmax' => '240%' '2.4vmax' => '240%'
]; ];
public static $headerHeights = [ public static $headerHeights = [
'unset' => 'Libre', // texte dynamique cf header.js.php 'unset' => 'Libre',
// texte dynamique cf header.js.php
'100px' => '100px', '100px' => '100px',
'150px' => '150px', '150px' => '150px',
'200px' => '200px', '200px' => '200px',
@ -119,7 +120,7 @@ class theme extends common
]; ];
public static $headerFeatures = [ public static $headerFeatures = [
'wallpaper' => 'Couleur unie ou papier-peint', 'wallpaper' => 'Couleur unie ou papier-peint',
'feature' => 'Contenu HTML' 'feature' => 'Contenu HTML'
]; ];
public static $imagePositions = [ public static $imagePositions = [
'top left' => 'En haut à gauche', 'top left' => 'En haut à gauche',
@ -249,21 +250,24 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['admin', [ $this->setData([
'backgroundColor' => $this->getInput('adminBackgroundColor'), 'admin',
'colorTitle' => $this->getInput('adminColorTitle'), [
'colorText' => $this->getInput('adminColorText'), 'backgroundColor' => $this->getInput('adminBackgroundColor'),
'backgroundColorButton' => $this->getInput('adminColorButton'), 'colorTitle' => $this->getInput('adminColorTitle'),
'backgroundColorButtonGrey' => $this->getInput('adminColorGrey'), 'colorText' => $this->getInput('adminColorText'),
'backgroundColorButtonRed' => $this->getInput('adminColorRed'), 'backgroundColorButton' => $this->getInput('adminColorButton'),
'backgroundColorButtonGreen' => $this->getInput('adminColorGreen'), 'backgroundColorButtonGrey' => $this->getInput('adminColorGrey'),
'backgroundColorButtonHelp' => $this->getInput('adminColorHelp'), 'backgroundColorButtonRed' => $this->getInput('adminColorRed'),
'fontText' => $this->getInput('adminFontText'), 'backgroundColorButtonGreen' => $this->getInput('adminColorGreen'),
'fontSize' => $this->getInput('adminFontTextSize'), 'backgroundColorButtonHelp' => $this->getInput('adminColorHelp'),
'fontTitle' => $this->getInput('adminFontTitle'), 'fontText' => $this->getInput('adminFontText'),
'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'), 'fontSize' => $this->getInput('adminFontTextSize'),
'borderBlockColor' => $this->getInput('adminBorderBlockColor'), 'fontTitle' => $this->getInput('adminFontTitle'),
]]); 'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'),
'borderBlockColor' => $this->getInput('adminBorderBlockColor'),
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
@ -318,16 +322,20 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['theme', 'body', [ $this->setData([
'backgroundColor' => $this->getInput('themeBodyBackgroundColor'), 'theme',
'image' => $this->getInput('themeBodyImage'), 'body',
'imageAttachment' => $this->getInput('themeBodyImageAttachment'), [
'imagePosition' => $this->getInput('themeBodyImagePosition'), 'backgroundColor' => $this->getInput('themeBodyBackgroundColor'),
'imageRepeat' => $this->getInput('themeBodyImageRepeat'), 'image' => $this->getInput('themeBodyImage'),
'imageSize' => $this->getInput('themeBodyImageSize'), 'imageAttachment' => $this->getInput('themeBodyImageAttachment'),
'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'), 'imagePosition' => $this->getInput('themeBodyImagePosition'),
'toTopColor' => $this->getInput('themeBodyToTopColor') 'imageRepeat' => $this->getInput('themeBodyImageRepeat'),
]]); 'imageSize' => $this->getInput('themeBodyImageSize'),
'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'),
'toTopColor' => $this->getInput('themeBodyToTopColor')
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
@ -364,34 +372,38 @@ class theme extends common
'state' => false 'state' => false
]); ]);
} else { } else {
$this->setData(['theme', 'footer', [ $this->setData([
'backgroundColor' => $this->getInput('themeFooterBackgroundColor'), 'theme',
'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'), 'footer',
'height' => $this->getInput('themeFooterHeight'), [
'loginLink' => $this->getInput('themeFooterLoginLink'), 'backgroundColor' => $this->getInput('themeFooterBackgroundColor'),
'margin' => $this->getInput('themeFooterMargin', helper::FILTER_BOOLEAN), 'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'),
'position' => $this->getInput('themeFooterPosition'), 'height' => $this->getInput('themeFooterHeight'),
'fixed' => $this->getInput('themeFooterFixed', helper::FILTER_BOOLEAN), 'loginLink' => $this->getInput('themeFooterLoginLink'),
'socialsAlign' => $this->getInput('themeFooterSocialsAlign'), 'margin' => $this->getInput('themeFooterMargin', helper::FILTER_BOOLEAN),
'text' => $this->getInput('themeFooterText', null), 'position' => $this->getInput('themeFooterPosition'),
'textAlign' => $this->getInput('themeFooterTextAlign'), 'fixed' => $this->getInput('themeFooterFixed', helper::FILTER_BOOLEAN),
'textColor' => $this->getInput('themeFooterTextColor'), 'socialsAlign' => $this->getInput('themeFooterSocialsAlign'),
'copyrightPosition' => $this->getInput('themeFooterCopyrightPosition'), 'text' => $this->getInput('themeFooterText', null),
'textPosition' => $this->getInput('themeFooterTextPosition'), 'textAlign' => $this->getInput('themeFooterTextAlign'),
'socialsPosition' => $this->getInput('themeFooterSocialsPosition'), 'textColor' => $this->getInput('themeFooterTextColor'),
'textTransform' => $this->getInput('themeFooterTextTransform'), 'copyrightPosition' => $this->getInput('themeFooterCopyrightPosition'),
'font' => $this->getInput('themeFooterFont'), 'textPosition' => $this->getInput('themeFooterTextPosition'),
'fontSize' => $this->getInput('themeFooterFontSize'), 'socialsPosition' => $this->getInput('themeFooterSocialsPosition'),
'fontWeight' => $this->getInput('themeFooterFontWeight'), 'textTransform' => $this->getInput('themeFooterTextTransform'),
'displayVersion' => $this->getInput('themefooterDisplayVersion', helper::FILTER_BOOLEAN), 'font' => $this->getInput('themeFooterFont'),
'displaySiteMap' => $this->getInput('themefooterDisplaySiteMap', helper::FILTER_BOOLEAN), 'fontSize' => $this->getInput('themeFooterFontSize'),
'displayCopyright' => $this->getInput('themefooterDisplayCopyright', helper::FILTER_BOOLEAN), 'fontWeight' => $this->getInput('themeFooterFontWeight'),
'displayCookie' => $this->getInput('themefooterDisplayCookie', helper::FILTER_BOOLEAN), 'displayVersion' => $this->getInput('themefooterDisplayVersion', helper::FILTER_BOOLEAN),
'displayLegal' => $this->getInput('themeFooterDisplayLegal', helper::FILTER_BOOLEAN), 'displaySiteMap' => $this->getInput('themefooterDisplaySiteMap', helper::FILTER_BOOLEAN),
'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN), 'displayCopyright' => $this->getInput('themefooterDisplayCopyright', helper::FILTER_BOOLEAN),
'memberBar' => $this->getInput('themeFooterMemberBar', helper::FILTER_BOOLEAN), 'displayCookie' => $this->getInput('themefooterDisplayCookie', helper::FILTER_BOOLEAN),
'template' => $this->getInput('themeFooterTemplate') 'displayLegal' => $this->getInput('themeFooterDisplayLegal', helper::FILTER_BOOLEAN),
]]); 'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN),
'memberBar' => $this->getInput('themeFooterMemberBar', helper::FILTER_BOOLEAN),
'template' => $this->getInput('themeFooterTemplate')
]
]);
// Sauvegarder la configuration localisée // Sauvegarder la configuration localisée
$this->setData(['locale', 'legalPageId', $this->getInput('configLegalPageId')]); $this->setData(['locale', 'legalPageId', $this->getInput('configLegalPageId')]);
@ -453,29 +465,33 @@ class theme extends common
} }
// Sauvegarder // Sauvegarder
$this->setData(['theme', 'header', [ $this->setData([
'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'), 'theme',
'font' => $this->getInput('themeHeaderFont'), 'header',
'fontSize' => $this->getInput('themeHeaderFontSize'), [
'fontWeight' => $this->getInput('themeHeaderFontWeight'), 'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'),
'height' => $this->getInput('themeHeaderHeight'), 'font' => $this->getInput('themeHeaderFont'),
'wide' => $this->getInput('themeHeaderWide'), 'fontSize' => $this->getInput('themeHeaderFontSize'),
'image' => $this->getInput('themeHeaderImage'), 'fontWeight' => $this->getInput('themeHeaderFontWeight'),
'imagePosition' => $this->getInput('themeHeaderImagePosition'), 'height' => $this->getInput('themeHeaderHeight'),
'imageRepeat' => $this->getInput('themeHeaderImageRepeat'), 'wide' => $this->getInput('themeHeaderWide'),
'margin' => $this->getInput('themeHeaderMargin', helper::FILTER_BOOLEAN), 'image' => $this->getInput('themeHeaderImage'),
'position' => $this->getInput('themeHeaderPosition'), 'imagePosition' => $this->getInput('themeHeaderImagePosition'),
'textAlign' => $this->getInput('themeHeaderTextAlign'), 'imageRepeat' => $this->getInput('themeHeaderImageRepeat'),
'textColor' => $this->getInput('themeHeaderTextColor'), 'margin' => $this->getInput('themeHeaderMargin', helper::FILTER_BOOLEAN),
'textHide' => $this->getInput('themeHeaderTextHide', helper::FILTER_BOOLEAN), 'position' => $this->getInput('themeHeaderPosition'),
'textTransform' => $this->getInput('themeHeaderTextTransform'), 'textAlign' => $this->getInput('themeHeaderTextAlign'),
'linkHomePage' => $this->getInput('themeHeaderlinkHomePage', helper::FILTER_BOOLEAN), 'textColor' => $this->getInput('themeHeaderTextColor'),
'imageContainer' => $this->getInput('themeHeaderImageContainer'), 'textHide' => $this->getInput('themeHeaderTextHide', helper::FILTER_BOOLEAN),
'tinyHidden' => $this->getInput('themeHeaderTinyHidden', helper::FILTER_BOOLEAN), 'textTransform' => $this->getInput('themeHeaderTextTransform'),
'feature' => $this->getInput('themeHeaderFeature'), 'linkHomePage' => $this->getInput('themeHeaderlinkHomePage', helper::FILTER_BOOLEAN),
'featureContent' => $featureContent, 'imageContainer' => $this->getInput('themeHeaderImageContainer'),
'featureFiles' => $files 'tinyHidden' => $this->getInput('themeHeaderTinyHidden', helper::FILTER_BOOLEAN),
]]); 'feature' => $this->getInput('themeHeaderFeature'),
'featureContent' => $featureContent,
'featureFiles' => $files
]
]);
// Modification de la position du menu selon la position de la bannière // Modification de la position du menu selon la position de la bannière
if ($this->getData(['theme', 'header', 'position']) == 'site') { if ($this->getData(['theme', 'header', 'position']) == 'site') {
$this->setData(['theme', 'menu', 'position', str_replace('body-', 'site-', $this->getData(['theme', 'menu', 'position']))]); $this->setData(['theme', 'menu', 'position', str_replace('body-', 'site-', $this->getData(['theme', 'menu', 'position']))]);
@ -535,30 +551,34 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['theme', 'menu', [ $this->setData([
'backgroundColor' => $this->getInput('themeMenuBackgroundColor'), 'theme',
'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'), 'menu',
'font' => $this->getInput('themeMenuFont'), [
'fontSize' => $this->getInput('themeMenuFontSize'), 'backgroundColor' => $this->getInput('themeMenuBackgroundColor'),
'fontWeight' => $this->getInput('themeMenuFontWeight'), 'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'),
'height' => $this->getInput('themeMenuHeight'), 'font' => $this->getInput('themeMenuFont'),
'wide' => $this->getInput('themeMenuWide'), 'fontSize' => $this->getInput('themeMenuFontSize'),
'loginLink' => $this->getInput('themeMenuLoginLink', helper::FILTER_BOOLEAN), 'fontWeight' => $this->getInput('themeMenuFontWeight'),
'margin' => $this->getInput('themeMenuMargin', helper::FILTER_BOOLEAN), 'height' => $this->getInput('themeMenuHeight'),
'position' => $this->getInput('themeMenuPosition'), 'wide' => $this->getInput('themeMenuWide'),
'textAlign' => $this->getInput('themeMenuTextAlign'), 'loginLink' => $this->getInput('themeMenuLoginLink', helper::FILTER_BOOLEAN),
'textColor' => $this->getInput('themeMenuTextColor'), 'margin' => $this->getInput('themeMenuMargin', helper::FILTER_BOOLEAN),
'textTransform' => $this->getInput('themeMenuTextTransform'), 'position' => $this->getInput('themeMenuPosition'),
'fixed' => $this->getInput('themeMenuFixed', helper::FILTER_BOOLEAN), 'textAlign' => $this->getInput('themeMenuTextAlign'),
'activeColorAuto' => $this->getInput('themeMenuActiveColorAuto', helper::FILTER_BOOLEAN), 'textColor' => $this->getInput('themeMenuTextColor'),
'activeColor' => $this->getInput('themeMenuActiveColor'), 'textTransform' => $this->getInput('themeMenuTextTransform'),
'activeTextColor' => $this->getInput('themeMenuActiveTextColor'), 'fixed' => $this->getInput('themeMenuFixed', helper::FILTER_BOOLEAN),
'radius' => $this->getInput('themeMenuRadius'), 'activeColorAuto' => $this->getInput('themeMenuActiveColorAuto', helper::FILTER_BOOLEAN),
'burgerTitle' => $this->getInput('themeMenuBurgerTitle', helper::FILTER_BOOLEAN), 'activeColor' => $this->getInput('themeMenuActiveColor'),
'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN), 'activeTextColor' => $this->getInput('themeMenuActiveTextColor'),
'burgerLogo' => $this->getInput('themeMenuBurgerLogo'), 'radius' => $this->getInput('themeMenuRadius'),
'burgerContent' => $this->getInput('themeMenuBurgerContent') 'burgerTitle' => $this->getInput('themeMenuBurgerTitle', helper::FILTER_BOOLEAN),
]]); 'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN),
'burgerLogo' => $this->getInput('themeMenuBurgerLogo'),
'burgerContent' => $this->getInput('themeMenuBurgerContent')
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
@ -591,19 +611,19 @@ class theme extends common
// Polices liées au thème // Polices liées au thème
$used = [ $used = [
'Bannière' => $this->getData(['theme', 'header', 'font']), 'Bannière' => $this->getData(['theme', 'header', 'font']),
'Menu' => $this->getData(['theme', 'menu', 'font']), 'Menu' => $this->getData(['theme', 'menu', 'font']),
'Titre ' => $this->getData(['theme', 'title', 'font']), 'Titre ' => $this->getData(['theme', 'title', 'font']),
'Texte' => $this->getData(['theme', 'text', 'font']), 'Texte' => $this->getData(['theme', 'text', 'font']),
'Pied de page' => $this->getData(['theme', 'footer', 'font']), 'Pied de page' => $this->getData(['theme', 'footer', 'font']),
'Titre (admin)' => $this->getData(['admin', 'fontTitle']), 'Titre (admin)' => $this->getData(['admin', 'fontTitle']),
'Admin (texte)' => $this->getData(['admin', 'fontText']) 'Admin (texte)' => $this->getData(['admin', 'fontText'])
]; ];
// Récupérer le détail des fontes installées // Récupérer le détail des fontes installées
//$f = $this->getFonts(); //$f = $this->getFonts();
$f['files'] = $this->getData(['fonts', 'files']); $f['files'] = $this->getData(['fonts', 'files']);
$f['imported'] = $this->getData(['fonts', 'imported']); $f['imported'] = $this->getData(['fonts', 'imported']);
$f['websafe'] = self::$fontsWebSafe; $f['websafe'] = self::$fontsWebSafe;
// Parcourir les fontes disponibles et construire le tableau pour le formulaire // Parcourir les fontes disponibles et construire le tableau pour le formulaire
@ -614,7 +634,7 @@ class theme extends common
$fontUsed[$fontId] = ''; $fontUsed[$fontId] = '';
foreach ($used as $key => $value) { foreach ($used as $key => $value) {
if ($value === $fontId) { if ($value === $fontId) {
$fontUsed[$fontId] .= $key . '<br/>'; $fontUsed[$fontId] .= $key . '<br/>';
} }
} }
self::$fontsDetail[] = [ self::$fontsDetail[] = [
@ -623,20 +643,20 @@ class theme extends common
$f[$type][$fontId]['font-family'], $f[$type][$fontId]['font-family'],
$fontUsed[$fontId], $fontUsed[$fontId],
$type, $type,
$type !== 'websafe' ? template::button('themeFontEdit' . $fontId, [ $type !== 'websafe' ? template::button('themeFontEdit' . $fontId, [
'class' => 'themeFontEdit', 'class' => 'themeFontEdit',
'href' => helper::baseUrl() . $this->getUrl(0) . '/fontEdit/' . $type . '/' . $fontId , 'href' => helper::baseUrl() . $this->getUrl(0) . '/fontEdit/' . $type . '/' . $fontId,
'value' => template::ico('pencil'), 'value' => template::ico('pencil'),
'disabled' => !empty($fontUsed[$fontId]) 'disabled' => !empty($fontUsed[$fontId])
]) ])
: '', : '',
$type !== 'websafe' ? template::button('themeFontDelete' . $fontId, [ $type !== 'websafe' ? template::button('themeFontDelete' . $fontId, [
'class' => 'themeFontDelete buttonRed', 'class' => 'themeFontDelete buttonRed',
'href' => helper::baseUrl() . $this->getUrl(0) . '/fontDelete/' . $type . '/' . $fontId , 'href' => helper::baseUrl() . $this->getUrl(0) . '/fontDelete/' . $type . '/' . $fontId,
'value' => template::ico('cancel'), 'value' => template::ico('cancel'),
'disabled' => !empty($fontUsed[$fontId]) 'disabled' => !empty($fontUsed[$fontId])
]) ])
: '' : ''
]; ];
} }
} }
@ -663,7 +683,7 @@ class theme extends common
if (!empty($ressource)) { if (!empty($ressource)) {
$fontId = $this->getInput('fontAddFontId', null, true); $fontId = $this->getInput('fontAddFontId', null, true);
$fontName = $this->getInput('fontAddFontName', null, true); $fontName = $this->getInput('fontAddFontName', null, true);
$fontFamilyName = $this->getInput('fontAddFontFamilyName', null, true); $fontFamilyName = $this->getInput('fontAddFontFamilyName', null, true);
// Remplace les doubles quotes par des simples quotes // Remplace les doubles quotes par des simples quotes
$fontFamilyName = str_replace('"', '\'', $fontFamilyName); $fontFamilyName = str_replace('"', '\'', $fontFamilyName);
@ -676,7 +696,8 @@ class theme extends common
$this->setData([ $this->setData([
'fonts', 'fonts',
$type, $type,
$fontId, [ $fontId,
[
'name' => $fontName, 'name' => $fontName,
'font-family' => $fontFamilyName, 'font-family' => $fontFamilyName,
'resource' => $ressource 'resource' => $ressource
@ -724,10 +745,10 @@ class theme extends common
if ($this->isPost()) { if ($this->isPost()) {
// Type d'import en ligne ou local // Type d'import en ligne ou local
$type = $this->getInput('fontEditUrl', helper::FILTER_BOOLEAN) ? 'imported' : 'files'; $type = $this->getInput('fontEditUrl', helper::FILTER_BOOLEAN) ? 'imported' : 'files';
$ressource = $type === 'imported' ? $this->getInput('fontEditUrl', null) : $this->getInput('fontEditFile', null); $ressource = $type === 'imported' ? $this->getInput('fontEditUrl', null) : $this->getInput('fontEditFile', null);
$fontId = $this->getInput('fontEditFontId', null, true); $fontId = $this->getInput('fontEditFontId', null, true);
$fontName = $this->getInput('fontEditFontName', null, true); $fontName = $this->getInput('fontEditFontName', null, true);
$fontFamilyName = $this->getInput('fontEditFontFamilyName', null, true); $fontFamilyName = $this->getInput('fontEditFontFamilyName', null, true);
// Remplace les doubles quotes par des simples quotes // Remplace les doubles quotes par des simples quotes
$fontFamilyName = str_replace('"', '\'', $fontFamilyName); $fontFamilyName = str_replace('"', '\'', $fontFamilyName);
@ -741,7 +762,8 @@ class theme extends common
$this->setData([ $this->setData([
'fonts', 'fonts',
$type, $type,
$fontId, [ $fontId,
[
'name' => $fontName, 'name' => $fontName,
'font-family' => $fontFamilyName, 'font-family' => $fontFamilyName,
'resource' => $ressource 'resource' => $ressource
@ -775,11 +797,11 @@ class theme extends common
public function fontDelete() public function fontDelete()
{ {
// Jeton incorrect // Jeton incorrect
if ($this->getUrl(4) !== $_SESSION['csrf']) { if ($this->checkCSRF()) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'theme/fonts', 'redirect' => helper::baseUrl() . 'theme/fonts',
'notification' => helper::translate('Action interdite') 'notification' => helper::translate('Jeton invalide')
]); ]);
} }
// Suppression // Suppression
@ -798,7 +820,7 @@ class theme extends common
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'theme/fonts', 'redirect' => helper::baseUrl() . 'theme/fonts',
'notification' => helper::translate('Fonte supprimée'), 'notification' => helper::translate('Fonte supprimée'),
'state' => true 'state' => true
]); ]);
@ -811,44 +833,32 @@ class theme extends common
*/ */
public function reset() public function reset()
{ {
// $url prend l'adresse sans le token // Réinitialisation
$url = explode('&', $this->getUrl(2)); $redirect = '';
switch ($this->getUrl(2)) {
if ( case 'admin':
isset($_GET['csrf']) $this->initData('admin', self::$i18nUI);
and $_GET['csrf'] === $_SESSION['csrf'] $redirect = helper::baseUrl() . 'theme/admin';
) { break;
// Réinitialisation case 'manage':
$redirect = ''; $this->initData('theme', self::$i18nUI);
switch ($url[0]) { $redirect = helper::baseUrl() . 'theme/manage';
case 'admin': break;
$this->initData('admin', self::$i18nUI); case 'custom':
$redirect = helper::baseUrl() . 'theme/admin'; unlink(self::DATA_DIR . 'custom.css');
break; $redirect = helper::baseUrl() . 'theme/advanced';
case 'manage': break;
$this->initData('theme', self::$i18nUI); default:
$redirect = helper::baseUrl() . 'theme/manage'; $redirect = helper::baseUrl() . 'theme';
break;
case 'custom':
unlink(self::DATA_DIR . 'custom.css');
$redirect = helper::baseUrl() . 'theme/advanced';
break;
default:
$redirect = helper::baseUrl() . 'theme';
}
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Thème réinitialisé'),
'redirect' => $redirect,
'state' => true
]);
} else {
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Jeton incorrect')
]);
} }
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Thème réinitialisé'),
'redirect' => $redirect,
'state' => true
]);
} }
@ -859,32 +869,52 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['theme', 'title', [ $this->setData([
'font' => $this->getInput('themeTitleFont'), 'theme',
'textColor' => $this->getInput('themeTitleTextColor'), 'title',
'fontWeight' => $this->getInput('themeTitleFontWeight'), [
'textTransform' => $this->getInput('themeTitleTextTransform') 'font' => $this->getInput('themeTitleFont'),
]]); 'textColor' => $this->getInput('themeTitleTextColor'),
$this->setData(['theme', 'text', [ 'fontWeight' => $this->getInput('themeTitleFontWeight'),
'font' => $this->getInput('themeTextFont'), 'textTransform' => $this->getInput('themeTitleTextTransform')
'fontSize' => $this->getInput('themeTextFontSize'), ]
'textColor' => $this->getInput('themeTextTextColor'), ]);
'linkColor' => $this->getInput('themeTextLinkColor') $this->setData([
]]); 'theme',
$this->setData(['theme', 'site', [ 'text',
'backgroundColor' => $this->getInput('themeSiteBackgroundColor'), [
'radius' => $this->getInput('themeSiteRadius'), 'font' => $this->getInput('themeTextFont'),
'shadow' => $this->getInput('themeSiteShadow'), 'fontSize' => $this->getInput('themeTextFontSize'),
'width' => $this->getInput('themeSiteWidth'), 'textColor' => $this->getInput('themeTextTextColor'),
'margin' => $this->getInput('themeSiteMargin', helper::FILTER_BOOLEAN) 'linkColor' => $this->getInput('themeTextLinkColor')
]]); ]
$this->setData(['theme', 'button', [ ]);
'backgroundColor' => $this->getInput('themeButtonBackgroundColor') $this->setData([
]]); 'theme',
$this->setData(['theme', 'block', [ 'site',
'backgroundColor' => $this->getInput('themeBlockBackgroundColor'), [
'borderColor' => $this->getInput('themeBlockBorderColor') 'backgroundColor' => $this->getInput('themeSiteBackgroundColor'),
]]); 'radius' => $this->getInput('themeSiteRadius'),
'shadow' => $this->getInput('themeSiteShadow'),
'width' => $this->getInput('themeSiteWidth'),
'margin' => $this->getInput('themeSiteMargin', helper::FILTER_BOOLEAN)
]
]);
$this->setData([
'theme',
'button',
[
'backgroundColor' => $this->getInput('themeButtonBackgroundColor')
]
]);
$this->setData([
'theme',
'block',
[
'backgroundColor' => $this->getInput('themeBlockBackgroundColor'),
'borderColor' => $this->getInput('themeBlockBorderColor')
]
]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => helper::translate('Modifications enregistrées'), 'notification' => helper::translate('Modifications enregistrées'),
@ -914,7 +944,7 @@ class theme extends common
{ {
if ($this->isPost()) { if ($this->isPost()) {
$zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true); $zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true);
$data = $this->import(self::FILE_DIR . 'source/' . $zipFilename); $data = $this->import(self::FILE_DIR . 'source/' . $zipFilename);
if ($data['success']) { if ($data['success']) {
header("Refresh:0"); header("Refresh:0");
@ -925,7 +955,8 @@ class theme extends common
'notification' => $data['notification'], 'notification' => $data['notification'],
'state' => $data['success'], 'state' => $data['success'],
'view' => 'manage' 'view' => 'manage'
]);; ]);
;
} }
} }
// Valeurs en sortie // Valeurs en sortie
@ -1057,7 +1088,7 @@ class theme extends common
unlink(self::TEMP_DIR . $zipFilename); unlink(self::TEMP_DIR . $zipFilename);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => '<b>' . $zipFilename . '</b>'. helper::translate('sauvegardé avec succès'), 'notification' => '<b>' . $zipFilename . '</b>' . helper::translate('sauvegardé avec succès'),
'redirect' => helper::baseUrl() . 'theme/manage', 'redirect' => helper::baseUrl() . 'theme/manage',
'state' => true 'state' => true
]); ]);
@ -1070,7 +1101,7 @@ class theme extends common
private function zipTheme($modele) private function zipTheme($modele)
{ {
// Creation du dossier // Creation du dossier
$zipFilename = $modele . date('Y-m-d-H-i-s', time()) . '.zip'; $zipFilename = $modele . date('Y-m-d-H-i-s', time()) . '.zip';
$zip = new ZipArchive(); $zip = new ZipArchive();
if ($zip->open(self::TEMP_DIR . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { if ($zip->open(self::TEMP_DIR . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
switch ($modele) { switch ($modele) {
@ -1197,8 +1228,8 @@ class theme extends common
* id - nom * id - nom
* id - font-family - resource * id - font-family - resource
*/ */
$f['files'] = $this->getData(['fonts', 'files']); $f['files'] = $this->getData(['fonts', 'files']);
$f['imported'] = $this->getData(['fonts', 'imported']); $f['imported'] = $this->getData(['fonts', 'imported']);
$f['websafe'] = self::$fontsWebSafe; $f['websafe'] = self::$fontsWebSafe;
// Construit un tableau avec leur ID et leur famille // Construit un tableau avec leur ID et leur famille
foreach (['websafe', 'imported', 'files'] as $type) { foreach (['websafe', 'imported', 'files'] as $type) {
@ -1223,7 +1254,7 @@ class theme extends common
// Filtrage par fontes installées // Filtrage par fontes installées
$fontsInstalled = [ $fontsInstalled = [
$this->getData(['theme', 'text', 'font']), $this->getData(['theme', 'text', 'font']),
$this->getData(['theme', 'title', 'font']), $this->getData(['theme', 'title', 'font']),
$this->getData(['theme', 'header', 'font']), $this->getData(['theme', 'header', 'font']),
$this->getData(['theme', 'menu', 'font']), $this->getData(['theme', 'menu', 'font']),
@ -1244,13 +1275,13 @@ class theme extends common
foreach ($this->getData(['fonts', 'imported']) as $fontId => $fontValue) { foreach ($this->getData(['fonts', 'imported']) as $fontId => $fontValue) {
if ( if (
($scope === 'user' && in_array($fontId, $fontsInstalled)) ($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all' || $scope === 'all'
) { ) {
//Pré chargement à revoir //Pré chargement à revoir
//$fileContent .= '<link rel="preload" href="' . $fontValue['resource'] . '" crossorigin="anonymous" as="style">'; //$fileContent .= '<link rel="preload" href="' . $fontValue['resource'] . '" crossorigin="anonymous" as="style">';
$fileContent .= '<link href="' . $fontValue['resource'] . '" rel="stylesheet">'; $fileContent .= '<link href="' . $fontValue['resource'] . '" rel="stylesheet">';
// Pré connect pour api.google // Pré connect pour api.google
$gf = strpos($fontValue['resource'], 'fonts.googleapis.com') === false ? $gf || false : $gf || true; $gf = strpos($fontValue['resource'], 'fonts.googleapis.com') === false ? $gf || false : $gf || true;
} }
} }
} }
@ -1269,16 +1300,16 @@ class theme extends common
foreach ($this->getData(['fonts', 'files']) as $fontId => $fontValue) { foreach ($this->getData(['fonts', 'files']) as $fontId => $fontValue) {
if ( if (
($scope === 'user' && in_array($fontId, $fontsInstalled)) ($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all' || $scope === 'all'
) { ) {
if (file_exists(self::DATA_DIR . 'fonts/' . $fontValue['resource'])) { if (file_exists(self::DATA_DIR . 'fonts/' . $fontValue['resource'])) {
// Extension // Extension
$path_parts = pathinfo(helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontValue['resource']); $path_parts = pathinfo(helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontValue['resource']);
// Chargement de la police // Chargement de la police
$fileContentCss .= '@font-face {'; $fileContentCss .= '@font-face {';
$fileContentCss .= 'font-family:"' . $fontValue['name'] . '";'; $fileContentCss .= 'font-family:"' . $fontValue['name'] . '";';
$fileContentCss .= 'src: url("' . $fontValue['resource'] . '") format("' . $path_parts['extension'] . '");'; $fileContentCss .= 'src: url("' . $fontValue['resource'] . '") format("' . $path_parts['extension'] . '");';
$fileContentCss .= '}'; $fileContentCss .= '}';
// Préchargement // Préchargement
//$fileContent = '<link rel="preload" href="' . self::DATA_DIR . 'fonts/' . $fontValue['resource'] . '" type="font/woff" crossorigin="anonymous" as="font">' . $fileContent; //$fileContent = '<link rel="preload" href="' . self::DATA_DIR . 'fonts/' . $fontValue['resource'] . '" type="font/woff" crossorigin="anonymous" as="font">' . $fileContent;
} }
@ -1289,6 +1320,6 @@ class theme extends common
// Enregistre la personnalisation // Enregistre la personnalisation
file_put_contents(self::DATA_DIR . 'fonts/fonts.html', $fileContent); file_put_contents(self::DATA_DIR . 'fonts/fonts.html', $fileContent);
// Enregistre la personnalisation // Enregistre la personnalisation
file_put_contents(self::DATA_DIR . 'fonts/fonts.css', $fileContentCss); file_put_contents(self::DATA_DIR . 'fonts/fonts.css', $fileContentCss);
} }
} }