From f0201145888b4ada87d6fcb1067f8568119ebca7 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Fri, 11 Feb 2022 11:50:28 +0100 Subject: [PATCH] Bug import par cdnfonts --- core/core.php | 187 +++++++++++++----------------------------- core/layout/blank.php | 1 - core/layout/light.php | 1 - core/layout/main.php | 1 - 4 files changed, 59 insertions(+), 131 deletions(-) diff --git a/core/core.php b/core/core.php index 0c96d4b7..a044462c 100644 --- a/core/core.php +++ b/core/core.php @@ -1929,63 +1929,6 @@ class common { echo ''; } - /** - * Fontes de caractère à importer depuis cdn fonts - * - */ - public function showFonts() { - $cdnFonts = [ - $this->getData(['theme', 'text', 'font']), - $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']), - - ]; - // Suppression des polices identiques - $cdnFonts = array_unique($cdnFonts); - - // Lire le fichier et check l'existence des fichiers locaux - $localFonts = $this->getData(['fonts', 'files']); - - // Validité du format - if ( is_array($localFonts) && - !empty($localFonts) - ) { - // Validité du format - if (is_array($localFonts) ) { - foreach ($localFonts as $fontId => $fontName) { - // Validité du tableau : - // L'id de la police est présent dans la liste interne - // Le nom de la police fournie correspond à un fichier existant - if ( array_key_exists($fontId, self::$fonts) && - file_exists(self::DATA_DIR . 'fonts/' . $fontName) - ) { - // La police locale est-elle invoquée oou téléchargée ? - $d = array_search($fontId, $cdnFonts); - if ( $d !== false ) { - // Supprimer l'élément des fontes chargées en ligne - unset($cdnFonts[$d]); - } - } - } - } - } - // Chargement des polices en ligne - $css = ''; - if ($cdnFonts) { - foreach ($cdnFonts as $fontId) { - //$css .= '@import url("http://fonts.cdnfonts.com/css/' . $fontId . '");'; - $css .= ''; - } - echo $css; - } - } - - - /** * Affiche la notification */ @@ -2339,53 +2282,46 @@ class core extends common { * Import des polices de caractères * A partir du CDN ou dans le dossier site/file/source/fonts */ - $cdnFonts = [ $this->getData(['theme', 'text', 'font']), + $fonts = [ $this->getData(['theme', 'text', 'font']), $this->getData(['theme', 'title', 'font']), $this->getData(['theme', 'header', 'font']), $this->getData(['theme', 'menu', 'font']), $this->getData(['theme', 'footer', 'font']) ]; // Suppression des polices identiques - $cdnFonts = array_unique($cdnFonts); - - // Lire le fichier et check l'existence des fichiers locaux + $fonts = array_unique($fonts); + // Lire le fichier des fontes locales $localFonts = $this->getData(['fonts', 'files']); - // Validité du format - if ( is_array($localFonts) && - !empty($localFonts) - ) { - // Validité du format - if (is_array($localFonts) ) { - foreach ($localFonts as $fontId => $fontName) { - // Validité du tableau : - // L'id de la police est présent dans la liste interne - // Le nom de la police fournie correspond à un fichier existant - if ( array_key_exists($fontId, self::$fonts) && - file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) { - // La police locale est-elle invoquée ? - $d = array_search($fontId, $cdnFonts); - if ( $d !== false ) { - // Chargement de la police demandée dans le thème - //$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 . '");}'; - // Supprimer l'élément des fontes chargées en ligne - unset($cdnFonts[$d]); - } - } - - } + /** + * Chargement des polices en ligne + */ + foreach ($fonts as $fontId) { + if (!array_key_exists($fontId, $localFonts) ) { + $css .= '@import url("http://fonts.cdnfonts.com/css/' . $fontId . '");'; + // Supprimer l'élément des fontes chargées en ligne + unset($fonts[$fontId]); } } - /* - // Chargement des polices en ligne - /* Désormais dans main.php avec showFonts - if ($cdnFonts) { - foreach ($cdnFonts as $fontId) { - $css .= '@import url("http://fonts.cdnfonts.com/css/' . $fontId . '");'; + + /** + * 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 . '");}'; + } + } - }*/ + } // Fond du body $colors = helper::colorVariants($this->getData(['theme', 'body', 'backgroundColor'])); @@ -2575,50 +2511,45 @@ class core extends common { * Import des polices de caractères * A partir du CDN ou dans le dossier site/file/source/fonts */ - $cdnFonts = [ $this->getData(['admin', 'fontText']), + $fonts = [ $this->getData(['admin', 'fontText']), $this->getData(['admin', 'fontTitle']), ]; // Suppression des polices identiques - $cdnFonts = array_unique($cdnFonts); - // Lire le fichier et check l'existence des fichiers locaux + $fonts = array_unique($fonts); + // Lire le fichier des fontes locales $localFonts = $this->getData(['fonts', 'files']); - // Validité du format - if ( is_array($localFonts) && - !empty($localFonts) - ) { - // Validité du format - if (is_array($localFonts) ) { - foreach ($localFonts as $fontId => $fontName) { - // Validité du tableau : - // L'id de la police est présent dans la liste interne - // Le nom de la police fournie correspond à un fichier existant - if ( array_key_exists($fontId, self::$fonts) && - file_exists(self::DATA_DIR . 'fonts/' . $fontName) ) { - // La police locale est-elle invoquée ? - $d = array_search($fontId, $cdnFonts); - if ( $d !== false ) { - // Chargement de la police demandée dans le thème - //$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 . '");}'; - // Supprimer l'élément des fontes chargées en ligne - unset($cdnFonts[$d]); - } - } - - } + /** + * Chargement des polices en ligne + */ + foreach ($fonts as $fontId) { + if (!array_key_exists($fontId, $localFonts) ) { + $css .= '@import url("http://fonts.cdnfonts.com/css/' . $fontId . '");'; + // Supprimer l'élément des fontes chargées en ligne + unset($fonts[$fontId]); } } - // Chargement des polices en ligne - /* Désormais dans main.php avec showFonts - if ($cdnFonts) { - foreach ($cdnFonts as $fontId) { - $css .= '@import url("http://fonts.cdnfonts.com/css/' . $fontId . '");'; - } - }*/ + /** + * 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 . '");}'; + } + } + } + + // 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;}'; diff --git a/core/layout/blank.php b/core/layout/blank.php index 0146631d..789b1af6 100644 --- a/core/layout/blank.php +++ b/core/layout/blank.php @@ -14,7 +14,6 @@ - showFonts(); ?> showContent(); ?> showScript(); ?> diff --git a/core/layout/light.php b/core/layout/light.php index 403a3a7c..833cb19d 100644 --- a/core/layout/light.php +++ b/core/layout/light.php @@ -14,7 +14,6 @@ - showFonts(); ?> showNotification(); ?> diff --git a/core/layout/main.php b/core/layout/main.php index b72ad402..7cb5ab98 100644 --- a/core/layout/main.php +++ b/core/layout/main.php @@ -13,7 +13,6 @@ - showFonts(); ?> getData(['page', $this->getUrl(0), 'moduleId']) === 'blog' OR $this->getData(['page', $this->getUrl(0), 'moduleId']) === 'news' )