Merge blog folder

This commit is contained in:
Fred 2020-07-02 19:48:47 +02:00
parent 23a1e929a3
commit 457b536fca
8 changed files with 195 additions and 53 deletions

162
module/blog/blog.php Normal file → Executable file
View File

@ -18,6 +18,7 @@ class blog extends common {
'add' => self::GROUP_MODERATOR,
'comment' => self::GROUP_MODERATOR,
'commentDelete' => self::GROUP_MODERATOR,
'commentDeleteAll' => self::GROUP_MODERATOR,
'config' => self::GROUP_MODERATOR,
'delete' => self::GROUP_MODERATOR,
'edit' => self::GROUP_MODERATOR,
@ -26,8 +27,21 @@ class blog extends common {
public static $articles = [];
// Signature de l'article
public static $articleSignature = '';
// Signature du commentaire
public static $editCommentSignature = '';
public static $comments = [];
public static $messageComments;
public static $commentsDelete;
// Signatures des commentaires déjà saisis
public static $commentsSignature = [];
public static $pages;
public static $states = [
@ -48,10 +62,18 @@ class blog extends common {
'right' => 'À droite ',
];
//Paramètre longueur maximale des commentaires en nb de caractères
public static $longueur_comment = [
'500' => '500',
'1000' => '1000',
'2000' => '2000',
'5000' => '5000',
'10000' => '10000'
];
public static $users = [];
const BLOG_VERSION = '2.02';
const BLOG_VERSION = '2.04';
/**
* Édition
@ -59,6 +81,13 @@ class blog extends common {
public function add() {
// Soumission du formulaire
if($this->isPost()) {
// 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');
}
// 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)]));
@ -77,7 +106,8 @@ class blog extends common {
'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' => $this->getInput('blogAddUserId', helper::FILTER_ID, true)
'userId' => $newuserid,
'maxlengthcomment' => $this->getInput('blogAddlength', null)
]]);
// Valeurs en sortie
$this->addOutput([
@ -108,14 +138,14 @@ class blog extends common {
* Liste des commentaires
*/
public function comment() {
// Liste les commentaires
$comments = [];
foreach((array) $this->getData(['module', $this->getUrl(0)]) as $articleId => $article) {
foreach($article['comment'] as &$comment) {
$comment['articleId'] = $articleId;
}
$comments += $article['comment'];
}
$comments = $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'comment']);
self::$messageComments = '<h2>Commentaires de l\'article '. $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'title']).'</h2>';
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'
]);
// Ids des commentaires par ordre de création
$commentIds = array_keys(helper::arrayCollumn($comments, 'createdOn', 'SORT_DESC'));
// Pagination
@ -132,7 +162,7 @@ class blog extends common {
$comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'],
template::button('blogCommentDelete' . $commentIds[$i], [
'class' => 'blogCommentDelete buttonRed',
'href' => helper::baseUrl() . $this->getUrl(0) . '/comment-delete/' . $comment['articleId'] . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] ,
'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] ,
'value' => template::ico('cancel')
])
];
@ -168,13 +198,37 @@ class blog extends common {
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3)]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment',
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2),
'notification' => 'Commentaire supprimé',
'state' => true
]);
}
}
/**
* 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
]);
}
}
/**
* Configuration
*/
@ -195,6 +249,12 @@ class blog extends common {
.' à '.
utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'publishedOn']))),
self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])],
// Bouton pour afficher les commentaires de l'article
template::button('blogConfigComment' . $articleIds[$i], [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i],
'value' => count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment']))
]),
template::button('blogConfigEdit' . $articleIds[$i], [
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $articleIds[$i] . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil')
@ -266,6 +326,12 @@ class blog extends common {
else {
// Soumission du formulaire
if($this->isPost()) {
if($this->getUser('group') === self::GROUP_ADMIN){
$newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true);
}
else{
$newuserid = $this->getUser('id');
}
$articleId = $this->getInput('blogEditTitle', helper::FILTER_ID, true);
// Incrémente le nouvel id de l'article
if($articleId !== $this->getUrl(2)) {
@ -286,7 +352,8 @@ class blog extends common {
'publishedOn' => $this->getInput('blogEditPublishedOn', helper::FILTER_DATETIME, true),
'state' => $this->getInput('blogEditState', helper::FILTER_BOOLEAN),
'title' => $this->getInput('blogEditTitle', helper::FILTER_STRING_SHORT, true),
'userId' => $this->getInput('blogEditUserId', helper::FILTER_ID, true)
'userId' => $newuserid,
'maxlengthcomment' => $this->getInput('blogEditlength', null)
]]);
// Supprime l'ancien article
if($articleId !== $this->getUrl(2)) {
@ -350,7 +417,7 @@ class blog extends common {
$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, [
'author' => $this->getInput('blogArticleAuthor', helper::FILTER_STRING_SHORT, empty($this->getInput('blogArticleUserId')) ? TRUE : FALSE),
'content' => $this->getInput('blogArticleContent', helper::FILTER_STRING_SHORT, true),
'content' => $this->getInput('blogArticleContent', false),
'createdOn' => time(),
'userId' => $this->getInput('blogArticleUserId'),
]]);
@ -370,7 +437,8 @@ class blog extends common {
$to,
'Nouveau commentaire',
'Bonjour' . ' <strong>' . $user['firstname'] . ' ' . $user['lastname'] . '</strong>,<br><br>' .
'Nouveau commentaire déposé sur la page "' . $this->getData(['page', $this->getUrl(0), 'title']) . '" :<br><br>',
'Nouveau commentaire déposé sur la page "' . $this->getData(['page', $this->getUrl(0), 'title']) . '" :<br><br>'.
$this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentId, 'content']),
''
);
// Valeurs en sortie
@ -398,14 +466,76 @@ class blog extends common {
$pagination = helper::pagination($commentIds, $this->getUrl(),$this->getData(['config','itemsperPage']),'#comment');
// Liste des pages
self::$pages = $pagination['pages'];
// 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']);
}
}
// Commentaires en fonction de la pagination
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
// 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']);
}
// Données du commentaire
self::$comments[$commentIds[$i]] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment', $commentIds[$i]]);
}
// Valeurs en sortie
$this->addOutput([
'showBarEditButton' => true,
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'title']),
'vendor' => [
'tinymce'
],
'view' => 'article'
]);
}
@ -438,4 +568,4 @@ class blog extends common {
]);
}
}
}
}

