diff --git a/core/core.php b/core/core.php index 5eb63537..aed8d23d 100644 --- a/core/core.php +++ b/core/core.php @@ -422,16 +422,15 @@ class common { 'font-family'=> $fontValue ]; } - // Ajoute les polices importées chez cdnfonts + // Ajoute les polices importées $fontsImported = $this->getData(['fonts', 'imported']); if (is_array($fontsImported) ) { foreach ($fontsImported as $fontId => $fontValue) { - $fontName = explode (',', $fontValue); $f ['imported'] [$fontId] = [ - 'name' => str_replace('"', '', $fontName[0]), - 'font-family'=> $fontValue - //'ressource' + 'name' => $fontValue ['name'], + 'font-family'=> $fontValue ['font-family'], + 'url' => $fontValue ['url'] ]; } } @@ -441,9 +440,9 @@ class common { ) { foreach ($fontsFiles as $fontId => $fontValue) { $f ['files'] [$fontId] = [ + 'name' => $fontValue ['name'], 'font-family'=> $fontValue ['font-family'], - 'ressource'=> $fontValue ['ressource'], - 'name' => ucfirst($fontId) // A créer + 'file' => $fontValue ['file'] ]; } } @@ -2362,7 +2361,7 @@ class core extends common { $fontFile = ''; foreach ($fonts as $fontId) { if ( isset($fontsAvailable['imported'][$fontId])) { - $fontFile .= ''; + $fontFile .= ''; // Tableau pour la construction de la feuille de style $fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family']; } @@ -2380,7 +2379,7 @@ class core extends common { // 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 . '");}'; + $css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' .$fontsAvailable['files'][$fontId]['file'] . '");}'; // Tableau pour la construction de la feuille de style $fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family']; } @@ -2596,7 +2595,7 @@ class core extends common { $fontFile = ''; foreach ($fonts as $fontId) { if ( isset($fontsAvailable['imported'][$fontId])) { - $fontFile .= ''; + $fontFile .= ''; // Tableau pour la construction de la feuille de style $fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family']; } @@ -2614,7 +2613,7 @@ class core extends common { // 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 . '");}'; + $css .= 'src: url("' . helper::baseUrl(false) . self::DATA_DIR . 'fonts/' .$fontsAvailable['files'][$fontId]['file'] . '");}'; // Tableau pour la construction de la feuille de style $fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family']; } diff --git a/core/include/update.inc.php b/core/include/update.inc.php index 3dcf1306..021cf19a 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -813,26 +813,106 @@ if ($this->getData(['core', 'dataVersion']) < 11303) { if ($this->getData(['core', 'dataVersion']) < 11400) { $fonts = [ - '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' + 'arimo'=> [ + 'name' => 'Arimo', + 'font-family' => 'Arimo, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/arimo' + ], + 'arvo'=> [ + 'name' => 'Arvo', + 'font-family' => 'Arvo, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/arvo' + ], + 'dancing-script' => [ + 'name' => 'Dancing Script', + 'font-family' => '"Dancing Script", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/dancing-script' + ], + 'droid-sans-2'=> [ + 'name' => 'Droid Sans', + 'font-family' => '"Droid Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/droid-sans-2' + ], + 'droid-serif-2'=> [ + 'name' => 'Droid Serif', + 'font-family' => '"Droid Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/droid-serif-2' + ], + 'indie-flower'=> [ + 'name' => 'Indie Flower', + 'font-family' => '"Indie Flower", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/indie-flower' + ], + 'liberation-sans'=> [ + 'name' => 'Liberation Sans', + 'font-family' => '"Liberation Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/liberation-sans' + ], + 'liberation-serif'=> [ + 'name' => 'Liberation Serif', + 'font-family' => '"Liberation Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/liberation-serif' + ], + 'lobster-2'=> [ + 'name' => 'Lobster', + 'font-family' => 'Lobster, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/lobster-2' + ], + 'lato'=> [ + 'name' => 'lato', + 'font-family' => 'Lato, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/lato' + ], + 'lora'=> [ + 'name' => 'Lora', + 'font-family' => 'Lora, serif', + 'url' => 'https://fonts.cdnfonts.com/css/lora' + ], + 'old-standard-tt-3'=> [ + 'name' => 'Old Standard TT', + 'font-family' => '"Old Standard TT", serif', + 'url' => 'https://fonts.cdnfonts.com/css/old-standard-tt-3' + ], + 'open-sans' => [ + 'name' => 'Open Sans', + 'font-family' => '"Open Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/open-sans' + ], + 'oswald-4'=> [ + 'name' => 'Oswald', + 'font-family' => 'Oswald, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/oswald-4' + ], + 'pt-mono'=> [ + 'name' => 'PT Mono', + 'font-family' => '"PT Mono", monospace', + 'url' => 'https://fonts.cdnfonts.com/css/pt-mono' + ], + 'pt-serif'=> [ + 'name' => "PR Serif", + 'font-family' => '"PT Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/pt-serif' + ], + 'rancho'=> [ + 'name' => 'Rancho', + 'font-family' => 'Rancho, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/rancho' + ], + 'roboto'=> [ + 'name' => 'Roboto', + 'font-family' => 'Roboto, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/roboto' + ], + 'ubuntu'=> [ + 'name' => 'Ubuntu', + 'font-family' => 'Ubuntu, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/ubuntu' + ], + 'vollkorn'=> [ + 'name' => 'Vollkorn', + 'font-family' => 'Vollkorn, serif', + 'url' => 'https://fonts.cdnfonts.com/css/vollkorn' + ] ]; $this->setData(['fonts', 'imported', $fonts]); diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index ee0d0dd8..21b5d70e 100644 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -88,26 +88,106 @@ class init extends common { 'fonts' => [ 'files' => [], 'imported'=> [ - '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' + 'arimo'=> [ + 'name' => 'Arimo', + 'font-family' => 'Arimo, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/arimo' + ], + 'arvo'=> [ + 'name' => 'Arvo', + 'font-family' => 'Arvo, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/arvo' + ], + 'dancing-script' => [ + 'name' => 'Dancing Script', + 'font-family' => '"Dancing Script", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/dancing-script' + ], + 'droid-sans-2'=> [ + 'name' => 'Droid Sans', + 'font-family' => '"Droid Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/droid-sans-2' + ], + 'droid-serif-2'=> [ + 'name' => 'Droid Serif', + 'font-family' => '"Droid Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/droid-serif-2' + ], + 'indie-flower'=> [ + 'name' => 'Indie Flower', + 'font-family' => '"Indie Flower", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/indie-flower' + ], + 'liberation-sans'=> [ + 'name' => 'Liberation Sans', + 'font-family' => '"Liberation Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/liberation-sans' + ], + 'liberation-serif'=> [ + 'name' => 'Liberation Serif', + 'font-family' => '"Liberation Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/liberation-serif' + ], + 'lobster-2'=> [ + 'name' => 'Lobster', + 'font-family' => 'Lobster, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/lobster-2' + ], + 'lato'=> [ + 'name' => 'lato', + 'font-family' => 'Lato, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/lato' + ], + 'lora'=> [ + 'name' => 'Lora', + 'font-family' => 'Lora, serif', + 'url' => 'https://fonts.cdnfonts.com/css/lora' + ], + 'old-standard-tt-3'=> [ + 'name' => 'Old Standard TT', + 'font-family' => '"Old Standard TT", serif', + 'url' => 'https://fonts.cdnfonts.com/css/old-standard-tt-3' + ], + 'open-sans' => [ + 'name' => 'Open Sans', + 'font-family' => '"Open Sans", sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/open-sans' + ], + 'oswald-4'=> [ + 'name' => 'Oswald', + 'font-family' => 'Oswald, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/oswald-4' + ], + 'pt-mono'=> [ + 'name' => 'PT Mono', + 'font-family' => '"PT Mono", monospace', + 'url' => 'https://fonts.cdnfonts.com/css/pt-mono' + ], + 'pt-serif'=> [ + 'name' => "PR Serif", + 'font-family' => '"PT Serif", serif', + 'url' => 'https://fonts.cdnfonts.com/css/pt-serif' + ], + 'rancho'=> [ + 'name' => 'Rancho', + 'font-family' => 'Rancho, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/rancho' + ], + 'roboto'=> [ + 'name' => 'Roboto', + 'font-family' => 'Roboto, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/roboto' + ], + 'ubuntu'=> [ + 'name' => 'Ubuntu', + 'font-family' => 'Ubuntu, sans-serif', + 'url' => 'https://fonts.cdnfonts.com/css/ubuntu' + ], + 'vollkorn'=> [ + 'name' => 'Vollkorn', + 'font-family' => 'Vollkorn, serif', + 'url' => 'https://fonts.cdnfonts.com/css/vollkorn' + ] ] ], 'page' => [ diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index ce1ae845..83aa2ea8 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -616,56 +616,44 @@ class theme extends common { public function fontAdd() { // Soumission du formulaire if ($this->isPost()) { - + // Type d'import en ligne ou local + $type = $this->getInput('fontAddFontImported', helper::FILTER_BOOLEAN) ? 'imported' : 'url'; + $ressource = $type === 'imported' ? $this->getInput('fontAddFile', helper::FILTER__SHORT_STRING) : $this->getInput('fontAddUrl', helper::FILTER__SHORT_STRING); $fontId = $this->getInput('fontAddFontId', null, true); $fontName = $this->getInput('fontAddFontName', null, true); - $filePath = $this->getInput('fontAddFile', null); - $e = explode ('/', $filePath); - $file = $e[count($e) - 1 ]; + $fontFamilyName = $this->getInput('fontAddFontFamilyName', null, true); - // Vérifier l'existence de fontId et validité de family namesi usage en ligne de cdnFonts - $data = helper::getUrlContents('https://www.cdnfonts.com/' . $fontId . '.font'); + // Vérifier l'existence de fontId et validité de family name si usage en ligne de cdnFonts + /* + if ($type === 'url') { + $data = helper::getUrlContents($ressource); + }*/ - if ( $filePath === '' - && $fontName !== '' - && strpos($data, $fontName) === false - ) { + // Charger les données des fontes + $files = $this->getData(['fonts', 'files']); + $imported = $this->getData(['fonts', 'imported']); - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Erreur de nom de fonte ou d\'identifiant', - 'redirect' => helper::baseUrl() . 'theme/fontAdd', - 'state' => false - ]); + // Concaténation dans les tableaux existants + $imported = array_merge([$fontId => $fontName], $imported); + $files = array_merge([$fontId => $file], $files); - } else { - - // Charger les données des fontes - $files = $this->getData(['fonts', 'files']); - $imported = $this->getData(['fonts', 'imported']); - - // Concaténation dans les tableaux existants - $imported = array_merge([$fontId => $fontName], $imported); - $files = array_merge([$fontId => $file], $files); - - // Copier la fonte si le nom du fichier est fourni - if (!empty($filePath)) { - copy ( self::FILE_DIR . 'source/' . $filePath, self::DATA_DIR . 'fonts/' . $file ); - } - - // Mettre à jour le fichier des fontes - $this->setData(['fonts', 'imported', $imported ]); - if (!empty($filePath) ) { - $this->setData(['fonts', 'files', $files ]); - } - - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'La fonte a été importée', - 'redirect' => helper::baseUrl() . 'theme/fonts', - 'state' => true - ]); + // Copier la fonte si le nom du fichier est fourni + if (!empty($filePath)) { + copy ( self::FILE_DIR . 'source/' . $filePath, self::DATA_DIR . 'fonts/' . $file ); } + + // Mettre à jour le fichier des fontes + $this->setData(['fonts', 'imported', $imported ]); + if (!empty($filePath) ) { + $this->setData(['fonts', 'files', $files ]); + } + + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'La fonte a été importée', + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => true + ]); } // Valeurs en sortie $this->addOutput([