News v4.0

This commit is contained in:
Fred Tempez 2022-01-17 19:11:05 +01:00
parent 7d570763eb
commit 432906085d
5 changed files with 189 additions and 136 deletions

4
module/news/changes.md Normal file
View File

@ -0,0 +1,4 @@
# Version 4
- Config : le nombre d'objet est fixe, constante dans news.php
- Ecran layout réservé à la configuration et au thème
- Bug avec l'initialisation, fichier css déclaré mais absent

View File

@ -15,7 +15,7 @@
class news extends common { class news extends common {
const VERSION = '3.7'; const VERSION = '4.0';
const REALNAME = 'News'; const REALNAME = 'News';
const DELETE = true; const DELETE = true;
const UPDATE = '0.0'; const UPDATE = '0.0';
@ -23,7 +23,8 @@ class news extends common {
public static $actions = [ public static $actions = [
'add' => self::GROUP_MODERATOR, 'add' => self::GROUP_MODERATOR,
'config' => self::GROUP_MODERATOR, 'config' => self::GROUP_MODERATOR, // Edition des news
'layout' => self::GROUP_MODERATOR, // paramétrage des news
'delete' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR,
'edit' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR,
'index' => self::GROUP_VISITOR, 'index' => self::GROUP_VISITOR,
@ -88,7 +89,8 @@ class news extends common {
// Signature de l'article // Signature de l'article
public static $articleSignature = ''; public static $articleSignature = '';
// Nombre d'articles dans la page de config:
public static $itemsperPage = 8;
/** /**
* Flux RSS * Flux RSS
@ -189,54 +191,10 @@ class news extends common {
// Mise à jour des données de module // Mise à jour des données de module
$this->update(); $this->update();
// Soumission du formulaire
if($this->isPost()) {
// Générer la feuille de CSS
$style = '.newsFrame {';
$style .= 'border:' . $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';';
$style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';';
$style .= '}';
// Dossier de l'instance
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
mkdir (self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', 0755, true);
}
$success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style );
// Fin feuille de style
$this->setData(['module', $this->getUrl(0), 'theme',[
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
'borderStyle' => $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT),
'borderColor' => $this->getInput('newsThemeBorderColor'),
'borderWidth' => $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT),
'backgroundColor' => $this->getInput('newsThemeBackgroundColor')
]]);
$this->setData(['module', $this->getUrl(0), 'config',[
'feeds' => $this->getInput('newsConfigShowFeeds',helper::FILTER_BOOLEAN),
'feedsLabel' => $this->getInput('newsConfigFeedslabel',helper::FILTER_STRING_SHORT),
'itemsperPage' => $this->getInput('newsConfigItemsperPage', helper::FILTER_INT,true),
'itemsperCol' => $this->getInput('newsConfigItemsperCol', helper::FILTER_INT,true),
'height' => $this->getInput('newsConfigHeight', helper::FILTER_INT,true),
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées',
'state' => true
]);
} else {
// Ids des news par ordre de publication // Ids des news par ordre de publication
$newsIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); $newsIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
// Pagination // Pagination fixe
$pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) ); $pagination = helper::pagination($newsIds, $this->getUrl(),self::$itemsperPage );
// Liste des pages // Liste des pages
self::$pages = $pagination['pages']; self::$pages = $pagination['pages'];
// News en fonction de la pagination // News en fonction de la pagination
@ -285,6 +243,60 @@ class news extends common {
] ]
]); ]);
} }
public function layout() {
// Soumission du formulaire
if($this->isPost()) {
// Générer la feuille de CSS
$style = '.newsFrame {';
$style .= 'border:' . $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';';
$style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';';
$style .= '}';
// Dossier de l'instance
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
mkdir (self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', 0755, true);
}
$success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style );
// Fin feuille de style
$this->setData(['module', $this->getUrl(0), 'theme',[
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
'borderStyle' => $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT),
'borderColor' => $this->getInput('newsThemeBorderColor'),
'borderWidth' => $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT),
'backgroundColor' => $this->getInput('newsThemeBackgroundColor')
]]);
$this->setData(['module', $this->getUrl(0), 'config',[
'feeds' => $this->getInput('newsLayoutShowFeeds',helper::FILTER_BOOLEAN),
'feedsLabel' => $this->getInput('newsLayoutFeedslabel',helper::FILTER_STRING_SHORT),
'itemsperPage' => $this->getInput('newsLayoutItemsperPage', helper::FILTER_INT,true),
'itemsperCol' => $this->getInput('newsLayoutItemsperCol', helper::FILTER_INT,true),
'height' => $this->getInput('newsLayoutHeight', helper::FILTER_INT,true),
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/layout',
'notification' => 'Modifications enregistrées',
'state' => true
]);
} else {
// Valeurs en sortie
$this->addOutput([
'title' => 'Mise en page',
'view' => 'layout',
'vendor' => [
'tinycolorpicker'
]
]);
}
} }
/** /**
@ -435,8 +447,7 @@ class news extends common {
$newsIds[] = $newsId; $newsIds[] = $newsId;
} }
} }
// Pagination // Pagination selon le layout
//$pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['config','itemsperPage']));
$pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage'])); $pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage']));
// Nombre de colonnes // Nombre de colonnes
self::$nbrCol = $this->getData(['module', $this->getUrl(0),'config', 'itemsperCol']); self::$nbrCol = $this->getData(['module', $this->getUrl(0),'config', 'itemsperCol']);

View File

@ -16,87 +16,14 @@
]); ?> ]); ?>
</div> </div>
<div class="col2"> <div class="col2">
<?php echo template::submit('newsConfigSubmit'); ?> <?php echo template::button('newsConfigLayout', [
</div> 'href' => helper::baseUrl() . $this->getUrl(0) . '/layout',
</div> 'ico' => 'puzzle',
<div class="row"> 'value' => 'Mise en page'
<div class="col12">
<div class="block">
<h4>Paramètres du module</h4>
<div class="row">
<div class="col6">
<?php echo template::checkbox('newsConfigShowFeeds', true, 'Lien du flux RSS', [
'checked' => $this->getData(['module', $this->getUrl(0), 'config', 'feeds']),
'help' => 'Flux limité aux articles de la première page.'
]); ?>
</div>
<div class="col6">
<?php echo template::text('newsConfigFeedslabel', [
'label' => 'Etiquette RSS',
'value' => $this->getData(['module', $this->getUrl(0), 'config', 'feedsLabel'])
]); ?> ]); ?>
</div> </div>
</div> </div>
<div class="row">
<div class="col4">
<?php echo template::select('newsConfigItemsperCol', $module::$columns, [
'label' => 'Nombre de colonnes',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'itemsperCol'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('newsConfigItemsperPage', $module::$itemsList, [
'label' => 'Articles par page',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'itemsperPage'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('newsConfigHeight', $module::$height, [
'label' => 'Abrégé de l\'article',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'height'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Thème du module</h4>
<div class="row">
<div class="col3">
<?php echo template::select('newsThemeBorderStyle', $module::$borderStyle, [
'label' => 'Bordure',
'selected' => $this->getData(['module', $this->getUrl(0),'theme', 'borderStyle'])
]); ?>
</div>
<div class="col3">
<?php echo template::select('newsThemeBorderWidth', $module::$borderWidth, [
'label' => 'Epaisseur',
'selected' => $this->getData(['module', $this->getUrl(0),'theme', 'borderWidth'])
]); ?>
</div>
<div class="col3">
<?php echo template::text('newsThemeBorderColor', [
'class' => 'colorPicker',
'help' => 'Couleur visible en l\'absence d\'une image.<br />Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur de la bordure',
'value' => $this->getData(['module', $this->getUrl(0),'theme', 'borderColor'])
]); ?>
</div>
<div class="col3">
<?php echo template::text('newsThemeBackgroundColor', [
'class' => 'colorPicker',
'help' => 'Couleur visible en l\'absence d\'une image.<br />Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur du fond',
'value' => $this->getData(['module', $this->getUrl(0),'theme', 'backgroundColor'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php if($module::$news): ?> <?php if($module::$news): ?>
<?php echo template::table([4, 2, 2, 2, 1, 1], $module::$news, ['Titre', 'Publication', 'Dépublication', 'État', '', '']); ?> <?php echo template::table([4, 2, 2, 2, 1, 1], $module::$news, ['Titre', 'Publication', 'Dépublication', 'État', '', '']); ?>
<?php echo $module::$pages; ?> <?php echo $module::$pages; ?>

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,93 @@
<?php echo template::formOpen('newsLayout'); ?>
<div class="row">
<div class="col2">
<?php echo template::button('newsLayoutBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . $this->getUrl(0) . '/config',
'ico' => 'left',
'value' => 'Retour'
]); ?>
</div>
<div class="col2 offset8">
<?php echo template::submit('newsLayoutSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Paramètres du module</h4>
<div class="row">
<div class="col6">
<?php echo template::checkbox('newsLayoutShowFeeds', true, 'Lien du flux RSS', [
'checked' => $this->getData(['module', $this->getUrl(0), 'config', 'feeds']),
'help' => 'Flux limité aux articles de la première page.'
]); ?>
</div>
<div class="col6">
<?php echo template::text('newsLayoutFeedslabel', [
'label' => 'Etiquette RSS',
'value' => $this->getData(['module', $this->getUrl(0), 'config', 'feedsLabel'])
]); ?>
</div>
</div>
<div class="row">
<div class="col4">
<?php echo template::select('newsLayoutItemsperCol', $module::$columns, [
'label' => 'Nombre de colonnes',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'itemsperCol'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('newsLayoutItemsperPage', $module::$itemsList, [
'label' => 'Articles par page',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'itemsperPage'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('newsLayoutHeight', $module::$height, [
'label' => 'Abrégé de l\'article',
'selected' => $this->getData(['module', $this->getUrl(0),'config', 'height'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Thème du module</h4>
<div class="row">
<div class="col3">
<?php echo template::select('newsThemeBorderStyle', $module::$borderStyle, [
'label' => 'Bordure',
'selected' => $this->getData(['module', $this->getUrl(0),'theme', 'borderStyle'])
]); ?>
</div>
<div class="col3">
<?php echo template::select('newsThemeBorderWidth', $module::$borderWidth, [
'label' => 'Epaisseur',
'selected' => $this->getData(['module', $this->getUrl(0),'theme', 'borderWidth'])
]); ?>
</div>
<div class="col3">
<?php echo template::text('newsThemeBorderColor', [
'class' => 'colorPicker',
'help' => 'Couleur visible en l\'absence d\'une image.<br />Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur de la bordure',
'value' => $this->getData(['module', $this->getUrl(0),'theme', 'borderColor'])
]); ?>
</div>
<div class="col3">
<?php echo template::text('newsThemeBackgroundColor', [
'class' => 'colorPicker',
'help' => 'Couleur visible en l\'absence d\'une image.<br />Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur du fond',
'value' => $this->getData(['module', $this->getUrl(0),'theme', 'backgroundColor'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>