10
module/blog/view/add/add.php Normal file → Executable file
View File

@ -73,7 +73,8 @@
<h4>Options de publication</h4>
<?php echo template::select('blogAddUserId', $module::$users, [
'label' => 'Auteur',
'selected' => $this->getUser('id')
'selected' => $this->getUser('id'),
'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false
]); ?>
<?php echo template::date('blogAddPublishedOn', [
'help' => 'L\'article n\'est visible qu\'après la date de publication prévue.',
@ -85,6 +86,11 @@
<div class="col6">
<div class="block">
<h4>Options avancées</h4>
<?php echo template::select('blogAddlength', $module::$longueur_comment,[
'help' => 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, caractères de mise en forme html inclus.',
'label' => 'Nombre maximum de caractères pour chaque commentaire',
'selected' => '5000'
]); ?>
<?php echo template::checkbox('blogAddCloseComment', true, 'Fermer les commentaires' ); ?>
<?php echo template::checkbox('blogAddMailNotification', true, 'Notifier le commentaire aux groupes à partir de :', [
'help' => 'Editeurs = éditeurs + administrateurs<br/> Membres = membres + éditeurs + administrateurs'
@ -95,4 +101,4 @@
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<?php echo template::formClose(); ?>

View File

@ -50,6 +50,4 @@
.blogArticlePicture {
height:auto;
max-width: 100%;}
}
}

27
module/blog/view/article/article.php Normal file → Executable file
View File

@ -3,7 +3,7 @@
<div class="blogDate">
<i class="far fa-calendar-alt"></i>
<?php echo utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn']))); ?>
à <?php echo utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn']))); ?>
à <?php echo utf8_encode(strftime('%H:%M', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'publishedOn']))); ?>
</div>
</div>
<?php if($this->getUser('group') >= self::GROUP_ADMIN): ?>
@ -18,15 +18,11 @@
<?php $pictureSize = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'pictureSize']) === null ? '100' : $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'pictureSize']); ?>
<?php if ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'hidePicture']) == false) {
echo '<img class="blogArticlePicture blogArticlePicture' . $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'picturePosition']) .
' pict' . $pictureSize . '" src="' . helper::baseUrl(false) . self::FILE_DIR.'source/' . $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'picture']) .
' pict' . $pictureSize . '" src="' . helper::baseUrl(false) . self::FILE_DIR.'source/' . $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'picture']) .
'" alt="' . $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'picture']) . '">';
} ?>
<?php echo $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'content']); ?>
<p class="clearBoth signature">
<?php echo $this->getData(['user', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'userId']), 'firstname']); ?>
<?php echo $this->getData(['user', $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'userId']), 'lastname']); ?>
</p>
<p class="clearBoth signature"><?php echo $module::$articleSignature;?></p>
<?php if($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'closeComment'])): ?>
<p>Cet article ne reçoit pas de commentaire.</p>
<?php else: ?>
@ -41,11 +37,11 @@
'readonly' => true
]); ?>
<div id="blogArticleCommentWrapper" class="displayNone">
<?php if($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')): ?>
<?php if($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')): ?>
<?php echo template::text('blogArticleUserName', [
'label' => 'Nom',
'readonly' => true,
'value' => $this->getUser('firstname') . ' ' . $this->getUser('lastname')
'value' => $module::$editCommentSignature
]); ?>
<?php echo template::hidden('blogArticleUserId', [
'value' => $this->getUser('id')
@ -69,9 +65,11 @@
</div>
<?php endif; ?>
<?php echo template::textarea('blogArticleContent', [
'label' => 'Commentaire',
'maxlength' => '500'
'label' => 'Commentaire avec maximum '.$this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'maxlengthcomment']).' caractères',
'class' => 'editorWysiwygComment',
'maxlength' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'maxlengthcomment'])
]); ?>
<div id="blogArticleContentAlarm"> </div>
<?php if($this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')): ?>
<div class="row">
<div class="col4">
@ -101,12 +99,7 @@
<div class="col12">
<?php foreach($module::$comments as $commentId => $comment): ?>
<div class="block">
<h4>
<?php if($comment['userId']): ?>
<?php echo $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']); ?>
<?php else: ?>
<?php echo $comment['author']; ?>
<?php endif; ?>
<h4><?php echo $module::$commentsSignature[$commentId]; ?>
le <?php echo utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])); ?>
</h4>
<?php echo $comment['content']; ?>

