font edit à terminer

This commit is contained in:
fredtempez 2022-03-11 16:09:43 +01:00
parent c6e1ef2aeb
commit dbf1f18e34
6 changed files with 216 additions and 12 deletions

View File

@ -185,16 +185,16 @@ class common {
public static $fontsWebSafe = [ public static $fontsWebSafe = [
'arial' => 'Arial, Helvetica, sans-serif;', 'arial' => 'Arial, Helvetica, sans-serif;',
'arial-black' => 'Arial Black, Gadget, sans-serif;', 'arial-black' => '"Arial Black", Gadget, sans-serif;',
'courrier' => 'Courier, Liberation Mono, monospace;', 'courrier' => 'Courier, "Liberation Mono", monospace;',
'courrier-new' => 'Courier New, Courier, monospace', 'courrier-new' => '"Courier New", Courier, monospace',
'garamond' => 'Garamond, serif', 'garamond' => 'Garamond, serif',
'georgia' => 'Georgia, serif;', 'georgia' => 'Georgia, serif;',
'impact' => 'Impact, Charcoal, sans-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;', 'tahoma' => 'Tahoma, Geneva, sans-serif;',
'times-new-roman' => 'Times New Roman, Liberation Serif, serif;', 'times-new-roman' => '"Times New Roman", "Liberation Serif", serif;',
'trebuchet' => 'Trebuchet MS, Arial, Helvetica, sans-serif;', 'trebuchet' => '"Trebuchet MS", Arial, Helvetica, sans-serif;',
'tahoma' => 'Tahoma, Geneva, sans-serif;', 'tahoma' => 'Tahoma, Geneva, sans-serif;',
'verdana' => 'Verdana, Geneva, sans-serif;', 'verdana' => 'Verdana, Geneva, sans-serif;',
]; ];

View File

@ -32,6 +32,7 @@ class theme extends common {
'save' => self::GROUP_ADMIN, 'save' => self::GROUP_ADMIN,
'fonts' => self::GROUP_ADMIN, 'fonts' => self::GROUP_ADMIN,
'fontAdd' => self::GROUP_ADMIN, 'fontAdd' => self::GROUP_ADMIN,
'fontEdit' => self::GROUP_ADMIN,
'fontDelete' => self::GROUP_ADMIN 'fontDelete' => self::GROUP_ADMIN
]; ];
public static $aligns = [ public static $aligns = [
@ -586,12 +587,14 @@ class theme extends common {
'<span style="font-family:' . $f[$type][$fontId]['font-family'] . '">' . $f[$type][$fontId]['name'] . '</span>' , '<span style="font-family:' . $f[$type][$fontId]['font-family'] . '">' . $f[$type][$fontId]['name'] . '</span>' ,
$f[$type][$fontId]['font-family'], $f[$type][$fontId]['font-family'],
$fontUsed[$fontId], $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,
$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, [ $type !== 'websafe' ? template::button('themeFontDelete' . $fontId, [
'class' => 'themeFontDelete buttonRed', 'class' => 'themeFontDelete buttonRed',
'href' => helper::baseUrl() . $this->getUrl(0) . '/fontDelete/' . $fontId . '/' . $_SESSION['csrf'], '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 * Effacer une fonte
*/ */

View File

@ -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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @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
*/

View File

@ -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 <frederic.tempez@outlook.com>
* @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();
});

View File

@ -0,0 +1,83 @@
<?php echo template::formOpen('fontAddForm'); ?>
<div class="row">
<div class="col2">
<?php echo template::button('fontAddBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'theme/fonts',
'ico' => 'left',
'value' => 'Retour'
]); ?>
</div>
<div class="col2">
<?php echo template::button('pageEditHelp', [
'href' => 'https://doc.zwiicms.fr/fontes#add',
'target' => '_blank',
'ico' => 'help',
'value' => 'Aide',
'class' => 'buttonHelp'
]); ?>
</div>
<div class="col2 offset6">
<?php echo template::submit('fontAddPublish', [
'value' => 'Valider',
'uniqueSubmission' => true
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Identité de la fonte</h4>
<div class="row">
<div class="col6">
<?php echo template::checkbox('fontAddFontImported', true, 'Fonte en ligne', []); ?>
</div>
<div class="col6">
<?php echo template::checkbox('fontAddFontFile', true,'Fonte installée', []); ?>
</div>
</div>
<div class="row">
<div class="col6">
<?php echo template::text('fontAddFontId', [
'autocomplete' => 'off',
'label' => 'Identifiant (sans espace ni majuscule)',
'placeholder' => 'big-marker-extrude'
]); ?>
</div>
<div class="col6">
<?php echo template::text('fontAddFontName', [
'autocomplete' => 'off',
'label' => 'Nom',
'placeholder' => 'Big Marker Extrude'
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::text('fontAddFontFamilyName', [
'autocomplete' => 'off',
'label' => 'Famille',
'placeholder' => "'Big Marker Extrude', sans-serif"
]); ?>
</div>
</div>
<div class="row" id="containerFontAddFile">
<div class="col12">
<?php echo template::file('fontAddFile', [
'label' => 'Fichier de fonte (Format WOFF)'
]); ?>
</div>
</div>
<div class="row" id="containerFontAddUrl">
<div class="col12">
<?php echo template::text('fontAddUrl', [
'label' => 'Url du fichier de fonte',
'placeholder' => 'https://fonts.cdnfonts.com/css/big-marker-extrude'
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>

View File

@ -25,7 +25,7 @@
</div> </div>
</div> </div>
<?php if($module::$fontsDetail): ?> <?php if($module::$fontsDetail): ?>
<?php echo template::table([2, 2, 3, 3, 1, 1], $module::$fontsDetail, ['FontId', 'Nom', 'Famille', 'Affectation', 'Origine', '']); ?> <?php echo template::table([2, 2, 3, 2, 1, 1, 1], $module::$fontsDetail, ['FontId', 'Nom', 'Famille', 'Affectation', 'Origine', '', '']); ?>
<?php else: ?> <?php else: ?>
<?php echo template::speech('Aucune fonte !'); ?> <?php echo template::speech('Aucune fonte !'); ?>
<?php endif; ?> <?php endif; ?>