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/
*/
class blog extends common {
class blog extends common
{
const VERSION = '6.3';
const REALNAME = 'Blog';
@ -123,13 +124,11 @@ class blog extends common {
* Mise à jour du module
* Appelée par les fonctions index et config
*/
private function update() {
private function update()
{
// Initialisation
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', 'feeds', true]);
$this->setData(['module', $this->getUrl(0), 'config', 'feedsLabel', 'Flux RSS']);
$this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.0']);
if (is_null($this->getData(['module', $this->getUrl(0), 'config', 'versionData']))) {
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '0.0']);
}
// Version 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
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', 'commentMaxlength', 250]);
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '6.0']);
}
}
@ -149,7 +149,8 @@ class blog extends common {
/**
* Flux RSS
*/
public function rss() {
public function rss()
{
// Inclure les classes
include_once 'module/blog/vendor/FeedWriter/Item.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');
$articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if( $articlePublishedOn <= time() AND $articleIdsStates[$articleId] ) {
if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
// Miniature
$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']));
@ -192,7 +193,8 @@ class blog extends common {
$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']))) {
$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['mime']
);
@ -212,14 +214,14 @@ class blog extends common {
/**
* Édition
*/
public function add() {
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{
} else {
$newuserid = $this->getUser('id');
}
// 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_keys(self::$actions));
// Crée l'article
$this->setData(['module',
$this->setData([
'module',
$this->getUrl(0),
'posts',
$articleId, [
@ -278,7 +281,8 @@ class blog extends common {
/**
* Liste des commentaires
*/
public function comment() {
public function comment()
{
$comments = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']);
self::$commentsDelete = template::button('blogCommentDeleteAll', [
'class' => 'blogCommentDeleteAll buttonRed',
@ -329,7 +333,8 @@ class blog extends common {
/**
* Suppression de commentaire
*/
public function commentDelete() {
public function commentDelete()
{
// Le commentaire n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
// Valeurs en sortie
@ -360,7 +365,8 @@ class blog extends common {
/**
* Suppression de tous les commentaires de l'article $this->getUrl(2)
*/
public function commentDeleteAll() {
public function commentDeleteAll()
{
// Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) {
// Valeurs en sortie
@ -384,7 +390,8 @@ class blog extends common {
/**
* Approbation oou désapprobation de commentaire
*/
public function commentApprove() {
public function commentApprove()
{
// Le commentaire n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) {
// Valeurs en sortie
@ -423,7 +430,8 @@ class blog extends common {
/**
* Configuration
*/
public function config() {
public function config()
{
// Ids des articles par ordre de publication
$articleIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
@ -433,16 +441,16 @@ class blog extends common {
if (
( // 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')
OR $this->getUser('group') === self::GROUP_ADMIN )
and ($this->getData(['module', $this->getUrl(0), 'posts', $value, 'userId']) === $this->getUser('id')
or $this->getUser('group') === self::GROUP_ADMIN)
)
OR (
or (
// Groupe
$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
$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
$this->update();
// Soumission du formulaire
@ -531,7 +540,8 @@ class blog extends common {
/**
* Suppression
*/
public function delete() {
public function delete()
{
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) {
// Valeurs en sortie
$this->addOutput([
@ -561,7 +571,8 @@ class blog extends common {
/**
* Édition
*/
public function edit() {
public function edit()
{
// Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) {
// Valeurs en sortie
@ -583,8 +594,7 @@ class blog extends common {
if ($this->isPost()) {
if ($this->getUser('group') === self::GROUP_ADMIN) {
$newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true);
}
else{
} else {
$newuserid = $this->getUser('id');
}
$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, array_keys(self::$actions));
}
$this->setData(['module',
$this->setData([
'module',
$this->getUrl(0),
'posts',
$articleId, [
@ -654,14 +665,15 @@ class blog extends common {
/**
* Accueil (deux affichages en un pour éviter une url à rallonge)
*/
public function index() {
public function index()
{
// Mise à jour des données de module
$this->update();
// 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
and intval($this->getUrl(1)) === 0
) {
// L'article n'existe pas
if ($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1)]) === null) {
@ -678,8 +690,8 @@ class blog extends common {
if (
$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 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';
}
// 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),
'state' => ($sent === true ? true : null)
]);
} else {
// Valeurs en sortie
$this->addOutput([
@ -732,7 +743,6 @@ class blog extends common {
'state' => true
]);
}
}
// Ids des commentaires approuvés par ordre de publication
$commentsApproved = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'comment']);
@ -778,7 +788,6 @@ class blog extends common {
'view' => 'article'
]);
}
}
// Liste des articles
else {
@ -787,7 +796,7 @@ class blog extends common {
$articleIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
$articleIds = [];
foreach ($articleIdsPublishedOns as $articleId => $articlePublishedOn) {
if($articlePublishedOn <= time() AND $articleIdsStates[$articleId]) {
if ($articlePublishedOn <= time() and $articleIdsStates[$articleId]) {
$articleIds[] = $articleId;
// Nombre de commentaires approuvés par article
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
*/
public function signature($userId) {
public function signature($userId)
{
switch ($this->getData(['user', $userId, 'signature'])) {
case 1:
return $userId;

View File

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