ZwiiCMS/core/module/theme/theme.php

1404 lines
43 KiB
PHP
Raw Normal View History

2022-03-10 17:06:28 +01:00
<?php
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
2022-03-10 17:06:28 +01:00
* @link http://zwiicms.fr/
* @copyright : Frédéric Tempez <frederic.tempez@outlook.com>
2024-01-14 19:31:28 +01:00
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
2022-03-10 17:06:28 +01:00
*/
2022-09-29 08:45:59 +02:00
class theme extends common
{
2022-03-10 17:06:28 +01:00
public static $actions = [
'advanced' => self::GROUP_ADMIN,
'body' => self::GROUP_ADMIN,
'footer' => self::GROUP_ADMIN,
'header' => self::GROUP_ADMIN,
'index' => self::GROUP_ADMIN,
'menu' => self::GROUP_ADMIN,
'reset' => self::GROUP_ADMIN,
'site' => self::GROUP_ADMIN,
'admin' => self::GROUP_ADMIN,
'manage' => self::GROUP_ADMIN,
'export' => self::GROUP_ADMIN,
'import' => self::GROUP_ADMIN,
'save' => self::GROUP_ADMIN,
'font' => self::GROUP_ADMIN,
2022-03-10 17:06:28 +01:00
'fontAdd' => self::GROUP_ADMIN,
2022-03-11 16:09:43 +01:00
'fontEdit' => self::GROUP_ADMIN,
2022-03-10 17:06:28 +01:00
'fontDelete' => self::GROUP_ADMIN
];
public static $aligns = [
'left' => 'À gauche',
'center' => 'Au centre',
'right' => 'À droite'
];
public static $attachments = [
'scroll' => 'Standard',
'fixed' => 'Fixe'
];
public static $containerWides = [
'container' => 'Limitée au site',
2023-04-14 13:56:43 +02:00
'none' => 'Étendu sur la page'
2022-03-10 17:06:28 +01:00
];
public static $footerblocks = [
1 => [
'hide' => 'Masqué',
2022-09-29 08:45:59 +02:00
'center' => 'Affiché'
],
2022-03-10 17:06:28 +01:00
2 => [
'hide' => 'Masqué',
'left' => 'À gauche',
2022-09-29 08:45:59 +02:00
'right' => 'À droite'
],
2022-03-10 17:06:28 +01:00
3 => [
'hide' => 'Masqué',
'left' => 'À gauche',
'center' => 'Au centre',
2022-09-29 08:45:59 +02:00
'right' => 'À droite'
],
2022-03-10 17:06:28 +01:00
4 => [
'hide' => 'Masqué',
'left' => 'En haut',
'center' => 'Au milieu',
2022-09-29 08:45:59 +02:00
'right' => 'En bas'
]
2022-03-10 17:06:28 +01:00
];
public static $fontWeights = [
'normal' => 'Maigre',
'bold' => 'Gras'
];
public static $footerHeights = [
2023-04-14 13:56:43 +02:00
'0px' => '0px',
'5px' => '5px',
'10px' => '10px',
'15px' => '15px',
'20px' => '20px'
2022-03-10 17:06:28 +01:00
];
public static $footerPositions = [
'hide' => 'Caché',
'site' => 'Dans le site',
'body' => 'En dessous du site'
];
public static $footerFontSizes = [
2023-04-14 13:56:43 +02:00
'.8em' => '80%',
'.9em' => '90%',
2022-03-10 17:06:28 +01:00
'1em' => 'Standard (100%)',
2023-04-14 13:56:43 +02:00
'1.1em' => '110%',
'1.2em' => '120%',
'1.3em' => '130%'
2022-03-10 17:06:28 +01:00
];
public static $headerFontSizes = [
2023-04-14 13:56:43 +02:00
'1.6em' => '160%',
'1.8em' => '180%',
'2em' => '200%',
'2.2em' => '220%',
'2.4vmax' => '240%'
2022-03-10 17:06:28 +01:00
];
public static $headerHeights = [
'unset' => 'Libre',
// texte dynamique cf header.js.php
2023-04-14 13:56:43 +02:00
'100px' => '100px',
'150px' => '150px',
'200px' => '200px',
'300px' => '300px',
'400px' => '400px',
2022-03-10 17:06:28 +01:00
];
public static $headerPositions = [
2023-04-14 17:05:46 +02:00
'body' => 'Au-dessus du site',
2022-03-10 17:06:28 +01:00
'site' => 'Dans le site',
'hide' => 'Cachée'
];
public static $headerFeatures = [
'wallpaper' => 'Couleur unie ou papier-peint',
'feature' => 'Contenu HTML'
2022-03-10 17:06:28 +01:00
];
public static $imagePositions = [
'top left' => 'En haut à gauche',
'top center' => 'En haut au centre',
'top right' => 'En haut à droite',
'center left' => 'Au milieu à gauche',
'center center' => 'Au milieu au centre',
'center right' => 'Au milieu à droite',
'bottom left' => 'En bas à gauche',
'bottom center' => 'En bas au centre',
'bottom right' => 'En bas à droite'
];
public static $menuFontSizes = [
2023-04-14 13:56:43 +02:00
'.8em' => '80%',
'.9em' => '90%',
2022-03-10 17:06:28 +01:00
'1em' => 'Standard (100%)',
2023-04-14 13:56:43 +02:00
'1.1em' => '110%',
'1.2em' => '120%',
'1.3em' => '130%'
2022-03-10 17:06:28 +01:00
];
public static $menuHeights = [
'5px 10px' => 'Très petite',
'10px' => 'Petite',
'15px 10px' => 'Moyenne',
'20px 15px' => 'Grande',
'25px 15px' => 'Très grande'
];
public static $menuPositionsSite = [
'top' => 'En-dehors du site',
'site-first' => 'Avant la bannière',
'site-second' => 'Après la bannière',
'hide' => 'Caché'
];
public static $menuPositionsBody = [
'top' => 'En-dehors du site',
'body-first' => 'Avant la bannière',
'body-second' => 'Après la bannière',
'site' => 'Dans le site',
'hide' => 'Caché'
];
public static $menuRadius = [
'0px' => 'Aucun',
'3px 3px 0px 0px' => 'Très léger',
'6px 6px 0px 0px' => 'Léger',
'9px 9px 0px 0px' => 'Moyen',
'12px 12px 0px 0px' => 'Important',
'15px 15px 0px 0px' => 'Très important'
];
public static $radius = [
'0px' => 'Aucun',
'5px' => 'Très léger',
'10px' => 'Léger',
'15px' => 'Moyen',
'25px' => 'Important',
'50px' => 'Très important'
];
public static $repeats = [
'no-repeat' => 'Ne pas répéter',
'repeat-x' => 'Sur l\'axe horizontal',
'repeat-y' => 'Sur l\'axe vertical',
'repeat' => 'Sur les deux axes'
];
public static $shadows = [
'0px' => 'Aucune',
'1px 1px 5px' => 'Très légère',
'1px 1px 10px' => 'Légère',
'1px 1px 15px' => 'Moyenne',
'1px 1px 25px' => 'Importante',
'1px 1px 50px' => 'Très importante'
];
public static $siteFontSizes = [
'12px' => '12 pixels',
'13px' => '13 pixels',
'14px' => '14 pixels',
'15px' => '15 pixels',
'16px' => '16 pixels'
];
public static $bodySizes = [
'auto' => 'Automatique',
'100% 100%' => 'Image étirée (100% 100%)',
'cover' => 'Responsive (cover)',
'contain' => 'Responsive (contain)'
];
public static $textTransforms = [
'none' => 'Standard',
'lowercase' => 'Minuscules',
'uppercase' => 'Majuscules',
'capitalize' => 'Majuscule à chaque mot'
];
public static $siteWidths = [
2023-04-14 16:08:58 +02:00
'750px' => '750 pixels',
'960px' => '960 pixels',
'1170px' => '1170 pixels',
2023-10-09 20:32:12 +02:00
'100%' => '100%',
2022-03-10 17:06:28 +01:00
];
public static $headerWide = [
'auto auto' => 'Automatique',
'100% 100%' => 'Image étirée (100% 100%)',
'cover' => 'Responsive (cover)',
'contain' => 'Responsive (contain)'
];
public static $footerTemplate = [
'1' => 'Une seule colonne',
'2' => 'Deux colonnes : 1/2 - 1/2',
'3' => 'Trois colonnes : 1/3 - 1/3 - 1/3',
'4' => 'Trois lignes superposées'
];
public static $burgerContent = [
'none' => 'Aucun',
2023-01-02 17:36:03 +01:00
'title' => 'Titre',
2022-03-10 17:06:28 +01:00
'logo' => 'Logo du site'
];
// Variable pour construire la liste des pages du site
public static $pagesList = [];
// Variable pour construire la liste des fontes installées
2022-09-29 08:45:59 +02:00
public static $fontsNames = [];
2022-04-21 18:38:19 +02:00
public static $fonts = [];
2022-03-11 09:59:59 +01:00
// Variable pour détailler les fontes installées
public static $fontsDetail = [];
2022-03-10 17:06:28 +01:00
/**
* Thème des écrans d'administration
*/
2022-09-29 08:45:59 +02:00
public function admin()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'admin',
[
'backgroundColor' => $this->getInput('adminBackgroundColor'),
'colorTitle' => $this->getInput('adminColorTitle'),
'colorText' => $this->getInput('adminColorText'),
'backgroundColorButton' => $this->getInput('adminColorButton'),
'backgroundColorButtonGrey' => $this->getInput('adminColorGrey'),
'backgroundColorButtonRed' => $this->getInput('adminColorRed'),
'backgroundColorButtonGreen' => $this->getInput('adminColorGreen'),
'backgroundColorButtonHelp' => $this->getInput('adminColorHelp'),
'fontText' => $this->getInput('adminFontText'),
'fontSize' => $this->getInput('adminFontTextSize'),
'fontTitle' => $this->getInput('adminFontTitle'),
'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'),
'borderBlockColor' => $this->getInput('adminBorderBlockColor'),
2023-10-09 20:32:12 +02:00
'width' => $this->getInput('adminSiteWidth'),
]
]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme/admin',
'state' => true
]);
}
// Lire les fontes installées
$this->enumFonts();
2022-04-22 11:55:01 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Thème de l\'administration'),
2022-03-10 17:06:28 +01:00
'view' => 'admin',
'vendor' => [
'tinycolorpicker'
],
]);
}
/**
* Mode avancé
*/
2022-09-29 08:45:59 +02:00
public function advanced()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-03-10 17:06:28 +01:00
// Enregistre le CSS
2022-09-29 08:45:59 +02:00
file_put_contents(self::DATA_DIR . 'custom.css', $this->getInput('themeAdvancedCss', null));
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme/advanced',
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Éditeur CSS'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'codemirror'
],
'view' => 'advanced'
]);
}
/**
* Options de l'arrière plan
*/
2022-09-29 08:45:59 +02:00
public function body()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'theme',
'body',
[
'backgroundColor' => $this->getInput('themeBodyBackgroundColor'),
'image' => $this->getInput('themeBodyImage'),
'imageAttachment' => $this->getInput('themeBodyImageAttachment'),
'imagePosition' => $this->getInput('themeBodyImagePosition'),
'imageRepeat' => $this->getInput('themeBodyImageRepeat'),
'imageSize' => $this->getInput('themeBodyImageSize'),
'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'),
'toTopColor' => $this->getInput('themeBodyToTopColor')
]
]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme',
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Arrière plan'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'tinycolorpicker'
],
'view' => 'body'
]);
}
/**
* Options du pied de page
*/
2022-09-29 08:45:59 +02:00
public function footer()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-09-29 08:45:59 +02:00
if (
$this->getInput('themeFooterCopyrightPosition') === 'hide' &&
$this->getInput('themeFooterSocialsPosition') === 'hide' &&
$this->getInput('themeFooterTextPosition') === 'hide'
) {
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Sélectionnez au moins un contenu à afficher'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme/footer',
'state' => false
]);
} else {
$this->setData([
'theme',
'footer',
[
'backgroundColor' => $this->getInput('themeFooterBackgroundColor'),
'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'),
'height' => $this->getInput('themeFooterHeight'),
'loginLink' => $this->getInput('themeFooterLoginLink'),
'margin' => $this->getInput('themeFooterMargin', helper::FILTER_BOOLEAN),
'position' => $this->getInput('themeFooterPosition'),
'fixed' => $this->getInput('themeFooterFixed', helper::FILTER_BOOLEAN),
'socialsAlign' => $this->getInput('themeFooterSocialsAlign'),
'text' => $this->getInput('themeFooterText', null),
'textAlign' => $this->getInput('themeFooterTextAlign'),
'textColor' => $this->getInput('themeFooterTextColor'),
'copyrightPosition' => $this->getInput('themeFooterCopyrightPosition'),
'textPosition' => $this->getInput('themeFooterTextPosition'),
'socialsPosition' => $this->getInput('themeFooterSocialsPosition'),
'textTransform' => $this->getInput('themeFooterTextTransform'),
'font' => $this->getInput('themeFooterFont'),
'fontSize' => $this->getInput('themeFooterFontSize'),
'fontWeight' => $this->getInput('themeFooterFontWeight'),
'displayVersion' => $this->getInput('themefooterDisplayVersion', helper::FILTER_BOOLEAN),
'displaySiteMap' => $this->getInput('themefooterDisplaySiteMap', helper::FILTER_BOOLEAN),
'displayCopyright' => $this->getInput('themefooterDisplayCopyright', helper::FILTER_BOOLEAN),
'displayCookie' => $this->getInput('themefooterDisplayCookie', helper::FILTER_BOOLEAN),
'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')
]
]);
2022-03-10 17:06:28 +01:00
// Sauvegarder la configuration localisée
2022-09-29 08:45:59 +02:00
$this->setData(['locale', 'legalPageId', $this->getInput('configLegalPageId')]);
$this->setData(['locale', 'searchPageId', $this->getInput('configSearchPageId')]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme',
'state' => true
]);
}
}
// Liste des pages
self::$pagesList = $this->getData(['page']);
2022-09-29 08:45:59 +02:00
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
2022-03-10 17:06:28 +01:00
unset(self::$pagesList[$page]);
}
}
2022-03-11 09:17:13 +01:00
// Lire les fontes installées
$this->enumFonts();
2022-04-22 11:55:01 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Pied de page'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'tinycolorpicker',
'tinymce'
],
'view' => 'footer'
]);
}
/**
* Options de la bannière
*/
2022-09-29 08:45:59 +02:00
public function header()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-03-10 17:06:28 +01:00
// Modification des URL des images dans la bannière perso
$featureContent = $this->getInput('themeHeaderText', null);
/**
2022-09-29 08:45:59 +02:00
* Stocker les images incluses dans la bannière perso dans un tableau
*/
$files = [];
2022-09-29 08:45:59 +02:00
preg_match_all('/<img[^>]+>/i', $featureContent, $results);
foreach ($results[0] as $value) {
2022-03-10 17:06:28 +01:00
// Lire le contenu XML
$sx = simplexml_load_string($value);
// Élément à remplacer
2022-09-29 08:45:59 +02:00
$files[] = str_replace('./site/file/source/', '', (string) $sx[0]['src']);
2022-03-10 17:06:28 +01:00
}
// Sauvegarder
$this->setData([
'theme',
'header',
[
'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'),
'font' => $this->getInput('themeHeaderFont'),
'fontSize' => $this->getInput('themeHeaderFontSize'),
'fontWeight' => $this->getInput('themeHeaderFontWeight'),
'height' => $this->getInput('themeHeaderHeight'),
'wide' => $this->getInput('themeHeaderWide'),
'image' => $this->getInput('themeHeaderImage'),
'imagePosition' => $this->getInput('themeHeaderImagePosition'),
'imageRepeat' => $this->getInput('themeHeaderImageRepeat'),
'margin' => $this->getInput('themeHeaderMargin', helper::FILTER_BOOLEAN),
'position' => $this->getInput('themeHeaderPosition'),
'textAlign' => $this->getInput('themeHeaderTextAlign'),
'textColor' => $this->getInput('themeHeaderTextColor'),
'textHide' => $this->getInput('themeHeaderTextHide', helper::FILTER_BOOLEAN),
'textTransform' => $this->getInput('themeHeaderTextTransform'),
'linkHomePage' => $this->getInput('themeHeaderlinkHomePage', helper::FILTER_BOOLEAN),
'imageContainer' => $this->getInput('themeHeaderImageContainer'),
'tinyHidden' => $this->getInput('themeHeaderTinyHidden', helper::FILTER_BOOLEAN),
'feature' => $this->getInput('themeHeaderFeature'),
'featureContent' => $featureContent,
'featureFiles' => $files
]
]);
2022-03-10 17:06:28 +01:00
// Modification de la position du menu selon la position de la bannière
2022-09-29 08:45:59 +02:00
if ($this->getData(['theme', 'header', 'position']) == 'site') {
$this->setData(['theme', 'menu', 'position', str_replace('body-', 'site-', $this->getData(['theme', 'menu', 'position']))]);
2022-03-10 17:06:28 +01:00
}
2022-09-29 08:45:59 +02:00
if ($this->getData(['theme', 'header', 'position']) == 'body') {
$this->setData(['theme', 'menu', 'position', str_replace('site-', 'body-', $this->getData(['theme', 'menu', 'position']))]);
2022-03-10 17:06:28 +01:00
}
// Menu accroché à la bannière qui devient cachée
2022-09-29 08:45:59 +02:00
if (
$this->getData(['theme', 'header', 'position']) == 'hide' &&
in_array($this->getData(['theme', 'menu', 'position']), ['body-first', 'site-first', 'body-first', 'site-second'])
) {
$this->setData(['theme', 'menu', 'position', 'site']);
2022-03-10 17:06:28 +01:00
}
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme',
'state' => true
]);
}
2022-03-11 09:17:13 +01:00
// Lire les fontes installées
$this->enumFonts();
2022-04-22 11:55:01 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Bannière'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'tinycolorpicker',
'tinymce'
],
'view' => 'header'
]);
}
/**
* Accueil de la personnalisation
*/
2022-09-29 08:45:59 +02:00
public function index()
{
2022-04-22 11:06:49 +02:00
// Restaurer les fontes utilisateurs
$this->setFonts('user');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Thèmes'),
2022-03-10 17:06:28 +01:00
'view' => 'index'
]);
}
/**
* Options du menu
*/
2022-09-29 08:45:59 +02:00
public function menu()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'theme',
'menu',
[
'backgroundColor' => $this->getInput('themeMenuBackgroundColor'),
'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'),
'font' => $this->getInput('themeMenuFont'),
'fontSize' => $this->getInput('themeMenuFontSize'),
'fontWeight' => $this->getInput('themeMenuFontWeight'),
'height' => $this->getInput('themeMenuHeight'),
'wide' => $this->getInput('themeMenuWide'),
'loginLink' => $this->getInput('themeMenuLoginLink', helper::FILTER_BOOLEAN),
'margin' => $this->getInput('themeMenuMargin', helper::FILTER_BOOLEAN),
'position' => $this->getInput('themeMenuPosition'),
'textAlign' => $this->getInput('themeMenuTextAlign'),
'textColor' => $this->getInput('themeMenuTextColor'),
'textTransform' => $this->getInput('themeMenuTextTransform'),
'fixed' => $this->getInput('themeMenuFixed', helper::FILTER_BOOLEAN),
'activeColorAuto' => $this->getInput('themeMenuActiveColorAuto', helper::FILTER_BOOLEAN),
'activeColor' => $this->getInput('themeMenuActiveColor'),
'activeTextColor' => $this->getInput('themeMenuActiveTextColor'),
'radius' => $this->getInput('themeMenuRadius'),
'burgerTitle' => $this->getInput('themeMenuBurgerTitle', helper::FILTER_BOOLEAN),
'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN),
'burgerLogo' => $this->getInput('themeMenuBurgerLogo'),
'burgerContent' => $this->getInput('themeMenuBurgerContent')
]
]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme',
'state' => true
]);
}
2022-03-11 09:17:13 +01:00
// Lire les fontes installées
$this->enumFonts();
2022-04-22 11:55:01 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Menu'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'tinycolorpicker'
],
'view' => 'menu'
]);
}
/**
* Options des fontes
*/
2023-04-04 18:56:41 +02:00
public function font()
2022-09-29 08:45:59 +02:00
{
2022-03-10 17:06:28 +01:00
2022-04-22 11:06:49 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Polices liées au thème
$used = [
'Bannière' => $this->getData(['theme', 'header', 'font']),
'Menu' => $this->getData(['theme', 'menu', 'font']),
'Titre ' => $this->getData(['theme', 'title', 'font']),
'Texte' => $this->getData(['theme', 'text', 'font']),
'Pied de page' => $this->getData(['theme', 'footer', 'font']),
2022-09-29 08:45:59 +02:00
'Titre (admin)' => $this->getData(['admin', 'fontTitle']),
'Admin (texte)' => $this->getData(['admin', 'fontText'])
2022-03-10 17:06:28 +01:00
];
2022-03-11 09:59:59 +01:00
// Récupérer le détail des fontes installées
2022-03-21 16:54:11 +01:00
//$f = $this->getFonts();
$f['files'] = $this->getData(['font', 'files']);
$f['imported'] = $this->getData(['font', 'imported']);
2022-09-29 08:45:59 +02:00
$f['websafe'] = self::$fontsWebSafe;
2022-03-11 09:59:59 +01:00
2022-03-11 09:17:13 +01:00
// Parcourir les fontes disponibles et construire le tableau pour le formulaire
2022-03-11 09:59:59 +01:00
foreach ($f as $type => $typeValue) {
2022-03-21 18:25:54 +01:00
if (is_array($typeValue)) {
foreach ($typeValue as $fontId => $fontValue) {
// Fontes utilisées par les thèmes
$fontUsed[$fontId] = '';
foreach ($used as $key => $value) {
2022-09-29 08:45:59 +02:00
if ($value === $fontId) {
$fontUsed[$fontId] .= $key . '<br/>';
2022-03-21 18:25:54 +01:00
}
2022-03-11 09:59:59 +01:00
}
2022-09-29 08:45:59 +02:00
self::$fontsDetail[] = [
2022-03-21 18:25:54 +01:00
$fontId,
2022-09-29 08:45:59 +02:00
'<span style="font-family:' . $f[$type][$fontId]['font-family'] . '">' . $f[$type][$fontId]['name'] . '</span>',
2022-03-21 18:25:54 +01:00
$f[$type][$fontId]['font-family'],
$fontUsed[$fontId],
$type,
$type !== 'websafe' ? template::button('themeFontEdit' . $fontId, [
2022-09-29 08:45:59 +02:00
'class' => 'themeFontEdit',
'href' => helper::baseUrl() . $this->getUrl(0) . '/fontEdit/' . $type . '/' . $fontId,
2022-09-29 08:45:59 +02:00
'value' => template::ico('pencil'),
2024-01-03 00:03:36 +01:00
//'disabled' => !empty($fontUsed[$fontId])
2022-09-29 08:45:59 +02:00
])
: '',
$type !== 'websafe' ? template::button('themeFontDelete' . $fontId, [
2022-09-29 08:45:59 +02:00
'class' => 'themeFontDelete buttonRed',
2023-06-19 19:46:00 +02:00
'href' => helper::baseUrl() . $this->getUrl(0) . '/fontDelete/' . $type . '/' . $fontId,
2022-09-29 08:45:59 +02:00
'value' => template::ico('cancel'),
'disabled' => !empty($fontUsed[$fontId])
])
: ''
2022-03-21 18:25:54 +01:00
];
2022-03-10 17:06:28 +01:00
}
}
}
2022-03-11 09:59:59 +01:00
sort(self::$fontsDetail);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Fontes'),
2024-01-03 00:12:33 +01:00
'view' => 'font',
'vendor' => [
'datatables'
]
2022-03-10 17:06:28 +01:00
]);
}
/**
* Ajouter une fonte
*/
2022-09-29 08:45:59 +02:00
public function fontAdd()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-03-11 14:03:42 +01:00
// Type d'import en ligne ou local
2023-03-10 14:10:31 +01:00
$type = $this->getInput('fontAddUrl', helper::FILTER_BOOLEAN) ? 'imported' : 'files';
2023-03-10 14:13:21 +01:00
$type === 'files' ? 'imported' : 'files';
2024-01-03 00:03:36 +01:00
$resource = $type === 'imported' ? $this->getInput('fontAddUrl', null) : $this->getInput('fontAddFile', null);
if (!empty($resource)) {
$fontId = $this->getInput('fontAddFontId', null, true);
$fontName = $this->getInput('fontAddFontName', null, true);
$fontFamilyName = $this->getInput('fontAddFontFamilyName', null, true);
2022-03-10 17:06:28 +01:00
// Remplace les doubles quotes par des simples quotes
$fontFamilyName = str_replace('"', '\'', $fontFamilyName);
2022-03-21 18:34:57 +01:00
// Supprime la fonte si elle existe dans le type inverse
if (is_array($this->getData(['font', $type, $fontId]))) {
$this->deleteData(['font', $type, $fontId]);
}
2024-01-03 00:03:36 +01:00
2024-01-06 15:48:43 +01:00
// Paramètres de la sortie vrai par défaut, c'est une fonte en ligne
$success = true;
2024-01-03 00:03:36 +01:00
// Copier la fonte si le nom du fichier est fourni
if (!is_dir(self::DATA_DIR . 'font/')) {
mkdir(self::DATA_DIR . 'font/');
}
if (
$type === 'files' &&
file_exists(self::FILE_DIR . 'source/' . $resource)
) {
$success = copy(self::FILE_DIR . 'source/' . $resource, self::DATA_DIR . 'font/' . basename($resource));
}
// Stocker la fonte
2022-09-29 08:45:59 +02:00
$this->setData([
2023-03-01 15:50:41 +01:00
'font',
2022-09-29 08:45:59 +02:00
$type,
$fontId,
[
2022-09-29 08:45:59 +02:00
'name' => $fontName,
'font-family' => $fontFamilyName,
2024-01-06 16:04:15 +01:00
// Stocke l'URL our lien vers la fonte dans data
'resource' => $type === 'imported' ? $resource : self::DATA_DIR . 'font/' . basename($resource),
2022-09-29 08:45:59 +02:00
]
]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2024-01-06 15:48:43 +01:00
'notification' => $success ? helper::translate('Fonte actualisée') : helper::translate('Fonte non créée, ressource absente !'),
2024-01-03 00:03:36 +01:00
'redirect' => helper::baseUrl() . 'theme/font',
'state' => $success
]);
} else {
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Fonte non créée, ressource absente !'),
'redirect' => helper::baseUrl() . 'theme/fontAdd',
'state' => false
]);
}
2022-03-11 16:09:43 +01:00
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Ajouter une fonte'),
2022-03-11 16:09:43 +01:00
'view' => 'fontAdd'
]);
}
/**
* Ajouter une fonte
*/
2022-09-29 08:45:59 +02:00
public function fontEdit()
{
2022-03-11 16:09:43 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-03-11 16:09:43 +01:00
// Type d'import en ligne ou local
2023-03-10 14:10:31 +01:00
$type = $this->getInput('fontEditUrl', helper::FILTER_BOOLEAN) ? 'imported' : 'files';
$fontId = $this->getInput('fontEditFontId', null, true);
2024-01-03 00:03:36 +01:00
$resource = $this->getData(['font', $type, $fontId, 'resource']);
2022-09-29 08:45:59 +02:00
$fontName = $this->getInput('fontEditFontName', null, true);
$fontFamilyName = $this->getInput('fontEditFontFamilyName', null, true);
2022-03-11 16:09:43 +01:00
2022-03-21 18:34:57 +01:00
// Remplace les doubles quotes par des simples quotes
$fontFamilyName = str_replace('"', '\'', $fontFamilyName);
2022-03-18 16:12:30 +01:00
// Supprime la fonte si elle existe dans le type inverse
if (is_array($this->getData(['font', $type, $fontId]))) {
$this->deleteData(['font', $type, $fontId]);
2022-03-18 16:12:30 +01:00
}
2023-03-10 14:10:31 +01:00
2024-01-03 00:03:36 +01:00
2022-03-11 16:09:43 +01:00
// Stocker les fontes
2022-09-29 08:45:59 +02:00
$this->setData([
2023-03-01 15:50:41 +01:00
'font',
2022-09-29 08:45:59 +02:00
$type,
$fontId,
[
2022-09-29 08:45:59 +02:00
'name' => $fontName,
'font-family' => $fontFamilyName,
2024-01-03 00:03:36 +01:00
'resource' => $resource
2022-09-29 08:45:59 +02:00
]
]);
2022-03-11 14:03:42 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Fonte actualisée'),
2024-01-03 00:03:36 +01:00
'redirect' => helper::baseUrl() . 'theme/font',
2022-03-11 14:03:42 +01:00
'state' => true
]);
2022-03-10 17:06:28 +01:00
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Éditer une fonte'),
2022-03-12 12:28:28 +01:00
'view' => 'fontEdit'
2022-03-10 17:06:28 +01:00
]);
}
/**
* Effacer une fonte
*/
2022-09-29 08:45:59 +02:00
public function fontDelete()
{
2023-06-20 20:35:26 +02:00
// Action interdite
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
) {
// Valeurs en sortie
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
'access' => false
2022-03-10 17:06:28 +01:00
]);
}
// Suppression
else {
2022-03-13 10:14:56 +01:00
// Effacer la fonte de la base
2023-03-01 15:50:41 +01:00
$this->deleteData(['font', $this->getUrl(2), $this->getUrl(3)]);
2022-03-10 17:06:28 +01:00
// Effacer le fichier existant
2022-09-29 08:45:59 +02:00
if (
2024-01-06 09:26:40 +01:00
$this->getUrl(2) === 'files' &&
file_exists($this->getData(['font', 'files', $this->getUrl(3), 'resource']))
2022-09-29 08:45:59 +02:00
) {
2024-01-06 09:26:40 +01:00
unlink($this->getData(['font', 'files', $this->getUrl(3), 'resource']));
2022-03-10 17:06:28 +01:00
}
// Valeurs en sortie
$this->addOutput([
2024-01-03 00:03:36 +01:00
'redirect' => helper::baseUrl() . 'theme/font',
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Fonte supprimée'),
2022-03-10 17:06:28 +01:00
'state' => true
]);
}
}
/**
* Réinitialisation de la personnalisation avancée
*/
2022-09-29 08:45:59 +02:00
public function reset()
{
// Action interdite
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
} else {
// Réinitialisation
$redirect = '';
switch ($this->getUrl(2)) {
case 'admin':
$this->initData('admin', self::$i18nUI);
$redirect = helper::baseUrl() . 'theme/admin';
break;
case 'manage':
$this->initData('theme', self::$i18nUI);
$redirect = helper::baseUrl() . 'theme/manage';
break;
case 'custom':
unlink(self::DATA_DIR . 'custom.css');
$redirect = helper::baseUrl() . 'theme/advanced';
break;
default:
$redirect = helper::baseUrl() . 'theme';
}
2023-06-20 20:15:55 +02:00
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Thème réinitialisé'),
'redirect' => $redirect,
'state' => true
]);
}
2022-03-10 17:06:28 +01:00
}
/**
* Options du site
*/
2022-09-29 08:45:59 +02:00
public function site()
{
2022-03-10 17:06:28 +01:00
// Soumission du formulaire
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'theme',
'title',
[
'font' => $this->getInput('themeTitleFont'),
'textColor' => $this->getInput('themeTitleTextColor'),
'fontWeight' => $this->getInput('themeTitleFontWeight'),
'textTransform' => $this->getInput('themeTitleTextTransform')
]
]);
$this->setData([
'theme',
'text',
[
'font' => $this->getInput('themeTextFont'),
'fontSize' => $this->getInput('themeTextFontSize'),
'textColor' => $this->getInput('themeTextTextColor'),
'linkColor' => $this->getInput('themeTextLinkColor')
]
]);
$this->setData([
'theme',
'site',
[
'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')
]
]);
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2022-03-10 17:06:28 +01:00
'redirect' => helper::baseUrl() . 'theme',
'state' => true
]);
}
2022-03-11 09:17:13 +01:00
// Lire les fontes installées
$this->enumFonts();
2022-04-22 11:55:01 +02:00
// Toutes les fontes installées sont chargées
$this->setFonts('all');
2022-03-10 17:06:28 +01:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Site'),
2022-03-10 17:06:28 +01:00
'vendor' => [
'tinycolorpicker',
'tinymce'
],
'view' => 'site'
]);
}
/**
* Import du thème
*/
2022-09-29 08:45:59 +02:00
public function manage()
{
if (
2023-06-30 09:09:39 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
2022-03-10 17:06:28 +01:00
$zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true);
2022-09-29 08:45:59 +02:00
$data = $this->import(self::FILE_DIR . 'source/' . $zipFilename);
2022-03-10 17:06:28 +01:00
if ($data['success']) {
header("Refresh:0");
} else {
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Gestion des thèmes'),
2022-03-10 17:06:28 +01:00
'notification' => $data['notification'],
'state' => $data['success'],
'view' => 'manage'
]);
;
2022-03-10 17:06:28 +01:00
}
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Gestion des thèmes'),
2022-03-10 17:06:28 +01:00
'view' => 'manage'
]);
}
/**
* Importe un thème
* @param string Url du thème à télécharger
* @param @return array contenant $success = true ou false ; $ notification string message à afficher
*/
2022-09-29 08:45:59 +02:00
public function import($zipName = '')
{
2023-07-04 19:03:27 +02:00
// Action interdite
2022-09-29 08:45:59 +02:00
if (
2023-07-04 19:03:27 +02:00
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
2022-09-29 08:45:59 +02:00
) {
2023-07-04 19:03:27 +02:00
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
} else {
2022-03-10 17:06:28 +01:00
2023-07-04 19:03:27 +02:00
if (
$zipName !== '' &&
file_exists($zipName)
) {
// Init variables de retour
$success = false;
$notification = '';
// Dossier temporaire
$tempFolder = uniqid();
// Ouvrir le zip
$zip = new ZipArchive();
if ($zip->open($zipName) === TRUE) {
mkdir(self::TEMP_DIR . $tempFolder, 0755);
$zip->extractTo(self::TEMP_DIR . $tempFolder);
$modele = '';
// Archive de thème ?
if (
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css')
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css')
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json')
) {
$modele = 'theme';
2022-03-10 17:06:28 +01:00
}
2023-07-04 19:03:27 +02:00
if (
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json')
and file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css')
) {
$modele = 'admin';
2022-03-10 17:06:28 +01:00
}
2023-07-04 19:03:27 +02:00
if (!empty($modele)) {
// traiter l'archive
$success = $zip->extractTo('.');
2022-03-10 17:06:28 +01:00
2023-07-04 19:03:27 +02:00
// Substitution des fontes Google
if ($modele = 'theme') {
$c = $this->subFont(self::DATA_DIR . 'theme.json');
// Un remplacement nécessite la régénération de la feuille de style
if (
$c > 0
and file_exists(self::DATA_DIR . 'theme.css')
) {
unlink(self::DATA_DIR . 'theme.css');
}
}
if ($modele = 'admin') {
$c = $this->subFont(self::DATA_DIR . 'admin.json');
// Un remplacement nécessite la régénération de la feuille de style
if (
$c > 0
and file_exists(self::DATA_DIR . 'admin.css')
) {
unlink(self::DATA_DIR . 'admin.css');
}
}
// traitement d'erreur
$notification = $success ? helper::translate('Thème importé') : helper::translate('Erreur lors de l\'extraction, vérifiez les permissions');
} else {
// pas une archive de thème
$success = false;
$notification = helper::translate('Archive de thème invalide');
}
// Supprimer le dossier temporaire même si le thème est invalide
2023-07-19 18:07:12 +02:00
$this->deleteDir(self::TEMP_DIR . $tempFolder);
2023-07-04 19:03:27 +02:00
$zip->close();
2022-03-10 17:06:28 +01:00
} else {
2023-07-04 19:03:27 +02:00
// erreur à l'ouverture
2022-03-10 17:06:28 +01:00
$success = false;
2023-07-04 19:03:27 +02:00
$notification = helper::translate('Impossible d\'ouvrir l\'archive');
2022-03-10 17:06:28 +01:00
}
2023-07-04 19:03:27 +02:00
return (['success' => $success, 'notification' => $notification]);
2022-03-10 17:06:28 +01:00
}
2023-07-04 19:03:27 +02:00
return (['success' => false, 'notification' => helper::translate('Archive non spécifiée ou introuvable')]);
}
2022-03-10 17:06:28 +01:00
}
/**
* Export du thème
*/
2022-09-29 08:45:59 +02:00
public function export()
{
// Action interdite
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
} else {
// Make zip
$zipFilename = $this->zipTheme($this->getUrl(2));
// Téléchargement du ZIP
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $zipFilename . '"');
header('Content-Length: ' . filesize(self::TEMP_DIR . $zipFilename));
readfile(self::TEMP_DIR . $zipFilename);
// Nettoyage du dossier
unlink(self::TEMP_DIR . $zipFilename);
exit();
}
2022-03-10 17:06:28 +01:00
}
/**
* Export du thème
*/
2022-09-29 08:45:59 +02:00
public function save()
{
// Action interdite
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) !== true
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
} else {
// Make zip
$zipFilename = $this->zipTheme($this->getUrl(2));
// Téléchargement du ZIP
if (!is_dir(self::FILE_DIR . 'source/theme')) {
mkdir(self::FILE_DIR . 'source/theme', 0755);
}
copy(self::TEMP_DIR . $zipFilename, self::FILE_DIR . 'source/theme/' . $zipFilename);
// Nettoyage du dossier
unlink(self::TEMP_DIR . $zipFilename);
// Valeurs en sortie
$this->addOutput([
'notification' => '<b>' . $zipFilename . '</b>' . helper::translate('sauvegardé avec succès'),
'redirect' => helper::baseUrl() . 'theme/manage',
'state' => true
]);
2022-03-10 17:06:28 +01:00
}
}
/**
* construction du zip Fonction appelée par export() et save()
* @param string $modele theme ou admin
*/
2022-09-29 08:45:59 +02:00
private function zipTheme($modele)
{
2022-03-10 17:06:28 +01:00
// Creation du dossier
$zipFilename = $modele . date('Y-m-d-H-i-s', time()) . '.zip';
2022-03-10 17:06:28 +01:00
$zip = new ZipArchive();
2022-09-29 08:45:59 +02:00
if ($zip->open(self::TEMP_DIR . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
2022-03-10 17:06:28 +01:00
switch ($modele) {
case 'admin':
2022-09-29 08:45:59 +02:00
$zip->addFile(self::DATA_DIR . 'admin.json', self::DATA_DIR . 'admin.json');
$zip->addFile(self::DATA_DIR . 'admin.css', self::DATA_DIR . 'admin.css');
2022-03-20 18:57:26 +01:00
// Ajoute les fontes
2023-03-01 15:50:41 +01:00
$zip->addEmptyDir(self::DATA_DIR . 'font');
$fonts = $this->getData(['font', 'files']);
2022-03-20 18:57:26 +01:00
foreach ($fonts as $fontId => $fontName) {
2023-04-04 18:56:41 +02:00
$zip->addFile(self::DATA_DIR . 'font/' . $fontName, self::DATA_DIR . 'font/' . $fontName);
2022-03-20 18:57:26 +01:00
}
2023-04-04 18:56:41 +02:00
if (file_exists(self::DATA_DIR . 'font/font.html')) {
2022-03-20 18:57:26 +01:00
2023-04-04 18:56:41 +02:00
$zip->addFile(self::DATA_DIR . 'font/font.html', self::DATA_DIR . 'font/font.html');
2022-03-20 18:57:26 +01:00
}
2022-03-10 17:06:28 +01:00
break;
case 'theme':
2022-09-29 08:45:59 +02:00
$zip->addFile(self::DATA_DIR . 'theme.json', self::DATA_DIR . 'theme.json');
$zip->addFile(self::DATA_DIR . 'theme.css', self::DATA_DIR . 'theme.css');
$zip->addFile(self::DATA_DIR . 'custom.css', self::DATA_DIR . 'custom.css');
2022-03-10 17:06:28 +01:00
// Traite l'image dans le body
2022-09-29 08:45:59 +02:00
if ($this->getData(['theme', 'body', 'image']) !== '') {
$zip->addFile(
self::FILE_DIR . 'source/' . $this->getData(['theme', 'body', 'image']),
self::FILE_DIR . 'source/' . $this->getData(['theme', 'body', 'image'])
);
2022-03-10 17:06:28 +01:00
}
// Traite l'image dans le header
2022-09-29 08:45:59 +02:00
if ($this->getData(['theme', 'header', 'image']) !== '') {
$zip->addFile(
self::FILE_DIR . 'source/' . $this->getData(['theme', 'header', 'image']),
self::FILE_DIR . 'source/' . $this->getData(['theme', 'header', 'image'])
);
2022-03-10 17:06:28 +01:00
}
// Traite les images du header perso
2022-09-29 08:45:59 +02:00
if (!empty($this->getData(['theme', 'header', 'featureFiles']))) {
foreach ($this->getData(['theme', 'header', 'featureFiles']) as $value) {
$zip->addFile(
self::FILE_DIR . 'source/' . $value,
self::FILE_DIR . 'source/' . $value
);
2022-03-10 17:06:28 +01:00
}
}
2022-03-20 18:57:26 +01:00
// Ajoute les fontes
2023-03-01 15:50:41 +01:00
$zip->addEmptyDir(self::DATA_DIR . 'font');
$fonts = $this->getData(['font', 'files']);
2024-01-06 23:17:45 +01:00
foreach ($fonts as $fontId => $fontInfo) {
$zip->addFile($fontInfo['resource'], $fontInfo['resource']);
2022-03-20 18:57:26 +01:00
}
2023-04-04 18:56:41 +02:00
if (file_exists(self::DATA_DIR . 'font/font.html')) {
$zip->addFile(self::DATA_DIR . 'font/font.html', self::DATA_DIR . 'font/font.html');
2022-03-20 18:57:26 +01:00
}
2024-01-06 23:17:45 +01:00
if (file_exists(self::DATA_DIR . 'font/font.css')) {
$zip->addFile(self::DATA_DIR . 'font/font.css', self::DATA_DIR . 'font/font.css');
}
2022-03-10 17:06:28 +01:00
break;
}
$ret = $zip->close();
}
return ($zipFilename);
}
/**
* Substitution des fontes de Google Fonts vers CdnFont grâce à un tableau de conversion
* Cette fonction est utilisée par l'import.
* @param string $file, nom du fichier json à convertir
* @return int nombre de substitution effectuées
*/
2023-04-04 18:56:41 +02:00
private function subFont($file)
2022-09-29 08:45:59 +02:00
{
2022-03-10 17:06:28 +01:00
// Tableau de substitution des fontes
$fonts = [
'Abril+Fatface' => 'abril-fatface',
'Arimo' => 'arimo',
'Arvo' => 'arvo',
'Berkshire+Swash' => 'berkshire-swash',
'Cabin' => 'genera',
'Dancing+Script' => 'dancing-script',
'Droid+Sans' => 'droid-sans-2',
'Droid+Serif' => 'droid-serif-2',
'Fira+Sans' => 'fira-sans',
'Inconsolata' => 'inconsolata-2',
2022-09-29 08:45:59 +02:00
'Indie+Flower' => 'indie-flower',
2022-03-10 17:06:28 +01:00
'Josefin+Slab' => 'josefin-sans-std',
'Lobster' => 'lobster-2',
'Lora' => 'lora',
2022-09-29 08:45:59 +02:00
'Lato' => 'lato',
2022-03-10 17:06:28 +01:00
'Marvel' => 'montserrat-ace',
'Old+Standard+TT' => 'old-standard-tt-3',
2022-09-29 08:45:59 +02:00
'Open+Sans' => 'open-sans',
// Corriger l'erreur de nom de police installée par défaut, il manquait un O en majuscule
'open+Sans' => 'open-sans',
'Oswald' => 'oswald-4',
2022-03-10 17:06:28 +01:00
'PT+Mono' => 'pt-mono',
2022-09-29 08:45:59 +02:00
'PT+Serif' => 'pt-serif',
2022-03-10 17:06:28 +01:00
'Raleway' => 'raleway-5',
'Rancho' => 'rancho',
'Roboto' => 'Roboto',
'Signika' => 'signika',
'Ubuntu' => 'ubuntu',
'Vollkorn' => 'vollkorn'
];
$data = file_get_contents($file);
$count = 0;
2022-09-29 08:45:59 +02:00
foreach ($fonts as $oldId => $newId) {
2022-03-10 17:06:28 +01:00
$data = str_replace($oldId, $newId, $data, $c);
$count = $count + (int) $c;
}
// Sauvegarder la chaîne modifiée
if ($count > 0) {
file_put_contents($file, $data);
}
// Retourner le nombre d'occurrences
return ($count);
}
2022-03-14 09:31:35 +01:00
2022-03-11 09:17:13 +01:00
// Retourne un tableau simple des fonts installées idfont avec le nom
// Cette fonction est utile aux sélecteurs de fonts dans les formulaires.
2022-09-29 08:45:59 +02:00
public function enumFonts()
{
2022-04-21 18:38:19 +02:00
/**
2022-09-29 08:45:59 +02:00
* Récupère la liste des fontes installées et construit deux tableaux
* id - nom
* id - font-family - resource
*/
$f['files'] = $this->getData(['font', 'files']);
$f['imported'] = $this->getData(['font', 'imported']);
2022-09-29 08:45:59 +02:00
$f['websafe'] = self::$fontsWebSafe;
2022-03-10 17:06:28 +01:00
// Construit un tableau avec leur ID et leur famille
2022-09-29 08:45:59 +02:00
foreach (['websafe', 'imported', 'files'] as $type) {
if (is_array($f[$type])) {
foreach ($f[$type] as $fontId => $fontValue) {
2022-04-21 18:38:19 +02:00
self::$fonts['name'][$fontId] = $fontValue['name'];
self::$fonts['family'][$fontId] = $fontValue['font-family'];
2022-03-14 09:31:35 +01:00
}
2022-03-10 17:06:28 +01:00
}
}
2022-04-21 18:38:19 +02:00
// Liste des fontes pour les sélecteurs
ksort(self::$fonts['name']);
ksort(self::$fonts['family']);
2022-03-10 17:06:28 +01:00
}
2022-04-21 23:37:57 +02:00
/**
* Création d'un fichier de liens d'appel des fontes
* @param string $scope vaut all pour toutes les fontes ; 'user' pour les fontes utilisateurs
2022-04-21 23:37:57 +02:00
*/
2022-09-29 08:45:59 +02:00
private function setFonts($scope = 'all')
{
// Filtrage par fontes installées
2022-09-29 08:45:59 +02:00
$fontsInstalled = [
$this->getData(['theme', 'text', 'font']),
2022-09-29 08:45:59 +02:00
$this->getData(['theme', 'title', 'font']),
$this->getData(['theme', 'header', 'font']),
$this->getData(['theme', 'menu', 'font']),
$this->getData(['theme', 'footer', 'font']),
$this->getData(['admin', 'fontText']),
$this->getData(['admin', 'fontTitle']),
];
// Compression
$fontsInstalled = array_unique($fontsInstalled);
2022-04-21 23:37:57 +02:00
/**
* Chargement des polices en ligne dans un fichier font.html inclus dans main.php
2022-09-29 08:45:59 +02:00
*/
2022-04-21 23:37:57 +02:00
$gf = false;
$fileContent = '<!-- Fontes personnalisées -->';
2023-03-01 15:50:41 +01:00
if (!empty($this->getData(['font', 'imported']))) {
foreach ($this->getData(['font', 'imported']) as $fontId => $fontValue) {
2022-09-29 08:45:59 +02:00
if (
($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all'
2022-09-29 08:45:59 +02:00
) {
//Pré chargement à revoir
//$fileContent .= '<link rel="preload" href="' . $fontValue['resource'] . '" crossorigin="anonymous" as="style">';
$fileContent .= '<link href="' . $fontValue['resource'] . '" rel="stylesheet">';
// Pré connect pour api.google
$gf = strpos($fontValue['resource'], 'fonts.googleapis.com') === false ? $gf || false : $gf || true;
2022-09-29 08:45:59 +02:00
}
}
}
2022-09-26 16:06:32 +02:00
2022-04-21 23:37:57 +02:00
// Ajoute le préconnect des fontes Googles.
$fileContent = $gf ? '<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . $fileContent
2022-09-29 08:45:59 +02:00
: $fileContent;
2022-04-21 23:37:57 +02:00
2022-04-22 15:56:45 +02:00
2022-04-21 23:37:57 +02:00
/**
* Fontes installées localement
*/
2022-04-22 15:56:45 +02:00
$fileContentCss = '';
2023-03-01 15:50:41 +01:00
if (!empty($this->getData(['font', 'files']))) {
foreach ($this->getData(['font', 'files']) as $fontId => $fontValue) {
2022-09-29 08:45:59 +02:00
if (
($scope === 'user' && in_array($fontId, $fontsInstalled))
|| $scope === 'all'
2022-09-29 08:45:59 +02:00
) {
2024-01-03 00:03:36 +01:00
if (file_exists($fontValue['resource'])) {
2022-09-29 08:45:59 +02:00
// Extension
$path_parts = pathinfo(helper::baseUrl(false) . self::DATA_DIR . 'font/' . $fontValue['resource']);
2022-09-29 08:45:59 +02:00
// Chargement de la police
$fileContentCss .= '@font-face {';
2022-09-29 08:45:59 +02:00
$fileContentCss .= 'font-family:"' . $fontValue['name'] . '";';
2024-01-03 00:03:36 +01:00
$fileContentCss .= 'src: url("' . helper::baseUrl(false) . $fontValue['resource'] . '") format("' . $path_parts['extension'] . '");';
$fileContentCss .= '}';
2022-09-29 08:45:59 +02:00
// Préchargement
2023-04-04 18:56:41 +02:00
//$fileContent = '<link rel="preload" href="' . self::DATA_DIR . 'font/' . $fontValue['resource'] . '" type="font/woff" crossorigin="anonymous" as="font">' . $fileContent;
}
2022-05-09 17:25:59 +02:00
}
2022-09-29 08:45:59 +02:00
}
}
2022-04-22 15:56:45 +02:00
// Enregistre la personnalisation
2023-04-04 18:56:41 +02:00
file_put_contents(self::DATA_DIR . 'font/font.html', $fileContent);
2022-04-21 23:37:57 +02:00
// Enregistre la personnalisation
file_put_contents(self::DATA_DIR . 'font/font.css', $fileContentCss);
2022-03-10 17:06:28 +01:00
}
}