ZwiiCMS/core/core.php

2859 lines
108 KiB
PHP
Raw Normal View History

2018-04-02 08:29:19 +02:00
<?php
/**
* This file is part of Zwii. *
2018-04-02 08:29:19 +02:00
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @license GNU General Public License, version 3
2019-01-22 21:56:38 +01:00
* @author Frédéric Tempez <frederic.tempez@outlook.com>
2020-01-21 08:53:30 +01:00
* @copyright Copyright (C) 2018-2020, Frédéric Tempez
* @link http://zwiicms.fr/
2018-04-02 08:29:19 +02:00
*/
class common {
const DISPLAY_RAW = 0;
const DISPLAY_JSON = 1;
const DISPLAY_LAYOUT_BLANK = 2;
const DISPLAY_LAYOUT_MAIN = 3;
const DISPLAY_LAYOUT_LIGHT = 4;
const GROUP_BANNED = -1;
const GROUP_VISITOR = 0;
const GROUP_MEMBER = 1;
2020-09-28 16:45:22 +02:00
const GROUP_EDITOR = 2;
2018-04-02 08:29:19 +02:00
const GROUP_ADMIN = 3;
2020-07-10 16:57:21 +02:00
const SIGNATURE_ID = 1;
const SIGNATURE_PSEUDO = 2;
const SIGNATURE_FIRSTLASTNAME = 3;
const SIGNATURE_LASTFIRSTNAME = 4;
2019-08-15 19:44:53 +02:00
// Dossier de travail
2019-05-28 09:04:10 +02:00
const BACKUP_DIR = 'site/backup/';
const DATA_DIR = 'site/data/';
const FILE_DIR = 'site/file/';
const TEMP_DIR = 'site/tmp/';
2019-03-22 19:04:51 +01:00
// Miniatures de la galerie
const THUMBS_SEPARATOR = 'mini_';
2020-04-15 17:26:26 +02:00
const THUMBS_WIDTH = 640;
// Contrôle d'édition temps max en secondes avant déconnexion 30 minutes
const ACCESS_TIMER = 1800;
2020-05-24 19:59:21 +02:00
// Numéro de version
2020-09-24 18:01:34 +02:00
const ZWII_VERSION = '10.4.00';
2020-02-23 17:44:44 +01:00
const ZWII_UPDATE_CHANNEL = "v10";
2018-04-02 08:29:19 +02:00
public static $actions = [];
public static $coreModuleIds = [
'config',
'install',
'maintenance',
'page',
'sitemap',
'theme',
2019-07-04 12:38:23 +02:00
'user'
2018-04-02 08:29:19 +02:00
];
public static $dataStage = [
'config',
'core',
2020-05-24 19:59:21 +02:00
'module',
'page',
'user',
'theme',
'admin'
];
2020-05-24 19:59:21 +02:00
public static $accessList = [
'user',
'theme',
'config',
'edit',
'config'
];
public static $accessExclude = [
'login',
'logout'
];
2018-04-02 08:29:19 +02:00
private $data = [];
private $hierarchy = [
'all' => [],
'visible' => [],
'bar' => []
2018-04-02 08:29:19 +02:00
];
private $input = [
'_COOKIE' => [],
'_POST' => []
];
public static $inputBefore = [];
public static $inputNotices = [];
public static $importNotices = [];
public static $coreNotices = [];
2018-04-02 08:29:19 +02:00
public $output = [
'access' => true,
'content' => '',
2019-05-02 13:21:48 +02:00
'contentLeft' => '',
'contentRight' => '',
2018-04-02 08:29:19 +02:00
'display' => self::DISPLAY_LAYOUT_MAIN,
'metaDescription' => '',
'metaTitle' => '',
'notification' => '',
2020-05-24 19:59:21 +02:00
'redirect' => '',
2018-04-02 08:29:19 +02:00
'script' => '',
'showBarEditButton' => false,
'showPageContent' => false,
'state' => false,
'style' => '',
'title' => null, // Null car un titre peut être vide
// Trié par ordre d'exécution
'vendor' => [
'jquery',
'normalize',
'lity',
'filemanager',
//'flatpickr', Appelé par les modules désactivé par défaut
2018-04-02 08:29:19 +02:00
// 'tinycolorpicker', Désactivé par défaut
// 'tinymce', Désactivé par défaut
// 'codemirror', // Désactivé par défaut
'tippy',
2019-03-11 11:36:23 +01:00
'zwiico',
2019-03-21 11:18:45 +01:00
'imagemap',
2020-05-11 17:46:25 +02:00
'simplelightbox'
2018-04-02 08:29:19 +02:00
],
'view' => ''
];
public static $groups = [
self::GROUP_BANNED => 'Banni',
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Membre',
2020-09-28 16:45:22 +02:00
self::GROUP_EDITOR => 'Éditeur',
2018-04-02 08:29:19 +02:00
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupEdits = [
self::GROUP_BANNED => 'Banni',
self::GROUP_MEMBER => 'Membre',
2020-09-28 16:45:22 +02:00
self::GROUP_EDITOR => 'Éditeur',
2018-04-02 08:29:19 +02:00
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupNews = [
self::GROUP_MEMBER => 'Membre',
2020-09-28 16:45:22 +02:00
self::GROUP_EDITOR => 'Éditeur',
2018-04-02 08:29:19 +02:00
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupPublics = [
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Membre',
2020-09-28 16:45:22 +02:00
self::GROUP_EDITOR => 'Éditeur',
2018-04-02 08:29:19 +02:00
self::GROUP_ADMIN => 'Administrateur'
];
public static $timezone;
private $url = '';
// Données de site
2018-04-02 08:29:19 +02:00
private $user = [];
private $page = [];
private $module = [];
2018-04-02 08:29:19 +02:00
/**
* Constructeur commun
*/
public function __construct() {
// Extraction des données http
if(isset($_POST)) {
$this->input['_POST'] = $_POST;
}
if(isset($_COOKIE)) {
$this->input['_COOKIE'] = $_COOKIE;
}
2020-05-24 19:59:21 +02:00
// Import version 9
if (file_exists(self::DATA_DIR . 'core.json') === true &&
$this->getData(['core','dataVersion']) < 10000) {
$keepUsers = isset($_SESSION['KEEP_USERS']) ? $_SESSION['KEEP_USERS'] : false;
$this->importData($keepUsers);
unset ($_SESSION['KEEP_USERS']);
2020-05-24 19:59:21 +02:00
// Réinstaller htaccess
copy('core/module/install/ressource/.htaccess', self::DATA_DIR . '.htaccess');
common::$importNotices [] = "Importation réalisée avec succès" ;
//echo '<script>window.location.replace("' . helper::baseUrl() . $this->getData(['config','homePageId']) . '")</script>';
2019-12-17 10:34:34 +01:00
}
// Installation fraîche, initialisation des modules manquants
// La langue d'installation par défaut est fr
foreach (self::$dataStage as $stageId) {
$folder = $this->dirData ($stageId, 'fr');
if (file_exists($folder . $stageId .'.json') === false) {
$this->initData($stageId,'fr');
common::$coreNotices [] = $stageId ;
}
2020-05-24 19:59:21 +02:00
}
2018-04-02 08:29:19 +02:00
// Utilisateur connecté
if($this->user === []) {
$this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]);
}
2020-05-16 21:24:20 +02:00
// Mise en cache des pages et des modules
$this->page = $this->getCache('page');
$this->module = $this->getCache('module');
2020-05-16 21:24:20 +02:00
2018-04-02 08:29:19 +02:00
// Construit la liste des pages parents/enfants
if($this->hierarchy['all'] === []) {
$pages = helper::arrayCollumn($this->getData(['page']), 'position', 'SORT_ASC');
// Parents
foreach($pages as $pageId => $pagePosition) {
if(
// Page parent
$this->getData(['page', $pageId, 'parentPageId']) === ""
// Ignore les pages dont l'utilisateur n'a pas accès
AND (
$this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
OR (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
)
)
) {
if($pagePosition !== 0) {
$this->hierarchy['visible'][$pageId] = [];
}
if($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
2018-04-02 08:29:19 +02:00
$this->hierarchy['all'][$pageId] = [];
}
}
// Enfants
foreach($pages as $pageId => $pagePosition) {
if(
// Page parent
$parentId = $this->getData(['page', $pageId, 'parentPageId'])
// Ignore les pages dont l'utilisateur n'a pas accès
AND (
(
$this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
AND $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR
)
OR (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])
AND $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
)
)
) {
if($pagePosition !== 0) {
$this->hierarchy['visible'][$parentId][] = $pageId;
}
if($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
2018-04-02 08:29:19 +02:00
$this->hierarchy['all'][$parentId][] = $pageId;
}
}
}
// Construit l'url
if($this->url === '') {
if($url = $_SERVER['QUERY_STRING']) {
$this->url = $url;
}
else {
$this->url = $this->getData(['config', 'homePageId']);
}
}
// Mise à jour des données core
$this->update();
2020-03-02 13:08:03 +01:00
// Données de proxy
$proxy = $this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort']);
if (!empty($this->getData(['config','proxyUrl'])) &&
!empty($this->getData(['config','proxyPort'])) ) {
$context = array(
'http' => array(
'proxy' => $proxy,
'request_fulluri' => true,
'verify_peer' => false,
'verify_peer_name' => false,
),
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false
)
);
stream_context_set_default($context);
2020-05-24 19:59:21 +02:00
}
2018-04-02 08:29:19 +02:00
}
/**
* Ajoute les valeurs en sortie
* @param array $output Valeurs en sortie
*/
public function addOutput($output) {
$this->output = array_merge($this->output, $output);
}
/**
* Ajoute une notice de champ obligatoire
* @param string $key Clef du champ
*/
public function addRequiredInputNotices($key) {
// La clef est un tableau
if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
if(empty($this->input['_POST'][$firstKey][$secondKey])) {
common::$inputNotices[$firstKey . '_' . $secondKey] = 'Obligatoire';
}
}
// La clef est une chaine
elseif(empty($this->input['_POST'][$key])) {
common::$inputNotices[$key] = 'Obligatoire';
}
}
/**
* Check du token CSRF (true = bo
*/
public function checkCSRF() {
return ((empty($_POST['csrf']) OR hash_equals($_SESSION['csrf'], $_POST['csrf']) === false) === false);
}
/**
* Supprime des données
* @param array $keys Clé(s) des données
*/
2020-05-24 19:59:21 +02:00
public function deleteData($keys) {
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
2020-09-18 03:57:02 +02:00
'dir' => $folder
]);
2018-04-02 08:29:19 +02:00
switch(count($keys)) {
case 1:
$db->delete($keys[0]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 2:
$db->delete($keys[0].'.'.$keys[1]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 3:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2]);
2020-05-24 19:59:21 +02:00
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 4:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 5:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 6:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 7:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5].'.'.$keys[6]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
}
}
/**
* Accède aux données
* @param array $keys Clé(s) des données
* @return mixed
*/
public function getData($keys = []) {
2020-05-24 19:59:21 +02:00
if (count($keys) >= 1) {
/**
* Lecture dans le cache, page et module
*/
if ($keys[0] === 'page' ||
$keys[0] === 'module' ) {
2020-05-16 21:24:20 +02:00
// Décent dans les niveaux de la variable $data
$data = array_merge ($this->page , $this->module);
2020-05-16 21:24:20 +02:00
foreach($keys as $key) {
// Si aucune donnée n'existe retourne null
if(isset($data[$key]) === false) {
return null;
}
// Sinon décent dans les niveaux
else {
$data = $data[$key];
}
}
// Retourne les données
return $data;
}
/**
* Lecture directe
*/
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
2020-09-18 03:57:02 +02:00
'dir' => $folder
]);
switch(count($keys)) {
case 1:
$tempData = $db->get($keys[0]);
2020-05-24 19:59:21 +02:00
break;
case 2:
$tempData = $db->get($keys[0].'.'.$keys[1]);
break;
case 3:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2]);
break;
case 4:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3]);
break;
case 5:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4]);
break;
case 6:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5]);
break;
case 7:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5].'.'.$keys[6]);
break;
2018-04-02 08:29:19 +02:00
}
return $tempData;
2018-04-02 08:29:19 +02:00
}
}
2020-05-16 21:24:20 +02:00
/**
* Lecture des fichiers de données de page et mise ne cache
* @param @return string données des pages
*/
public function getCache($data) {
$folder = $this->dirData ($data,'fr');
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $data . '.json',
'dir' => $folder
]);
$tempData = $db->get($data);
return [$data => $tempData];
2020-05-16 21:24:20 +02:00
}
/*
* Dummy function
* Compatibilité des modules avec v8 et v9
*/
public function saveData() {
return;
}
2018-04-02 08:29:19 +02:00
/**
2019-02-10 13:07:43 +01:00
* Accède à la liste des pages parents et de leurs enfants
2018-04-02 08:29:19 +02:00
* @param int $parentId Id de la page parent
* @param bool $onlyVisible Affiche seulement les pages visibles
2019-02-10 13:07:43 +01:00
* @param bool $onlyBlock Affiche seulement les pages de type barre
2018-04-02 08:29:19 +02:00
* @return array
*/
public function getHierarchy($parentId = null, $onlyVisible = true, $onlyBlock = false) {
2018-04-02 08:29:19 +02:00
$hierarchy = $onlyVisible ? $this->hierarchy['visible'] : $this->hierarchy['all'];
2020-05-24 19:59:21 +02:00
$hierarchy = $onlyBlock ? $this->hierarchy['bar'] : $hierarchy;
2018-04-02 08:29:19 +02:00
// Enfants d'un parent
if($parentId) {
if(array_key_exists($parentId, $hierarchy)) {
return $hierarchy[$parentId];
}
else {
return [];
}
}
// Parents et leurs enfants
else {
return $hierarchy;
}
}
/**
* Accède à une valeur des variables http (ordre de recherche en l'absence de type : _COOKIE, _POST)
* @param string $key Clé de la valeur
* @param int $filter Filtre à appliquer à la valeur
* @param bool $required Champ requis
* @return mixed
*/
public function getInput($key, $filter = helper::FILTER_STRING_SHORT, $required = false) {
// La clef est un tableau
if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
foreach($this->input as $type => $values) {
// Champ obligatoire
if($required) {
$this->addRequiredInputNotices($key);
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
2018-04-02 08:29:19 +02:00
if(
array_key_exists($firstKey, $values)
AND array_key_exists($secondKey, $values[$firstKey])
) {
// Retourne la valeur filtrée
if($filter) {
return helper::filter($this->input[$type][$firstKey][$secondKey], $filter);
}
// Retourne la valeur
else {
return $this->input[$type][$firstKey][$secondKey];
}
}
}
}
// La clef est une chaine
else {
foreach($this->input as $type => $values) {
2020-05-24 19:59:21 +02:00
// Champ obligatoire
2018-04-02 08:29:19 +02:00
if($required) {
$this->addRequiredInputNotices($key);
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
2018-04-02 08:29:19 +02:00
if(array_key_exists($key, $values)) {
// Retourne la valeur filtrée
if($filter) {
return helper::filter($this->input[$type][$key], $filter);
}
// Retourne la valeur
else {
return $this->input[$type][$key];
}
}
}
}
// Sinon retourne null
return helper::filter(null, $filter);
}
/**
* Accède à une partie l'url ou à l'url complète
* @param int $key Clé de l'url
* @return string|null
*/
public function getUrl($key = null) {
// Url complète
if($key === null) {
return $this->url;
}
// Une partie de l'url
else {
$url = explode('/', $this->url);
return array_key_exists($key, $url) ? $url[$key] : null;
}
}
/**
* Accède à l'utilisateur connecté
* @param int $key Clé de la valeur
* @return string|null
*/
public function getUser($key) {
if(is_array($this->user) === false) {
return false;
}
elseif($key === 'id') {
return $this->getInput('ZWII_USER_ID');
}
elseif(array_key_exists($key, $this->user)) {
return $this->user[$key];
}
else {
return false;
}
}
/**
* Check qu'une valeur est transmise par la méthode _POST
* @return bool
*/
public function isPost() {
return ($this->checkCSRF() AND $this->input['_POST'] !== []);
}
/**
* Import des données de la version 9
* Convertit un fichier de données data.json puis le renomme
2018-04-02 08:29:19 +02:00
*/
public function importData($keepUsers = false) {
// Trois tentatives de lecture
2018-04-02 08:29:19 +02:00
for($i = 0; $i < 3; $i++) {
$tempData=json_decode(file_get_contents(self::DATA_DIR.'core.json'), true);
$tempTheme=json_decode(file_get_contents(self::DATA_DIR.'theme.json'), true);
if($tempData && $tempTheme) {
// Backup
rename (self::DATA_DIR.'core.json',self::DATA_DIR.'imported_core.json');
rename (self::DATA_DIR.'theme.json',self::DATA_DIR.'imported_theme.json');
2018-12-23 23:37:17 +01:00
break;
}
elseif($i === 2) {
throw new \ErrorException('Import des données impossible.');
2018-04-02 08:29:19 +02:00
}
// Pause de 10 millisecondes
usleep(10000);
}
// Dossier de langues
if (!file_exists(self::DATA_DIR . '/fr')) {
mkdir (self::DATA_DIR . '/fr');
}
// Un seul fichier pour éviter les erreurs de sauvegarde des v9
$tempData = array_merge($tempData,$tempTheme);
// Ecriture des données
$this->setData(['config',$tempData['config']]);
2020-05-24 19:59:21 +02:00
$this->setData(['core',$tempData['core']]);
$this->setData(['page',$tempData['page']]);
2020-05-24 19:59:21 +02:00
$this->setData(['module',$tempData['module']]);
$this->setData(['theme',$tempData['theme']]);
// Import des users sauvegardés si option active
if ($keepUsers === false) {
2020-05-24 19:59:21 +02:00
$this->setData(['user',$tempData['user']]);
}
// Nettoyage du fichier de thème pour forcer une régénération
if (file_exists(self::DATA_DIR . '/theme.css')) { // On ne sait jamais
unlink (self::DATA_DIR . '/theme.css');
2020-05-24 19:59:21 +02:00
}
2018-04-02 08:29:19 +02:00
}
2019-03-13 17:11:04 +01:00
/**
* Génère un fichier json avec la liste des pages
2020-05-24 19:59:21 +02:00
*
*/
public function pages2Json() {
// Sauve la liste des pages pour TinyMCE
$parents = [];
$rewrite = (helper::checkRewrite()) ? '' : '?';
// Boucle de recherche des pages actives
foreach($this->getHierarchy(null,false,false) as $parentId => $childIds) {
$children = [];
// Exclure les barres
2020-05-24 19:59:21 +02:00
if ($this->getData(['page', $parentId, 'block']) !== 'bar' ) {
// Boucler sur les enfants et récupérer le tableau children avec la liste des enfants
2020-05-24 19:59:21 +02:00
foreach($childIds as $childId) {
$children [] = [ 'title' => ' » '. html_entity_decode($this->getData(['page', $childId, 'title']), ENT_QUOTES) ,
'value'=> $rewrite.$childId
2020-05-24 19:59:21 +02:00
];
2019-03-13 17:11:04 +01:00
}
2020-05-24 19:59:21 +02:00
// Traitement
if (empty($childIds)) {
// Pas d'enfant, uniquement l'entrée du parent
$parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
2020-05-24 19:59:21 +02:00
'value'=> $rewrite.$parentId
];
} else {
// Des enfants, on ajoute la page parent en premier
array_unshift ($children , ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
2020-05-24 19:59:21 +02:00
'value'=> $rewrite.$parentId
]);
// puis on ajoute les enfants au parent
$parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
2020-05-24 19:59:21 +02:00
'value'=> $rewrite.$parentId ,
'menu' => $children
];
}
}
}
// Sitemap et Search
$children = [];
$children [] = ['title'=>'Rechercher dans le site',
'value'=>$rewrite.'search'
];
$children [] = ['title'=>'Plan du site',
'value'=>$rewrite.'sitemap'
];
$parents [] = ['title' => 'Pages spéciales',
'value' => '#',
'menu' => $children
];
2020-05-24 19:59:21 +02:00
// Enregistrement : 3 tentatives
for($i = 0; $i < 3; $i++) {
if (file_put_contents ('core/vendor/tinymce/link_list.json', json_encode($parents), LOCK_EX) !== false) {
break;
}
// Pause de 10 millisecondes
usleep(10000);
2020-05-24 19:59:21 +02:00
}
2019-03-13 17:11:04 +01:00
}
/**
* Retourne une chemin localisé pour l'enregistrement des données
* @param $stageId nom du module
* @param $lang langue des pages
* @return string du dossier à créer
*/
public function dirData($id, $lang) {
// Sauf pour les pages et les modules
if ($id === 'page' ||
$id === 'module') {
$folder = self::DATA_DIR . $lang . '/' ;
} else {
$folder = self::DATA_DIR;
}
return ($folder);
}
2019-05-02 13:21:48 +02:00
/**
* Génère un fichier robots.txt à l'installation
* Si le fichier existe déjà les commandes sont ajoutées
2019-05-02 13:21:48 +02:00
*/
public function createRobots() {
2020-05-24 19:59:21 +02:00
$robotValue =
2019-05-02 13:21:48 +02:00
PHP_EOL .
'# ZWII CONFIG ---------' . PHP_EOL .
'User-agent: *' . PHP_EOL .
2020-05-24 19:59:21 +02:00
'Allow: /site/file/' .PHP_EOL .
2019-09-18 18:31:40 +02:00
'Disallow: /site/' .PHP_EOL .
2019-06-15 18:27:00 +02:00
'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml' . PHP_EOL .
'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml.gz' . PHP_EOL .
2019-05-02 13:21:48 +02:00
'# ZWII CONFIG ---------' . PHP_EOL ;
2020-05-24 19:59:21 +02:00
if (file_exists('robots.txt')) {
2019-05-02 13:21:48 +02:00
return(file_put_contents(
'robots.txt',
$robotValue,
FILE_APPEND
));
} else {
// Sinon on crée un fichier
return(file_put_contents(
'robots.txt',
$robotValue
));
}
}
/**
* Génère un fichier un fichier sitemap.xml
2019-05-02 13:21:48 +02:00
* https://github.com/icamys/php-sitemap-generator
* $command valeurs possible
* all : génère un site map complet
2019-05-02 13:21:48 +02:00
* Sinon contient id de la page à créer
*/
public function createSitemap($command = "all") {
2019-12-15 10:47:18 +01:00
//require_once "core/vendor/sitemap/SitemapGenerator.php";
2019-05-02 13:21:48 +02:00
$timezone = $this->getData(['config','timezone']);
2019-05-02 13:21:48 +02:00
$sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl());
// will create also compressed (gzipped) sitemap
$sitemap->createGZipFile = true;
// determine how many urls should be put into one file
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$sitemap->maxURLsPerSitemap = 50000;
// sitemap file name
$sitemap->sitemapFileName = "sitemap.xml";
2020-05-24 19:59:21 +02:00
2019-05-02 13:21:48 +02:00
$datetime = new DateTime(date('c'));
$datetime->format(DateTime::ATOM); // Updated ISO8601
// sitemap index file name
$sitemap->sitemapIndexFileName = "sitemap-index.xml";
foreach($this->getHierarchy(null, null, null) as $parentPageId => $childrenPageIds) {
2019-06-08 21:30:12 +02:00
// Exclure les barres et les pages non publiques et les pages masquées
2020-05-24 19:59:21 +02:00
if ($this->getData(['page',$parentPageId,'group']) !== 0 ||
$this->getData(['page', $parentPageId, 'block']) === 'bar' ) {
continue;
}
2019-06-18 16:25:39 +02:00
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
if ($this->getData(['page', $parentPageId, 'disable']) !== true ) {
$sitemap->addUrl ($parentPageId,$datetime);
}
// Sous-pages
2019-05-02 13:21:48 +02:00
foreach($childrenPageIds as $childKey) {
2019-06-08 21:30:12 +02:00
if ($this->getData(['page',$childKey,'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
continue;
}
2019-05-02 13:21:48 +02:00
$sitemap->addUrl($childKey,$datetime);
// La sous-page est un blog
if ($this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
!empty($this->getData(['module',$childKey])) ) {
foreach($this->getData(['module',$childKey]) as $articleId => $article) {
if($this->getData(['module',$childKey,$articleId,'state']) === true) {
$date = $this->getData(['module',$childKey,$articleId,'publishedOn']);
$sitemap->addUrl( $childKey . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
2020-05-24 19:59:21 +02:00
}
}
2020-05-24 19:59:21 +02:00
}
}
// Articles du blog
if ($this->getData(['page', $parentPageId, 'moduleId']) === 'blog' &&
2020-05-24 19:59:21 +02:00
!empty($this->getData(['module',$parentPageId])) ) {
foreach($this->getData(['module',$parentPageId]) as $articleId => $article) {
2020-05-24 19:59:21 +02:00
if($this->getData(['module',$parentPageId,$articleId,'state']) === true) {
$date = $this->getData(['module',$parentPageId,$articleId,'publishedOn']);
$sitemap->addUrl( $parentPageId . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
}
}
2019-05-02 13:21:48 +02:00
}
2020-05-24 19:59:21 +02:00
}
2019-05-02 13:21:48 +02:00
// generating internally a sitemap
$sitemap->createSitemap();
// writing early generated sitemap to file
$sitemap->writeSitemap();
2020-05-24 19:59:21 +02:00
2019-05-02 13:21:48 +02:00
return(file_exists('sitemap.xml'));
}
2020-05-24 19:59:21 +02:00
/*
* Création d'une miniature
* Fonction utilisée lors de la mise à jour d'une version 9 à une version 10
* @param string $src image source
* @param string $dets image destination
* @param integer $desired_width largeur demandée
*/
function makeThumb($src, $dest, $desired_width) {
// Vérifier l'existence du dossier de destination.
$fileInfo = pathinfo($dest);
if (!is_dir($fileInfo['dirname'])) {
2020-04-20 10:19:43 +02:00
mkdir($fileInfo['dirname'],0755,true);
}
// Type d'image
switch( $fileInfo['extension']) {
case 'jpeg':
case 'jpg':
$source_image = imagecreatefromjpeg($src);
break;
case 'png':
$source_image = imagecreatefrompng($src);
break;
case 'gif':
$source_image = imagecreatefromgif($src);
break;
}
// Image valide
if ($source_image) {
$width = imagesx($source_image);
2020-05-24 19:59:21 +02:00
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
2020-05-24 19:59:21 +02:00
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
2020-05-24 19:59:21 +02:00
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
2020-05-24 19:59:21 +02:00
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
switch(mime_content_type($src) ) {
case 'image/jpeg':
case 'image/jpg':
return (imagejpeg($virtual_image, $dest));
break;
case 'image/png':
return (imagepng($virtual_image, $dest));
break;
case 'image/gif':
return (imagegif($virtual_image, $dest));
break;
2020-05-24 19:59:21 +02:00
}
} else {
return (false);
}
}
/**
2018-04-02 08:29:19 +02:00
* Envoi un mail
* @param string|array $to Destinataire
* @param string $subject Sujet
* @param string $content Contenu
* @return bool
*/
2020-02-28 14:58:50 +01:00
public function sendMail($to, $subject, $content, $replyTo = null) {
2020-05-10 18:06:57 +02:00
2019-02-28 12:46:38 +01:00
2018-04-02 08:29:19 +02:00
// Layout
ob_start();
2020-05-24 19:59:21 +02:00
include 'core/layout/mail.php';
2018-04-02 08:29:19 +02:00
$layout = ob_get_clean();
$mail = new PHPMailer\PHPMailer\PHPMailer;
2020-05-24 19:59:21 +02:00
$mail->CharSet = 'UTF-8';
2018-04-02 08:29:19 +02:00
// Mail
2019-02-28 12:46:38 +01:00
try{
2020-05-10 18:06:57 +02:00
// Paramètres SMTP
if ($this->getdata(['config','smtp','enable'])) {
2020-05-24 19:59:21 +02:00
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
2020-05-10 18:06:57 +02:00
$mail->isSMTP();
2020-05-11 12:15:51 +02:00
$mail->SMTPAutoTLS = false;
2020-05-10 18:06:57 +02:00
$mail->Host = $this->getdata(['config','smtp','host']);
$mail->Port = (int) $this->getdata(['config','smtp','port']);
2020-05-24 19:59:21 +02:00
if ($this->getData(['config','smtp','auth'])) {
2020-05-10 18:06:57 +02:00
$mail->Username = $this->getData(['config','smtp','username']);
$mail->Password = helper::decrypt($this->getData(['config','smtp','username']),$this->getData(['config','smtp','password']));
2020-05-10 18:06:57 +02:00
$mail->SMTPAuth = $this->getData(['config','smtp','auth']);
$mail->SMTPSecure = $this->getData(['config','smtp','secure']);
$mail->setFrom($this->getData(['config','smtp','username']));
if (is_null($replyTo)) {
$mail->addReplyTo($this->getData(['config','smtp','username']));
} else {
$mail->addReplyTo($replyTo);
}
2020-05-10 18:06:57 +02:00
}
// Fin SMTP
} else {
2020-05-10 18:06:57 +02:00
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
2020-05-24 19:59:21 +02:00
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title']));
2020-05-10 18:06:57 +02:00
if (is_null($replyTo)) {
$mail->addReplyTo('no-reply@' . $host, $this->getData(['config', 'title']));
} else {
$mail->addReplyTo($replyTo);
2020-05-24 19:59:21 +02:00
}
2020-05-10 18:06:57 +02:00
}
2019-02-28 12:46:38 +01:00
if(is_array($to)) {
foreach($to as $userMail) {
$mail->addAddress($userMail);
2019-02-28 12:46:38 +01:00
}
2018-04-02 08:29:19 +02:00
}
2019-02-28 12:46:38 +01:00
else {
$mail->addAddress($to);
2019-02-28 12:46:38 +01:00
}
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $layout;
$mail->AltBody = strip_tags($content);
if($mail->send()) {
return true;
}
else {
return $mail->ErrorInfo;
}
} catch (phpmailerException $e) {
return $e->errorMessage();
} catch (Exception $e) {
return $e->getMessage();
2018-04-02 08:29:19 +02:00
}
2019-12-16 12:23:25 +01:00
}
2018-04-02 08:29:19 +02:00
/**
* Sauvegarde des données
2018-04-02 08:29:19 +02:00
* @param array $keys Clé(s) des données
*/
public function setData($keys = []) {
2020-09-08 14:14:59 +02:00
// Pas d'enregistrement lorsqu'une notice est présente ou tableau transmis vide
if (!empty(self::$inputNotices
OR empty($keys))) {
return false;
}
2020-05-24 19:59:21 +02:00
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
2020-09-18 03:57:02 +02:00
'dir' => $folder
]);
2020-05-24 19:59:21 +02:00
switch(count($keys)) {
2018-04-02 08:29:19 +02:00
case 2:
$db->set($keys[0],$keys[1]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 3:
$db->set($keys[0].'.'.$keys[1],$keys[2]);
2020-05-24 19:59:21 +02:00
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 4:
$db->set($keys[0].'.'.$keys[1].'.'.$keys[2],$keys[3]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 5:
$db->set($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3],$keys[4]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 6:
$db->set($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4],$keys[5]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
case 7:
$db->set($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5],$keys[6]);
$db->save();
2018-04-02 08:29:19 +02:00
break;
}
return true;
}
/**
* Initialisation des données
2020-05-24 19:59:21 +02:00
* @param array $module : nom du module à générer
* choix valides : core config user theme page module
2020-05-24 19:59:21 +02:00
*/
public function initData($module, $lang = 'fr', $sampleSite = false) {
2020-05-24 19:59:21 +02:00
// Tableau avec les données vierges
2020-05-24 19:59:21 +02:00
require_once('core/module/install/ressource/defaultdata.php');
// Stockage dans un sous-dossier localisé
// Le dossier de langue existe t-il ?
if (!file_exists(self::DATA_DIR . '/' . $lang)) {
mkdir (self::DATA_DIR . '/' . $lang);
}
$folder = $this->dirData ($module,$lang);
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $module . '.json',
2020-09-18 03:57:02 +02:00
'dir' => $folder
]);
if ($sampleSite === true) {
$db->set($module,init::$siteData[$module]);
} else {
$db->set($module,init::$defaultData[$module]);
}
2020-05-24 19:59:21 +02:00
$db->save;
2018-04-02 08:29:19 +02:00
}
2018-04-02 08:29:19 +02:00
/**
* Mises à jour
*/
private function update() {
2020-05-24 19:59:21 +02:00
2018-12-23 23:37:17 +01:00
// Version 9.0.0
2019-02-12 15:29:44 +01:00
if($this->getData(['core', 'dataVersion']) < 9000) {
2019-03-23 21:13:11 +01:00
$this->deleteData(['theme', 'site', 'block']);
if ($this->getData(['theme','menu','position']) === 'body-top') {
$this->setData(['theme','menu','position','top']);
}
2020-05-24 19:59:21 +02:00
$this->setData(['theme', 'menu','fixed',false]);
2019-02-12 15:29:44 +01:00
$this->setData(['core', 'dataVersion', 9000]);
//$this->SaveData();
2020-05-24 19:59:21 +02:00
}
2019-03-05 09:46:34 +01:00
// Version 9.0.01
2019-03-24 08:59:29 +01:00
if($this->getData(['core', 'dataVersion']) < 9001) {
$this->deleteData(['config', 'social', 'googleplusId']);
2019-03-05 09:46:34 +01:00
$this->setData(['core', 'dataVersion', 9001]);
//$this->SaveData();
2019-03-19 06:59:28 +01:00
}
// Version 9.0.08
if($this->getData(['core', 'dataVersion']) < 9008) {
$this->setData(['theme', 'footer', 'textTransform','none']);
$this->setData(['theme', 'footer', 'fontWeight','normal']);
2019-04-08 19:29:20 +02:00
$this->setData(['theme', 'footer', 'fontSize','.8em']);
2020-05-24 19:59:21 +02:00
$this->setData(['theme', 'footer', 'font','Open+Sans']);
2019-03-19 06:59:28 +01:00
$this->setData(['core', 'dataVersion', 9008]);
//$this->SaveData();
2019-03-23 18:41:05 +01:00
}
// Version 9.0.09
if($this->getData(['core', 'dataVersion']) < 9009) {
$this->setData(['core', 'dataVersion', 9009]);
//$this->SaveData();
2019-03-23 18:57:19 +01:00
}
2019-03-24 08:59:29 +01:00
// Version 9.0.10
if($this->getData(['core', 'dataVersion']) < 9010) {
2020-05-24 19:59:21 +02:00
$this->deleteData(['config', 'social', 'googleplusId']);
2019-03-24 08:59:29 +01:00
$this->setData(['core', 'dataVersion', 9010]);
//$this->SaveData();
2019-03-24 08:59:29 +01:00
}
// Version 9.0.11
if($this->getData(['core', 'dataVersion']) < 9011) {
if ($this->getData(['theme','menu','position']) === 'body')
$this->setData(['theme','menu','position','site']);
$this->setData(['core', 'dataVersion', 9011]);
//$this->SaveData();
}
2019-04-09 09:39:19 +02:00
// Version 9.0.17
if($this->getData(['core', 'dataVersion']) < 9017) {
$this->setData(['theme','footer','displayVersion', true ]);
2019-04-09 09:39:19 +02:00
$this->setData(['core', 'dataVersion', 9017]);
//$this->SaveData();
2019-04-09 09:39:19 +02:00
}
2019-05-02 13:21:48 +02:00
// Version 9.1.0
if($this->getData(['core', 'dataVersion']) < 9100) {
$this->setData(['theme','footer','displayVersion', true ]);
$this->setData(['theme','footer','displaySiteMap', true ]);
$this->setData(['theme','footer','displayCopyright', false ]);
2019-05-02 13:21:48 +02:00
$this->setData(['core', 'dataVersion', 9100]);
//$this->SaveData();
2019-05-02 13:21:48 +02:00
}
2019-07-10 09:19:12 +02:00
// Version 9.2.00
if($this->getData(['core', 'dataVersion']) < 9200) {
2019-06-18 20:08:04 +02:00
$this->setData(['theme','footer','template', 3 ]);
2020-05-24 19:59:21 +02:00
$this->setData(['theme','footer','margin', true ]);
$this->setData(['theme','footer','displayLegal', !empty($this->getdata(['config','legalPageId'])) ]);
2019-07-10 09:19:12 +02:00
$this->setData(['theme','footer','displaySearch', false ]);
$this->setData(['config','social','githubId', '' ]);
$this->setData(['core', 'dataVersion', 9200]);
//$this->SaveData();
2019-07-10 09:19:12 +02:00
}
2019-08-16 09:40:46 +02:00
// Version 9.2.05
if($this->getData(['core', 'dataVersion']) < 9205) {
// Nettoyage Swiper
if (file_exists('core/vendor/tinymce/templates/swiper.html')) {
unlink ('core/vendor/tinymce/templates/swiper.html');
}
if (is_dir('core/vendor/swiper')) {
$dir = getcwd();
chdir('core/vendor/swiper');
$files = glob('*');
foreach($files as $file) unlink($file);
chdir($dir);
rmdir ('core/vendor/swiper/');
}
$this->setData(['core', 'dataVersion', 9205]);
//$this->SaveData();
2019-08-16 09:40:46 +02:00
}
// Version 9.2.10
if($this->getData(['core', 'dataVersion']) < 9210) {
2020-05-24 19:59:21 +02:00
// Utile pour l'installation d'un backup sur un autre serveur
//$this->setData(['core', 'baseUrl', helper::baseUrl(false,false) ]);
2019-11-09 19:03:03 +01:00
// Suppression d'une option de hauteur de la bannière
if ($this->getData(['theme', 'header','height']) === 'none') {
$this->setData(['theme', 'header','height','150px']);
2020-05-24 19:59:21 +02:00
}
2019-11-09 19:03:03 +01:00
// Changer le nom de la clé linkHome -> linkHomePage
$this->setdata(['theme','header','linkHomePage',$this->getData(['theme','header','linkHome'])]);
$this->deleteData(['theme','header','linkHome']);
2019-11-09 19:03:03 +01:00
// Préparation des clés de légendes pour la v10
// Construire une liste plate de parents et d'enfants
2019-12-17 09:34:53 +01:00
$pageList = array();
foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) {
$pageList [] = $parentKey;
foreach ($parentValue as $childKey) {
$pageList [] = $childKey;
}
2020-05-24 19:59:21 +02:00
}
// Parcourir toutes les pages
foreach ($pageList as $parentKey => $parent) {
//La page a une galerie
if ($this->getData(['page',$parent,'moduleId']) === 'gallery' ) {
// Lire les données du module
// Parcourir les dossiers de la galerie
2020-05-24 19:59:21 +02:00
$tempData = $this->getData(['module', $parent]);
foreach ($tempData as $galleryKey => $galleryItem) {
foreach ($galleryItem as $legendKey => $legendValue) {
// Recherche la clé des légendes
if ($legendKey === 'legend') {
2020-05-24 19:59:21 +02:00
foreach ($legendValue as $itemKey=>$itemValue) {
// Ancien nom avec un point devant l'extension ?
if (strpos($itemKey,'.') > 0) {
// Créer une nouvelle clé
$this->setData(['module', $parent, $galleryKey, 'legend',str_replace('.','',$itemKey),$itemValue]);
// Supprimer la valeur
$this->deleteData(['module', $parent, $galleryKey, 'legend',$itemKey]);
2020-05-24 19:59:21 +02:00
}
}
}
}
}
}
2020-05-24 19:59:21 +02:00
}
$this->setData(['core', 'dataVersion', 9210]);
}
2019-11-21 22:18:42 +01:00
// Version 9.2.11
if($this->getData(['core', 'dataVersion']) < 9211) {
$autoUpdate= mktime(0, 0, 0);
$this->setData(['core', 'lastAutoUpdate', $autoUpdate]);
$this->setData(['config','autoUpdate', true]);
$this->setData(['core', 'dataVersion', 9211]);
}
// Version 9.2.12
if($this->getData(['core', 'dataVersion']) < 9212) {
2019-12-01 10:49:03 +01:00
$this->setData(['theme','menu', 'activeColorAuto',true]);
$this->setData(['theme','menu', 'activeColor','rgba(255, 255, 255, 1)']);
$this->setData(['core', 'dataVersion', 9212]);
//$this->SaveData();
}
// Version 9.2.15
if($this->getData(['core', 'dataVersion']) < 9215) {
// Données de la barre de langue dans le menu
$this->setData(['theme','menu','burgerTitle',true]);
$this->setData(['core', 'dataVersion', 9215]);
2020-05-24 19:59:21 +02:00
}
2019-12-22 18:33:58 +01:00
// Version 9.2.16
if($this->getData(['core', 'dataVersion']) < 9216) {
// Utile pour l'installation d'un backup sur un autre serveur
// mais avec la réécriture d'URM
$this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]);
$this->setData(['core', 'dataVersion', 9216]);
}
2020-02-13 10:48:56 +01:00
// Version 9.2.21
if($this->getData(['core', 'dataVersion']) < 9221) {
// Utile pour l'installation d'un backup sur un autre serveur
// mais avec la réécriture d'URM
$this->setData(['theme', 'body', 'toTopbackgroundColor', 'rgba(33, 34, 35, .8)' ]);
$this->setData(['theme', 'body', 'toTopColor', 'rgba(255, 255, 255, 1)' ]);
$this->setData(['core', 'dataVersion', 9221]);
2020-05-24 19:59:21 +02:00
}
2020-03-02 13:08:03 +01:00
// Version 9.2.23
if($this->getData(['core', 'dataVersion']) < 9223) {
// Utile pour l'installation d'un backup sur un autre serveur
// mais avec la réécriture d'URM
$this->setData(['config', 'proxyUrl', '' ]);
$this->setData(['config', 'proxyPort', '' ]);
$this->setData(['config', 'proxyType', 'tcp://' ]);
$this->setData(['core', 'dataVersion', 9223]);
2020-05-24 19:59:21 +02:00
}
2020-04-02 21:41:18 +02:00
// Version 9.2.27
if($this->getData(['core', 'dataVersion']) < 9227) {
// Forcer la régénération du thème
if (file_exists(self::DATA_DIR.'theme.css')) {
unlink (self::DATA_DIR.'theme.css');
2020-05-24 19:59:21 +02:00
}
2020-04-02 21:41:18 +02:00
$this->setData(['core', 'dataVersion', 9227]);
2020-05-24 19:59:21 +02:00
}
2019-12-10 21:30:31 +01:00
// Version 10.0.00
if($this->getData(['core', 'dataVersion']) < 10000) {
$this->setData(['config', 'faviconDark','faviconDark.ico']);
//----------------------------------------
// Mettre à jour les données des galeries
$pageList = array();
foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) {
$pageList [] = $parentKey;
foreach ($parentValue as $childKey) {
$pageList [] = $childKey;
}
2020-05-24 19:59:21 +02:00
}
2020-04-09 10:03:20 +02:00
// Mise à jour des données pour la galerie v2
foreach ($pageList as $parentKey => $parent) {
//La page a une galerie
if ($this->getData(['page',$parent,'moduleId']) === 'gallery' ) {
// Parcourir les dossiers de la galerie
2020-05-24 19:59:21 +02:00
$tempData = $this->getData(['module', $parent]);
$i = 1;
foreach ($tempData as $galleryKey => $galleryItem) {
2020-04-09 10:03:20 +02:00
// Ordre de tri des galeries
if ( $this->getdata(['module',$parent,$galleryKey,'config','sort']) === NULL) {
$this->setdata(['module',$parent,$galleryKey,'config','sort','SORT_ASC']);
}
2020-04-09 10:03:20 +02:00
// Position de la galerie, tri manuel
if ( $this->getdata(['module',$parent,$galleryKey,'config','position']) === NULL) {
$this->setdata(['module',$parent,$galleryKey,'config','position',$i++]);
2020-05-24 19:59:21 +02:00
}
2020-04-09 10:03:20 +02:00
// Positions des images, tri manuel
if ( $this->getdata(['module',$parent,$galleryKey,'positions']) === NULL) {
2020-04-09 10:03:20 +02:00
$c = count($this->getdata(['module',$parent,$galleryKey,'legend']));
$this->setdata(['module',$parent,$galleryKey,'positions', range(0,$c-1) ]);
2020-04-09 10:03:20 +02:00
}
2020-04-05 18:22:48 +02:00
// Image de couverture
if ( $this->getdata(['module',$parent,$galleryKey,'config','homePicture']) === NULL) {
if (is_dir($this->getdata(['module',$parent,$galleryKey,'config','directory']))) {
$iterator = new DirectoryIterator($this->getdata(['module',$parent,$galleryKey,'config','directory']));
foreach($iterator as $fileInfos) {
2020-05-24 19:59:21 +02:00
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
$this->setdata(['module',$parent,$galleryKey,'config','homePicture',$fileInfos->getFilename()]);
break;
}
}
}
2020-05-24 19:59:21 +02:00
}
}
}
2020-05-24 19:59:21 +02:00
}
2020-04-24 09:42:16 +02:00
// Contrôle des options php.ini pour la mise à jour auto
2020-10-12 09:49:17 +02:00
if (helper::urlGetContents('http://zwiicms.fr/update/' . common::ZWII_UPDATE_CHANNEL . '/version') === false) {
2020-04-24 09:42:16 +02:00
$this->setData(['config','autoUpdate',false]);
}
2020-05-24 19:59:21 +02:00
$this->setData(['core', 'dataVersion', 10000]);
}
// Version 10.0.92
2020-05-14 07:25:36 +02:00
if ($this->getData(['core', 'dataVersion']) < 10092) {
// Suppression du dossier fullpage
2020-05-12 09:19:28 +02:00
if (is_dir('core/vendor/fullpage')) {
$dir = getcwd();
chdir('core/vendor/fullpage');
$files = glob('*');
foreach($files as $file) unlink($file);
chdir($dir);
rmdir ('core/vendor/fullpage/');
}
2020-05-14 07:25:36 +02:00
if (file_exists('core/vendor/tinymce/templates/fullPageSections.html')) {
unlink ('core/vendor/tinymce/templates/fullPageSections.html'); }
if (file_exists('core/vendor/tinymce/templates/fullPageSlides.html')) {
unlink ('core/vendor/tinymce/templates/fullPageSlides.html'); }
2020-05-12 09:19:28 +02:00
$this->setData(['core', 'dataVersion', 10092]);
}
// Version 10.0.93
if ($this->getData(['core', 'dataVersion']) < 10093) {
// Déplacement du fichier admin.css dans data
if (file_exists('core/layout/admin.css')) {
2020-05-24 19:59:21 +02:00
copy('core/layout/admin.css',self::DATA_DIR.'admin.css');
unlink('core/layout/admin.css');
2020-05-24 19:59:21 +02:00
}
//Déplacement d'un fichier de ressources
if (file_exists('core/module/config/ressource/.htaccess')) {
unlink('core/module/config/ressource/.htaccess');
rmdir ('core/module/config/ressource');
}
$this->setData(['core', 'dataVersion', 10093]);
// Réorganisation du thème
$this->setData(['theme','text','linkTextColor',$this->getData(['theme','link', 'textColor'])]);
}
// Version 10.1.04
if ($this->getData(['core', 'dataVersion']) < 10104) {
$this->setData(['theme','text','linkColor','rgba(74, 105, 189, 1)']);
$this->deleteData(['theme','text','linkTextColor']);
$this->setdata(['theme','block','backgroundColor','rgba(236, 239, 241, 1)']);
$this->setdata(['theme','block','borderColor','rgba(236, 239, 241, 1)']);
$this->setdata(['theme','menu','radius','0px']);
$this->setData(['core', 'dataVersion', 10104]);
}
// Version 10.2.00
if ($this->getData(['core', 'dataVersion']) < 10200) {
// Paramètres du compte connecté
if ($this->getUser('id')) {
$this->setData(['user', $this->getUser('id'), 'connectFail',0]);
$this->setData(['user', $this->getUser('id'), 'connectTimeout',0]);
$this->setData(['user', $this->getUser('id'), 'accessTimer',0]);
$this->setData(['user', $this->getUser('id'), 'accessUrl','']);
$this->setData(['user', $this->getUser('id'), 'accessCsrf',$_SESSION['csrf']]);
}
// Paramètres de sécurité
$this->setData(['config', 'connect', 'attempt',999]);
$this->setData(['config', 'connect', 'timeout',0]);
$this->setData(['config', 'connect', 'log',false]);
// Thème
$this->deleteData(['admin','colorButtonText']);
// Remettre à zéro le thème pour la génération du CSS du blog
if (file_exists(self::DATA_DIR . 'theme.css')) {
unlink(self::DATA_DIR . 'theme.css');
}
// Créer les en-têtes du journal
$d = 'Date;Heure;IP;Id;Action' . PHP_EOL;
file_put_contents(self::DATA_DIR . 'journal.log',$d);
// Init préservation htaccess
$this->setData(['config','autoUpdateHtaccess',false]);
// Options de barre de membre simple
$this->setData(['theme','menu','memberBar',true]);
// Thème Menu : couleur de page active non définie
if (!$this->getData(['theme','menu','activeTextColor']) ) {
$this->setData(['theme','menu','activeTextColor', $this->getData(['theme','menu','textColor']) ]);
}
$this->setData(['core', 'updateAvailable', false]);
$this->setData(['core', 'dataVersion', 10200]);
}
// Version 10.2.01
if ($this->getData(['core', 'dataVersion']) < 10201) {
// Options de barre de membre simple
$this->setData(['theme','footer','displayMemberBar',false]);
$this->deleteData(['theme','footer','displayMemberAccount']);
$this->deleteData(['theme','footer','displayMemberLogout']);
$this->setData(['core', 'dataVersion', 10201]);
}
// Version 10.3.00
if ($this->getData(['core', 'dataVersion']) < 10300) {
// Options de barre de membre simple
$this->setData(['config','page404','none']);
2020-08-13 14:11:33 +02:00
$this->setData(['config','page403','none']);
2020-09-25 20:02:01 +02:00
$this->setData(['config','page302','none']);
// Module de recherche
// Suppression du dossier search
if (is_dir('core/module/search')) {
$dir = getcwd();
chdir('core/module/search');
$files = glob('*');
foreach($files as $file) unlink($file);
chdir($dir);
rmdir ('core/module/search/');
}
// Désactivation de l'option dans le pied de page
$this->setData(['theme','footer','displaySearch',false]);
// Inscription des nouvelles variables
$this->setData(['config','searchPageId','']);
// Mettre à jour les données des galeries
$pageList = array();
foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) {
$pageList [] = $parentKey;
foreach ($parentValue as $childKey) {
$pageList [] = $childKey;
}
}
// Mise à jour des données de thème de la galerie
// Les données de thème sont communes au site
foreach ($pageList as $parentKey => $parent) {
//La page a une galerie
if ($this->getData(['page',$parent,'moduleId']) === 'gallery' ) {
foreach ( $this->getData(['module', $parent]) as $galleryKey => $galleryItem) {
// Transfert du theme dans une structure unique
if ( is_array($this->getdata(['theme',$parent])) ) {
$this->setdata(['theme','gallery',$this->getdata(['theme',$parent])]);
}
}
$this->deleteData(['theme',$parent]);
}
}
// Mise à jour du numéro de version
$this->setData(['core', 'dataVersion', 10300]);
2020-08-13 14:11:33 +02:00
}
2020-09-25 20:02:01 +02:00
// Version 10.3.01
if ($this->getData(['core', 'dataVersion']) < 10301) {
// Inscription des nouvelles variables
if ($this->getData(['config','searchPageId']) === '') {
$this->setData(['config','searchPageId','none']);
}
if ($this->getData(['config','legalPageId']) === '') {
$this->setData(['config','legalPageId','none']);
}
$this->setData(['core', 'dataVersion', 10301]);
}
2020-09-30 09:16:40 +02:00
// Version 10.3.02
if ($this->getData(['core', 'dataVersion']) < 10302) {
// Activation par défaut du captcha à la connexion
$this->setData(['config', 'connect','captcha', true]);
2020-10-03 14:13:27 +02:00
$this->setData(['core', 'dataVersion', 10302]);
}
2020-09-24 18:01:34 +02:00
// Version 10.4.00
2020-09-28 16:20:43 +02:00
if ($this->getData(['core', 'dataVersion']) < 10400) {
// Ajouter le prénom comme pseudo et le pseudo comme signature
foreach($this->getData(['user']) as $userId => $userIds){
$this->setData(['user',$userId,'pseudo',$this->getData(['user',$userId,'firstname'])]);
$this->setData(['user',$userId,'signature',2]);
}
// Ajouter les champs de blog v3
// Liste des pages dans pageList
$pageList = array();
foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) {
$pageList [] = $parentKey;
foreach ($parentValue as $childKey) {
$pageList [] = $childKey;
}
}
// Parcourir pageList et rechercher les modules de blog
foreach ($pageList as $parentKey => $parent) {
//La page a une galerie
if ($this->getData(['page',$parent,'moduleId']) === 'blog' ) {
$articleIds = array_keys(helper::arrayCollumn($this->getData(['module',$parent]), 'publishedOn', 'SORT_DESC'));
foreach ($articleIds as $key => $article) {
// Droits les deux groupes
2020-10-11 19:10:42 +02:00
$this->setData(['module', $parent, $article,'editConsent','group']);
// Limite de taille 500
$this->setData(['module', $parent, $article,'commentMaxlength', '500']);
// Pas d'approbation des commentaires
2020-10-11 19:10:42 +02:00
$this->setData(['module', $parent, $article,'commentApproved', false ]);
// pas de notification
$this->setData(['module', $parent, $article,'commentNotification', false ]);
// groupe de notification
$this->setData(['module', $parent, $article,'commentGroupNotification', 3 ]);
}
// Traitement des commentaires
if ( is_array($this->getData(['module', $parent, $article,'comment'])) ) {
foreach($this->getData(['module', $parent, $article,'comment']) as $commentId => $comment) {
// Approbation
$this->setData(['module', $parent, $article,'comment', $commentId, 'approval', true ]);
}
}
}
}
2020-09-24 18:01:34 +02:00
$this->setData(['core', 'dataVersion', 10400]);
}
2020-10-11 19:29:33 +02:00
// Version 10.3.03
if ($this->getData(['core', 'dataVersion']) < 10303) {
// Activation par défaut du captcha à la connexion
$this->setData(['config', 'connect','captcha10', false]);
$this->setData(['core', 'dataVersion', 10303]);
}
2018-04-02 08:29:19 +02:00
}
}
class core extends common {
/**
* Constructeur du coeur
*/
public function __construct() {
parent::__construct();
// Token CSRF
if(empty($_SESSION['csrf'])) {
$_SESSION['csrf'] = bin2hex(openssl_random_pseudo_bytes(32));
}
// Fuseau horaire
self::$timezone = $this->getData(['config', 'timezone']); // Utile pour transmettre le timezone à la classe helper
date_default_timezone_set(self::$timezone);
// Supprime les fichiers temporaires
$lastClearTmp = mktime(0, 0, 0);
if($lastClearTmp > $this->getData(['core', 'lastClearTmp']) + 86400) {
2019-05-28 09:04:10 +02:00
$iterator = new DirectoryIterator(self::TEMP_DIR);
2018-04-02 08:29:19 +02:00
foreach($iterator as $fileInfos) {
2020-05-24 19:59:21 +02:00
if( $fileInfos->isFile() &&
2019-08-07 19:16:04 +02:00
$fileInfos->getBasename() !== '.htaccess' &&
$fileInfos->getBasename() !== '.gitkeep'
) {
2018-04-02 08:29:19 +02:00
@unlink($fileInfos->getPathname());
}
}
// Date de la dernière suppression
$this->setData(['core', 'lastClearTmp', $lastClearTmp]);
// Enregistre les données
//$this->SaveData();
2018-04-02 08:29:19 +02:00
}
// Backup automatique des données
$lastBackup = mktime(0, 0, 0);
if(
$this->getData(['config', 'autoBackup'])
AND $lastBackup > $this->getData(['core', 'lastBackup']) + 86400
AND $this->getData(['user']) // Pas de backup pendant l'installation
) {
// Copie des fichier de données
helper::autoBackup(self::BACKUP_DIR,['backup','tmp','file']);
2018-04-02 08:29:19 +02:00
// Date du dernier backup
$this->setData(['core', 'lastBackup', $lastBackup]);
// Supprime les backups de plus de 30 jours
2019-05-28 09:04:10 +02:00
$iterator = new DirectoryIterator(self::BACKUP_DIR);
2018-04-02 08:29:19 +02:00
foreach($iterator as $fileInfos) {
if(
$fileInfos->isFile()
AND $fileInfos->getBasename() !== '.htaccess'
AND $fileInfos->getMTime() + (86400 * 30) < time()
) {
@unlink($fileInfos->getPathname());
}
}
}
// Crée le fichier de personnalisation avancée
2019-05-28 09:04:10 +02:00
if(file_exists(self::DATA_DIR.'custom.css') === false) {
file_put_contents(self::DATA_DIR.'custom.css', file_get_contents('core/module/theme/resource/custom.css'));
chmod(self::DATA_DIR.'custom.css', 0755);
2018-04-02 08:29:19 +02:00
}
// Crée le fichier de personnalisation
2019-05-28 09:04:10 +02:00
if(file_exists(self::DATA_DIR.'theme.css') === false) {
file_put_contents(self::DATA_DIR.'theme.css', '');
chmod(self::DATA_DIR.'theme.css', 0755);
2018-04-02 08:29:19 +02:00
}
// Crée le fichier de personnalisation de l'administration
if(file_exists(self::DATA_DIR.'admin.css') === false) {
file_put_contents(self::DATA_DIR.'admin.css', '');
chmod(self::DATA_DIR.'admin.css', 0755);
2020-05-24 19:59:21 +02:00
}
// Check la version rafraichissement du theme
2019-05-28 09:04:10 +02:00
$cssVersion = preg_split('/\*+/', file_get_contents(self::DATA_DIR.'theme.css'));
2018-04-02 08:29:19 +02:00
if(empty($cssVersion[1]) OR $cssVersion[1] !== md5(json_encode($this->getData(['theme'])))) {
// Version
$css = '/*' . md5(json_encode($this->getData(['theme']))) . '*/';
// Import des polices de caractères
$css .= '@import url("https://fonts.googleapis.com/css?family=' . $this->getData(['theme', 'text', 'font']) . '|' . $this->getData(['theme', 'title', 'font']) . '|' . $this->getData(['theme', 'header', 'font']) . '|' . $this->getData(['theme', 'menu', 'font']) . '");';
2018-04-02 08:29:19 +02:00
// Fond du site
$colors = helper::colorVariants($this->getData(['theme', 'body', 'backgroundColor']));
2020-04-19 17:24:03 +02:00
$css .= 'body,div.mce-edit-area{background-color:' . $colors['normal'] . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'text', 'font'])) . '",sans-serif}';
// Fond TinyMCe
$css .= 'div.mce-edit-area{background-color:' . $colors['normal'] . ' !important}';
2018-04-02 08:29:19 +02:00
if($themeBodyImage = $this->getData(['theme', 'body', 'image'])) {
2020-04-19 17:24:03 +02:00
$css .= 'body,div.mce-edit-area{background-image:url("../file/source/' . $themeBodyImage . '");background-position:' . $this->getData(['theme', 'body', 'imagePosition']) . ';background-attachment:' . $this->getData(['theme', 'body', 'imageAttachment']) . ';background-size:' . $this->getData(['theme', 'body', 'imageSize']) . ';background-repeat:' . $this->getData(['theme', 'body', 'imageRepeat']) . '}';
$css .= 'div.mce-edit-area{background-image:url("../file/source/' . $themeBodyImage . '") !important;background-position:' . $this->getData(['theme', 'body', 'imagePosition']) . ';background-attachment:' . $this->getData(['theme', 'body', 'imageAttachment']) . ';background-size:' . $this->getData(['theme', 'body', 'imageSize']) . ';background-repeat:' . $this->getData(['theme', 'body', 'imageRepeat']) . '}';
2018-04-02 08:29:19 +02:00
}
2020-02-13 10:48:56 +01:00
// Icône BacktoTop
$css .= '#backToTop {background-color:' .$this->getData(['theme', 'body', 'toTopbackgroundColor']). ';color:'.$this->getData(['theme', 'body', 'toTopColor']).';}';
2018-04-02 08:29:19 +02:00
// Site
2020-05-18 10:50:43 +02:00
$colors = helper::colorVariants($this->getData(['theme', 'text', 'linkColor']));
2018-04-02 08:29:19 +02:00
$css .= 'a{color:' . $colors['normal'] . '}';
2020-07-16 11:01:57 +02:00
$css .= 'a:hover:not(.inputFile, button){color:' . $colors['darken'] . '}';
2018-04-02 08:29:19 +02:00
$css .= 'body,.row > div{font-size:' . $this->getData(['theme', 'text', 'fontSize']) . '}';
2020-06-17 20:45:49 +02:00
$css .= 'body{color:' . $this->getData(['theme', 'text', 'textColor']) . '}';
$css .= 'select,input[type=\'password\'],input[type=\'email\'],input[type=\'text\'],.inputFile,select,textarea{color:' . $this->getData(['theme', 'text', 'textColor']) .';background-color:'.$this->getData(['theme', 'site', 'backgroundColor']).';}';
// spécifiques au module de blog
$css .= '.blogDate {color:' . $this->getData(['theme', 'text', 'textColor']) . ';}.blogPicture img{border:1px solid ' . $this->getData(['theme', 'text', 'textColor']) . '; box-shadow: 1px 1px 5px ' . $this->getData(['theme', 'text', 'textColor']) . ';}';
2020-03-28 09:45:26 +01:00
// Couleur fixée dans admin.css
2020-05-24 19:59:21 +02:00
//$css .= '.button.buttonGrey,.button.buttonGrey:hover{color:' . $this->getData(['theme', 'text', 'textColor']) . '}';
2018-04-02 08:29:19 +02:00
$css .= '.container{max-width:' . $this->getData(['theme', 'site', 'width']) . '}';
2020-05-24 19:59:21 +02:00
$margin = $this->getData(['theme', 'site', 'margin']) ? '0' : '20px';
$css .= $this->getData(['theme', 'site', 'width']) === '100%' ? '#site{margin:0 auto !important;} body{margin:0 auto !important;} #bar{margin:0 auto !important;} body > header{margin:0 auto !important;} body > nav {margin: 0 auto !important;} body > footer {margin:0 auto !important;}': "#site{margin: " . $margin . " auto !important;} body{margin:0px 10px;} #bar{margin: 0 -10px;} body > header{margin: 0 -10px;} body > nav {margin: 0 -10px;} body > footer {margin: 0 -10px;} ";
$css .= $this->getData(['theme', 'site', 'width']) === '750px' ? '.button, button{font-size:0.8em;}' : '';
2019-06-19 03:42:05 +02:00
$css .= '#site{background-color:' . $this->getData(['theme', 'site', 'backgroundColor']) . ';border-radius:' . $this->getData(['theme', 'site', 'radius']) . ';box-shadow:' . $this->getData(['theme', 'site', 'shadow']) . ' #212223;}';
2020-03-16 08:59:10 +01:00
$css .= '.editorWysiwyg {background-color:' . $this->getData(['theme', 'site', 'backgroundColor']) . ';}';
2018-04-02 08:29:19 +02:00
$colors = helper::colorVariants($this->getData(['theme', 'button', 'backgroundColor']));
$css .= '.speechBubble,.button,.button:hover,button[type=\'submit\'],.pagination a,.pagination a:hover,input[type=\'checkbox\']:checked + label:before,input[type=\'radio\']:checked + label:before,.helpContent{background-color:' . $colors['normal'] . ';color:' . $colors['text'] . '}';
$css .= '.helpButton span{color:' . $colors['normal'] . '}';
$css .= 'input[type=\'text\']:hover,input[type=\'password\']:hover,.inputFile:hover,select:hover,textarea:hover{border-color:' . $colors['normal'] . '}';
$css .= '.speechBubble:before{border-color:' . $colors['normal'] . ' transparent transparent transparent}';
$css .= '.button:hover,button[type=\'submit\']:hover,.pagination a:hover,input[type=\'checkbox\']:not(:active):checked:hover + label:before,input[type=\'checkbox\']:active + label:before,input[type=\'radio\']:checked:hover + label:before,input[type=\'radio\']:not(:checked):active + label:before{background-color:' . $colors['darken'] . '}';
$css .= '.helpButton span:hover{color:' . $colors['darken'] . '}';
2020-05-24 19:59:21 +02:00
$css .= '.button:active,button[type=\'submit\']:active,.pagination a:active{background-color:' . $colors['veryDarken'] . '}';
2018-04-02 08:29:19 +02:00
$colors = helper::colorVariants($this->getData(['theme', 'title', 'textColor']));
$css .= 'h1,h2,h3,h4,h5,h6,h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:' . $colors['normal'] . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'title', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'title', 'fontWeight']) . ';text-transform:' . $this->getData(['theme', 'title', 'textTransform']) . '}';
$css .= 'h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color:' . $colors['darken'] . '}';
2020-05-18 10:50:43 +02:00
// Les blocs
$colors = helper::colorVariants($this->getData(['theme', 'block', 'backgroundColor']));
$css .= '.block {border: 1px solid ' . $this->getdata(['theme','block','borderColor']) . ';}.block h4 {background-color:'. $colors['normal'] . ';color:' . $colors['text'] .';}';
$css .= '.mce-tinymce {border: 1px solid ' . $this->getdata(['theme','block','borderColor']) .' !important;}';
2018-04-02 08:29:19 +02:00
// Bannière
$colors = helper::colorVariants($this->getData(['theme', 'header', 'backgroundColor']));
if($this->getData(['theme', 'header', 'margin'])) {
if($this->getData(['theme', 'menu', 'position']) === 'site-first') {
$css .= 'header{margin:0 20px}';
}
else {
$css .= 'header{margin:20px 20px 0 20px}';
}
}
2018-09-09 11:47:24 +02:00
$css .= 'header{background-size:' . $this->getData(['theme','header','imageContainer']).'}';
2019-05-06 21:53:00 +02:00
$css .= 'header{background-color:' . $colors['normal'];
2019-11-11 09:00:34 +01:00
// Valeur de hauteur traditionnelle
$css .= ';height:' . $this->getData(['theme', 'header', 'height']) . ';line-height:' . $this->getData(['theme', 'header', 'height']) ;
2019-05-06 21:53:00 +02:00
$css .= ';text-align:' . $this->getData(['theme', 'header', 'textAlign']) . '}';
2018-04-02 08:29:19 +02:00
if($themeHeaderImage = $this->getData(['theme', 'header', 'image'])) {
$css .= 'header{background-image:url("../file/source/' . $themeHeaderImage . '");background-position:' . $this->getData(['theme', 'header', 'imagePosition']) . ';background-repeat:' . $this->getData(['theme', 'header', 'imageRepeat']) . '}';
}
$colors = helper::colorVariants($this->getData(['theme', 'header', 'textColor']));
$css .= 'header span{color:' . $colors['normal'] . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'header', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'header', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'header', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'header', 'textTransform']) . '}';
// Menu
2020-05-24 19:59:21 +02:00
$colors = helper::colorVariants($this->getData(['theme', 'menu', 'backgroundColor']));
2018-04-02 08:29:19 +02:00
$css .= 'nav,nav a{background-color:' . $colors['normal'] . '}';
$css .= 'nav a,#toggle span,nav a:hover{color:' . $this->getData(['theme', 'menu', 'textColor']) . '}';
$css .= 'nav a:hover{background-color:' . $colors['darken'] . '}';
$css .= 'nav a.active{color:' . $this->getData(['theme','menu','activeTextColor']) . ';}';
if ($this->getData(['theme','menu','activeColorAuto']) === true) {
2020-05-24 19:59:21 +02:00
$css .= 'nav a.active{background-color:' . $colors['veryDarken'] . '}';
} else {
$css .= 'nav a.active{background-color:' . $this->getData(['theme','menu','activeColor']) . '}';
/*$color2 = helper::colorVariants($this->getData(['theme', 'menu', 'textColor']));
$css .= 'nav a.active{color:' . $color2['text'] . '}';*/
2020-05-24 19:59:21 +02:00
}
$css .= 'nav #burgerText{color:' . $colors['text'] . '}';
2020-05-24 19:59:21 +02:00
$css .= 'nav .navLevel1 a.active {border-radius:' . $this->getData(['theme', 'menu', 'radius']) . '}';
2018-04-02 08:29:19 +02:00
$css .= '#menu{text-align:' . $this->getData(['theme', 'menu', 'textAlign']) . '}';
if($this->getData(['theme', 'menu', 'margin'])) {
if(
$this->getData(['theme', 'menu', 'position']) === 'site-first'
2019-03-23 18:41:05 +01:00
OR $this->getData(['theme', 'menu', 'position']) === 'site-second'
2018-04-02 08:29:19 +02:00
) {
$css .= 'nav{padding:10px 10px 0 10px;}';
2018-04-02 08:29:19 +02:00
}
else {
$css .= 'nav{padding:0 10px}';
2020-05-24 19:59:21 +02:00
}
} else {
$css .= 'nav{margin:0}';
2018-04-02 08:29:19 +02:00
}
if(
$this->getData(['theme', 'menu', 'position']) === 'top'
) {
$css .= 'nav{padding:0 10px;}';
}
2020-05-24 19:59:21 +02:00
$css .= '#toggle span,#menu a{padding:' . $this->getData(['theme', 'menu', 'height']) .';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'menu', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'menu', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'menu', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'menu', 'textTransform']) . '}';
2018-04-02 08:29:19 +02:00
// Pied de page
2018-04-02 08:29:19 +02:00
$colors = helper::colorVariants($this->getData(['theme', 'footer', 'backgroundColor']));
if($this->getData(['theme', 'footer', 'margin'])) {
2019-11-12 19:01:53 +01:00
$css .= 'footer{padding:0 20px;}';
2019-06-20 07:51:56 +02:00
} else {
$css .= 'footer{padding:0}';
2018-04-02 08:29:19 +02:00
}
$css .= 'footer span, #footerText > p {color:' . $this->getData(['theme', 'footer', 'textColor']) . ';font-family:"' . str_replace('+', ' ', $this->getData(['theme', 'footer', 'font'])) . '",sans-serif;font-weight:' . $this->getData(['theme', 'footer', 'fontWeight']) . ';font-size:' . $this->getData(['theme', 'footer', 'fontSize']) . ';text-transform:' . $this->getData(['theme', 'footer', 'textTransform']) . '}';
2018-04-02 08:29:19 +02:00
$css .= 'footer{background-color:' . $colors['normal'] . ';color:' . $this->getData(['theme', 'footer', 'textColor']) . '}';
$css .= 'footer a{color:' . $this->getData(['theme', 'footer', 'textColor']) . '}';
$css .= 'footer #footersite > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}';
$css .= 'footer #footerbody > div {margin:' . $this->getData(['theme', 'footer', 'height']) . ' 0}';
2018-04-02 08:29:19 +02:00
$css .= '#footerSocials{text-align:' . $this->getData(['theme', 'footer', 'socialsAlign']) . '}';
$css .= '#footerText > p {text-align:' . $this->getData(['theme', 'footer', 'textAlign']) . '}';
2018-04-02 08:29:19 +02:00
$css .= '#footerCopyright{text-align:' . $this->getData(['theme', 'footer', 'copyrightAlign']) . '}';
2020-05-24 19:59:21 +02:00
// Marge supplémentaire lorsque le pied de page est fixe
2020-02-04 13:17:38 +01:00
if ( $this->getData(['theme', 'footer', 'fixed']) === true &&
$this->getData(['theme', 'footer', 'position']) === 'body') {
2020-02-04 10:17:56 +01:00
$css .= "@media (min-width: 769px) { #site {margin-bottom: 100px;} }";
$css .= "@media (max-width: 768px) { #site {margin-bottom: 150px;} }";
}
2018-04-02 08:29:19 +02:00
// Enregistre la personnalisation
2019-05-28 09:04:10 +02:00
file_put_contents(self::DATA_DIR.'theme.css', $css);
// Effacer le cache pour tenir compte de la couleur de fond TinyMCE
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
2018-04-02 08:29:19 +02:00
}
// Check la version rafraichissement du theme admin
$cssVersion = preg_split('/\*+/', file_get_contents(self::DATA_DIR.'admin.css'));
if(empty($cssVersion[1]) OR $cssVersion[1] !== md5(json_encode($this->getData(['admin'])))) {
// Version
$css = '/*' . md5(json_encode($this->getData(['admin']))) . '*/';
$colors = helper::colorVariants($this->getData(['admin','backgroundColor']));
$css .= '#site{background-color:' . $colors['normal']. ';}';
2020-07-15 22:56:51 +02:00
$css .= '.row > div {font:' . $this->getData(['admin','fontSize']) . ' "' . $this->getData(['admin','fontText']) . '", sans-serif;}';
$css .= 'body h1, h2, h3, h4, h5, h6 {font-family:' . $this->getData(['admin','fontTitle' ]) . ', sans-serif;color:' . $this->getData(['admin','colorTitle' ]) . ';}';
$css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this->getData(['admin','colorText']) . ';}';
$colors = helper::colorVariants($this->getData(['admin','backgroundColorButton']));
2020-06-07 17:04:02 +02:00
$css .= 'input[type="checkbox"]:checked + label::before,.speechBubble{background-color:' . $colors['normal'] . ';color:' . $colors['text'] . ';}';
$css .= '.speechBubble::before {border-color:' . $colors['normal'] . ' transparent transparent transparent;}';
$css .= '.button {background-color:' . $colors['normal'] . ';color:' . $colors['text'] . ';}.button:hover {background-color:' . $colors['darken'] . ';color:' . $colors['text'] . ';}.button:active {background-color:' . $colors['veryDarken'] . ';color:' . $colors['text'] . ';}';
$colors = helper::colorVariants($this->getData(['admin','backgroundColorButtonGrey']));
$css .= '.button.buttonGrey {background-color: ' . $colors['normal'] . ';color: ' . $colors['text'] . ';}.button.buttonGrey:hover {background-color:' . $colors['darken'] . ';color:' . $colors['text'] . ';}.button.buttonGrey:active {background-color:' . $colors['veryDarken'] . ';color:' . $colors['text'] . ';}';
$colors = helper::colorVariants($this->getData(['admin','backgroundColorButtonRed']));
$css .= '.button.buttonRed {background-color: ' . $colors['normal'] . ';color: ' . $colors['text'] . ';}.button.buttonRed:hover {background-color:' . $colors['darken'] . ';color:' . $colors['text'] . ';}.button.buttonRed:active {background-color:' . $colors['veryDarken'] . ';color:' . $colors['text'] . ';}';
$colors = helper::colorVariants($this->getData(['admin','backgroundColorButtonGreen']));
$css .= 'button[type=submit] {background-color: ' . $colors['normal'] . ';color: ' . $colors['text'] . '}button[type=submit]:hover {background-color: ' . $colors['darken'] . ';color: ' . $colors['text'] .';}button[type=submit]:active {background-color: ' . $colors['darken'] . ';color: ' .$colors['text'] .';}';
2020-05-17 07:41:44 +02:00
$colors = helper::colorVariants($this->getData(['admin','backgroundBlockColor']));
$css .= '.block {border: 1px solid ' . $this->getData(['admin','borderBlockColor']) . ';}.block h4 {background-color: ' . $colors['normal'] . ';color:' . $colors['text'] . ';}';
$css .= 'table tr,input[type=email],input[type=text],input[type=password],select:not(#barSelectPage),textarea:not(.editorWysiwyg),.inputFile{background-color: ' . $colors['normal'] . ';color:' . $colors['text'] . ';border: 1px solid ' . $this->getData(['admin','borderBlockColor']) . ';}';
2020-06-07 17:04:02 +02:00
// Bordure du contour TinyMCE
$css .= '.mce-tinymce{border: 1px solid '. $this->getData(['admin','borderBlockColor']) . '!important;}';
// Enregistre la personnalisation
file_put_contents(self::DATA_DIR.'admin.css', $css);
}
2018-04-02 08:29:19 +02:00
}
/**
* Auto-chargement des classes
* @param string $className Nom de la classe à charger
*/
public static function autoload($className) {
2020-05-10 18:06:57 +02:00
2018-04-02 08:29:19 +02:00
$classPath = strtolower($className) . '/' . strtolower($className) . '.php';
// Module du coeur
if(is_readable('core/module/' . $classPath)) {
require 'core/module/' . $classPath;
}
// Module
elseif(is_readable('module/' . $classPath)) {
require 'module/' . $classPath;
}
// Librairie
elseif(is_readable('core/vendor/' . $classPath)) {
require 'core/vendor/' . $classPath;
}
}
/**
* Routage des modules
*/
public function router() {
// Installation
if(
$this->getData(['user']) === []
AND $this->getUrl(0) !== 'install'
) {
http_response_code(302);
header('Location:' . helper::baseUrl() . 'install');
exit();
}
// Journalisation
$dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;
$dataLog .= helper::getIp() . ';';
$dataLog .= $this->getUser('id') ? $this->getUser('id') . ';' : 'anonyme' . ';';
$dataLog .= $this->getUrl();
$dataLog .= PHP_EOL;
if ($this->getData(['config','connect','log'])) {
file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND);
}
2020-05-24 19:59:21 +02:00
// Force la déconnexion des membres bannis ou d'une seconde session
2018-04-02 08:29:19 +02:00
if (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
2020-05-24 19:59:21 +02:00
AND ( $this->getUser('group') === self::GROUP_BANNED
OR $_SESSION['csrf'] !== $this->getData(['user',$this->getUser('id'),'accessCsrf']) )
2018-04-02 08:29:19 +02:00
) {
$user = new user;
$user->logout();
}
// Mode maintenance
if(
$this->getData(['config', 'maintenance'])
AND in_array($this->getUrl(0), ['maintenance', 'user']) === false
AND $this->getUrl(1) !== 'login'
AND (
$this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
OR (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUser('group') < self::GROUP_ADMIN
)
)
) {
// Déconnexion
$user = new user;
$user->logout();
2020-09-12 09:52:30 +02:00
// Redirection
2018-04-02 08:29:19 +02:00
http_response_code(302);
header('Location:' . helper::baseUrl() . 'maintenance');
exit();
}
// Check l'accès à la page
$access = null;
2020-05-24 20:21:00 +02:00
$accessInfo['userName'] = '';
$accessInfo['pageId'] = '';
2018-04-02 08:29:19 +02:00
if($this->getData(['page', $this->getUrl(0)]) !== null) {
if(
$this->getData(['page', $this->getUrl(0), 'group']) === self::GROUP_VISITOR
OR (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUser('group') >= $this->getData(['page', $this->getUrl(0), 'group'])
)
) {
$access = true;
}
else {
if($this->getUrl(0) === $this->getData(['config', 'homePageId'])) {
$access = 'login';
}
else {
$access = false;
}
}
}
/**
2020-06-03 09:07:00 +02:00
* Contrôle si la page demandée est en édition ou accès à la gestion du site
* conditions de blocage :
* - Les deux utilisateurs qui accèdent à la même page sont différents
* - les URLS sont identiques
* - Une partie de l'URL fait partie de la liste de filtrage (édition d'un module etc..)
* - L'édition est ouverte depuis un temps dépassé, on considère que la page est restée ouverte et qu'elle ne sera pas validée
*/
2020-05-24 19:59:21 +02:00
foreach($this->getData(['user']) as $userId => $userIds){
$t = explode('/',$this->getData(['user', $userId, 'accessUrl']));
2020-10-12 16:47:35 +02:00
if ( $this->getUser('id') &&
$userId !== $this->getUser('id') &&
2020-09-18 03:57:02 +02:00
$this->getData(['user', $userId,'accessUrl']) === $this->getUrl() &&
array_intersect($t,self::$accessList) &&
array_intersect($t,self::$accessExclude) !== false &&
time() < $this->getData(['user', $userId,'accessTimer']) + self::ACCESS_TIMER
) {
2020-05-24 19:59:21 +02:00
$access = false;
2020-05-24 20:21:00 +02:00
$accessInfo['userName'] = $this->getData(['user', $userId, 'lastname']) . ' ' . $this->getData(['user', $userId, 'firstname']);
$accessInfo['pageId'] = end($t);
2020-05-24 19:59:21 +02:00
}
}
// Accès concurrent stocke la page visitée
if ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')) {
2020-10-12 16:47:35 +02:00
$this->setData(['user',$this->getUser('id'),'accessUrl',$this->getUrl()]);
$this->setData(['user',$this->getUser('id'),'accessTimer',time()]);
2020-05-24 19:59:21 +02:00
}
// Breadcrumb
$title = $this->getData(['page', $this->getUrl(0), 'title']);
if (!empty($this->getData(['page', $this->getUrl(0), 'parentPageId'])) &&
$this->getData(['page', $this->getUrl(0), 'breadCrumb'])) {
2020-05-24 19:59:21 +02:00
$title = '<a href="' . helper::baseUrl() .
$this->getData(['page', $this->getUrl(0), 'parentPageId']) .
'">' .
ucfirst($this->getData(['page',$this->getData(['page', $this->getUrl(0), 'parentPageId']), 'title'])) .
'</a> &#8250; '.
2020-05-24 19:59:21 +02:00
$this->getData(['page', $this->getUrl(0), 'title']);
}
2018-04-02 08:29:19 +02:00
// Importe la page
if(
$this->getData(['page', $this->getUrl(0)]) !== null
AND $this->getData(['page', $this->getUrl(0), 'moduleId']) === ''
AND $access
) {
$this->addOutput([
2019-02-06 16:54:10 +01:00
'title' => $title,
2018-04-02 08:29:19 +02:00
'content' => $this->getData(['page', $this->getUrl(0), 'content']),
'metaDescription' => $this->getData(['page', $this->getUrl(0), 'metaDescription']),
'metaTitle' => $this->getData(['page', $this->getUrl(0), 'metaTitle']),
'typeMenu' => $this->getData(['page', $this->getUrl(0), 'typeMenu']),
'iconUrl' => $this->getData(['page', $this->getUrl(0), 'iconUrl']),
2019-05-02 13:21:48 +02:00
'disable' => $this->getData(['page', $this->getUrl(0), 'disable']),
'contentRight' => $this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'content']),
'contentLeft' => $this->getData(['page',$this->getData(['page',$this->getUrl(0),'barLeft']),'content']),
2018-04-02 08:29:19 +02:00
]);
}
// Importe le module
else {
2020-05-24 19:59:21 +02:00
// Id du module, et valeurs en sortie de la page si il s'agit d'un module de page
2019-05-02 13:21:48 +02:00
2018-04-02 08:29:19 +02:00
if($access AND $this->getData(['page', $this->getUrl(0), 'moduleId'])) {
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
$this->addOutput([
2019-02-06 16:54:10 +01:00
'title' => $title,
// Meta description = 160 premiers caractères de l'article
2020-05-24 19:59:21 +02:00
'metaDescription' => $this->getData(['page',$this->getUrl(0),'moduleId']) === 'blog' && !empty($this->getUrl(1))
? strip_tags(substr($this->getData(['module',$this->getUrl(0),$this->getUrl(1),'content']) ,0,159))
: $this->getData(['page', $this->getUrl(0), 'metaDescription']),
2018-04-02 08:29:19 +02:00
'metaTitle' => $this->getData(['page', $this->getUrl(0), 'metaTitle']),
'typeMenu' => $this->getData(['page', $this->getUrl(0), 'typeMenu']),
'iconUrl' => $this->getData(['page', $this->getUrl(0), 'iconUrl']),
2019-05-02 13:21:48 +02:00
'disable' => $this->getData(['page', $this->getUrl(0), 'disable']),
'contentRight' => $this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'content']),
'contentLeft' => $this->getData(['page',$this->getData(['page',$this->getUrl(0),'barLeft']),'content'])
2018-04-02 08:29:19 +02:00
]);
$pageContent = $this->getData(['page', $this->getUrl(0), 'content']);
}
else {
$moduleId = $this->getUrl(0);
$pageContent = '';
}
// Check l'existence du module
if(class_exists($moduleId)) {
/** @var common $module */
$module = new $moduleId;
// Check l'existence de l'action
$action = '';
$ignore = true;
foreach(explode('-', $this->getUrl(1)) as $actionPart) {
if($ignore) {
$action .= $actionPart;
$ignore = false;
}
else {
$action .= ucfirst($actionPart);
}
}
$action = array_key_exists($action, $module::$actions) ? $action : 'index';
if(array_key_exists($action, $module::$actions)) {
$module->$action();
$output = $module->output;
// Check le groupe de l'utilisateur
2018-04-02 08:29:19 +02:00
if(
(
$module::$actions[$action] === self::GROUP_VISITOR
OR (
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
AND $this->getUser('group') >= $module::$actions[$action]
)
)
AND $output['access'] === true
) {
// Enregistrement du contenu de la méthode POST lorsqu'une notice est présente
if(common::$inputNotices) {
2018-04-02 08:29:19 +02:00
foreach($_POST as $postId => $postValue) {
if(is_array($postValue)) {
foreach($postValue as $subPostId => $subPostValue) {
self::$inputBefore[$postId . '_' . $subPostId] = $subPostValue;
}
}
else {
self::$inputBefore[$postId] = $postValue;
}
}
}
// Sinon traitement des données de sortie qui requiert qu'aucune notice ne soit présente
else {
// Notification
if($output['notification']) {
if($output['state'] === true) {
$notification = 'ZWII_NOTIFICATION_SUCCESS';
}
elseif($output['state'] === false) {
$notification = 'ZWII_NOTIFICATION_ERROR';
}
else {
$notification = 'ZWII_NOTIFICATION_OTHER';
}
$_SESSION[$notification] = $output['notification'];
}
// Redirection
if($output['redirect']) {
http_response_code(301);
header('Location:' . $output['redirect']);
2020-05-24 19:59:21 +02:00
exit();
2018-04-02 08:29:19 +02:00
}
2020-05-24 19:59:21 +02:00
}
2018-04-02 08:29:19 +02:00
// Données en sortie applicables même lorsqu'une notice est présente
// Affichage
2020-05-24 19:59:21 +02:00
if($output['display']) {
2018-04-02 08:29:19 +02:00
$this->addOutput([
'display' => $output['display']
2020-05-24 19:59:21 +02:00
]);
2018-04-02 08:29:19 +02:00
}
// Contenu brut
if($output['content']) {
$this->addOutput([
'content' => $output['content']
]);
}
// Contenu par vue
elseif($output['view']) {
// Chemin en fonction d'un module du coeur ou d'un module
$modulePath = in_array($moduleId, self::$coreModuleIds) ? 'core/' : '';
// CSS
$stylePath = $modulePath . 'module/' . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.css';
if(file_exists($stylePath)) {
$this->addOutput([
'style' => file_get_contents($stylePath)
]);
}
// JS
$scriptPath = $modulePath . 'module/' . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.js.php';
if(file_exists($scriptPath)) {
ob_start();
include $scriptPath;
$this->addOutput([
'script' => ob_get_clean()
]);
}
// Vue
$viewPath = $modulePath . 'module/' . $moduleId . '/view/' . $output['view'] . '/' . $output['view'] . '.php';
if(file_exists($viewPath)) {
ob_start();
include $viewPath;
2018-10-23 10:21:57 +02:00
$modpos = $this->getData(['page', $this->getUrl(0), 'modulePosition']);
if ($modpos === 'top') {
2018-10-23 10:21:57 +02:00
$this->addOutput([
'content' => ob_get_clean() . ($output['showPageContent'] ? $pageContent : '')]);
}
else if ($modpos === 'free') {
if ( strstr($pageContent, '[MODULE]', true) === false) {
$begin = strstr($pageContent, '[]', true); } else {
$begin = strstr($pageContent, '[MODULE]', true);
}
if ( strstr($pageContent, '[MODULE]') === false ) {
$end = strstr($pageContent, '[]');} else {
$end = strstr($pageContent, '[MODULE]');
}
$cut=8;
2018-10-23 10:21:57 +02:00
$end=substr($end,-strlen($end)+$cut);
$this->addOutput([
'content' => ($output['showPageContent'] ? $begin : '') . ob_get_clean() . ($output['showPageContent'] ? $end : '')]); }
else {
2018-10-23 10:21:57 +02:00
$this->addOutput([
'content' => ($output['showPageContent'] ? $pageContent : '') . ob_get_clean()]);
}
2018-04-02 08:29:19 +02:00
}
}
2018-04-02 08:29:19 +02:00
// Librairies
if($output['vendor'] !== $this->output['vendor']) {
$this->addOutput([
'vendor' => array_merge($this->output['vendor'], $output['vendor'])
]);
}
2020-05-24 19:59:21 +02:00
if($output['title'] !== null) {
2018-04-02 08:29:19 +02:00
$this->addOutput([
'title' => $output['title']
]);
}
// Affiche le bouton d'édition de la page dans la barre de membre
if($output['showBarEditButton']) {
$this->addOutput([
'showBarEditButton' => $output['showBarEditButton']
]);
}
}
// Erreur 403
else {
$access = false;
}
}
}
}
// Erreurs
if($access === 'login') {
http_response_code(302);
header('Location:' . helper::baseUrl() . 'user/login/');
exit();
}
if($access === false) {
http_response_code(403);
2020-05-24 20:21:00 +02:00
if ($accessInfo['userName']) {
2020-05-24 19:59:21 +02:00
$this->addOutput([
'title' => 'Accès verrouillé',
'content' => template::speech('La page <strong>' . $accessInfo['pageId'] . '</strong> est ouverte par l\'utilisateur <strong>' . $accessInfo['userName'] . '</strong>')
2020-05-24 19:59:21 +02:00
]);
} else {
2020-09-08 22:26:33 +02:00
if ( $this->getData(['config','page403']) !== 'none'
AND $this->getData(['page',$this->getData(['config','page403'])]))
2020-09-08 22:26:33 +02:00
{
header('Location:' . helper::baseUrl() . $this->getData(['config','page403']));
} else {
2020-08-13 14:11:33 +02:00
$this->addOutput([
'title' => 'Erreur 403',
'content' => template::speech('Vous n\'êtes pas autorisé à accéder à cette page...')
]);
}
2020-05-24 19:59:21 +02:00
}
2020-09-08 22:26:33 +02:00
} elseif ($this->output['content'] === '') {
2018-04-02 08:29:19 +02:00
http_response_code(404);
if ( $this->getData(['config','page404']) !== 'none'
AND $this->getData(['page',$this->getData(['config','page404'])]))
2020-09-08 22:26:33 +02:00
{
header('Location:' . helper::baseUrl() . $this->getData(['config','page404']));
2020-05-24 19:59:21 +02:00
} else {
$this->addOutput([
2020-09-08 22:26:33 +02:00
'title' => 'Erreur 404',
'content' => template::speech('Oups ! La page demandée est introuvable...')
2020-05-24 19:59:21 +02:00
]);
}
2018-04-02 08:29:19 +02:00
}
// Mise en forme des métas
if($this->output['metaTitle'] === '') {
if($this->output['title']) {
$this->addOutput([
2019-02-06 17:05:28 +01:00
'metaTitle' => strip_tags($this->output['title']) . ' - ' . $this->getData(['config', 'title'])
2018-04-02 08:29:19 +02:00
]);
}
else {
$this->addOutput([
'metaTitle' => $this->getData(['config', 'title'])
]);
}
}
if($this->output['metaDescription'] === '') {
$this->addOutput([
'metaDescription' => $this->getData(['config', 'metaDescription'])
]);
}
2020-05-24 19:59:21 +02:00
switch($this->output['display']) {
// Layout vide
case self::DISPLAY_LAYOUT_BLANK:
require 'core/layout/blank.php';
break;
// Affichage en JSON
case self::DISPLAY_JSON:
header('Content-Type: application/json');
echo json_encode($this->output['content']);
break;
// Layout alléger
case self::DISPLAY_LAYOUT_LIGHT:
require 'core/layout/light.php';
break;
// Layout principal
case self::DISPLAY_LAYOUT_MAIN:
require 'core/layout/main.php';
2020-05-24 19:59:21 +02:00
break;
// Layout brut
case self::DISPLAY_RAW:
echo $this->output['content'];
2020-05-24 19:59:21 +02:00
break;
}
2018-04-02 08:29:19 +02:00
}
}
class layout extends common {
private $core;
/**
* Constructeur du layout
*/
public function __construct(core $core) {
parent::__construct();
$this->core = $core;
}
/**
* Affiche le script Google Analytics
*/
public function showAnalytics() {
if($code = $this->getData(['config', 'analyticsId'])) {
2019-05-02 13:21:48 +02:00
echo '<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id='. $code .'"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config","'. $code .'");
</script>';
2018-04-02 08:29:19 +02:00
}
}
/**
* Affiche le contenu
2020-05-24 19:59:21 +02:00
* @param Page par défaut
2018-04-02 08:29:19 +02:00
*/
public function showContent() {
2019-01-27 18:28:29 +01:00
if(
$this->core->output['title']
AND (
$this->getData(['page', $this->getUrl(0)]) === null
OR $this->getData(['page', $this->getUrl(0), 'hideTitle']) === false
OR $this->getUrl(1) === 'config'
2019-01-27 18:28:29 +01:00
)
) {
2020-04-29 02:57:57 +02:00
echo '<h1 id="sectionTitle">' . $this->core->output['title'] . '</h1>';
2018-04-02 08:29:19 +02:00
}
2019-01-27 18:28:29 +01:00
echo $this->core->output['content'];
2018-04-02 08:29:19 +02:00
}
2019-05-02 13:21:48 +02:00
/**
* Affiche le contenu de la barre gauche
2020-05-24 19:59:21 +02:00
*
2019-05-02 13:21:48 +02:00
*/
public function showBarContentLeft() {
// Détermine si le menu est présent
if ($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barLeft']),'displayMenu']) === 'none') {
// Pas de menu
echo $this->core->output['contentLeft'];
} else {
// $mark contient 0 le menu est positionné à la fin du contenu
$contentLeft = str_replace ('[]','[MENU]',$this->core->output['contentLeft']);
$contentLeft = str_replace ('[menu]','[MENU]',$contentLeft);
2020-05-24 19:59:21 +02:00
$mark = strrpos($contentLeft,'[MENU]') !== false ? strrpos($contentLeft,'[MENU]') : strlen($contentLeft);
echo substr($contentLeft,0,$mark);
2019-05-30 19:53:18 +02:00
echo '<div id="menuSideLeft">';
echo $this->showMenuSide($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barLeft']),'displayMenu']) === 'parents' ? false : true);
echo '</div>';
2020-05-24 19:59:21 +02:00
echo substr($contentLeft,$mark+6,strlen($contentLeft));
}
2019-05-02 13:21:48 +02:00
}
/**
* Affiche le contenu de la barre droite
*/
public function showBarContentRight() {
// Détermine si le menu est présent
if ($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'displayMenu']) === 'none') {
// Pas de menu
echo $this->core->output['contentRight'];
} else {
// $mark contient 0 le menu est positionné à la fin du contenu
$contentRight = str_replace ('[]','[MENU]',$this->core->output['contentRight']);
$contentRight = str_replace ('[menu]','[MENU]',$contentRight);
2020-05-24 19:59:21 +02:00
$mark = strrpos($contentRight,'[MENU]') !== false ? strrpos($contentRight,'[MENU]') : strlen($contentRight);
echo substr($contentRight,0,$mark);
2019-05-30 19:53:18 +02:00
echo '<div id="menuSideRight">';
echo $this->showMenuSide($this->getData(['page',$this->getData(['page',$this->getUrl(0),'barRight']),'displayMenu']) === 'parents' ? false : true);
echo '</div>';
2020-05-24 19:59:21 +02:00
echo substr($contentRight,$mark+6,strlen($contentRight));
}
2019-05-02 13:21:48 +02:00
}
2019-06-18 23:29:42 +02:00
/**
* Affiche le texte du footer
*/
public function showFooterText() {
if($footerText = $this->getData(['theme', 'footer', 'text']) OR $this->getUrl(0) === 'theme') {
echo '<div id="footerText">' . $footerText . '</div>';
2019-06-18 23:29:42 +02:00
}
}
2019-05-02 13:21:48 +02:00
/**
2019-01-11 18:54:14 +01:00
* Affiche le copyright
*/
public function showCopyright() {
2019-05-11 22:23:55 +02:00
// Ouverture Bloc copyright
2019-05-02 13:21:48 +02:00
$items = '<div id="footerCopyright">';
2019-05-30 19:53:18 +02:00
$items .= '<span id="footerFontCopyright">';
2020-05-24 19:59:21 +02:00
// Affichage de motorisé par
$items .= '<span id="footerDisplayCopyright" ';
$items .= $this->getData(['theme','footer','displayCopyright']) === false ? 'class="displayNone"' : '';
2019-05-30 19:53:18 +02:00
$items .= '>Motorisé&nbsp;par&nbsp;</span>';
2019-05-11 22:23:55 +02:00
// Toujours afficher le nom du CMS
$items .= '<span id="footerZwiiCMS">';
$items .= '<a href="https://zwiicms.fr/" onclick="window.open(this.href);return false" data-tippy-content="Zwii CMS sans base de données, très léger et performant">ZwiiCMS</a>';
$items .= '</span>';
// Affichage du numéro de version
$items .= '<span id="footerDisplayVersion"';
2019-06-22 23:43:31 +02:00
$items .= $this->getData(['theme','footer','displayVersion']) === false ? ' class="displayNone"' : '';
2020-05-24 19:59:21 +02:00
$items .= '><wbr>&nbsp;'. common::ZWII_VERSION ;
$items .= '</span>';
// Affichage du sitemap
$items .= '<span id="footerDisplaySiteMap"';
2019-07-10 09:19:12 +02:00
$items .= $this->getData(['theme','footer','displaySiteMap']) === false ? ' class="displayNone"' : '';
$items .= '><wbr>&nbsp;|&nbsp;<a href="' . helper::baseUrl() . 'sitemap" data-tippy-content="Plan du site" >Plan&nbsp;du&nbsp;site</a>';
2019-05-02 13:21:48 +02:00
$items .= '</span>';
// Affichage du module de recherche
$items .= '<span id="footerDisplaySearch"';
2020-09-26 10:02:03 +02:00
$items .= $this->getData(['theme','footer','displaySearch']) === false ? ' class="displayNone" >' : '>';
if ($this->getData(['config','searchPageId']) !== 'none') {
$items .= '<wbr>&nbsp;|&nbsp;<a href="' . helper::baseUrl() . $this->getData(['config','searchPageId']) . '" data-tippy-content="Rechercher dans le site" >Recherche</a>';
}
$items .= '</span>';
// Affichage des mentions légales
$items .= '<span id="footerDisplayLegal"';
$items .= $this->getData(['theme','footer','displayLegal']) === false ? ' class="displayNone" >' : '>';
if ($this->getData(['config','legalPageId']) !== 'none') {
$items .= '<wbr>&nbsp;|&nbsp;<a href="' . helper::baseUrl() . $this->getData(['config','legalPageId']) . '" data-tippy-content="Mentions Légales">Mentions légales</a>';
}
2020-05-24 19:59:21 +02:00
$items .= '</span>';
// Affichage du lien de connexion
if(
2019-01-11 18:54:14 +01:00
(
$this->getData(['theme', 'footer', 'loginLink'])
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
)
OR $this->getUrl(0) === 'theme'
) {
2020-05-24 19:59:21 +02:00
$items .= '<span id="footerLoginLink" ' .
($this->getUrl(0) === 'theme' ? 'class="displayNone"' : '') .
'><wbr>&nbsp;|&nbsp;<a href="' . helper::baseUrl() . 'user/login/' .
strip_tags(str_replace('/', '_', $this->getUrl())) .
2019-05-30 19:53:18 +02:00
'" data-tippy-content="Connexion à l\'administration" rel="nofollow">Connexion</a></span>';
}
// Affichage de la barre de membre simple
if ( $this->getUser('group') === self::GROUP_MEMBER
&& $this->getData(['theme','footer','displayMemberBar']) === true
) {
$items .= '<span id="footerDisplayMemberAccount"';
$items .= $this->getData(['theme','footer','displaymemberAccount']) === false ? ' class="displayNone"' : '';
$items .= '><wbr>&nbsp;|<a href="' . helper::baseUrl() . 'user/edit/' . $this->getUser('id'). '/' . $_SESSION['csrf'] . '" data-tippy-content="Gérer mon compte" >' . template::ico('user', 'all') . '</a>';
$items .= '<wbr><a id="barLogout" href="' . helper::baseUrl() . 'user/logout" data-tippy-content="Me déconnecter">' . template::ico('logout','left') . '</a>';
$items .= '</span>';
}
// Fermeture du bloc copyright
2019-05-02 13:21:48 +02:00
$items .= '</span></div>';
2019-01-11 18:54:14 +01:00
echo $items;
2019-06-18 23:29:42 +02:00
}
2020-05-24 19:59:21 +02:00
2019-06-18 23:29:42 +02:00
/**
* Affiche les réseaux sociaux
*/
public function showSocials() {
$socials = '';
foreach($this->getData(['config', 'social']) as $socialName => $socialId) {
switch($socialName) {
case 'facebookId':
$socialUrl = 'https://www.facebook.com/';
$title = 'Facebook';
break;
case 'linkedinId':
$socialUrl = 'https://fr.linkedin.com/in/';
$title = 'Linkedin';
break;
case 'instagramId':
$socialUrl = 'https://www.instagram.com/';
$title = 'Instagram';
break;
case 'pinterestId':
$socialUrl = 'https://pinterest.com/';
$title = 'Pinterest';
break;
case 'twitterId':
$socialUrl = 'https://twitter.com/';
$title = 'Twitter';
break;
case 'youtubeId':
$socialUrl = 'https://www.youtube.com/channel/';
2020-01-31 12:19:13 +01:00
$title = 'Chaîne YouTube';
2019-06-18 23:29:42 +02:00
break;
2020-02-01 20:49:35 +01:00
case 'youtubeUserId':
2020-01-31 12:19:13 +01:00
$socialUrl = 'https://www.youtube.com/user/';
$title = 'YouTube';
2020-05-24 19:59:21 +02:00
break;
2019-06-18 23:29:42 +02:00
case 'githubId':
$socialUrl = 'https://www.github.com/';
$title = 'Github';
break;
default:
$socialUrl = '';
}
if($socialId !== '') {
2020-02-01 20:49:35 +01:00
$socials .= '<a href="' . $socialUrl . $socialId . '" onclick="window.open(this.href);return false" data-tippy-content="' . $title . '">' . template::ico(substr(str_replace('User','',$socialName), 0, -2)) . '</a>';
2019-06-18 23:29:42 +02:00
}
}
if($socials !== '') {
echo '<div id="footerSocials">' . $socials . '</div>';
}
}
2018-04-02 08:29:19 +02:00
/**
* Affiche le favicon
*/
public function showFavicon() {
2020-01-02 19:30:23 +01:00
// Light scheme
2020-05-24 19:59:21 +02:00
$favicon = $this->getData(['config', 'favicon']);
if($favicon &&
2019-05-28 09:04:10 +02:00
file_exists(self::FILE_DIR.'source/' . $favicon)
) {
2020-01-02 19:30:23 +01:00
echo '<link rel="shortcut icon" media="(prefers-color-scheme:light)" href="' . helper::baseUrl(false) . self::FILE_DIR.'source/' . $favicon . '">';
} else {
2020-01-02 19:30:23 +01:00
echo '<link rel="shortcut icon" media="(prefers-color-scheme:light)" href="' . helper::baseUrl(false) . 'core/vendor/zwiico/ico/favicon.ico">';
2018-04-02 08:29:19 +02:00
}
2020-01-02 19:30:23 +01:00
// Dark scheme
2020-05-24 19:59:21 +02:00
$faviconDark = $this->getData(['config', 'faviconDark']);
2020-03-01 18:11:04 +01:00
if(!empty($faviconDark) &&
2020-01-02 19:30:23 +01:00
file_exists(self::FILE_DIR.'source/' . $faviconDark)
) {
echo '<link rel="shortcut icon" media="(prefers-color-scheme:dark)" href="' . helper::baseUrl(false) . self::FILE_DIR.'source/' . $faviconDark . '">';
2020-09-19 17:35:02 +02:00
//echo '<script src="https://unpkg.com/favicon-switcher@1.2.2/dist/index.js" crossorigin="anonymous" type="application/javascript"></script>';
echo '<script src="' . helper::baseUrl(false) . 'core/vendor/favicon-switcher/favicon-switcher.js" crossorigin="anonymous" type="application/javascript"></script>';
2020-05-24 19:59:21 +02:00
}
2018-04-02 08:29:19 +02:00
}
/**
* Affiche le menu
*/
public function showMenu() {
// Met en forme les items du menu
$items = '';
$currentPageId = $this->getData(['page', $this->getUrl(0)]) ? $this->getUrl(0) : $this->getUrl(2);
foreach($this->getHierarchy() as $parentPageId => $childrenPageIds) {
2020-05-24 19:59:21 +02:00
// Passer les entrées masquées
2018-04-02 08:29:19 +02:00
// Propriétés de l'item
2020-08-09 19:16:39 +02:00
$active = ($parentPageId === $currentPageId OR in_array($currentPageId, $childrenPageIds)) ? 'active ' : '';
2019-12-02 13:20:19 +01:00
$targetBlank = $this->getData(['page', $parentPageId, 'targetBlank']) ? ' target="_blank"' : '';
2018-04-02 08:29:19 +02:00
// Mise en page de l'item
$items .= '<li>';
2020-05-24 19:59:21 +02:00
if ( $this->getData(['page',$parentPageId,'disable']) === true
2018-04-02 08:54:57 +02:00
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') )
2020-07-08 08:24:50 +02:00
{$items .= '<a class="' . $parentPageId . '" href="'.$this->getUrl(1).'">';
} else {
2020-08-09 19:16:39 +02:00
$items .= '<a class="' . $active . $parentPageId . '" href="' . helper::baseUrl() . $parentPageId . '"' . $targetBlank . '>';
}
2018-04-02 08:29:19 +02:00
switch ($this->getData(['page', $parentPageId, 'typeMenu'])) {
case '' :
$items .= $this->getData(['page', $parentPageId, 'title']);
break;
case 'text' :
$items .= $this->getData(['page', $parentPageId, 'title']);
2018-09-24 18:25:46 +02:00
break;
2018-04-02 08:29:19 +02:00
case 'icon' :
if ($this->getData(['page', $parentPageId, 'iconUrl']) != "") {
2019-05-28 09:04:10 +02:00
$items .= '<img alt="'.$this->getData(['page', $parentPageId, 'title']).'" src="'. helper::baseUrl(false) .self::FILE_DIR.'source/'.$this->getData(['page', $parentPageId, 'iconUrl']).'" />';
2018-04-02 08:29:19 +02:00
} else {
$items .= $this->getData(['page', $parentPageId, 'title']);
}
break;
case 'icontitle' :
if ($this->getData(['page', $parentPageId, 'iconUrl']) != "") {
2019-05-28 09:04:10 +02:00
$items .= '<img alt="'.$this->getData(['page', $parentPageId, 'title']).'" src="'. helper::baseUrl(false) .self::FILE_DIR.'source/'.$this->getData(['page', $parentPageId, 'iconUrl']).'" data-tippy-content="';
$items .= $this->getData(['page', $parentPageId, 'title']).'"/>';
2018-04-02 08:29:19 +02:00
} else {
$items .= $this->getData(['page', $parentPageId, 'title']);
2018-09-24 18:25:46 +02:00
}
2018-04-02 08:29:19 +02:00
break;
}
2019-05-02 13:21:48 +02:00
// Cas où les pages enfants enfant sont toutes masquées dans le menu
// ne pas afficher de symbole lorsqu'il n'y a rien à afficher
$totalChild = 0;
$disableChild = 0;
foreach($childrenPageIds as $childKey) {
$totalChild += 1;
2020-05-24 19:59:21 +02:00
}
2019-05-02 13:21:48 +02:00
if($childrenPageIds && $disableChild !== $totalChild &&
$this->getdata(['page',$parentPageId,'hideMenuChildren']) === false) {
2018-04-02 08:29:19 +02:00
$items .= template::ico('down', 'left');
}
2020-05-24 19:59:21 +02:00
// ------------------------------------------------
2018-04-03 13:09:12 +02:00
$items .= '</a>';
2019-05-30 19:53:18 +02:00
if ($this->getdata(['page',$parentPageId,'hideMenuChildren']) === true ||
empty($childrenPageIds)) {
2019-05-02 13:21:48 +02:00
continue;
}
2019-07-31 17:47:26 +02:00
$items .= '<ul class="navLevel2">';
2020-05-24 19:59:21 +02:00
foreach($childrenPageIds as $childKey) {
2018-04-02 08:29:19 +02:00
// Propriétés de l'item
2020-08-09 19:16:39 +02:00
$active = ($childKey === $currentPageId) ? 'active ' : '';
2020-05-24 19:59:21 +02:00
$targetBlank = $this->getData(['page', $childKey, 'targetBlank']) ? ' target="_blank"' : '';
2018-04-02 08:29:19 +02:00
// Mise en page du sous-item
2019-05-31 23:25:31 +02:00
$items .= '<li>';
if ( $this->getData(['page',$childKey,'disable']) === true
2019-05-31 23:25:31 +02:00
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') ) {
2020-07-08 08:24:50 +02:00
$items .= '<a class="' . $parentPageId . '" href="'.$this->getUrl(1).'">';
2019-05-31 23:25:31 +02:00
} else {
2020-08-09 19:16:39 +02:00
$items .= '<a class="' . $active . $parentPageId . '" href="' . helper::baseUrl() . $childKey . '"' . $targetBlank . '>';
2019-05-31 23:25:31 +02:00
}
2018-04-02 08:29:19 +02:00
switch ($this->getData(['page', $childKey, 'typeMenu'])) {
case '' :
$items .= $this->getData(['page', $childKey, 'title']);
break;
case 'text' :
$items .= $this->getData(['page', $childKey, 'title']);
2018-09-24 18:25:46 +02:00
break;
2018-04-02 08:29:19 +02:00
case 'icon' :
if ($this->getData(['page', $childKey, 'iconUrl']) != "") {
2019-05-28 09:04:10 +02:00
$items .= '<img alt="'.$this->getData(['page', $parentPageId, 'title']).'" src="'. helper::baseUrl(false) .self::FILE_DIR.'source/'.$this->getData(['page', $childKey, 'iconUrl']).'" />';
2018-04-02 08:29:19 +02:00
} else {
$items .= $this->getData(['page', $parentPageId, 'title']);
}
break;
case 'icontitle' :
if ($this->getData(['page', $childKey, 'iconUrl']) != "") {
2019-05-28 09:04:10 +02:00
$items .= '<img alt="'.$this->getData(['page', $parentPageId, 'title']).'" src="'. helper::baseUrl(false) .self::FILE_DIR.'source/'.$this->getData(['page', $childKey, 'iconUrl']).'" data-tippy-content="';
2018-04-02 08:29:19 +02:00
$items .= $this->getData(['page', $childKey, 'title']).'"/>';
} else {
$items .= $this->getData(['page', $childKey, 'title']);
2018-09-24 18:25:46 +02:00
}
2018-04-02 08:29:19 +02:00
break;
case 'icontext' :
if ($this->getData(['page', $childKey, 'iconUrl']) != "") {
2019-05-28 09:04:10 +02:00
$items .= '<img alt="'.$this->getData(['page', $parentPageId, 'title']).'" src="'. helper::baseUrl(false) .self::FILE_DIR.'source/'.$this->getData(['page', $childKey, 'iconUrl']).'" />';
2018-04-02 08:29:19 +02:00
$items .= $this->getData(['page', $childKey, 'title']);
} else {
$items .= $this->getData(['page', $childKey, 'title']);
}
2018-09-24 18:25:46 +02:00
break;
2018-04-02 08:29:19 +02:00
}
2019-05-31 23:25:31 +02:00
$items .= '</a></li>';
}
2018-04-02 08:29:19 +02:00
$items .= '</ul>';
}
// Lien de connexion
if(
(
$this->getData(['theme', 'menu', 'loginLink'])
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
)
OR $this->getUrl(0) === 'theme'
) {
2020-05-24 19:59:21 +02:00
$items .= '<li id="menuLoginLink" ' .
($this->getUrl(0) === 'theme' ? 'class="displayNone"' : '') .
'><a href="' . helper::baseUrl() . 'user/login/' .
strip_tags(str_replace('/', '_', $this->getUrl())) .
2019-03-22 09:03:08 +01:00
'">Connexion</a></li>';
2018-04-02 08:29:19 +02:00
}
// Commandes pour les membres simples
if($this->getUser('group') == self::GROUP_MEMBER
&& ( $this->getData(['theme','menu','memberBar']) === true
|| $this->getData(['theme','footer','displayMemberBar']) === false
)
) {
$items .= '<li><a href="' . helper::baseUrl() . 'user/edit/' . $this->getUser('id'). '/' . $_SESSION['csrf'] . '" data-tippy-content="Gérer mon compte">' . template::ico('user', 'right') . '</a></li>';
$items .= '<li><a id="barLogout" href="' . helper::baseUrl() . 'user/logout" data-tippy-content="Me déconnecter">' . template::ico('logout') . '</a></li>';
}
2018-04-02 08:29:19 +02:00
// Retourne les items du menu
2019-07-31 17:47:26 +02:00
echo '<ul class="navLevel1">' . $items . '</ul>';
2018-04-02 08:29:19 +02:00
}
2019-05-02 13:21:48 +02:00
/**
* Générer un menu pour la barre latérale
2020-05-24 19:59:21 +02:00
* Uniquement texte
2019-05-02 13:21:48 +02:00
* @param onlyChildren n'affiche les sous-pages de la page actuelle
*/
public function showMenuSide($onlyChildren = null) {
// Met en forme les items du menu
$items = '';
// Nom de la page courante
$currentPageId = $this->getData(['page', $this->getUrl(0)]) ? $this->getUrl(0) : $this->getUrl(2);
// Nom de la page parente
$currentParentPageId = $this->getData(['page',$currentPageId,'parentPageId']);
// Détermine si on affiche uniquement le parent et les enfants
// Filtre contient le nom de la page parente
if ($onlyChildren === true) {
2020-05-24 19:59:21 +02:00
if (empty($currentParentPageId)) {
2019-05-02 13:21:48 +02:00
$filterCurrentPageId = $currentPageId;
} else {
2020-05-24 19:59:21 +02:00
$filterCurrentPageId = $currentParentPageId;
2019-05-02 13:21:48 +02:00
}
2019-05-31 23:25:31 +02:00
} else {
$items .= '<ul class="menuSide">';
}
2019-05-02 13:21:48 +02:00
foreach($this->getHierarchy() as $parentPageId => $childrenPageIds) {
// Ne pas afficher les entrées masquées
2019-05-31 23:25:31 +02:00
if ($this->getData(['page',$parentPageId,'hideMenuSide']) === true ) {
2019-05-02 13:21:48 +02:00
continue;
}
// Filtre actif et nom de la page parente courante différente, on sort de la boucle
if ($onlyChildren === true && $parentPageId !== $filterCurrentPageId) {
continue;
}
// Propriétés de l'item
2020-08-09 19:16:39 +02:00
$active = ($parentPageId === $currentPageId OR in_array($currentPageId, $childrenPageIds)) ? 'active ' : '';
2019-05-02 13:21:48 +02:00
$targetBlank = $this->getData(['page', $parentPageId, 'targetBlank']) ? ' target="_blank"' : '';
// Mise en page de l'item;
// Ne pas afficher le parent d'une sous-page quand l'option est sélectionnée.
if ($onlyChildren === false) {
2019-05-31 23:25:31 +02:00
$items .= '<li class="menuSideChild">';
2019-05-02 13:21:48 +02:00
if ( $this->getData(['page',$parentPageId,'disable']) === true
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') ) {
$items .= '<a href="'.$this->getUrl(1).'">';
} else {
2020-08-09 19:16:39 +02:00
$items .= '<a href="' . $active . helper::baseUrl() . $parentPageId . '"' . $targetBlank . '>';
2019-05-02 13:21:48 +02:00
}
$items .= $this->getData(['page', $parentPageId, 'title']);
2019-06-01 13:07:38 +02:00
$items .= '</a>';
2019-05-02 13:21:48 +02:00
}
2019-05-31 23:25:31 +02:00
$itemsChildren = '';
2019-05-02 13:21:48 +02:00
foreach($childrenPageIds as $childKey) {
// Passer les entrées masquées
if ($this->getData(['page',$childKey,'hideMenuSide']) === true ) {
continue;
}
2020-05-24 19:59:21 +02:00
2019-05-02 13:21:48 +02:00
// Propriétés de l'item
2020-08-09 19:16:39 +02:00
$active = ($childKey === $currentPageId) ? 'active ' : '';
2020-05-24 19:59:21 +02:00
$targetBlank = $this->getData(['page', $childKey, 'targetBlank']) ? ' target="_blank"' : '';
2019-05-02 13:21:48 +02:00
// Mise en page du sous-item
2019-05-31 23:25:31 +02:00
$itemsChildren .= '<li class="menuSideChild">';
2019-05-02 13:21:48 +02:00
if ( $this->getData(['page',$childKey,'disable']) === true
2019-05-31 23:25:31 +02:00
AND $this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD') ) {
$itemsChildren .= '<a href="'.$this->getUrl(1).'">';
} else {
2020-08-09 19:16:39 +02:00
$itemsChildren .= '<a href="' .$active . helper::baseUrl() . $childKey . '"' . $targetBlank . '>';
2019-05-31 23:25:31 +02:00
}
2019-05-02 13:21:48 +02:00
2020-05-24 19:59:21 +02:00
$itemsChildren .= $this->getData(['page', $childKey, 'title']);
2019-05-31 23:25:31 +02:00
$itemsChildren .= '</a></li>';
2019-05-02 13:21:48 +02:00
}
// Concatène les items enfants
2019-05-31 23:25:31 +02:00
if (!empty($itemsChildren)) {
$items .= '<ul class="menuSideChild">';
$items .= $itemsChildren;
2019-05-30 19:53:18 +02:00
$items .= '</ul>';
2019-06-01 13:07:38 +02:00
} else {
$items .= '</li>';
2019-05-30 19:53:18 +02:00
}
2019-06-01 13:07:38 +02:00
2019-05-02 13:21:48 +02:00
}
2019-05-31 23:25:31 +02:00
if ($onlyChildren === false) {
$items .= '</ul>';
}
2019-05-02 13:21:48 +02:00
// Retourne les items du menu
2019-05-31 23:25:31 +02:00
echo $items;
2019-05-02 13:21:48 +02:00
}
2018-04-02 08:29:19 +02:00
/**
* Affiche le meta titre
*/
public function showMetaTitle() {
echo '<title>' . $this->core->output['metaTitle'] . '</title>';
echo '<meta property="og:title" content="' . $this->core->output['metaTitle'] . '" />';
2020-05-24 19:59:21 +02:00
echo '<link rel="canonical" href="'. helper::baseUrl(true).$this->getUrl() .'" />';
2018-04-02 08:29:19 +02:00
}
/**
* Affiche la meta description
*/
public function showMetaDescription() {
echo '<meta name="description" content="' . $this->core->output['metaDescription'] . '" />';
echo '<meta property="og:description" content="' . $this->core->output['metaDescription'] . '" />';
2018-04-02 08:29:19 +02:00
}
/**
2018-10-24 15:50:07 +02:00
* Affiche le meta type
*/
public function showMetaType() {
echo '<meta property="og:type" content="website" />';
}
2018-10-24 15:50:07 +02:00
/**
* Affiche la meta image (site screenshot)
*/
public function showMetaImage() {
2020-05-25 11:58:54 +02:00
echo '<meta property="og:image" content="' . helper::baseUrl() .self::FILE_DIR.'source/screenshot.jpg" />';
2018-10-24 15:50:07 +02:00
}
2018-04-02 08:29:19 +02:00
/**
* Affiche la notification
*/
public function showNotification() {
2019-12-11 20:38:27 +01:00
if (common::$importNotices) {
$notification = common::$importNotices [0];
$notificationClass = 'notificationSuccess';
}
if(common::$inputNotices) {
$notification = 'Impossible de soumettre le formulaire, car il contient des erreurs';
$notificationClass = 'notificationError';
}
if (common::$coreNotices) {
$notification = 'Données absentes, restauration de <p> | ';
foreach (common::$coreNotices as $item) $notification .= $item . ' | ';
$notificationClass = 'notificationError';
}
2018-04-02 08:29:19 +02:00
if(common::$inputNotices) {
$notification = 'Impossible de soumettre le formulaire, car il contient des erreurs';
$notificationClass = 'notificationError';
}
elseif(empty($_SESSION['ZWII_NOTIFICATION_SUCCESS']) === false) {
$notification = $_SESSION['ZWII_NOTIFICATION_SUCCESS'];
$notificationClass = 'notificationSuccess';
unset($_SESSION['ZWII_NOTIFICATION_SUCCESS']);
}
elseif(empty($_SESSION['ZWII_NOTIFICATION_ERROR']) === false) {
$notification = $_SESSION['ZWII_NOTIFICATION_ERROR'];
$notificationClass = 'notificationError';
unset($_SESSION['ZWII_NOTIFICATION_ERROR']);
}
elseif(empty($_SESSION['ZWII_NOTIFICATION_OTHER']) === false) {
$notification = $_SESSION['ZWII_NOTIFICATION_OTHER'];
$notificationClass = 'notificationOther';
unset($_SESSION['ZWII_NOTIFICATION_OTHER']);
}
if(isset($notification) AND isset($notificationClass)) {
2019-05-30 19:53:18 +02:00
echo '<div id="notification" class="' . $notificationClass . '">' . $notification . '<span id="notificationClose">' . template::ico('cancel') . '<!----></span><div id="notificationProgress"></div></div>';
2018-04-02 08:29:19 +02:00
}
}
/**
* Affiche la barre de membre
*/
public function showBar() {
if($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')) {
// Items de gauche
$leftItems = '';
2020-09-28 16:45:22 +02:00
if($this->getUser('group') >= self::GROUP_EDITOR) {
2018-04-02 08:29:19 +02:00
$leftItems .= '<li><select id="barSelectPage">';
$leftItems .= '<option value="">Choisissez une page</option>';
2019-03-16 16:25:54 +01:00
$leftItems .= '<optgroup label="Pages orphelines">';
$orpheline = true ;
2020-05-24 19:59:21 +02:00
$currentPageId = $this->getData(['page', $this->getUrl(0)]) ? $this->getUrl(0) : $this->getUrl(2);
2019-03-16 16:25:54 +01:00
foreach($this->getHierarchy(null,false) as $parentPageId => $childrenPageIds) {
if ($this->getData(['page', $parentPageId, 'position']) !== 0 &&
$orpheline ) {
$orpheline = false;
2019-03-16 22:31:27 +01:00
$leftItems .= '<optgroup label="Pages du menu">';
2020-05-24 19:59:21 +02:00
}
2019-03-16 16:25:54 +01:00
// Exclure les barres
if ($this->getData(['page', $parentPageId, 'block']) !== 'bar') {
2020-05-24 19:59:21 +02:00
$leftItems .= '<option value="' .
helper::baseUrl() .
$parentPageId . '"' .
($parentPageId === $currentPageId ? ' selected' : false) .
($this->getData(['page', $parentPageId, 'disable']) === true ? ' class="inactive"' : '') .
2020-05-24 19:59:21 +02:00
'>' .
$this->getData(['page', $parentPageId, 'title']) .
2019-03-16 16:25:54 +01:00
'</option>';
foreach($childrenPageIds as $childKey) {
2020-05-24 19:59:21 +02:00
$leftItems .= '<option value="' .
helper::baseUrl() .
$childKey . '"' .
($childKey === $currentPageId ? ' selected' : false) .
($this->getData(['page', $childKey, 'disable']) === true ? ' class="inactive"' : '') .
2020-05-24 19:59:21 +02:00
'>&nbsp;&nbsp;&nbsp;&nbsp;' .
$this->getData(['page', $childKey, 'title']) .
'</option>';
2019-03-16 16:25:54 +01:00
}
}
}
2019-05-31 23:25:31 +02:00
$leftItems .= '</optgroup'>
2019-03-16 16:25:54 +01:00
// Afficher les barres
$leftItems .= '<optgroup label="Barres latérales">';
foreach($this->getHierarchy(null, false,true) as $parentPageId => $childrenPageIds) {
2018-04-02 08:29:19 +02:00
$leftItems .= '<option value="' . helper::baseUrl() . $parentPageId . '"' . ($parentPageId === $currentPageId ? ' selected' : false) . '>' . $this->getData(['page', $parentPageId, 'title']) . '</option>';
foreach($childrenPageIds as $childKey) {
$leftItems .= '<option value="' . helper::baseUrl() . $childKey . '"' . ($childKey === $currentPageId ? ' selected' : false) . '>&nbsp;&nbsp;&nbsp;&nbsp;' . $this->getData(['page', $childKey, 'title']) . '</option>';
}
2020-05-24 19:59:21 +02:00
}
$leftItems .= '</optgroup>';
2018-04-02 08:29:19 +02:00
$leftItems .= '</select></li>';
$leftItems .= '<li><a href="' . helper::baseUrl() . 'page/add" data-tippy-content="Créer une page ou<br>une barre latérale">' . template::ico('plus') . '</a></li>';
2018-04-02 08:29:19 +02:00
if(
// Sur un module de page qui autorise le bouton de modification de la page
$this->core->output['showBarEditButton']
// Sur une page sans module
OR $this->getData(['page', $this->getUrl(0), 'moduleId']) === ''
// Sur une page d'accueil
OR $this->getUrl(0) === ''
) {
$leftItems .= '<li><a href="' . helper::baseUrl() . 'page/edit/' . $this->getUrl(0) . '" data-tippy-content="Modifier la page">' . template::ico('pencil') . '</a></li>';
if ($this->getData(['page', $this->getUrl(0),'moduleId'])) {
2020-05-24 19:59:21 +02:00
$leftItems .= '<li><a href="' . helper::baseUrl() . $this->getUrl(0) . '/config' . '" data-tippy-content="Configurer le module">' . template::ico('gear') . '</a></li>';
}
2020-09-20 17:39:42 +02:00
$leftItems .= '<li><a id="pageDuplicate" href="' . helper::baseUrl() . 'page/duplicate/' . $this->getUrl(0) . '&csrf=' . $_SESSION['csrf'] . '" data-tippy-content="Dupliquer la page">' . template::ico('clone') . '</a></li>';
2020-05-24 19:59:21 +02:00
$leftItems .= '<li><a id="pageDelete" href="' . helper::baseUrl() . 'page/delete/' . $this->getUrl(0) . '&csrf=' . $_SESSION['csrf'] . '" data-tippy-content="Effacer la page">' . template::ico('trash') . '</a></li>';
2018-04-02 08:29:19 +02:00
}
}
// Items de droite
$rightItems = '';
2020-09-28 16:45:22 +02:00
if($this->getUser('group') >= self::GROUP_EDITOR) {
2019-05-28 09:04:10 +02:00
$rightItems .= '<li><a href="' . helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR.'core.json') .'" data-tippy-content="Gérer les fichiers" data-lity>' . template::ico('folder') . '</a></li>';
2018-04-02 08:29:19 +02:00
}
if($this->getUser('group') >= self::GROUP_ADMIN) {
$rightItems .= '<li><a href="' . helper::baseUrl() . 'user" data-tippy-content="Configurer les utilisateurs">' . template::ico('users') . '</a></li>';
2020-06-02 12:03:45 +02:00
$rightItems .= '<li><a href="' . helper::baseUrl() . 'theme" data-tippy-content="Personnaliser les thèmes">' . template::ico('brush') . '</a></li>';
2019-05-03 22:48:18 +02:00
$rightItems .= '<li><a href="' . helper::baseUrl() . 'config" data-tippy-content="Configurer le site">' . template::ico('cog-alt') . '</a></li>';
// Mise à jour automatique
$today = mktime(0, 0, 0);
// Une mise à jour est disponible + recherche auto activée + 1 jour de délais
if ( $this->getData(['config','autoUpdate']) === true
AND $today > $this->getData(['core','lastAutoUpdate']) + 86400 ) {
if ( helper::checkNewVersion(common::ZWII_UPDATE_CHANNEL) ) {
$this->setData(['core','updateAvailable', true]);
$this->setData(['core','lastAutoUpdate',$today]);
}
}
2020-05-24 19:59:21 +02:00
// Afficher le bouton : Mise à jour détectée + activée
2020-04-23 10:17:40 +02:00
if ( $this->getData(['core','updateAvailable']) === true &&
$this->getData(['config','autoUpdate']) === true ) {
2020-04-23 10:17:40 +02:00
$rightItems .= '<li><a id="barUpdate" href="' . helper::baseUrl() . 'install/update" data-tippy-content="Mettre à jour Zwii '. common::ZWII_VERSION .' vers '. helper::getOnlineVersion(common::ZWII_UPDATE_CHANNEL) .'">' . template::ico('update colorRed') . '</a></li>';
}
2018-04-02 08:29:19 +02:00
}
$rightItems .= '<li><a href="' . helper::baseUrl() . 'user/edit/' . $this->getUser('id'). '/' . $_SESSION['csrf'] . '" data-tippy-content="Configurer mon compte">' . template::ico('user', 'right') . '<span id="displayUsername">' . $this->getUser('firstname') . ' ' . $this->getUser('lastname') . '</span></a></li>';
$rightItems .= '<li><a id="barLogout" href="' . helper::baseUrl() . 'user/logout" data-tippy-content="Me déconnecter">' . template::ico('logout') . '</a></li>';
2020-05-24 19:59:21 +02:00
// Barre de membre
echo '<div id="bar"><div class="container"><ul id="barLeft">' . $leftItems . '</ul><ul id="barRight">' . $rightItems . '</ul></div></div>';
2018-04-02 08:29:19 +02:00
}
}
/**
* Affiche le script
*/
public function showScript() {
ob_start();
require 'core/core.js.php';
$coreScript = ob_get_clean();
echo '<script>' . helper::minifyJs($coreScript . $this->core->output['script']) . '</script>';
}
/**
* Affiche le style
*/
public function showStyle() {
if($this->core->output['style']) {
echo '<base href="' . helper::baseUrl(true) .'">';
2020-03-23 10:36:50 +01:00
echo '<style type="text/css">' . helper::minifyCss($this->core->output['style']) . '</style>';
2018-04-02 08:29:19 +02:00
}
}
/**
* Affiche l'import des librairies
*/
public function showVendor() {
// Variables partagées
$vars = 'var baseUrl = ' . json_encode(helper::baseUrl(false)) . ';';
$vars .= 'var baseUrlQs = ' . json_encode(helper::baseUrl()) . ';';
if(
$this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
2020-09-28 16:45:22 +02:00
AND $this->getUser('group') >= self::GROUP_EDITOR
2018-04-02 08:29:19 +02:00
) {
2019-05-28 09:04:10 +02:00
$vars .= 'var privateKey = ' . json_encode(md5_file(self::DATA_DIR.'core.json')) . ';';
2018-04-02 08:29:19 +02:00
}
echo '<script>' . helper::minifyJs($vars) . '</script>';
// Librairies
$moduleId = $this->getData(['page', $this->getUrl(0), 'moduleId']);
foreach($this->core->output['vendor'] as $vendorName) {
// Coeur
if(file_exists('core/vendor/' . $vendorName . '/inc.json')) {
$vendorPath = 'core/vendor/' . $vendorName . '/';
}
// Module
elseif(
$moduleId
AND in_array($moduleId, self::$coreModuleIds) === false
AND file_exists('module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json')
) {
$vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/';
}
// Sinon continue
else {
continue;
}
// Détermine le type d'import en fonction de l'extension de la librairie
$vendorFiles = json_decode(file_get_contents($vendorPath . 'inc.json'));
foreach($vendorFiles as $vendorFile) {
switch(pathinfo($vendorFile, PATHINFO_EXTENSION)) {
case 'css':
echo '<link rel="stylesheet" href="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '">';
break;
case 'js':
echo '<script src="' . helper::baseUrl(false) . $vendorPath . $vendorFile . '"></script>';
break;
}
}
}
}
}