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
];
}
// 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 .= '<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
$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 .= '<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
$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'];
}

View File

@ -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]);

View File

@ -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' => [

View File

@ -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([