2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2021-02-17 13:51:12 +01:00
|
|
|
* This file is part of Zwii.
|
2018-04-02 08:29:19 +02:00
|
|
|
* 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
|
2021-02-17 13:49:58 +01:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2021-12-18 10:25:33 +01:00
|
|
|
* @copyright Copyright (C) 2018-2022, Frédéric Tempez
|
2018-04-02 08:29:19 +02:00
|
|
|
* @license GNU General Public License, version 3
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
class news extends common
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
|
2022-10-19 10:31:31 +02:00
|
|
|
const VERSION = '4.23';
|
2021-07-22 23:11:55 +02:00
|
|
|
const REALNAME = 'News';
|
2021-05-03 16:32:36 +02:00
|
|
|
const DATADIRECTORY = self::DATA_DIR . 'news/';
|
2021-02-18 10:07:05 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $actions = [
|
|
|
|
'add' => self::GROUP_MODERATOR,
|
2022-02-18 12:43:48 +01:00
|
|
|
'config' => self::GROUP_MODERATOR, // Edition des news
|
|
|
|
'option' => self::GROUP_MODERATOR, // paramétrage des news
|
2018-04-02 08:29:19 +02:00
|
|
|
'delete' => self::GROUP_MODERATOR,
|
|
|
|
'edit' => self::GROUP_MODERATOR,
|
2020-11-15 18:39:03 +01:00
|
|
|
'index' => self::GROUP_VISITOR,
|
2020-11-20 19:52:44 +01:00
|
|
|
'rss' => self::GROUP_VISITOR
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
public static $news = [];
|
|
|
|
|
|
|
|
public static $comments = [];
|
|
|
|
|
|
|
|
public static $pages;
|
|
|
|
|
|
|
|
public static $states = [
|
|
|
|
false => 'Brouillon',
|
|
|
|
true => 'Publié'
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $users = [];
|
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Nombre d'objets par page
|
2021-04-09 13:29:11 +02:00
|
|
|
public static $itemsList = [
|
2021-04-05 08:59:24 +02:00
|
|
|
4 => '4 articles',
|
|
|
|
8 => '8 articles',
|
|
|
|
12 => '12 articles',
|
|
|
|
16 => '16 articles',
|
2021-07-23 19:34:23 +02:00
|
|
|
22 => '22 articles'
|
2021-04-05 08:59:24 +02:00
|
|
|
];
|
|
|
|
// Nombre de colone par page
|
2021-04-09 13:29:11 +02:00
|
|
|
public static $columns = [
|
2021-07-23 19:34:23 +02:00
|
|
|
12 => '1 colonne',
|
|
|
|
6 => '2 colonnes',
|
|
|
|
4 => '3 colonnes',
|
|
|
|
3 => '4 colonnes'
|
2021-04-05 08:59:24 +02:00
|
|
|
];
|
|
|
|
public static $nbrCol = 1;
|
|
|
|
|
2021-07-22 23:11:55 +02:00
|
|
|
public static $height = [
|
2021-07-23 19:34:23 +02:00
|
|
|
-1 => 'Article complet',
|
2021-07-23 10:12:01 +02:00
|
|
|
1000 => '1000 caractères',
|
2021-07-23 19:34:23 +02:00
|
|
|
800 => '800 caractères',
|
|
|
|
600 => '600 caractères',
|
|
|
|
400 => '400 caractères',
|
|
|
|
200 => '200 caractères',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $borderWidth = [
|
|
|
|
0 => 'Aucune',
|
|
|
|
'0.1em' => 'Très fine',
|
|
|
|
'0.15em' => 'Fine',
|
|
|
|
'0.2em' => 'Très petite',
|
|
|
|
'0.25em' => 'Petite',
|
|
|
|
];
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
public static $borderStyle = [
|
2021-07-23 19:34:23 +02:00
|
|
|
'none' => 'Aucune',
|
2022-03-17 12:55:04 +01:00
|
|
|
'solid' => 'Tiret'
|
2021-04-05 08:59:24 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// Signature de l'article
|
|
|
|
public static $articleSignature = '';
|
2022-02-18 12:43:48 +01:00
|
|
|
// Nombre d'articles dans la page de config:
|
|
|
|
public static $itemsperPage = 8;
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2020-11-15 18:39:03 +01:00
|
|
|
/**
|
|
|
|
* Flux RSS
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function rss()
|
|
|
|
{
|
2020-11-16 14:33:59 +01:00
|
|
|
// Inclure les classes
|
|
|
|
include_once 'module/news/vendor/FeedWriter/Item.php';
|
|
|
|
include_once 'module/news/vendor/FeedWriter/Feed.php';
|
|
|
|
include_once 'module/news/vendor/FeedWriter/RSS2.php';
|
|
|
|
include_once 'module/news/vendor/FeedWriter/InvalidOperationException.php';
|
|
|
|
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
|
|
|
|
$feeds = new \FeedWriter\RSS2();
|
|
|
|
|
2020-11-15 18:39:03 +01:00
|
|
|
// En-tête
|
2022-10-16 17:47:05 +02:00
|
|
|
$feeds->setTitle($this->getData(['page', $this->getUrl(0), 'title']));
|
2020-11-16 14:33:59 +01:00
|
|
|
$feeds->setLink(helper::baseUrl() . $this->getUrl(0));
|
2022-10-16 17:47:05 +02:00
|
|
|
$feeds->setDescription($this->getData(['page', $this->getUrl(0), 'metaDescription']));
|
2020-11-16 14:33:59 +01:00
|
|
|
$feeds->setChannelElement('language', 'fr-FR');
|
2022-10-16 17:47:05 +02:00
|
|
|
$feeds->setDate(date('r', time()));
|
2020-11-16 14:33:59 +01:00
|
|
|
$feeds->addGenerator();
|
|
|
|
// Corps des articles
|
2022-04-06 09:46:28 +02:00
|
|
|
$newsIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC');
|
|
|
|
$newsIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
|
2022-10-16 17:47:05 +02:00
|
|
|
foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) {
|
|
|
|
if ($newsPublishedOn <= time() and $newsIdsStates[$newsId]) {
|
2020-11-16 14:33:59 +01:00
|
|
|
$newsArticle = $feeds->createNewItem();
|
2020-11-20 13:44:32 +01:00
|
|
|
$author = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'userId']));
|
2020-11-16 14:33:59 +01:00
|
|
|
$newsArticle->addElementArray([
|
2022-10-16 17:47:05 +02:00
|
|
|
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'title']),
|
2020-11-21 03:57:27 +01:00
|
|
|
'link' => helper::baseUrl() . $this->getUrl(0) . '/' . $newsId . '#' . $newsId,
|
2022-10-16 17:47:05 +02:00
|
|
|
'description' => $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'content'])
|
2020-11-16 14:33:59 +01:00
|
|
|
]);
|
2022-10-16 17:47:05 +02:00
|
|
|
$newsArticle->setAuthor($author, 'no@mail.com');
|
|
|
|
$newsArticle->setId(helper::baseUrl() . $this->getUrl(0) . '/' . $newsId . '#' . $newsId);
|
2020-11-20 17:32:38 +01:00
|
|
|
$newsArticle->setDate(date('r', $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOn'])));
|
2020-11-16 14:33:59 +01:00
|
|
|
$feeds->addItem($newsArticle);
|
2020-11-15 18:39:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-16 14:33:59 +01:00
|
|
|
|
2020-11-15 18:39:03 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_RSS,
|
2020-11-16 14:33:59 +01:00
|
|
|
'content' => $feeds->generateFeed(),
|
2020-11-15 18:39:03 +01:00
|
|
|
'view' => 'rss'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
2021-04-05 08:59:24 +02:00
|
|
|
* Ajout d'un article
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function add()
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
// Soumission du formulaire
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->isPost()) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Crée la news
|
2021-07-05 08:44:10 +02:00
|
|
|
$newsId = helper::increment($this->getInput('newsAddTitle', helper::FILTER_ID), (array) $this->getData(['module', $this->getUrl(0), 'posts']));
|
2021-05-15 12:04:10 +02:00
|
|
|
$publishedOn = $this->getInput('newsAddPublishedOn', helper::FILTER_DATETIME, true);
|
2022-10-16 17:47:05 +02:00
|
|
|
$publishedOff = $this->getInput('newsAddPublishedOff') ? $this->getInput('newsAddPublishedOff', helper::FILTER_DATETIME) : '';
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'posts', $newsId, [
|
2018-04-02 08:29:19 +02:00
|
|
|
'content' => $this->getInput('newsAddContent', null),
|
2021-05-15 12:04:10 +02:00
|
|
|
'publishedOn' => $publishedOn,
|
|
|
|
'publishedOff' => $publishedOff,
|
2018-04-02 08:29:19 +02:00
|
|
|
'state' => $this->getInput('newsAddState', helper::FILTER_BOOLEAN),
|
|
|
|
'title' => $this->getInput('newsAddTitle', helper::FILTER_STRING_SHORT, true),
|
|
|
|
'userId' => $this->getInput('newsAddUserId', helper::FILTER_ID, true)
|
|
|
|
]]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Nouvelle news créée',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Liste des utilisateurs
|
2022-04-06 09:46:28 +02:00
|
|
|
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
2018-04-02 08:29:19 +02:00
|
|
|
ksort(self::$users);
|
2022-10-16 17:47:05 +02:00
|
|
|
foreach (self::$users as $userId => &$userFirstname) {
|
2018-04-02 08:29:19 +02:00
|
|
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
|
|
|
}
|
|
|
|
unset($userFirstname);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Nouvelle news',
|
|
|
|
'vendor' => [
|
|
|
|
'flatpickr',
|
|
|
|
'tinymce'
|
|
|
|
],
|
|
|
|
'view' => 'add'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function config()
|
|
|
|
{
|
2021-04-07 14:26:12 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
2022-02-18 12:43:48 +01:00
|
|
|
// Ids des news par ordre de publication
|
2022-04-06 09:46:28 +02:00
|
|
|
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
2022-02-18 12:43:48 +01:00
|
|
|
// Pagination fixe
|
2022-10-16 17:47:05 +02:00
|
|
|
$pagination = helper::pagination($newsIds, $this->getUrl(), self::$itemsperPage);
|
2022-02-18 12:43:48 +01:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
|
|
|
// News en fonction de la pagination
|
2022-10-16 17:47:05 +02:00
|
|
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
2022-02-18 12:43:48 +01:00
|
|
|
// Met en forme le tableau
|
2022-10-16 17:47:05 +02:00
|
|
|
$dateOn = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn']));
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) {
|
|
|
|
$dateOff = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff']));
|
2022-02-18 12:43:48 +01:00
|
|
|
} else {
|
|
|
|
$dateOff = 'Permanent';
|
|
|
|
}
|
|
|
|
self::$news[] = [
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'title']),
|
2022-02-18 12:43:48 +01:00
|
|
|
$dateOn,
|
|
|
|
$dateOff,
|
2022-10-16 17:47:05 +02:00
|
|
|
self::$states[$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'state'])],
|
2022-02-18 12:43:48 +01:00
|
|
|
template::button('newsConfigEdit' . $newsIds[$i], [
|
2022-10-16 17:47:05 +02:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
2022-02-18 12:43:48 +01:00
|
|
|
'value' => template::ico('pencil'),
|
2022-10-02 10:59:42 +02:00
|
|
|
'help' => 'Éditer cette nouvelle'
|
2022-02-18 12:43:48 +01:00
|
|
|
]),
|
|
|
|
template::button('newsConfigDelete' . $newsIds[$i], [
|
|
|
|
'class' => 'newsConfigDelete buttonRed',
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
2022-02-25 10:04:46 +01:00
|
|
|
'value' => template::ico('trash'),
|
2022-02-18 12:43:48 +01:00
|
|
|
'help' => 'Effacer cette nouvelle'
|
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration du module',
|
|
|
|
'view' => 'config',
|
|
|
|
'vendor' => [
|
|
|
|
'tinycolorpicker'
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
public function option()
|
|
|
|
{
|
2020-11-17 09:47:45 +01:00
|
|
|
// Soumission du formulaire
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->isPost()) {
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Générer la feuille de CSS
|
2021-07-23 19:34:23 +02:00
|
|
|
$style = '.newsFrame {';
|
2022-10-16 17:47:05 +02:00
|
|
|
$style .= 'border-right:' . $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT) . ';';
|
|
|
|
$style .= 'border-left:' . $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT) . ';';
|
2021-07-23 19:34:23 +02:00
|
|
|
$style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';';
|
|
|
|
$style .= '}';
|
2021-04-12 17:54:31 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Dossier de l'instance
|
2021-06-05 17:21:07 +02:00
|
|
|
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
2022-10-16 17:47:05 +02:00
|
|
|
mkdir(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', 0755, true);
|
2021-04-05 08:59:24 +02:00
|
|
|
}
|
|
|
|
|
2022-10-19 10:31:31 +02:00
|
|
|
$success = is_int(file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style));
|
2021-04-09 11:34:16 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Fin feuille de style
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', [
|
2021-07-23 19:34:23 +02:00
|
|
|
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
|
2022-10-16 17:47:05 +02:00
|
|
|
'borderStyle' => $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT),
|
2021-07-23 19:34:23 +02:00
|
|
|
'borderColor' => $this->getInput('newsThemeBorderColor'),
|
2022-10-16 17:47:05 +02:00
|
|
|
'borderWidth' => $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT),
|
2021-07-23 19:34:23 +02:00
|
|
|
'backgroundColor' => $this->getInput('newsThemeBackgroundColor')
|
2021-04-09 11:34:16 +02:00
|
|
|
]]);
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', [
|
|
|
|
'feeds' => $this->getInput('newsOptionShowFeeds', helper::FILTER_BOOLEAN),
|
|
|
|
'feedsLabel' => $this->getInput('newsOptionFeedslabel', helper::FILTER_STRING_SHORT),
|
|
|
|
'itemsperPage' => $this->getInput('newsOptionItemsperPage', helper::FILTER_INT, true),
|
|
|
|
'itemsperCol' => $this->getInput('newsOptionItemsperCol', helper::FILTER_INT, true),
|
|
|
|
'height' => $this->getInput('newsOptionHeight', helper::FILTER_INT, true),
|
2021-04-09 11:34:16 +02:00
|
|
|
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
|
|
|
|
]]);
|
2021-07-23 19:34:23 +02:00
|
|
|
|
|
|
|
|
2020-11-17 09:47:45 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-02-18 12:43:48 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/option',
|
2020-11-17 09:47:45 +01:00
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
} else {
|
2022-02-12 17:10:59 +01:00
|
|
|
// Ids des news par ordre de publication
|
2022-04-06 09:46:28 +02:00
|
|
|
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
2022-02-12 17:10:59 +01:00
|
|
|
// Pagination
|
2022-10-16 17:47:05 +02:00
|
|
|
$pagination = helper::pagination($newsIds, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
2022-02-12 17:10:59 +01:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
|
|
|
// News en fonction de la pagination
|
2022-10-16 17:47:05 +02:00
|
|
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
2022-02-12 17:10:59 +01:00
|
|
|
// Met en forme le tableau
|
2022-10-16 17:47:05 +02:00
|
|
|
$dateOn = $dateOn = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn']));
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) {
|
|
|
|
$dateOff = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff']));
|
2022-02-12 17:10:59 +01:00
|
|
|
} else {
|
|
|
|
$dateOff = 'Permanent';
|
|
|
|
}
|
|
|
|
self::$news[] = [
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'title']),
|
2022-02-12 17:10:59 +01:00
|
|
|
$dateOn,
|
|
|
|
$dateOff,
|
2022-10-16 17:47:05 +02:00
|
|
|
self::$states[$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'state'])],
|
2022-02-12 17:10:59 +01:00
|
|
|
template::button('newsConfigEdit' . $newsIds[$i], [
|
2022-10-16 17:47:05 +02:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
2022-02-12 17:10:59 +01:00
|
|
|
'value' => template::ico('pencil')
|
|
|
|
]),
|
|
|
|
template::button('newsConfigDelete' . $newsIds[$i], [
|
|
|
|
'class' => 'newsConfigDelete buttonRed',
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
|
|
|
'value' => template::ico('cancel')
|
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
2020-11-17 09:47:45 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-02-18 12:43:48 +01:00
|
|
|
'title' => 'Options de configuration',
|
|
|
|
'view' => 'option',
|
2021-07-23 19:34:23 +02:00
|
|
|
'vendor' => [
|
|
|
|
'tinycolorpicker'
|
|
|
|
]
|
2020-11-17 09:47:45 +01:00
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function delete()
|
|
|
|
{
|
2018-04-02 08:29:19 +02:00
|
|
|
// La news n'existe pas
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
2019-01-08 17:55:18 +01:00
|
|
|
// Jeton incorrect
|
2019-01-16 19:25:09 +01:00
|
|
|
elseif ($this->getUrl(3) !== $_SESSION['csrf']) {
|
2019-01-08 17:55:18 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-01-16 19:25:09 +01:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
2022-10-11 10:33:44 +02:00
|
|
|
'notification' => 'Action interdite'
|
2019-01-08 17:55:18 +01:00
|
|
|
]);
|
2020-06-03 09:07:00 +02:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Suppression
|
|
|
|
else {
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]);
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'News supprimée',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Édition
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function edit()
|
|
|
|
{
|
2019-01-16 19:25:09 +01:00
|
|
|
// Jeton incorrect
|
|
|
|
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Action non autorisée'
|
|
|
|
]);
|
2020-06-03 09:07:00 +02:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// La news n'existe pas
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// La news existe
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->isPost()) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Si l'id a changée
|
|
|
|
$newsId = $this->getInput('newsEditTitle', helper::FILTER_ID, true);
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($newsId !== $this->getUrl(2)) {
|
2018-04-02 08:29:19 +02:00
|
|
|
// Incrémente le nouvel id de la news
|
2021-07-05 08:44:10 +02:00
|
|
|
$newsId = helper::increment($newsId, $this->getData(['module', $this->getUrl(0), 'posts']));
|
2018-04-02 08:29:19 +02:00
|
|
|
// Supprime l'ancien news
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2021-05-03 22:18:38 +02:00
|
|
|
$publishedOn = $this->getInput('newsEditPublishedOn', helper::FILTER_DATETIME, true);
|
2022-10-16 17:47:05 +02:00
|
|
|
$publishedOff = $this->getInput('newsEditPublishedOff') ? $this->getInput('newsEditPublishedOff', helper::FILTER_DATETIME) : '';
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'posts', $newsId, [
|
2018-04-02 08:29:19 +02:00
|
|
|
'content' => $this->getInput('newsEditContent', null),
|
2021-05-03 22:18:38 +02:00
|
|
|
'publishedOn' => $publishedOn,
|
|
|
|
'publishedOff' => $publishedOff < $publishedOn ? '' : $publishedOff,
|
2018-04-02 08:29:19 +02:00
|
|
|
'state' => $this->getInput('newsEditState', helper::FILTER_BOOLEAN),
|
|
|
|
'title' => $this->getInput('newsEditTitle', helper::FILTER_STRING_SHORT, true),
|
|
|
|
'userId' => $this->getInput('newsEditUserId', helper::FILTER_ID, true)
|
|
|
|
]]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Liste des utilisateurs
|
2022-04-06 09:46:28 +02:00
|
|
|
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
2018-04-02 08:29:19 +02:00
|
|
|
ksort(self::$users);
|
2022-10-16 17:47:05 +02:00
|
|
|
foreach (self::$users as $userId => &$userFirstname) {
|
2018-04-02 08:29:19 +02:00
|
|
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
|
|
|
}
|
|
|
|
unset($userFirstname);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2022-10-16 17:47:05 +02:00
|
|
|
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']),
|
2018-04-02 08:29:19 +02:00
|
|
|
'vendor' => [
|
|
|
|
'flatpickr',
|
|
|
|
'tinymce'
|
|
|
|
],
|
|
|
|
'view' => 'edit'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accueil
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
public function index()
|
|
|
|
{
|
2021-04-07 14:26:12 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
2021-04-09 11:34:16 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Affichage d'un article
|
2022-10-16 17:47:05 +02:00
|
|
|
if (
|
2021-04-05 08:59:24 +02:00
|
|
|
$this->getUrl(1)
|
|
|
|
// Protection pour la pagination, un ID ne peut pas être un entier, une page oui
|
2022-10-16 17:47:05 +02:00
|
|
|
and intval($this->getUrl(1)) === 0
|
2021-04-05 08:59:24 +02:00
|
|
|
) {
|
|
|
|
// L'article n'existe pas
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1)]) === null) {
|
2021-04-05 08:59:24 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2021-04-05 08:59:24 +02:00
|
|
|
// L'article existe
|
|
|
|
else {
|
|
|
|
self::$articleSignature = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'userId']));
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'title']),
|
|
|
|
'view' => 'article'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Affichage index
|
|
|
|
// Ids des news par ordre de publication
|
2022-04-06 09:46:28 +02:00
|
|
|
$newsIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC');
|
|
|
|
$newsIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
|
2021-04-05 08:59:24 +02:00
|
|
|
$newsIds = [];
|
2022-10-16 17:47:05 +02:00
|
|
|
foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) {
|
2021-05-03 22:18:38 +02:00
|
|
|
$newsIdsPublishedOff = $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOff']);
|
2022-10-16 17:47:05 +02:00
|
|
|
if (
|
|
|
|
$newsPublishedOn <= time() and
|
|
|
|
$newsIdsStates[$newsId] and
|
|
|
|
// date de péremption tenant des champs non définis
|
|
|
|
(!is_integer($newsIdsPublishedOff) or
|
|
|
|
$newsIdsPublishedOff > time()
|
|
|
|
)
|
|
|
|
) {
|
2021-04-05 08:59:24 +02:00
|
|
|
$newsIds[] = $newsId;
|
|
|
|
}
|
|
|
|
}
|
2022-02-18 12:43:48 +01:00
|
|
|
// Pagination selon le layout
|
2022-10-16 17:47:05 +02:00
|
|
|
$pagination = helper::pagination($newsIds, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
2021-04-05 08:59:24 +02:00
|
|
|
// Nombre de colonnes
|
2022-10-16 17:47:05 +02:00
|
|
|
self::$nbrCol = $this->getData(['module', $this->getUrl(0), 'config', 'itemsperCol']);
|
2021-04-05 08:59:24 +02:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
|
|
|
// News en fonction de la pagination
|
2022-10-16 17:47:05 +02:00
|
|
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
|
|
|
self::$news[$newsIds[$i]] = $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i]]);
|
2021-07-22 23:11:55 +02:00
|
|
|
// Longueur de la news affichée
|
2022-10-16 17:47:05 +02:00
|
|
|
if (
|
|
|
|
$this->getData(['module', $this->getUrl(0), 'config', 'height']) !== -1
|
|
|
|
&& strlen($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content'])) >= $this->getData(['module', $this->getUrl(0), 'config', 'height'])
|
|
|
|
) {
|
|
|
|
// Contenu raccourci
|
|
|
|
$content = substr($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content']), 0, $this->getData(['module', $this->getUrl(0), 'config', 'height']));
|
|
|
|
// Ne pas couper un mot
|
|
|
|
$lastSpace = strrpos($content, ' ', -1);
|
|
|
|
self::$news[$newsIds[$i]]['content'] = substr(strip_tags($content, '<br><p><img>'), 0, $lastSpace);
|
2021-07-22 23:11:55 +02:00
|
|
|
}
|
|
|
|
// Mise en forme de la signature
|
|
|
|
self::$news[$newsIds[$i]]['userId'] = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'userId']));
|
2021-04-05 08:59:24 +02:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true,
|
|
|
|
'view' => 'index',
|
2022-10-16 17:47:05 +02:00
|
|
|
'style' => file_exists($this->getData(['module', $this->getUrl(0), 'theme', 'style']))
|
|
|
|
? $this->getData(['module', $this->getUrl(0), 'theme', 'style'])
|
|
|
|
: ''
|
2021-04-05 08:59:24 +02:00
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 13:44:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la signature d'un utilisateur
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
private function signature($userId)
|
|
|
|
{
|
|
|
|
switch ($this->getData(['user', $userId, 'signature'])) {
|
2020-11-20 13:44:32 +01:00
|
|
|
case 1:
|
|
|
|
return $userId;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return $this->getData(['user', $userId, 'pseudo']);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return $this->getData(['user', $userId, 'lastname']) . ' ' . $this->getData(['user', $userId, 'firstname']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return $this->getData(['user', $userId, 'firstname']);
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 14:26:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mise à jour du module
|
|
|
|
* Appelée par les fonctions index et config
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
private function update()
|
|
|
|
{
|
2021-04-08 11:33:35 +02:00
|
|
|
|
2021-08-20 11:44:38 +02:00
|
|
|
// le module n'est pas initialisé
|
2022-10-16 17:47:05 +02:00
|
|
|
if (
|
|
|
|
$this->getData(['module', $this->getUrl(0), 'config']) === NULL
|
|
|
|
|| $this->getData(['module', $this->getUrl(0), 'theme']) === NULL
|
|
|
|
|| !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')
|
|
|
|
) {
|
2021-08-20 11:44:38 +02:00
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
|
2022-10-16 17:47:05 +02:00
|
|
|
$versionData = $this->getData(['module', $this->getUrl(0), 'config', 'versionData']);
|
2021-05-15 14:17:14 +02:00
|
|
|
// Mise à jour 3.2
|
2022-10-16 17:47:05 +02:00
|
|
|
if (version_compare($versionData, '3.1', '<')) {
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'itemsBlur', '0%']);
|
2021-06-05 17:38:11 +02:00
|
|
|
// Mettre à jour la version
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.2']);
|
2021-05-15 14:17:14 +02:00
|
|
|
}
|
2021-06-05 17:38:11 +02:00
|
|
|
// Mise à jour 3.3
|
2022-10-16 17:47:05 +02:00
|
|
|
if (version_compare($versionData, '3.3', '<')) {
|
2021-06-07 10:57:03 +02:00
|
|
|
if (is_dir(self::DATADIRECTORY . 'pages/')) {
|
|
|
|
// Déplacer les données du dossier Pages
|
|
|
|
$this->copyDir(self::DATADIRECTORY . 'pages/' . $this->getUrl(0), self::DATADIRECTORY . $this->getUrl(0));
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->removeDir(self::DATADIRECTORY . 'pages/');
|
2021-06-07 10:57:03 +02:00
|
|
|
$style = $this->getData(['module', $this->getUrl(0), 'theme', 'style']);
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', str_replace('pages/', '', $style)]);
|
|
|
|
}
|
2021-06-05 17:38:11 +02:00
|
|
|
// Mettre à jour la version
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.3']);
|
2021-06-05 17:38:11 +02:00
|
|
|
}
|
2021-07-22 23:11:55 +02:00
|
|
|
// Mise à jour 3.4
|
2022-10-16 17:47:05 +02:00
|
|
|
if (version_compare($versionData, '3.4', '<')) {
|
2021-07-23 19:34:23 +02:00
|
|
|
// Effacer le style précédent
|
|
|
|
unlink(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css');
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->deleteData(['module', $this->getUrl(0), 'theme']);
|
2021-07-23 19:34:23 +02:00
|
|
|
// Le générer
|
|
|
|
$this->init();
|
2021-07-22 23:11:55 +02:00
|
|
|
// Mettre à jour la version
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.4']);
|
2021-07-22 23:11:55 +02:00
|
|
|
}
|
2021-04-07 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation du thème d'un nouveau module
|
|
|
|
*/
|
2022-10-16 17:47:05 +02:00
|
|
|
private function init()
|
|
|
|
{
|
2021-04-12 17:54:31 +02:00
|
|
|
|
2021-07-23 19:34:23 +02:00
|
|
|
$fileCSS = self::DATADIRECTORY . $this->getUrl(0) . '/theme.css';
|
2021-04-12 17:54:31 +02:00
|
|
|
|
2021-05-03 18:35:31 +02:00
|
|
|
// Données du module absentes
|
2021-07-23 19:34:23 +02:00
|
|
|
require_once('module/news/ressource/defaultdata.php');
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'config']) === null) {
|
2021-04-12 17:54:31 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]);
|
2021-07-23 19:34:23 +02:00
|
|
|
}
|
2022-10-16 17:47:05 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), 'theme']) === null) {
|
2021-04-12 17:54:31 +02:00
|
|
|
// Données de thème
|
2021-07-23 19:34:23 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', init::$defaultTheme]);
|
2022-10-16 17:47:05 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
2021-04-08 11:33:35 +02:00
|
|
|
}
|
2021-04-07 14:26:12 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Dossier de l'instance
|
2022-10-16 17:47:05 +02:00
|
|
|
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
|
|
|
mkdir(self::DATADIRECTORY . $this->getUrl(0), 0755, true);
|
2021-07-23 19:34:23 +02:00
|
|
|
}
|
2021-04-07 14:26:12 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Check la présence de la feuille de style
|
2022-10-16 17:47:05 +02:00
|
|
|
if (!file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')) {
|
2021-04-12 17:54:31 +02:00
|
|
|
// Générer la feuille de CSS
|
2021-07-23 19:34:23 +02:00
|
|
|
$style = '.newsFrame {';
|
2022-10-16 17:47:05 +02:00
|
|
|
$style .= 'border:' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderStyle']) . ' ' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderColor']) . ' ' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderWidth']) . ';';
|
|
|
|
$style .= 'background-color:' . $this->getData(['module', $this->getUrl(0), 'theme', 'backgroundColor']) . ';';
|
2021-07-23 19:34:23 +02:00
|
|
|
$style .= '}';
|
2022-10-16 17:47:05 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Sauver la feuille de style
|
2022-10-16 17:47:05 +02:00
|
|
|
file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style);
|
2021-04-12 17:54:31 +02:00
|
|
|
// Stocker le nom de la feuille de style
|
2021-07-23 19:34:23 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
|
|
|
}
|
2021-04-07 14:26:12 +02:00
|
|
|
}
|
2021-02-25 07:53:57 +01:00
|
|
|
}
|