Nouvelle structure de fontes ok

This commit is contained in:
fredtempez 2022-03-11 14:03:42 +01:00
parent cd6e6145f4
commit 2aadc1bbaa
4 changed files with 241 additions and 94 deletions

View File

@ -422,16 +422,15 @@ class common {
'font-family'=> $fontValue 'font-family'=> $fontValue
]; ];
} }
// Ajoute les polices importées chez cdnfonts // Ajoute les polices importées
$fontsImported = $this->getData(['fonts', 'imported']); $fontsImported = $this->getData(['fonts', 'imported']);
if (is_array($fontsImported) if (is_array($fontsImported)
) { ) {
foreach ($fontsImported as $fontId => $fontValue) { foreach ($fontsImported as $fontId => $fontValue) {
$fontName = explode (',', $fontValue);
$f ['imported'] [$fontId] = [ $f ['imported'] [$fontId] = [
'name' => str_replace('"', '', $fontName[0]), 'name' => $fontValue ['name'],
'font-family'=> $fontValue 'font-family'=> $fontValue ['font-family'],
//'ressource' 'url' => $fontValue ['url']
]; ];
} }
} }
@ -441,9 +440,9 @@ class common {
) { ) {
foreach ($fontsFiles as $fontId => $fontValue) { foreach ($fontsFiles as $fontId => $fontValue) {
$f ['files'] [$fontId] = [ $f ['files'] [$fontId] = [
'name' => $fontValue ['name'],
'font-family'=> $fontValue ['font-family'], 'font-family'=> $fontValue ['font-family'],
'ressource'=> $fontValue ['ressource'], 'file' => $fontValue ['file']
'name' => ucfirst($fontId) // A créer
]; ];
} }
} }
@ -2362,7 +2361,7 @@ class core extends common {
$fontFile = ''; $fontFile = '';
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
if ( isset($fontsAvailable['imported'][$fontId])) { if ( isset($fontsAvailable['imported'][$fontId])) {
$fontFile .= '<link href="https://fonts.cdnfonts.com/css/' . $fontId .'" rel="stylesheet">'; $fontFile .= '<link href="' . $fontsAvailable['imported'][$fontId]['url'] .'" rel="stylesheet">';
// Tableau pour la construction de la feuille de style // Tableau pour la construction de la feuille de style
$fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family']; $fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family'];
} }
@ -2380,7 +2379,7 @@ class core extends common {
// 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:"' . $fontsAvailable['files'][$fontId]['font-family'] . '";'; $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 // Tableau pour la construction de la feuille de style
$fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family']; $fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family'];
} }
@ -2596,7 +2595,7 @@ class core extends common {
$fontFile = ''; $fontFile = '';
foreach ($fonts as $fontId) { foreach ($fonts as $fontId) {
if ( isset($fontsAvailable['imported'][$fontId])) { if ( isset($fontsAvailable['imported'][$fontId])) {
$fontFile .= '<link href="https://fonts.cdnfonts.com/css/' . $fontId .'" rel="stylesheet">'; $fontFile .= '<link href="' . $fontsAvailable['imported'][$fontId]['url'] .'" rel="stylesheet">';
// Tableau pour la construction de la feuille de style // Tableau pour la construction de la feuille de style
$fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family']; $fonts [$fontId] = $fontsAvailable['imported'][$fontId]['font-family'];
} }
@ -2614,7 +2613,7 @@ class core extends common {
// 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:"' . $fontsAvailable['files'][$fontId]['font-family'] . '";'; $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 // Tableau pour la construction de la feuille de style
$fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family']; $fonts [$fontId] = $fontsAvailable['files'][$fontId]['font-family'];
} }

View File

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

View File

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

View File

@ -616,29 +616,18 @@ class theme extends common {
public function fontAdd() { public function fontAdd() {
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { 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); $fontId = $this->getInput('fontAddFontId', null, true);
$fontName = $this->getInput('fontAddFontName', null, true); $fontName = $this->getInput('fontAddFontName', null, true);
$filePath = $this->getInput('fontAddFile', null); $fontFamilyName = $this->getInput('fontAddFontFamilyName', null, true);
$e = explode ('/', $filePath);
$file = $e[count($e) - 1 ];
// Vérifier l'existence de fontId et validité de family namesi usage en ligne de cdnFonts // Vérifier l'existence de fontId et validité de family name si usage en ligne de cdnFonts
$data = helper::getUrlContents('https://www.cdnfonts.com/' . $fontId . '.font'); /*
if ($type === 'url') {
if ( $filePath === '' $data = helper::getUrlContents($ressource);
&& $fontName !== '' }*/
&& strpos($data, $fontName) === false
) {
// Valeurs en sortie
$this->addOutput([
'notification' => 'Erreur de nom de fonte ou d\'identifiant',
'redirect' => helper::baseUrl() . 'theme/fontAdd',
'state' => false
]);
} else {
// Charger les données des fontes // Charger les données des fontes
$files = $this->getData(['fonts', 'files']); $files = $this->getData(['fonts', 'files']);
@ -666,7 +655,6 @@ class theme extends common {
'state' => true 'state' => true
]); ]);
} }
}
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => 'Ajouter une fonte', 'title' => 'Ajouter une fonte',