Browse Source

Gestion des fontes des feuilles de style ok

12_dev
fredtempez 4 months ago
parent
commit
9dc533d7a9
  1. 120
      core/core.php
  2. 40
      core/include/update.inc.php
  3. 40
      core/module/install/ressource/defaultdata.php

120
core/core.php

@ -413,21 +413,17 @@ class common {
/**
* Construit la liste des fontes dans un tableau
* @return @fonts
* fontid
* 'familyName' =>
* 'type=> websafe ou imported ou file
* 'ressource' => stack ou file
* @return array @fonts
*
*/
public function getFonts() {
// Fusionne la liste des fontes avec les webSafe
foreach (self::$fontsWebSafe as $fontId => $fontValue) {
$fontName = explode (',', $fontValue);
$f[$fontId] = [
'fontfamily'=> $fontName[0],
'ressource' => $fontValue,
'type' => 'websafe'
$f ['websafe'] [$fontId] = [
'name' => $fontName[0],
'font-family'=> $fontValue
];
}
// Ajoute les polices importées chez cdnfonts
@ -435,10 +431,11 @@ class common {
if (is_array($fontsImported)
) {
foreach ($fontsImported as $fontId => $fontValue) {
$f[$fontId] = [
'fontfamily'=> $fontValue,
'ressource' => $fontValue . "; sans-serif", // Format par défaut
'type' => 'imported'
$fontName = explode (',', $fontValue);
$f ['imported'] [$fontId] = [
'name' => $fontName[0],
'font-family'=> $fontValue
//'ressource'
];
}
}
@ -447,15 +444,12 @@ class common {
if (is_array($fontsFiles)
) {
foreach ($fontsFiles as $fontId => $fontValue) {
$f[$fontId] = [
// la fonte family est reprise de files
'ressource' => $fontValue,
'type' => 'files'
$f ['files'] [$fontId] = [
'font-family'=> $fontValue ['font-family'],
'ressource'=> $fontValue ['ressource']
];
}
}
// Tri Alphabétique
ksort($f);
return $f;
}
@ -2355,14 +2349,25 @@ class core extends common {
// Suppression des polices identiques
$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
*/
$fontFile = '';
foreach ($fonts as $fontId) {
if ( isset($fontsAvailable[$fontId]) &&
$fontsAvailable[$fontId]['type'] === 'imported' ) {
if ( isset($fontsAvailable['imported'][$fontId])) {
$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
@ -2373,12 +2378,14 @@ class core extends common {
*/
foreach ($fonts as $fontId) {
// Validité du tableau :
if ( array_key_exists($fontId, self::$fonts) &&
file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) {
if ( isset($fontsAvailable['files'][$fontId]) &&
file_exists(self::DATA_DIR . 'fonts/' . $f) ) {
// Chargement de la police
//$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 . '");}';
// 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
$colors = helper::colorVariants($this->getData(['theme', 'body', 'backgroundColor']));
// 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'])) {
// 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']) . '}';
@ -2404,7 +2411,7 @@ class core extends common {
$colors = helper::colorVariants($this->getData(['theme', 'text', 'linkColor']));
$css .= 'a{color:' . $colors['normal'] . '}';
// 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
$css .= '.editorWysiwyg {background-color:' . $this->getData(['theme', 'site', 'backgroundColor']) . ';}';
$css .= 'span.mce-text{background-color: unset !important;}';
@ -2445,7 +2452,7 @@ class core extends common {
$css .= '.helpButton span:hover{color:' . $colors['darken'] . '}';
$css .= '.button:active,button[type=\'submit\']:active,.pagination a:active{background-color:' . $colors['veryDarken'] . '}';
$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'] . '}';
// Les blocs
$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']) . '}';
}
$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é
@ -2528,7 +2535,7 @@ class core extends common {
$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
$colors = helper::colorVariants($this->getData(['theme', 'footer', 'backgroundColor']));
@ -2538,7 +2545,7 @@ class core extends common {
$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 a{color:' . $this->getData(['theme', 'footer', 'textColor']) . '}';
$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 .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}';
// Enregistre la personnalisation
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
header("Expires: Tue, 01 Jan 2000 00:00:00 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);
/**
* Fontes Web Safe, ne sont pas chargées.
* Charge les fontes websafe
*/
$fontFile = '';
foreach ($fonts as $fontId) {
if (array_key_exists($fontId, self::$fontsWebSafe) ) {
unset($fonts[$fontId]);
if ( isset($fontsAvailable['websafe'][$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) {
if (!array_key_exists($fontId, $localFonts) ) {
$css .= '@import url("https://fonts.cdnfonts.com/css/' . $fontId . '");';
// Supprimer l'élément des fontes chargées en ligne
unset($fonts[$fontId]);
if ( isset($fontsAvailable['imported'][$fontId])) {
$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
file_put_contents(self::DATA_DIR.'fonts/fonts.html', $fontFile);
/**
* Fontes installées localement
*/
// Validité du format
if ( !empty($localFonts)
) {
foreach ($localFonts as $fontId => $fontName) {
// Validité du tableau :
if ( array_key_exists($fontId, self::$fonts) &&
file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) {
// Chargement de la police
//$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName);
$css .= '@font-face {font-family:"' . self::$fonts[$fontId] . '";';
$css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' . $fontName . '");}';
}
foreach ($fonts as $fontId) {
// Validité du tableau :
if ( isset($fontsAvailable['files'][$fontId]) &&
file_exists(self::DATA_DIR . 'fonts/' . $f) ) {
// Chargement de la police
//$formatFont = explode('.', self::DATA_DIR . 'fonts/' . $fontName);
$css .= '@font-face {font-family:"' . $fontsAvailable['files'][$fontId]['font-family'] . '";';
$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'];
}
}
// Thème Administration
$colors = helper::colorVariants($this->getData(['admin','backgroundColor']));
$css .= '#site{background-color:' . $colors['normal']. ';}';
$css .= '.row > div {font:' . $this->getData(['admin','fontSize']) . ' "' . self::$fonts[$this->getData(['admin','fontText'])] . '", sans-serif;}';
$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 .= '.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'])] . ';color:' . $this->getData(['admin','colorTitle' ]) . ';}';
// TinyMCE
$css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this->getData(['admin','colorText']) . ';}';

40
core/include/update.inc.php

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

40
core/module/install/ressource/defaultdata.php

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

Loading…
Cancel
Save