Gestion des fontes des feuilles de style ok

This commit is contained in:
fredtempez 2022-03-10 15:09:56 +01:00
parent cfb61590f0
commit 9dc533d7a9
3 changed files with 102 additions and 98 deletions

View File

@ -413,21 +413,17 @@ class common {
/** /**
* Construit la liste des fontes dans un tableau * Construit la liste des fontes dans un tableau
* @return @fonts * @return array @fonts
* fontid *
* 'familyName' =>
* 'type=> websafe ou imported ou file
* 'ressource' => stack ou file
*/ */
public function getFonts() { public function getFonts() {
// Fusionne la liste des fontes avec les webSafe // Fusionne la liste des fontes avec les webSafe
foreach (self::$fontsWebSafe as $fontId => $fontValue) { foreach (self::$fontsWebSafe as $fontId => $fontValue) {
$fontName = explode (',', $fontValue); $fontName = explode (',', $fontValue);
$f[$fontId] = [ $f ['websafe'] [$fontId] = [
'fontfamily'=> $fontName[0], 'name' => $fontName[0],
'ressource' => $fontValue, 'font-family'=> $fontValue
'type' => 'websafe'
]; ];
} }
// Ajoute les polices importées chez cdnfonts // Ajoute les polices importées chez cdnfonts
@ -435,10 +431,11 @@ class common {
if (is_array($fontsImported) if (is_array($fontsImported)
) { ) {
foreach ($fontsImported as $fontId => $fontValue) { foreach ($fontsImported as $fontId => $fontValue) {
$f[$fontId] = [ $fontName = explode (',', $fontValue);
'fontfamily'=> $fontValue, $f ['imported'] [$fontId] = [
'ressource' => $fontValue . "; sans-serif", // Format par défaut 'name' => $fontName[0],
'type' => 'imported' 'font-family'=> $fontValue
//'ressource'
]; ];
} }
} }
@ -447,15 +444,12 @@ class common {
if (is_array($fontsFiles) if (is_array($fontsFiles)
) { ) {
foreach ($fontsFiles as $fontId => $fontValue) { foreach ($fontsFiles as $fontId => $fontValue) {
$f[$fontId] = [ $f ['files'] [$fontId] = [
// la fonte family est reprise de files 'font-family'=> $fontValue ['font-family'],
'ressource' => $fontValue, 'ressource'=> $fontValue ['ressource']
'type' => 'files'
]; ];
} }
} }
// Tri Alphabétique
ksort($f);
return $f; return $f;
} }
@ -2355,14 +2349,25 @@ class core extends common {
// Suppression des polices identiques // Suppression des polices identiques
$fonts = array_unique($fonts); $fonts = array_unique($fonts);
/**
* Charge les fontes websafe
*/
$fontFile = '';
foreach ($fonts as $fontId) {
if ( isset($fontsAvailable['websafe'][$fontId])) {
self::$fonts [$fontId] = $fontsAvailable['websafe'][$fontId]['font-family'];
}
}
/** /**
* Chargement des polices en ligne dans un fichier fonts.html inclus dans main.php * Chargement des polices en ligne dans un fichier fonts.html inclus dans main.php
*/ */
$fontFile = ''; $fontFile = '';
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
if ( isset($fontsAvailable[$fontId]) && if ( isset($fontsAvailable['imported'][$fontId])) {
$fontsAvailable[$fontId]['type'] === 'imported' ) {
$fontFile .= '<link href="https://fonts.cdnfonts.com/css/' . $fontId .'" rel="stylesheet">'; $fontFile .= '<link href="https://fonts.cdnfonts.com/css/' . $fontId .'" rel="stylesheet">';
// Tableau pour la construction de la feuille de style
self::$fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family'];
} }
} }
// Enregistre la personnalisation // Enregistre la personnalisation
@ -2373,12 +2378,14 @@ class core extends common {
*/ */
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
// Validité du tableau : // Validité du tableau :
if ( array_key_exists($fontId, self::$fonts) && if ( isset($fontsAvailable['files'][$fontId]) &&
file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) { file_exists(self::DATA_DIR . 'fonts/' . $f) ) {
// Chargement de la police // Chargement de la police
//$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName); //$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName);
$css .= '@font-face {font-family:"' . self::$fonts[$fontId] . '";'; $css .= '@font-face {font-family:"' . $fontsAvailable['files'][$fontId]['font-family'] . '";';
$css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontName . '");}'; $css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontName . '");}';
// Tableau pour la construction de la feuille de style
self::$fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family'];
} }
} }
@ -2386,7 +2393,7 @@ class core extends common {
// Fond du body // Fond du body
$colors = helper::colorVariants($this->getData(['theme', 'body', 'backgroundColor'])); $colors = helper::colorVariants($this->getData(['theme', 'body', 'backgroundColor']));
// Body // Body
$css .= 'body{font-family:"' . self::$fonts[$this->getData(['theme', 'text', 'font'])] . '",sans-serif}'; $css .= 'body{font-family:' . self::$fonts[$this->getData(['theme', 'text', 'font'])] . ';}';
if($themeBodyImage = $this->getData(['theme', 'body', 'image'])) { if($themeBodyImage = $this->getData(['theme', 'body', 'image'])) {
// Image dans html pour éviter les déformations. // Image dans html pour éviter les déformations.
$css .= 'html {background-image:url("../file/source/' . $themeBodyImage . '");background-position:' . $this->getData(['theme', 'body', 'imagePosition']) . ';background-attachment:' . $this->getData(['theme', 'body', 'imageAttachment']) . ';background-size:' . $this->getData(['theme', 'body', 'imageSize']) . ';background-repeat:' . $this->getData(['theme', 'body', 'imageRepeat']) . '}'; $css .= 'html {background-image:url("../file/source/' . $themeBodyImage . '");background-position:' . $this->getData(['theme', 'body', 'imagePosition']) . ';background-attachment:' . $this->getData(['theme', 'body', 'imageAttachment']) . ';background-size:' . $this->getData(['theme', 'body', 'imageSize']) . ';background-repeat:' . $this->getData(['theme', 'body', 'imageRepeat']) . '}';
@ -2404,7 +2411,7 @@ class core extends common {
$colors = helper::colorVariants($this->getData(['theme', 'text', 'linkColor'])); $colors = helper::colorVariants($this->getData(['theme', 'text', 'linkColor']));
$css .= 'a{color:' . $colors['normal'] . '}'; $css .= 'a{color:' . $colors['normal'] . '}';
// Couleurs de site dans TinyMCe // Couleurs de site dans TinyMCe
$css .= 'div.mce-edit-area {font-family:"' . self::$fonts[$this->getData(['theme', 'text', 'font'])] . '",sans-serif}'; $css .= 'div.mce-edit-area {font-family:' . self::$fonts[$this->getData(['theme', 'text', 'font'])] . ';}';
// Site dans TinyMCE // Site dans TinyMCE
$css .= '.editorWysiwyg {background-color:' . $this->getData(['theme', 'site', 'backgroundColor']) . ';}'; $css .= '.editorWysiwyg {background-color:' . $this->getData(['theme', 'site', 'backgroundColor']) . ';}';
$css .= 'span.mce-text{background-color: unset !important;}'; $css .= 'span.mce-text{background-color: unset !important;}';
@ -2445,7 +2452,7 @@ class core extends common {
$css .= '.helpButton span:hover{color:' . $colors['darken'] . '}'; $css .= '.helpButton span:hover{color:' . $colors['darken'] . '}';
$css .= '.button:active,button[type=\'submit\']:active,.pagination a:active{background-color:' . $colors['veryDarken'] . '}'; $css .= '.button:active,button[type=\'submit\']:active,.pagination a:active{background-color:' . $colors['veryDarken'] . '}';
$colors = helper::colorVariants($this->getData(['theme', 'title', 'textColor'])); $colors = helper::colorVariants($this->getData(['theme', 'title', 'textColor']));
$css .= 'h1,h2,h3,h4,h5,h6,h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:' . $colors['normal'] . ';font-family:"' . self::$fonts[$this->getData(['theme', 'title', 'font'])] . '",sans-serif;font-weight:' . $this->getData(['theme', 'title', 'fontWeight']) . ';text-transform:' . $this->getData(['theme', 'title', 'textTransform']) . '}'; $css .= 'h1,h2,h3,h4,h5,h6,h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:' . $colors['normal'] . ';font-family:' . self::$fonts[$this->getData(['theme', 'title', 'font'])] . ';font-weight:' . $this->getData(['theme', 'title', 'fontWeight']) . ';text-transform:' . $this->getData(['theme', 'title', 'textTransform']) . '}';
$css .= 'h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color:' . $colors['darken'] . '}'; $css .= 'h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color:' . $colors['darken'] . '}';
// Les blocs // Les blocs
$colors = helper::colorVariants($this->getData(['theme', 'block', 'backgroundColor'])); $colors = helper::colorVariants($this->getData(['theme', 'block', 'backgroundColor']));
@ -2479,7 +2486,7 @@ class core extends common {
$css .= 'header{background-image:url("../file/source/' . $themeHeaderImage . '");background-position:' . $this->getData(['theme', 'header', 'imagePosition']) . ';background-repeat:' . $this->getData(['theme', 'header', 'imageRepeat']) . '}'; $css .= 'header{background-image:url("../file/source/' . $themeHeaderImage . '");background-position:' . $this->getData(['theme', 'header', 'imagePosition']) . ';background-repeat:' . $this->getData(['theme', 'header', 'imageRepeat']) . '}';
} }
$colors = helper::colorVariants($this->getData(['theme', 'header', 'textColor'])); $colors = helper::colorVariants($this->getData(['theme', 'header', 'textColor']));
$css .= 'header span{color:' . $colors['normal'] . ';font-family:"' . self::$fonts[$this->getData(['theme', 'header', 'font'])] . '",sans-serif;font-weight:' . $this->getData(['theme', 'header', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'header', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'header', 'textTransform']) . '}'; $css .= 'header span{color:' . $colors['normal'] . ';font-family:' . self::$fonts[$this->getData(['theme', 'header', 'font'])] . ';font-weight:' . $this->getData(['theme', 'header', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'header', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'header', 'textTransform']) . '}';
} }
// Bannière au contenu personnalisé // Bannière au contenu personnalisé
@ -2528,7 +2535,7 @@ class core extends common {
$css .= 'nav{padding:0 10px;}'; $css .= 'nav{padding:0 10px;}';
} }
$css .= '#toggle span,#menu a{padding:' . $this->getData(['theme', 'menu', 'height']) .';font-family:"' . self::$fonts[$this->getData(['theme', 'menu', 'font'])] . '",sans-serif;font-weight:' . $this->getData(['theme', 'menu', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'menu', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'menu', 'textTransform']) . '}'; $css .= '#toggle span,#menu a{padding:' . $this->getData(['theme', 'menu', 'height']) .';font-family:' . self::$fonts[$this->getData(['theme', 'menu', 'font'])] . ';font-weight:' . $this->getData(['theme', 'menu', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'menu', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'menu', 'textTransform']) . '}';
// Pied de page // Pied de page
$colors = helper::colorVariants($this->getData(['theme', 'footer', 'backgroundColor'])); $colors = helper::colorVariants($this->getData(['theme', 'footer', 'backgroundColor']));
@ -2538,7 +2545,7 @@ class core extends common {
$css .= 'footer{padding:0}'; $css .= 'footer{padding:0}';
} }
$css .= 'footer span, #footerText > p {color:' . $this->getData(['theme', 'footer', 'textColor']) . ';font-family:"' . self::$fonts[$this->getData(['theme', 'footer', 'font'])] . '",sans-serif;font-weight:' . $this->getData(['theme', 'footer', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'footer', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'footer', 'textTransform']) . '}'; $css .= 'footer span, #footerText > p {color:' . $this->getData(['theme', 'footer', 'textColor']) . ';font-family:' . self::$fonts[$this->getData(['theme', 'footer', 'font'])] . ';font-weight:' . $this->getData(['theme', 'footer', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'footer', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'footer', 'textTransform']) . '}';
$css .= 'footer {background-color:' . $colors['normal'] . ';color:' . $this->getData(['theme', 'footer', 'textColor']) . '}'; $css .= 'footer {background-color:' . $colors['normal'] . ';color:' . $this->getData(['theme', 'footer', 'textColor']) . '}';
$css .= 'footer a{color:' . $this->getData(['theme', 'footer', 'textColor']) . '}'; $css .= 'footer a{color:' . $this->getData(['theme', 'footer', 'textColor']) . '}';
$css .= 'footer #footersite > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}'; $css .= 'footer #footersite > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}';
@ -2549,10 +2556,8 @@ class core extends common {
$css .= '#footerText > p {text-align:' . $this->getData(['theme', 'footer', 'textAlign']) . '}'; $css .= '#footerText > p {text-align:' . $this->getData(['theme', 'footer', 'textAlign']) . '}';
$css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}'; $css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}';
// Enregistre la personnalisation // Enregistre la personnalisation
file_put_contents(self::DATA_DIR.'theme.css', $css); file_put_contents(self::DATA_DIR.'theme.css', $css);
file_put_contents(self::DATA_DIR.'fonts/fonts.html', $fontFile);
// Effacer le cache pour tenir compte de la couleur de fond TinyMCE // Effacer le cache pour tenir compte de la couleur de fond TinyMCE
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT"); header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
@ -2579,52 +2584,51 @@ class core extends common {
$fonts = array_unique($fonts); $fonts = array_unique($fonts);
/** /**
* Fontes Web Safe, ne sont pas chargées. * Charge les fontes websafe
*/ */
$fontFile = '';
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
if (array_key_exists($fontId, self::$fontsWebSafe) ) { if ( isset($fontsAvailable['websafe'][$fontId])) {
unset($fonts[$fontId]); self::$fonts [$fontId] = $fontsAvailable['websafe'][$fontId]['font-family'];
} }
} }
// Lire le fichier des fontes locales
$localFonts = $this->getData(['fonts', 'files']);
/** /**
* Chargement des polices en ligne * Chargement des polices en ligne dans un fichier fonts.html inclus dans main.php
*/ */
$fontFile = '';
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
if (!array_key_exists($fontId, $localFonts) ) { if ( isset($fontsAvailable['imported'][$fontId])) {
$css .= '@import url("https://fonts.cdnfonts.com/css/' . $fontId . '");'; $fontFile .= '<link href="https://fonts.cdnfonts.com/css/' . $fontId .'" rel="stylesheet">';
// Supprimer l'élément des fontes chargées en ligne // Tableau pour la construction de la feuille de style
unset($fonts[$fontId]); self::$fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family'];
} }
} }
// Enregistre la personnalisation
file_put_contents(self::DATA_DIR.'fonts/fonts.html', $fontFile);
/** /**
* Fontes installées localement * Fontes installées localement
*/ */
// Validité du format foreach ($fonts as $fontId) {
if ( !empty($localFonts) // Validité du tableau :
) { if ( isset($fontsAvailable['files'][$fontId]) &&
foreach ($localFonts as $fontId => $fontName) { file_exists(self::DATA_DIR . 'fonts/' . $f) ) {
// Validité du tableau : // Chargement de la police
if ( array_key_exists($fontId, self::$fonts) && //$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName);
file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) { $css .= '@font-face {font-family:"' . $fontsAvailable['files'][$fontId]['font-family'] . '";';
// Chargement de la police $css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontName . '");}';
//$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName); // Tableau pour la construction de la feuille de style
$css .= '@font-face {font-family:"' . self::$fonts[$fontId] . '";'; self::$fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family'];
$css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontName . '");}';
}
} }
} }
// Thème Administration // Thème Administration
$colors = helper::colorVariants($this->getData(['admin','backgroundColor'])); $colors = helper::colorVariants($this->getData(['admin','backgroundColor']));
$css .= '#site{background-color:' . $colors['normal']. ';}'; $css .= '#site{background-color:' . $colors['normal']. ';}';
$css .= '.row > div {font:' . $this->getData(['admin','fontSize']) . ' "' . self::$fonts[$this->getData(['admin','fontText'])] . '", sans-serif;}'; $css .= '.row > div {font:' . self::$fonts[$this->getData(['admin','fontText'])] . ';font-size:' . $this->getData(['admin','fontSize']) .'}';
$css .= 'body h1, h2, h3, h4 a, h5, h6 {font-family:"' . self::$fonts[$this->getData(['admin','fontTitle'])] . '", sans-serif;color:' . $this->getData(['admin','colorTitle' ]) . ';}'; $css .= 'body h1, h2, h3, h4 a, h5, h6 {font-family:' . self::$fonts[$this->getData(['admin','fontTitle'])] . ';color:' . $this->getData(['admin','colorTitle' ]) . ';}';
// TinyMCE // TinyMCE
$css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this->getData(['admin','colorText']) . ';}'; $css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this->getData(['admin','colorText']) . ';}';

