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 >
2023-01-09 10:23:32 +01:00
* @ copyright Copyright ( C ) 2018 - 2023 , Frédéric Tempez
2022-12-29 17:02:20 +01:00
* @ license CC Attribution - NonCommercial - NoDerivatives 4.0 International
2020-09-01 20:48:40 +02:00
* @ link http :// zwiicms . fr /
2018-04-02 08:29:19 +02:00
*/
2022-10-16 18:07:51 +02:00
class blog extends common
{
2018-04-02 08:29:19 +02:00
2023-03-23 07:49:52 +01:00
const VERSION = '6.6' ;
2021-02-18 10:07:05 +01:00
const REALNAME = 'Blog' ;
2022-09-02 18:07:53 +02:00
const DELETE = true ;
const UPDATE = '0.0' ;
2021-04-06 11:20:04 +02:00
const DATADIRECTORY = '' ; // Contenu localisé inclus par défaut (page.json et module.json)
2021-02-18 10:07:05 +01:00
2020-10-11 18:36:20 +02:00
const EDIT_OWNER = 'owner' ;
const EDIT_GROUP = 'group' ;
2020-10-14 11:07:38 +02:00
const EDIT_ALL = 'all' ;
2020-07-12 18:05:33 +02:00
2018-04-02 08:29:19 +02:00
public static $actions = [
2020-10-14 19:17:13 +02:00
'add' => self :: GROUP_MODERATOR ,
'comment' => self :: GROUP_MODERATOR ,
'commentApprove' => self :: GROUP_MODERATOR ,
'commentDelete' => self :: GROUP_MODERATOR ,
'commentDeleteAll' => self :: GROUP_MODERATOR ,
'config' => self :: GROUP_MODERATOR ,
2022-02-18 12:43:48 +01:00
'option' => self :: GROUP_MODERATOR ,
2020-10-14 19:17:13 +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 $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-10-11 18:36:20 +02:00
2020-10-07 19:06:40 +02:00
public static $nbCommentsApproved = 0 ;
2018-04-02 08:29:19 +02:00
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 ' ,
];
2021-04-05 08:59:24 +02:00
// Nombre d'objets par page
2022-03-15 09:16:42 +01:00
public static $ArticlesListed = [
2022-03-15 15:39:44 +01:00
1 => '1 article' ,
2 => '2 articles' ,
2021-04-05 08:59:24 +02:00
4 => '4 articles' ,
2022-03-15 15:39:44 +01:00
6 => '6 articles' ,
2021-04-05 08:59:24 +02:00
8 => '8 articles' ,
2022-03-15 15:39:44 +01:00
10 => '10 articles' ,
12 => '12 articles'
2021-04-05 08:59:24 +02:00
];
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 = [
2022-03-15 09:16:42 +01:00
100 => '100 signes' ,
250 => '250 signes' ,
500 => '500 signes' ,
750 => '750 signes'
];
2022-03-15 15:39:44 +01:00
public static $articlesLenght = [
2022-10-07 20:13:55 +02:00
0 => 'Article complet en pleine page' ,
2023-01-13 17:16:39 +01:00
200 => 'Tableau : couverture + 200 signes' ,
400 => 'Tableau : couverture + 400 signes' ,
600 => 'Tableau : couverture + 600 signes' ,
800 => 'Tableau : couverture + 800 signes'
2020-07-02 19:48:47 +02:00
];
2020-04-23 19:55:47 +02:00
2020-07-16 18:50:57 +02:00
// Permissions d'un article
2020-10-11 18:36:20 +02:00
public static $articleConsent = [
2023-02-10 22:45:26 +01:00
self :: EDIT_ALL => 'Tous les groupes' ,
self :: EDIT_GROUP => 'Groupe du propriétaire' ,
self :: EDIT_OWNER => 'Propriétaire'
2020-07-12 18:05:33 +02:00
];
2023-02-10 17:19:38 +01:00
public static $dateFormats = [
'%d %B %Y' => 'DD MMMM YYYY' ,
'%d/%m/%Y' => 'DD/MM/YYYY' ,
2023-02-10 22:45:26 +01:00
'%m/%d/%Y' => 'MM/DD/YYYY' ,
2023-02-10 17:19:38 +01:00
'%d/%m/%y' => 'DD/MM/YY' ,
'%m/%d/%y' => 'MM/DD/YY' ,
'%d-%m-%Y' => 'DD-MM-YYYY' ,
2023-02-10 22:45:26 +01:00
'%m-%d-%Y' => 'MM-DD-YYYY' ,
2023-02-10 17:19:38 +01:00
'%d-%m-%y' => 'DD-MM-YY' ,
2023-02-10 22:45:26 +01:00
'%m-%d-%y' => 'MM-DD-YY' ,
2023-02-10 17:19:38 +01:00
];
public static $timeFormats = [
'%H:%M' => 'HH:MM' ,
2023-02-10 22:37:51 +01:00
'%I:%M %p' => " HH:MM tt " ,
2023-02-10 17:19:38 +01:00
];
public static $timeFormat = '' ;
public static $dateFormat = '' ;
2022-02-18 12:43:48 +01:00
// Nombre d'articles dans la page de config:
public static $itemsperPage = 8 ;
2020-10-11 18:36:20 +02:00
2018-04-02 08:29:19 +02:00
public static $users = [];
2021-04-05 08:59:24 +02:00
/**
* Mise à jour du module
* Appelée par les fonctions index et config
*/
2022-10-16 18:07:51 +02:00
private function update ()
{
2022-03-16 19:02:07 +01:00
// Initialisation
2022-10-16 18:07:51 +02:00
if ( is_null ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]))) {
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' , '0.0' ]);
2022-03-16 19:02:07 +01:00
}
2021-04-05 08:59:24 +02:00
// Version 5.0
2022-10-16 18:07:51 +02:00
if ( version_compare ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]), '5.0' , '<' )) {
2021-04-05 08:59:24 +02:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'itemsperPage' , 6 ]);
2022-10-16 18:07:51 +02:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' , '5.0' ]);
2021-04-05 08:59:24 +02:00
}
2022-03-16 19:02:07 +01:00
// Version 6.0
2022-10-16 18:07:51 +02:00
if ( version_compare ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]), '6.0' , '<' )) {
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'feeds' , false ]);
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'feedsLabel' , '' ]);
2022-03-16 19:02:07 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'articlesLenght' , 0 ]);
2022-10-16 18:07:51 +02:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' , '6.0' ]);
2022-03-16 19:02:07 +01:00
}
2023-02-10 22:37:51 +01:00
// Version 6.5
if ( version_compare ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]), '6.5' , '<' )) {
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'dateFormat' , '%d %B %Y' ]);
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'timeFormat' , '%H:%M' ]);
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' , '6.5' ]);
}
2021-04-05 08:59:24 +02:00
}
2023-02-10 22:37:51 +01:00
2021-04-05 08:59:24 +02:00
/**
2020-11-18 21:45:36 +01:00
* Flux RSS
*/
2022-10-16 18:07:51 +02:00
public function rss ()
{
2020-11-18 21:45:36 +01:00
// Inclure les classes
2021-03-09 16:59:32 +01:00
include_once 'module/blog/vendor/FeedWriter/Item.php' ;
include_once 'module/blog/vendor/FeedWriter/Feed.php' ;
include_once 'module/blog/vendor/FeedWriter/RSS2.php' ;
include_once 'module/blog/vendor/FeedWriter/InvalidOperationException.php' ;
2020-11-18 21:45:36 +01:00
date_default_timezone_set ( 'UTC' );
$feeds = new \FeedWriter\RSS2 ();
// En-tête
2022-10-16 18:07:51 +02:00
$feeds -> setTitle ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'title' ]));
2020-11-18 21:45:36 +01:00
$feeds -> setLink ( helper :: baseUrl () . $this -> getUrl ( 0 ));
2022-10-16 18:07:51 +02:00
$feeds -> setDescription ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'metaDescription' ]));
2020-11-18 21:45:36 +01:00
$feeds -> setChannelElement ( 'language' , 'fr-FR' );
2022-10-16 18:07:51 +02:00
$feeds -> setDate ( date ( 'r' , time ()));
2020-11-18 21:45:36 +01:00
$feeds -> addGenerator ();
// Corps des articles
2022-04-06 09:46:28 +02:00
$articleIdsPublishedOns = helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]), 'publishedOn' , 'SORT_DESC' );
2022-10-16 18:07:51 +02:00
$articleIdsStates = helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]), 'state' , 'SORT_DESC' );
foreach ( $articleIdsPublishedOns as $articleId => $articlePublishedOn ) {
if ( $articlePublishedOn <= time () and $articleIdsStates [ $articleId ]) {
2020-11-18 21:45:36 +01:00
// Miniature
2022-10-19 14:11:46 +02:00
$parts = pathinfo ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'picture' ]));
$thumb = 'mini_' . $parts [ 'basename' ];
2020-11-18 21:45:36 +01:00
// Créer les articles du flux
$newsArticle = $feeds -> createNewItem ();
2020-11-20 13:44:32 +01:00
// Signature de l'article
2023-02-10 22:45:26 +01:00
$author = $this -> signature ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'userId' ]));
2020-11-18 21:45:36 +01:00
$newsArticle -> addElementArray ([
2023-02-10 22:45:26 +01:00
'title' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'title' ]),
'link' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/' . $articleId ,
'description' => '<img src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'thumb/' . $thumb
. '" alt="' . $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'title' ])
. '" title="' . $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'title' ])
. '" />' .
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'content' ]),
2020-11-18 21:45:36 +01:00
]);
2022-10-16 18:07:51 +02:00
$newsArticle -> setAuthor ( $author , 'no@mail.com' );
$newsArticle -> setId ( helper :: baseUrl () . $this -> getUrl ( 0 ) . '/' . $articleId );
2020-11-20 17:32:38 +01:00
$newsArticle -> setDate ( date ( 'r' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'publishedOn' ])));
2022-10-16 18:07:51 +02:00
if ( file_exists ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'picture' ]))) {
2023-02-10 22:45:26 +01:00
$imageData = getimagesize ( helper :: baseUrl ( false ) . self :: FILE_DIR . 'thumb/' . $thumb );
2022-10-16 18:07:51 +02:00
$newsArticle -> addEnclosure (
2023-02-10 22:45:26 +01:00
helper :: baseUrl ( false ) . self :: FILE_DIR . 'thumb/' . $thumb ,
2022-10-16 18:07:51 +02:00
$imageData [ 0 ] * $imageData [ 1 ],
$imageData [ 'mime' ]
2021-05-26 19:14:53 +02:00
);
}
2020-11-18 21:45:36 +01:00
$feeds -> addItem ( $newsArticle );
}
}
// Valeurs en sortie
$this -> addOutput ([
'display' => self :: DISPLAY_RSS ,
'content' => $feeds -> generateFeed (),
'view' => 'rss'
]);
}
2018-04-02 08:29:19 +02:00
/**
* Édition
*/
2022-10-16 18:07:51 +02:00
public function add ()
{
2018-04-02 08:29:19 +02:00
// Soumission du formulaire
2022-10-16 18:07:51 +02:00
if ( $this -> isPost ()) {
2020-07-02 19:48:47 +02:00
// Modification de l'userId
2022-10-16 18:07:51 +02:00
if ( $this -> getUser ( 'group' ) === self :: GROUP_ADMIN ) {
2020-07-02 19:48:47 +02:00
$newuserid = $this -> getInput ( 'blogAddUserId' , helper :: FILTER_STRING_SHORT , true );
2022-10-16 18:07:51 +02:00
} else {
2020-07-02 19:48:47 +02:00
$newuserid = $this -> getUser ( 'id' );
}
2018-04-02 08:29:19 +02:00
// Incrémente l'id de l'article
2022-03-16 11:53:26 +01:00
$articleId = helper :: increment ( $this -> getInput ( 'blogAddPermalink' ), $this -> getData ([ 'page' ]));
2018-04-02 08:29:19 +02:00
$articleId = helper :: increment ( $articleId , ( array ) $this -> getData ([ 'module' , $this -> getUrl ( 0 )]));
$articleId = helper :: increment ( $articleId , array_keys ( self :: $actions ));
// Crée l'article
2022-10-16 18:07:51 +02:00
$this -> setData ([
'module' ,
2020-10-11 18:36:20 +02:00
$this -> getUrl ( 0 ),
2020-11-18 21:45:14 +01:00
'posts' ,
2023-02-10 22:45:26 +01:00
$articleId ,
[
2020-10-11 18:36:20 +02:00
'content' => $this -> getInput ( 'blogAddContent' , null ),
2022-03-16 11:53:26 +01:00
'picture' => $this -> getInput ( 'blogAddPicture' , helper :: FILTER_STRING_SHORT ),
2020-10-11 18:36:20 +02:00
'hidePicture' => $this -> getInput ( 'blogAddHidePicture' , helper :: FILTER_BOOLEAN ),
'pictureSize' => $this -> getInput ( 'blogAddPictureSize' , helper :: FILTER_STRING_SHORT ),
'picturePosition' => $this -> getInput ( 'blogAddPicturePosition' , helper :: FILTER_STRING_SHORT ),
'publishedOn' => $this -> getInput ( 'blogAddPublishedOn' , helper :: FILTER_DATETIME , true ),
'state' => $this -> getInput ( 'blogAddState' , helper :: FILTER_BOOLEAN ),
'title' => $this -> getInput ( 'blogAddTitle' , helper :: FILTER_STRING_SHORT , true ),
'userId' => $newuserid ,
2023-02-10 22:45:26 +01:00
'editConsent' => $this -> getInput ( 'blogAddConsent' ) === self :: EDIT_GROUP ? $this -> getUser ( 'group' ) : $this -> getInput ( 'blogAddConsent' ),
2020-10-11 18:36:20 +02:00
'commentMaxlength' => $this -> getInput ( 'blogAddCommentMaxlength' ),
'commentApproved' => $this -> getInput ( 'blogAddCommentApproved' , helper :: FILTER_BOOLEAN ),
'commentClose' => $this -> getInput ( 'blogAddCommentClose' , helper :: FILTER_BOOLEAN ),
2023-02-10 22:45:26 +01:00
'commentNotification' => $this -> getInput ( 'blogAddCommentNotification' , helper :: FILTER_BOOLEAN ),
2021-04-05 08:59:24 +02:00
'commentGroupNotification' => $this -> getInput ( 'blogAddCommentGroupNotification' , helper :: FILTER_INT ),
2022-03-16 11:53:26 +01:00
'comment' => []
2020-10-11 18:36:20 +02:00
]
]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Nouvel article créé' ),
2018-04-02 08:29:19 +02:00
'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 18:07:51 +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 ([
2023-01-23 15:44:11 +01:00
'title' => helper :: translate ( 'Rédiger un article' ),
2018-04-02 08:29:19 +02:00
'vendor' => [
'flatpickr' ,
2022-03-15 09:16:42 +01:00
'tinymce' ,
'furl'
2018-04-02 08:29:19 +02:00
],
'view' => 'add'
]);
}
/**
* Liste des commentaires
*/
2022-10-16 18:07:51 +02:00
public function comment ()
{
$comments = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' ]);
2023-02-10 22:45:26 +01:00
self :: $commentsDelete = template :: button ( 'blogCommentDeleteAll' , [
2022-10-16 18:07:51 +02:00
'class' => 'blogCommentDeleteAll buttonRed' ,
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/commentDeleteAll/' . $this -> getUrl ( 2 ) . '/' . $_SESSION [ 'csrf' ],
'value' => 'Tout effacer'
2020-07-02 19:48:47 +02:00
]);
2018-04-02 08:29:19 +02:00
// Ids des commentaires par ordre de création
2022-04-06 09:46:28 +02:00
$commentIds = array_keys ( helper :: arrayColumn ( $comments , 'createdOn' , 'SORT_DESC' ));
2018-04-02 08:29:19 +02:00
// Pagination
2022-10-16 18:07:51 +02:00
$pagination = helper :: pagination ( $commentIds , $this -> getUrl (), $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'itemsperPage' ]));
2018-04-02 08:29:19 +02:00
// Liste des pages
self :: $pages = $pagination [ 'pages' ];
// Commentaires en fonction de la pagination
2022-10-16 18:07:51 +02:00
for ( $i = $pagination [ 'first' ]; $i < $pagination [ 'last' ]; $i ++ ) {
2018-04-02 08:29:19 +02:00
// Met en forme le tableau
$comment = $comments [ $commentIds [ $i ]];
2020-07-16 12:06:51 +02:00
// Bouton d'approbation
$buttonApproval = '' ;
2020-07-17 10:05:24 +02:00
// Compatibilité avec les commentaires des versions précédentes, les valider
2022-10-16 18:07:51 +02:00
$comment [ 'approval' ] = array_key_exists ( 'approval' , $comment ) === false ? true : $comment [ 'approval' ];
2023-02-10 22:45:26 +01:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'commentApproved' ]) === true ) {
2020-10-15 21:13:48 +02:00
$buttonApproval = template :: button ( 'blogCommentApproved' . $commentIds [ $i ], [
2022-10-16 18:07:51 +02:00
'class' => $comment [ 'approval' ] === true ? 'blogCommentRejected buttonGreen' : 'blogCommentApproved buttonRed' ,
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/commentApprove/' . $this -> getUrl ( 2 ) . '/' . $commentIds [ $i ] . '/' . $_SESSION [ 'csrf' ],
2023-01-23 15:44:11 +01:00
'value' => $comment [ 'approval' ] === true ? 'A' : 'R' ,
2023-01-23 18:07:22 +01:00
'help' => $comment [ 'approval' ] === true ? 'Approuvé' : 'Rejeté' ,
2020-07-16 12:06:51 +02:00
]);
}
2023-02-11 10:02:44 +01:00
self :: $dateFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'dateFormat' ]);
self :: $timeFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'timeFormat' ]);
2020-06-03 09:07:00 +02:00
self :: $comments [] = [
2023-02-11 10:02:44 +01:00
helper :: dateUTF8 ( self :: $dateFormat , $comment [ 'createdOn' ]) . ' - ' . helper :: dateUTF8 ( self :: $timeFormat , $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' ,
2022-10-16 18:07:51 +02:00
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/commentDelete/' . $this -> getUrl ( 2 ) . '/' . $commentIds [ $i ] . '/' . $_SESSION [ 'csrf' ],
2022-02-25 10:04:46 +01:00
'value' => template :: ico ( 'trash' )
2018-04-02 08:29:19 +02:00
])
];
}
// Valeurs en sortie
$this -> addOutput ([
2023-01-23 15:44:11 +01:00
'title' => helper :: translate ( 'Gestion des commentaires' ),
2018-04-02 08:29:19 +02:00
'view' => 'comment'
]);
}
/**
* Suppression de commentaire
*/
2022-10-16 18:07:51 +02:00
public function commentDelete ()
{
2018-04-02 08:29:19 +02:00
// Le commentaire n'existe pas
2022-10-16 18:07:51 +02:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 )]) === null ) {
2018-04-02 08:29:19 +02:00
// 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 ([
2023-02-10 22:45:26 +01:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Action interdite' )
2019-01-16 19:25:09 +01:00
]);
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
// Suppression
else {
2020-11-17 08:52:32 +01:00
$this -> deleteData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 )]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
2020-07-02 19:35:51 +02:00
$this -> addOutput ([
2022-10-16 18:07:51 +02:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/comment/' . $this -> getUrl ( 2 ),
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Commentaire supprimé' ),
2020-07-02 19:35:51 +02:00
'state' => true
]);
}
}
2020-07-02 19:48:47 +02:00
/**
2023-02-23 20:19:54 +01:00
* Suppression de tous les commentairess de l ' article $this -> getUrl ( 2 )
2020-07-02 19:48:47 +02:00
*/
2022-10-16 18:07:51 +02:00
public function commentDeleteAll ()
{
2020-07-02 19:48:47 +02:00
// Jeton incorrect
if ( $this -> getUrl ( 3 ) !== $_SESSION [ 'csrf' ]) {
// Valeurs en sortie
$this -> addOutput ([
2023-02-10 22:45:26 +01:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2022-10-11 10:33:44 +02:00
'notification' => 'Action interdite'
2020-07-02 19:48:47 +02:00
]);
}
// Suppression
else {
2023-02-10 22:45:26 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , []]);
2020-07-02 19:48:47 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/comment' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Commentaires supprimés' ),
2020-07-02 19:48:47 +02:00
'state' => true
]);
}
}
2020-07-16 12:06:51 +02:00
/**
* Approbation oou désapprobation de commentaire
*/
2022-10-16 18:07:51 +02:00
public function commentApprove ()
{
2020-07-16 12:06:51 +02:00
// Le commentaire n'existe pas
2023-02-10 22:45:26 +01:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 )]) === null ) {
2020-07-16 12:06:51 +02:00
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
// Jeton incorrect
elseif ( $this -> getUrl ( 4 ) !== $_SESSION [ 'csrf' ]) {
// Valeurs en sortie
$this -> addOutput ([
2023-02-10 22:45:26 +01:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Action interdite' )
2020-07-16 12:06:51 +02:00
]);
}
// Inversion du statut
else {
2023-02-10 22:45:26 +01:00
$approved = ! $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 ), 'approval' ]);
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'posts' , $this -> getUrl ( 2 ),
'comment' , $this -> getUrl ( 3 ),
[
'author' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 ), 'author' ]),
'content' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 ), 'content' ]),
'createdOn' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 ), 'createdOn' ]),
'userId' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' , $this -> getUrl ( 3 ), 'userId' ]),
'approval' => $approved
]
]);
2020-07-16 12:06:51 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-16 18:07:51 +02:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/comment/' . $this -> getUrl ( 2 ),
2023-02-10 22:45:26 +01:00
'notification' => $approved ? helper :: translate ( 'Commentaire approuvé' ) : helper :: translate ( 'Commentaire rejeté' ),
2020-10-28 06:29:49 +01:00
'state' => $approved
2020-07-16 12:06:51 +02:00
]);
}
}
2018-04-02 08:29:19 +02:00
/**
* Configuration
*/
2022-10-16 18:07:51 +02:00
public function config ()
{
2022-02-18 12:43:48 +01:00
2023-02-23 22:14:26 +01:00
// Mise à jour des données de module
$this -> update ();
2022-02-18 12:43:48 +01:00
// Ids des articles par ordre de publication
2022-04-06 09:46:28 +02:00
$articleIds = array_keys ( helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]), 'publishedOn' , 'SORT_DESC' ));
2022-02-18 12:43:48 +01:00
// Gestion des droits d'accès
2022-10-16 18:07:51 +02:00
$filterData = [];
2022-02-18 12:43:48 +01:00
foreach ( $articleIds as $key => $value ) {
if (
2023-02-10 22:45:26 +01:00
( // Propriétaire
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $value , 'editConsent' ]) === self :: EDIT_OWNER
and ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $value , 'userId' ]) === $this -> getUser ( 'id' )
2022-10-16 18:07:51 +02:00
or $this -> getUser ( 'group' ) === self :: GROUP_ADMIN )
2022-02-18 12:43:48 +01:00
)
2022-10-16 18:07:51 +02:00
or (
2022-02-18 12:43:48 +01:00
// Groupe
2023-02-10 22:45:26 +01:00
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $value , 'editConsent' ]) !== self :: EDIT_OWNER
and $this -> getUser ( 'group' ) >= $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $value , 'editConsent' ])
2022-02-18 12:43:48 +01:00
)
2022-10-16 18:07:51 +02:00
or (
2022-02-18 12:43:48 +01:00
// Tout le monde
2023-02-10 22:45:26 +01:00
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $value , 'editConsent' ]) === self :: EDIT_ALL
2022-02-18 12:43:48 +01:00
)
) {
$filterData [] = $value ;
}
}
$articleIds = $filterData ;
// Pagination
2022-10-16 18:07:51 +02:00
$pagination = helper :: pagination ( $articleIds , $this -> getUrl (), self :: $itemsperPage );
2022-02-18 12:43:48 +01:00
// Liste des pages
self :: $pages = $pagination [ 'pages' ];
2023-02-11 10:02:44 +01:00
// Format de temps
self :: $dateFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'dateFormat' ]);
self :: $timeFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'timeFormat' ]);
2022-02-18 12:43:48 +01:00
// Articles en fonction de la pagination
2022-10-16 18:07:51 +02:00
for ( $i = $pagination [ 'first' ]; $i < $pagination [ 'last' ]; $i ++ ) {
2022-02-18 12:43:48 +01:00
// Nombre de commentaires à approuver et approuvés
2023-02-10 22:45:26 +01:00
$approvals = helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'comment' ]), 'approval' , 'SORT_DESC' );
2022-10-16 18:07:51 +02:00
if ( is_array ( $approvals )) {
2022-02-18 12:43:48 +01:00
$a = array_values ( $approvals );
2022-10-16 18:07:51 +02:00
$toApprove = count ( array_keys ( $a , false ));
$approved = count ( array_keys ( $a , true ));
2022-02-18 12:43:48 +01:00
} else {
$toApprove = 0 ;
2022-10-16 18:07:51 +02:00
$approved = count ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'comment' ]));
2022-02-18 12:43:48 +01:00
}
// Met en forme le tableau
self :: $articles [] = [
'<a href="' . helper :: baseurl () . $this -> getUrl ( 0 ) . '/' . $articleIds [ $i ] . '" target="_blank" >' .
2023-02-10 22:45:26 +01:00
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'title' ]) .
'</a>' ,
2023-02-11 10:02:44 +01:00
helper :: dateUTF8 ( self :: $dateFormat , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'publishedOn' ])) . ' - ' . helper :: dateUTF8 ( self :: $timeFormat , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'publishedOn' ])),
2022-02-18 12:43:48 +01:00
self :: $states [ $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ], 'state' ])],
// Bouton pour afficher les commentaires de l'article
template :: button ( 'blogConfigComment' . $articleIds [ $i ], [
2023-02-10 22:45:26 +01:00
'class' => ( $toApprove || $approved ) > 0 ? '' : 'buttonGrey' ,
2022-10-16 18:07:51 +02:00
'href' => ( $toApprove || $approved ) > 0 ? helper :: baseUrl () . $this -> getUrl ( 0 ) . '/comment/' . $articleIds [ $i ] : '' ,
2022-02-18 12:43:48 +01:00
'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved ,
2023-02-10 22:45:26 +01:00
'help' => ( $toApprove || $approved ) > 0 ? 'Éditer / Approuver les commentaires' : ''
2022-02-18 12:43:48 +01:00
]),
template :: button ( 'blogConfigEdit' . $articleIds [ $i ], [
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/edit/' . $articleIds [ $i ] . '/' . $_SESSION [ 'csrf' ],
2023-01-23 15:44:11 +01:00
'value' => template :: ico ( 'pencil' )
2022-02-18 12:43:48 +01:00
]),
template :: button ( 'blogConfigDelete' . $articleIds [ $i ], [
'class' => 'blogConfigDelete buttonRed' ,
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/delete/' . $articleIds [ $i ] . '/' . $_SESSION [ 'csrf' ],
2023-01-23 15:44:11 +01:00
'value' => template :: ico ( 'trash' )
2022-02-18 12:43:48 +01:00
])
];
}
// Valeurs en sortie
$this -> addOutput ([
2023-01-23 15:44:11 +01:00
'title' => helper :: translate ( 'Configuration du module' ),
2022-02-18 12:43:48 +01:00
'view' => 'config'
]);
}
2022-10-16 18:07:51 +02:00
public function option ()
{
2023-02-23 22:14:26 +01:00
2020-11-16 18:39:32 +01:00
// Soumission du formulaire
2022-10-16 18:07:51 +02:00
if ( $this -> isPost ()) {
2023-02-10 22:45:26 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'config' ,
[
'feeds' => $this -> getInput ( 'blogOptionShowFeeds' , helper :: FILTER_BOOLEAN ),
'feedsLabel' => $this -> getInput ( 'blogOptionFeedslabel' , helper :: FILTER_STRING_SHORT ),
'itemsperPage' => $this -> getInput ( 'blogOptionItemsperPage' , helper :: FILTER_INT , true ),
'articlesLenght' => $this -> getInput ( 'blogOptionArticlesLenght' , helper :: FILTER_INT ),
'versionData' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]),
'dateFormat' => $this -> getInput ( 'blogOptionDateFormat' ),
'timeFormat' => $this -> getInput ( 'blogOptionTimeFormat' ),
]
]);
2020-11-16 18:39:32 +01:00
// Valeurs en sortie
$this -> addOutput ([
2022-02-18 12:43:48 +01:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/option' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2020-11-16 18:39:32 +01:00
'state' => true
]);
2022-10-10 09:48:00 +02:00
}
// Valeurs en sortie
2022-10-16 18:07:51 +02:00
$this -> addOutput ([
2023-02-13 15:06:43 +01:00
'title' => helper :: translate ( 'Options de configuration' ),
2022-10-16 18:07:51 +02:00
'view' => 'option'
]);
2018-04-02 08:29:19 +02:00
}
2022-02-18 12:43:48 +01:00
2018-04-02 08:29:19 +02:00
/**
* Suppression
*/
2022-10-16 18:07:51 +02:00
public function delete ()
{
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 ([
2023-02-10 22:45:26 +01:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( '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 {
2020-11-17 08:52:32 +01: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' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Article supprimé' ),
2018-04-02 08:29:19 +02:00
'state' => true
]);
}
}
/**
* Édition
*/
2022-10-16 18:07:51 +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' ,
2023-02-10 22:45:26 +01:00
'notification' => helper :: translate ( 'Action interdite' )
2019-01-16 19:25:09 +01:00
]);
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
// L'article n'existe pas
2022-10-16 18:07:51 +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
]);
}
// L'article existe
else {
// Soumission du formulaire
2022-10-16 18:07:51 +02:00
if ( $this -> isPost ()) {
if ( $this -> getUser ( 'group' ) === self :: GROUP_ADMIN ) {
2020-07-02 19:48:47 +02:00
$newuserid = $this -> getInput ( 'blogEditUserId' , helper :: FILTER_STRING_SHORT , true );
2022-10-16 18:07:51 +02:00
} else {
2020-07-02 19:48:47 +02:00
$newuserid = $this -> getUser ( 'id' );
}
2022-03-16 11:53:26 +01:00
$articleId = $this -> getInput ( 'blogEditPermalink' , null , true );
2018-04-02 08:29:19 +02:00
// Incrémente le nouvel id de l'article
2022-10-16 18:07:51 +02:00
if ( $articleId !== $this -> getUrl ( 2 )) {
2018-04-02 08:29:19 +02:00
$articleId = helper :: increment ( $articleId , $this -> getData ([ 'page' ]));
2022-10-16 18:07:51 +02:00
$articleId = helper :: increment ( $articleId , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]));
2018-04-02 08:29:19 +02:00
$articleId = helper :: increment ( $articleId , array_keys ( self :: $actions ));
}
2022-10-16 18:07:51 +02:00
$this -> setData ([
'module' ,
2020-10-11 18:36:20 +02:00
$this -> getUrl ( 0 ),
2020-11-18 21:45:14 +01:00
'posts' ,
2023-02-10 22:45:26 +01:00
$articleId ,
[
2022-03-15 09:16:42 +01:00
'title' => $this -> getInput ( 'blogEditTitle' , helper :: FILTER_STRING_SHORT , true ),
2023-02-10 22:45:26 +01:00
'comment' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'comment' ]),
2020-10-11 18:36:20 +02:00
'content' => $this -> getInput ( 'blogEditContent' , null ),
2022-03-16 11:53:26 +01:00
'picture' => $this -> getInput ( 'blogEditPicture' , helper :: FILTER_STRING_SHORT ),
2020-10-11 18:36:20 +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 ),
'publishedOn' => $this -> getInput ( 'blogEditPublishedOn' , helper :: FILTER_DATETIME , true ),
'state' => $this -> getInput ( 'blogEditState' , helper :: FILTER_BOOLEAN ),
'userId' => $newuserid ,
2020-10-15 21:13:48 +02:00
'editConsent' => $this -> getInput ( 'blogEditConsent' ) === self :: EDIT_GROUP ? $this -> getUser ( 'group' ) : $this -> getInput ( 'blogEditConsent' ),
2020-10-13 19:07:10 +02:00
'commentMaxlength' => $this -> getInput ( 'blogEditCommentMaxlength' ),
2020-10-11 18:36:20 +02:00
'commentApproved' => $this -> getInput ( 'blogEditCommentApproved' , helper :: FILTER_BOOLEAN ),
'commentClose' => $this -> getInput ( 'blogEditCommentClose' , helper :: FILTER_BOOLEAN ),
2023-02-10 22:45:26 +01:00
'commentNotification' => $this -> getInput ( 'blogEditCommentNotification' , helper :: FILTER_BOOLEAN ),
2020-10-11 18:36:20 +02:00
'commentGroupNotification' => $this -> getInput ( 'blogEditCommentGroupNotification' , helper :: FILTER_INT )
]
]);
2018-04-02 08:29:19 +02:00
// Supprime l'ancien article
2022-10-16 18:07:51 +02:00
if ( $articleId !== $this -> getUrl ( 2 )) {
2020-11-17 08:52:32 +01: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' ,
2023-01-23 15:44:11 +01:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2018-04-02 08:29:19 +02:00
'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 18:07:51 +02:00
foreach ( self :: $users as $userId => & $userFirstname ) {
// Les membres ne sont pas éditeurs, les exclure de la liste
if ( $this -> getData ([ 'user' , $userId , 'group' ]) < self :: GROUP_MODERATOR ) {
2020-09-28 16:44:01 +02:00
unset ( self :: $users [ $userId ]);
2020-10-11 18:36:20 +02:00
}
2023-02-10 22:45:26 +01: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 ([
2020-11-17 08:52:32 +01:00
'title' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 2 ), 'title' ]),
2018-04-02 08:29:19 +02:00
'vendor' => [
'flatpickr' ,
2022-03-15 09:16:42 +01:00
'tinymce' ,
'furl'
2018-04-02 08:29:19 +02:00
],
'view' => 'edit'
]);
}
}
/**
* Accueil ( deux affichages en un pour éviter une url à rallonge )
*/
2022-10-16 18:07:51 +02:00
public function index ()
{
2021-04-05 08:59:24 +02:00
// Mise à jour des données de module
$this -> update ();
2018-04-02 08:29:19 +02:00
// Affichage d'un article
2022-10-16 18:07:51 +02:00
if (
2018-04-02 08:29:19 +02:00
$this -> getUrl ( 1 )
// Protection pour la pagination, un ID ne peut pas être un entier, une page oui
2022-10-16 18:07:51 +02:00
and intval ( $this -> getUrl ( 1 )) === 0
2018-04-02 08:29:19 +02:00
) {
// L'article n'existe pas
2022-10-16 18:07:51 +02:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 )]) === null ) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
// L'article existe
else {
// Soumission du formulaire
2022-10-16 18:07:51 +02:00
if ( $this -> isPost ()) {
2020-08-10 19:07:17 +02:00
// Check la captcha
2022-10-16 18:07:51 +02:00
if (
2018-04-02 08:29:19 +02:00
$this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
2020-10-01 15:50:19 +02:00
//AND $this->getInput('blogArticlecaptcha', helper::FILTER_INT) !== $this->getInput('blogArticlecaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticlecaptchaSecondNumber', helper::FILTER_INT))
2022-10-16 18:07:51 +02:00
and password_verify ( $this -> getInput ( 'blogArticleCaptcha' , helper :: FILTER_INT ), $this -> getInput ( 'blogArticleCaptchaResult' )) === false
) {
2020-10-04 12:16:37 +02:00
self :: $inputNotices [ 'blogArticleCaptcha' ] = 'Incorrect' ;
2018-04-02 08:29:19 +02:00
}
// Crée le commentaire
2023-02-10 22:45:26 +01:00
$commentId = helper :: increment ( uniqid (), $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' ]));
2020-10-03 14:48:00 +02:00
$content = $this -> getInput ( 'blogArticleContent' , false );
2023-02-10 22:45:26 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'posts' , $this -> getUrl ( 1 ),
'comment' ,
$commentId ,
[
'author' => $this -> getInput ( 'blogArticleAuthor' , helper :: FILTER_STRING_SHORT , empty ( $this -> getInput ( 'blogArticleUserId' )) ? TRUE : FALSE ),
'content' => $content ,
'createdOn' => time (),
'userId' => $this -> getInput ( 'blogArticleUserId' ),
'approval' => ! $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'commentApproved' ]) // true commentaire publié false en attente de publication
]
]);
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
2022-10-16 18:07:51 +02:00
foreach ( $this -> getData ([ 'user' ]) as $userId => $user ) {
2023-02-10 22:45:26 +01:00
if ( $user [ 'group' ] >= $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'commentGroupNotification' ])) {
2019-05-02 13:21:48 +02:00
$to [] = $user [ 'mail' ];
2021-01-08 10:49:31 +01:00
$firstname [] = $user [ 'firstname' ];
$lastname [] = $user [ 'lastname' ];
2019-05-02 13:21:48 +02:00
}
}
2020-06-03 09:07:00 +02:00
// Envoi du mail $sent code d'erreur ou de réussite
2023-02-10 22:45:26 +01:00
$notification = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'commentApproved' ]) === true ? 'Commentaire déposé en attente d\'approbation' : 'Commentaire déposé' ;
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'commentNotification' ]) === true ) {
2021-01-08 10:49:31 +01:00
$error = 0 ;
2022-10-16 18:07:51 +02:00
foreach ( $to as $key => $adress ) {
2021-01-08 10:49:31 +01:00
$sent = $this -> sendMail (
$adress ,
'Nouveau commentaire déposé' ,
'Bonjour' . ' <strong>' . $firstname [ $key ] . ' ' . $lastname [ $key ] . '</strong>,<br><br>' .
2023-02-10 22:45:26 +01:00
'L\'article <a href="' . helper :: baseUrl () . $this -> getUrl ( 0 ) . '/ ' . $this -> getUrl ( 1 ) . '">' . $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'title' ]) . '</a> a reçu un nouveau commentaire.<br><br>' ,
2023-02-25 22:17:17 +01:00
null ,
$this -> getData ([ 'config' , 'smtp' , 'from' ]),
2021-01-08 10:49:31 +01:00
);
2023-02-10 22:45:26 +01:00
if ( $sent === false )
$error ++ ;
2021-01-08 10:49:31 +01:00
}
2019-05-02 13:21:48 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl () . '#comment' ,
2021-01-08 10:49:31 +01:00
'notification' => ( $error === 0 ? $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
]);
}
2018-04-02 08:29:19 +02:00
}
2020-10-04 12:21:46 +02:00
// Ids des commentaires approuvés par ordre de publication
2020-11-18 21:45:36 +01:00
$commentsApproved = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' ]);
2020-10-11 18:36:20 +02:00
if ( $commentsApproved ) {
2022-10-16 18:07:51 +02:00
foreach ( $commentsApproved as $key => $value ) {
2023-02-10 22:45:26 +01:00
if ( $value [ 'approval' ] === false )
unset ( $commentsApproved [ $key ]);
2020-10-11 18:36:20 +02:00
}
// Ligne suivante si affichage du nombre total de commentaires approuvés sous l'article
self :: $nbCommentsApproved = count ( $commentsApproved );
2020-10-04 12:21:46 +02:00
}
2022-04-06 09:46:28 +02:00
$commentIds = array_keys ( helper :: arrayColumn ( $commentsApproved , 'createdOn' , 'SORT_DESC' ));
2018-04-02 08:29:19 +02:00
// Pagination
2022-10-16 18:07:51 +02:00
$pagination = helper :: pagination ( $commentIds , $this -> getUrl (), $this -> getData ([ 'module' , $this -> getUrl ( 0 ), '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
2023-02-10 22:45:26 +01:00
self :: $articleSignature = $this -> signature ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'userId' ]));
2020-07-02 19:48:47 +02:00
// Signature du commentaire édité
2022-10-16 18:07:51 +02:00
if ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )) {
2020-11-20 13:44:32 +01:00
self :: $editCommentSignature = $this -> signature ( $this -> getUser ( 'id' ));
2020-07-02 19:48:47 +02:00
}
2018-04-02 08:29:19 +02:00
// Commentaires en fonction de la pagination
2022-10-16 18:07:51 +02:00
for ( $i = $pagination [ 'first' ]; $i < $pagination [ 'last' ]; $i ++ ) {
2020-07-02 19:48:47 +02:00
// Signatures des commentaires
2023-02-10 22:45:26 +01:00
$e = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' , $commentIds [ $i ], 'userId' ]);
2020-07-02 19:48:47 +02:00
if ( $e ) {
2020-11-20 13:44:32 +01:00
self :: $commentsSignature [ $commentIds [ $i ]] = $this -> signature ( $e );
2020-07-02 19:48:47 +02:00
} else {
2023-02-10 22:45:26 +01:00
self :: $commentsSignature [ $commentIds [ $i ]] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' , $commentIds [ $i ], 'author' ]);
2020-07-02 19:48:47 +02:00
}
2020-07-16 13:59:04 +02:00
// Données du commentaire si approuvé
2022-10-16 18:07:51 +02:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' , $commentIds [ $i ], 'approval' ]) === true ) {
2020-11-18 21:45:36 +01:00
self :: $comments [ $commentIds [ $i ]] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'comment' , $commentIds [ $i ]]);
2020-07-16 13:59:04 +02:00
}
2018-04-02 08:29:19 +02:00
}
2023-02-10 22:45:26 +01:00
// Format de temps
self :: $dateFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'dateFormat' ]);
self :: $timeFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'timeFormat' ]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'showBarEditButton' => true ,
2023-02-10 22:45:26 +01:00
'title' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $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
2022-10-16 18:07:51 +02:00
$articleIdsPublishedOns = helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]), 'publishedOn' , 'SORT_DESC' );
2022-04-06 09:46:28 +02:00
$articleIdsStates = helper :: arrayColumn ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' ]), 'state' , 'SORT_DESC' );
2018-04-02 08:29:19 +02:00
$articleIds = [];
2022-10-16 18:07:51 +02:00
foreach ( $articleIdsPublishedOns as $articleId => $articlePublishedOn ) {
if ( $articlePublishedOn <= time () and $articleIdsStates [ $articleId ]) {
2018-04-02 08:29:19 +02:00
$articleIds [] = $articleId ;
2022-03-15 09:16:42 +01:00
// Nombre de commentaires approuvés par article
2022-10-16 18:07:51 +02:00
if ( is_array ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'comment' ]))) {
self :: $comments [ $articleId ] = count ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleId , 'comment' ]));
2022-09-02 18:07:53 +02:00
} else {
2022-10-16 18:07:51 +02:00
self :: $comments [ $articleId ] = '0' ;
}
2018-04-02 08:29:19 +02:00
}
}
// Pagination
2022-10-16 18:07:51 +02:00
$pagination = helper :: pagination ( $articleIds , $this -> getUrl (), $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'itemsperPage' ]));
2018-04-02 08:29:19 +02:00
// Liste des pages
self :: $pages = $pagination [ 'pages' ];
// Articles en fonction de la pagination
2022-10-16 18:07:51 +02:00
for ( $i = $pagination [ 'first' ]; $i < $pagination [ 'last' ]; $i ++ ) {
2020-11-17 08:52:32 +01:00
self :: $articles [ $articleIds [ $i ]] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $articleIds [ $i ]]);
2018-04-02 08:29:19 +02:00
}
2023-02-10 17:19:38 +01:00
// Format de temps
self :: $dateFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'dateFormat' ]);
self :: $timeFormat = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'timeFormat' ]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'showBarEditButton' => true ,
'showPageContent' => true ,
'view' => 'index'
]);
}
}
2020-11-20 13:44:32 +01:00
/**
* Retourne la signature d ' un utilisateur
*/
2022-10-16 18:07:51 +02:00
public 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' ]);
}
}
2023-02-10 22:45:26 +01:00
}