2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @license GNU General Public License, version 3
|
|
|
|
* @link http://zwiicms.com/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class blog extends common {
|
|
|
|
|
2020-07-12 18:05:33 +02:00
|
|
|
// Objets
|
2020-07-16 18:50:57 +02:00
|
|
|
// Propriétaire - groupe
|
|
|
|
const EDIT_ALL = '02'; // Groupes Editeurs et admins
|
|
|
|
const EDIT_OWNER_ADMIN = '23'; // Propriétaire éditeur + groupe admin
|
|
|
|
const EDIT_ADMIN = '03'; // Groupe des admin
|
2020-07-12 18:05:33 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $actions = [
|
|
|
|
'add' => self::GROUP_MODERATOR,
|
|
|
|
'comment' => self::GROUP_MODERATOR,
|
2020-07-16 12:06:51 +02:00
|
|
|
'commentApprove' => self::GROUP_MODERATOR,
|
2018-04-02 08:29:19 +02:00
|
|
|
'commentDelete' => self::GROUP_MODERATOR,
|
2020-07-02 19:48:47 +02:00
|
|
|
'commentDeleteAll' => self::GROUP_MODERATOR,
|
2018-04-02 08:29:19 +02:00
|
|
|
'config' => self::GROUP_MODERATOR,
|
|
|
|
'delete' => self::GROUP_MODERATOR,
|
|
|
|
'edit' => self::GROUP_MODERATOR,
|
|
|
|
'index' => self::GROUP_VISITOR
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $articles = [];
|
|
|
|
|
2020-07-02 19:48:47 +02:00
|
|
|
// Signature de l'article
|
|
|
|
public static $articleSignature = '';
|
|
|
|
|
|
|
|
// Signature du commentaire
|
|
|
|
public static $editCommentSignature = '';
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $comments = [];
|
|
|
|
|
2020-07-02 19:48:47 +02:00
|
|
|
public static $commentsDelete;
|
|
|
|
|
|
|
|
// Signatures des commentaires déjà saisis
|
|
|
|
public static $commentsSignature = [];
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $pages;
|
|
|
|
|
|
|
|
public static $states = [
|
|
|
|
false => 'Brouillon',
|
|
|
|
true => 'Publié'
|
|
|
|
];
|
|
|
|
|
2020-04-23 19:55:47 +02:00
|
|
|
public static $pictureSizes = [
|
|
|
|
'20' => 'Très petite',
|
|
|
|
'30' => 'Petite',
|
|
|
|
'40' => 'Grande',
|
|
|
|
'50' => 'Très Grande',
|
|
|
|
'100' => 'Pleine largeur',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $picturePositions = [
|
2020-06-03 09:07:00 +02:00
|
|
|
'left' => 'À gauche',
|
2020-04-23 19:55:47 +02:00
|
|
|
'right' => 'À droite ',
|
|
|
|
];
|
|
|
|
|
2020-07-02 19:48:47 +02:00
|
|
|
//Paramètre longueur maximale des commentaires en nb de caractères
|
2020-07-16 10:33:37 +02:00
|
|
|
public static $commentLength = [
|
2020-07-02 19:48:47 +02:00
|
|
|
'500' => '500',
|
|
|
|
'1000' => '1000',
|
|
|
|
'2000' => '2000',
|
|
|
|
'5000' => '5000',
|
|
|
|
'10000' => '10000'
|
|
|
|
];
|
2020-04-23 19:55:47 +02:00
|
|
|
|
2020-07-16 18:50:57 +02:00
|
|
|
// Permissions d'un article
|
|
|
|
public static $articleRightsAdmin = [
|
|
|
|
self::EDIT_ALL => 'Groupes des éditeurs et des administrateurs',
|
|
|
|
self::EDIT_OWNER_ADMIN => 'Editeur et groupe des administrateurs',
|
|
|
|
self::EDIT_ADMIN => 'Groupe des administrateurs'
|
|
|
|
];
|
|
|
|
public static $articleRightsModerator = [
|
|
|
|
self::EDIT_ALL => 'Groupes des éditeurs et des administrateurs',
|
|
|
|
self::EDIT_OWNER_ADMIN => 'Editeur et groupe des administrateurs'
|
2020-07-12 18:05:33 +02:00
|
|
|
];
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
public static $users = [];
|
|
|
|
|
2020-07-16 09:18:58 +02:00
|
|
|
const BLOG_VERSION = '3.00.dev';
|
2019-02-14 15:17:03 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Édition
|
|
|
|
*/
|
|
|
|
public function add() {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-07-02 19:48:47 +02:00
|
|
|
// Modification de l'userId
|
|
|
|
if($this->getUser('group') === self::GROUP_ADMIN){
|
|
|
|
$newuserid = $this->getInput('blogAddUserId', helper::FILTER_STRING_SHORT, true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$newuserid = $this->getUser('id');
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Incrémente l'id de l'article
|
|
|
|
$articleId = helper::increment($this->getInput('blogAddTitle', helper::FILTER_ID), $this->getData(['page']));
|
|
|
|
$articleId = helper::increment($articleId, (array) $this->getData(['module', $this->getUrl(0)]));
|
|
|
|
$articleId = helper::increment($articleId, array_keys(self::$actions));
|
|
|
|
// Crée l'article
|
|
|
|
$this->setData(['module', $this->getUrl(0), $articleId, [
|
|
|
|
'closeComment' => $this->getInput('blogAddCloseComment', helper::FILTER_BOOLEAN),
|
2020-06-10 16:32:33 +02:00
|
|
|
'mailNotification' => $this->getInput('blogAddMailNotification', helper::FILTER_BOOLEAN),
|
|
|
|
'groupNotification' => $this->getInput('blogAddGroupNotification', helper::FILTER_INT),
|
2018-04-02 08:29:19 +02:00
|
|
|
'comment' => [],
|
|
|
|
'content' => $this->getInput('blogAddContent', null),
|
|
|
|
'picture' => $this->getInput('blogAddPicture', helper::FILTER_STRING_SHORT, true),
|
2020-06-03 09:07:00 +02:00
|
|
|
'hidePicture' => $this->getInput('blogAddHidePicture', helper::FILTER_BOOLEAN),
|
2020-06-10 16:32:33 +02:00
|
|
|
'pictureSize' => $this->getInput('blogAddPictureSize', helper::FILTER_STRING_SHORT),
|
2020-06-10 16:38:53 +02:00
|
|
|
'picturePosition' => $this->getInput('blogAddPicturePosition', helper::FILTER_STRING_SHORT),
|
2018-04-02 08:29:19 +02:00
|
|
|
'publishedOn' => $this->getInput('blogAddPublishedOn', helper::FILTER_DATETIME, true),
|
|
|
|
'state' => $this->getInput('blogAddState', helper::FILTER_BOOLEAN),
|
|
|
|
'title' => $this->getInput('blogAddTitle', helper::FILTER_STRING_SHORT, true),
|
2020-07-02 19:48:47 +02:00
|
|
|
'userId' => $newuserid,
|
2020-07-16 09:21:57 +02:00
|
|
|
'commentMaxlength' => $this->getInput('blogAddlength', null)
|
2018-04-02 08:29:19 +02:00
|
|
|
]]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Nouvel article créé',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Liste des utilisateurs
|
|
|
|
self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname');
|
|
|
|
ksort(self::$users);
|
|
|
|
foreach(self::$users as $userId => &$userFirstname) {
|
|
|
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
|
|
|
}
|
|
|
|
unset($userFirstname);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Nouvel article',
|
|
|
|
'vendor' => [
|
|
|
|
'flatpickr',
|
|
|
|
'tinymce'
|
|
|
|
],
|
|
|
|
'view' => 'add'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Liste des commentaires
|
|
|
|
*/
|
|
|
|
public function comment() {
|
2020-07-02 19:48:47 +02:00
|
|
|
$comments = $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'comment']);
|
|
|
|
self::$commentsDelete = template::button('blogCommentDeleteAll', [
|
|
|
|
'class' => 'blogCommentDeleteAll buttonRed',
|
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDeleteAll/' . $this->getUrl(2).'/' . $_SESSION['csrf'] ,
|
|
|
|
'ico' => 'cancel',
|
|
|
|
'value' => 'Tout effacer'
|
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
// Ids des commentaires par ordre de création
|
|
|
|
$commentIds = array_keys(helper::arrayCollumn($comments, 'createdOn', 'SORT_DESC'));
|
|
|
|
// Pagination
|
2018-12-09 00:52:05 +01:00
|
|
|
$pagination = helper::pagination($commentIds, $this->getUrl(),$this->getData(['config','itemsperPage']));
|
2018-04-02 08:29:19 +02:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
|
|
|
// Commentaires en fonction de la pagination
|
|
|
|
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
|
|
|
// Met en forme le tableau
|
|
|
|
$comment = $comments[$commentIds[$i]];
|
2020-07-16 12:06:51 +02:00
|
|
|
// Bouton d'approbation
|
|
|
|
$buttonApproval = '';
|
|
|
|
if ( $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'commentApprove']) === true) {
|
|
|
|
$buttonApproval = template::button('blogcommentApprove' . $commentIds[$i], [
|
2020-07-16 12:10:20 +02:00
|
|
|
'class' => $comment['approval'] === true ? 'blogCommentReject' : 'blogCommentApprove buttonRed' ,
|
2020-07-16 12:06:51 +02:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/commentApprove/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] ,
|
|
|
|
'value' => $comment['approval'] === true ? 'A' : 'R'
|
|
|
|
]);
|
|
|
|
}
|
2020-06-03 09:07:00 +02:00
|
|
|
self::$comments[] = [
|
2019-12-03 18:19:34 +01:00
|
|
|
utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])),
|
2018-04-02 08:29:19 +02:00
|
|
|
$comment['content'],
|
|
|
|
$comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'],
|
2020-07-16 12:06:51 +02:00
|
|
|
$buttonApproval,
|
2018-04-02 08:29:19 +02:00
|
|
|
template::button('blogCommentDelete' . $commentIds[$i], [
|
|
|
|
'class' => 'blogCommentDelete buttonRed',
|
2020-07-02 19:48:47 +02:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] ,
|
2018-04-02 08:29:19 +02:00
|
|
|
'value' => template::ico('cancel')
|
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-07-06 12:20:46 +02:00
|
|
|
'title' => 'Gestion des commentaires : '. $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'title']),
|
2018-04-02 08:29:19 +02:00
|
|
|
'view' => 'comment'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression de commentaire
|
|
|
|
*/
|
|
|
|
public function commentDelete() {
|
|
|
|
// Le commentaire n'existe pas
|
|
|
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
2019-01-16 19:25:09 +01:00
|
|
|
// Jeton incorrect
|
|
|
|
elseif ($this->getUrl(4) !== $_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
|
|
|
// Suppression
|
|
|
|
else {
|
|
|
|
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3)]);
|
|
|
|
// Valeurs en sortie
|
2020-07-02 19:35:51 +02:00
|
|
|
$this->addOutput([
|
2020-07-02 19:48:47 +02:00
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2),
|
2020-07-02 19:38:52 +02:00
|
|
|
'notification' => 'Commentaire supprimé',
|
2020-07-02 19:35:51 +02:00
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 19:48:47 +02:00
|
|
|
/**
|
|
|
|
* Suppression de tous les commentaires de l'article $this->getUrl(2)
|
|
|
|
*/
|
|
|
|
public function commentDeleteAll() {
|
|
|
|
// 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'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Suppression
|
|
|
|
else {
|
|
|
|
$this->setData(['module', $this->getUrl(0), $this->getUrl(2), 'comment',[] ]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment',
|
|
|
|
'notification' => 'Commentaires supprimés',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 12:06:51 +02:00
|
|
|
/**
|
|
|
|
* Approbation oou désapprobation de commentaire
|
|
|
|
*/
|
|
|
|
public function commentApprove() {
|
|
|
|
// Le commentaire n'existe pas
|
|
|
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Jeton incorrect
|
|
|
|
elseif ($this->getUrl(4) !== $_SESSION['csrf']) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Action non autorisée'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Inversion du statut
|
|
|
|
else {
|
|
|
|
$this->setData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), [
|
|
|
|
'author' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'author']),
|
|
|
|
'content' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'content']),
|
|
|
|
'createdOn' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'createdOn']),
|
|
|
|
'userId' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'userId']),
|
|
|
|
'approval' => !$this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval'])
|
|
|
|
]]);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2),
|
|
|
|
'notification' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) === true ? 'Commentaire approuvé' : 'Commentaire rejeté',
|
|
|
|
'state' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval'])
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function config() {
|
|
|
|
// Ids des articles par ordre de publication
|
|
|
|
$articleIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0)]), 'publishedOn', 'SORT_DESC'));
|
2020-07-16 18:50:57 +02:00
|
|
|
// Gestion des droits d'accès
|
|
|
|
$filterData=[];
|
|
|
|
foreach ($articleIds as $key => $value) {
|
|
|
|
$rights = $this->getData(['module', $this->getUrl(0), $value,'editRights']);
|
|
|
|
// Compatibilité pas de droit stocké placer droit par défaut
|
|
|
|
$rights = empty($rights) ? '02' : $rights;
|
|
|
|
// Check les droits du propriétaire
|
|
|
|
// Check les droits du groupe
|
|
|
|
if (
|
|
|
|
( substr($rights,0,1) === '2'
|
|
|
|
AND $this->getData(['module', $this->getUrl(0), $value,'userId']) === $this->getUser('id')
|
|
|
|
)
|
|
|
|
OR ( $this->getUser('group') >= substr($rights,1,1) )
|
|
|
|
) {
|
|
|
|
$filterData[] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$articleIds = $filterData;
|
2018-04-02 08:29:19 +02:00
|
|
|
// Pagination
|
2018-12-09 00:52:05 +01:00
|
|
|
$pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['config','itemsperPage']));
|
2018-04-02 08:29:19 +02:00
|
|
|
// Liste des pages
|
2020-06-03 09:07:00 +02:00
|
|
|
self::$pages = $pagination['pages'];
|
2018-04-02 08:29:19 +02:00
|
|
|
// Articles en fonction de la pagination
|
|
|
|
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
2020-07-16 10:33:37 +02:00
|
|
|
// Nombre de commentaires à approuver et approuvés
|
2020-07-16 18:50:57 +02:00
|
|
|
$approvals = [];
|
|
|
|
// Compatibilité : vérifier si les données sont disponibles
|
|
|
|
if ( $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ,'approval' ]) !== NULL ) {
|
|
|
|
$approvals = helper::arrayCollumn($this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC');
|
|
|
|
}
|
|
|
|
if ( empty($approvals) ) {
|
2020-07-16 10:33:37 +02:00
|
|
|
$toApprove = 0;
|
|
|
|
$approved = count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment']));
|
2020-07-16 18:50:57 +02:00
|
|
|
} else {
|
|
|
|
$a = array_values($approvals);
|
|
|
|
$toApprove = count(array_keys($a,false));
|
|
|
|
$approved = count(array_keys($a,true));
|
2020-07-16 10:33:37 +02:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Met en forme le tableau
|
|
|
|
self::$articles[] = [
|
2020-07-16 12:24:52 +02:00
|
|
|
'<a href="' . helper::baseurl() . $this->getUrl(0) . '/' . $articleIds[$i] . '" target="_blank" >' .
|
|
|
|
$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'title']) .
|
|
|
|
'</a>',
|
2018-11-13 18:33:22 +01:00
|
|
|
// date('d/m/Y H:i', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])),
|
2018-11-24 14:25:51 +01:00
|
|
|
utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn'])))
|
|
|
|
.' à '.
|
2020-06-03 09:07:00 +02:00
|
|
|
utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn']))),
|
2018-04-02 08:29:19 +02:00
|
|
|
self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])],
|
2020-07-02 19:48:47 +02:00
|
|
|
// Bouton pour afficher les commentaires de l'article
|
|
|
|
template::button('blogConfigComment' . $articleIds[$i], [
|
2020-07-16 12:06:51 +02:00
|
|
|
'class' => ($toApprove || $approved ) > 0 ? 'buttonBlue' : 'buttonGrey' ,
|
|
|
|
'href' => ($toApprove || $approved ) > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '',
|
2020-07-16 10:33:37 +02:00
|
|
|
'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved
|
|
|
|
//'value' => count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment']))
|
2020-07-02 19:48:47 +02:00
|
|
|
]),
|
2018-04-02 08:29:19 +02:00
|
|
|
template::button('blogConfigEdit' . $articleIds[$i], [
|
2019-01-16 19:25:09 +01:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $articleIds[$i] . '/' . $_SESSION['csrf'],
|
2018-04-02 08:29:19 +02:00
|
|
|
'value' => template::ico('pencil')
|
|
|
|
]),
|
|
|
|
template::button('blogConfigDelete' . $articleIds[$i], [
|
|
|
|
'class' => 'blogConfigDelete buttonRed',
|
2019-01-16 19:25:09 +01:00
|
|
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $articleIds[$i] . '/' . $_SESSION['csrf'],
|
2018-04-02 08:29:19 +02:00
|
|
|
'value' => template::ico('cancel')
|
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration du module',
|
|
|
|
'view' => 'config'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression
|
|
|
|
*/
|
|
|
|
public function delete() {
|
2019-01-16 19:25:09 +01:00
|
|
|
if($this->getData(['module', $this->getUrl(0), $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',
|
|
|
|
'notification' => 'Action non autorisée'
|
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 {
|
2019-01-16 19:25:09 +01:00
|
|
|
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]);
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Article supprimé',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Édition
|
|
|
|
*/
|
|
|
|
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
|
|
|
// L'article n'existe pas
|
|
|
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// L'article existe
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
2020-06-03 09:07:00 +02:00
|
|
|
if($this->isPost()) {
|
2020-07-02 19:48:47 +02:00
|
|
|
if($this->getUser('group') === self::GROUP_ADMIN){
|
|
|
|
$newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$newuserid = $this->getUser('id');
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
$articleId = $this->getInput('blogEditTitle', helper::FILTER_ID, true);
|
|
|
|
// Incrémente le nouvel id de l'article
|
|
|
|
if($articleId !== $this->getUrl(2)) {
|
|
|
|
$articleId = helper::increment($articleId, $this->getData(['page']));
|
|
|
|
$articleId = helper::increment($articleId, $this->getData(['module', $this->getUrl(0)]));
|
|
|
|
$articleId = helper::increment($articleId, array_keys(self::$actions));
|
|
|
|
}
|
|
|
|
$this->setData(['module', $this->getUrl(0), $articleId, [
|
2020-07-16 10:33:37 +02:00
|
|
|
'closeComment' => $this->getInput('blogEditCloseComment', helper::FILTER_BOOLEAN),
|
2019-05-02 13:21:48 +02:00
|
|
|
'mailNotification' => $this->getInput('blogEditMailNotification', helper::FILTER_BOOLEAN),
|
|
|
|
'groupNotification' => $this->getInput('blogEditGroupNotification', helper::FILTER_INT),
|
2018-04-02 08:29:19 +02:00
|
|
|
'comment' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment']),
|
|
|
|
'content' => $this->getInput('blogEditContent', null),
|
|
|
|
'picture' => $this->getInput('blogEditPicture', helper::FILTER_STRING_SHORT, true),
|
2020-04-23 19:55:47 +02:00
|
|
|
'hidePicture' => $this->getInput('blogEditHidePicture', helper::FILTER_BOOLEAN),
|
|
|
|
'pictureSize' => $this->getInput('blogEditPictureSize', helper::FILTER_STRING_SHORT),
|
|
|
|
'picturePosition' => $this->getInput('blogEditPicturePosition', helper::FILTER_STRING_SHORT),
|
2018-04-02 08:29:19 +02:00
|
|
|
'publishedOn' => $this->getInput('blogEditPublishedOn', helper::FILTER_DATETIME, true),
|
|
|
|
'state' => $this->getInput('blogEditState', helper::FILTER_BOOLEAN),
|
|
|
|
'title' => $this->getInput('blogEditTitle', helper::FILTER_STRING_SHORT, true),
|
2020-07-02 19:48:47 +02:00
|
|
|
'userId' => $newuserid,
|
2020-07-16 09:21:57 +02:00
|
|
|
'commentMaxlength' => $this->getInput('blogEditCommentMaxlength'),
|
2020-07-16 18:50:57 +02:00
|
|
|
'commentApprove' => $this->getInput('blogEditCommentApprove', helper::FILTER_BOOLEAN),
|
|
|
|
'editRights' => $this->getInput('blogEditRights')
|
2018-04-02 08:29:19 +02:00
|
|
|
]]);
|
|
|
|
// Supprime l'ancien article
|
|
|
|
if($articleId !== $this->getUrl(2)) {
|
|
|
|
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Liste des utilisateurs
|
|
|
|
self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname');
|
|
|
|
ksort(self::$users);
|
|
|
|
foreach(self::$users as $userId => &$userFirstname) {
|
2020-07-16 18:50:57 +02:00
|
|
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']) . ' (' . self::$groupEdits[$this->getData(['user', $userId, 'group'])] . ')';
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
unset($userFirstname);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'title']),
|
|
|
|
'vendor' => [
|
|
|
|
'flatpickr',
|
|
|
|
'tinymce'
|
|
|
|
],
|
|
|
|
'view' => 'edit'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accueil (deux affichages en un pour éviter une url à rallonge)
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
// Affichage d'un article
|
|
|
|
if(
|
|
|
|
$this->getUrl(1)
|
|
|
|
// Protection pour la pagination, un ID ne peut pas être un entier, une page oui
|
|
|
|
AND intval($this->getUrl(1)) === 0
|
|
|
|
) {
|
|
|
|
// L'article n'existe pas
|
|
|
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(1)]) === null) {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'access' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// L'article existe
|
|
|
|
else {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
|
|
|
// Check la capcha
|
|
|
|
if(
|
|
|
|
$this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
|
|
|
|
AND $this->getInput('blogArticleCapcha', helper::FILTER_INT) !== $this->getInput('blogArticleCapchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticleCapchaSecondNumber', helper::FILTER_INT))
|
|
|
|
{
|
|
|
|
self::$inputNotices['blogArticleCapcha'] = 'Incorrect';
|
|
|
|
}
|
|
|
|
// Crée le commentaire
|
|
|
|
$commentId = helper::increment(uniqid(), $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment']));
|
|
|
|
$this->setData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentId, [
|
2018-04-04 21:20:50 +02:00
|
|
|
'author' => $this->getInput('blogArticleAuthor', helper::FILTER_STRING_SHORT, empty($this->getInput('blogArticleUserId')) ? TRUE : FALSE),
|
2020-07-02 19:48:47 +02:00
|
|
|
'content' => $this->getInput('blogArticleContent', false),
|
2018-04-02 08:29:19 +02:00
|
|
|
'createdOn' => time(),
|
|
|
|
'userId' => $this->getInput('blogArticleUserId'),
|
2020-07-16 10:33:37 +02:00
|
|
|
'approval' => !$this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'commentApprove']) // true commentaire publié false en attente de publication
|
2018-04-02 08:29:19 +02:00
|
|
|
]]);
|
2019-05-02 13:21:48 +02:00
|
|
|
// Envoi d'une notification aux administrateurs
|
|
|
|
// Init tableau
|
|
|
|
$to = [];
|
2020-06-03 09:07:00 +02:00
|
|
|
// Liste des destinataires
|
2019-05-02 13:21:48 +02:00
|
|
|
foreach($this->getData(['user']) as $userId => $user) {
|
|
|
|
if ($user['group'] >= $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'groupNotification']) ) {
|
|
|
|
$to[] = $user['mail'];
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 09:07:00 +02:00
|
|
|
// Envoi du mail $sent code d'erreur ou de réussite
|
2020-07-16 13:59:04 +02:00
|
|
|
$notification = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentId, 'approval']) === false ? 'Commentaire déposé en attente d\'approbation.': 'Commentaire déposé.';
|
2019-05-02 13:21:48 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'mailNotification']) === true) {
|
|
|
|
$sent = $this->sendMail(
|
|
|
|
$to,
|
|
|
|
'Nouveau commentaire',
|
|
|
|
'Bonjour' . ' <strong>' . $user['firstname'] . ' ' . $user['lastname'] . '</strong>,<br><br>' .
|
2020-07-16 13:59:04 +02:00
|
|
|
'Nouveau commentaire ' . $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentId, 'approval']) === false ? 'à approuver' : '' .
|
|
|
|
'déposé sur la page "' . $this->getData(['page', $this->getUrl(0), 'title']) . '" :<br><br>'.
|
2020-07-02 19:48:47 +02:00
|
|
|
$this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentId, 'content']),
|
2020-02-26 23:45:49 +01:00
|
|
|
''
|
2019-05-02 13:21:48 +02:00
|
|
|
);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl() . '#comment',
|
2020-07-16 13:59:04 +02:00
|
|
|
'notification' => ($sent === true ? $notification . '<br/>Une notification a été envoyée.' : $notification . '<br/> Erreur de notification : ' . $sent),
|
2020-06-03 09:07:00 +02:00
|
|
|
'state' => ($sent === true ? true : null)
|
2019-05-02 13:21:48 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl() . '#comment',
|
2020-07-16 13:59:04 +02:00
|
|
|
'notification' => $notification,
|
2020-06-03 09:07:00 +02:00
|
|
|
'state' => true
|
2019-05-02 13:21:48 +02:00
|
|
|
]);
|
|
|
|
}
|
2020-06-03 09:07:00 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Ids des commentaires par ordre de publication
|
|
|
|
$commentIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment']), 'createdOn', 'SORT_DESC'));
|
|
|
|
// Pagination
|
2018-12-09 00:52:05 +01:00
|
|
|
$pagination = helper::pagination($commentIds, $this->getUrl(),$this->getData(['config','itemsperPage']),'#comment');
|
2018-04-02 08:29:19 +02:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
2020-07-02 19:48:47 +02:00
|
|
|
// Signature de l'article
|
|
|
|
$userIdArticle = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'userId']);
|
|
|
|
switch ($this->getData(['user', $userIdArticle, 'signature'])){
|
|
|
|
case 1:
|
|
|
|
self::$articleSignature = $userIdArticle;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
self::$articleSignature = $this->getData(['user', $userIdArticle, 'pseudo']);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
self::$articleSignature = $this->getData(['user', $userIdArticle, 'firstname']) . ' ' . $this->getData(['user', $userIdArticle, 'lastname']);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
self::$articleSignature = $this->getData(['user', $userIdArticle, 'lastname']) . ' ' . $this->getData(['user', $userIdArticle, 'firstname']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
self::$articleSignature = $this->getData(['user', $userIdArticle, 'firstname']);
|
|
|
|
}
|
|
|
|
// Signature du commentaire édité
|
|
|
|
if($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')) {
|
|
|
|
$useridcomment = $this->getUser('id');
|
|
|
|
switch ($this->getData(['user', $useridcomment, 'signature'])){
|
|
|
|
case 1:
|
|
|
|
self::$editCommentSignature = $useridcomment;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
self::$editCommentSignature = $this->getData(['user', $useridcomment, 'pseudo']);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
self::$editCommentSignature = $this->getData(['user', $useridcomment, 'firstname']) . ' ' . $this->getData(['user', $useridcomment, 'lastname']);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
self::$editCommentSignature = $this->getData(['user', $useridcomment, 'lastname']) . ' ' . $this->getData(['user', $useridcomment, 'firstname']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
self::$editCommentSignature = $this->getData(['user', $useridcomment, 'firstname']);
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Commentaires en fonction de la pagination
|
|
|
|
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
2020-07-02 19:48:47 +02:00
|
|
|
// Signatures des commentaires
|
|
|
|
$e = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentIds[$i],'userId']);
|
|
|
|
if ($e) {
|
|
|
|
switch ($this->getData(['user', $e, 'signature'])){
|
|
|
|
case 1:
|
|
|
|
self::$commentsSignature[$commentIds[$i]] = $e;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
self::$commentsSignature[$commentIds[$i]] = $this->getData(['user', $e, 'pseudo']);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
self::$commentsSignature[$commentIds[$i]] = $this->getData(['user', $e, 'firstname']) . ' ' . $this->getData(['user', $e, 'lastname']);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
self::$commentsSignature[$commentIds[$i]] = $this->getData(['user', $e, 'lastname']) . ' ' . $this->getData(['user', $e, 'firstname']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self::$commentsSignature[$commentIds[$i]] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentIds[$i],'author']);
|
|
|
|
}
|
2020-07-16 13:59:04 +02:00
|
|
|
// Données du commentaire si approuvé
|
|
|
|
if ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentIds[$i],'approval']) === true ) {
|
|
|
|
self::$comments[$commentIds[$i]] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentIds[$i]]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'title']),
|
2020-07-02 19:48:47 +02:00
|
|
|
'vendor' => [
|
|
|
|
'tinymce'
|
|
|
|
],
|
2018-04-02 08:29:19 +02:00
|
|
|
'view' => 'article'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Liste des articles
|
|
|
|
else {
|
|
|
|
// Ids des articles par ordre de publication
|
|
|
|
$articleIdsPublishedOns = helper::arrayCollumn($this->getData(['module', $this->getUrl(0)]), 'publishedOn', 'SORT_DESC');
|
|
|
|
$articleIdsStates = helper::arrayCollumn($this->getData(['module', $this->getUrl(0)]), 'state', 'SORT_DESC');
|
|
|
|
$articleIds = [];
|
|
|
|
foreach($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
|
|
|
|
if($articlePublishedOn <= time() AND $articleIdsStates[$articleId]) {
|
|
|
|
$articleIds[] = $articleId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Pagination
|
2018-12-09 00:52:05 +01:00
|
|
|
$pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['config','itemsperPage']));
|
2018-04-02 08:29:19 +02:00
|
|
|
// Liste des pages
|
|
|
|
self::$pages = $pagination['pages'];
|
|
|
|
// Articles en fonction de la pagination
|
|
|
|
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
|
|
|
self::$articles[$articleIds[$i]] = $this->getData(['module', $this->getUrl(0), $articleIds[$i]]);
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true,
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 19:48:47 +02:00
|
|
|
}
|