8
module/blog/view/comment/comment.js.php Normal file → Executable file
View File

@ -18,4 +18,10 @@ $(".blogCommentDelete").on("click", function() {
return core.confirm("Êtes-vous sûr de vouloir supprimer ce commentaire ?", function() {
$(location).attr("href", _this.attr("href"));
});
});
});
$(".blogCommentDeleteAll").on("click", function() {
var _this = $(this);
return core.confirm("Êtes-vous sûr de vouloir supprimer les "+ <?php echo count($this->getData(['module',$this->getUrl(0), $this->getUrl(2), 'comment']));?>+" commentaires de l'article sélectionné ?", function() {
$(location).attr("href", _this.attr("href"));
});
});

15
module/blog/view/comment/comment.php Normal file → Executable file
View File

@ -7,10 +7,19 @@
'value' => 'Retour'
]); ?>
</div>
</div>
<?php if($module::$comments): ?>
<div class="col6 offset2">
<?php echo $module::$messageComments; ?>
</div>
<div class="col2">
<?php echo $module::$commentsDelete; ?>
</div>
</div>
<?php echo template::table([3, 6, 2, 1], $module::$comments, ['Date', 'Contenu', 'Auteur', '']); ?>
<?php echo $module::$pages; ?>
<?php echo $module::$pages.'<br/>'; ?>
<?php else: ?>
</div>
<?php echo template::speech('Aucun commentaire.'); ?>
<?php endif; ?>
<?php endif; ?>

12
module/blog/view/config/config.php Normal file → Executable file
View File

@ -7,13 +7,7 @@
'value' => 'Retour'
]); ?>
</div>
<div class="col3 offset5">
<?php echo template::button('blogConfigComment', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/comment',
'value' => 'Gérer les commentaires'
]); ?>
</div>
<div class="col2">
<div class="col2 offset8">
<?php echo template::button('blogConfigAdd', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/add',
'ico' => 'plus',
@ -22,11 +16,11 @@
</div>
</div>
<?php if($module::$articles): ?>
<?php echo template::table([4, 4, 2, 1, 1], $module::$articles, ['Titre', 'Date de publication', 'État', '', '']); ?>
<?php echo template::table([4, 4, 1, 1, 1, 1], $module::$articles, ['Titre', 'Date de publication', 'État', '', '','']); ?>
<?php echo $module::$pages; ?>
<?php else: ?>
<?php echo template::speech('Aucun article.'); ?>
<?php endif; ?>
<div class="moduleVersion">Version
<?php echo $module::BLOG_VERSION; ?>
</div>
</div>

10
module/blog/view/edit/edit.php Normal file → Executable file
View File

@ -78,7 +78,8 @@
<h4>Options de publication</h4>
<?php echo template::select('blogEditUserId', $module::$users, [
'label' => 'Auteur',
'selected' => $this->getUser('id')
'selected' => $this->getUser('id'),
'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false
]); ?>
<?php echo template::date('blogEditPublishedOn', [
'help' => 'L\'article n\'est visible qu\'après la date de publication prévue.',
@ -90,6 +91,11 @@
<div class="col6">
<div class="block">
<h4>Options avancées</h4>
<?php echo template::select('blogEditlength', $module::$longueur_comment,[
'help' => 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, caractères de mise en forme html inclus.',
'label' => 'Nombre maximum de caractères pour chaque commentaire',
'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'maxlengthcomment'])
]); ?>
<?php echo template::checkbox('blogEditCloseComment', true, 'Fermer les commentaires', [
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'closeComment'])
]); ?>
@ -105,4 +111,4 @@
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<?php echo template::formClose(); ?>