From de202823d9b93ecba83f8694f5bc27d34474e87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tempez?= Date: Sun, 20 Mar 2022 19:21:02 +0100 Subject: [PATCH] =?UTF-8?q?bug=20double=20fontes=20=C3=A0=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/module/theme/theme.php | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index 1340d6de..9b624d66 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -603,13 +603,14 @@ class theme extends common { // Soumission du formulaire if ($this->isPost()) { - $fontId = $this->getInput('fontAddFontId', null, true); - $fontName = $this->getInput('fontAddFontName', null, true); - $filePath = $this->getInput('fontAddFile', null); + $fontId = $this->getInput('fontAddFontId', helper::FILTER_STRING_SHORT, true); + $fontName = $this->getInput('fontAddFontName',helper::FILTER_STRING_SHORT, true); + $filePath = $this->getInput('fontAddFile', helper::FILTER_STRING_SHORT); + $type = $this->getInput('fontAddFontImported', helper::FILTER_BOOLEAN) ? 'imported' : 'files'; $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 ( $filePath === '' @@ -626,23 +627,20 @@ class theme extends common { } 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 ]); + switch ($type) { + case 'imported': + $imported = $this->getData(['fonts', 'imported']); + $imported = array_merge([$fontId => $fontName], $imported); + $this->setData(['fonts', 'imported', $imported ]); + break; + case 'files': + $files = $this->getData(['fonts', 'files']); + $files = array_merge([$fontId => $file], $files); + $this->setData(['fonts', 'files', $files ]); + // Copier la fonte si le nom du fichier est fourni + copy ( self::FILE_DIR . 'source/' . $filePath, self::DATA_DIR . 'fonts/' . $file ); + break; } // Valeurs en sortie