From 82b3c27b8b064e3a0499c2181c4cfd97c94695d4 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Fri, 18 Mar 2022 16:12:30 +0100 Subject: [PATCH] bug de fontes --- core/core.js.php | 4 +- core/core.php | 11 ++++-- core/module/theme/theme.php | 76 +++++++++++++++---------------------- 3 files changed, 40 insertions(+), 51 deletions(-) diff --git a/core/core.js.php b/core/core.js.php index afceb326..118c66a6 100644 --- a/core/core.js.php +++ b/core/core.js.php @@ -216,7 +216,7 @@ core.start = function() { var getUrl = window.location; var domain = "domain=" + getUrl.host + ";"; var path = "path=" + getUrl.pathname.split('/')[1] + ";"; - + var e = new Date(); e.setFullYear(e.getFullYear() + 1); var expires = "expires=" + e.toUTCString(); @@ -225,7 +225,7 @@ core.start = function() { var analytics = "getData(['config', 'seo', 'analyticsId']);?>"; // l'Id GA est défini dans la configuration, afficher la checkbox d'acceptation if( analytics.length > 0){ - // Traitement du retour de la checkbox + // Traitement du retour de la checkbox if ($("#googleAnalytics").is(":checked")) { // L'URL du serveur faut TRUE diff --git a/core/core.php b/core/core.php index b74c16ae..dcf8e092 100644 --- a/core/core.php +++ b/core/core.php @@ -410,7 +410,7 @@ class common { /** * Construit la liste des fontes dans un tableau * @return array @fonts - * + * */ public function getFonts() { @@ -2374,16 +2374,19 @@ class core extends common { */ foreach ($fonts as $fontId) { // Validité du tableau : - if ( isset($fontsAvailable['files'][$fontId]) && - file_exists(self::DATA_DIR . 'fonts/' . $f) ) { + if ( isset($fontsAvailable['files'][$fontId]) ) { + if (file_exists(self::DATA_DIR . 'fonts/' . $fontId) ) { // 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/' .$fontsAvailable['files'][$fontId]['resource'] . '");}'; // Tableau pour la construction de la feuille de style $fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family']; + } else { + // Le fichier de font n'est pas disponible, fonte par défaut + $fonts [$fontId] = 'verdana'; + } } - } // Fond du body diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index d47f7fe3..2db6ba31 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -621,37 +621,31 @@ class theme extends common { if ($this->isPost()) { // Type d'import en ligne ou local $type = $this->getInput('fontAddFontImported', helper::FILTER_BOOLEAN) ? 'imported' : 'files'; - $ressource = $type === 'imported' ? $this->getInput('fontAddUrl', helper::FILTER_STRING_SHORT) : $this->getInput('fontAddFile', helper::FILTER__SHORT_STRING); + $typeFlip = $type === 'files' ? 'imported' : 'files'; + $ressource = $type === 'imported' ? $this->getInput('fontAddUrl', helper::FILTER_STRING_SHORT) : $this->getInput('fontAddFile', helper::FILTER_STRING_SHORT); $fontId = $this->getInput('fontAddFontId', helper::FILTER_STRING_SHORT, true); $fontName = $this->getInput('fontAddFontName', helper::FILTER_STRING_SHORT, true); $fontFamilyName = $this->getInput('fontAddFontFamilyName', helper::FILTER_STRING_SHORT, true); - // Vérifier l'existence de fontId et validité de family name si usage en ligne de cdnFonts + // Supprime la fonte si elle existe dans le type inverse + if (is_array($this->getData(['fonts', $typeFlip, $fontId])) ) { + $this->deleteData(['fonts', $typeFlip, $fontId ]); + } + // Stocker la fonte + $this->setData(['fonts', + $type, + $fontId, [ + 'name' => $fontName, + 'font-family' => $fontFamilyName, + 'resource' => $ressource + ]]); - // Charger les données des fontes - $fonts = $this->getData(['fonts']); - - // Concaténation dans les tableaux existants - $t = [ $fontId => [ - 'name' => $fontName, - 'font-family' => $fontFamilyName, - 'resource' => $ressource - ]]; - - // Stocker les fontes - $this->setData(['fonts', $type, [ $fontId => - [ - 'name' => $fontName, - 'font-family' => $fontFamilyName, - 'resource' => $ressource - ]] - ]); // Copier la fonte si le nom du fichier est fourni if ( $type === 'files' && - is_file(self::FILE_DIR . 'source/' . $ressource) + file_exists(self::FILE_DIR . 'source/' . $ressource) ) { - copy ( self::FILE_DIR . 'source/' . $ressource, self::DATA_DIR . 'fonts/' . $ressource ); + copy ( self::FILE_DIR . 'source/' . $ressource, self::DATA_DIR . $ressource ); } // Valeurs en sortie @@ -677,37 +671,29 @@ class theme extends common { if ($this->isPost()) { // Type d'import en ligne ou local $type = $this->getInput('fontEditFontImported', helper::FILTER_BOOLEAN) ? 'imported' : 'files'; - $ressource = $type === 'imported' ? $this->getInput('fontEditUrl', helper::FILTER_STRING_SHORT) : $this->getInput('fontEditFile', helper::FILTER__SHORT_STRING); + $typeFlip = $type === 'files' ? 'imported' : 'files'; + $ressource = $type === 'imported' ? $this->getInput('fontEditUrl', helper::FILTER_STRING_SHORT) : $this->getInput('fontEditFile', helper::FILTER_STRING_SHORT); $fontId = $this->getInput('fontEditFontId', helper::FILTER_STRING_SHORT, true); $fontName = $this->getInput('fontEditFontName', helper::FILTER_STRING_SHORT, true); $fontFamilyName = $this->getInput('fontEditFontFamilyName', helper::FILTER_STRING_SHORT, true); - // Vérifier l'existence de fontId et validité de family name si usage en ligne de cdnFonts - - // Charger les données des fontes - $fonts = $this->getData(['fonts']); - - // Concaténation dans les tableaux existants - $t = [ $fontId => [ - 'name' => $fontName, - 'font-family' => $fontFamilyName, - 'resource' => $ressource - ]]; - + // Supprime la fonte si elle existe dans le type inverse + if (is_array($this->getData(['fonts', $typeFlip, $fontId])) ) { + $this->deleteData(['fonts', $typeFlip, $fontId ]); + } // Stocker les fontes - $this->setData(['fonts', $type, [ $fontId => - [ - 'name' => $fontName, - 'font-family' => $fontFamilyName, - 'resource' => $ressource - ]] - ]); - + $this->setData(['fonts', + $type, + $fontId, [ + 'name' => $fontName, + 'font-family' => $fontFamilyName, + 'resource' => $ressource + ]]); // Copier la fonte si le nom du fichier est fourni if ( $type === 'files' && - is_file(self::FILE_DIR . 'source/' . $ressource) + file_exists(self::FILE_DIR . 'source/' . $ressource) ) { - copy ( self::FILE_DIR . 'source/' . $ressource, self::DATA_DIR . 'fonts/' . $ressource ); + copy ( self::FILE_DIR . 'source/' . $ressource, self::DATA_DIR . $ressource ); } // Valeurs en sortie