Normalisation

This commit is contained in:
Fred Tempez 2022-10-16 17:47:05 +02:00
parent 29d46887e9
commit a85dedbeb3
1 changed files with 130 additions and 117 deletions

View File

@ -13,7 +13,8 @@
* @link http://zwiicms.fr/ * @link http://zwiicms.fr/
*/ */
class news extends common { class news extends common
{
const VERSION = '4.22'; const VERSION = '4.22';
const REALNAME = 'News'; const REALNAME = 'News';
@ -89,7 +90,8 @@ class news extends common {
/** /**
* Flux RSS * Flux RSS
*/ */
public function rss() { public function rss()
{
// Inclure les classes // Inclure les classes
include_once 'module/news/vendor/FeedWriter/Item.php'; include_once 'module/news/vendor/FeedWriter/Item.php';
include_once 'module/news/vendor/FeedWriter/Feed.php'; include_once 'module/news/vendor/FeedWriter/Feed.php';
@ -111,7 +113,7 @@ class news extends common {
$newsIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'); $newsIdsPublishedOns = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC');
$newsIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC'); $newsIdsStates = helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'state', 'SORT_DESC');
foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) { foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) {
if($newsPublishedOn <= time() AND $newsIdsStates[$newsId]) { if ($newsPublishedOn <= time() and $newsIdsStates[$newsId]) {
$newsArticle = $feeds->createNewItem(); $newsArticle = $feeds->createNewItem();
$author = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'userId'])); $author = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'userId']));
$newsArticle->addElementArray([ $newsArticle->addElementArray([
@ -137,7 +139,8 @@ class news extends common {
/** /**
* Ajout d'un article * Ajout d'un article
*/ */
public function add() { public function add()
{
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
// Crée la news // Crée la news
@ -180,7 +183,8 @@ class news extends common {
/** /**
* Configuration * Configuration
*/ */
public function config() { public function config()
{
// Mise à jour des données de module // Mise à jour des données de module
$this->update(); $this->update();
@ -228,7 +232,8 @@ class news extends common {
]); ]);
} }
public function option() { public function option()
{
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
@ -318,7 +323,8 @@ class news extends common {
/** /**
* Suppression * Suppression
*/ */
public function delete() { public function delete()
{
// La news n'existe pas // La news n'existe pas
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
@ -349,7 +355,8 @@ class news 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
@ -416,7 +423,8 @@ class news extends common {
/** /**
* Accueil * Accueil
*/ */
public function index() { public function index()
{
// Mise à jour des données de module // Mise à jour des données de module
$this->update(); $this->update();
@ -425,7 +433,7 @@ class news extends common {
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) {
@ -443,7 +451,6 @@ class news extends common {
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'title']), 'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(1), 'title']),
'view' => 'article' 'view' => 'article'
]); ]);
} }
} else { } else {
// Affichage index // Affichage index
@ -453,10 +460,11 @@ class news extends common {
$newsIds = []; $newsIds = [];
foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) { foreach ($newsIdsPublishedOns as $newsId => $newsPublishedOn) {
$newsIdsPublishedOff = $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOff']); $newsIdsPublishedOff = $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOff']);
if( $newsPublishedOn <= time() AND if (
$newsIdsStates[$newsId] AND $newsPublishedOn <= time() and
$newsIdsStates[$newsId] and
// date de péremption tenant des champs non définis // date de péremption tenant des champs non définis
(!is_integer($newsIdsPublishedOff) OR (!is_integer($newsIdsPublishedOff) or
$newsIdsPublishedOff > time() $newsIdsPublishedOff > time()
) )
) { ) {
@ -473,8 +481,10 @@ class news extends common {
for ($i = $pagination['first']; $i < $pagination['last']; $i++) { for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
self::$news[$newsIds[$i]] = $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i]]); self::$news[$newsIds[$i]] = $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i]]);
// Longueur de la news affichée // Longueur de la news affichée
if ( $this->getData(['module', $this->getUrl(0), 'config', 'height']) !== -1 if (
&& strlen($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content'])) >= $this->getData(['module', $this->getUrl(0), 'config', 'height']) ) { $this->getData(['module', $this->getUrl(0), 'config', 'height']) !== -1
&& strlen($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content'])) >= $this->getData(['module', $this->getUrl(0), 'config', 'height'])
) {
// Contenu raccourci // Contenu raccourci
$content = substr($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content']), 0, $this->getData(['module', $this->getUrl(0), 'config', 'height'])); $content = substr($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content']), 0, $this->getData(['module', $this->getUrl(0), 'config', 'height']));
// Ne pas couper un mot // Ne pas couper un mot
@ -493,14 +503,14 @@ class news extends common {
? $this->getData(['module', $this->getUrl(0), 'theme', 'style']) ? $this->getData(['module', $this->getUrl(0), 'theme', 'style'])
: '' : ''
]); ]);
} }
} }
/** /**
* Retourne la signature d'un utilisateur * Retourne la signature d'un utilisateur
*/ */
private function signature($userId) { private function signature($userId)
{
switch ($this->getData(['user', $userId, 'signature'])) { switch ($this->getData(['user', $userId, 'signature'])) {
case 1: case 1:
return $userId; return $userId;
@ -523,10 +533,12 @@ class news 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()
{
// le module n'est pas initialisé // le module n'est pas initialisé
if ( $this->getData(['module',$this->getUrl(0), 'config']) === NULL if (
$this->getData(['module', $this->getUrl(0), 'config']) === NULL
|| $this->getData(['module', $this->getUrl(0), 'theme']) === NULL || $this->getData(['module', $this->getUrl(0), 'theme']) === NULL
|| !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css') || !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')
) { ) {
@ -567,7 +579,8 @@ class news extends common {
/** /**
* Initialisation du thème d'un nouveau module * Initialisation du thème d'un nouveau module
*/ */
private function init() { private function init()
{
$fileCSS = self::DATADIRECTORY . $this->getUrl(0) . '/theme.css'; $fileCSS = self::DATADIRECTORY . $this->getUrl(0) . '/theme.css';