blog 6.22 initialisation de la config + reformatage

This commit is contained in:
Fred Tempez 2022-10-16 18:07:51 +02:00
parent a85dedbeb3
commit bfd48adcf9
2 changed files with 160 additions and 149 deletions

View File

@ -13,7 +13,8 @@
* @link http://zwiicms.fr/ * @link http://zwiicms.fr/
*/ */
class blog extends common { class blog extends common
{
const VERSION = '6.3'; const VERSION = '6.3';
const REALNAME = 'Blog'; const REALNAME = 'Blog';
@ -123,13 +124,11 @@ class blog extends common {
* Mise à jour du module * Mise à jour du module
* Appelée par les fonctions index et config * Appelée par les fonctions index et config
*/ */
private function update() { private function update()
{
// Initialisation // Initialisation
if (is_null($this->getData(['module', $this->getUrl(0), 'config', 'versionData'])) || if (is_null($this->getData(['module', $this->getUrl(0), 'config', 'versionData']))) {
version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '0.0', '<') ) { $this->setData(['module', $this->getUrl(0), 'config', 'versionData', '0.0']);
$this->setData(['module', $this->getUrl(0), 'config', 'feeds', true]);
$this->setData(['module', $this->getUrl(0), 'config', 'feedsLabel', 'Flux RSS']);
$this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.0']);
} }
// Version 5.0 // Version 5.0
if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '5.0', '<')) { if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '5.0', '<')) {
@ -138,8 +137,9 @@ class blog extends common {
} }
// Version 6.0 // Version 6.0
if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '6.0', '<')) { 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', '']);
$this->setData(['module', $this->getUrl(0), 'config', 'articlesLenght', 0]); $this->setData(['module', $this->getUrl(0), 'config', 'articlesLenght', 0]);
$this->setData(['module', $this->getUrl(0), 'config', 'commentMaxlength', 250]);
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '6.0']); $this->setData(['module', $this->getUrl(0), 'config', 'versionData', '6.0']);
} }
} }
@ -149,7 +149,8 @@ class blog extends common {
/** /**
* Flux RSS * Flux RSS
*/ */
public function rss() { public function rss()
{
// Inclure les classes // Inclure les classes
include_once 'module/blog/vendor/FeedWriter/Item.php'; include_once 'module/blog/vendor/FeedWriter/Item.php';
include_once 'module/blog/vendor/FeedWriter/Feed.php'; include_once 'module/blog/vendor/FeedWriter/Feed.php';
@ -170,7 +171,7 @@ class blog extends common {
$articleIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'); $articleIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC');
$articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC'); $articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) { foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if( $articlePublishedOn <= time() AND $articleIdsStates[$articleId] ) { if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
// Miniature // Miniature
$parts = explode('/', $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture'])); $parts = explode('/', $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture']));
$thumb = str_replace($parts[(count($parts) - 1)], 'mini_' . $parts[(count($parts) - 1)], $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture'])); $thumb = str_replace($parts[(count($parts) - 1)], 'mini_' . $parts[(count($parts) - 1)], $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture']));
@ -192,7 +193,8 @@ class blog extends common {
$newsArticle->setDate(date('r', $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn']))); $newsArticle->setDate(date('r', $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn'])));
if (file_exists($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture']))) { if (file_exists($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture']))) {
$imageData = getimagesize(helper::baseUrl(false) . self::FILE_DIR . 'thumb/' . $thumb); $imageData = getimagesize(helper::baseUrl(false) . self::FILE_DIR . 'thumb/' . $thumb);
$newsArticle->addEnclosure( helper::baseUrl(false) . self::FILE_DIR . 'thumb/' . $thumb, $newsArticle->addEnclosure(
helper::baseUrl(false) . self::FILE_DIR . 'thumb/' . $thumb,
$imageData[0] * $imageData[1], $imageData[0] * $imageData[1],
$imageData['mime'] $imageData['mime']
); );
@ -212,14 +214,14 @@ class blog extends common {
/** /**
* Édition * Édition
*/ */
public function add() { public function add()
{
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
// Modification de l'userId // Modification de l'userId
if ($this->getUser('group') === self::GROUP_ADMIN) { if ($this->getUser('group') === self::GROUP_ADMIN) {
$newuserid = $this->getInput('blogAddUserId', helper::FILTER_STRING_SHORT, true); $newuserid = $this->getInput('blogAddUserId', helper::FILTER_STRING_SHORT, true);
} } else {
else{
$newuserid = $this->getUser('id'); $newuserid = $this->getUser('id');
} }
// Incrémente l'id de l'article // Incrémente l'id de l'article
@ -227,7 +229,8 @@ class blog extends common {
$articleId = helper::increment($articleId, (array) $this->getData(['module', $this->getUrl(0)])); $articleId = helper::increment($articleId, (array) $this->getData(['module', $this->getUrl(0)]));
$articleId = helper::increment($articleId, array_keys(self::$actions)); $articleId = helper::increment($articleId, array_keys(self::$actions));
// Crée l'article // Crée l'article
$this->setData(['module', $this->setData([
'module',
$this->getUrl(0), $this->getUrl(0),
'posts', 'posts',
$articleId, [ $articleId, [
@ -278,7 +281,8 @@ class blog extends common {
/** /**
* Liste des commentaires * Liste des commentaires
*/ */
public function comment() { public function comment()
{
$comments = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']); $comments = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']);
self::$commentsDelete = template::button('blogCommentDeleteAll', [ self::$commentsDelete = template::button('blogCommentDeleteAll', [
'class' => 'blogCommentDeleteAll buttonRed', 'class' => 'blogCommentDeleteAll buttonRed',
@ -329,7 +333,8 @@ class blog extends common {
/** /**
* Suppression de commentaire * Suppression de commentaire
*/ */
public function commentDelete() { public function commentDelete()
{
// Le commentaire n'existe pas // Le commentaire n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
// Valeurs en sortie // Valeurs en sortie
@ -360,7 +365,8 @@ class blog extends common {
/** /**
* Suppression de tous les commentaires de l'article $this->getUrl(2) * Suppression de tous les commentaires de l'article $this->getUrl(2)
*/ */
public function commentDeleteAll() { public function commentDeleteAll()
{
// Jeton incorrect // Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) { if ($this->getUrl(3) !== $_SESSION['csrf']) {
// Valeurs en sortie // Valeurs en sortie
@ -384,7 +390,8 @@ class blog extends common {
/** /**
* Approbation oou désapprobation de commentaire * Approbation oou désapprobation de commentaire
*/ */
public function commentApprove() { public function commentApprove()
{
// Le commentaire n'existe pas // Le commentaire n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
// Valeurs en sortie // Valeurs en sortie
@ -423,7 +430,8 @@ class blog extends common {
/** /**
* Configuration * Configuration
*/ */
public function config() { public function config()
{
// Ids des articles par ordre de publication // Ids des articles par ordre de publication
$articleIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); $articleIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
@ -433,16 +441,16 @@ class blog extends common {
if ( if (
( // Propriétaire ( // Propriétaire
$this->getData(['module', $this->getUrl(0), 'posts', $value, 'editConsent']) === self::EDIT_OWNER $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') and ($this->getData(['module', $this->getUrl(0), 'posts', $value, 'userId']) === $this->getUser('id')
OR $this->getUser('group') === self::GROUP_ADMIN ) or $this->getUser('group') === self::GROUP_ADMIN)
) )
OR ( or (
// Groupe // Groupe
$this->getData(['module', $this->getUrl(0), 'posts', $value, 'editConsent']) !== self::EDIT_OWNER $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']) and $this->getUser('group') >= $this->getData(['module', $this->getUrl(0), 'posts', $value, 'editConsent'])
) )
OR ( or (
// Tout le monde // Tout le monde
$this->getData(['module', $this->getUrl(0), 'posts', $value, 'editConsent']) === self::EDIT_ALL $this->getData(['module', $this->getUrl(0), 'posts', $value, 'editConsent']) === self::EDIT_ALL
) )
@ -501,7 +509,8 @@ class blog extends common {
]); ]);
} }
public function option() { public function option()
{
// Mise à jour des données de module // Mise à jour des données de module
$this->update(); $this->update();
// Soumission du formulaire // Soumission du formulaire
@ -531,7 +540,8 @@ class blog extends common {
/** /**
* Suppression * Suppression
*/ */
public function delete() { public function delete()
{
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) { if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -561,7 +571,8 @@ class blog extends common {
/** /**
* Édition * Édition
*/ */
public function edit() { public function edit()
{
// Jeton incorrect // Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) { if ($this->getUrl(3) !== $_SESSION['csrf']) {
// Valeurs en sortie // Valeurs en sortie
@ -583,8 +594,7 @@ class blog extends common {
if ($this->isPost()) { if ($this->isPost()) {
if ($this->getUser('group') === self::GROUP_ADMIN) { if ($this->getUser('group') === self::GROUP_ADMIN) {
$newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true); $newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true);
} } else {
else{
$newuserid = $this->getUser('id'); $newuserid = $this->getUser('id');
} }
$articleId = $this->getInput('blogEditPermalink', null, true); $articleId = $this->getInput('blogEditPermalink', null, true);
@ -594,7 +604,8 @@ class blog extends common {
$articleId = helper::increment($articleId, $this->getData(['module', $this->getUrl(0), 'posts'])); $articleId = helper::increment($articleId, $this->getData(['module', $this->getUrl(0), 'posts']));
$articleId = helper::increment($articleId, array_keys(self::$actions)); $articleId = helper::increment($articleId, array_keys(self::$actions));
} }
$this->setData(['module', $this->setData([
'module',
$this->getUrl(0), $this->getUrl(0),
'posts', 'posts',
$articleId, [ $articleId, [
@ -654,14 +665,15 @@ class blog extends common {
/** /**
* Accueil (deux affichages en un pour éviter une url à rallonge) * Accueil (deux affichages en un pour éviter une url à rallonge)
*/ */
public function index() { public function index()
{
// Mise à jour des données de module // Mise à jour des données de module
$this->update(); $this->update();
// Affichage d'un article // Affichage d'un article
if ( if (
$this->getUrl(1) $this->getUrl(1)
// Protection pour la pagination, un ID ne peut pas être un entier, une page oui // Protection pour la pagination, un ID ne peut pas être un entier, une page oui
AND intval($this->getUrl(1)) === 0 and intval($this->getUrl(1)) === 0
) { ) {
// L'article n'existe pas // L'article n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1)]) === null) { if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1)]) === null) {
@ -678,8 +690,8 @@ class blog extends common {
if ( if (
$this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
//AND $this->getInput('blogArticlecaptcha', helper::FILTER_INT) !== $this->getInput('blogArticlecaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticlecaptchaSecondNumber', helper::FILTER_INT)) //AND $this->getInput('blogArticlecaptcha', helper::FILTER_INT) !== $this->getInput('blogArticlecaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticlecaptchaSecondNumber', helper::FILTER_INT))
AND password_verify($this->getInput('blogArticleCaptcha', helper::FILTER_INT), $this->getInput('blogArticleCaptchaResult') ) === false ) and password_verify($this->getInput('blogArticleCaptcha', helper::FILTER_INT), $this->getInput('blogArticleCaptchaResult')) === false
{ ) {
self::$inputNotices['blogArticleCaptcha'] = 'Incorrect'; self::$inputNotices['blogArticleCaptcha'] = 'Incorrect';
} }
// Crée le commentaire // Crée le commentaire
@ -723,7 +735,6 @@ class blog extends common {
'notification' => ($error === 0 ? $notification . '<br/>Une notification a été envoyée.' : $notification . '<br/> Erreur de notification : ' . $sent), 'notification' => ($error === 0 ? $notification . '<br/>Une notification a été envoyée.' : $notification . '<br/> Erreur de notification : ' . $sent),
'state' => ($sent === true ? true : null) 'state' => ($sent === true ? true : null)
]); ]);
} else { } else {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -732,7 +743,6 @@ class blog extends common {
'state' => true 'state' => true
]); ]);
} }
} }
// Ids des commentaires approuvés par ordre de publication // Ids des commentaires approuvés par ordre de publication
$commentsApproved = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'comment']); $commentsApproved = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'comment']);
@ -778,7 +788,6 @@ class blog extends common {
'view' => 'article' 'view' => 'article'
]); ]);
} }
} }
// Liste des articles // Liste des articles
else { else {
@ -787,7 +796,7 @@ class blog extends common {
$articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC'); $articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
$articleIds = []; $articleIds = [];
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) { foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if($articlePublishedOn <= time() AND $articleIdsStates[$articleId]) { if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
$articleIds[] = $articleId; $articleIds[] = $articleId;
// Nombre de commentaires approuvés par article // Nombre de commentaires approuvés par article
if (is_array($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'comment']))) { if (is_array($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'comment']))) {
@ -817,7 +826,8 @@ class blog extends common {
/** /**
* Retourne la signature d'un utilisateur * Retourne la signature d'un utilisateur
*/ */
public function signature($userId) { public function signature($userId)
{
switch ($this->getData(['user', $userId, 'signature'])) { switch ($this->getData(['user', $userId, 'signature'])) {
case 1: case 1:
return $userId; return $userId;

View File

@ -1,5 +1,6 @@
# version 6.22 # version 6.22
- mise en oeuvre du helper dateUTF8 - mise en oeuvre du helper dateUTF8
- Réglage de l'initialisaion de la configuration
# version 6.2 # version 6.2
- date des commentaires - date des commentaires
# version 6.1 # version 6.1