self devient common

This commit is contained in:
Fred Tempez 2024-04-23 17:15:20 +02:00
parent 9bfa8280fd
commit b3e3ead5ac
1 changed files with 50 additions and 50 deletions

View File

@ -15,12 +15,12 @@ class core extends common
} }
// Fuseau horaire // Fuseau horaire
self::$timezone = $this->getData(['config', 'timezone']); // Utile pour transmettre le timezone à la classe helper common::$timezone = $this->getData(['config', 'timezone']); // Utile pour transmettre le timezone à la classe helper
date_default_timezone_set(self::$timezone); date_default_timezone_set(common::$timezone);
// Supprime les fichiers temporaires // Supprime les fichiers temporaires
$lastClearTmp = mktime(0, 0, 0); $lastClearTmp = mktime(0, 0, 0);
if ($lastClearTmp > $this->getData(['core', 'lastClearTmp']) + 86400) { if ($lastClearTmp > $this->getData(['core', 'lastClearTmp']) + 86400) {
$iterator = new DirectoryIterator(self::TEMP_DIR); $iterator = new DirectoryIterator(common::TEMP_DIR);
foreach ($iterator as $fileInfos) { foreach ($iterator as $fileInfos) {
if ( if (
$fileInfos->isFile() && $fileInfos->isFile() &&
@ -43,11 +43,11 @@ class core extends common
and $this->getData(['user']) // Pas de backup pendant l'installation and $this->getData(['user']) // Pas de backup pendant l'installation
) { ) {
// Copie des fichier de données // Copie des fichier de données
helper::autoBackup(self::BACKUP_DIR, ['backup', 'tmp', 'file']); helper::autoBackup(common::BACKUP_DIR, ['backup', 'tmp', 'file']);
// Date du dernier backup // Date du dernier backup
$this->setData(['core', 'lastBackup', $lastBackup]); $this->setData(['core', 'lastBackup', $lastBackup]);
// Supprime les backups de plus de 30 jours // Supprime les backups de plus de 30 jours
$iterator = new DirectoryIterator(self::BACKUP_DIR); $iterator = new DirectoryIterator(common::BACKUP_DIR);
foreach ($iterator as $fileInfos) { foreach ($iterator as $fileInfos) {
if ( if (
$fileInfos->isFile() $fileInfos->isFile()
@ -60,23 +60,23 @@ class core extends common
} }
// Crée le fichier de personnalisation avancée // Crée le fichier de personnalisation avancée
if (file_exists(self::DATA_DIR . 'custom.css') === false) { if (file_exists(common::DATA_DIR . 'custom.css') === false) {
$this->secure_file_put_contents(self::DATA_DIR . 'custom.css', file_get_contents('core/module/theme/resource/custom.css')); $this->secure_file_put_contents(common::DATA_DIR . 'custom.css', file_get_contents('core/module/theme/resource/custom.css'));
chmod(self::DATA_DIR . 'custom.css', 0755); chmod(common::DATA_DIR . 'custom.css', 0755);
} }
// Crée le fichier de personnalisation // Crée le fichier de personnalisation
if (file_exists(self::DATA_DIR . 'theme.css') === false) { if (file_exists(common::DATA_DIR . 'theme.css') === false) {
$this->secure_file_put_contents(self::DATA_DIR . 'theme.css', ''); $this->secure_file_put_contents(common::DATA_DIR . 'theme.css', '');
chmod(self::DATA_DIR . 'theme.css', 0755); chmod(common::DATA_DIR . 'theme.css', 0755);
} }
// Crée le fichier de personnalisation de l'administration // Crée le fichier de personnalisation de l'administration
if (file_exists(self::DATA_DIR . 'admin.css') === false) { if (file_exists(common::DATA_DIR . 'admin.css') === false) {
$this->secure_file_put_contents(self::DATA_DIR . 'admin.css', ''); $this->secure_file_put_contents(common::DATA_DIR . 'admin.css', '');
chmod(self::DATA_DIR . 'admin.css', 0755); chmod(common::DATA_DIR . 'admin.css', 0755);
} }
// Check la version rafraichissement du theme // Check la version rafraichissement du theme
$cssVersion = preg_split('/\*+/', file_get_contents(self::DATA_DIR . 'theme.css')); $cssVersion = preg_split('/\*+/', file_get_contents(common::DATA_DIR . 'theme.css'));
if (empty($cssVersion[1]) or $cssVersion[1] !== md5(json_encode($this->getData(['theme'])))) { if (empty($cssVersion[1]) or $cssVersion[1] !== md5(json_encode($this->getData(['theme'])))) {
// Version // Version
$css = '/*' . md5(json_encode($this->getData(['theme']))) . '*/'; $css = '/*' . md5(json_encode($this->getData(['theme']))) . '*/';
@ -92,7 +92,7 @@ class core extends common
// Fonts disponibles // Fonts disponibles
$fontsAvailable['files'] = $this->getData(['font', 'files']); $fontsAvailable['files'] = $this->getData(['font', 'files']);
$fontsAvailable['imported'] = $this->getData(['font', 'imported']); $fontsAvailable['imported'] = $this->getData(['font', 'imported']);
$fontsAvailable['websafe'] = self::$fontsWebSafe; $fontsAvailable['websafe'] = common::$fontsWebSafe;
// Fontes installées // Fontes installées
$fonts = [ $fonts = [
@ -273,7 +273,7 @@ class core extends common
$css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}'; $css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}';
// Enregistre la personnalisation // Enregistre la personnalisation
$this->secure_file_put_contents(self::DATA_DIR . 'theme.css', $css); $this->secure_file_put_contents(common::DATA_DIR . 'theme.css', $css);
// Effacer le cache pour tenir compte de la couleur de fond TinyMCE // Effacer le cache pour tenir compte de la couleur de fond TinyMCE
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT"); header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
@ -284,7 +284,7 @@ class core extends common
} }
// Check la version rafraichissement du theme admin // Check la version rafraichissement du theme admin
$cssVersion = preg_split('/\*+/', file_get_contents(self::DATA_DIR . 'admin.css')); $cssVersion = preg_split('/\*+/', file_get_contents(common::DATA_DIR . 'admin.css'));
if (empty($cssVersion[1]) or $cssVersion[1] !== md5(json_encode($this->getData(['admin'])))) { if (empty($cssVersion[1]) or $cssVersion[1] !== md5(json_encode($this->getData(['admin'])))) {
// Version // Version
@ -293,7 +293,7 @@ class core extends common
// Fonts disponibles // Fonts disponibles
$fontsAvailable['files'] = $this->getData(['font', 'files']); $fontsAvailable['files'] = $this->getData(['font', 'files']);
$fontsAvailable['imported'] = $this->getData(['font', 'imported']); $fontsAvailable['imported'] = $this->getData(['font', 'imported']);
$fontsAvailable['websafe'] = self::$fontsWebSafe; $fontsAvailable['websafe'] = common::$fontsWebSafe;
/** /**
* Import des polices de caractères * Import des polices de caractères
@ -367,7 +367,7 @@ class core extends common
// Bordure du contour TinyMCE // Bordure du contour TinyMCE
$css .= '.mce-tinymce{border: 1px solid ' . $this->getData(['admin', 'borderBlockColor']) . '!important;}'; $css .= '.mce-tinymce{border: 1px solid ' . $this->getData(['admin', 'borderBlockColor']) . '!important;}';
// Enregistre la personnalisation // Enregistre la personnalisation
$this->secure_file_put_contents(self::DATA_DIR . 'admin.css', $css); $this->secure_file_put_contents(common::DATA_DIR . 'admin.css', $css);
} }
} }
/** /**
@ -383,8 +383,8 @@ class core extends common
require 'core/module/' . $classPath; require 'core/module/' . $classPath;
} }
// Module // Module
elseif (is_readable(self::MODULE_DIR . $classPath)) { elseif (is_readable(common::MODULE_DIR . $classPath)) {
require self::MODULE_DIR . $classPath; require common::MODULE_DIR . $classPath;
} }
// Librairie // Librairie
elseif (is_readable('core/vendor/' . $classPath)) { elseif (is_readable('core/vendor/' . $classPath)) {
@ -416,7 +416,7 @@ class core extends common
// Force la déconnexion des membres bannis ou d'une seconde session // Force la déconnexion des membres bannis ou d'une seconde session
if ( if (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
and ($this->getUser('group') === self::GROUP_BANNED and ($this->getUser('group') === common::GROUP_BANNED
or ($_SESSION['csrf'] !== $this->getData(['user', $this->getUser('id'), 'accessCsrf']) or ($_SESSION['csrf'] !== $this->getData(['user', $this->getUser('id'), 'accessCsrf'])
and $this->getData(['config', 'connect', 'autoDisconnect']) === true) and $this->getData(['config', 'connect', 'autoDisconnect']) === true)
) )
@ -431,7 +431,7 @@ class core extends common
and $this->getUrl(1) !== 'login' and $this->getUrl(1) !== 'login'
and ($this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') and ($this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
and $this->getUser('group') < self::GROUP_ADMIN and $this->getUser('group') < common::GROUP_ADMIN
) )
) )
) { ) {
@ -446,12 +446,12 @@ class core extends common
// Pour éviter une 404 sur une langue étrangère, bascule dans la langue correcte. // Pour éviter une 404 sur une langue étrangère, bascule dans la langue correcte.
if (is_null($this->getData(['page', $this->getUrl(0)]))) { if (is_null($this->getData(['page', $this->getUrl(0)]))) {
foreach (self::$languages as $key => $value) { foreach (common::$languages as $key => $value) {
if ( if (
is_dir(self::DATA_DIR . $key) && is_dir(common::DATA_DIR . $key) &&
file_exists(self::DATA_DIR . $key . '/page.json') file_exists(common::DATA_DIR . $key . '/page.json')
) { ) {
$pagesId = json_decode(file_get_contents(self::DATA_DIR . $key . '/page.json'), true); $pagesId = json_decode(file_get_contents(common::DATA_DIR . $key . '/page.json'), true);
if ( if (
is_array($pagesId['page']) && is_array($pagesId['page']) &&
array_key_exists($this->getUrl(0), $pagesId['page']) array_key_exists($this->getUrl(0), $pagesId['page'])
@ -468,7 +468,7 @@ class core extends common
$access = null; $access = null;
if ($this->getData(['page', $this->getUrl(0)]) !== null) { if ($this->getData(['page', $this->getUrl(0)]) !== null) {
if ( if (
$this->getData(['page', $this->getUrl(0), 'group']) === self::GROUP_VISITOR $this->getData(['page', $this->getUrl(0), 'group']) === common::GROUP_VISITOR
or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
// and $this->getUser('group') >= $this->getData(['page', $this->getUrl(0), 'group']) // and $this->getUser('group') >= $this->getData(['page', $this->getUrl(0), 'group'])
// Modification qui tient compte du profil de la page // Modification qui tient compte du profil de la page
@ -489,7 +489,7 @@ class core extends common
and $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') and $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
) or ($this->getData(['page', $this->getUrl(0), 'disable']) === true ) or ($this->getData(['page', $this->getUrl(0), 'disable']) === true
and $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') and $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
and $this->getUser('group') < self::GROUP_EDITOR and $this->getUser('group') < common::GROUP_EDITOR
) )
) { ) {
$access = false; $access = false;
@ -515,9 +515,9 @@ class core extends common
$this->getUser('id') && $this->getUser('id') &&
$userId !== $this->getUser('id') && $userId !== $this->getUser('id') &&
$this->getData(['user', $userId, 'accessUrl']) === $this->getUrl() && $this->getData(['user', $userId, 'accessUrl']) === $this->getUrl() &&
array_intersect($t, self::$concurrentAccess) && array_intersect($t, common::$concurrentAccess) &&
//array_intersect($t, self::$accessExclude) !== false && //array_intersect($t, common::$accessExclude) !== false &&
time() < $this->getData(['user', $userId, 'accessTimer']) + self::ACCESS_TIMER time() < $this->getData(['user', $userId, 'accessTimer']) + common::ACCESS_TIMER
) { ) {
$access = false; $access = false;
$accessInfo['userName'] = $this->getData(['user', $userId, 'lastname']) . ' ' . $this->getData(['user', $userId, 'firstname']); $accessInfo['userName'] = $this->getData(['user', $userId, 'lastname']) . ' ' . $this->getData(['user', $userId, 'firstname']);
@ -554,10 +554,10 @@ class core extends common
$inlineScript[] = $this->getData(['page', $this->getUrl(0), 'js']) === null ? '' : $this->getData(['page', $this->getUrl(0), 'js']); $inlineScript[] = $this->getData(['page', $this->getUrl(0), 'js']) === null ? '' : $this->getData(['page', $this->getUrl(0), 'js']);
// Importe le contenu, le CSS et le script des barres // Importe le contenu, le CSS et le script des barres
$contentRight = $this->getData(['page', $this->getUrl(0), 'barRight']) ? $this->getPage($this->getData(['page', $this->getUrl(0), 'barRight']), self::$siteContent) : ''; $contentRight = $this->getData(['page', $this->getUrl(0), 'barRight']) ? $this->getPage($this->getData(['page', $this->getUrl(0), 'barRight']), common::$siteContent) : '';
$inlineStyle[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'css']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'css']); $inlineStyle[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'css']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'css']);
$inlineScript[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'js']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'js']); $inlineScript[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'js']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'js']);
$contentLeft = $this->getData(['page', $this->getUrl(0), 'barLeft']) ? $this->getPage($this->getData(['page', $this->getUrl(0), 'barLeft']), self::$siteContent) : ''; $contentLeft = $this->getData(['page', $this->getUrl(0), 'barLeft']) ? $this->getPage($this->getData(['page', $this->getUrl(0), 'barLeft']), common::$siteContent) : '';
$inlineStyle[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'css']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'css']); $inlineStyle[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'css']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'css']);
$inlineScript[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'js']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'js']); $inlineScript[] = $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'js']) === null ? '' : $this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'js']);
@ -575,7 +575,7 @@ class core extends common
$this->addOutput([ $this->addOutput([
'title' => $title, 'title' => $title,
'content' => $this->getPage($this->getUrl(0), self::$siteContent), 'content' => $this->getPage($this->getUrl(0), common::$siteContent),
'metaDescription' => $this->getData(['page', $this->getUrl(0), 'metaDescription']), 'metaDescription' => $this->getData(['page', $this->getUrl(0), 'metaDescription']),
'metaTitle' => $this->getData(['page', $this->getUrl(0), 'metaTitle']), 'metaTitle' => $this->getData(['page', $this->getUrl(0), 'metaTitle']),
'typeMenu' => $this->getData(['page', $this->getUrl(0), 'typeMenu']), 'typeMenu' => $this->getData(['page', $this->getUrl(0), 'typeMenu']),
@ -601,7 +601,7 @@ class core extends common
: $this->getData(['page', $this->getUrl(0), 'metaDescription']); : $this->getData(['page', $this->getUrl(0), 'metaDescription']);
// Importe le CSS de la page principale // Importe le CSS de la page principale
$pageContent = $this->getPage($this->getUrl(0), self::$siteContent); $pageContent = $this->getPage($this->getUrl(0), common::$siteContent);
$this->addOutput([ $this->addOutput([
'title' => $title, 'title' => $title,
@ -646,7 +646,7 @@ class core extends common
$output = $module->output; $output = $module->output;
// Check le groupe de l'utilisateur // Check le groupe de l'utilisateur
if ( if (
($module::$actions[$action] === self::GROUP_VISITOR ($module::$actions[$action] === common::GROUP_VISITOR
or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD') or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
and $this->getUser('group') >= $module::$actions[$action] and $this->getUser('group') >= $module::$actions[$action]
and $this->getUser('permission', $moduleId, $action) and $this->getUser('permission', $moduleId, $action)
@ -659,10 +659,10 @@ class core extends common
foreach ($_POST as $postId => $postValue) { foreach ($_POST as $postId => $postValue) {
if (is_array($postValue)) { if (is_array($postValue)) {
foreach ($postValue as $subPostId => $subPostValue) { foreach ($postValue as $subPostId => $subPostValue) {
self::$inputBefore[$postId . '_' . $subPostId] = $subPostValue; common::$inputBefore[$postId . '_' . $subPostId] = $subPostValue;
} }
} else { } else {
self::$inputBefore[$postId] = $postValue; common::$inputBefore[$postId] = $postValue;
} }
} }
} }
@ -702,9 +702,9 @@ class core extends common
// Contenu par vue // Contenu par vue
elseif ($output['view']) { elseif ($output['view']) {
// Chemin en fonction d'un module du coeur ou d'un module // Chemin en fonction d'un module du coeur ou d'un module
$modulePath = in_array($moduleId, self::$coreModuleIds) ? 'core/' : ''; $modulePath = in_array($moduleId, common::$coreModuleIds) ? 'core/' : '';
// CSS // CSS
$stylePath = $modulePath . self::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.css'; $stylePath = $modulePath . common::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.css';
if (file_exists($stylePath)) { if (file_exists($stylePath)) {
$this->addOutput([ $this->addOutput([
'style' => file_get_contents($stylePath) 'style' => file_get_contents($stylePath)
@ -717,7 +717,7 @@ class core extends common
} }
// JS // JS
$scriptPath = $modulePath . self::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.js.php'; $scriptPath = $modulePath . common::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.js.php';
if (file_exists($scriptPath)) { if (file_exists($scriptPath)) {
ob_start(); ob_start();
include $scriptPath; include $scriptPath;
@ -726,7 +726,7 @@ class core extends common
]); ]);
} }
// Vue // Vue
$viewPath = $modulePath . self::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.php'; $viewPath = $modulePath . common::MODULE_DIR . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.php';
if (file_exists($viewPath)) { if (file_exists($viewPath)) {
ob_start(); ob_start();
include $viewPath; include $viewPath;
@ -844,25 +844,25 @@ class core extends common
} }
switch ($this->output['display']) { switch ($this->output['display']) {
// Layout brut // Layout brut
case self::DISPLAY_RAW: case common::DISPLAY_RAW:
echo $this->output['content']; echo $this->output['content'];
break; break;
// Layout vide // Layout vide
case self::DISPLAY_LAYOUT_BLANK: case common::DISPLAY_LAYOUT_BLANK:
require 'core/layout/blank.php'; require 'core/layout/blank.php';
break; break;
// Affichage en JSON // Affichage en JSON
case self::DISPLAY_JSON: case common::DISPLAY_JSON:
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode($this->output['content']); echo json_encode($this->output['content']);
break; break;
// RSS feed // RSS feed
case self::DISPLAY_RSS: case common::DISPLAY_RSS:
header('Content-type: application/rss+xml; charset=UTF-8'); header('Content-type: application/rss+xml; charset=UTF-8');
echo $this->output['content']; echo $this->output['content'];
break; break;
// Layout allégé // Layout allégé
case self::DISPLAY_LAYOUT_LIGHT: case common::DISPLAY_LAYOUT_LIGHT:
ob_start(); ob_start();
require 'core/layout/light.php'; require 'core/layout/light.php';
$content = ob_get_clean(); $content = ob_get_clean();
@ -873,7 +873,7 @@ class core extends common
echo $content; echo $content;
break; break;
// Layout principal // Layout principal
case self::DISPLAY_LAYOUT_MAIN: case common::DISPLAY_LAYOUT_MAIN:
ob_start(); ob_start();
require 'core/layout/main.php'; require 'core/layout/main.php';
$content = ob_get_clean(); $content = ob_get_clean();