2021-06-07 10:16:09 +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
* @ author Frédéric Tempez < frederic . tempez @ outlook . com >
2023-01-09 10:23:32 +01:00
* @ copyright Copyright ( C ) 2018 - 2023 , Frédéric Tempez
2022-12-29 17:02:20 +01:00
* @ license CC Attribution - NonCommercial - NoDerivatives 4.0 International
2021-06-07 10:16:09 +02:00
* @ link http :// zwiicms . fr /
*/
2023-03-08 15:59:02 +01:00
/**
* Chargement des classes filles
* router : aiguillage des pages
*/
2023-06-12 18:15:46 +02:00
2023-03-08 15:59:02 +01:00
2022-09-29 08:45:59 +02:00
class common
{
2021-06-07 10:16:09 +02:00
const DISPLAY_RAW = 0 ;
const DISPLAY_JSON = 1 ;
const DISPLAY_RSS = 2 ;
const DISPLAY_LAYOUT_BLANK = 3 ;
const DISPLAY_LAYOUT_MAIN = 4 ;
const DISPLAY_LAYOUT_LIGHT = 5 ;
const GROUP_BANNED = - 1 ;
const GROUP_VISITOR = 0 ;
const GROUP_MEMBER = 1 ;
const GROUP_MODERATOR = 2 ;
2023-03-31 14:36:19 +02:00
const GROUP_ADMIN = 3 ;
2021-06-07 10:16:09 +02:00
const SIGNATURE_ID = 1 ;
const SIGNATURE_PSEUDO = 2 ;
const SIGNATURE_FIRSTLASTNAME = 3 ;
const SIGNATURE_LASTFIRSTNAME = 4 ;
// Dossier de travail
const BACKUP_DIR = 'site/backup/' ;
const DATA_DIR = 'site/data/' ;
const FILE_DIR = 'site/file/' ;
const TEMP_DIR = 'site/tmp/' ;
2022-09-02 15:37:23 +02:00
const I18N_DIR = 'site/i18n/' ;
2022-04-08 09:47:35 +02:00
const MODULE_DIR = 'module/' ;
2021-06-07 10:16:09 +02:00
// Miniatures de la galerie
const THUMBS_SEPARATOR = 'mini_' ;
const THUMBS_WIDTH = 640 ;
// Contrôle d'édition temps maxi en secondes avant déconnexion 30 minutes
const ACCESS_TIMER = 1800 ;
2023-04-22 18:51:32 +02:00
// Numéro de version
2023-06-20 19:33:13 +02:00
const ZWII_VERSION = '13.0.00' ;
2023-02-07 08:36:19 +01:00
2022-12-27 09:49:29 +01:00
// URL autoupdate
2023-02-07 11:26:18 +01:00
const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/update/raw/branch/master/' ;
2023-06-20 19:33:13 +02:00
const ZWII_UPDATE_CHANNEL = " v13 " ;
2022-08-08 10:16:12 +02:00
2022-12-27 09:49:29 +01:00
// URL langues de l'UI en ligne
const ZWII_UI_URL = 'https://forge.chapril.org/ZwiiCMS-Team/zwiicms-translations/raw/branch/master/' ;
2021-06-07 10:16:09 +02:00
public static $actions = [];
public static $coreModuleIds = [
'config' ,
'install' ,
'maintenance' ,
'page' ,
'sitemap' ,
'theme' ,
'user' ,
'translate' ,
2022-02-17 15:45:25 +01:00
'plugin'
2021-06-07 10:16:09 +02:00
];
public static $accessList = [
'user' ,
'theme' ,
'config' ,
'edit' ,
2022-05-05 18:19:56 +02:00
'config' ,
'translate'
2021-06-07 10:16:09 +02:00
];
public static $accessExclude = [
'login' ,
'logout'
];
2022-05-05 18:19:56 +02:00
private $data = [];
2021-06-07 10:16:09 +02:00
private $hierarchy = [
'all' => [],
'visible' => [],
'bar' => []
];
private $input = [
'_COOKIE' => [],
'_POST' => []
];
public static $inputBefore = [];
public static $inputNotices = [];
public static $importNotices = [];
public static $coreNotices = [];
public $output = [
'access' => true ,
'content' => '' ,
'contentLeft' => '' ,
'contentRight' => '' ,
'display' => self :: DISPLAY_LAYOUT_MAIN ,
'metaDescription' => '' ,
'metaTitle' => '' ,
'notification' => '' ,
'redirect' => '' ,
'script' => '' ,
'showBarEditButton' => false ,
'showPageContent' => false ,
'state' => false ,
'style' => '' ,
2023-02-16 11:52:40 +01:00
'inlineStyle' => [],
'inlineScript' => [],
2023-02-02 21:00:03 +01:00
'title' => null ,
// Null car un titre peut être vide
2021-06-07 10:16:09 +02:00
// Trié par ordre d'exécution
'vendor' => [
'jquery' ,
'normalize' ,
'lity' ,
'filemanager' ,
// 'tinycolorpicker', Désactivé par défaut
// 'tinymce', Désactivé par défaut
// 'codemirror', // Désactivé par défaut
'tippy' ,
'zwiico' ,
'imagemap' ,
'simplelightbox'
],
'view' => ''
];
public static $groups = [
self :: GROUP_BANNED => 'Banni' ,
self :: GROUP_VISITOR => 'Visiteur' ,
self :: GROUP_MEMBER => 'Membre' ,
self :: GROUP_MODERATOR => 'Éditeur' ,
self :: GROUP_ADMIN => 'Administrateur'
];
public static $groupEdits = [
self :: GROUP_BANNED => 'Banni' ,
self :: GROUP_MEMBER => 'Membre' ,
self :: GROUP_MODERATOR => 'Éditeur' ,
self :: GROUP_ADMIN => 'Administrateur'
];
public static $groupNews = [
self :: GROUP_MEMBER => 'Membre' ,
self :: GROUP_MODERATOR => 'Éditeur' ,
self :: GROUP_ADMIN => 'Administrateur'
];
public static $groupPublics = [
self :: GROUP_VISITOR => 'Visiteur' ,
self :: GROUP_MEMBER => 'Membre' ,
self :: GROUP_MODERATOR => 'Éditeur' ,
self :: GROUP_ADMIN => 'Administrateur'
];
2022-09-21 16:02:06 +02:00
//Langues de l'UI
// Langue de l'interface, tableau des dialogues
public static $dialog ;
// Langue de l'interface sélectionnée
public static $i18nUI = 'fr_FR' ;
2023-02-10 09:58:55 +01:00
// Langues de contenu
2023-04-24 22:28:53 +02:00
public static $i18nContent = 'fr_FR' ;
2022-09-26 14:45:40 +02:00
public static $languages = [
2022-09-24 17:27:15 +02:00
'az_AZ' => 'Azərbaycan dili' ,
'bg_BG' => 'български език' ,
//'ca' => 'Català, valencià',
//'cs' => 'čeština, český jazyk',
//'da' => 'Dansk',
2022-09-21 16:02:06 +02:00
'de' => 'Deutsch' ,
'en_EN' => 'English' ,
'es' => 'Español' ,
2022-09-24 17:27:15 +02:00
//'fa' => 'فارسی',
2022-09-21 16:02:06 +02:00
'fr_FR' => 'Français' ,
2022-12-27 18:38:51 +01:00
'he_IL' => 'Hebrew (Israel)' ,
2023-03-02 14:17:12 +01:00
'gr_GR' => 'Ελληνικά' ,
2022-09-24 17:27:15 +02:00
'hr' => 'Hrvatski jezik' ,
'hu_HU' => 'Magyar' ,
'id' => 'Bahasa Indonesia' ,
2022-09-21 16:02:06 +02:00
'it' => 'Italiano' ,
2022-09-24 17:27:15 +02:00
'ja' => '日本' ,
'lt' => 'Lietuvių kalba' ,
//'mn_MN' => 'монгол',
'nb_NO' => 'Norsk bokmål' ,
'nn_NO' => 'Norsk nynorsk' ,
2022-09-21 16:02:06 +02:00
'nl' => 'Nederlands, Vlaams' ,
'pl' => 'Język polski, polszczyzna' ,
2022-09-24 17:27:15 +02:00
'pt_BR' => 'Português(Brazil)' ,
2022-09-21 16:02:06 +02:00
'pt_PT' => 'Português' ,
'ro' => 'Română' ,
2022-09-24 17:27:15 +02:00
'ru' => 'Pу с с кий язык' ,
'sk' => 'Slovenčina' ,
'sl' => 'Slovenski jezik' ,
2022-09-21 16:02:06 +02:00
'sv_SE' => 'Svenska' ,
2022-09-24 17:27:15 +02:00
'th_TH' => 'ไทย' ,
'tr_TR' => 'Türkçe' ,
'uk_UA' => 'Yкр а їнс ька мова' ,
'vi' => 'Tiếng Việt' ,
'zh_CN' => '中文 (Zhōngwén), 汉语, 漢語' ,
2022-09-21 16:02:06 +02:00
// source: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
];
2022-09-19 16:57:54 +02:00
2022-09-02 15:35:39 +02:00
// Zone de temps
2021-06-07 10:16:09 +02:00
public static $timezone ;
private $url = '' ;
// Données de site
private $user = [];
// Descripteur de données Entrées / Sorties
2022-05-05 18:19:56 +02:00
// Liste ici tous les fichiers de données
2021-06-07 10:16:09 +02:00
private $dataFiles = [
2022-02-17 16:58:52 +01:00
'admin' => '' ,
'blacklist' => '' ,
2021-06-07 10:16:09 +02:00
'config' => '' ,
'core' => '' ,
2023-03-01 15:50:41 +01:00
'font' => '' ,
2022-02-17 16:58:52 +01:00
'module' => '' ,
'locale' => '' ,
2021-06-07 10:16:09 +02:00
'page' => '' ,
'theme' => '' ,
2022-12-28 16:20:55 +01:00
'user' => '' ,
2023-03-01 15:50:41 +01:00
'language' => '' ,
2023-04-14 07:32:23 +02:00
'profil' => '' ,
2021-06-07 10:16:09 +02:00
];
2022-02-06 17:13:16 +01:00
2022-03-05 15:49:03 +01:00
public static $fontsWebSafe = [
2023-02-02 21:00:03 +01:00
'arial' => [
'name' => 'Arial' ,
'font-family' => 'Arial, Helvetica, sans-serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2022-05-05 18:19:56 +02:00
'arial-black' => [
2023-02-02 21:00:03 +01:00
'name' => 'Arial Black' ,
'font-family' => '\'Arial Black\', Gadget, sans-serif' ,
'resource' => 'websafe'
2022-05-05 18:19:56 +02:00
],
'courrier' => [
2023-02-02 21:00:03 +01:00
'name' => 'Courier' ,
'font-family' => 'Courier, \'Liberation Mono\', monospace' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'courrier-new' => [
'name' => 'Courier New' ,
'font-family' => '\'Courier New\', Courier, monospace' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'garamond' => [
'name' => 'Garamond' ,
'font-family' => 'Garamond, serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'georgia' => [
2023-02-21 14:58:36 +01:00
'name' => 'Georgia' ,
2023-02-02 21:00:03 +01:00
'font-family' => 'Georgia, serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'impact' => [
'name' => 'Impact' ,
'font-family' => 'Impact, Charcoal, sans-serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'lucida' => [
'name' => 'Lucida' ,
'font-family' => '\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'tahoma' => [
'name' => 'Tahoma' ,
'font-family' => 'Tahoma, Geneva, sans-serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'times-new-roman' => [
'name' => 'Times New Roman' ,
'font-family' => '\'Times New Roman\', \'Liberation Serif\', serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'trebuchet' => [
'name' => 'Trebuchet' ,
'font-family' => '\'Trebuchet MS\', Arial, Helvetica, sans-serif' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
],
2023-02-02 21:00:03 +01:00
'verdana' => [
'name' => 'Verdana' ,
'font-family' => 'Verdana, Geneva, sans-serif;' ,
'resource' => 'websafe'
2022-03-21 15:35:05 +01:00
]
2022-03-05 15:49:03 +01:00
];
2022-03-07 11:31:52 +01:00
2021-06-07 10:16:09 +02:00
/**
* Constructeur commun
*/
2022-09-29 08:45:59 +02:00
public function __construct ()
{
2021-06-14 18:37:45 +02:00
2021-06-07 10:16:09 +02:00
// Extraction des données http
2022-09-29 08:45:59 +02:00
if ( isset ( $_POST )) {
2021-06-07 10:16:09 +02:00
$this -> input [ '_POST' ] = $_POST ;
}
2022-09-29 08:45:59 +02:00
if ( isset ( $_COOKIE )) {
2021-06-07 10:16:09 +02:00
$this -> input [ '_COOKIE' ] = $_COOKIE ;
}
2023-04-15 19:26:18 +02:00
// Extraction de la sesion
// $this->input['_SESSION'] = $_SESSION;
// Déterminer la langue du contenu du site
2023-04-12 15:29:21 +02:00
if ( isset ( $_SESSION [ 'ZWII_CONTENT' ])) {
2023-04-15 19:26:18 +02:00
// Déterminé par la session présente
2023-04-12 15:29:21 +02:00
self :: $i18nContent = $_SESSION [ 'ZWII_CONTENT' ];
2023-04-21 17:25:08 +02:00
} else {
// Détermine la langue par défaut
foreach ( self :: $languages as $key => $value ) {
if ( file_exists ( self :: DATA_DIR . $key . '/.default' )) {
self :: $i18nContent = $key ;
$_SESSION [ 'ZWII_CONTENT' ] = $key ;
break ;
}
}
2023-04-15 19:26:18 +02:00
}
2023-04-21 17:25:08 +02:00
\setlocale ( LC_ALL , self :: $i18nContent . '.UTF8' );
2023-04-12 15:29:21 +02:00
2022-11-21 10:22:04 +01:00
// Instanciation de la classe des entrées / sorties
// Récupère les descripteurs
foreach ( $this -> dataFiles as $keys => $value ) {
2023-04-26 21:40:09 +02:00
// Constructeur JsonDB;
2022-11-21 10:22:04 +01:00
$this -> dataFiles [ $keys ] = new \Prowebcraft\JsonDb ([
'name' => $keys . '.json' ,
'dir' => $this -> dataPath ( $keys , self :: $i18nContent ),
'backup' => file_exists ( 'site/data/.backup' )
2023-02-02 21:00:03 +01:00
]);
2022-11-21 10:05:55 +01:00
}
2022-09-12 22:14:51 +02:00
2023-03-02 21:12:45 +01:00
// Installation fraîche, initialisation des modules
if ( $this -> user === []) {
foreach ( $this -> dataFiles as $stageId => $item ) {
$folder = $this -> dataPath ( $stageId , self :: $i18nContent );
if (
file_exists ( $folder . $stageId . '.json' ) === false
) {
$this -> initData ( $stageId , self :: $i18nContent );
2023-04-15 19:26:18 +02:00
common :: $coreNotices [] = $stageId ;
2023-03-02 21:12:45 +01:00
}
2022-05-05 18:19:56 +02:00
}
}
2023-06-12 21:44:24 +02:00
// Récupère un utilisateur connecté
2023-04-15 19:03:28 +02:00
if ( $this -> user === []) {
$this -> user = $this -> getData ([ 'user' , $this -> getInput ( 'ZWII_USER_ID' )]);
}
2023-04-15 19:09:36 +02:00
2023-04-15 19:03:28 +02:00
// Langue de l'administration si le user est connecté
if ( $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'language' ])) {
2023-02-19 17:42:02 +01:00
// Langue sélectionnée dans le compte, la langue du cookie sinon celle du compte ouvert
2023-04-15 19:03:28 +02:00
self :: $i18nUI = $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'language' ]);
2022-10-27 21:22:06 +02:00
// Validation de la langue
2023-04-22 18:25:35 +02:00
self :: $i18nUI = isset ( self :: $i18nUI ) && file_exists ( self :: I18N_DIR . self :: $i18nUI . '.json' )
? self :: $i18nUI
: 'fr_FR' ;
2023-02-20 15:22:58 +01:00
} else {
2023-04-24 21:24:41 +02:00
if ( isset ( $_SESSION [ 'ZWII_UI' ])) {
self :: $i18nUI = $_SESSION [ 'ZWII_UI' ];
2023-04-26 21:40:09 +02:00
} elseif ( isset ( $_COOKIE [ 'ZWII_UI' ])) {
self :: $i18nUI = $_COOKIE [ 'ZWII_UI' ];
2023-04-15 19:03:28 +02:00
} else {
self :: $i18nUI = 'fr_FR' ;
}
$_SESSION [ 'ZWII_UI' ] = self :: $i18nUI ;
2021-06-07 10:16:09 +02:00
}
2023-04-22 18:25:35 +02:00
// Stocker le cookie de langue pour l'éditeur de texte
setcookie ( 'ZWII_UI' , self :: $i18nUI , time () + 3600 , helper :: baseUrl ( false , false ), '' , false , false );
2021-06-07 10:16:09 +02:00
// Construit la liste des pages parents/enfants
2022-09-29 08:45:59 +02:00
if ( $this -> hierarchy [ 'all' ] === []) {
2023-03-26 09:31:42 +02:00
$this -> buildHierarchy ();
2021-06-07 10:16:09 +02:00
}
2022-09-02 15:35:39 +02:00
2021-06-07 10:16:09 +02:00
// Construit l'url
2022-09-29 08:45:59 +02:00
if ( $this -> url === '' ) {
if ( $url = $_SERVER [ 'QUERY_STRING' ]) {
2021-06-07 10:16:09 +02:00
$this -> url = $url ;
2022-09-29 08:45:59 +02:00
} else {
2021-06-07 10:16:09 +02:00
$this -> url = $this -> getData ([ 'locale' , 'homePageId' ]);
}
}
2022-09-02 15:35:39 +02:00
// Chargement des dialogues
2022-11-07 17:44:38 +01:00
if ( ! file_exists ( self :: I18N_DIR . self :: $i18nUI . '.json' )) {
2022-10-16 07:41:57 +02:00
// Copie des fichiers de langue par défaut fr_FR si pas initialisé
2022-11-07 17:44:38 +01:00
$this -> copyDir ( 'core/module/install/ressource/i18n' , self :: I18N_DIR );
2022-10-16 07:41:57 +02:00
}
2022-09-21 16:02:06 +02:00
self :: $dialog = json_decode ( file_get_contents ( self :: I18N_DIR . self :: $i18nUI . '.json' ), true );
2023-02-02 21:00:03 +01:00
2023-01-23 15:44:11 +01:00
// Dialogue du module
if ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ])) {
$moduleId = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]);
if (
is_dir ( self :: MODULE_DIR . $moduleId . '/i18n' )
&& file_exists ( self :: MODULE_DIR . $moduleId . '/i18n/' . self :: $i18nUI . '.json' )
) {
$d = json_decode ( file_get_contents ( self :: MODULE_DIR . $moduleId . '/i18n/' . self :: $i18nUI . '.json' ), true );
self :: $dialog = array_merge ( self :: $dialog , $d );
}
}
2021-06-07 10:16:09 +02:00
// Données de proxy
2022-09-29 08:45:59 +02:00
$proxy = $this -> getData ([ 'config' , 'proxyType' ]) . $this -> getData ([ 'config' , 'proxyUrl' ]) . ':' . $this -> getData ([ 'config' , 'proxyPort' ]);
if (
! empty ( $this -> getData ([ 'config' , 'proxyUrl' ])) &&
! empty ( $this -> getData ([ 'config' , 'proxyPort' ]))
) {
2021-06-07 10:16:09 +02:00
$context = array (
'http' => array (
'proxy' => $proxy ,
'request_fulluri' => true ,
2023-02-02 21:00:03 +01:00
'verify_peer' => false ,
2021-06-07 10:16:09 +02:00
'verify_peer_name' => false ,
),
2022-09-29 08:45:59 +02:00
" ssl " => array (
" verify_peer " => false ,
" verify_peer_name " => false
2021-06-07 10:16:09 +02:00
)
);
stream_context_set_default ( $context );
}
2023-06-13 20:59:10 +02:00
// Mise à jour des données core
include ( 'core/include/update.inc.php' );
2021-06-07 10:16:09 +02:00
}
2022-10-03 11:28:28 +02:00
2021-06-07 10:16:09 +02:00
/**
* Ajoute les valeurs en sortie
* @ param array $output Valeurs en sortie
*/
2022-09-29 08:45:59 +02:00
public function addOutput ( $output )
{
2021-06-07 10:16:09 +02:00
$this -> output = array_merge ( $this -> output , $output );
}
/**
* Ajoute une notice de champ obligatoire
* @ param string $key Clef du champ
*/
2022-09-29 08:45:59 +02:00
public function addRequiredInputNotices ( $key )
{
2021-06-07 10:16:09 +02:00
// La clef est un tableau
2022-09-29 08:45:59 +02:00
if ( preg_match ( '#\[(.*)\]#' , $key , $secondKey )) {
2021-06-07 10:16:09 +02:00
$firstKey = explode ( '[' , $key )[ 0 ];
$secondKey = $secondKey [ 1 ];
2022-09-29 08:45:59 +02:00
if ( empty ( $this -> input [ '_POST' ][ $firstKey ][ $secondKey ])) {
2023-02-19 18:01:28 +01:00
common :: $inputNotices [ $firstKey . '_' . $secondKey ] = helper :: translate ( 'Obligatoire' );
2021-06-07 10:16:09 +02:00
}
}
// La clef est une chaine
2022-09-29 08:45:59 +02:00
elseif ( empty ( $this -> input [ '_POST' ][ $key ])) {
2023-02-19 18:01:28 +01:00
common :: $inputNotices [ $key ] = helper :: translate ( 'Obligatoire' );
2021-06-07 10:16:09 +02:00
}
}
/**
* Check du token CSRF ( true = bo
*/
2022-09-29 08:45:59 +02:00
public function checkCSRF ()
{
2023-06-20 17:58:58 +02:00
return (( empty ( $_POST [ 'csrf' ]) or hash_equals ( $_POST [ 'csrf' ], $_SESSION [ 'csrf' ]) === false ) === false );
2021-06-07 10:16:09 +02:00
}
/**
* Supprime des données
* @ param array $keys Clé ( s ) des données
*/
2022-09-29 08:45:59 +02:00
public function deleteData ( $keys )
{
2022-02-25 09:05:37 +01:00
// Descripteur de la base
2021-06-07 10:16:09 +02:00
$db = $this -> dataFiles [ $keys [ 0 ]];
2022-02-25 09:05:37 +01:00
// Initialisation de la requête par le nom de la base
$query = $keys [ 0 ];
// Construire la requête
2022-09-29 08:45:59 +02:00
for ( $i = 1 ; $i <= count ( $keys ) - 1 ; $i ++ ) {
2022-02-25 09:05:37 +01:00
$query .= '.' . $keys [ $i ];
2021-06-07 10:16:09 +02:00
}
2022-02-25 09:05:37 +01:00
// Effacer la donnée
$success = $db -> delete ( $query , true );
2022-02-25 08:49:06 +01:00
return is_object ( $success );
2021-06-07 10:16:09 +02:00
}
2022-09-29 08:45:59 +02:00
/**
2022-02-24 15:41:51 +01:00
* Sauvegarde des données
* @ param array $keys Clé ( s ) des données
*/
2022-09-29 08:45:59 +02:00
public function setData ( $keys = [])
{
2022-02-24 15:41:51 +01:00
// Pas d'enregistrement lorsqu'une notice est présente ou tableau transmis vide
2022-09-29 08:45:59 +02:00
if (
! empty ( self :: $inputNotices )
or empty ( $keys )
) {
2022-02-24 15:41:51 +01:00
return false ;
}
// Empêcher la sauvegarde d'une donnée nulle.
2022-09-29 08:45:59 +02:00
if ( gettype ( $keys [ count ( $keys ) - 1 ]) === NULL ) {
2022-02-24 15:41:51 +01:00
return false ;
}
2022-02-25 09:05:37 +01:00
// Initialisation du retour en cas d'erreur de descripteur
2022-02-25 08:27:16 +01:00
$success = false ;
2022-02-25 09:05:37 +01:00
// Construire la requête dans la base inf à 1 retourner toute la base
2022-02-24 15:41:51 +01:00
if ( count ( $keys ) >= 1 ) {
2022-02-25 09:05:37 +01:00
// Descripteur de la base
2022-02-24 15:41:51 +01:00
$db = $this -> dataFiles [ $keys [ 0 ]];
2022-02-25 09:05:37 +01:00
$query = $keys [ 0 ];
// Construire la requête
2022-02-25 08:42:00 +01:00
// Ne pas tenir compte du dernier élément qui une une value donc <
2022-09-29 08:45:59 +02:00
for ( $i = 1 ; $i < count ( $keys ) - 1 ; $i ++ ) {
2022-02-25 09:05:37 +01:00
$query .= '.' . $keys [ $i ];
2022-02-24 15:41:51 +01:00
}
2022-02-25 09:05:37 +01:00
// Appliquer la modification, le dernier élément étant la donnée à sauvegarder
2022-09-29 08:45:59 +02:00
$success = is_object ( $db -> set ( $query , $keys [ count ( $keys ) - 1 ], true ));
2022-02-24 15:41:51 +01:00
}
2022-02-25 08:27:16 +01:00
return $success ;
2022-02-24 15:41:51 +01:00
}
2021-06-07 10:16:09 +02:00
/**
* Accède aux données
* @ param array $keys Clé ( s ) des données
* @ return mixed
*/
2022-09-29 08:45:59 +02:00
public function getData ( $keys = [])
{
2022-02-25 09:05:37 +01:00
// Eviter une requete vide
2021-06-07 10:16:09 +02:00
if ( count ( $keys ) >= 1 ) {
2022-02-25 09:05:37 +01:00
// descripteur de la base
2021-06-07 10:16:09 +02:00
$db = $this -> dataFiles [ $keys [ 0 ]];
2022-02-25 09:05:37 +01:00
$query = $keys [ 0 ];
// Construire la requête
2022-09-29 08:45:59 +02:00
for ( $i = 1 ; $i < count ( $keys ); $i ++ ) {
2022-02-25 09:05:37 +01:00
$query .= '.' . $keys [ $i ];
2021-06-07 10:16:09 +02:00
}
2022-02-25 09:05:37 +01:00
return $db -> get ( $query );
2021-06-07 10:16:09 +02:00
}
}
2021-08-17 08:24:12 +02:00
/**
* Lire les données de la page
* @ param string pageId
2021-08-21 08:44:37 +02:00
* @ param string langue
2023-02-06 21:45:03 +01:00
* @ return string contenu de la page
2021-08-17 08:24:12 +02:00
*/
2022-09-29 08:45:59 +02:00
public function getPage ( $page , $lang )
{
2021-08-17 08:24:12 +02:00
2021-11-18 11:34:19 +01:00
// Le nom de la ressource et le fichier de contenu sont définis :
2021-10-01 12:41:15 +02:00
if (
2022-09-29 08:45:59 +02:00
$this -> getData ([ 'page' , $page , 'content' ]) !== ''
&& file_exists ( self :: DATA_DIR . $lang . '/content/' . $this -> getData ([ 'page' , $page , 'content' ]))
) {
return file_get_contents ( self :: DATA_DIR . $lang . '/content/' . $this -> getData ([ 'page' , $page , 'content' ]));
} else {
return 'Aucun contenu trouvé.' ;
2021-11-18 11:34:19 +01:00
}
2021-08-17 08:24:12 +02:00
}
/**
* Ecrire les données de la page
* @ param string pageId
2021-11-18 11:34:19 +01:00
* @ param string contenu de la page
2023-02-06 21:45:03 +01:00
* @ return int nombre d ' octets écrits ou erreur
2021-08-17 08:24:12 +02:00
*/
2022-09-29 08:45:59 +02:00
public function setPage ( $page , $value , $lang )
{
2021-08-17 08:24:12 +02:00
2021-09-14 20:54:31 +02:00
return file_put_contents ( self :: DATA_DIR . $lang . '/content/' . $page . '.html' , $value );
2021-08-17 08:24:12 +02:00
}
2022-02-18 12:43:48 +01:00
2021-08-17 08:24:12 +02:00
/**
* Effacer les données de la page
* @ param string pageId
2023-02-06 21:45:03 +01:00
* @ return bool statut de l ' effacement
2021-08-17 08:24:12 +02:00
*/
2022-09-29 08:45:59 +02:00
public function deletePage ( $page , $lang )
{
2021-08-17 08:24:12 +02:00
2022-09-29 08:45:59 +02:00
return unlink ( self :: DATA_DIR . $lang . '/content/' . $this -> getData ([ 'page' , $page , 'content' ]));
2022-02-18 12:43:48 +01:00
}
2021-06-07 10:16:09 +02:00
/**
* Initialisation des données
2023-04-14 09:00:15 +02:00
* @ param string $module : nom du module à générer
* @ param string $lang la langue à créer
* @ param bool $sampleSite créer un site exemple en FR
2021-06-07 10:16:09 +02:00
* choix valides : core config user theme page module
*/
2022-09-29 08:45:59 +02:00
public function initData ( $module , $lang , $sampleSite = false )
{
2021-06-07 10:16:09 +02:00
// Tableau avec les données vierges
require_once ( 'core/module/install/ressource/defaultdata.php' );
2023-04-14 10:11:13 +02:00
if (
$module === 'page' ||
$module === 'module' ||
$module === 'locale'
) {
// Création des sous-dossiers localisés
if ( ! file_exists ( self :: DATA_DIR . $lang )) {
mkdir ( self :: DATA_DIR . $lang , 0755 );
}
if ( ! file_exists ( self :: DATA_DIR . $lang . '/content' )) {
mkdir ( self :: DATA_DIR . $lang . '/content' , 0755 );
}
// Site en français avec site exemple
if ( $lang == 'fr_FR' && $sampleSite === true ) {
2023-05-03 19:47:37 +02:00
file_put_contents ( self :: DATA_DIR . $lang . '/' . $module . '.json' , json_encode ([ $module => init :: $siteTemplate [ $module ]], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT ));
2023-06-12 21:08:33 +02:00
// Création des pages
2023-04-14 09:00:15 +02:00
foreach ( init :: $siteContent as $key => $value ) {
2023-06-12 21:08:33 +02:00
$this -> setPage ( $key , $value , 'fr_FR' );
2021-06-07 10:16:09 +02:00
}
2023-04-14 10:11:13 +02:00
// Version en langue étrangère ou fr_FR sans site de test
} else {
// En_EN par défaut si le contenu localisé n'est pas traduit
$langDefault = $lang ;
if ( ! isset ( init :: $defaultDataI18n [ $lang ])) {
$langDefault = 'default' ;
}
2023-05-03 19:47:37 +02:00
file_put_contents ( self :: DATA_DIR . $lang . '/' . $module . '.json' , json_encode ([ $module => init :: $defaultDataI18n [ $langDefault ][ $module ]], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT ));
2023-04-14 10:11:13 +02:00
// Créer la page d'accueil
$pageId = init :: $defaultDataI18n [ $langDefault ][ 'locale' ][ 'homePageId' ];
$content = init :: $defaultDataI18n [ $langDefault ][ 'html' ];
file_put_contents ( self :: DATA_DIR . $lang . '/content/' . init :: $defaultDataI18n [ $langDefault ][ 'page' ][ $pageId ][ 'content' ], $content );
2023-04-14 07:32:23 +02:00
}
2023-04-14 10:11:13 +02:00
} else {
// Installation des données du module
2023-05-03 19:47:37 +02:00
file_put_contents ( self :: DATA_DIR . $module . '.json' , json_encode ([ $module => init :: $defaultData [ $module ]], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT ));
2021-06-07 10:16:09 +02:00
}
2023-04-14 10:11:13 +02:00
2021-06-07 10:16:09 +02:00
}
2023-03-26 09:31:42 +02:00
2021-06-07 10:16:09 +02:00
/**
* Accède à la liste des pages parents et de leurs enfants
* @ param int $parentId Id de la page parent
* @ param bool $onlyVisible Affiche seulement les pages visibles
* @ param bool $onlyBlock Affiche seulement les pages de type barre
* @ return array
*/
2022-09-29 08:45:59 +02:00
public function getHierarchy ( $parentId = null , $onlyVisible = true , $onlyBlock = false )
{
2021-06-07 10:16:09 +02:00
$hierarchy = $onlyVisible ? $this -> hierarchy [ 'visible' ] : $this -> hierarchy [ 'all' ];
$hierarchy = $onlyBlock ? $this -> hierarchy [ 'bar' ] : $hierarchy ;
// Enfants d'un parent
2022-09-29 08:45:59 +02:00
if ( $parentId ) {
if ( array_key_exists ( $parentId , $hierarchy )) {
2021-06-07 10:16:09 +02:00
return $hierarchy [ $parentId ];
2022-09-29 08:45:59 +02:00
} else {
2021-06-07 10:16:09 +02:00
return [];
}
}
// Parents et leurs enfants
else {
return $hierarchy ;
}
}
2023-03-26 09:31:42 +02:00
/**
* Fonction pour construire le tableau des pages
* Appelée par le core uniquement
*/
private function buildHierarchy ()
{
$pages = helper :: arrayColumn ( $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 ] = [];
}
$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 ] = [];
}
$this -> hierarchy [ 'all' ][ $parentId ][] = $pageId ;
}
}
}
2023-03-28 13:12:47 +02:00
/**
2023-03-26 09:31:42 +02:00
* Génère un fichier json avec la liste des pages
*
*/
private function tinyMcePages ()
{
// 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
if ( $this -> getData ([ 'page' , $parentId , 'block' ]) !== 'bar' ) {
// Boucler sur les enfants et récupérer le tableau children avec la liste des enfants
foreach ( $childIds as $childId ) {
$children [] = [
'title' => ' » ' . html_entity_decode ( $this -> getData ([ 'page' , $childId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $childId
];
}
// Traitement
if ( empty ( $childIds )) {
// Pas d'enfant, uniquement l'entrée du parent
$parents [] = [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $parentId
];
} else {
// Des enfants, on ajoute la page parent en premier
array_unshift ( $children , [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $parentId
]);
// puis on ajoute les enfants au parent
$parents [] = [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'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
];
// Enregistrement : 3 tentatives
for ( $i = 0 ; $i < 3 ; $i ++ ) {
if ( file_put_contents ( 'core/vendor/tinymce/link_list.json' , json_encode ( $parents , JSON_UNESCAPED_UNICODE ), LOCK_EX ) !== false ) {
break ;
}
// Pause de 10 millisecondes
usleep ( 10000 );
}
}
2021-06-07 10:16:09 +02:00
/**
* 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
*/
2022-09-29 08:45:59 +02:00
public function getInput ( $key , $filter = helper :: FILTER_STRING_SHORT , $required = false )
{
2021-06-07 10:16:09 +02:00
// La clef est un tableau
2022-09-29 08:45:59 +02:00
if ( preg_match ( '#\[(.*)\]#' , $key , $secondKey )) {
2021-06-07 10:16:09 +02:00
$firstKey = explode ( '[' , $key )[ 0 ];
$secondKey = $secondKey [ 1 ];
2022-09-29 08:45:59 +02:00
foreach ( $this -> input as $type => $values ) {
2021-06-07 10:16:09 +02:00
// Champ obligatoire
2022-09-29 08:45:59 +02:00
if ( $required ) {
2021-06-07 10:16:09 +02:00
$this -> addRequiredInputNotices ( $key );
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
2022-09-29 08:45:59 +02:00
if (
2021-06-07 10:16:09 +02:00
array_key_exists ( $firstKey , $values )
2022-09-29 08:45:59 +02:00
and array_key_exists ( $secondKey , $values [ $firstKey ])
2021-06-07 10:16:09 +02:00
) {
// Retourne la valeur filtrée
2022-09-29 08:45:59 +02:00
if ( $filter ) {
2021-06-07 10:16:09 +02:00
return helper :: filter ( $this -> input [ $type ][ $firstKey ][ $secondKey ], $filter );
}
// Retourne la valeur
else {
return $this -> input [ $type ][ $firstKey ][ $secondKey ];
}
}
}
}
// La clef est une chaîne
else {
2022-09-29 08:45:59 +02:00
foreach ( $this -> input as $type => $values ) {
2021-06-07 10:16:09 +02:00
// Champ obligatoire
2022-09-29 08:45:59 +02:00
if ( $required ) {
2021-06-07 10:16:09 +02:00
$this -> addRequiredInputNotices ( $key );
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
2022-09-29 08:45:59 +02:00
if ( array_key_exists ( $key , $values )) {
2021-06-07 10:16:09 +02:00
// Retourne la valeur filtrée
2022-09-29 08:45:59 +02:00
if ( $filter ) {
2021-06-07 10:16:09 +02:00
return helper :: filter ( $this -> input [ $type ][ $key ], $filter );
}
// Retourne la valeur
else {
return $this -> input [ $type ][ $key ];
}
}
}
}
// Sinon retourne null
2022-10-05 10:15:35 +02:00
return helper :: filter ( null , $filter );
2021-06-07 10:16:09 +02:00
}
/**
* Accède à une partie l 'url ou à l' url complète
* @ param int $key Clé de l ' url
* @ return string | null
*/
2022-09-29 08:45:59 +02:00
public function getUrl ( $key = null )
{
2021-06-07 10:16:09 +02:00
// Url complète
2022-09-29 08:45:59 +02:00
if ( $key === null ) {
2021-06-07 10:16:09 +02:00
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
*/
2023-05-14 22:38:18 +02:00
public function getUser ( $key , $perm1 = null , $perm2 = null )
2022-09-29 08:45:59 +02:00
{
if ( is_array ( $this -> user ) === false ) {
2021-06-07 10:16:09 +02:00
return false ;
2022-09-29 08:45:59 +02:00
} elseif ( $key === 'id' ) {
2021-06-07 10:16:09 +02:00
return $this -> getInput ( 'ZWII_USER_ID' );
2023-05-14 22:38:18 +02:00
} elseif ( $key === 'permission' ) {
return $this -> getPermission ( $perm1 , $perm2 );
2022-09-29 08:45:59 +02:00
} elseif ( array_key_exists ( $key , $this -> user )) {
2021-06-07 10:16:09 +02:00
return $this -> user [ $key ];
2022-09-29 08:45:59 +02:00
} else {
2021-06-07 10:16:09 +02:00
return false ;
}
}
2023-03-28 14:51:46 +02:00
/**
2023-03-29 14:48:09 +02:00
* Retourne les permission de l ' utilisateur connecté
* @ param int $key Clé de la valeur du groupe
2023-03-28 14:51:46 +02:00
* @ return string | null
2023-04-14 07:32:23 +02:00
*/
public function getPermission ( $key1 , $key2 = null )
{
2023-05-11 19:31:20 +02:00
// User n'existe pas
2023-05-13 23:36:02 +02:00
// if (is_array($this->user) === false) {
// return false;
2023-05-11 19:31:20 +02:00
// Administrateur, toutes les permissions
2023-05-14 22:38:18 +02:00
if ( $this -> getUser ( 'group' ) === self :: GROUP_ADMIN ) {
return true ;
} elseif ( $this -> getUser ( 'group' ) < 1 ) { // Groupe sans autorisation
return false ;
2023-06-12 18:38:41 +02:00
} elseif (
// Groupe avec profil, consultation des autorisations sur deux clés
2023-05-14 22:38:18 +02:00
$key1
2023-05-13 23:36:02 +02:00
&& $key2
&& $this -> user
2023-05-10 16:50:02 +02:00
&& $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ], $key1 ])
&& array_key_exists ( $key2 , $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ], $key1 ]))
) {
return $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ], $key1 , $key2 ]);
2023-05-14 22:38:18 +02:00
// Groupe avec profil, consultation des autorisations sur une seule clé
2023-05-10 16:50:02 +02:00
} elseif (
2023-05-13 23:36:02 +02:00
$key1
&& $this -> user
&& $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ]])
2023-05-10 16:50:02 +02:00
&& array_key_exists ( $key1 , $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ]]))
) {
return $this -> getData ([ 'profil' , $this -> user [ 'group' ], $this -> user [ 'profil' ], $key1 ]);
2023-03-28 14:51:46 +02:00
} else {
2023-05-14 22:38:18 +02:00
// Une permission non spécifiée dans le profil est autorisée par défaut pour le fonctionnement de $action
2023-05-11 19:31:20 +02:00
return true ;
2023-03-28 14:51:46 +02:00
}
2023-05-10 16:50:02 +02:00
2023-03-28 14:51:46 +02:00
}
2021-06-07 10:16:09 +02:00
/**
* Check qu ' une valeur est transmise par la méthode _POST
* @ return bool
*/
2022-09-29 08:45:59 +02:00
public function isPost ()
{
return ( $this -> checkCSRF () and $this -> input [ '_POST' ] !== []);
2021-06-07 10:16:09 +02: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
*/
2022-09-29 08:45:59 +02:00
public function dataPath ( $id , $lang )
{
2021-06-07 10:16:09 +02:00
// Sauf pour les pages et les modules
2022-09-29 08:45:59 +02:00
if (
$id === 'page' ||
2023-02-02 21:00:03 +01:00
$id === 'module' ||
2022-09-29 08:45:59 +02:00
$id === 'locale'
) {
$folder = self :: DATA_DIR . $lang . '/' ;
2021-06-07 10:16:09 +02:00
} else {
$folder = self :: DATA_DIR ;
}
return ( $folder );
}
/**
* Génère un fichier un fichier sitemap . xml
* https :// github . com / icamys / php - sitemap - generator
* all : génère un site map complet
* Sinon contient id de la page à créer
2023-03-26 09:31:42 +02:00
* @ param string Valeurs possibles
2022-09-29 08:45:59 +02:00
*/
2021-06-07 10:16:09 +02:00
2023-03-26 09:31:42 +02:00
public function updateSitemap ()
2022-09-29 08:45:59 +02:00
{
2021-06-07 10:16:09 +02:00
2023-03-26 09:31:42 +02:00
// Rafraîchit la liste des pages après une modification de pageId notamment
$this -> buildHierarchy ();
// Actualise la liste des pages pour TinyMCE
$this -> tinyMcePages ();
2023-06-12 18:15:46 +02:00
//require_once "core/vendor/sitemap/SitemapGenerator.php";
2022-05-05 18:19:56 +02:00
2022-09-29 08:45:59 +02:00
$timezone = $this -> getData ([ 'config' , 'timezone' ]);
2021-06-07 10:16:09 +02:00
$outputDir = getcwd ();
2022-09-29 08:45:59 +02:00
$sitemap = new \Icamys\SitemapGenerator\SitemapGenerator ( helper :: baseurl ( false ), $outputDir );
2021-06-07 10:16:09 +02:00
2021-08-08 07:01:19 +02:00
// will create also compressed (gzipped) sitemap : option buguée
// $sitemap->enableCompression();
2021-06-07 10:16:09 +02:00
// 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 -> setMaxUrlsPerSitemap ( 50000 );
// sitemap file name
2022-09-29 08:45:59 +02:00
$sitemap -> setSitemapFileName ( 'sitemap.xml' );
2021-06-07 10:16:09 +02:00
// Set the sitemap index file name
2022-09-29 08:45:59 +02:00
$sitemap -> setSitemapIndexFileName ( 'sitemap-index.xml' );
2021-06-07 10:16:09 +02:00
$datetime = new DateTime ( date ( 'c' ));
$datetime -> format ( DateTime :: ATOM ); // Updated ISO8601
2022-09-29 08:45:59 +02:00
foreach ( $this -> getHierarchy ( null , null , null ) as $parentPageId => $childrenPageIds ) {
2021-06-07 10:16:09 +02:00
// Exclure les barres et les pages non publiques et les pages masquées
2022-09-29 08:45:59 +02:00
if (
2023-02-02 21:00:03 +01:00
$this -> getData ([ 'page' , $parentPageId , 'group' ]) !== 0 ||
2022-09-29 08:45:59 +02:00
$this -> getData ([ 'page' , $parentPageId , 'block' ]) === 'bar'
) {
2021-06-07 10:16:09 +02:00
continue ;
}
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
2022-09-29 08:45:59 +02:00
if ( $this -> getData ([ 'page' , $parentPageId , 'disable' ]) !== true ) {
2021-12-09 18:28:37 +01:00
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ( $parentPageId !== $this -> getData ([ 'locale' , 'homePageId' ])) ? $parentPageId : '' ;
2022-09-29 08:45:59 +02:00
$sitemap -> addUrl ( '/' . $pageId , $datetime );
2021-06-07 10:16:09 +02:00
}
// Articles du blog
2022-09-29 08:45:59 +02:00
if (
$this -> getData ([ 'page' , $parentPageId , 'moduleId' ]) === 'blog' &&
! empty ( $this -> getData ([ 'module' , $parentPageId ]))
) {
foreach ( $this -> getData ([ 'module' , $parentPageId , 'posts' ]) as $articleId => $article ) {
if ( $this -> getData ([ 'module' , $parentPageId , 'posts' , $articleId , 'state' ]) === true ) {
$date = $this -> getData ([ 'module' , $parentPageId , 'posts' , $articleId , 'publishedOn' ]);
2023-02-02 21:00:03 +01:00
$sitemap -> addUrl ( '/' . $parentPageId . '/' . $articleId , new DateTime ( " @ { $date } " , new DateTimeZone ( $timezone )));
2021-06-07 10:16:09 +02:00
}
}
}
// Sous-pages
2022-09-29 08:45:59 +02:00
foreach ( $childrenPageIds as $childKey ) {
if ( $this -> getData ([ 'page' , $childKey , 'group' ]) !== 0 || $this -> getData ([ 'page' , $childKey , 'disable' ]) === true ) {
2021-06-07 10:16:09 +02:00
continue ;
}
2021-12-09 18:28:37 +01:00
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ( $childKey !== $this -> getData ([ 'locale' , 'homePageId' ])) ? $childKey : '' ;
2022-09-29 08:45:59 +02:00
$sitemap -> addUrl ( '/' . $childKey , $datetime );
2021-06-07 10:16:09 +02:00
// La sous-page est un blog
2022-09-29 08:45:59 +02:00
if (
$this -> getData ([ 'page' , $childKey , 'moduleId' ]) === 'blog' &&
! empty ( $this -> getData ([ 'module' , $childKey ]))
) {
foreach ( $this -> getData ([ 'module' , $childKey , 'posts' ]) as $articleId => $article ) {
if ( $this -> getData ([ 'module' , $childKey , 'posts' , $articleId , 'state' ]) === true ) {
$date = $this -> getData ([ 'module' , $childKey , 'posts' , $articleId , 'publishedOn' ]);
$sitemap -> addUrl ( '/' . $childKey . '/' . $articleId , new DateTime ( " @ { $date } " , new DateTimeZone ( $timezone )));
2021-06-07 10:16:09 +02:00
}
}
}
}
}
// Flush all stored urls from memory to the disk and close all necessary tags.
$sitemap -> flush ();
// Move flushed files to their final location. Compress if the option is enabled.
$sitemap -> finalize ();
2021-10-30 18:42:00 +02:00
// Update robots.txt file in output directory
2021-08-10 22:59:29 +02:00
2022-09-29 08:45:59 +02:00
if ( $this -> getData ([ 'config' , 'seo' , 'robots' ]) === true ) {
2022-09-13 10:29:39 +02:00
if ( file_exists ( 'robots.txt' )) {
unlink ( 'robots.txt' );
}
2021-08-08 07:01:19 +02:00
$sitemap -> updateRobots ();
2021-11-03 17:25:26 +01:00
} else {
2023-02-02 21:00:03 +01:00
file_put_contents ( 'robots.txt' , 'User-agent: *' . PHP_EOL . 'Disallow: /' );
2021-08-08 07:01:19 +02:00
}
2021-11-18 11:34:19 +01:00
2021-06-07 10:16:09 +02:00
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com
2022-09-29 08:45:59 +02:00
if ( empty ( $this -> getData ([ 'config' , 'proxyType' ]) . $this -> getData ([ 'config' , 'proxyUrl' ]) . ':' . $this -> getData ([ 'config' , 'proxyPort' ]))) {
2021-06-07 10:16:09 +02:00
$sitemap -> submitSitemap ();
}
2022-09-29 08:45:59 +02:00
return ( file_exists ( 'sitemap.xml' ) && file_exists ( 'robots.txt' ));
2023-03-26 09:31:42 +02:00
2021-06-07 10:16:09 +02:00
}
/*
2023-02-02 21:00:03 +01: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
*/
2022-09-29 08:45:59 +02:00
function makeThumb ( $src , $dest , $desired_width )
{
2021-06-07 10:16:09 +02:00
// Vérifier l'existence du dossier de destination.
$fileInfo = pathinfo ( $dest );
if ( ! is_dir ( $fileInfo [ 'dirname' ])) {
2021-09-29 14:50:25 +02:00
mkdir ( $fileInfo [ 'dirname' ], 0755 , true );
2021-06-07 10:16:09 +02:00
}
2021-11-26 11:36:41 +01:00
$source_image = '' ;
2021-06-07 10:16:09 +02:00
// Type d'image
2022-09-29 08:45:59 +02:00
switch ( $fileInfo [ 'extension' ]) {
2021-06-07 10:16:09 +02:00
case 'jpeg' :
case 'jpg' :
$source_image = imagecreatefromjpeg ( $src );
break ;
case 'png' :
$source_image = imagecreatefrompng ( $src );
break ;
case 'gif' :
$source_image = imagecreatefromgif ( $src );
break ;
2022-10-09 10:50:28 +02:00
case 'webp' :
2022-10-03 18:17:02 +02:00
$source_image = imagecreatefromwebp ( $src );
break ;
2021-06-07 10:16:09 +02:00
}
// Image valide
if ( $source_image ) {
$width = imagesx ( $source_image );
$height = imagesy ( $source_image );
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor ( $height * ( $desired_width / $width ));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor ( $desired_width , $desired_height );
/* copy source image at a resized size */
imagecopyresampled ( $virtual_image , $source_image , 0 , 0 , 0 , 0 , $desired_width , $desired_height , $width , $height );
2022-09-29 08:45:59 +02:00
switch ( mime_content_type ( $src )) {
2021-06-07 10:16:09 +02:00
case 'image/jpeg' :
case 'image/jpg' :
return ( imagejpeg ( $virtual_image , $dest ));
case 'image/png' :
return ( imagepng ( $virtual_image , $dest ));
case 'image/gif' :
return ( imagegif ( $virtual_image , $dest ));
2022-10-09 10:50:28 +02:00
case 'webp' :
2022-10-03 18:17:02 +02:00
$source_image = imagecreatefromwebp ( $src );
2021-06-07 10:16:09 +02:00
}
} else {
return ( false );
}
}
/**
* Envoi un mail
* @ param string | array $to Destinataire
* @ param string $subject Sujet
* @ param string $content Contenu
* @ return bool
*/
2023-02-23 16:02:06 +01:00
public function sendMail ( $to , $subject , $content , $replyTo = null , $from = '' )
2022-09-29 08:45:59 +02:00
{
2021-06-07 10:16:09 +02:00
// Layout
ob_start ();
include 'core/layout/mail.php' ;
$layout = ob_get_clean ();
$mail = new PHPMailer\PHPMailer\PHPMailer ;
2023-02-25 22:45:40 +01:00
$mail -> setLanguage ( substr ( self :: $i18nUI , 0 , 2 ), 'core/class/phpmailer/i18n/' );
2023-03-25 18:24:16 +01:00
$mail -> CharSet = 'UTF-8' ;
$mail -> Encoding = 'base64' ;
2021-06-07 10:16:09 +02:00
// Mail
2022-09-29 08:45:59 +02:00
try {
2023-02-25 22:17:17 +01:00
// Paramètres SMTP perso
2022-09-29 08:45:59 +02:00
if ( $this -> getdata ([ 'config' , 'smtp' , 'enable' ])) {
2023-03-28 13:13:04 +02:00
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_CLIENT;
2021-06-07 10:16:09 +02:00
$mail -> isSMTP ();
$mail -> SMTPAutoTLS = false ;
2023-03-17 13:58:38 +01:00
$mail -> SMTPSecure = false ;
2023-03-26 09:31:42 +02:00
$mail -> SMTPAuth = false ;
2022-09-29 08:45:59 +02:00
$mail -> Host = $this -> getdata ([ 'config' , 'smtp' , 'host' ]);
$mail -> Port = ( int ) $this -> getdata ([ 'config' , 'smtp' , 'port' ]);
if ( $this -> getData ([ 'config' , 'smtp' , 'auth' ])) {
2023-03-17 13:58:38 +01:00
$mail -> SMTPSecure = true ;
2023-03-28 13:12:47 +02:00
$mail -> SMTPAuth = true ;
2022-09-29 08:45:59 +02:00
$mail -> Username = $this -> getData ([ 'config' , 'smtp' , 'username' ]);
2023-03-28 13:12:47 +02:00
$mail -> Password = helper :: decrypt ( $this -> getData ([ 'config' , 'smtp' , 'password' ]), $this -> getData ([ 'config' , 'smtp' , 'host' ]));
switch ( $this -> getData ([ 'config' , 'smtp' , 'secure' ])) {
case 'ssl' :
$mail -> SMTPSecure = PHPMailer\PHPMailer\PHPMailer :: ENCRYPTION_SMTPS ;
break ;
case 'tls' :
$mail -> SMTPSecure = PHPMailer\PHPMailer\PHPMailer :: ENCRYPTION_STARTTLS ;
break ;
default :
break ;
}
2021-06-07 10:16:09 +02:00
}
2023-02-25 22:17:17 +01:00
}
// Expéditeur
$host = str_replace ( 'www.' , '' , $_SERVER [ 'HTTP_HOST' ]);
$from = $from ? $from : 'no-reply@' . $host ;
2023-03-27 11:47:46 +02:00
$mail -> setFrom ( $from , html_entity_decode ( $this -> getData ([ 'locale' , 'title' ])));
2023-02-25 22:17:17 +01:00
// répondre à
if ( is_null ( $replyTo )) {
2023-03-27 11:47:46 +02:00
$mail -> addReplyTo ( $from , html_entity_decode ( $this -> getData ([ 'locale' , 'title' ])));
2021-06-07 10:16:09 +02:00
} else {
2023-02-25 22:17:17 +01:00
$mail -> addReplyTo ( $replyTo );
2021-06-07 10:16:09 +02:00
}
2023-02-25 22:17:17 +01:00
// Destinataires
2022-09-29 08:45:59 +02:00
if ( is_array ( $to )) {
foreach ( $to as $userMail ) {
$mail -> addAddress ( $userMail );
}
} else {
$mail -> addAddress ( $to );
2021-06-07 10:16:09 +02:00
}
$mail -> isHTML ( true );
2023-03-25 18:24:16 +01:00
$mail -> Subject = html_entity_decode ( $subject );
2021-06-07 10:16:09 +02:00
$mail -> Body = $layout ;
$mail -> AltBody = strip_tags ( $content );
2022-09-29 08:45:59 +02:00
if ( $mail -> send ()) {
return true ;
} else {
return $mail -> ErrorInfo ;
2021-06-07 10:16:09 +02:00
}
} catch ( Exception $e ) {
2023-03-28 13:12:47 +02:00
return $mail -> ErrorInfo ;
2021-06-07 10:16:09 +02:00
}
}
/**
2022-09-29 08:45:59 +02:00
* Effacer un dossier non vide .
* @ param string URL du dossier à supprimer
*/
public function removeDir ( $path )
{
foreach ( new DirectoryIterator ( $path ) as $item ) {
2023-02-02 21:00:03 +01:00
if ( $item -> isFile ())
@ unlink ( $item -> getRealPath ());
if ( ! $item -> isDot () && $item -> isDir ())
$this -> removeDir ( $item -> getRealPath ());
2021-06-07 10:16:09 +02:00
}
2022-09-29 08:45:59 +02:00
return ( rmdir ( $path ));
2021-06-07 10:16:09 +02:00
}
/*
2023-02-02 21:00:03 +01:00
* Copie récursive de dossiers
* @ param string $src dossier source
* @ param string $dst dossier destination
* @ return bool
*/
2022-09-29 08:45:59 +02:00
public function copyDir ( $src , $dst )
{
2021-06-07 10:16:09 +02:00
// Ouvrir le dossier source
$dir = opendir ( $src );
// Créer le dossier de destination
if ( ! is_dir ( $dst ))
$success = mkdir ( $dst , 0755 , true );
else
$success = true ;
// Boucler dans le dossier source en l'absence d'échec de lecture écriture
2022-09-29 08:45:59 +02:00
while (
$success
and $file = readdir ( $dir )
) {
2022-05-26 19:57:57 +02:00
2022-09-29 08:45:59 +02:00
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir ( $src . '/' . $file )) {
2021-06-07 10:16:09 +02:00
// Appel récursif des sous-dossiers
2023-02-02 21:00:03 +01:00
$s = $this -> copyDir ( $src . '/' . $file , $dst . '/' . $file );
2022-05-26 19:57:57 +02:00
$success = $s || $success ;
2022-09-29 08:45:59 +02:00
} else {
2022-05-26 19:57:57 +02:00
$s = copy ( $src . '/' . $file , $dst . '/' . $file );
$success = $s || $success ;
2021-06-07 10:16:09 +02:00
}
}
2022-04-08 09:47:35 +02:00
}
2021-06-07 10:16:09 +02:00
return $success ;
}
2022-02-18 12:43:48 +01:00
/**
* Fonction de parcours des données de module
* @ param string $find donnée à rechercher
* @ param string $replace donnée à remplacer
* @ param array tableau à analyser
* @ param int count nombres d ' occurrences
* @ return array avec les valeurs remplacées .
*/
2022-09-29 08:45:59 +02:00
public function recursive_array_replace ( $find , $replace , $array , & $count )
{
2022-02-18 12:43:48 +01:00
if ( ! is_array ( $array )) {
return str_replace ( $find , $replace , $array , $count );
}
$newArray = [];
foreach ( $array as $key => $value ) {
2022-09-29 08:45:59 +02:00
$newArray [ $key ] = $this -> recursive_array_replace ( $find , $replace , $value , $c );
2022-02-18 12:43:48 +01:00
$count += $c ;
}
return $newArray ;
}
2021-06-07 10:16:09 +02:00
/**
* Génère une archive d ' un dossier et des sous - dossiers
* @ param string fileName path et nom de l ' archive
* @ param string folder path à zipper
* @ param array filter dossiers à exclure
*/
2022-09-29 08:45:59 +02:00
public function makeZip ( $fileName , $folder , $filter = [])
{
2021-06-07 10:16:09 +02:00
$zip = new ZipArchive ();
$zip -> open ( $fileName , ZipArchive :: CREATE | ZipArchive :: OVERWRITE );
//$directory = 'site/';
2023-02-02 21:00:03 +01:00
$files = new RecursiveIteratorIterator (
2021-06-07 10:16:09 +02:00
new RecursiveCallbackFilterIterator (
2022-09-29 08:45:59 +02:00
new RecursiveDirectoryIterator (
$folder ,
2023-03-26 09:31:42 +02:00
RecursiveDirectoryIterator :: SKIP_DOTS
2022-09-29 08:45:59 +02:00
),
function ( $fileInfo , $key , $iterator ) use ( $filter ) {
return $fileInfo -> isFile () || ! in_array ( $fileInfo -> getBaseName (), $filter );
}
2021-06-07 10:16:09 +02:00
)
);
2022-09-29 08:45:59 +02:00
foreach ( $files as $name => $file ) {
if ( ! $file -> isDir ()) {
2021-06-07 10:16:09 +02:00
$filePath = $file -> getRealPath ();
$relativePath = substr ( $filePath , strlen ( realpath ( $folder )) + 1 );
2023-01-31 22:52:07 +01:00
$zip -> addFile ( $filePath , str_replace ( " \\ " , " / " , $relativePath ));
2021-06-07 10:16:09 +02:00
}
}
$zip -> close ();
}
2023-04-23 18:51:37 +02:00
/**
* Journalisation
*/
2023-05-10 16:50:02 +02:00
public function saveLog ( $message = '' )
{
2023-04-23 18:51:37 +02:00
// Journalisation
$dataLog = helper :: dateUTF8 ( '%Y %m %d' , time ()) . ' - ' . helper :: dateUTF8 ( '%H:%M' , time ());
$dataLog .= helper :: getIp ( $this -> getData ([ 'config' , 'connect' , 'anonymousIp' ])) . ';' ;
$dataLog .= empty ( $this -> getUser ( 'id' )) ? 'visitor;' : $this -> getUser ( 'id' ) . ';' ;
2023-05-10 16:50:02 +02:00
$dataLog .= $message ? $this -> getUrl () . ';' . $message : $this -> getUrl ();
2023-04-23 18:51:37 +02:00
$dataLog .= PHP_EOL ;
if ( $this -> getData ([ 'config' , 'connect' , 'log' ])) {
file_put_contents ( self :: DATA_DIR . 'journal.log' , $dataLog , FILE_APPEND );
}
}
2023-06-12 18:15:46 +02:00
}
class core extends common
{
/**
* Constructeur du coeur
*/
public function __construct ()
{
parent :: __construct ();
// Token CSRF
if ( empty ( $_SESSION [ 'csrf' ])) {
2023-06-19 19:46:00 +02:00
$_SESSION [ 'csrf' ] = bin2hex ( openssl_random_pseudo_bytes ( 128 ));
2023-06-12 18:15:46 +02:00
}
// 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 ) {
$iterator = new DirectoryIterator ( self :: TEMP_DIR );
foreach ( $iterator as $fileInfos ) {
if (
$fileInfos -> isFile () &&
$fileInfos -> getBasename () !== '.htaccess' &&
$fileInfos -> getBasename () !== '.gitkeep'
) {
@ unlink ( $fileInfos -> getPathname ());
}
}
// Date de la dernière suppression
$this -> setData ([ 'core' , 'lastClearTmp' , $lastClearTmp ]);
// Enregistre les données
//$this->SaveData();
}
// 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' ]);
// Date du dernier backup
$this -> setData ([ 'core' , 'lastBackup' , $lastBackup ]);
// Supprime les backups de plus de 30 jours
$iterator = new DirectoryIterator ( self :: BACKUP_DIR );
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
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 );
}
// Crée le fichier de personnalisation
if ( file_exists ( self :: DATA_DIR . 'theme.css' ) === false ) {
file_put_contents ( self :: DATA_DIR . 'theme.css' , '' );
chmod ( self :: DATA_DIR . 'theme.css' , 0755 );
}
// 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 );
}
// Check la version rafraichissement du theme
$cssVersion = preg_split ( '/\*+/' , file_get_contents ( self :: DATA_DIR . 'theme.css' ));
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
* A partir du CDN
* ou dans le dossier site / file / source / fonts
* ou pas du tout si fonte webSafe
*/
// Fonts disponibles
$fontsAvailable [ 'files' ] = $this -> getData ([ 'font' , 'files' ]);
$fontsAvailable [ 'imported' ] = $this -> getData ([ 'font' , 'imported' ]);
$fontsAvailable [ 'websafe' ] = self :: $fontsWebSafe ;
// Fontes installées
$fonts = [
$this -> getData ([ 'theme' , 'text' , 'font' ]),
$this -> getData ([ 'theme' , 'title' , 'font' ]),
$this -> getData ([ 'theme' , 'header' , 'font' ]),
$this -> getData ([ 'theme' , 'menu' , 'font' ]),
$this -> getData ([ 'theme' , 'footer' , 'font' ])
];
// Suppression des polices identiques
$fonts = array_unique ( $fonts );
/**
* Charge les fontes websafe
*/
$fontFile = '' ;
foreach ( $fonts as $fontId ) {
if ( isset ( $fontsAvailable [ 'websafe' ][ $fontId ])) {
$fonts [ $fontId ] = $fontsAvailable [ 'websafe' ][ $fontId ][ 'font-family' ];
}
}
/**
* Chargement des polices en ligne dans un fichier font . html inclus dans main . php
*/
$fontFile = '' ;
$gf = false ;
foreach ( $fonts as $fontId ) {
if ( isset ( $fontsAvailable [ 'imported' ][ $fontId ])) {
$fontFile .= '<link href="' . $fontsAvailable [ 'imported' ][ $fontId ][ 'resource' ] . '" rel="stylesheet">' ;
// Tableau pour la construction de la feuille de style
$fonts [ $fontId ] = $fontsAvailable [ 'imported' ][ $fontId ][ 'font-family' ];
$gf = strpos ( $fontsAvailable [ 'imported' ][ $fontId ][ 'resource' ], 'fonts.googleapis.com' ) === false ? $gf || false : $gf || true ;
}
}
// Ajoute le préconnect des fontes Googles.
$fontFile = $gf ? '<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . $fontFile
: $fontFile ;
// Enregistre la personnalisation
if ( ! is_dir ( self :: DATA_DIR . 'font' )) {
mkdir ( self :: DATA_DIR . 'font' );
}
file_put_contents ( self :: DATA_DIR . 'font/font.html' , $fontFile );
/**
* Fontes installées localement
*/
foreach ( $fonts as $fontId ) {
// Validité du tableau :
if ( isset ( $fontsAvailable [ 'files' ][ $fontId ])) {
if ( file_exists ( self :: DATA_DIR . 'font/' . $fontId )) {
// Chargement de la police
$css .= '@font-face {font-family:"' . $fontsAvailable [ 'files' ][ $fontId ][ 'font-family' ] . '";' ;
$css .= 'src: url("' . helper :: baseUrl ( false ) . self :: DATA_DIR . 'font/' . $fontsAvailable [ 'files' ][ $fontId ][ 'resource' ] . '");}' ;
// Tableau pour la construction de la feuille de style
$fonts [ $fontId ] = $fontsAvailable [ 'files' ][ $fontId ][ 'font-family' ];
} else {
// Le fichier de font n'est pas disponible, fonte par défaut
$fonts [ $fontId ] = 'verdana' ;
}
}
}
// Fond du body
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'body' , 'backgroundColor' ]));
// Body
$css .= 'body{font-family:' . $fonts [ $this -> getData ([ 'theme' , 'text' , 'font' ])] . ';}' ;
if ( $themeBodyImage = $this -> getData ([ 'theme' , 'body' , 'image' ])) {
// Image dans html pour éviter les déformations.
$css .= 'html {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' ]) . '}' ;
// Couleur du body transparente
$css .= 'body {background-color: rgba(0,0,0,0)}' ;
} else {
// Pas d'image couleur du body
$css .= 'html {background-color:' . $colors [ 'normal' ] . ';}' ;
}
// Icône BacktoTop
$css .= '#backToTop {background-color:' . $this -> getData ([ 'theme' , 'body' , 'toTopbackgroundColor' ]) . ';color:' . $this -> getData ([ 'theme' , 'body' , 'toTopColor' ]) . ';}' ;
// Site
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'text' , 'linkColor' ]));
$css .= 'a{color:' . $colors [ 'normal' ] . '}' ;
// Couleurs de site dans TinyMCe
$css .= 'div.mce-edit-area {font-family:' . $fonts [ $this -> getData ([ 'theme' , 'text' , 'font' ])] . ';}' ;
// Site dans TinyMCE
$css .= '.editorWysiwyg, .editorWysiwygComment {background-color:' . $this -> getData ([ 'theme' , 'site' , 'backgroundColor' ]) . ';}' ;
$css .= 'span.mce-text{background-color: unset !important;}' ;
$css .= 'body,.row > div{font-size:' . $this -> getData ([ 'theme' , 'text' , 'fontSize' ]) . '}' ;
$css .= 'body{color:' . $this -> getData ([ 'theme' , 'text' , 'textColor' ]) . '}' ;
$css .= 'select,input[type=password],input[type=email],input[type=text],input[type=date],input[type=time],input[type=week],input[type=month],input[type=datetime-local],.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' ]) . ';}' ;
// Couleur fixée dans admin.css
$css .= '.container {max-width:' . $this -> getData ([ 'theme' , 'site' , 'width' ]) . '}' ;
$margin = $this -> getData ([ 'theme' , 'site' , 'margin' ]) ? '0' : '20px' ;
// Marge supplémentaire lorsque le pied de page est fixe
if (
$this -> getData ([ 'theme' , 'footer' , 'fixed' ]) === true &&
$this -> getData ([ 'theme' , 'footer' , 'position' ]) === 'body'
) {
$marginBottomLarge = (( str_replace ( 'px' , '' , $this -> getData ([ 'theme' , 'footer' , 'height' ])) * 2 ) + 31 ) . 'px' ;
$marginBottomSmall = (( str_replace ( 'px' , '' , $this -> getData ([ 'theme' , 'footer' , 'height' ])) * 2 ) + 93 ) . 'px' ;
} else {
$marginBottomSmall = $margin ;
$marginBottomLarge = $margin ;
}
$css .= $this -> getData ([ 'theme' , 'site' , 'width' ]) === '100%'
? '@media (min-width: 769px) {#site{margin:0 auto ' . $marginBottomLarge . ' 0 !important;}}@media (max-width: 768px) {#site{margin:0 auto ' . $marginBottomSmall . ' 0 !important;}}#site.light{margin:5% 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;}'
: '@media (min-width: 769px) {#site{margin: ' . $margin . ' auto ' . $marginBottomLarge . ' auto !important;}}@media (max-width: 768px) {#site{margin: ' . $margin . ' auto ' . $marginBottomSmall . ' auto !important;}}#site.light{margin: 5% 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;}'
: '' ;
$css .= '#site{background-color:' . $this -> getData ([ 'theme' , 'site' , 'backgroundColor' ]) . ';border-radius:' . $this -> getData ([ 'theme' , 'site' , 'radius' ]) . ';box-shadow:' . $this -> getData ([ 'theme' , 'site' , 'shadow' ]) . ' #212223;}' ;
$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=date]:hover,input[type=time]:hover,input[type=week]:hover,input[type=month]:hover,input[type=datetime-local]: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' ] . '}' ;
$css .= '.button:active,button[type=submit]:active,.pagination a:active{background-color:' . $colors [ 'veryDarken' ] . '}' ;
$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:' . $fonts [ $this -> getData ([ 'theme' , 'title' , 'font' ])] . ';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' ] . '}' ;
// 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' ] . ';}' ;
// Bannière
// Eléments communs
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}' ;
}
}
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'header' , 'backgroundColor' ]));
$css .= 'header{background-color:' . $colors [ 'normal' ] . ';}' ;
// Bannière de type papier peint
if ( $this -> getData ([ 'theme' , 'header' , 'feature' ]) === 'wallpaper' ) {
$css .= 'header{background-size:' . $this -> getData ([ 'theme' , 'header' , 'imageContainer' ]) . '}' ;
$css .= 'header{background-color:' . $colors [ 'normal' ];
// Valeur de hauteur traditionnelle
$css .= ';height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . ';line-height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]);
$css .= ';text-align:' . $this -> getData ([ 'theme' , 'header' , 'textAlign' ]) . '}' ;
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:' . $fonts [ $this -> getData ([ 'theme' , 'header' , 'font' ])] . ';font-weight:' . $this -> getData ([ 'theme' , 'header' , 'fontWeight' ]) . ';font-size:' . $this -> getData ([ 'theme' , 'header' , 'fontSize' ]) . ';text-transform:' . $this -> getData ([ 'theme' , 'header' , 'textTransform' ]) . '}' ;
}
// Bannière au Contenu HTML
if ( $this -> getData ([ 'theme' , 'header' , 'feature' ]) === 'feature' ) {
// Hauteur de la taille du contenu perso
$css .= 'header {height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . '; min-height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . ';overflow: hidden;}' ;
}
// Menu
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'menu' , 'backgroundColor' ]));
$css .= 'nav,nav.navMain 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 ) {
$css .= 'nav a.active{background-color:' . $colors [ 'veryDarken' ] . '}' ;
} else {
$css .= 'nav a.active{background-color:' . $this -> getData ([ 'theme' , 'menu' , 'activeColor' ]) . '}' ;
}
$css .= 'nav #burgerText{color:' . $colors [ 'text' ] . '}' ;
// Sous menu
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'menu' , 'backgroundColorSub' ]));
$css .= 'nav .navSub a{background-color:' . $colors [ 'normal' ] . '}' ;
$css .= 'nav .navMain a.active {border-radius:' . $this -> getData ([ 'theme' , 'menu' , 'radius' ]) . '}' ;
$css .= '#menu{text-align:' . $this -> getData ([ 'theme' , 'menu' , 'textAlign' ]) . '}' ;
if ( $this -> getData ([ 'theme' , 'menu' , 'margin' ])) {
if (
$this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'site-first'
or $this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'site-second'
) {
$css .= 'nav{padding:10px 10px 0 10px;}' ;
} else {
$css .= 'nav{padding:0 10px}' ;
}
} else {
$css .= 'nav{margin:0}' ;
}
if (
$this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'top'
) {
$css .= 'nav{padding:0 10px;}' ;
}
$css .= '#toggle span,#menu a{padding:' . $this -> getData ([ 'theme' , 'menu' , 'height' ]) . ';font-family:' . $fonts [ $this -> getData ([ 'theme' , 'menu' , 'font' ])] . ';font-weight:' . $this -> getData ([ 'theme' , 'menu' , 'fontWeight' ]) . ';font-size:' . $this -> getData ([ 'theme' , 'menu' , 'fontSize' ]) . ';text-transform:' . $this -> getData ([ 'theme' , 'menu' , 'textTransform' ]) . '}' ;
// Pied de page
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'footer' , 'backgroundColor' ]));
if ( $this -> getData ([ 'theme' , 'footer' , 'margin' ])) {
$css .= 'footer{padding:0 20px;}' ;
} else {
$css .= 'footer{padding:0}' ;
}
$css .= 'footer span, #footerText > p {color:' . $this -> getData ([ 'theme' , 'footer' , 'textColor' ]) . ';font-family:' . $fonts [ $this -> getData ([ 'theme' , 'footer' , 'font' ])] . ';font-weight:' . $this -> getData ([ 'theme' , 'footer' , 'fontWeight' ]) . ';font-size:' . $this -> getData ([ 'theme' , 'footer' , 'fontSize' ]) . ';text-transform:' . $this -> getData ([ 'theme' , 'footer' , 'textTransform' ]) . '}' ;
$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}' ;
$css .= '@media (max-width: 768px) {footer #footerbody > div { padding: 2px }}' ;
$css .= '#footerSocials{text-align:' . $this -> getData ([ 'theme' , 'footer' , 'socialsAlign' ]) . '}' ;
$css .= '#footerText > p {text-align:' . $this -> getData ([ 'theme' , 'footer' , 'textAlign' ]) . '}' ;
$css .= '#footerCopyright{text-align:' . $this -> getData ([ 'theme' , 'footer' , 'copyrightAlign' ]) . '}' ;
// Enregistre les fontes
if ( ! is_dir ( self :: DATA_DIR . 'font' )) {
mkdir ( self :: DATA_DIR . 'font' );
}
file_put_contents ( self :: DATA_DIR . 'font/font.html' , $fontFile );
// Enregistre la personnalisation
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 " );
}
// 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' ]))) . '*/' ;
// Fonts disponibles
$fontsAvailable [ 'files' ] = $this -> getData ([ 'font' , 'files' ]);
$fontsAvailable [ 'imported' ] = $this -> getData ([ 'font' , 'imported' ]);
$fontsAvailable [ 'websafe' ] = self :: $fontsWebSafe ;
/**
* Import des polices de caractères
* A partir du CDN ou dans le dossier site / file / source / fonts
*/
$fonts = [
$this -> getData ([ 'admin' , 'fontText' ]),
$this -> getData ([ 'admin' , 'fontTitle' ]),
];
// Suppression des polices identiques
$fonts = array_unique ( $fonts );
/**
* Charge les fontes websafe
*/
$fontFile = '' ;
foreach ( $fonts as $fontId ) {
if ( isset ( $fontsAvailable [ 'websafe' ][ $fontId ])) {
$fonts [ $fontId ] = $fontsAvailable [ 'websafe' ][ $fontId ][ 'font-family' ];
}
}
/**
* Chargement des polices en ligne dans un fichier font . html inclus dans main . php
*/
$fontFile = '' ;
foreach ( $fonts as $fontId ) {
if ( isset ( $fontsAvailable [ 'imported' ][ $fontId ])) {
$fontFile .= '<link href="' . $fontsAvailable [ 'imported' ][ $fontId ][ 'resource' ] . '" rel="stylesheet">' ;
// Tableau pour la construction de la feuille de style
$fonts [ $fontId ] = $fontsAvailable [ 'imported' ][ $fontId ][ 'font-family' ];
}
}
// Enregistre la personnalisation
file_put_contents ( self :: DATA_DIR . 'font/font.html' , $fontFile );
/**
* Fontes installées localement
*/
foreach ( $fonts as $fontId ) {
// Validité du tableau :
if ( isset ( $fontsAvailable [ 'files' ][ $fontId ])) {
if ( file_exists ( self :: DATA_DIR . 'font/' . $fontId )) {
// Chargement de la police
$css .= '@font-face {font-family:"' . $fontsAvailable [ 'files' ][ $fontId ][ 'font-family' ] . '";' ;
$css .= 'src: url("' . helper :: baseUrl ( false ) . self :: DATA_DIR . 'font/' . $fontsAvailable [ 'files' ][ $fontId ][ 'resource' ] . '");}' ;
// Tableau pour la construction de la feuille de style
$fonts [ $fontId ] = $fontsAvailable [ 'files' ][ $fontId ][ 'font-family' ];
} else {
// Le fichier de font n'est pas disponible, fonte par défaut
$fonts [ $fontId ] = 'verdana' ;
}
}
}
// Thème Administration
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColor' ]));
$css .= '#site{background-color:' . $colors [ 'normal' ] . ';}' ;
$css .= 'p, div, label, select, input, table, span {font-family:' . $fonts [ $this -> getData ([ 'admin' , 'fontText' ])] . '}' ;
$css .= 'body,.row > div {font-size:' . $this -> getData ([ 'admin' , 'fontSize' ]) . '}' ;
$css .= 'body h1, h2, h3, h4 a, h5, h6 {font-family:' . $fonts [ $this -> getData ([ 'admin' , 'fontTitle' ])] . ';color:' . $this -> getData ([ 'admin' , 'colorTitle' ]) . ';}' ;
// TinyMCE
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'colorText' ]));
$css .= 'body:not(.editorWysiwyg), body:not(editorWysiwygComment),span .zwiico-help {color:' . $colors [ 'normal' ] . ';}' ;
$css .= 'table thead tr, table thead tr .zwiico-help{ background-color:' . $colors [ 'normal' ] . '; color:' . $colors [ 'text' ] . ';}' ;
$css .= 'table thead th { color:' . $colors [ 'text' ] . ';}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButton' ]));
$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' , 'backgroundColorButtonHelp' ]));
$css .= '.button.buttonHelp {background-color: ' . $colors [ 'normal' ] . ';color: ' . $colors [ 'text' ] . ';}.button.buttonHelp:hover {background-color:' . $colors [ 'darken' ] . ';color:' . $colors [ 'text' ] . ';}.button.buttonHelp:active {background-color:' . $colors [ 'veryDarken' ] . ';color:' . $colors [ 'text' ] . ';}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButtonGreen' ]));
$css .= '.button.buttonGreen, button[type=submit] {background-color: ' . $colors [ 'normal' ] . ';color: ' . $colors [ 'text' ] . ';}.button.buttonGreen:hover, button[type=submit]:hover {background-color: ' . $colors [ 'darken' ] . ';color: ' . $colors [ 'text' ] . ';}.button.buttonGreen:active, button[type=submit]:active {background-color: ' . $colors [ 'darken' ] . ';color: ' . $colors [ 'text' ] . ';}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundBlockColor' ]));
$css .= '.buttonTab, .block {border: 1px solid ' . $this -> getData ([ 'admin' , 'borderBlockColor' ]) . ';}.buttonTab, .block h4 {background-color: ' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';}' ;
$css .= 'table tr,input[type=email],input[type=date],input[type=time],input[type=month],input[type=week],input[type=datetime-local],input[type=text],input[type=password],select:not(#barSelectLanguage),select:not(#barSelectPage),textarea:not(.editorWysiwyg), textarea:not(.editorWysiwygComment),.inputFile{background-color: ' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';border: 1px solid ' . $this -> getData ([ 'admin' , 'borderBlockColor' ]) . ';}' ;
// 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 );
}
}
/**
* Auto - chargement des classes
* @ param string $className Nom de la classe à charger
*/
public static function autoload ( $className )
{
$classPath = strtolower ( $className ) . '/' . strtolower ( $className ) . '.php' ;
// Module du coeur
if ( is_readable ( 'core/module/' . $classPath )) {
require 'core/module/' . $classPath ;
}
// Module
elseif ( is_readable ( self :: MODULE_DIR . $classPath )) {
require self :: MODULE_DIR . $classPath ;
}
// Librairie
elseif ( is_readable ( 'core/vendor/' . $classPath )) {
require 'core/vendor/' . $classPath ;
}
}
/**
* Routage des modules
*/
public function router ()
{
$layout = new layout ( $this );
// Installation
if (
$this -> getData ([ 'user' ]) === []
and $this -> getUrl ( 0 ) !== 'install'
) {
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'install' );
exit ();
}
// Journalisation
$this -> saveLog ();
// Force la déconnexion des membres bannis ou d'une seconde session
if (
$this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and ( $this -> getUser ( 'group' ) === self :: GROUP_BANNED
or ( $_SESSION [ 'csrf' ] !== $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'accessCsrf' ])
and $this -> getData ([ 'config' , 'connect' , 'autoDisconnect' ]) === true )
)
) {
$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 ();
// Redirection
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'maintenance' );
exit ();
}
// Pour éviter une 404 sur une langue étrangère, bascule dans la langue correcte.
if ( is_null ( $this -> getData ([ 'page' , $this -> getUrl ( 0 )]))) {
foreach ( self :: $languages as $key => $value ) {
if (
is_dir ( self :: DATA_DIR . $key ) &&
file_exists ( self :: DATA_DIR . $key . '/page.json' )
) {
$pagesId = json_decode ( file_get_contents ( self :: DATA_DIR . $key . '/page.json' ), true );
if ( array_key_exists ( $this -> getUrl ( 0 ), $pagesId [ 'page' ])) {
$_SESSION [ 'ZWII_CONTENT' ] = $key ;
header ( 'Refresh:0; url=' . helper :: baseUrl () . $this -> getUrl ( 0 ));
exit ();
}
}
}
}
// Check l'accès à la page
$access = null ;
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 ([ 'locale' , 'homePageId' ])) {
$access = 'login' ;
} else {
$access = false ;
}
}
// Empêcher l'accès aux pages désactivées par URL directe
if (
( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'disable' ]) === true
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
) or ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'disable' ]) === true
and $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) < self :: GROUP_MODERATOR
)
) {
$access = false ;
}
}
/**
* 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
*/
$accessInfo [ 'userName' ] = '' ;
$accessInfo [ 'pageId' ] = '' ;
2023-06-12 21:13:33 +02:00
if ( $this -> getData ([ 'user' ])) {
foreach ( $this -> getData ([ 'user' ]) as $userId => $userIds ) {
if ( ! is_null ( $this -> getData ([ 'user' , $userId , 'accessUrl' ]))) {
$t = explode ( '/' , $this -> getData ([ 'user' , $userId , 'accessUrl' ]));
}
if (
$this -> getUser ( 'id' ) &&
$userId !== $this -> getUser ( 'id' ) &&
$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
) {
$access = false ;
$accessInfo [ 'userName' ] = $this -> getData ([ 'user' , $userId , 'lastname' ]) . ' ' . $this -> getData ([ 'user' , $userId , 'firstname' ]);
$accessInfo [ 'pageId' ] = end ( $t );
}
2023-06-12 18:15:46 +02:00
}
}
// Accès concurrent stocke la page visitée
if (
$this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
&& $this -> getUser ( 'id' )
) {
$this -> setData ([ 'user' , $this -> getUser ( 'id' ), 'accessUrl' , $this -> getUrl ()]);
$this -> setData ([ 'user' , $this -> getUser ( 'id' ), 'accessTimer' , time ()]);
}
// 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' ])
) {
$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> › ' .
$this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'title' ]);
}
// Importe le style de la page principale
$inlineStyle [] = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'css' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'css' ]);
// Importe le script de la page principale
$inlineScript [] = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'js' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'js' ]);
// Importe le contenu, le CSS et le script des barres
$contentRight = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]) ? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), self :: $i18nContent ) : '' ;
$inlineStyle [] = $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'css' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'css' ]);
$inlineScript [] = $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'js' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'js' ]);
$contentLeft = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]) ? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), self :: $i18nContent ) : '' ;
$inlineStyle [] = $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'css' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'css' ]);
$inlineScript [] = $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'js' ]) === null ? '' : $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'js' ]);
// Importe la page simple sans module ou avec un module inexistant
if (
$this -> getData ([ 'page' , $this -> getUrl ( 0 )]) !== null
and ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]) === ''
or ! class_exists ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]))
)
and $access
) {
// Importe le CSS de la page principale
$this -> addOutput ([
'title' => $title ,
'content' => $this -> getPage ( $this -> getUrl ( 0 ), self :: $i18nContent ),
'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' ]),
'disable' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'disable' ]),
'contentRight' => $contentRight ,
'contentLeft' => $contentLeft ,
'inlineStyle' => $inlineStyle ,
'inlineScript' => $inlineScript ,
]);
}
// Importe le module
else {
// Id du module, et valeurs en sortie de la page s'il s'agit d'un module de page
if ( $access and $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ])) {
$moduleId = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]);
// Construit un meta absent
$metaDescription = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]) === 'blog' && ! empty ( $this -> getUrl ( 1 )) && in_array ( $this -> getUrl ( 1 ), $this -> getData ([ 'module' ]))
? strip_tags ( substr ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'content' ]), 0 , 159 ))
: $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'metaDescription' ]);
// Importe le CSS de la page principale
$pageContent = $this -> getPage ( $this -> getUrl ( 0 ), self :: $i18nContent );
$this -> addOutput ([
'title' => $title ,
// Meta description = 160 premiers caractères de l'article
'content' => $pageContent ,
'metaDescription' => $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' ]),
'disable' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'disable' ]),
'contentRight' => $contentRight ,
'contentLeft' => $contentLeft ,
'inlineStyle' => $inlineStyle ,
'inlineScript' => $inlineScript ,
]);
} 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 ;
if ( ! is_null ( $this -> getUrl ( 1 ))) {
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
if (
( $module :: $actions [ $action ] === self :: GROUP_VISITOR
or ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) >= $module :: $actions [ $action ]
and $this -> getUser ( 'permission' , $moduleId , $action )
)
)
and $output [ 'access' ] === true
) {
// Enregistrement du contenu de la méthode POST lorsqu'une notice est présente
if ( common :: $inputNotices ) {
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' ]);
exit ();
}
}
// Données en sortie applicables même lorsqu'une notice est présente
// Affichage
if ( $output [ 'display' ]) {
$this -> addOutput ([
'display' => $output [ 'display' ]
]);
}
// 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 . self :: MODULE_DIR . $moduleId . '/view/' . $output [ 'view' ] . '/' . $output [ 'view' ] . '.css' ;
if ( file_exists ( $stylePath )) {
$this -> addOutput ([
'style' => file_get_contents ( $stylePath )
]);
}
if ( $output [ 'style' ]) {
$this -> addOutput ([
'style' => file_get_contents ( $output [ 'style' ])
]);
}
// JS
$scriptPath = $modulePath . self :: MODULE_DIR . $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 . self :: MODULE_DIR . $moduleId . '/view/' . $output [ 'view' ] . '/' . $output [ 'view' ] . '.php' ;
if ( file_exists ( $viewPath )) {
ob_start ();
include $viewPath ;
$modpos = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'modulePosition' ]);
if ( $modpos === 'top' ) {
$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 ;
$end = substr ( $end , - strlen ( $end ) + $cut );
$this -> addOutput ([
'content' => ( $output [ 'showPageContent' ] ? $begin : '' ) . ob_get_clean () . ( $output [ 'showPageContent' ] ? $end : '' )
]);
} else {
$this -> addOutput ([
'content' => ( $output [ 'showPageContent' ] ? $pageContent : '' ) . ob_get_clean ()
]);
}
}
}
// Librairies
if ( $output [ 'vendor' ] !== $this -> output [ 'vendor' ]) {
$this -> addOutput ([
'vendor' => array_merge ( $this -> output [ 'vendor' ], $output [ 'vendor' ])
]);
}
if ( $output [ 'title' ] !== null ) {
$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 );
if ( $accessInfo [ 'userName' ]) {
$this -> addOutput ([
'title' => 'Accès verrouillé' ,
'content' => template :: speech ( sprintf ( helper :: translate ( 'La page %s est ouverte par l\'utilisateur %s' ), $accessInfo [ 'pageId' ], $accessInfo [ 'userName' ]))
]);
} else {
if (
$this -> getData ([ 'locale' , 'page403' ]) !== 'none'
and $this -> getData ([ 'page' , $this -> getData ([ 'locale' , 'page403' ])])
) {
header ( 'Location:' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'page403' ]));
} else {
$this -> addOutput ([
'title' => 'Accès interdit' ,
'content' => template :: speech ( helper :: translate ( 'Vous n\'êtes pas autorisé à consulter cette page (erreur 403)' ))
]);
}
}
} elseif ( $this -> output [ 'content' ] === '' ) {
http_response_code ( 404 );
if (
$this -> getData ([ 'locale' , 'page404' ]) !== 'none'
and $this -> getData ([ 'page' , $this -> getData ([ 'locale' , 'page404' ])])
) {
header ( 'Location:' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'page404' ]));
} else {
$this -> addOutput ([
'title' => 'Page indisponible' ,
'content' => template :: speech ( helper :: translate ( 'La page demandée n\'existe pas ou est introuvable (erreur 404)' ))
]);
}
}
// Mise en forme des métas
if ( $this -> output [ 'metaTitle' ] === '' ) {
if ( $this -> output [ 'title' ]) {
$this -> addOutput ([
'metaTitle' => strip_tags ( $this -> output [ 'title' ]) . ' - ' . $this -> getData ([ 'locale' , 'title' ])
]);
} else {
$this -> addOutput ([
'metaTitle' => $this -> getData ([ 'locale' , 'title' ])
]);
}
}
if ( $this -> output [ 'metaDescription' ] === '' ) {
$this -> addOutput ([
'metaDescription' => $this -> getData ([ 'locale' , 'metaDescription' ])
]);
}
switch ( $this -> output [ 'display' ]) {
// Layout brut
case self :: DISPLAY_RAW :
echo $this -> output [ 'content' ];
break ;
// 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 ;
// RSS feed
case self :: DISPLAY_RSS :
header ( 'Content-type: application/rss+xml; charset=UTF-8' );
echo $this -> output [ 'content' ];
break ;
// Layout allégé
case self :: DISPLAY_LAYOUT_LIGHT :
ob_start ();
require 'core/layout/light.php' ;
$content = ob_get_clean ();
// Convertit la chaîne en UTF-8 pour conserver les caractères accentués
$content = mb_convert_encoding ( $content , 'UTF-8' , 'UTF-8' );
// Supprime les espaces, les sauts de ligne, les tabulations et autres caractères inutiles
$content = preg_replace ( '/[\t ]+/u' , ' ' , $content );
echo $content ;
break ;
// Layout principal
case self :: DISPLAY_LAYOUT_MAIN :
ob_start ();
require 'core/layout/main.php' ;
$content = ob_get_clean ();
// Convertit la chaîne en UTF-8 pour conserver les caractères accentués
$content = mb_convert_encoding ( $content , 'UTF-8' , 'UTF-8' );
// Supprime les espaces, les sauts de ligne, les tabulations et autres caractères inutiles
$content = preg_replace ( '/[\t ]+/u' , ' ' , $content );
echo $content ;
break ;
}
}
2023-03-28 13:21:16 +02:00
}