View File

@ -813,26 +813,26 @@ if ($this->getData(['core', 'dataVersion']) < 11303) {
if ($this->getData(['core', 'dataVersion']) < 11400) { if ($this->getData(['core', 'dataVersion']) < 11400) {
$fonts = [ $fonts = [
'arimo' => 'Arimo', 'arimo'=> 'Arimo, sans-serif',
'arvo' => 'Arvo', 'arvo'=> 'Arvo, sans-serif',
'dancing-script' => 'Dancing Script', 'dancing-script' => '"Dancing Script", sans-serif',
'droid-sans-2' => 'Droid Sans', 'droid-sans-2'=> '"Droid Sans", sans-serif',
'droid-serif-2' => 'Droid Serif', 'droid-serif-2'=> '"Droid Serif", serif',
'indie-flower' => 'Indie Flower', 'indie-flower'=> '"Indie Flower", sans-serif',
'liberation-sans' => 'Liberation Sans', 'liberation-sans'=> '"Liberation Sans", sans-serif',
'liberation-serif' => 'Liberation Serif', 'liberation-serif'=> '"Liberation Serif", serif',
'lobster-2' => 'Lobster', 'lobster-2'=> 'Lobster, sans-serif',
'lora' => 'Lora', 'lora'=> 'Lora, serif',
'lato' => 'Lato', 'lato'=> 'Lato, sans-serif',
'old-standard-tt-3' => 'Old Standard TT', 'old-standard-tt-3'=> '"Old Standard TT", serif',
'open-sans' => 'Open Sans', 'open-sans'=> '"Open Sans", sans-serif',
'oswald-4' => 'Oswald', 'oswald-4'=> 'Oswald, sans-serif',
'pt-mono' => 'PT Mono', 'pt-mono'=> '"PT Mono", monospace',
'pt-serif' => 'PT Serif', 'pt-serif'=> '"PT Serif", serif',
'rancho' => 'Rancho', 'rancho'=> 'Rancho, sans-serif',
'roboto' => 'Roboto', 'roboto'=> 'Roboto, sans-serif',
'ubuntu' => 'Ubuntu', 'ubuntu'=> 'Ubuntu, sans-serif',
'vollkorn' => 'Vollkorn' 'vollkorn'=> 'Vollkorn, serif'
]; ];
$this->setData(['fonts', 'imported', $fonts]); $this->setData(['fonts', 'imported', $fonts]);

View File

@ -88,26 +88,26 @@ class init extends common {
'fonts' => [ 'fonts' => [
'files' => [], 'files' => [],
'imported'=> [ 'imported'=> [
'arimo'=> 'Arimo', 'arimo'=> 'Arimo, sans-serif',
'arvo'=> 'Arvo', 'arvo'=> 'Arvo, sans-serif',
'dancing-script' => 'Dancing Script', 'dancing-script' => '"Dancing Script", sans-serif',
'droid-sans-2'=> 'Droid Sans', 'droid-sans-2'=> '"Droid Sans", sans-serif',
'droid-serif-2'=> 'Droid Serif', 'droid-serif-2'=> '"Droid Serif", serif',
'indie-flower'=> 'Indie Flower', 'indie-flower'=> '"Indie Flower", sans-serif',
'liberation-sans'=> 'Liberation Sans', 'liberation-sans'=> '"Liberation Sans", sans-serif',
'liberation-serif'=> 'Liberation Serif', 'liberation-serif'=> '"Liberation Serif", serif',
'lobster-2'=> 'Lobster', 'lobster-2'=> 'Lobster, sans-serif',
'lora'=> 'Lora', 'lora'=> 'Lora, serif',
'lato'=> 'Lato', 'lato'=> 'Lato, sans-serif',
'old-standard-tt-3'=> 'Old Standard TT', 'old-standard-tt-3'=> '"Old Standard TT", serif',
'open-sans'=> 'Open Sans', 'open-sans'=> '"Open Sans", sans-serif',
'oswald-4'=> 'Oswald', 'oswald-4'=> 'Oswald, sans-serif',
'pt-mono'=> 'PT Mono', 'pt-mono'=> '"PT Mono", monospace',
'pt-serif'=> 'PT Serif', 'pt-serif'=> '"PT Serif", serif',
'rancho'=> 'Rancho', 'rancho'=> 'Rancho, sans-serif',
'roboto'=> 'Roboto', 'roboto'=> 'Roboto, sans-serif',
'ubuntu'=> 'Ubuntu', 'ubuntu'=> 'Ubuntu, sans-serif',
'vollkorn'=> 'Vollkorn' 'vollkorn'=> 'Vollkorn, serif'
] ]
], ],
'page' => [ 'page' => [