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',
@ -249,7 +250,9 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['admin', [ $this->setData([
'admin',
[
'backgroundColor' => $this->getInput('adminBackgroundColor'), 'backgroundColor' => $this->getInput('adminBackgroundColor'),
'colorTitle' => $this->getInput('adminColorTitle'), 'colorTitle' => $this->getInput('adminColorTitle'),
'colorText' => $this->getInput('adminColorText'), 'colorText' => $this->getInput('adminColorText'),
@ -263,7 +266,8 @@ class theme extends common
'fontTitle' => $this->getInput('adminFontTitle'), 'fontTitle' => $this->getInput('adminFontTitle'),
'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'), 'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'),
'borderBlockColor' => $this->getInput('adminBorderBlockColor'), '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,7 +322,10 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['theme', 'body', [ $this->setData([
'theme',
'body',
[
'backgroundColor' => $this->getInput('themeBodyBackgroundColor'), 'backgroundColor' => $this->getInput('themeBodyBackgroundColor'),
'image' => $this->getInput('themeBodyImage'), 'image' => $this->getInput('themeBodyImage'),
'imageAttachment' => $this->getInput('themeBodyImageAttachment'), 'imageAttachment' => $this->getInput('themeBodyImageAttachment'),
@ -327,7 +334,8 @@ class theme extends common
'imageSize' => $this->getInput('themeBodyImageSize'), 'imageSize' => $this->getInput('themeBodyImageSize'),
'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'), 'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'),
'toTopColor' => $this->getInput('themeBodyToTopColor') '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,7 +372,10 @@ class theme extends common
'state' => false 'state' => false
]); ]);
} else { } else {
$this->setData(['theme', 'footer', [ $this->setData([
'theme',
'footer',
[
'backgroundColor' => $this->getInput('themeFooterBackgroundColor'), 'backgroundColor' => $this->getInput('themeFooterBackgroundColor'),
'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'), 'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'),
'height' => $this->getInput('themeFooterHeight'), 'height' => $this->getInput('themeFooterHeight'),
@ -391,7 +402,8 @@ class theme extends common
'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN), 'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN),
'memberBar' => $this->getInput('themeFooterMemberBar', helper::FILTER_BOOLEAN), 'memberBar' => $this->getInput('themeFooterMemberBar', helper::FILTER_BOOLEAN),
'template' => $this->getInput('themeFooterTemplate') '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,7 +465,10 @@ class theme extends common
} }
// Sauvegarder // Sauvegarder
$this->setData(['theme', 'header', [ $this->setData([
'theme',
'header',
[
'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'), 'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'),
'font' => $this->getInput('themeHeaderFont'), 'font' => $this->getInput('themeHeaderFont'),
'fontSize' => $this->getInput('themeHeaderFontSize'), 'fontSize' => $this->getInput('themeHeaderFontSize'),
@ -475,7 +490,8 @@ class theme extends common
'feature' => $this->getInput('themeHeaderFeature'), 'feature' => $this->getInput('themeHeaderFeature'),
'featureContent' => $featureContent, 'featureContent' => $featureContent,
'featureFiles' => $files '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,7 +551,10 @@ class theme extends common
{ {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$this->setData(['theme', 'menu', [ $this->setData([
'theme',
'menu',
[
'backgroundColor' => $this->getInput('themeMenuBackgroundColor'), 'backgroundColor' => $this->getInput('themeMenuBackgroundColor'),
'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'), 'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'),
'font' => $this->getInput('themeMenuFont'), 'font' => $this->getInput('themeMenuFont'),
@ -558,7 +577,8 @@ class theme extends common
'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN), 'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN),
'burgerLogo' => $this->getInput('themeMenuBurgerLogo'), 'burgerLogo' => $this->getInput('themeMenuBurgerLogo'),
'burgerContent' => $this->getInput('themeMenuBurgerContent') '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'),
@ -625,14 +645,14 @@ class theme extends common
$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])
]) ])
@ -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
@ -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
@ -811,16 +833,9 @@ class theme extends common
*/ */
public function reset() public function reset()
{ {
// $url prend l'adresse sans le token
$url = explode('&', $this->getUrl(2));
if (
isset($_GET['csrf'])
and $_GET['csrf'] === $_SESSION['csrf']
) {
// Réinitialisation // Réinitialisation
$redirect = ''; $redirect = '';
switch ($url[0]) { switch ($this->getUrl(2)) {
case 'admin': case 'admin':
$this->initData('admin', self::$i18nUI); $this->initData('admin', self::$i18nUI);
$redirect = helper::baseUrl() . 'theme/admin'; $redirect = helper::baseUrl() . 'theme/admin';
@ -843,12 +858,7 @@ class theme extends common
'redirect' => $redirect, 'redirect' => $redirect,
'state' => true 'state' => true
]); ]);
} else {
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Jeton incorrect')
]);
}
} }
@ -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([
'theme',
'title',
[
'font' => $this->getInput('themeTitleFont'), 'font' => $this->getInput('themeTitleFont'),
'textColor' => $this->getInput('themeTitleTextColor'), 'textColor' => $this->getInput('themeTitleTextColor'),
'fontWeight' => $this->getInput('themeTitleFontWeight'), 'fontWeight' => $this->getInput('themeTitleFontWeight'),
'textTransform' => $this->getInput('themeTitleTextTransform') 'textTransform' => $this->getInput('themeTitleTextTransform')
]]); ]
$this->setData(['theme', 'text', [ ]);
$this->setData([
'theme',
'text',
[
'font' => $this->getInput('themeTextFont'), 'font' => $this->getInput('themeTextFont'),
'fontSize' => $this->getInput('themeTextFontSize'), 'fontSize' => $this->getInput('themeTextFontSize'),
'textColor' => $this->getInput('themeTextTextColor'), 'textColor' => $this->getInput('themeTextTextColor'),
'linkColor' => $this->getInput('themeTextLinkColor') 'linkColor' => $this->getInput('themeTextLinkColor')
]]); ]
$this->setData(['theme', 'site', [ ]);
$this->setData([
'theme',
'site',
[
'backgroundColor' => $this->getInput('themeSiteBackgroundColor'), 'backgroundColor' => $this->getInput('themeSiteBackgroundColor'),
'radius' => $this->getInput('themeSiteRadius'), 'radius' => $this->getInput('themeSiteRadius'),
'shadow' => $this->getInput('themeSiteShadow'), 'shadow' => $this->getInput('themeSiteShadow'),
'width' => $this->getInput('themeSiteWidth'), 'width' => $this->getInput('themeSiteWidth'),
'margin' => $this->getInput('themeSiteMargin', helper::FILTER_BOOLEAN) 'margin' => $this->getInput('themeSiteMargin', helper::FILTER_BOOLEAN)
]]); ]
$this->setData(['theme', 'button', [ ]);
$this->setData([
'theme',
'button',
[
'backgroundColor' => $this->getInput('themeButtonBackgroundColor') 'backgroundColor' => $this->getInput('themeButtonBackgroundColor')
]]); ]
$this->setData(['theme', 'block', [ ]);
$this->setData([
'theme',
'block',
[
'backgroundColor' => $this->getInput('themeBlockBackgroundColor'), 'backgroundColor' => $this->getInput('themeBlockBackgroundColor'),
'borderColor' => $this->getInput('themeBlockBorderColor') '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'),
@ -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
]); ]);