Normalisation
This commit is contained in:
parent
29d46887e9
commit
a85dedbeb3
|
@ -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';
|
||||||
|
@ -76,7 +77,7 @@ class news extends common {
|
||||||
'0.25em' => 'Petite',
|
'0.25em' => 'Petite',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $borderStyle =[
|
public static $borderStyle = [
|
||||||
'none' => 'Aucune',
|
'none' => 'Aucune',
|
||||||
'solid' => 'Tiret'
|
'solid' => 'Tiret'
|
||||||
];
|
];
|
||||||
|
@ -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';
|
||||||
|
@ -101,26 +103,26 @@ class news extends common {
|
||||||
$feeds = new \FeedWriter\RSS2();
|
$feeds = new \FeedWriter\RSS2();
|
||||||
|
|
||||||
// En-tête
|
// En-tête
|
||||||
$feeds->setTitle($this->getData (['page', $this->getUrl(0),'title']));
|
$feeds->setTitle($this->getData(['page', $this->getUrl(0), 'title']));
|
||||||
$feeds->setLink(helper::baseUrl() . $this->getUrl(0));
|
$feeds->setLink(helper::baseUrl() . $this->getUrl(0));
|
||||||
$feeds->setDescription($this->getData (['page', $this->getUrl(0), 'metaDescription']));
|
$feeds->setDescription($this->getData(['page', $this->getUrl(0), 'metaDescription']));
|
||||||
$feeds->setChannelElement('language', 'fr-FR');
|
$feeds->setChannelElement('language', 'fr-FR');
|
||||||
$feeds->setDate(date('r',time()));
|
$feeds->setDate(date('r', time()));
|
||||||
$feeds->addGenerator();
|
$feeds->addGenerator();
|
||||||
// Corps des articles
|
// Corps des articles
|
||||||
$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([
|
||||||
'title' => $this->getData(['module', $this->getUrl(0),'posts', $newsId, 'title']),
|
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'title']),
|
||||||
'link' => helper::baseUrl() . $this->getUrl(0) . '/' . $newsId . '#' . $newsId,
|
'link' => helper::baseUrl() . $this->getUrl(0) . '/' . $newsId . '#' . $newsId,
|
||||||
'description' => $this->getData(['module', $this->getUrl(0),'posts', $newsId, 'content'])
|
'description' => $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'content'])
|
||||||
]);
|
]);
|
||||||
$newsArticle->setAuthor($author,'no@mail.com');
|
$newsArticle->setAuthor($author, 'no@mail.com');
|
||||||
$newsArticle->setId(helper::baseUrl() .$this->getUrl(0) . '/' . $newsId . '#' . $newsId);
|
$newsArticle->setId(helper::baseUrl() . $this->getUrl(0) . '/' . $newsId . '#' . $newsId);
|
||||||
$newsArticle->setDate(date('r', $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOn'])));
|
$newsArticle->setDate(date('r', $this->getData(['module', $this->getUrl(0), 'posts', $newsId, 'publishedOn'])));
|
||||||
$feeds->addItem($newsArticle);
|
$feeds->addItem($newsArticle);
|
||||||
}
|
}
|
||||||
|
@ -137,14 +139,15 @@ 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
|
||||||
$newsId = helper::increment($this->getInput('newsAddTitle', helper::FILTER_ID), (array) $this->getData(['module', $this->getUrl(0), 'posts']));
|
$newsId = helper::increment($this->getInput('newsAddTitle', helper::FILTER_ID), (array) $this->getData(['module', $this->getUrl(0), 'posts']));
|
||||||
$publishedOn = $this->getInput('newsAddPublishedOn', helper::FILTER_DATETIME, true);
|
$publishedOn = $this->getInput('newsAddPublishedOn', helper::FILTER_DATETIME, true);
|
||||||
$publishedOff = $this->getInput('newsAddPublishedOff' ) ? $this->getInput('newsAddPublishedOff', helper::FILTER_DATETIME) : '';
|
$publishedOff = $this->getInput('newsAddPublishedOff') ? $this->getInput('newsAddPublishedOff', helper::FILTER_DATETIME) : '';
|
||||||
$this->setData(['module', $this->getUrl(0),'posts', $newsId, [
|
$this->setData(['module', $this->getUrl(0), 'posts', $newsId, [
|
||||||
'content' => $this->getInput('newsAddContent', null),
|
'content' => $this->getInput('newsAddContent', null),
|
||||||
'publishedOn' => $publishedOn,
|
'publishedOn' => $publishedOn,
|
||||||
'publishedOff' => $publishedOff,
|
'publishedOff' => $publishedOff,
|
||||||
|
@ -162,7 +165,7 @@ class news extends common {
|
||||||
// Liste des utilisateurs
|
// Liste des utilisateurs
|
||||||
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
||||||
ksort(self::$users);
|
ksort(self::$users);
|
||||||
foreach(self::$users as $userId => &$userFirstname) {
|
foreach (self::$users as $userId => &$userFirstname) {
|
||||||
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
||||||
}
|
}
|
||||||
unset($userFirstname);
|
unset($userFirstname);
|
||||||
|
@ -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();
|
||||||
|
@ -188,25 +192,25 @@ class news extends common {
|
||||||
// Ids des news par ordre de publication
|
// Ids des news par ordre de publication
|
||||||
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
||||||
// Pagination fixe
|
// Pagination fixe
|
||||||
$pagination = helper::pagination($newsIds, $this->getUrl(),self::$itemsperPage );
|
$pagination = helper::pagination($newsIds, $this->getUrl(), self::$itemsperPage);
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
self::$pages = $pagination['pages'];
|
self::$pages = $pagination['pages'];
|
||||||
// News en fonction de la pagination
|
// News en fonction de la pagination
|
||||||
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
||||||
// Met en forme le tableau
|
// Met en forme le tableau
|
||||||
$dateOn = helper::dateUTF8('%d %B %Y',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']));
|
$dateOn = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn']));
|
||||||
if ($this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) {
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) {
|
||||||
$dateOff = helper::dateUTF8('%d %B %Y',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']));
|
$dateOff = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff']));
|
||||||
} else {
|
} else {
|
||||||
$dateOff = 'Permanent';
|
$dateOff = 'Permanent';
|
||||||
}
|
}
|
||||||
self::$news[] = [
|
self::$news[] = [
|
||||||
$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'title']),
|
$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'title']),
|
||||||
$dateOn,
|
$dateOn,
|
||||||
$dateOff,
|
$dateOff,
|
||||||
self::$states[$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'state'])],
|
self::$states[$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'state'])],
|
||||||
template::button('newsConfigEdit' . $newsIds[$i], [
|
template::button('newsConfigEdit' . $newsIds[$i], [
|
||||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i]. '/' . $_SESSION['csrf'],
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
||||||
'value' => template::ico('pencil'),
|
'value' => template::ico('pencil'),
|
||||||
'help' => 'Éditer cette nouvelle'
|
'help' => 'Éditer cette nouvelle'
|
||||||
]),
|
]),
|
||||||
|
@ -228,40 +232,41 @@ class news extends common {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function option() {
|
public function option()
|
||||||
|
{
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
if($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
|
|
||||||
// Générer la feuille de CSS
|
// Générer la feuille de CSS
|
||||||
$style = '.newsFrame {';
|
$style = '.newsFrame {';
|
||||||
$style .= 'border-right:' . $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';';
|
$style .= 'border-right:' . $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT) . ';';
|
||||||
$style .= 'border-left:' . $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';';
|
$style .= 'border-left:' . $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT) . ' ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT) . ';';
|
||||||
$style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';';
|
$style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';';
|
||||||
$style .= '}';
|
$style .= '}';
|
||||||
|
|
||||||
// Dossier de l'instance
|
// Dossier de l'instance
|
||||||
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
||||||
mkdir (self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', 0755, true);
|
mkdir(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style );
|
$success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style);
|
||||||
|
|
||||||
// Fin feuille de style
|
// Fin feuille de style
|
||||||
|
|
||||||
$this->setData(['module', $this->getUrl(0), 'theme',[
|
$this->setData(['module', $this->getUrl(0), 'theme', [
|
||||||
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
|
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
|
||||||
'borderStyle' => $this->getInput('newsThemeBorderStyle',helper::FILTER_STRING_SHORT),
|
'borderStyle' => $this->getInput('newsThemeBorderStyle', helper::FILTER_STRING_SHORT),
|
||||||
'borderColor' => $this->getInput('newsThemeBorderColor'),
|
'borderColor' => $this->getInput('newsThemeBorderColor'),
|
||||||
'borderWidth' => $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT),
|
'borderWidth' => $this->getInput('newsThemeBorderWidth', helper::FILTER_STRING_SHORT),
|
||||||
'backgroundColor' => $this->getInput('newsThemeBackgroundColor')
|
'backgroundColor' => $this->getInput('newsThemeBackgroundColor')
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
$this->setData(['module', $this->getUrl(0), 'config',[
|
$this->setData(['module', $this->getUrl(0), 'config', [
|
||||||
'feeds' => $this->getInput('newsOptionShowFeeds',helper::FILTER_BOOLEAN),
|
'feeds' => $this->getInput('newsOptionShowFeeds', helper::FILTER_BOOLEAN),
|
||||||
'feedsLabel' => $this->getInput('newsOptionFeedslabel',helper::FILTER_STRING_SHORT),
|
'feedsLabel' => $this->getInput('newsOptionFeedslabel', helper::FILTER_STRING_SHORT),
|
||||||
'itemsperPage' => $this->getInput('newsOptionItemsperPage', helper::FILTER_INT,true),
|
'itemsperPage' => $this->getInput('newsOptionItemsperPage', helper::FILTER_INT, true),
|
||||||
'itemsperCol' => $this->getInput('newsOptionItemsperCol', helper::FILTER_INT,true),
|
'itemsperCol' => $this->getInput('newsOptionItemsperCol', helper::FILTER_INT, true),
|
||||||
'height' => $this->getInput('newsOptionHeight', helper::FILTER_INT,true),
|
'height' => $this->getInput('newsOptionHeight', helper::FILTER_INT, true),
|
||||||
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
|
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
|
@ -276,25 +281,25 @@ class news extends common {
|
||||||
// Ids des news par ordre de publication
|
// Ids des news par ordre de publication
|
||||||
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
$newsIds = array_keys(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC'));
|
||||||
// Pagination
|
// Pagination
|
||||||
$pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) );
|
$pagination = helper::pagination($newsIds, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
self::$pages = $pagination['pages'];
|
self::$pages = $pagination['pages'];
|
||||||
// News en fonction de la pagination
|
// News en fonction de la pagination
|
||||||
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
||||||
// Met en forme le tableau
|
// Met en forme le tableau
|
||||||
$dateOn = $dateOn = helper::dateUTF8('%d %B %Y',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']));
|
$dateOn = $dateOn = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOn']));
|
||||||
if ($this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) {
|
if ($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) {
|
||||||
$dateOff = helper::dateUTF8('%d %B %Y',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']));
|
$dateOff = helper::dateUTF8('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff'])) . ' - ' . helper::dateUTF8('%H:%M', $this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'publishedOff']));
|
||||||
} else {
|
} else {
|
||||||
$dateOff = 'Permanent';
|
$dateOff = 'Permanent';
|
||||||
}
|
}
|
||||||
self::$news[] = [
|
self::$news[] = [
|
||||||
$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'title']),
|
$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'title']),
|
||||||
$dateOn,
|
$dateOn,
|
||||||
$dateOff,
|
$dateOff,
|
||||||
self::$states[$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'state'])],
|
self::$states[$this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'state'])],
|
||||||
template::button('newsConfigEdit' . $newsIds[$i], [
|
template::button('newsConfigEdit' . $newsIds[$i], [
|
||||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i]. '/' . $_SESSION['csrf'],
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i] . '/' . $_SESSION['csrf'],
|
||||||
'value' => template::ico('pencil')
|
'value' => template::ico('pencil')
|
||||||
]),
|
]),
|
||||||
template::button('newsConfigDelete' . $newsIds[$i], [
|
template::button('newsConfigDelete' . $newsIds[$i], [
|
||||||
|
@ -318,9 +323,10 @@ 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
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'access' => false
|
'access' => false
|
||||||
|
@ -336,7 +342,7 @@ class news extends common {
|
||||||
}
|
}
|
||||||
// Suppression
|
// Suppression
|
||||||
else {
|
else {
|
||||||
$this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]);
|
$this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]);
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
|
||||||
|
@ -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
|
||||||
|
@ -359,7 +366,7 @@ class news extends common {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// 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
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'access' => false
|
'access' => false
|
||||||
|
@ -368,18 +375,18 @@ class news extends common {
|
||||||
// La news existe
|
// La news existe
|
||||||
else {
|
else {
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
if($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
// Si l'id a changée
|
// Si l'id a changée
|
||||||
$newsId = $this->getInput('newsEditTitle', helper::FILTER_ID, true);
|
$newsId = $this->getInput('newsEditTitle', helper::FILTER_ID, true);
|
||||||
if($newsId !== $this->getUrl(2)) {
|
if ($newsId !== $this->getUrl(2)) {
|
||||||
// Incrémente le nouvel id de la news
|
// Incrémente le nouvel id de la news
|
||||||
$newsId = helper::increment($newsId, $this->getData(['module', $this->getUrl(0), 'posts']));
|
$newsId = helper::increment($newsId, $this->getData(['module', $this->getUrl(0), 'posts']));
|
||||||
// Supprime l'ancien news
|
// Supprime l'ancien news
|
||||||
$this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]);
|
$this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]);
|
||||||
}
|
}
|
||||||
$publishedOn = $this->getInput('newsEditPublishedOn', helper::FILTER_DATETIME, true);
|
$publishedOn = $this->getInput('newsEditPublishedOn', helper::FILTER_DATETIME, true);
|
||||||
$publishedOff = $this->getInput('newsEditPublishedOff' ) ? $this->getInput('newsEditPublishedOff', helper::FILTER_DATETIME) : '';
|
$publishedOff = $this->getInput('newsEditPublishedOff') ? $this->getInput('newsEditPublishedOff', helper::FILTER_DATETIME) : '';
|
||||||
$this->setData(['module', $this->getUrl(0),'posts', $newsId, [
|
$this->setData(['module', $this->getUrl(0), 'posts', $newsId, [
|
||||||
'content' => $this->getInput('newsEditContent', null),
|
'content' => $this->getInput('newsEditContent', null),
|
||||||
'publishedOn' => $publishedOn,
|
'publishedOn' => $publishedOn,
|
||||||
'publishedOff' => $publishedOff < $publishedOn ? '' : $publishedOff,
|
'publishedOff' => $publishedOff < $publishedOn ? '' : $publishedOff,
|
||||||
|
@ -397,13 +404,13 @@ class news extends common {
|
||||||
// Liste des utilisateurs
|
// Liste des utilisateurs
|
||||||
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
self::$users = helper::arrayColumn($this->getData(['user']), 'firstname');
|
||||||
ksort(self::$users);
|
ksort(self::$users);
|
||||||
foreach(self::$users as $userId => &$userFirstname) {
|
foreach (self::$users as $userId => &$userFirstname) {
|
||||||
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
$userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']);
|
||||||
}
|
}
|
||||||
unset($userFirstname);
|
unset($userFirstname);
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'title' => $this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2), 'title']),
|
'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']),
|
||||||
'vendor' => [
|
'vendor' => [
|
||||||
'flatpickr',
|
'flatpickr',
|
||||||
'tinymce'
|
'tinymce'
|
||||||
|
@ -416,19 +423,20 @@ 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();
|
||||||
|
|
||||||
// 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) {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'access' => false
|
'access' => false
|
||||||
|
@ -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
|
||||||
|
@ -451,35 +458,38 @@ 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');
|
||||||
$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
|
||||||
// date de péremption tenant des champs non définis
|
$newsIdsStates[$newsId] and
|
||||||
(!is_integer($newsIdsPublishedOff) OR
|
// date de péremption tenant des champs non définis
|
||||||
$newsIdsPublishedOff > time()
|
(!is_integer($newsIdsPublishedOff) or
|
||||||
)
|
$newsIdsPublishedOff > time()
|
||||||
) {
|
)
|
||||||
|
) {
|
||||||
$newsIds[] = $newsId;
|
$newsIds[] = $newsId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Pagination selon le layout
|
// Pagination selon le layout
|
||||||
$pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage']));
|
$pagination = helper::pagination($newsIds, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
||||||
// Nombre de colonnes
|
// Nombre de colonnes
|
||||||
self::$nbrCol = $this->getData(['module', $this->getUrl(0),'config', 'itemsperCol']);
|
self::$nbrCol = $this->getData(['module', $this->getUrl(0), 'config', 'itemsperCol']);
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
self::$pages = $pagination['pages'];
|
self::$pages = $pagination['pages'];
|
||||||
// News en fonction de la pagination
|
// News en fonction de la pagination
|
||||||
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
|
||||||
// Contenu raccourci
|
&& strlen($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content'])) >= $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
|
// Contenu raccourci
|
||||||
$lastSpace = strrpos($content, ' ', -1 );
|
$content = substr($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'content']), 0, $this->getData(['module', $this->getUrl(0), 'config', 'height']));
|
||||||
self::$news[$newsIds[$i]]['content'] = substr(strip_tags($content,'<br><p><img>'), 0, $lastSpace) ;
|
// Ne pas couper un mot
|
||||||
|
$lastSpace = strrpos($content, ' ', -1);
|
||||||
|
self::$news[$newsIds[$i]]['content'] = substr(strip_tags($content, '<br><p><img>'), 0, $lastSpace);
|
||||||
}
|
}
|
||||||
// Mise en forme de la signature
|
// Mise en forme de la signature
|
||||||
self::$news[$newsIds[$i]]['userId'] = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'userId']));
|
self::$news[$newsIds[$i]]['userId'] = $this->signature($this->getData(['module', $this->getUrl(0), 'posts', $newsIds[$i], 'userId']));
|
||||||
|
@ -489,19 +499,19 @@ class news extends common {
|
||||||
'showBarEditButton' => true,
|
'showBarEditButton' => true,
|
||||||
'showPageContent' => true,
|
'showPageContent' => true,
|
||||||
'view' => 'index',
|
'view' => 'index',
|
||||||
'style' => file_exists($this->getData(['module', $this->getUrl(0), 'theme', 'style']))
|
'style' => file_exists($this->getData(['module', $this->getUrl(0), 'theme', 'style']))
|
||||||
? $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;
|
||||||
break;
|
break;
|
||||||
|
@ -523,80 +533,83 @@ 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), 'theme']) === NULL
|
$this->getData(['module', $this->getUrl(0), 'config']) === NULL
|
||||||
|| !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')
|
|| $this->getData(['module', $this->getUrl(0), 'theme']) === NULL
|
||||||
) {
|
|| !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')
|
||||||
|
) {
|
||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
$versionData = $this->getData(['module',$this->getUrl(0),'config', 'versionData' ]);
|
$versionData = $this->getData(['module', $this->getUrl(0), 'config', 'versionData']);
|
||||||
// Mise à jour 3.2
|
// Mise à jour 3.2
|
||||||
if (version_compare($versionData, '3.1', '<') ) {
|
if (version_compare($versionData, '3.1', '<')) {
|
||||||
$this->setData(['module',$this->getUrl(0),'theme', 'itemsBlur', '0%' ]);
|
$this->setData(['module', $this->getUrl(0), 'theme', 'itemsBlur', '0%']);
|
||||||
// Mettre à jour la version
|
// Mettre à jour la version
|
||||||
$this->setData(['module',$this->getUrl(0),'config', 'versionData', '3.2' ]);
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.2']);
|
||||||
}
|
}
|
||||||
// Mise à jour 3.3
|
// Mise à jour 3.3
|
||||||
if (version_compare($versionData, '3.3', '<') ) {
|
if (version_compare($versionData, '3.3', '<')) {
|
||||||
if (is_dir(self::DATADIRECTORY . 'pages/')) {
|
if (is_dir(self::DATADIRECTORY . 'pages/')) {
|
||||||
// Déplacer les données du dossier Pages
|
// Déplacer les données du dossier Pages
|
||||||
$this->copyDir(self::DATADIRECTORY . 'pages/' . $this->getUrl(0), self::DATADIRECTORY . $this->getUrl(0));
|
$this->copyDir(self::DATADIRECTORY . 'pages/' . $this->getUrl(0), self::DATADIRECTORY . $this->getUrl(0));
|
||||||
$this->removeDir(self::DATADIRECTORY . 'pages/' );
|
$this->removeDir(self::DATADIRECTORY . 'pages/');
|
||||||
$style = $this->getData(['module', $this->getUrl(0), 'theme', 'style']);
|
$style = $this->getData(['module', $this->getUrl(0), 'theme', 'style']);
|
||||||
$this->setData(['module', $this->getUrl(0), 'theme', 'style', str_replace('pages/', '', $style)]);
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', str_replace('pages/', '', $style)]);
|
||||||
}
|
}
|
||||||
// Mettre à jour la version
|
// Mettre à jour la version
|
||||||
$this->setData(['module',$this->getUrl(0),'config', 'versionData', '3.3' ]);
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.3']);
|
||||||
}
|
}
|
||||||
// Mise à jour 3.4
|
// Mise à jour 3.4
|
||||||
if (version_compare($versionData, '3.4', '<') ) {
|
if (version_compare($versionData, '3.4', '<')) {
|
||||||
// Effacer le style précédent
|
// Effacer le style précédent
|
||||||
unlink(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css');
|
unlink(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css');
|
||||||
$this->deleteData(['module', $this->getUrl(0), 'theme' ]);
|
$this->deleteData(['module', $this->getUrl(0), 'theme']);
|
||||||
// Le générer
|
// Le générer
|
||||||
$this->init();
|
$this->init();
|
||||||
// Mettre à jour la version
|
// Mettre à jour la version
|
||||||
$this->setData(['module',$this->getUrl(0),'config', 'versionData', '3.4' ]);
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.4']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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';
|
||||||
|
|
||||||
// Données du module absentes
|
// Données du module absentes
|
||||||
require_once('module/news/ressource/defaultdata.php');
|
require_once('module/news/ressource/defaultdata.php');
|
||||||
if ($this->getData(['module', $this->getUrl(0), 'config' ]) === null) {
|
if ($this->getData(['module', $this->getUrl(0), 'config']) === null) {
|
||||||
$this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]);
|
$this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]);
|
||||||
}
|
}
|
||||||
if ($this->getData(['module', $this->getUrl(0), 'theme' ]) === null) {
|
if ($this->getData(['module', $this->getUrl(0), 'theme']) === null) {
|
||||||
// Données de thème
|
// Données de thème
|
||||||
$this->setData(['module', $this->getUrl(0), 'theme', init::$defaultTheme]);
|
$this->setData(['module', $this->getUrl(0), 'theme', init::$defaultTheme]);
|
||||||
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' ]);
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dossier de l'instance
|
// Dossier de l'instance
|
||||||
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0) )) {
|
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
||||||
mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true);
|
mkdir(self::DATADIRECTORY . $this->getUrl(0), 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check la présence de la feuille de style
|
// Check la présence de la feuille de style
|
||||||
if ( !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')) {
|
if (!file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')) {
|
||||||
// Générer la feuille de CSS
|
// Générer la feuille de CSS
|
||||||
$style = '.newsFrame {';
|
$style = '.newsFrame {';
|
||||||
$style .= 'border:' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderStyle' ]) . ' ' .$this->getData(['module', $this->getUrl(0), 'theme', 'borderColor' ]) . ' ' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderWidth' ]) . ';';
|
$style .= 'border:' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderStyle']) . ' ' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderColor']) . ' ' . $this->getData(['module', $this->getUrl(0), 'theme', 'borderWidth']) . ';';
|
||||||
$style .= 'background-color:' . $this->getData(['module', $this->getUrl(0), 'theme', 'backgroundColor' ]) . ';';
|
$style .= 'background-color:' . $this->getData(['module', $this->getUrl(0), 'theme', 'backgroundColor']) . ';';
|
||||||
$style .= '}';
|
$style .= '}';
|
||||||
|
|
||||||
// Sauver la feuille de style
|
// Sauver la feuille de style
|
||||||
file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' , $style );
|
file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style);
|
||||||
// Stocker le nom de la feuille de style
|
// Stocker le nom de la feuille de style
|
||||||
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue