2018-04-02 08:29:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
* @copyright Copyright (C) 2018-2019, Frédéric Tempez
|
2018-04-02 08:29:19 +02:00
|
|
|
* @link http://zwiicms.com/
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2019-12-08 16:48:42 +01:00
|
|
|
const DISPLAY_LAYOUT_POPUP = 5;
|
2018-04-02 08:29:19 +02:00
|
|
|
const GROUP_BANNED = -1;
|
|
|
|
const GROUP_VISITOR = 0;
|
|
|
|
const GROUP_MEMBER = 1;
|
|
|
|
const GROUP_MODERATOR = 2;
|
|
|
|
const GROUP_ADMIN = 3;
|
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
|
|
|
|
2019-05-02 13:21:48 +02:00
|
|
|
// Numéro de version
|
2019-12-22 19:10:16 +01:00
|
|
|
const ZWII_VERSION = '10.0.020.dev';
|
2018-04-02 08:29:19 +02:00
|
|
|
|
|
|
|
public static $actions = [];
|
|
|
|
public static $coreModuleIds = [
|
|
|
|
'config',
|
|
|
|
'install',
|
|
|
|
'maintenance',
|
|
|
|
'page',
|
2019-07-04 12:38:23 +02:00
|
|
|
'search',
|
2018-04-02 08:29:19 +02:00
|
|
|
'sitemap',
|
|
|
|
'theme',
|
2019-07-04 12:38:23 +02:00
|
|
|
'user'
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
2019-12-10 10:53:31 +01:00
|
|
|
public static $dataStage = [
|
|
|
|
'config',
|
|
|
|
'core',
|
|
|
|
'module',
|
|
|
|
'page',
|
|
|
|
'user',
|
|
|
|
'theme'
|
|
|
|
];
|
2018-04-02 08:29:19 +02:00
|
|
|
private $data = [];
|
|
|
|
private $hierarchy = [
|
|
|
|
'all' => [],
|
2019-01-30 19:38:17 +01:00
|
|
|
'visible' => [],
|
|
|
|
'bar' => []
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
|
|
|
private $input = [
|
|
|
|
'_COOKIE' => [],
|
|
|
|
'_POST' => []
|
|
|
|
];
|
|
|
|
public static $inputBefore = [];
|
|
|
|
public static $inputNotices = [];
|
2019-12-10 10:53:31 +01:00
|
|
|
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' => '',
|
|
|
|
'redirect' => '',
|
|
|
|
'script' => '',
|
2019-12-08 16:48:42 +01:00
|
|
|
'targetLity' => false,
|
2018-04-02 08:29:19 +02:00
|
|
|
'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',
|
2018-11-28 14:12:33 +01:00
|
|
|
'flatpickr',
|
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',
|
2019-08-13 14:38:16 +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',
|
2019-01-11 19:42:35 +01:00
|
|
|
self::GROUP_MODERATOR => 'Éditeur',
|
2018-04-02 08:29:19 +02:00
|
|
|
self::GROUP_ADMIN => 'Administrateur'
|
|
|
|
];
|
|
|
|
public static $groupEdits = [
|
|
|
|
self::GROUP_BANNED => 'Banni',
|
|
|
|
self::GROUP_MEMBER => 'Membre',
|
2019-01-11 19:42:35 +01:00
|
|
|
self::GROUP_MODERATOR => 'Éditeur',
|
2018-04-02 08:29:19 +02:00
|
|
|
self::GROUP_ADMIN => 'Administrateur'
|
|
|
|
];
|
|
|
|
public static $groupNews = [
|
|
|
|
self::GROUP_MEMBER => 'Membre',
|
2019-01-11 19:42:35 +01:00
|
|
|
self::GROUP_MODERATOR => 'Éditeur',
|
2018-04-02 08:29:19 +02:00
|
|
|
self::GROUP_ADMIN => 'Administrateur'
|
|
|
|
];
|
|
|
|
public static $groupPublics = [
|
|
|
|
self::GROUP_VISITOR => 'Visiteur',
|
|
|
|
self::GROUP_MEMBER => 'Membre',
|
2019-01-11 19:42:35 +01:00
|
|
|
self::GROUP_MODERATOR => 'Éditeur',
|
2018-04-02 08:29:19 +02:00
|
|
|
self::GROUP_ADMIN => 'Administrateur'
|
|
|
|
];
|
|
|
|
public static $timezone;
|
|
|
|
private $url = '';
|
|
|
|
private $user = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur commun
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
// Extraction des données http
|
|
|
|
if(isset($_POST)) {
|
|
|
|
$this->input['_POST'] = $_POST;
|
|
|
|
}
|
|
|
|
if(isset($_COOKIE)) {
|
|
|
|
$this->input['_COOKIE'] = $_COOKIE;
|
|
|
|
}
|
2019-01-24 20:44:53 +01:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Import version 9
|
|
|
|
if (file_exists(self::DATA_DIR . 'core.json') === true &&
|
2019-12-17 16:04:40 +01:00
|
|
|
$this->getData(['core','dataVersion']) < 10000) {
|
|
|
|
$keepUsers = isset($_SESSION['KEEP_USERS']) ? $_SESSION['KEEP_USERS'] : false;
|
|
|
|
$this->importData($keepUsers);
|
|
|
|
unset ($_SESSION['KEEP_USERS']);
|
2019-12-17 10:34:34 +01:00
|
|
|
// Réinstaller htaccess
|
|
|
|
copy('core/module/config/ressource/.htaccess', self::DATA_DIR . '.htaccess');
|
2019-12-10 10:53:31 +01:00
|
|
|
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
|
|
|
}
|
2019-12-10 10:53:31 +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 ;
|
|
|
|
}
|
2019-01-26 22:45:04 +01:00
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Utilisateur connecté
|
|
|
|
if($this->user === []) {
|
|
|
|
$this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]);
|
|
|
|
}
|
|
|
|
// 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] = [];
|
|
|
|
}
|
2019-01-30 19:38:17 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-01-30 19:38:17 +01:00
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 21:27:04 +01:00
|
|
|
|
|
|
|
// Mise à jour des données core
|
|
|
|
$this->update();
|
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
|
|
|
|
*/
|
2019-12-10 10:53:31 +01:00
|
|
|
public function deleteData($keys) {
|
|
|
|
//Retourne une chaine contenant le dossier à créer
|
|
|
|
$folder = $this->dirData ($keys[0],'fr');
|
|
|
|
// Constructeur JsonDB
|
2019-12-15 10:47:18 +01:00
|
|
|
//require_once "core/vendor/jsondb/Dot.php";
|
|
|
|
//require_once "core/vendor/jsondb/JsonDb.php";
|
2019-12-10 10:53:31 +01:00
|
|
|
$db = new \Prowebcraft\JsonDb([
|
|
|
|
'name' => $keys[0] . '.json',
|
|
|
|
'dir' => $folder,
|
|
|
|
'template' => self::TEMP_DIR . 'data.template.json'
|
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
switch(count($keys)) {
|
2019-12-10 10:53:31 +01:00
|
|
|
case 1:
|
|
|
|
$db->delete($keys[0]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->delete($keys[0].'.'.$keys[1]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 10:46:38 +01:00
|
|
|
|
2018-10-24 22:48:10 +02:00
|
|
|
/**
|
2018-11-13 13:27:37 +01:00
|
|
|
* Récupérer une copie d'écran du site Web pour le tag image si le fichier n'existe pas
|
2018-10-24 22:48:10 +02:00
|
|
|
* En local, copie du site décran de ZwiiCMS
|
2018-11-19 10:46:38 +01:00
|
|
|
*/
|
2018-10-24 22:48:10 +02:00
|
|
|
public function makeImageTag () {
|
2019-05-28 09:04:10 +02:00
|
|
|
if (!file_exists(self::FILE_DIR.'source/screenshot.png'))
|
2018-11-19 10:46:38 +01:00
|
|
|
{
|
|
|
|
if ( strpos(helper::baseUrl(false),'localhost') == 0 AND strpos(helper::baseUrl(false),'127.0.0.1') == 0) {
|
2019-06-18 10:13:09 +02:00
|
|
|
$googlePagespeedData = @file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. helper::baseUrl(false) .'&screenshot=true');
|
|
|
|
if ($googlePagespeedData !== false) {
|
|
|
|
$googlePagespeedData = json_decode($googlePagespeedData, true);
|
|
|
|
$screenshot = $googlePagespeedData['screenshot']['data'];
|
|
|
|
$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
|
|
|
|
$data = 'data:image/jpeg;base64,'.$screenshot;
|
|
|
|
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
|
|
|
|
file_put_contents( self::FILE_DIR.'source/screenshot.png',$data);
|
|
|
|
}
|
2018-11-19 10:46:38 +01:00
|
|
|
}
|
2018-10-24 22:48:10 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-19 10:50:18 +01:00
|
|
|
|
2018-10-24 22:48:10 +02:00
|
|
|
|
2018-11-19 10:46:38 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Accède aux données
|
|
|
|
* @param array $keys Clé(s) des données
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-12-11 11:59:10 +01:00
|
|
|
public function getData($keys = []) {
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
if (count($keys) >= 1) {
|
|
|
|
//Retourne une chaine contenant le dossier à créer
|
|
|
|
$folder = $this->dirData ($keys[0],'fr');
|
|
|
|
// Constructeur JsonDB
|
2019-12-15 10:47:18 +01:00
|
|
|
//require_once "core/vendor/jsondb/Dot.php";
|
|
|
|
//require_once "core/vendor/jsondb/JsonDb.php";
|
2019-12-10 10:53:31 +01:00
|
|
|
$db = new \Prowebcraft\JsonDb([
|
|
|
|
'name' => $keys[0] . '.json',
|
|
|
|
'dir' => $folder,
|
|
|
|
'template' => self::TEMP_DIR . 'data.template.json'
|
|
|
|
]);
|
|
|
|
switch(count($keys)) {
|
|
|
|
case 1:
|
|
|
|
$tempData = $db->get($keys[0]);
|
|
|
|
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
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
return $tempData;
|
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
|
|
|
|
*/
|
2019-01-30 19:38:17 +01:00
|
|
|
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'];
|
2019-01-30 19:38:17 +01: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 checkboxs qui ne retournent rien lorsqu'elles ne sont pas cochées
|
|
|
|
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) {
|
|
|
|
// Champ obligatoire
|
|
|
|
if($required) {
|
|
|
|
$this->addRequiredInputNotices($key);
|
|
|
|
}
|
|
|
|
// Check de l'existence
|
|
|
|
// Également utile pour les checkboxs qui ne retournent rien lorsqu'elles ne sont pas cochées
|
|
|
|
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'] !== []);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-10 10:53:31 +01:00
|
|
|
* 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
|
|
|
*/
|
2019-12-10 10:53:31 +01:00
|
|
|
public function importData($keepUsers = false) {
|
|
|
|
// Trois tentatives de lecture
|
2018-04-02 08:29:19 +02:00
|
|
|
for($i = 0; $i < 3; $i++) {
|
2019-12-10 10:53:31 +01:00
|
|
|
$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;
|
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
elseif($i === 2) {
|
|
|
|
exit('Impossible de lire les données à importer.');
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
// Pause de 10 millisecondes
|
|
|
|
usleep(10000);
|
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
|
|
|
|
// Dossier de langues
|
|
|
|
if (!file_exists(self::DATA_DIR . '/fr')) {
|
|
|
|
mkdir (self::DATA_DIR . '/fr');
|
|
|
|
}
|
2019-12-11 21:56:18 +01:00
|
|
|
|
|
|
|
// Un seul fichier pour éviter les erreurs de sauvegarde des v9
|
|
|
|
$tempData = array_merge($tempData,$tempTheme);
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Ecriture des données
|
|
|
|
$this->setData(['config',$tempData['config']]);
|
|
|
|
$this->setData(['core',$tempData['core']]);
|
|
|
|
$this->setData(['page',$tempData['page']]);
|
2019-12-11 21:56:18 +01:00
|
|
|
$this->setData(['module',$tempData['module']]);
|
|
|
|
$this->setData(['theme',$tempData['theme']]);
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Import des users sauvegardés si option active
|
|
|
|
if ($keepUsers === false) {
|
|
|
|
$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');
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2019-03-13 17:11:04 +01:00
|
|
|
/**
|
2019-05-02 13:21:48 +02:00
|
|
|
* Génére un fichier json avec la liste des pages
|
|
|
|
*
|
2019-12-10 10:53:31 +01:00
|
|
|
*/
|
2019-07-04 19:54:51 +02:00
|
|
|
public function pages2Json() {
|
|
|
|
// Sauve la liste des pages pour TinyMCE
|
2019-03-14 19:04:03 +01:00
|
|
|
$parents = [];
|
2019-07-04 19:54:51 +02:00
|
|
|
$rewrite = (helper::checkRewrite()) ? '' : '?';
|
|
|
|
// Boucle de recherche des pages actives
|
2019-03-14 19:04:03 +01:00
|
|
|
foreach($this->getHierarchy(null,false,false) as $parentId => $childIds) {
|
|
|
|
$children = [];
|
|
|
|
// Exclure les barres
|
|
|
|
if ($this->getData(['page', $parentId, 'block']) !== 'bar' ) {
|
2019-04-23 19:24:03 +02:00
|
|
|
// Boucler sur les enfants et récupérer le tableau children avec la liste des enfants
|
|
|
|
foreach($childIds as $childId) {
|
2019-12-03 14:49:38 +01:00
|
|
|
$children [] = [ 'title' => ' » '. html_entity_decode($this->getData(['page', $childId, 'title']), ENT_QUOTES) ,
|
2019-03-14 19:04:03 +01:00
|
|
|
'value'=> $rewrite.$childId
|
2019-04-23 19:24:03 +02:00
|
|
|
];
|
2019-03-13 17:11:04 +01:00
|
|
|
}
|
2019-04-23 19:24:03 +02:00
|
|
|
// Traitement
|
|
|
|
if (empty($childIds)) {
|
|
|
|
// Pas d'enfant, uniuement l'entrée du parent
|
2019-12-03 14:49:38 +01:00
|
|
|
$parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
|
2019-04-23 19:24:03 +02:00
|
|
|
'value'=> $rewrite.$parentId
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// Des enfants, on ajoute la page parent en premier
|
2019-12-03 14:49:38 +01:00
|
|
|
array_unshift ($children , ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
|
2019-04-23 19:24:03 +02:00
|
|
|
'value'=> $rewrite.$parentId
|
|
|
|
]);
|
|
|
|
// puis on ajoute les enfants au parent
|
2019-12-03 14:49:38 +01:00
|
|
|
$parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), ENT_QUOTES) ,
|
2019-04-23 19:24:03 +02:00
|
|
|
'value'=> $rewrite.$parentId ,
|
|
|
|
'menu' => $children
|
|
|
|
];
|
|
|
|
}
|
2019-03-14 19:04:03 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-04 23:52:21 +02:00
|
|
|
// 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
|
|
|
|
];
|
2019-03-14 19:04:03 +01:00
|
|
|
|
2019-07-04 23:52:21 +02:00
|
|
|
// Enregistrement : 3 tentatives
|
2019-03-14 19:04:03 +01:00
|
|
|
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);
|
|
|
|
}
|
2019-03-13 17:11:04 +01:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +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 exite déjà les commandes sont ajoutées
|
|
|
|
*/
|
|
|
|
public function createRobots() {
|
|
|
|
|
|
|
|
$robotValue =
|
|
|
|
PHP_EOL .
|
|
|
|
'# ZWII CONFIG ---------' . PHP_EOL .
|
|
|
|
'User-agent: *' . PHP_EOL .
|
2019-09-19 09:35:45 +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 ;
|
|
|
|
|
|
|
|
if (file_exists('robots.txt')) {
|
|
|
|
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 fchier sitemap.xml
|
|
|
|
* https://github.com/icamys/php-sitemap-generator
|
|
|
|
* $command valeurs possible
|
|
|
|
* all : génére un site map complet
|
|
|
|
* 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
|
|
|
|
2019-06-13 14:01:43 +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";
|
|
|
|
|
|
|
|
$datetime = new DateTime(date('c'));
|
|
|
|
$datetime->format(DateTime::ATOM); // Updated ISO8601
|
|
|
|
// sitemap index file name
|
|
|
|
$sitemap->sitemapIndexFileName = "sitemap-index.xml";
|
2019-06-10 15:48:43 +02:00
|
|
|
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
|
2019-06-13 14:01:43 +02:00
|
|
|
if ($this->getData(['page',$parentPageId,'group']) !== 0 ||
|
|
|
|
$this->getData(['page', $parentPageId, 'block']) === 'bar' ) {
|
2019-05-07 18:36:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-06-09 15:24:43 +02:00
|
|
|
// 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);
|
2019-06-09 15:24:43 +02:00
|
|
|
|
|
|
|
// La sous-page est un blog
|
2019-06-20 20:26:08 +02:00
|
|
|
if ($this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
|
|
|
|
!empty($this->getData(['module',$childKey])) ) {
|
2019-06-10 16:21:41 +02:00
|
|
|
foreach($this->getData(['module',$childKey]) as $articleId => $article) {
|
|
|
|
if($this->getData(['module',$childKey,$articleId,'state']) === true) {
|
2019-06-13 14:01:43 +02:00
|
|
|
$date = $this->getData(['module',$childKey,$articleId,'publishedOn']);
|
2019-06-16 17:54:41 +02:00
|
|
|
$sitemap->addUrl( $childKey . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
|
2019-06-10 16:21:41 +02:00
|
|
|
}
|
2019-06-09 18:36:57 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-09 15:24:43 +02:00
|
|
|
}
|
|
|
|
// Articles du blog
|
2019-06-20 20:26:08 +02:00
|
|
|
if ($this->getData(['page', $parentPageId, 'moduleId']) === 'blog' &&
|
|
|
|
!empty($this->getData(['module',$parentPageId])) ) {
|
2019-06-10 16:21:41 +02:00
|
|
|
foreach($this->getData(['module',$parentPageId]) as $articleId => $article) {
|
2019-06-13 14:01:43 +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-06-10 16:21:41 +02:00
|
|
|
}
|
2019-06-09 15:24:43 +02:00
|
|
|
}
|
2019-05-02 13:21:48 +02:00
|
|
|
}
|
2019-06-13 14:01:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 13:21:48 +02:00
|
|
|
// generating internally a sitemap
|
|
|
|
$sitemap->createSitemap();
|
|
|
|
|
|
|
|
// writing early generated sitemap to file
|
|
|
|
$sitemap->writeSitemap();
|
|
|
|
|
|
|
|
return(file_exists('sitemap.xml'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-23 23:37:17 +01:00
|
|
|
|
2019-02-28 12:46:38 +01:00
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
public function sendMail($to, $subject, $content) {
|
2019-02-28 12:46:38 +01:00
|
|
|
// Utilisation de PHPMailer version 6.0.6
|
2019-12-15 10:47:18 +01:00
|
|
|
//require_once "core/vendor/phpmailer/phpmailer.php";
|
|
|
|
//require_once "core/vendor/phpmailer/exception.php";
|
2019-02-28 12:46:38 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Layout
|
|
|
|
ob_start();
|
|
|
|
include 'core/layout/mail.php';
|
|
|
|
$layout = ob_get_clean();
|
|
|
|
// Mail
|
2019-02-28 12:46:38 +01:00
|
|
|
try{
|
|
|
|
$mail = new PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
|
|
|
|
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title']));
|
|
|
|
$mail->addReplyTo('no-reply@' . $host, $this->getData(['config', 'title']));
|
|
|
|
if(is_array($to)) {
|
|
|
|
foreach($to as $userMail) {
|
2019-03-05 09:58:52 +01:00
|
|
|
$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 {
|
2019-03-05 09:38:09 +01:00
|
|
|
$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
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
2019-12-10 10:53:31 +01:00
|
|
|
* Sauvegarde des données
|
2018-04-02 08:29:19 +02:00
|
|
|
* @param array $keys Clé(s) des données
|
|
|
|
*/
|
2019-12-11 16:14:47 +01:00
|
|
|
public function setData($keys = []) {
|
2019-12-10 10:53:31 +01:00
|
|
|
|
|
|
|
// Pas d'enregistrement lorsque'une notice est présente
|
|
|
|
if (!empty(self::$inputNotices)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Retourne une chaine contenant le dossier à créer
|
|
|
|
$folder = $this->dirData ($keys[0],'fr');
|
|
|
|
// Constructeur JsonDB
|
2019-12-15 10:47:18 +01:00
|
|
|
//require_once "core/vendor/jsondb/Dot.php";
|
|
|
|
//require_once "core/vendor/jsondb/JsonDb.php";
|
2019-12-10 10:53:31 +01:00
|
|
|
$db = new \Prowebcraft\JsonDb([
|
|
|
|
'name' => $keys[0] . '.json',
|
|
|
|
'dir' => $folder,
|
|
|
|
'template' => self::TEMP_DIR . 'data.template.json'
|
|
|
|
]);
|
|
|
|
|
|
|
|
switch(count($keys)) {
|
2018-04-02 08:29:19 +02:00
|
|
|
case 2:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->set($keys[0],$keys[1]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->set($keys[0].'.'.$keys[1],$keys[2]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-12-10 10:53:31 +01:00
|
|
|
$db->set($keys[0].'.'.$keys[1].'.'.$keys[2],$keys[3]);
|
|
|
|
$db->save();
|
2018-04-02 08:29:19 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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:
|
2019-12-10 10:53:31 +01:00
|
|
|
$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
|
|
|