From dbf1f18e34ea18e1bbad23dfa3c07442da1fee92 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Fri, 11 Mar 2022 16:09:43 +0100 Subject: [PATCH] =?UTF-8?q?font=20edit=20=C3=A0=20terminer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 12 +-- core/module/theme/theme.php | 69 +++++++++++++-- core/module/theme/view/fontEdit/fontEdit.css | 18 ++++ .../theme/view/fontEdit/fontEdit.js.php | 44 ++++++++++ core/module/theme/view/fontEdit/fontEdit.php | 83 +++++++++++++++++++ core/module/theme/view/fonts/fonts.php | 2 +- 6 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 core/module/theme/view/fontEdit/fontEdit.css create mode 100644 core/module/theme/view/fontEdit/fontEdit.js.php create mode 100644 core/module/theme/view/fontEdit/fontEdit.php diff --git a/core/core.php b/core/core.php index 35f49f42..db18c31c 100644 --- a/core/core.php +++ b/core/core.php @@ -185,16 +185,16 @@ class common { public static $fontsWebSafe = [ 'arial' => 'Arial, Helvetica, sans-serif;', - 'arial-black' => 'Arial Black, Gadget, sans-serif;', - 'courrier' => 'Courier, Liberation Mono, monospace;', - 'courrier-new' => 'Courier New, Courier, monospace', + 'arial-black' => '"Arial Black", Gadget, sans-serif;', + 'courrier' => 'Courier, "Liberation Mono", monospace;', + 'courrier-new' => '"Courier New", Courier, monospace', 'garamond' => 'Garamond, serif', 'georgia' => 'Georgia, serif;', 'impact' => 'Impact, Charcoal, sans-serif;', - 'lucida' => 'Lucida Sans Unicode, Lucida Grande, sans-serif', + 'lucida' => '"Lucida Sans Unicode", "Lucida Grande", sans-serif', 'tahoma' => 'Tahoma, Geneva, sans-serif;', - 'times-new-roman' => 'Times New Roman, Liberation Serif, serif;', - 'trebuchet' => 'Trebuchet MS, Arial, Helvetica, sans-serif;', + 'times-new-roman' => '"Times New Roman", "Liberation Serif", serif;', + 'trebuchet' => '"Trebuchet MS", Arial, Helvetica, sans-serif;', 'tahoma' => 'Tahoma, Geneva, sans-serif;', 'verdana' => 'Verdana, Geneva, sans-serif;', ]; diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index f14527f6..d2c3be20 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -32,6 +32,7 @@ class theme extends common { 'save' => self::GROUP_ADMIN, 'fonts' => self::GROUP_ADMIN, 'fontAdd' => self::GROUP_ADMIN, + 'fontEdit' => self::GROUP_ADMIN, 'fontDelete' => self::GROUP_ADMIN ]; public static $aligns = [ @@ -586,12 +587,14 @@ class theme extends common { '' . $f[$type][$fontId]['name'] . '' , $f[$type][$fontId]['font-family'], $fontUsed[$fontId], - //array_key_exists($fontId, $fonts['imported']) ? 'Importée' : '', - /*array_key_exists($fontId, $fonts['files']) ? - $fonts['files'][$fontId] : - (array_key_exists($fontId, self::$fontsWebSafe) ? 'WebSafe' : 'CDN Fonts'), - */ $type, + $type !== 'websafe' ? template::button('themeFontEdit' . $fontId, [ + 'class' => 'themeFontEdit', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/fontEdit/' . $fontId . '/' . $_SESSION['csrf'], + 'value' => template::ico('pencil'), + 'disabled' => !empty($fontUsed[$fontId]) + ]) + : '', $type !== 'websafe' ? template::button('themeFontDelete' . $fontId, [ 'class' => 'themeFontDelete buttonRed', 'href' => helper::baseUrl() . $this->getUrl(0) . '/fontDelete/' . $fontId . '/' . $_SESSION['csrf'], @@ -665,6 +668,62 @@ class theme extends common { ]); } + + /** + * Ajouter une fonte + */ + public function fontEdit() { + // Soumission du formulaire + if ($this->isPost()) { + // Type d'import en ligne ou local + $type = $this->getInput('fontAddFontImported', helper::FILTER_BOOLEAN) ? 'imported' : 'files'; + $ressource = $type === 'imported' ? $this->getInput('fontAddUrl', helper::FILTER_STRING_SHORT) : $this->getInput('fontAddFile', helper::FILTER__SHORT_STRING); + $fontId = $this->getInput('fontAddFontId', helper::FILTER_STRING_SHORT, true); + $fontName = $this->getInput('fontAddFontName', helper::FILTER_STRING_SHORT, true); + $fontFamilyName = $this->getInput('fontAddFontFamilyName', helper::FILTER_STRING_SHORT, true); + + // Vérifier l'existence de fontId et validité de family name si usage en ligne de cdnFonts + + // Charger les données des fontes + $fonts = $this->getData(['fonts']); + + // Concaténation dans les tableaux existants + $t = [ $fontId => [ + 'name' => $fontName, + 'font-family' => $fontFamilyName, + 'ressource' => $ressource + ]]; + + // Stocker les fontes + $this->setData(['fonts', $type, [ $fontId => + [ + 'name' => $fontName, + 'font-family' => $fontFamilyName, + 'ressource' => $ressource + ]] + ]); + + // Copier la fonte si le nom du fichier est fourni + if ( $type === 'files' && + is_file(self::FILE_DIR . 'source/' . $ressource) + ) { + copy ( self::FILE_DIR . 'source/' . $ressource, self::DATA_DIR . 'fonts/' . $ressource ); + } + + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'La fonte a été importée', + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => true + ]); + } + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Ajouter une fonte', + 'view' => 'fontAdd' + ]); + } + /** * Effacer une fonte */ diff --git a/core/module/theme/view/fontEdit/fontEdit.css b/core/module/theme/view/fontEdit/fontEdit.css new file mode 100644 index 00000000..52709ea6 --- /dev/null +++ b/core/module/theme/view/fontEdit/fontEdit.css @@ -0,0 +1,18 @@ +/** + * This file is part of Zwii. + * + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2022, Frédéric Tempez + * @license GNU General Public License, version 3 + * @link http://zwiicms.fr/ + */ + + +/** NE PAS EFFACER +* admin.css +*/ \ No newline at end of file diff --git a/core/module/theme/view/fontEdit/fontEdit.js.php b/core/module/theme/view/fontEdit/fontEdit.js.php new file mode 100644 index 00000000..e9105513 --- /dev/null +++ b/core/module/theme/view/fontEdit/fontEdit.js.php @@ -0,0 +1,44 @@ +/** + * This file is part of Zwii. + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2022, Frédéric Tempez + * @license GNU General Public License, version 3 + * @link http://zwiicms.fr/ + */ + + +/** + * Option par défaut du sélecteur de mode + */ + $(document).ready(function(){ + $('input[name=fontAddFontImported]').prop('checked', true); + $('input[name=fontAddFontUrl]').prop('checked', false); + $('#containerFontAddFile').hide(); +}); + + +/** + * Mode téléchargement en ligne de la fonte ou installation locale + */ +$("input[name=fontAddFontImported]").on("click", function() { + if( $('input[name=fontAddFontImported]').is(':checked') ){ + $('input[name=fontAddFontFile]').prop('checked', false); + } else { + $('input[name=fontAddFontFile]').prop('checked', true); + } + $('#containerFontAddFile').hide(); + $('#containerFontAddUrl').show(); +}); + +$("input[name=fontAddFontFile]").on("click", function() { + if( $('input[name=fontAddFontFile]').is(':checked') ){ + $('input[name=fontAddFontImported]').prop('checked', false); + } else { + $('input[name=fontAddFontImported]').prop('checked', true); + } + $('#containerFontAddFile').show(); + $('#containerFontAddUrl').hide(); +}); diff --git a/core/module/theme/view/fontEdit/fontEdit.php b/core/module/theme/view/fontEdit/fontEdit.php new file mode 100644 index 00000000..ebe3daf9 --- /dev/null +++ b/core/module/theme/view/fontEdit/fontEdit.php @@ -0,0 +1,83 @@ + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'theme/fonts', + 'ico' => 'left', + 'value' => 'Retour' + ]); ?> +
+
+ 'https://doc.zwiicms.fr/fontes#add', + 'target' => '_blank', + 'ico' => 'help', + 'value' => 'Aide', + 'class' => 'buttonHelp' + ]); ?> +
+
+ 'Valider', + 'uniqueSubmission' => true + ]); ?> +
+
+
+
+
+

Identité de la fonte

+
+
+ +
+
+ +
+
+
+
+ 'off', + 'label' => 'Identifiant (sans espace ni majuscule)', + 'placeholder' => 'big-marker-extrude' + + ]); ?> +
+
+ 'off', + 'label' => 'Nom', + 'placeholder' => 'Big Marker Extrude' + ]); ?> +
+
+
+
+ 'off', + 'label' => 'Famille', + 'placeholder' => "'Big Marker Extrude', sans-serif" + ]); ?> +
+
+
+
+ 'Fichier de fonte (Format WOFF)' + ]); ?> +
+
+
+
+ 'Url du fichier de fonte', + 'placeholder' => 'https://fonts.cdnfonts.com/css/big-marker-extrude' + ]); ?> +
+
+
+
+
+ \ No newline at end of file diff --git a/core/module/theme/view/fonts/fonts.php b/core/module/theme/view/fonts/fonts.php index 000601a9..87c28836 100644 --- a/core/module/theme/view/fonts/fonts.php +++ b/core/module/theme/view/fonts/fonts.php @@ -25,7 +25,7 @@ - + \ No newline at end of file