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 >
2021-12-18 10:25:33 +01:00
* @ copyright Copyright ( C ) 2018 - 2022 , Frédéric Tempez
2021-06-07 10:16:09 +02:00
* @ license GNU General Public License , version 3
* @ link http :// zwiicms . fr /
*/
2022-10-04 14:06:52 +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 ;
const GROUP_ADMIN = 3 ;
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/' ;
// 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 ;
// Numéro de version
const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/update/raw/branch/master/' ;
2022-11-29 08:45:24 +01:00
const ZWII_VERSION = '11.5.13' ;
2022-02-12 17:10:59 +01:00
const ZWII_UPDATE_CHANNEL = " v11 " ;
2021-06-07 10:16:09 +02:00
public static $actions = [];
public static $coreModuleIds = [
'config' ,
'install' ,
'maintenance' ,
'page' ,
'sitemap' ,
'theme' ,
'user' ,
'translate' ,
2022-02-12 17:10:59 +01:00
'addon'
2021-06-07 10:16:09 +02:00
];
public static $accessList = [
'user' ,
'theme' ,
'config' ,
'edit' ,
2022-04-18 17:18:05 +02:00
'translate' ,
'addon'
2021-06-07 10:16:09 +02:00
];
public static $accessExclude = [
'login' ,
'logout'
];
private $data = [];
private $hierarchy = [
'all' => [],
'visible' => [],
'bar' => []
];
private $input = [
'_COOKIE' => [],
'_POST' => []
];
public static $inputBefore = [];
public static $inputNotices = [];
public static $importNotices = [];
public static $captchaNotices = [];
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' => '' ,
'title' => null , // Null car un titre peut être vide
// Trié par ordre d'exécution
'vendor' => [
'jquery' ,
'normalize' ,
'lity' ,
'filemanager' ,
//'flatpickr', Appelé par les modules désactivé par défaut
// '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'
];
// Langues proposées
public static $i18nList = [
'fr' => 'Français (fr)' ,
'de' => 'Allemand (de)' ,
'en' => 'Anglais (en)' ,
'es' => 'Espagnol (es)' ,
'it' => 'Italien (it)' ,
'nl' => 'Néerlandais (nl)' ,
'pt' => 'Portugais (pt)' ,
];
// Langue courante
public static $i18n ;
public static $timezone ;
private $url = '' ;
// Données de site
private $user = [];
private $core = [];
private $config = [];
// Dossier localisé
private $page = [];
private $module = [];
private $locale = [];
// Descripteur de données Entrées / Sorties
// Liste ici tous les fichiers de données
private $dataFiles = [
2022-02-17 16:58:52 +01:00
'admin' => '' ,
'blacklist' => '' ,
2021-06-07 10:16:09 +02:00
'config' => '' ,
'core' => '' ,
2022-02-17 16:58:52 +01:00
'fonts' => '' ,
'module' => '' ,
'locale' => '' ,
2021-06-07 10:16:09 +02:00
'page' => '' ,
'theme' => '' ,
2022-02-17 16:58:52 +01:00
'user' => ''
2022-03-04 17:59:30 +01:00
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 = [
2022-04-22 09:17:49 +02:00
'arial' => [
2022-03-21 15:35:05 +01:00
'name' => 'Arial' ,
'font-family' => 'Arial, Helvetica, sans-serif' ,
'resource' => 'websafe'
],
2022-10-04 14:06:52 +02:00
'arvo' => [
2022-04-22 15:44:58 +02:00
'name' => 'Arvo' ,
'font-family' => 'Arvo, sans-serif' ,
'resource' => 'websafe'
],
2022-03-21 15:35:05 +01:00
'courrier-new' => [
'name' => 'Courier New' ,
'font-family' => '\'Courier New\', Courier, monospace' ,
'resource' => 'websafe'
],
'garamond' => [
'name' => 'Garamond' ,
'font-family' => 'Garamond, serif' ,
'resource' => 'websafe'
],
'georgia' => [
'name' => 'Geogia' ,
'font-family' => 'Georgia, serif' ,
'resource' => 'websafe'
],
'impact' => [
'name' => 'Impact' ,
'font-family' => 'Impact, Charcoal, sans-serif' ,
'resource' => 'websafe'
],
2022-10-04 14:06:52 +02:00
'lora' => [
2022-04-22 15:44:58 +02:00
'name' => 'Lora' ,
'font-family' => 'Lora, serif' ,
'resource' => 'websafe'
],
2022-03-21 15:35:05 +01:00
'lucida' => [
'name' => 'Lucida' ,
'font-family' => '\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif' ,
'resource' => 'websafe'
],
2022-10-04 14:06:52 +02:00
'roboto' => [
2022-04-22 15:44:58 +02:00
'name' => 'Roboto' ,
'font-family' => 'Roboto, sans-serif' ,
'resource' => 'websafe'
],
2022-03-21 15:35:05 +01:00
'tahoma' => [
'name' => 'Tahoma' ,
'font-family' => 'Tahoma, Geneva, sans-serif' ,
'resource' => 'websafe'
],
'times-new-roman' => [
'name' => 'Times New Roman' ,
'font-family' => '\'Times New Roman\', \'Liberation Serif\', serif' ,
'resource' => 'websafe'
],
'trebuchet' => [
'name' => 'Trebuchet' ,
'font-family' => '\'Trebuchet MS\', Arial, Helvetica, sans-serif' ,
'resource' => 'websafe'
],
'tahoma' => [
'name' => 'Tahoma' ,
'font-family' => 'Tahoma, Geneva, sans-serif' ,
'resource' => 'websafe'
],
'verdana' => [
'name' => 'Verdana' ,
'font-family' => 'Verdana, Geneva, sans-serif;' ,
'resource' => 'websafe'
]
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-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if ( isset ( $_POST )) {
2021-06-07 10:16:09 +02:00
$this -> input [ '_POST' ] = $_POST ;
}
2022-10-04 14:06:52 +02:00
if ( isset ( $_COOKIE )) {
2021-06-07 10:16:09 +02:00
$this -> input [ '_COOKIE' ] = $_COOKIE ;
}
// Déterminer la langue sélectionnée pour le chargement des fichiers de données
2022-10-04 14:06:52 +02:00
if ( isset ( $this -> input [ '_COOKIE' ][ 'ZWII_I18N_SITE' ])) {
2021-06-07 10:16:09 +02:00
self :: $i18n = $this -> input [ '_COOKIE' ][ 'ZWII_I18N_SITE' ];
2022-10-08 17:01:27 +02:00
\setlocale ( LC_TIME , self :: $i18n . '_' . strtoupper ( self :: $i18n ) . '.UTF-8' );
2022-10-04 14:06:52 +02:00
} else {
2021-06-07 10:16:09 +02:00
self :: $i18n = 'fr' ;
2022-10-08 17:01:27 +02:00
\setlocale ( LC_TIME , 'fr_FR.UTF-8' );
2021-06-07 10:16:09 +02:00
}
// Instanciation de la classe des entrées / sorties
// Récupère les descripteurs
foreach ( $this -> dataFiles as $keys => $value ) {
// Constructeur JsonDB
$this -> dataFiles [ $keys ] = new \Prowebcraft\JsonDb ([
'name' => $keys . '.json' ,
2022-10-04 14:06:52 +02:00
'dir' => $this -> dataPath ( $keys , self :: $i18n ),
2021-06-07 10:16:09 +02:00
'backup' => file_exists ( 'site/data/.backup' )
]);;
}
// Import version 9
2022-10-04 14:06:52 +02:00
if (
file_exists ( self :: DATA_DIR . 'core.json' ) === true &&
$this -> getData ([ 'core' , 'dataVersion' ]) < 10000
) {
2021-06-07 10:16:09 +02:00
$keepUsers = isset ( $_SESSION [ 'KEEP_USERS' ]) ? $_SESSION [ 'KEEP_USERS' ] : false ;
$this -> importData ( $keepUsers );
2022-10-04 14:06:52 +02:00
unset ( $_SESSION [ 'KEEP_USERS' ]);
2021-06-07 10:16:09 +02:00
// Réinstaller htaccess
copy ( 'core/module/install/ressource/.htaccess' , self :: DATA_DIR . '.htaccess' );
2022-10-04 14:06:52 +02:00
common :: $importNotices [] = " Importation réalisée avec succès " ;
2021-06-07 10:16:09 +02:00
//echo '<script>window.location.replace("' . helper::baseUrl() . $this->getData(['config','homePageId']) . '")</script>';
}
// Installation fraîche, initialisation des modules manquants
// La langue d'installation par défaut est fr
foreach ( $this -> dataFiles as $stageId => $item ) {
2022-10-04 14:06:52 +02:00
$folder = $this -> dataPath ( $stageId , self :: $i18n );
if (
file_exists ( $folder . $stageId . '.json' ) === false ||
$this -> getData ([ $stageId ]) === NULL
) {
2021-08-21 08:44:37 +02:00
$this -> initData ( $stageId , self :: $i18n );
2022-10-04 14:06:52 +02:00
common :: $coreNotices [] = $stageId ;
2021-06-07 10:16:09 +02:00
}
}
// Utilisateur connecté
2022-10-04 14:06:52 +02:00
if ( $this -> user === []) {
2021-06-07 10:16:09 +02:00
$this -> user = $this -> getData ([ 'user' , $this -> getInput ( 'ZWII_USER_ID' )]);
}
/**
* Traduction du site par script
* Traduction par clic sur le drapeau OU
* Traduction automatisée
* - Exclure la traduction manuelle
* - La mangue du navigateur est lisible
* - L ' auto - détection est active
*/
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'config' , 'i18n' , 'enable' ]) === true
and $this -> getData ([ 'config' , 'i18n' , 'scriptGoogle' ]) === true
and $this -> getData ([ 'config' , 'i18n' , 'autoDetect' ]) === true
and $this -> getInput ( 'ZWII_I18N_SITE' ) !== ''
and ! empty ( $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ])
) {
2021-06-07 10:16:09 +02:00
/**
* Le cookie est prioritaire sur le navigateur
* la traduction est celle de la langue du drapeau
* */
2022-10-04 14:06:52 +02:00
if ( $this -> getInput ( 'ZWII_I18N_SCRIPT' ) !== substr ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ], 0 , 2 )) {
setrawcookie ( 'googtrans' , '/fr/' . substr ( $_SERVER [ " HTTP_ACCEPT_LANGUAGE " ], 0 , 2 ), time () + 3600 , helper :: baseUrl ( false , false ));
2021-11-29 17:29:59 +01:00
} else {
// Langue du drapeau si elle est définie
2022-10-04 14:06:52 +02:00
if ( $this -> getInput ( 'ZWII_I18N_SCRIPT' ) !== '' ) {
2021-11-29 17:29:59 +01:00
// Paramètre du script
2022-10-04 14:06:52 +02:00
setrawcookie ( " googtrans " , '/fr/' . $this -> getInput ( 'ZWII_I18N_SCRIPT' ), time () + 3600 , helper :: baseUrl ( false , false ));
2021-11-29 17:29:59 +01:00
}
2021-06-07 10:16:09 +02:00
}
}
// Construit la liste des pages parents/enfants
2022-10-04 14:06:52 +02:00
if ( $this -> hierarchy [ 'all' ] === []) {
2022-04-06 09:38:58 +02:00
$pages = helper :: arrayCollumn ( $this -> getData ([ 'page' ]), 'position' , 'SORT_ASC' );
2021-06-07 10:16:09 +02:00
// Parents
2022-10-04 14:06:52 +02:00
foreach ( $pages as $pageId => $pagePosition ) {
if (
2021-06-07 10:16:09 +02:00
// Page parent
$this -> getData ([ 'page' , $pageId , 'parentPageId' ]) === " "
// Ignore les pages dont l'utilisateur n'a pas accès
2022-10-04 14:06:52 +02:00
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' ])
2021-06-07 10:16:09 +02:00
)
)
) {
2022-10-04 14:06:52 +02:00
if ( $pagePosition !== 0 ) {
2021-06-07 10:16:09 +02:00
$this -> hierarchy [ 'visible' ][ $pageId ] = [];
}
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $pageId , 'block' ]) === 'bar' ) {
2021-06-07 10:16:09 +02:00
$this -> hierarchy [ 'bar' ][ $pageId ] = [];
}
$this -> hierarchy [ 'all' ][ $pageId ] = [];
}
}
// Enfants
2022-10-04 14:06:52 +02:00
foreach ( $pages as $pageId => $pagePosition ) {
if (
2021-06-07 10:16:09 +02:00
// Page parent
$parentId = $this -> getData ([ 'page' , $pageId , 'parentPageId' ])
// Ignore les pages dont l'utilisateur n'a pas accès
2022-10-04 14:06:52 +02:00
and (
( $this -> getData ([ 'page' , $pageId , 'group' ]) === self :: GROUP_VISITOR
and $this -> getData ([ 'page' , $parentId , 'group' ]) === self :: GROUP_VISITOR
2021-06-07 10:16:09 +02:00
)
2022-10-04 14:06:52 +02:00
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' ])
2021-06-07 10:16:09 +02:00
)
)
) {
2022-10-04 14:06:52 +02:00
if ( $pagePosition !== 0 ) {
2021-06-07 10:16:09 +02:00
$this -> hierarchy [ 'visible' ][ $parentId ][] = $pageId ;
}
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $pageId , 'block' ]) === 'bar' ) {
2021-06-07 10:16:09 +02:00
$this -> hierarchy [ 'bar' ][ $pageId ] = [];
}
$this -> hierarchy [ 'all' ][ $parentId ][] = $pageId ;
}
}
}
// Construit l'url
2022-10-04 14:06:52 +02:00
if ( $this -> url === '' ) {
if ( $url = $_SERVER [ 'QUERY_STRING' ]) {
2021-06-07 10:16:09 +02:00
$this -> url = $url ;
2022-10-04 14:06:52 +02:00
} else {
2021-06-07 10:16:09 +02:00
$this -> url = $this -> getData ([ 'locale' , 'homePageId' ]);
}
}
// Mise à jour des données core
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'core' , 'dataVersion' ]) !== intval ( str_replace ( '.' , '' , self :: ZWII_VERSION ))) include ( 'core/include/update.inc.php' );
2021-06-07 10:16:09 +02:00
// Données de proxy
2022-10-04 14:06:52 +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 ,
'verify_peer' => false ,
'verify_peer_name' => false ,
),
2022-10-04 14:06:52 +02:00
" ssl " => array (
" verify_peer " => false ,
" verify_peer_name " => false
2021-06-07 10:16:09 +02:00
)
);
stream_context_set_default ( $context );
}
}
/**
* Ajoute les valeurs en sortie
* @ param array $output Valeurs en sortie
*/
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
public function addRequiredInputNotices ( $key )
{
2021-06-07 10:16:09 +02:00
// La clef est un tableau
2022-10-04 14:06:52 +02:00
if ( preg_match ( '#\[(.*)\]#' , $key , $secondKey )) {
2021-06-07 10:16:09 +02:00
$firstKey = explode ( '[' , $key )[ 0 ];
$secondKey = $secondKey [ 1 ];
2022-10-04 14:06:52 +02:00
if ( empty ( $this -> input [ '_POST' ][ $firstKey ][ $secondKey ])) {
2021-06-07 10:16:09 +02:00
common :: $inputNotices [ $firstKey . '_' . $secondKey ] = 'Obligatoire' ;
}
}
// La clef est une chaine
2022-10-04 14:06:52 +02:00
elseif ( empty ( $this -> input [ '_POST' ][ $key ])) {
2021-06-07 10:16:09 +02:00
common :: $inputNotices [ $key ] = 'Obligatoire' ;
}
}
/**
* Check du token CSRF ( true = bo
*/
2022-10-04 14:06:52 +02:00
public function checkCSRF ()
{
return (( empty ( $_POST [ 'csrf' ]) or hash_equals ( $_SESSION [ 'csrf' ], $_POST [ 'csrf' ]) === false ) === false );
2021-06-07 10:16:09 +02:00
}
/**
* Supprime des données
* @ param array $keys Clé ( s ) des données
*/
2022-10-04 14:06:52 +02:00
public function deleteData ( $keys )
{
2021-06-07 10:16:09 +02:00
// Descripteur
$db = $this -> dataFiles [ $keys [ 0 ]];
// Aiguillage
2022-10-04 14:06:52 +02:00
switch ( count ( $keys )) {
2021-06-07 10:16:09 +02:00
case 1 :
$db -> delete ( $keys [ 0 ], true );
break ;
case 2 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 3 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 4 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 5 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 6 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 7 :
2022-10-04 14:06:52 +02:00
$db -> delete ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ] . '.' . $keys [ 6 ], true );
2021-06-07 10:16:09 +02:00
break ;
}
}
/**
* Accède aux données
* @ param array $keys Clé ( s ) des données
* @ return mixed
*/
2022-10-04 14:06:52 +02:00
public function getData ( $keys = [])
{
2021-06-07 10:16:09 +02:00
if ( count ( $keys ) >= 1 ) {
/**
* Lecture directe
2022-10-04 14:06:52 +02:00
*/
2021-06-07 10:16:09 +02:00
$db = $this -> dataFiles [ $keys [ 0 ]];
2022-10-04 14:06:52 +02:00
switch ( count ( $keys )) {
2021-06-07 10:16:09 +02:00
case 1 :
$tempData = $db -> get ( $keys [ 0 ]);
break ;
case 2 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ]);
2021-06-07 10:16:09 +02:00
break ;
case 3 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ]);
2021-06-07 10:16:09 +02:00
break ;
case 4 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ]);
2021-06-07 10:16:09 +02:00
break ;
case 5 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ]);
2021-06-07 10:16:09 +02:00
break ;
case 6 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ]);
2021-06-07 10:16:09 +02:00
break ;
case 7 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ] . '.' . $keys [ 6 ]);
2021-06-07 10:16:09 +02:00
break ;
case 8 :
2022-10-04 14:06:52 +02:00
$tempData = $db -> get ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ] . '.' . $keys [ 6 ] . '.' . $keys [ 7 ]);
2021-06-07 10:16:09 +02:00
break ;
}
return $tempData ;
}
}
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
2021-08-17 08:24:12 +02:00
* @ param return contenu de la page
*/
2022-10-04 14:06:52 +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-10-04 14:06:52 +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
2021-08-21 08:56:08 +02:00
* @ param return nombre d ' octets écrits ou erreur
2021-08-17 08:24:12 +02:00
*/
2022-10-04 14:06:52 +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
}
/**
* Effacer les données de la page
* @ param string pageId
* @ param return statut de l ' effacement
*/
2022-10-04 14:06:52 +02:00
public function deletePage ( $page , $lang )
{
2021-08-17 08:24:12 +02:00
2022-10-04 14:06:52 +02:00
return unlink ( self :: DATA_DIR . $lang . '/content/' . $this -> getData ([ 'page' , $page , 'content' ]));
}
2021-08-17 08:24:12 +02:00
2021-06-07 10:16:09 +02:00
/**
* Sauvegarde des données
* @ param array $keys Clé ( s ) des données
*/
2022-10-04 14:06:52 +02:00
public function setData ( $keys = [])
{
2021-06-07 10:16:09 +02:00
// Pas d'enregistrement lorsqu'une notice est présente ou tableau transmis vide
2022-10-04 14:06:52 +02:00
if (
! empty ( self :: $inputNotices )
or empty ( $keys )
) {
2021-06-07 10:16:09 +02:00
return false ;
}
// Empêcher la sauvegarde d'une donnée nulle.
2022-10-04 14:06:52 +02:00
if ( gettype ( $keys [ count ( $keys ) - 1 ]) === NULL ) {
2021-06-07 10:16:09 +02:00
return false ;
}
// Descripteur
$db = $this -> dataFiles [ $keys [ 0 ]];
// Aiguillage
2022-10-04 14:06:52 +02:00
switch ( count ( $keys )) {
2021-06-07 10:16:09 +02:00
case 2 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ], $keys [ 1 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 3 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ], $keys [ 2 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 4 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ], $keys [ 3 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 5 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ], $keys [ 4 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 6 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ], $keys [ 5 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 7 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ], $keys [ 6 ], true );
2021-06-07 10:16:09 +02:00
break ;
case 8 :
2022-10-04 14:06:52 +02:00
$db -> set ( $keys [ 0 ] . '.' . $keys [ 1 ] . '.' . $keys [ 2 ] . '.' . $keys [ 3 ] . '.' . $keys [ 4 ] . '.' . $keys [ 5 ] . '.' . $keys [ 6 ], $keys [ 7 ], true );
2021-06-07 10:16:09 +02:00
break ;
}
return true ;
}
/**
* Initialisation des données
* @ param array $module : nom du module à générer
* choix valides : core config user theme page module
*/
2022-10-04 14:06:52 +02:00
public function initData ( $module , $lang = 'fr' , $sampleSite = false )
{
2021-06-07 10:16:09 +02:00
// Tableau avec les données vierges
require_once ( 'core/module/install/ressource/defaultdata.php' );
// Stockage dans un sous-dossier localisé
2021-06-18 19:52:08 +02:00
if ( ! file_exists ( self :: DATA_DIR . $lang )) {
2022-10-04 14:06:52 +02:00
mkdir ( self :: DATA_DIR . $lang , 0755 );
2021-06-07 10:16:09 +02:00
}
$db = $this -> dataFiles [ $module ];
if ( $sampleSite === true ) {
2022-10-04 14:06:52 +02:00
$db -> set ( $module , init :: $siteData [ $module ]);
2021-06-07 10:16:09 +02:00
} else {
2022-10-04 14:06:52 +02:00
$db -> set ( $module , init :: $defaultData [ $module ]);
2021-06-07 10:16:09 +02:00
}
$db -> save ;
// Dossier des pages
if ( ! is_dir ( self :: DATA_DIR . $lang . '/content' )) {
2021-09-29 14:50:25 +02:00
mkdir ( self :: DATA_DIR . $lang . '/content' , 0755 );
2021-06-07 10:16:09 +02:00
}
// Créer le jeu de pages du site de test
2022-10-04 14:06:52 +02:00
if ( $module === 'page' ) {
2021-06-07 10:16:09 +02:00
// Site de test ou page simple
if ( $sampleSite === true ) {
2022-10-04 14:06:52 +02:00
foreach ( init :: $siteContent as $key => $value ) {
2021-06-07 10:16:09 +02:00
// Creation du contenu de la page
2022-10-04 14:06:52 +02:00
if ( ! empty ( $this -> getData ([ 'page' , $key , 'content' ]))) {
2021-10-19 19:14:52 +02:00
file_put_contents ( self :: DATA_DIR . $lang . '/content/' . $this -> getData ([ 'page' , $key , 'content' ]), $value );
}
2021-06-07 10:16:09 +02:00
}
} else {
// Créer la page d'accueil
2021-08-21 18:22:31 +02:00
file_put_contents ( self :: DATA_DIR . $lang . '/content/' . 'accueil.html' , '<p>Contenu de votre nouvelle page.</p>' );
2021-06-07 10:16:09 +02:00
}
}
}
/*
* Dummy function
* Compatibilité des modules avec v8 et v9
*/
2022-10-04 14:06:52 +02:00
public function saveData ()
{
2021-06-07 10:16:09 +02:00
return ;
}
/**
* 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-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if ( $parentId ) {
if ( array_key_exists ( $parentId , $hierarchy )) {
2021-06-07 10:16:09 +02:00
return $hierarchy [ $parentId ];
2022-10-04 14:06:52 +02:00
} else {
2021-06-07 10:16:09 +02:00
return [];
}
}
// Parents et leurs enfants
else {
return $hierarchy ;
}
}
/**
* Accède à une valeur des variables http ( ordre de recherche en l ' absence de type : _COOKIE , _POST )
* @ param string $key Clé de la valeur
* @ param int $filter Filtre à appliquer à la valeur
* @ param bool $required Champ requis
* @ return mixed
*/
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if ( preg_match ( '#\[(.*)\]#' , $key , $secondKey )) {
2021-06-07 10:16:09 +02:00
$firstKey = explode ( '[' , $key )[ 0 ];
$secondKey = $secondKey [ 1 ];
2022-10-04 14:06:52 +02:00
foreach ( $this -> input as $type => $values ) {
2021-06-07 10:16:09 +02:00
// Champ obligatoire
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if (
2021-06-07 10:16:09 +02:00
array_key_exists ( $firstKey , $values )
2022-10-04 14:06:52 +02:00
and array_key_exists ( $secondKey , $values [ $firstKey ])
2021-06-07 10:16:09 +02:00
) {
// Retourne la valeur filtrée
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
foreach ( $this -> input as $type => $values ) {
2021-06-07 10:16:09 +02:00
// Champ obligatoire
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if ( array_key_exists ( $key , $values )) {
2021-06-07 10:16:09 +02:00
// Retourne la valeur filtrée
2022-10-04 14:06:52 +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 ];
}
}
}
}
2022-10-05 10:32:21 +02:00
//Sinon retourne null
2022-10-05 09:55:57 +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-10-04 14:06:52 +02:00
public function getUrl ( $key = null )
{
2021-06-07 10:16:09 +02:00
// Url complète
2022-10-04 14:06:52 +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
*/
2022-10-04 14:06:52 +02:00
public function getUser ( $key )
{
if ( is_array ( $this -> user ) === false ) {
2021-06-07 10:16:09 +02:00
return false ;
2022-10-04 14:06:52 +02:00
} elseif ( $key === 'id' ) {
2021-06-07 10:16:09 +02:00
return $this -> getInput ( 'ZWII_USER_ID' );
2022-10-04 14:06:52 +02:00
} elseif ( array_key_exists ( $key , $this -> user )) {
2021-06-07 10:16:09 +02:00
return $this -> user [ $key ];
2022-10-04 14:06:52 +02:00
} else {
2021-06-07 10:16:09 +02:00
return false ;
}
}
/**
* Check qu ' une valeur est transmise par la méthode _POST
* @ return bool
*/
2022-10-04 14:06:52 +02:00
public function isPost ()
{
return ( $this -> checkCSRF () and $this -> input [ '_POST' ] !== []);
2021-06-07 10:16:09 +02:00
}
/**
* Import des données de la version 9
* Convertit un fichier de données data . json puis le renomme
*/
2022-10-04 14:06:52 +02:00
public function importData ( $keepUsers = false )
{
2021-06-07 10:16:09 +02:00
// Trois tentatives de lecture
2022-10-04 14:06:52 +02:00
for ( $i = 0 ; $i < 3 ; $i ++ ) {
$tempData = json_decode ( file_get_contents ( self :: DATA_DIR . 'core.json' ), true );
$tempTheme = json_decode ( file_get_contents ( self :: DATA_DIR . 'theme.json' ), true );
if ( $tempData && $tempTheme ) {
2021-06-07 10:16:09 +02:00
// Backup
2022-10-04 14:06:52 +02:00
rename ( self :: DATA_DIR . 'core.json' , self :: DATA_DIR . 'imported_core.json' );
rename ( self :: DATA_DIR . 'theme.json' , self :: DATA_DIR . 'imported_theme.json' );
2021-06-07 10:16:09 +02:00
break ;
2022-10-04 14:06:52 +02:00
} elseif ( $i === 2 ) {
throw new \ErrorException ( 'Import des données impossible.' );
2021-06-07 10:16:09 +02:00
}
// Pause de 10 millisecondes
usleep ( 10000 );
}
// Dossier de langues
if ( ! file_exists ( self :: DATA_DIR . '/fr' )) {
2022-10-04 14:06:52 +02:00
mkdir ( self :: DATA_DIR . '/fr' , 0755 );
2021-06-07 10:16:09 +02:00
}
// Un seul fichier pour éviter les erreurs de sauvegarde des v9
2022-10-04 14:06:52 +02:00
$tempData = array_merge ( $tempData , $tempTheme );
2021-06-07 10:16:09 +02:00
// Ecriture des données
2022-10-04 14:06:52 +02:00
$this -> setData ([ 'config' , $tempData [ 'config' ]]);
$this -> setData ([ 'core' , $tempData [ 'core' ]]);
$this -> setData ([ 'page' , $tempData [ 'page' ]]);
$this -> setData ([ 'module' , $tempData [ 'module' ]]);
$this -> setData ([ 'theme' , $tempData [ 'theme' ]]);
2021-06-07 10:16:09 +02:00
// Import des users sauvegardés si option active
2022-10-04 14:06:52 +02:00
if (
$keepUsers === false
and $tempData [ 'user' ] !== NULL
) {
$this -> setData ([ 'user' , $tempData [ 'user' ]]);
2021-06-07 10:16:09 +02:00
}
// Nettoyage du fichier de thème pour forcer une régénération
if ( file_exists ( self :: DATA_DIR . '/theme.css' )) { // On ne sait jamais
2022-10-04 14:06:52 +02:00
unlink ( self :: DATA_DIR . '/theme.css' );
2021-06-07 10:16:09 +02:00
}
}
/**
2022-04-16 10:08:59 +02:00
* Génère la liste des pages pour le plugin Link de TinyMCE
2022-10-04 14:06:52 +02:00
*/
public function listPages ()
{
// Sauve la liste des pages pour TinyMCE
2021-06-07 10:16:09 +02:00
$parents = [];
2022-10-04 14:06:52 +02:00
$rewrite = ( helper :: checkRewrite ()) ? '' : '?' ;
// Boucle de recherche des pages actives
foreach ( $this -> getHierarchy ( null , false , false ) as $parentId => $childIds ) {
2021-06-07 10:16:09 +02:00
$children = [];
// Exclure les barres
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $parentId , 'block' ]) !== 'bar' ) {
2021-06-07 10:16:09 +02:00
// Boucler sur les enfants et récupérer le tableau children avec la liste des enfants
2022-10-04 14:06:52 +02:00
foreach ( $childIds as $childId ) {
$children [] = [
'title' => ' » ' . html_entity_decode ( $this -> getData ([ 'page' , $childId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $childId
2021-06-07 10:16:09 +02:00
];
}
// Traitement
if ( empty ( $childIds )) {
// Pas d'enfant, uniquement l'entrée du parent
2022-10-04 14:06:52 +02:00
$parents [] = [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $parentId
2021-06-07 10:16:09 +02:00
];
} else {
// Des enfants, on ajoute la page parent en premier
2022-10-04 14:06:52 +02:00
array_unshift ( $children , [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $parentId
2021-06-07 10:16:09 +02:00
]);
// puis on ajoute les enfants au parent
2022-10-04 14:06:52 +02:00
$parents [] = [
'title' => html_entity_decode ( $this -> getData ([ 'page' , $parentId , 'shortTitle' ]), ENT_QUOTES ),
'value' => $rewrite . $parentId ,
'menu' => $children
2021-06-07 10:16:09 +02:00
];
}
}
}
2022-10-04 14:06:52 +02:00
// Sitemap et Search
$children = [];
$children [] = [
'title' => 'Rechercher dans le site' ,
'value' => $rewrite . 'search'
];
$children [] = [
'title' => 'Plan du site' ,
'value' => $rewrite . 'sitemap'
];
$parents [] = [
'title' => 'Pages spéciales' ,
'value' => '#' ,
'menu' => $children
];
2021-06-07 10:16:09 +02:00
// Enregistrement : 3 tentatives
2022-10-04 14:06:52 +02:00
for ( $i = 0 ; $i < 3 ; $i ++ ) {
if ( file_put_contents ( 'core/vendor/tinymce/link_list.json' , json_encode ( $parents ), LOCK_EX ) !== false ) {
2021-06-07 10:16:09 +02:00
break ;
}
// Pause de 10 millisecondes
usleep ( 10000 );
}
}
/**
* 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-10-04 14:06:52 +02:00
public function dataPath ( $id , $lang )
{
2021-06-07 10:16:09 +02:00
// Sauf pour les pages et les modules
2022-10-04 14:06:52 +02:00
if (
$id === 'page' ||
2021-06-07 10:16:09 +02:00
$id === 'module' ||
2022-10-04 14:06:52 +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
* $command valeurs possible
* all : génère un site map complet
* Sinon contient id de la page à créer
2022-10-04 14:06:52 +02:00
*/
2021-06-07 10:16:09 +02:00
2022-10-04 14:06:52 +02:00
public function createSitemap ( $command = " all " )
{
2021-06-07 10:16:09 +02:00
2022-10-04 14:06:52 +02:00
$timezone = $this -> getData ([ 'config' , 'timezone' ]);
2021-06-07 10:16:09 +02:00
$outputDir = getcwd ();
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
$sitemap -> setSitemapFileName ( 'sitemap.xml' );
2021-06-07 10:16:09 +02:00
// Set the sitemap index file name
2022-10-04 14:06:52 +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-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'page' , $parentPageId , 'group' ]) !== 0 ||
$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-10-04 14:06:52 +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-10-04 14:06:52 +02:00
$sitemap -> addUrl ( '/' . $pageId , $datetime );
2021-06-07 10:16:09 +02:00
}
// Articles du blog
2022-10-04 14:06:52 +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' ]);
$sitemap -> addUrl ( '/' . $parentPageId . '/' . $articleId , new DateTime ( " @ { $date } " , new DateTimeZone ( $timezone )));
2021-06-07 10:16:09 +02:00
}
}
}
// Sous-pages
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
$sitemap -> addUrl ( '/' . $childKey , $datetime );
2021-06-07 10:16:09 +02:00
// La sous-page est un blog
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'config' , 'seo' , 'robots' ]) === true ) {
2021-08-10 22:59:29 +02:00
unlink ( 'robots.txt' );
2021-08-08 07:01:19 +02:00
$sitemap -> updateRobots ();
2021-11-03 17:25:26 +01:00
} else {
2022-10-04 14:06:52 +02: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-10-04 14:06:52 +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-10-04 14:06:52 +02:00
return ( file_exists ( 'sitemap.xml' ) && file_exists ( 'robots.txt' ));
2021-06-07 10:16:09 +02:00
}
/*
* Création d ' une miniature
* Fonction utilisée lors de la mise à jour d ' une version 9 à une version 10
* @ param string $src image source
* @ param string $dets image destination
* @ param integer $desired_width largeur demandée
*/
2022-10-04 14:06:52 +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-10-04 14:06:52 +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-02-13 15:03:34 +01:00
case 'webp' :
$source_image = imagecreatefromwebp ( $src );
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-10-04 14:06:52 +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 ));
break ;
case 'image/png' :
return ( imagepng ( $virtual_image , $dest ));
break ;
case 'image/gif' :
return ( imagegif ( $virtual_image , $dest ));
break ;
2022-02-13 15:03:34 +01:00
case 'image/webp' :
return ( imagewebp ( $virtual_image , $dest ));
break ;
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
*/
2022-10-04 14:06:52 +02:00
public function sendMail ( $to , $subject , $content , $replyTo = null )
{
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 ;
$mail -> CharSet = 'UTF-8' ;
2022-04-18 17:52:14 +02:00
$mail -> setLanguage ( 'fr' , 'core/class/phpmailer/phpmailer.lang-fr.php' );
2021-06-07 10:16:09 +02:00
// Mail
2022-10-04 14:06:52 +02:00
try {
2021-06-07 10:16:09 +02:00
// Paramètres SMTP
2022-10-04 14:06:52 +02:00
if ( $this -> getdata ([ 'config' , 'smtp' , 'enable' ])) {
2021-06-07 10:16:09 +02:00
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
$mail -> isSMTP ();
$mail -> SMTPAutoTLS = false ;
2022-10-04 14:06:52 +02:00
$mail -> Host = $this -> getdata ([ 'config' , 'smtp' , 'host' ]);
$mail -> Port = ( int ) $this -> getdata ([ 'config' , 'smtp' , 'port' ]);
if ( $this -> getData ([ 'config' , 'smtp' , 'auth' ])) {
$mail -> Username = $this -> getData ([ 'config' , 'smtp' , 'username' ]);
$mail -> Password = helper :: decrypt ( $this -> getData ([ 'config' , 'smtp' , 'username' ]), $this -> getData ([ 'config' , 'smtp' , 'password' ]));
$mail -> SMTPAuth = $this -> getData ([ 'config' , 'smtp' , 'auth' ]);
$mail -> SMTPSecure = $this -> getData ([ 'config' , 'smtp' , 'secure' ]);
$mail -> setFrom ( $this -> getData ([ 'config' , 'smtp' , 'username' ]));
2021-06-07 10:16:09 +02:00
if ( is_null ( $replyTo )) {
2022-10-04 14:06:52 +02:00
$mail -> addReplyTo ( $this -> getData ([ 'config' , 'smtp' , 'username' ]));
2021-06-07 10:16:09 +02:00
} else {
$mail -> addReplyTo ( $replyTo );
}
}
2022-10-04 14:06:52 +02:00
// Fin SMTP
2021-06-07 10:16:09 +02:00
} else {
$host = str_replace ( 'www.' , '' , $_SERVER [ 'HTTP_HOST' ]);
$mail -> setFrom ( 'no-reply@' . $host , $this -> getData ([ 'locale' , 'title' ]));
if ( is_null ( $replyTo )) {
$mail -> addReplyTo ( 'no-reply@' . $host , $this -> getData ([ 'locale' , 'title' ]));
} else {
$mail -> addReplyTo ( $replyTo );
}
}
2022-10-04 14:06:52 +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 );
$mail -> Subject = $subject ;
$mail -> Body = $layout ;
$mail -> AltBody = strip_tags ( $content );
2022-10-04 14:06:52 +02:00
if ( $mail -> send ()) {
return true ;
} else {
return $mail -> ErrorInfo ;
2021-06-07 10:16:09 +02:00
}
2022-04-18 17:52:14 +02:00
} catch ( \Exception $e ) {
echo $e -> getMessage ();
2021-06-07 10:16:09 +02:00
}
}
/**
2022-10-04 14:06:52 +02:00
* Effacer un dossier non vide .
* @ param string URL du dossier à supprimer
*/
public function removeDir ( $path )
{
foreach ( new DirectoryIterator ( $path ) as $item ) {
if ( $item -> isFile ()) @ unlink ( $item -> getRealPath ());
if ( ! $item -> isDot () && $item -> isDir ()) $this -> removeDir ( $item -> getRealPath ());
2021-06-07 10:16:09 +02:00
}
2022-10-04 14:06:52 +02:00
return ( rmdir ( $path ));
2021-06-07 10:16:09 +02:00
}
/*
* Copie récursive de dossiers
* @ param string $src dossier source
* @ param string $dst dossier destination
* @ return bool
*/
2022-10-04 14:06:52 +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-10-04 14:06:52 +02:00
while (
$success
and $file = readdir ( $dir )
) {
2022-05-26 19:57:57 +02:00
2022-10-04 14:06:52 +02:00
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir ( $src . '/' . $file )) {
2021-06-07 10:16:09 +02:00
// Appel récursif des sous-dossiers
2022-05-26 19:57:57 +02:00
$s = $this -> copyDir ( $src . '/' . $file , $dst . '/' . $file );
$success = $s || $success ;
2022-10-04 14:06:52 +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
}
}
}
return $success ;
}
/**
* 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-10-04 14:06:52 +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/';
$files = new RecursiveIteratorIterator (
new RecursiveCallbackFilterIterator (
2022-10-04 14:06:52 +02:00
new RecursiveDirectoryIterator (
$folder ,
RecursiveDirectoryIterator :: SKIP_DOTS
),
function ( $fileInfo , $key , $iterator ) use ( $filter ) {
return $fileInfo -> isFile () || ! in_array ( $fileInfo -> getBaseName (), $filter );
}
2021-06-07 10:16:09 +02:00
)
);
2022-10-04 14:06:52 +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 );
$zip -> addFile ( $filePath , $relativePath );
}
}
$zip -> close ();
}
2021-06-14 18:37:45 +02:00
// Layout remplace la classe précédente
2021-06-07 10:16:09 +02:00
/**
2021-06-14 18:37:45 +02:00
* Affiche le script Google Analytics
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showAnalytics ()
{
if (
! empty ( $code = $this -> getData ([ 'config' , 'seo' , 'analyticsId' ])) &&
$this -> getInput ( 'ZWII_COOKIE_GA_CONSENT' ) === 'true'
) {
echo ' <!-- Global site tag ( gtag . js ) - Google Analytics -->
< script async src = " https://www.googletagmanager.com/gtag/js?id=' . $code . ' " ></ script >
2021-11-20 07:48:41 +01:00
< script >
window . dataLayer = window . dataLayer || [];
function gtag (){ dataLayer . push ( arguments );}
gtag ( " js " , new Date ());
2022-10-04 14:06:52 +02:00
gtag ( " config " , " ' . $code . ' " ,{ " anonymize_ip " : true });
2021-11-20 07:48:41 +01:00
</ script > ' ;
2022-10-04 14:06:52 +02:00
}
}
2021-06-14 18:37:45 +02:00
2021-11-18 11:34:19 +01:00
/**
2021-11-29 11:30:54 +01:00
* Affiche le consentement aux cookies
2021-11-18 11:34:19 +01:00
*/
2022-10-04 14:06:52 +02:00
public function showCookies ()
{
2021-11-25 13:40:14 +01:00
2021-11-29 11:30:54 +01:00
// Gestion des cookies intégrée
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'config' , 'cookieConsent' ]) === true ) {
2021-11-29 11:30:54 +01:00
// Détermine si le bloc doit être affiché selon la validité du cookie
// L'URL du serveur faut TRUE
2021-11-28 14:29:22 +01:00
$item = '<div id="cookieConsent"' ;
2021-12-07 10:21:06 +01:00
$item .= $this -> getInput ( 'ZWII_COOKIE_CONSENT' ) !== 'true' ? '>' : ' class="displayNone">' ;
2021-11-28 14:29:22 +01:00
// Bouton de fermeture
2021-11-28 12:07:07 +01:00
$item .= '<div class="cookieClose">' ;
$item .= template :: ico ( 'cancel' );
$item .= '</div>' ;
2021-11-28 14:29:22 +01:00
// Texte de la popup
2022-10-04 14:06:52 +02:00
$item .= '<h3>' . $this -> getData ([ 'locale' , 'cookies' , 'titleLabel' ]) . '</h3>' ;
2022-01-09 10:29:00 +01:00
$item .= '<p>' . $this -> getData ([ 'locale' , 'cookies' , 'mainLabel' ]) . '</p>' ;
2021-11-28 14:29:22 +01:00
// Formulaire de réponse
2022-10-07 17:40:53 +02:00
if (
$this -> getData ([ 'locale' , 'homePageId' ]) === $this -> getUrl ( 0 )
) {
$item .= '<form method="POST" action="' . helper :: baseUrl ( false ) . '" id="cookieForm">' ;
} else {
$item .= '<form method="POST" action="' . helper :: baseUrl ( true ) . $this -> getUrl () . '" id="cookieForm">' ;
}
2021-11-28 12:07:07 +01:00
$analytics = $this -> getData ([ 'config' , 'seo' , 'analyticsId' ]);
2021-12-07 10:21:06 +01:00
$stateCookieGA = $this -> getInput ( 'ZWII_COOKIE_GA_CONSENT' ) === 'true' ? 'checked="checked"' : '' ;
2022-10-04 14:06:52 +02:00
if ( $analytics !== null and $analytics !== '' ) {
2022-01-09 10:29:00 +01:00
$item .= '<p>' . $this -> getData ([ 'locale' , 'cookies' , 'gaLabel' ]) . '</p>' ;
2021-11-28 12:07:07 +01:00
$item .= '<input type="checkbox" id="googleAnalytics" name="googleAnalytics" value="GA" ' . $stateCookieGA . '>' ;
2022-01-09 10:29:00 +01:00
$item .= '<label for="googleAnalytics">' . $this -> getData ([ 'locale' , 'cookies' , 'checkboxGaLabel' ]) . '</label>' ;
2021-11-29 11:30:54 +01:00
}
$item .= '<br><br>' ;
2022-01-09 10:29:00 +01:00
$item .= '<input type="submit" id="cookieConsentConfirm" value="' . $this -> getData ([ 'locale' , 'cookies' , 'buttonValidLabel' ]) . '">' ;
2021-11-28 14:29:22 +01:00
$item .= '</form>' ;
2021-11-29 11:30:54 +01:00
// mentions légales si la page est définie
2021-11-28 14:29:22 +01:00
$legalPage = $this -> getData ([ 'locale' , 'legalPageId' ]);
2022-10-04 14:06:52 +02:00
if ( $legalPage !== 'none' ) {
2022-01-09 10:29:00 +01:00
$item .= '<p><a href="' . helper :: baseUrl () . $legalPage . '">' . $this -> getData ([ 'locale' , 'cookies' , 'linkLegalLabel' ]) . '</a></p>' ;
2021-11-28 14:29:22 +01:00
}
$item .= '</div>' ;
2021-11-28 12:07:07 +01:00
echo $item ;
2021-11-25 13:40:14 +01:00
}
}
2021-11-18 11:34:19 +01:00
2021-10-25 17:51:30 +02:00
/**
* Formate le contenu de la page selon les gabarits
* @ param Page par defaut
*/
2022-10-04 14:06:52 +02:00
public function showSection ()
{
2021-10-25 17:51:30 +02:00
echo '<section>' ;
// Récupérer la config de la page courante
2022-10-04 14:06:52 +02:00
$blocks = is_null ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'block' ])) ? '12' : $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'block' ]);
2022-10-04 10:21:39 +02:00
$blocks = explode ( '-' , $blocks );
2021-10-25 17:51:30 +02:00
// Initialiser
2022-10-04 14:06:52 +02:00
$blockleft = $blockright = " " ;
2021-10-25 17:51:30 +02:00
switch ( sizeof ( $blocks )) {
2022-10-04 14:06:52 +02:00
case 1 : // une colonne
$content = 'col' . $blocks [ 0 ];
2021-10-25 17:51:30 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 2 : // 2 blocs
2021-10-25 17:51:30 +02:00
if ( $blocks [ 0 ] < $blocks [ 1 ]) { // détermine la position de la colonne
2022-10-04 14:06:52 +02:00
$blockleft = 'col' . $blocks [ 0 ];
$content = 'col' . $blocks [ 1 ];
2021-10-25 17:51:30 +02:00
} else {
$content = 'col' . $blocks [ 0 ];
$blockright = 'col' . $blocks [ 1 ];
}
2022-10-04 14:06:52 +02:00
break ;
case 3 : // 3 blocs
$blockleft = 'col' . $blocks [ 0 ];
$content = 'col' . $blocks [ 1 ];
$blockright = 'col' . $blocks [ 2 ];
2021-10-25 17:51:30 +02:00
}
// Page pleine pour la configuration des modules et l'édition des pages sauf l'affichage d'un article de blog
2022-10-04 14:06:52 +02:00
$pattern = [ 'config' , 'edit' , 'add' , 'comment' , 'data' ];
2021-10-25 17:51:30 +02:00
if (( sizeof ( $blocks ) === 1 ||
2022-10-04 14:06:52 +02:00
in_array ( $this -> getUrl ( 1 ), $pattern ))) { // Pleine page en mode configuration
$this -> showContent ();
if ( file_exists ( self :: DATA_DIR . 'body.inc.html' )) {
include ( self :: DATA_DIR . 'body.inc.html' );
}
2021-10-25 17:51:30 +02:00
} else {
echo '<div class="row siteContainer">' ;
2022-10-04 14:06:52 +02:00
/**
* Barre gauche
*/
if ( $blockleft !== " " ) {
echo '<div class="' . $blockleft . '" id="contentLeft"><aside>' ;
// Détermine si le menu est présent
if ( $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'displayMenu' ]) === 'none' ) {
// Pas de menu
echo $this -> output [ 'contentLeft' ];
} else {
// $mark contient 0 le menu est positionné à la fin du contenu
$contentLeft = str_replace ( '[]' , '[MENU]' , $this -> output [ 'contentLeft' ]);
$contentLeft = str_replace ( '[menu]' , '[MENU]' , $contentLeft );
$mark = strrpos ( $contentLeft , '[MENU]' ) !== false ? strrpos ( $contentLeft , '[MENU]' ) : strlen ( $contentLeft );
echo substr ( $contentLeft , 0 , $mark );
echo '<div id="menuSideLeft">' ;
echo $this -> showMenuSide ( $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), 'displayMenu' ]) === 'parents' ? false : true );
echo '</div>' ;
echo substr ( $contentLeft , $mark + 6 , strlen ( $contentLeft ));
2021-10-25 17:51:30 +02:00
}
2022-10-04 14:06:52 +02:00
echo " </aside></div> " ;
}
/**
* Contenu de page
*/
echo '<div class="' . $content . '" id="contentSite">' ;
$this -> showContent ();
echo '</div>' ;
/**
* Barre droite
*/
if ( $blockright !== " " ) {
echo '<div class="' . $blockright . '" id="contentRight"><aside>' ;
// Détermine si le menu est présent
if ( $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'displayMenu' ]) === 'none' ) {
// Pas de menu
echo $this -> output [ 'contentRight' ];
} else {
// $mark contient 0 le menu est positionné à la fin du contenu
$contentRight = str_replace ( '[]' , '[MENU]' , $this -> output [ 'contentRight' ]);
$contentRight = str_replace ( '[menu]' , '[MENU]' , $contentRight );
$mark = strrpos ( $contentRight , '[MENU]' ) !== false ? strrpos ( $contentRight , '[MENU]' ) : strlen ( $contentRight );
echo substr ( $contentRight , 0 , $mark );
echo '<div id="menuSideRight">' ;
echo $this -> showMenuSide ( $this -> getData ([ 'page' , $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), 'displayMenu' ]) === 'parents' ? false : true );
echo '</div>' ;
echo substr ( $contentRight , $mark + 6 , strlen ( $contentRight ));
2021-10-25 17:51:30 +02:00
}
2022-10-04 14:06:52 +02:00
echo '</aside></div>' ;
}
2021-10-25 17:51:30 +02:00
echo '</div>' ;
}
echo '</section>' ;
}
2021-06-14 18:37:45 +02:00
/**
* Affiche le contenu
* @ param Page par défaut
*/
2022-10-04 14:06:52 +02:00
public function showContent ()
{
if (
2021-06-14 18:37:45 +02:00
$this -> output [ 'title' ]
2022-10-04 14:06:52 +02:00
and ( $this -> getData ([ 'page' , $this -> getUrl ( 0 )]) === null
or $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'hideTitle' ]) === false
or $this -> getUrl ( 1 ) === 'config'
2021-06-14 18:37:45 +02:00
)
2021-06-07 10:16:09 +02:00
) {
2021-06-14 18:37:45 +02:00
echo '<h1 id="sectionTitle">' . $this -> output [ 'title' ] . '</h1>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
echo $this -> output [ 'content' ];
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
/**
* Affiche les crédits , conditions requis :
* La traduction est active et le site n ' est pas en français .
* La fonction est activée .
*/
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'config' , 'i18n' , 'enable' ]) === true
and $this -> getData ([ 'config' , 'i18n' , 'scriptGoogle' ]) === true
and $this -> getData ([ 'config' , 'i18n' , 'showCredits' ]) === true
and
// et la traduction n'est pas manuelle
( $this -> getInput ( 'ZWII_I18N_SCRIPT' )
and $this -> getData ([ 'config' , 'i18n' , $this -> getInput ( 'ZWII_I18N_SCRIPT' )]) === 'script'
)
) {
echo '<div id="googTransLogo"><a href="//policies.google.com/terms#toc-content" data-lity><img src="core/module/translate/ressource/googtrans.png" /></a></div>' ;
2021-06-14 18:37:45 +02:00
}
}
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
/**
2021-10-25 17:51:30 +02:00
* Affiche le pied de page
2021-06-14 18:37:45 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showFooter ()
{
2021-10-25 17:51:30 +02:00
// Déterminer la position
$positionFixed = '' ;
if (
$this -> getData ([ 'theme' , 'footer' , 'position' ]) === 'site'
// Affiche toujours le pied de page pour l'édition du thème
2022-10-04 14:06:52 +02:00
or ( $this -> getData ([ 'theme' , 'footer' , 'position' ]) === 'hide'
and $this -> getUrl ( 0 ) === 'theme'
2021-10-25 17:51:30 +02:00
)
2022-10-04 14:06:52 +02:00
) {
$position = 'site' ;
} else {
$position = 'body' ;
if ( $this -> getData ([ 'theme' , 'footer' , 'fixed' ]) === true ) {
$positionFixed = ' footerbodyFixed' ;
}
// Sortir de la division précédente
echo '</div>' ;
2021-06-07 10:16:09 +02:00
}
2021-11-18 11:34:19 +01:00
2021-10-25 17:51:30 +02:00
echo $this -> getData ([ 'theme' , 'footer' , 'position' ]) === 'hide' ? '<footer class="displayNone">' : '<footer>' ;
2022-10-04 14:06:52 +02:00
echo ( $position === 'site' ) ? '<div class="container"><div class="row" id="footersite">' : '<div class="container-large' . $positionFixed . '"><div class="row" id="footerbody">' ;
2021-10-25 17:51:30 +02:00
/**
* Calcule la dimension des blocs selon la configuration
*/
2022-10-04 14:06:52 +02:00
switch ( $this -> getData ([ 'theme' , 'footer' , 'template' ])) {
case '1' :
2021-10-25 17:51:30 +02:00
$class [ 'left' ] = " displayNone " ;
$class [ 'center' ] = " col12 " ;
$class [ 'right' ] = " displayNone " ;
break ;
2022-10-04 14:06:52 +02:00
case '2' :
2021-10-25 17:51:30 +02:00
$class [ 'left' ] = " col6 " ;
$class [ 'center' ] = " displayNone " ;
$class [ 'right' ] = " col6 " ;
break ;
2022-10-04 14:06:52 +02:00
case '3' :
2021-10-25 17:51:30 +02:00
$class [ 'left' ] = " col4 " ;
$class [ 'center' ] = " col4 " ;
$class [ 'right' ] = " col4 " ;
break ;
2022-10-04 14:06:52 +02:00
case '4' :
2021-10-25 17:51:30 +02:00
$class [ 'left' ] = " col12 " ;
$class [ 'center' ] = " col12 " ;
$class [ 'right' ] = " col12 " ;
break ;
2021-06-07 10:16:09 +02:00
}
2021-10-25 17:51:30 +02:00
/**
* Affiche les blocs
*/
echo '<div class="' . $class [ 'left' ] . '" id="footer' . $position . 'Left">' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'footer' , 'textPosition' ]) === 'left' ) {
$this -> showFooterText ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'socialsPosition' ]) === 'left' ) {
$this -> showSocials ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'copyrightPosition' ]) === 'left' ) {
$this -> showCopyright ();
}
2021-10-25 17:51:30 +02:00
echo '</div>' ;
2022-10-04 14:06:52 +02:00
echo '<div class="' . $class [ 'center' ] . '" id="footer' . $position . 'Center">' ;
if ( $this -> getData ([ 'theme' , 'footer' , 'textPosition' ]) === 'center' ) {
$this -> showFooterText ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'socialsPosition' ]) === 'center' ) {
$this -> showSocials ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'copyrightPosition' ]) === 'center' ) {
$this -> showCopyright ();
}
2021-10-25 17:51:30 +02:00
echo '</div>' ;
2022-10-04 14:06:52 +02:00
echo '<div class="' . $class [ 'right' ] . '" id="footer' . $position . 'Right">' ;
if ( $this -> getData ([ 'theme' , 'footer' , 'textPosition' ]) === 'right' ) {
$this -> showFooterText ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'socialsPosition' ]) === 'right' ) {
$this -> showSocials ();
}
if ( $this -> getData ([ 'theme' , 'footer' , 'copyrightPosition' ]) === 'right' ) {
$this -> showCopyright ();
}
2021-10-25 17:51:30 +02:00
echo '</div>' ;
2022-02-10 10:38:46 +01:00
// Fermeture du conteneur
2021-10-25 17:51:30 +02:00
echo '</div></div>' ;
echo '</footer>' ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le texte du footer
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
private function showFooterText ()
{
if ( $footerText = $this -> getData ([ 'theme' , 'footer' , 'text' ]) or $this -> getUrl ( 0 ) === 'theme' ) {
2021-06-14 18:37:45 +02:00
echo '<div id="footerText">' . $footerText . '</div>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
}
2022-10-04 14:06:52 +02:00
/**
* Affiche le copyright
*/
private function showCopyright ()
{
2021-06-14 18:37:45 +02:00
// Ouverture Bloc copyright
$items = '<div id="footerCopyright">' ;
$items .= '<span id="footerFontCopyright">' ;
// Affichage de motorisé par
$items .= '<span id="footerDisplayCopyright" ' ;
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'theme' , 'footer' , 'displayCopyright' ]) === false ? 'class="displayNone"' : '' ;
2021-06-14 18:37:45 +02:00
$items .= '>Motorisé par </span>' ;
// Toujours afficher le nom du CMS
$items .= '<span id="footerZwiiCMS">' ;
2021-12-10 13:40:45 +01:00
$items .= '<a href="https://zwiicms.fr/" onclick="window.open(this.href);return false" >ZwiiCMS</a>' ;
2021-06-14 18:37:45 +02:00
$items .= '</span>' ;
// Affichage du numéro de version
$items .= '<span id="footerDisplayVersion"' ;
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'theme' , 'footer' , 'displayVersion' ]) === false ? ' class="displayNone"' : '' ;
$items .= '><wbr> ' . common :: ZWII_VERSION ;
2021-06-14 18:37:45 +02:00
$items .= '</span>' ;
// Affichage du sitemap
$items .= '<span id="footerDisplaySiteMap"' ;
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'theme' , 'footer' , 'displaySiteMap' ]) === false ? ' class="displayNone"' : '' ;
$label = empty ( $this -> getData ([ 'locale' , 'sitemapPageLabel' ])) ? 'Plan du site' : $this -> getData ([ 'locale' , 'sitemapPageLabel' ]);
2021-12-10 13:40:45 +01:00
$items .= '><wbr> | <a href="' . helper :: baseUrl () . 'sitemap" >' . $label . '</a>' ;
2021-06-14 18:37:45 +02:00
$items .= '</span>' ;
2022-10-04 14:06:52 +02:00
// Affichage du module de recherche
$items .= '<span id="footerDisplaySearch"' ;
$items .= $this -> getData ([ 'theme' , 'footer' , 'displaySearch' ]) === false ? ' class="displayNone" >' : '>' ;
$label = empty ( $this -> getData ([ 'locale' , 'searchPageLabel' ])) ? 'Rechercher' : $this -> getData ([ 'locale' , 'searchPageLabel' ]);
if ( $this -> getData ([ 'locale' , 'searchPageId' ]) !== 'none' ) {
$items .= '<wbr> | <a href="' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'searchPageId' ]) . '" >' . $label . '</a>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
$items .= '</span>' ;
// Affichage des mentions légales
$items .= '<span id="footerDisplayLegal"' ;
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'theme' , 'footer' , 'displayLegal' ]) === false ? ' class="displayNone" >' : '>' ;
$label = empty ( $this -> getData ([ 'locale' , 'legalPageLabel' ])) ? 'Mentions Légales' : $this -> getData ([ 'locale' , 'legalPageLabel' ]);
if ( $this -> getData ([ 'locale' , 'legalPageId' ]) !== 'none' ) {
$items .= '<wbr> | <a href="' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'legalPageId' ]) . '" >' . $label . '</a>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
$items .= '</span>' ;
2021-11-27 08:47:00 +01:00
// Affichage de la gestion des cookies
2021-11-28 14:29:22 +01:00
$items .= '<span id="footerDisplayCookie"' ;
2021-11-30 19:14:06 +01:00
$items .= ( $this -> getData ([ 'config' , 'cookieConsent' ]) === true && $this -> getData ([ 'theme' , 'footer' , 'displayCookie' ]) === true ) ? '>' : ' class="displayNone" >' ;
2022-10-04 14:06:52 +02:00
$label = empty ( $this -> getData ([ 'locale' , 'cookies' , 'cookiesFooterText' ])) ? 'Cookies' : $this -> getData ([ 'locale' , 'cookies' , 'cookiesFooterText' ]);
$items .= '<wbr> | <a href="javascript:void(0)" class="skiptranslate" id="footerLinkCookie">' . $label . '</a>' ;
2021-11-28 14:29:22 +01:00
$items .= '</span>' ;
2021-06-14 18:37:45 +02:00
// Affichage du lien de connexion
2022-10-04 14:06:52 +02:00
if (
( $this -> getData ([ 'theme' , 'footer' , 'loginLink' ])
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
)
or $this -> getUrl ( 0 ) === 'theme'
) {
2021-06-14 18:37:45 +02:00
$items .= '<span id="footerLoginLink" ' .
2022-10-04 14:06:52 +02:00
( $this -> getUrl ( 0 ) === 'theme' ? 'class="displayNone"' : '' ) .
'><wbr> | <a href="' . helper :: baseUrl () . 'user/login/' .
strip_tags ( str_replace ( '/' , '_' , $this -> getUrl ())) .
'" rel="nofollow">' . template :: ico ( 'login' ) . '</a></span>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Affichage de la barre de membre simple
2022-10-04 14:06:52 +02:00
if (
$this -> getUser ( 'group' ) === self :: GROUP_MEMBER
&& $this -> getData ([ 'theme' , 'footer' , 'memberBar' ]) === true
) {
$items .= '<span id="footerDisplayMemberAccount"' ;
$items .= $this -> getData ([ 'theme' , 'footer' , 'displaymemberAccount' ]) === false ? ' class="displayNone"' : '' ;
$items .= '><wbr> | <a href="' . helper :: baseUrl () . 'user/edit/' . $this -> getUser ( 'id' ) . '/' . $_SESSION [ 'csrf' ] . '" >' . template :: ico ( 'user' , 'all' ) . '</a>' ;
if ( $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'files' ]) === true ) $items .= '<wbr><a href="' . helper :: baseUrl ( false ) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file ( self :: DATA_DIR . 'core.json' ) . '" data-lity>' . template :: ico ( 'folder' ) . '</a>' ;
$items .= '<wbr><a id="barLogout" href="' . helper :: baseUrl () . 'user/logout" >' . template :: ico ( 'logout' , 'left' ) . '</a>' ;
$items .= '</span>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Fermeture du bloc copyright
2022-10-04 14:06:52 +02:00
$items .= '</span></div>' ;
echo $items ;
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
/**
* Affiche les réseaux sociaux
*/
2022-10-04 14:06:52 +02:00
private function showSocials ()
{
2021-06-14 18:37:45 +02:00
$socials = '' ;
2022-10-04 14:06:52 +02:00
foreach ( $this -> getData ([ 'config' , 'social' ]) as $socialName => $socialId ) {
switch ( $socialName ) {
2021-06-14 18:37:45 +02:00
case 'facebookId' :
$socialUrl = 'https://www.facebook.com/' ;
$title = 'Facebook' ;
break ;
case 'linkedinId' :
$socialUrl = 'https://fr.linkedin.com/in/' ;
$title = 'Linkedin' ;
break ;
case 'instagramId' :
$socialUrl = 'https://www.instagram.com/' ;
$title = 'Instagram' ;
break ;
case 'pinterestId' :
$socialUrl = 'https://pinterest.com/' ;
$title = 'Pinterest' ;
break ;
case 'twitterId' :
$socialUrl = 'https://twitter.com/' ;
$title = 'Twitter' ;
break ;
case 'youtubeId' :
$socialUrl = 'https://www.youtube.com/channel/' ;
$title = 'Chaîne YouTube' ;
break ;
case 'youtubeUserId' :
$socialUrl = 'https://www.youtube.com/user/' ;
$title = 'YouTube' ;
break ;
case 'githubId' :
$socialUrl = 'https://www.github.com/' ;
$title = 'Github' ;
break ;
default :
$socialUrl = '' ;
}
2022-10-04 14:06:52 +02:00
if ( $socialId !== '' ) {
$socials .= '<a href="' . $socialUrl . $socialId . '" onclick="window.open(this.href);return false" data-tippy-content="' . $title . '">' . template :: ico ( substr ( str_replace ( 'User' , '' , $socialName ), 0 , - 2 )) . '</a>' ;
2021-06-07 10:16:09 +02:00
}
}
2022-10-04 14:06:52 +02:00
if ( $socials !== '' ) {
2021-06-14 18:37:45 +02:00
echo '<div id="footerSocials">' . $socials . '</div>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
}
/**
* Affiche le favicon
*/
2022-10-04 14:06:52 +02:00
public function showFavicon ()
{
2021-06-14 18:37:45 +02:00
// Light scheme
$favicon = $this -> getData ([ 'config' , 'favicon' ]);
2022-10-04 14:06:52 +02:00
if (
$favicon &&
file_exists ( self :: FILE_DIR . 'source/' . $favicon )
) {
echo '<link rel="shortcut icon" media="(prefers-color-scheme:light)" href="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $favicon . '">' ;
2021-06-14 18:37:45 +02:00
} else {
echo '<link rel="shortcut icon" media="(prefers-color-scheme:light)" href="' . helper :: baseUrl ( false ) . 'core/vendor/zwiico/ico/favicon.ico">' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Dark scheme
$faviconDark = $this -> getData ([ 'config' , 'faviconDark' ]);
2022-10-04 14:06:52 +02:00
if (
! empty ( $faviconDark ) &&
file_exists ( self :: FILE_DIR . 'source/' . $faviconDark )
2021-06-07 10:16:09 +02:00
) {
2022-10-04 14:06:52 +02:00
echo '<link rel="shortcut icon" media="(prefers-color-scheme:dark)" href="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $faviconDark . '">' ;
2021-06-14 18:37:45 +02:00
//echo '<script src="https://unpkg.com/favicon-switcher@1.2.2/dist/index.js" crossorigin="anonymous" type="application/javascript"></script>';
2022-04-01 09:32:04 +02:00
echo '<script src="' . helper :: baseUrl ( false ) . 'core/vendor/favicon-switcher/favicon-switcher.js" crossorigin="anonymous"></script>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
/**
* Affiche le menu
*/
2022-10-04 14:06:52 +02:00
public function showMenu ()
{
2021-06-14 18:37:45 +02:00
// Met en forme les items du menu
2022-02-12 16:55:41 +01:00
$itemsLeft = $this -> formatMenu ( false );
// Menu extra
$itemsRight = $this -> formatMenu ( true );
// Lien de connexion
2022-10-04 14:06:52 +02:00
if (
( $this -> getData ([ 'theme' , 'menu' , 'loginLink' ])
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
2022-02-12 16:55:41 +01:00
)
2022-10-04 14:06:52 +02:00
or $this -> getUrl ( 0 ) === 'theme'
2022-02-12 16:55:41 +01:00
) {
$itemsRight .= '<li id="menuLoginLink" ' .
2022-10-04 14:06:52 +02:00
( $this -> getUrl ( 0 ) === 'theme' ? 'class="displayNone"' : '' ) .
'><a href="' . helper :: baseUrl () . 'user/login/' .
strip_tags ( str_replace ( '/' , '_' , $this -> getUrl ())) .
'">' . template :: ico ( 'login' ) . '</a></li>' ;
2022-02-12 16:55:41 +01:00
}
// Commandes pour les membres simples
2022-10-04 14:06:52 +02:00
if (
$this -> getUser ( 'group' ) == self :: GROUP_MEMBER
&& $this -> getData ([ 'theme' , 'menu' , 'memberBar' ]) === true
2022-02-12 16:55:41 +01:00
) {
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'files' ]) === true ) $itemsRight .= '<li><a href="' . helper :: baseUrl ( false ) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file ( self :: DATA_DIR . 'core.json' ) . '" data-tippy-content="Gérer les fichiers" data-lity>' . template :: ico ( 'folder' ) . '</a></li>' ;
$itemsRight .= '<li><a href="' . helper :: baseUrl () . 'user/edit/' . $this -> getUser ( 'id' ) . '/' . $_SESSION [ 'csrf' ] . '" data-tippy-content="Gérer mon compte">' . template :: ico ( 'user' , 'right' ) . '</a></li>' ;
2022-02-12 16:55:41 +01:00
$itemsRight .= '<li><a id="barLogout" href="' . helper :: baseUrl () . 'user/logout" data-tippy-content="Me déconnecter">' . template :: ico ( 'logout' ) . '</a></li>' ;
}
// Retourne les items du menu
echo '<ul class="navMain" id="menuLeft">' . $itemsLeft . '</ul><ul class="navMain" id="menuRight">' . $itemsRight ;
if ( $this -> getData ([ 'config' , 'i18n' , 'enable' ]) === true ) {
echo $this -> showi18n ();
}
echo '</ul>' ;
}
/**
* Cette fonction est appelée par showMenu
* Elle permet de générer le menu selon qu 'il s' agisse du menu principal ou du petit menu
* @ param $menu bool false pour le menu principal , true pour le petit menu
*/
2022-10-04 14:06:52 +02:00
private function formatMenu ( $extra = false )
{
2022-02-12 16:55:41 +01:00
$items = '' ;
2021-06-14 18:37:45 +02:00
$currentPageId = $this -> getData ([ 'page' , $this -> getUrl ( 0 )]) ? $this -> getUrl ( 0 ) : $this -> getUrl ( 2 );
2022-10-04 14:06:52 +02:00
foreach ( $this -> getHierarchy () as $parentPageId => $childrenPageIds ) {
2022-02-12 16:55:41 +01:00
// Menu extra ou standard
if (
// Absence de la position extra, la page est toujours affichée à gauche.
2022-10-04 14:06:52 +02:00
( $this -> getData ([ 'page' , $parentPageId , 'extraPosition' ]) !== NULL || $extra === true )
2022-02-12 16:55:41 +01:00
&&
2022-10-04 14:06:52 +02:00
$this -> getData ([ 'page' , $parentPageId , 'extraPosition' ]) !== $extra
) {
2022-02-12 16:55:41 +01:00
continue ;
}
2021-06-14 18:37:45 +02:00
// Propriétés de l'item
2022-10-04 14:06:52 +02:00
$active = ( $parentPageId === $currentPageId or in_array ( $currentPageId , $childrenPageIds )) ? 'active ' : '' ;
2021-06-14 18:37:45 +02:00
$targetBlank = $this -> getData ([ 'page' , $parentPageId , 'targetBlank' ]) ? ' target="_blank"' : '' ;
// Mise en page de l'item
2022-10-04 14:06:52 +02:00
$items .= '<li id="' . $parentPageId . '">' ;
if (( $this -> getData ([ 'page' , $parentPageId , 'disable' ]) === true
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
) or ( $this -> getData ([ 'page' , $parentPageId , 'disable' ]) === true
and $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) < self :: GROUP_MODERATOR
)
) {
2021-12-09 17:23:15 +01:00
$pageUrl = ( $this -> getData ([ 'locale' , 'homePageId' ]) === $this -> getUrl ( 0 )) ? helper :: baseUrl ( false ) : helper :: baseUrl () . $this -> getUrl ( 0 );
2022-03-01 10:27:27 +01:00
$items .= '<a href="' . $pageUrl . '">' ;
2021-06-14 18:37:45 +02:00
} else {
2021-12-09 17:23:15 +01:00
$pageUrl = ( $this -> getData ([ 'locale' , 'homePageId' ]) === $parentPageId ) ? helper :: baseUrl ( false ) : helper :: baseUrl () . $parentPageId ;
2022-03-01 10:27:27 +01:00
$items .= '<a class="' . $active . '" href="' . $pageUrl . '"' . $targetBlank . '>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
switch ( $this -> getData ([ 'page' , $parentPageId , 'typeMenu' ])) {
2022-10-04 14:06:52 +02:00
case '' :
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
break ;
case 'text' :
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
break ;
case 'icon' :
if ( $this -> getData ([ 'page' , $parentPageId , 'iconUrl' ]) != " " ) {
$items .= '<img alt="' . $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '" src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $this -> getData ([ 'page' , $parentPageId , 'iconUrl' ]) . '" />' ;
} else {
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
}
2021-06-14 18:37:45 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 'icontitle' :
if ( $this -> getData ([ 'page' , $parentPageId , 'iconUrl' ]) != " " ) {
$items .= '<img alt="' . $this -> getData ([ 'page' , $parentPageId , 'titlshortTitlee' ]) . '" src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $this -> getData ([ 'page' , $parentPageId , 'iconUrl' ]) . '" data-tippy-content="' ;
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '"/>' ;
} else {
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
}
break ;
}
2021-06-14 18:37:45 +02:00
// Cas où les pages enfants enfant sont toutes masquées dans le menu
// ne pas afficher de symbole lorsqu'il n'y a rien à afficher
$totalChild = 0 ;
$disableChild = 0 ;
2022-10-04 14:06:52 +02:00
foreach ( $childrenPageIds as $childKey ) {
2021-06-14 18:37:45 +02:00
$totalChild += 1 ;
}
2022-10-04 14:06:52 +02:00
if (
$childrenPageIds && $disableChild !== $totalChild &&
$this -> getdata ([ 'page' , $parentPageId , 'hideMenuChildren' ]) === false
) {
2022-02-12 16:55:41 +01:00
$items .= template :: ico ( 'down' , 'left' );
2021-06-14 18:37:45 +02:00
}
// ------------------------------------------------
2022-02-12 16:55:41 +01:00
$items .= '</a>' ;
2022-10-04 14:06:52 +02:00
if (
$this -> getdata ([ 'page' , $parentPageId , 'hideMenuChildren' ]) === true ||
empty ( $childrenPageIds )
) {
2021-06-14 18:37:45 +02:00
continue ;
}
2022-02-12 16:55:41 +01:00
$items .= '<ul class="navSub">' ;
2022-10-04 14:06:52 +02:00
foreach ( $childrenPageIds as $childKey ) {
2021-06-14 18:37:45 +02:00
// Propriétés de l'item
$active = ( $childKey === $currentPageId ) ? 'active ' : '' ;
$targetBlank = $this -> getData ([ 'page' , $childKey , 'targetBlank' ]) ? ' target="_blank"' : '' ;
// Mise en page du sous-item
2022-10-04 14:06:52 +02:00
$items .= '<li id=' . $childKey . '>' ;
if (( $this -> getData ([ 'page' , $childKey , 'disable' ]) === true
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
) or ( $this -> getData ([ 'page' , $childKey , 'disable' ]) === true
and $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) < self :: GROUP_MODERATOR
)
) {
2021-12-09 17:23:15 +01:00
$pageUrl = ( $this -> getData ([ 'locale' , 'homePageId' ]) === $this -> getUrl ( 0 )) ? helper :: baseUrl ( false ) : helper :: baseUrl () . $this -> getUrl ( 0 );
2022-10-04 14:06:52 +02:00
$items .= '<a href="' . $pageUrl . '">' ;
2021-06-14 18:37:45 +02:00
} else {
2021-12-09 17:23:15 +01:00
$pageUrl = ( $this -> getData ([ 'locale' , 'homePageId' ]) === $childKey ) ? helper :: baseUrl ( false ) : helper :: baseUrl () . $childKey ;
2022-03-01 10:27:27 +01:00
$items .= '<a class="' . $active . ' ' . $parentPageId . '" href="' . $pageUrl . '"' . $targetBlank . '>' ;
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
switch ( $this -> getData ([ 'page' , $childKey , 'typeMenu' ])) {
2022-10-04 14:06:52 +02:00
case '' :
2022-02-12 16:55:41 +01:00
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 'text' :
2022-02-12 16:55:41 +01:00
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 'icon' :
2021-06-14 18:37:45 +02:00
if ( $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) != " " ) {
2022-10-04 14:06:52 +02:00
$items .= '<img alt="' . $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '" src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) . '" />' ;
2021-06-14 18:37:45 +02:00
} else {
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 'icontitle' :
2021-06-14 18:37:45 +02:00
if ( $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) != " " ) {
2022-10-04 14:06:52 +02:00
$items .= '<img alt="' . $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '" src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) . '" data-tippy-content="' ;
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]) . '"/>' ;
2021-06-14 18:37:45 +02:00
} else {
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
break ;
2022-10-04 14:06:52 +02:00
case 'icontext' :
2021-06-14 18:37:45 +02:00
if ( $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) != " " ) {
2022-10-04 14:06:52 +02:00
$items .= '<img alt="' . $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '" src="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/' . $this -> getData ([ 'page' , $childKey , 'iconUrl' ]) . '" />' ;
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
} else {
2022-10-04 14:06:52 +02:00
$items .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
}
break ;
2021-06-07 10:16:09 +02:00
}
2022-02-12 16:55:41 +01:00
$items .= '</a></li>' ;
2021-06-07 10:16:09 +02:00
}
2022-02-12 16:55:41 +01:00
$items .= '</ul>' ;
2021-06-14 18:37:45 +02:00
}
2022-10-04 14:06:52 +02:00
return ( $items );
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
/**
* Générer un menu pour la barre latérale
* Uniquement texte
* @ param onlyChildren n ' affiche les sous - pages de la page actuelle
*/
2022-10-04 14:06:52 +02:00
private function showMenuSide ( $onlyChildren = null )
{
2021-06-14 18:37:45 +02:00
// Met en forme les items du menu
$items = '' ;
// Nom de la page courante
$currentPageId = $this -> getData ([ 'page' , $this -> getUrl ( 0 )]) ? $this -> getUrl ( 0 ) : $this -> getUrl ( 2 );
// Nom de la page parente
2022-10-04 14:06:52 +02:00
$currentParentPageId = $this -> getData ([ 'page' , $currentPageId , 'parentPageId' ]);
2021-06-14 18:37:45 +02:00
// Détermine si on affiche uniquement le parent et les enfants
// Filtre contient le nom de la page parente
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
if ( $onlyChildren === true ) {
if ( empty ( $currentParentPageId )) {
$filterCurrentPageId = $currentPageId ;
} else {
$filterCurrentPageId = $currentParentPageId ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
} else {
$items .= '<ul class="menuSide">' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
2022-10-04 14:06:52 +02:00
foreach ( $this -> getHierarchy () as $parentPageId => $childrenPageIds ) {
2021-06-14 18:37:45 +02:00
// Ne pas afficher les entrées masquées
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $parentPageId , 'hideMenuSide' ]) === true ) {
2021-06-14 18:37:45 +02:00
continue ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Filtre actif et nom de la page parente courante différente, on sort de la boucle
if ( $onlyChildren === true && $parentPageId !== $filterCurrentPageId ) {
continue ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Propriétés de l'item
2022-10-04 14:06:52 +02:00
$active = ( $parentPageId === $currentPageId or in_array ( $currentPageId , $childrenPageIds )) ? ' class="active"' : '' ;
2021-06-14 18:37:45 +02:00
$targetBlank = $this -> getData ([ 'page' , $parentPageId , 'targetBlank' ]) ? ' target="_blank" ' : '' ;
// Mise en page de l'item;
// Ne pas afficher le parent d'une sous-page quand l'option est sélectionnée.
if ( $onlyChildren === false ) {
$items .= '<li class="menuSideChild">' ;
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'page' , $parentPageId , 'disable' ]) === true
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
) {
$items .= '<a href="' . $this -> getUrl ( 1 ) . '">' ;
2021-06-14 18:37:45 +02:00
} else {
2022-10-04 14:06:52 +02:00
$items .= '<a href="' . helper :: baseUrl () . $parentPageId . '"' . $targetBlank . $active . '>' ;
2021-06-14 18:37:45 +02:00
}
2021-11-04 13:55:23 +01:00
$items .= $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
$items .= '</a>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
$itemsChildren = '' ;
2022-10-04 14:06:52 +02:00
foreach ( $childrenPageIds as $childKey ) {
2021-06-14 18:37:45 +02:00
// Passer les entrées masquées
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $childKey , 'hideMenuSide' ]) === true ) {
2021-06-14 18:37:45 +02:00
continue ;
}
// Propriétés de l'item
$active = ( $childKey === $currentPageId ) ? ' class="active"' : '' ;
$targetBlank = $this -> getData ([ 'page' , $childKey , 'targetBlank' ]) ? ' target="_blank"' : '' ;
// Mise en page du sous-item
$itemsChildren .= '<li class="menuSideChild">' ;
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'page' , $childKey , 'disable' ]) === true
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
) {
$itemsChildren .= '<a href="' . $this -> getUrl ( 1 ) . '">' ;
2021-06-14 18:37:45 +02:00
} else {
$itemsChildren .= '<a href="' . helper :: baseUrl () . $childKey . '"' . $targetBlank . $active . '>' ;
}
2021-11-04 13:55:23 +01:00
$itemsChildren .= $this -> getData ([ 'page' , $childKey , 'shortTitle' ]);
2021-06-14 18:37:45 +02:00
$itemsChildren .= '</a></li>' ;
}
// Concatène les items enfants
if ( ! empty ( $itemsChildren )) {
$items .= '<ul class="menuSideChild">' ;
$items .= $itemsChildren ;
$items .= '</ul>' ;
} else {
$items .= '</li>' ;
2021-06-07 10:16:09 +02:00
}
}
2021-06-14 18:37:45 +02:00
if ( $onlyChildren === false ) {
$items .= '</ul>' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Retourne les items du menu
echo $items ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le meta titre
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showMetaTitle ()
{
2021-06-14 18:37:45 +02:00
echo '<title>' . $this -> output [ 'metaTitle' ] . '</title>' ;
echo '<meta property="og:title" content="' . $this -> output [ 'metaTitle' ] . '" />' ;
2022-10-07 17:30:08 +02:00
if (
$this -> getData ([ 'locale' , 'homePageId' ]) === $this -> getUrl ( 0 )
) {
echo '<link rel="canonical" href="' . helper :: baseUrl ( false ) . '" />' ;
} else {
echo '<link rel="canonical" href="' . helper :: baseUrl ( true ) . $this -> getUrl () . '" />' ;
}
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche la meta description
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showMetaDescription ()
{
echo '<meta name="description" content="' . $this -> output [ 'metaDescription' ] . '" />' ;
echo '<meta property="og:description" content="' . $this -> output [ 'metaDescription' ] . '" />' ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le meta type
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showMetaType ()
{
2021-06-14 18:37:45 +02:00
echo '<meta property="og:type" content="website" />' ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche la meta image ( site screenshot )
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showMetaImage ()
{
2022-11-29 08:45:24 +01:00
echo '<meta property="og:image" content="' . helper :: baseUrl ( false ) . self :: FILE_DIR . 'source/screenshot.jpg" />' ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche la notification
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showNotification ()
{
2021-06-14 18:37:45 +02:00
if ( common :: $importNotices ) {
2022-10-04 14:06:52 +02:00
$notification = common :: $importNotices [ 0 ];
2021-06-14 18:37:45 +02:00
$notificationClass = 'notificationSuccess' ;
}
2022-10-04 14:06:52 +02:00
if ( common :: $inputNotices ) {
2021-06-14 18:37:45 +02:00
$notification = 'Impossible de soumettre le formulaire, car il contient des erreurs' ;
$notificationClass = 'notificationError' ;
}
if ( common :: $coreNotices ) {
$notification = 'Données absentes, restauration de <p> | ' ;
foreach ( common :: $coreNotices as $item ) $notification .= $item . ' | ' ;
$notificationClass = 'notificationError' ;
2022-10-04 14:06:52 +02:00
} elseif ( empty ( $_SESSION [ 'ZWII_NOTIFICATION_SUCCESS' ]) === false ) {
2021-06-14 18:37:45 +02:00
$notification = $_SESSION [ 'ZWII_NOTIFICATION_SUCCESS' ];
$notificationClass = 'notificationSuccess' ;
unset ( $_SESSION [ 'ZWII_NOTIFICATION_SUCCESS' ]);
2022-10-04 14:06:52 +02:00
} elseif ( empty ( $_SESSION [ 'ZWII_NOTIFICATION_ERROR' ]) === false ) {
2021-06-14 18:37:45 +02:00
$notification = $_SESSION [ 'ZWII_NOTIFICATION_ERROR' ];
$notificationClass = 'notificationError' ;
unset ( $_SESSION [ 'ZWII_NOTIFICATION_ERROR' ]);
2022-10-04 14:06:52 +02:00
} elseif ( empty ( $_SESSION [ 'ZWII_NOTIFICATION_OTHER' ]) === false ) {
2021-06-14 18:37:45 +02:00
$notification = $_SESSION [ 'ZWII_NOTIFICATION_OTHER' ];
$notificationClass = 'notificationOther' ;
unset ( $_SESSION [ 'ZWII_NOTIFICATION_OTHER' ]);
}
2022-10-04 14:06:52 +02:00
if ( isset ( $notification ) and isset ( $notificationClass )) {
2021-06-14 18:37:45 +02:00
echo '<div id="notification" class="' . $notificationClass . '">' . $notification . '<span id="notificationClose">' . template :: ico ( 'cancel' ) . '<!----></span><div id="notificationProgress"></div></div>' ;
2021-06-07 10:16:09 +02:00
}
}
/**
2021-06-14 18:37:45 +02:00
* Affiche la barre de membre
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showBar ()
{
if ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )) {
2021-06-14 18:37:45 +02:00
// Items de gauche
$leftItems = '' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getUser ( 'group' ) >= self :: GROUP_MODERATOR ) {
2021-06-14 18:37:45 +02:00
$leftItems .= '<li><select id="barSelectPage">' ;
$leftItems .= '<option value="">Choisissez une page</option>' ;
$leftItems .= '<optgroup label="Pages orphelines">' ;
2022-10-04 14:06:52 +02:00
$orpheline = true ;
2021-06-14 18:37:45 +02:00
$currentPageId = $this -> getData ([ 'page' , $this -> getUrl ( 0 )]) ? $this -> getUrl ( 0 ) : $this -> getUrl ( 2 );
2022-10-04 14:06:52 +02:00
foreach ( $this -> getHierarchy ( null , false ) as $parentPageId => $childrenPageIds ) {
if (
$this -> getData ([ 'page' , $parentPageId , 'position' ]) !== 0 &&
$orpheline
) {
$orpheline = false ;
$leftItems .= '<optgroup label="Pages du menu">' ;
2021-06-14 18:37:45 +02:00
}
// Exclure les barres
if ( $this -> getData ([ 'page' , $parentPageId , 'block' ]) !== 'bar' ) {
$leftItems .= '<option value="' .
2022-10-04 14:06:52 +02:00
helper :: baseUrl () .
$parentPageId . '"' .
( $parentPageId === $currentPageId ? ' selected' : false ) .
' class="' .
( $this -> getData ([ 'page' , $parentPageId , 'disable' ]) === true ? 'pageInactive' : '' ) .
( $this -> getData ([ 'page' , $parentPageId , 'position' ]) === 0 ? ' pageHidden' : '' ) .
'">' .
$this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) .
'</option>' ;
foreach ( $childrenPageIds as $childKey ) {
2021-06-14 18:37:45 +02:00
$leftItems .= '<option value="' .
2022-10-04 14:06:52 +02:00
helper :: baseUrl () .
$childKey . '"' .
( $childKey === $currentPageId ? ' selected' : false ) .
' class="' .
( $this -> getData ([ 'page' , $childKey , 'disable' ]) === true ? 'pageInactive' : '' ) .
( $this -> getData ([ 'page' , $childKey , 'position' ]) === 0 ? ' pageHidden' : '' ) .
'"> ' .
$this -> getData ([ 'page' , $childKey , 'shortTitle' ]) .
'</option>' ;
2021-06-14 18:37:45 +02:00
}
}
}
2022-10-04 14:06:52 +02:00
$leftItems .= '</optgroup' >
// Afficher les barres
$leftItems .= '<optgroup label="Barres latérales">' ;
foreach ( $this -> getHierarchy ( null , false , true ) as $parentPageId => $childrenPageIds ) {
2021-11-04 13:55:23 +01:00
$leftItems .= '<option value="' . helper :: baseUrl () . $parentPageId . '"' . ( $parentPageId === $currentPageId ? ' selected' : false ) . '>' . $this -> getData ([ 'page' , $parentPageId , 'shortTitle' ]) . '</option>' ;
2022-10-04 14:06:52 +02:00
foreach ( $childrenPageIds as $childKey ) {
2021-11-04 13:55:23 +01:00
$leftItems .= '<option value="' . helper :: baseUrl () . $childKey . '"' . ( $childKey === $currentPageId ? ' selected' : false ) . '> ' . $this -> getData ([ 'page' , $childKey , 'shortTitle' ]) . '</option>' ;
2021-06-14 18:37:45 +02:00
}
}
$leftItems .= '</optgroup>' ;
$leftItems .= '</select></li>' ;
$leftItems .= '<li><a href="' . helper :: baseUrl () . 'page/add" data-tippy-content="Créer une page ou<br>une barre latérale">' . template :: ico ( 'plus' ) . '</a></li>' ;
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
// Sur un module de page qui autorise le bouton de modification de la page
$this -> output [ 'showBarEditButton' ]
// Sur une page sans module
2022-10-04 14:06:52 +02:00
or $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]) === ''
2022-06-02 14:35:31 +02:00
// Sur une page avec un module invalide
2022-10-04 14:06:52 +02:00
or ( ! is_null ( $this -> getData ([ 'page' , $this -> getUrl ( 2 ), 'moduleId' ])) &&
2022-10-04 10:27:12 +02:00
! class_exists ( $this -> getData ([ 'page' , $this -> getUrl ( 2 ), 'moduleId' ]))
2022-10-04 14:06:52 +02:00
)
2021-06-14 18:37:45 +02:00
// Sur une page d'accueil
2022-10-04 14:06:52 +02:00
or $this -> getUrl ( 0 ) === ''
2021-06-14 18:37:45 +02:00
) {
$leftItems .= '<li><a href="' . helper :: baseUrl () . 'page/edit/' . $this -> getUrl ( 0 ) . '" data-tippy-content="Modifier la page">' . template :: ico ( 'pencil' ) . '</a></li>' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ])) {
2021-06-14 18:37:45 +02:00
$leftItems .= '<li><a href="' . helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' . '" data-tippy-content="Configurer le module">' . template :: ico ( 'gear' ) . '</a></li>' ;
}
$leftItems .= '<li><a id="pageDuplicate" href="' . helper :: baseUrl () . 'page/duplicate/' . $this -> getUrl ( 0 ) . '&csrf=' . $_SESSION [ 'csrf' ] . '" data-tippy-content="Dupliquer la page">' . template :: ico ( 'clone' ) . '</a></li>' ;
$leftItems .= '<li><a id="pageDelete" href="' . helper :: baseUrl () . 'page/delete/' . $this -> getUrl ( 0 ) . '&csrf=' . $_SESSION [ 'csrf' ] . '" data-tippy-content="Effacer la page">' . template :: ico ( 'trash' ) . '</a></li>' ;
}
}
// Items de droite
$rightItems = '' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getUser ( 'group' ) >= self :: GROUP_MODERATOR ) {
$rightItems .= '<li><a href="' . helper :: baseUrl ( false ) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file ( self :: DATA_DIR . 'core.json' ) . '" data-tippy-content="Gérer les fichiers" data-lity>' . template :: ico ( 'folder' ) . '</a></li>' ;
2021-06-14 18:37:45 +02:00
}
2022-10-04 14:06:52 +02:00
if ( $this -> getUser ( 'group' ) >= self :: GROUP_ADMIN ) {
2021-12-10 13:46:00 +01:00
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'theme" data-tippy-content="Personnaliser les thèmes">' . template :: ico ( 'brush' ) . '</a></li>' ;
2022-02-12 17:10:59 +01:00
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'addon" data-tippy-content="Gérer les modules">' . template :: ico ( 'puzzle' ) . '</a></li>' ;
2021-09-29 16:40:25 +02:00
if ( $this -> getData ([ 'config' , 'i18n' , 'enable' ]) === true ) {
2021-06-14 18:37:45 +02:00
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'translate" data-tippy-content="Gestion des langues">' . template :: ico ( 'flag' ) . '</a></li>' ;
}
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'config" data-tippy-content="Configurer le site">' . template :: ico ( 'cog-alt' ) . '</a></li>' ;
2021-12-10 13:46:00 +01:00
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'user" data-tippy-content="Configurer les utilisateurs">' . template :: ico ( 'users' ) . '</a></li>' ;
2022-02-06 17:13:16 +01:00
2021-06-14 18:37:45 +02:00
// Mise à jour automatique
$today = mktime ( 0 , 0 , 0 );
2022-10-04 14:06:52 +02:00
$checkUpdate = ( int ) $this -> getData ([ 'core' , 'lastAutoUpdate' ]);
2022-06-25 16:31:25 +02:00
// Recherche d'une mise à jour si active, si une mise à jour n'est pas déjà disponible et le délais journalier est dépassé.
if (
2022-10-04 14:06:52 +02:00
$this -> getData ([ 'config' , 'autoUpdate' ]) === true
and $this -> getData ([ 'core' , 'updateAvailable' ]) === false
and $today > $checkUpdate + 86400
) {
$this -> setData ([ 'core' , 'updateAvailable' , helper :: checkNewVersion ( common :: ZWII_UPDATE_CHANNEL )]);
2021-06-14 18:37:45 +02:00
}
2022-06-25 16:31:25 +02:00
// Dernier auto controle
2022-10-04 14:06:52 +02:00
$this -> setData ([ 'core' , 'lastAutoUpdate' , $today ]);
2021-06-14 18:37:45 +02:00
// Afficher le bouton : Mise à jour détectée + activée
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'core' , 'updateAvailable' ]) === true &&
$this -> getData ([ 'config' , 'autoUpdate' ]) === true
) {
$rightItems .= '<li><a id="barUpdate" href="' . helper :: baseUrl () . 'install/update" data-tippy-content="Mettre à jour Zwii ' . common :: ZWII_VERSION . ' vers ' . helper :: getOnlineVersion ( common :: ZWII_UPDATE_CHANNEL ) . '">' . template :: ico ( 'update colorRed' ) . '</a></li>' ;
2021-06-14 18:37:45 +02:00
}
}
2022-10-04 14:06:52 +02:00
if ( $this -> getUser ( 'group' ) >= self :: GROUP_MODERATOR ) {
$rightItems .= '<li><a href="' . helper :: baseUrl () . 'user/edit/' . $this -> getUser ( 'id' ) . '/' . $_SESSION [ 'csrf' ] . '" data-tippy-content="Configurer mon compte">' . template :: ico ( 'user' , 'right' ) . '<span id="displayUsername">' . $this -> getUser ( 'firstname' ) . ' ' . $this -> getUser ( 'lastname' ) . '</span></a></li>' ;
2022-02-06 17:13:16 +01:00
}
2021-06-14 18:37:45 +02:00
$rightItems .= '<li><a id="barLogout" href="' . helper :: baseUrl () . 'user/logout" data-tippy-content="Me déconnecter">' . template :: ico ( 'logout' ) . '</a></li>' ;
// Barre de membre
echo '<div id="bar"><div class="container"><ul id="barLeft">' . $leftItems . '</ul><ul id="barRight">' . $rightItems . '</ul></div></div>' ;
2021-06-07 10:16:09 +02:00
}
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le script
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showScript ()
{
2021-06-14 18:37:45 +02:00
ob_start ();
require 'core/core.js.php' ;
$coreScript = ob_get_clean ();
echo '<script>' . helper :: minifyJs ( $coreScript . $this -> output [ 'script' ]) . '</script>' ;
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le style
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showStyle ()
{
2022-03-04 18:00:26 +01:00
// Import des styles liés à la page
2022-10-04 14:06:52 +02:00
if ( $this -> output [ 'style' ]) {
echo '<base href="' . helper :: baseUrl ( true ) . '">' ;
2022-04-21 23:37:57 +02:00
// Import de la feuille de style des pages admin
2022-10-04 14:06:52 +02:00
if ( strpos ( $this -> output [ 'style' ], 'admin.css' ) >= 1 ) {
echo '<link rel="stylesheet" href="' . self :: DATA_DIR . 'admin.css?' . md5_file ( self :: DATA_DIR . 'admin.css' ) . '">' ;
2021-06-14 18:37:45 +02:00
}
echo '<style type="text/css">' . helper :: minifyCss ( $this -> output [ 'style' ]) . '</style>' ;
2021-06-07 10:16:09 +02:00
}
2022-04-22 11:55:01 +02:00
// Import des fontes
2022-10-04 14:06:52 +02:00
if ( file_exists ( self :: DATA_DIR . 'fonts/fonts.html' )) {
2022-04-22 09:17:49 +02:00
include_once ( self :: DATA_DIR . 'fonts/fonts.html' );
}
2022-10-04 14:06:52 +02:00
if ( file_exists ( self :: DATA_DIR . 'fonts/fonts.css' )) {
echo '<link rel="stylesheet" href="' . helper :: baseUrl ( false ) . self :: DATA_DIR . 'fonts/fonts.css?' . md5_file ( self :: DATA_DIR . 'fonts/fonts.css' ) . '">' ;
2022-04-26 18:46:09 +02:00
}
2021-06-07 10:16:09 +02:00
}
/**
2021-06-14 18:37:45 +02:00
* Affiche l ' import des librairies
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showVendor ()
{
2021-06-14 18:37:45 +02:00
// Variables partagées
$vars = 'var baseUrl = ' . json_encode ( helper :: baseUrl ( false )) . ';' ;
$vars .= 'var baseUrlQs = ' . json_encode ( helper :: baseUrl ()) . ';' ;
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
2022-10-04 14:06:52 +02:00
and $this -> getUser ( 'group' ) >= self :: GROUP_MODERATOR
2021-06-14 18:37:45 +02:00
) {
2022-10-04 14:06:52 +02:00
$vars .= 'var privateKey = ' . json_encode ( md5_file ( self :: DATA_DIR . 'core.json' )) . ';' ;
2021-06-14 18:37:45 +02:00
}
echo '<script>' . helper :: minifyJs ( $vars ) . '</script>' ;
// Librairies
$moduleId = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]);
2022-10-04 14:06:52 +02:00
foreach ( $this -> output [ 'vendor' ] as $vendorName ) {
2021-06-14 18:37:45 +02:00
// Coeur
2022-10-04 14:06:52 +02:00
if ( file_exists ( 'core/vendor/' . $vendorName . '/inc.json' )) {
2021-06-14 18:37:45 +02:00
$vendorPath = 'core/vendor/' . $vendorName . '/' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Module
2022-10-04 14:06:52 +02:00
elseif (
2021-06-14 18:37:45 +02:00
$moduleId
2022-10-04 14:06:52 +02:00
and in_array ( $moduleId , self :: $coreModuleIds ) === false
and file_exists ( 'module/' . $moduleId . '/vendor/' . $vendorName . '/inc.json' )
2021-06-14 18:37:45 +02:00
) {
$vendorPath = 'module/' . $moduleId . '/vendor/' . $vendorName . '/' ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Sinon continue
else {
2021-06-07 10:16:09 +02:00
continue ;
}
2021-06-14 18:37:45 +02:00
// Détermine le type d'import en fonction de l'extension de la librairie
$vendorFiles = json_decode ( file_get_contents ( $vendorPath . 'inc.json' ));
2022-10-04 14:06:52 +02:00
foreach ( $vendorFiles as $vendorFile ) {
switch ( pathinfo ( $vendorFile , PATHINFO_EXTENSION )) {
2021-06-14 18:37:45 +02:00
case 'css' :
// Force le rechargement lors d'une mise à jour du jeu d'icônes
$reload = $vendorPath === 'core/vendor/zwiico/'
? '?' . md5_file ( 'core/vendor/zwiico/css/zwiico-codes.css' )
: '' ;
echo '<link rel="stylesheet" href="' . helper :: baseUrl ( false ) . $vendorPath . $vendorFile . $reload . '">' ;
2021-06-07 10:16:09 +02:00
break ;
2021-06-14 18:37:45 +02:00
case 'js' :
echo '<script src="' . helper :: baseUrl ( false ) . $vendorPath . $vendorFile . '"></script>' ;
2021-06-07 10:16:09 +02:00
break ;
}
}
}
}
/**
2021-06-14 18:37:45 +02:00
* Affiche le cadre avec les drapeaux sélectionnés
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function showi18n ()
{
2021-06-14 18:37:45 +02:00
foreach ( self :: $i18nList as $key => $value ) {
2021-11-16 12:11:56 +01:00
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'config' , 'i18n' , $key ]) === 'site'
or (
2021-12-06 18:26:16 +01:00
// Le script de traduction est actif et la langue est traduite par script
2022-10-04 14:06:52 +02:00
$this -> getData ([ 'config' , 'i18n' , 'scriptGoogle' ]) === true
and $this -> getData ([ 'config' , 'i18n' , $key ]) === 'script'
2021-12-06 18:26:16 +01:00
// Le drapeau n'est pas actif pour les non admin en mode connecté.
2022-10-04 14:06:52 +02:00
and
( $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
or $this -> getUser ( 'group' ) === self :: GROUP_ADMIN )
2021-06-07 10:16:09 +02:00
)
2021-06-14 18:37:45 +02:00
) {
if (
2022-10-04 14:06:52 +02:00
( isset ( $_COOKIE [ 'ZWII_I18N_SITE' ])
and $_COOKIE [ 'ZWII_I18N_SITE' ] === $key
)
or
( isset ( $_COOKIE [ 'ZWII_I18N_SCRIPT' ])
and $_COOKIE [ 'ZWII_I18N_SCRIPT' ] === $key
)
) {
$select = ' class="i18nFlagSelected" ' ;
} else {
$select = ' class="i18nFlag" ' ;
}
echo '<li>' ;
echo '<a href="' . helper :: baseUrl () . 'translate/i18n/' . $key . '/' . $this -> getData ([ 'config' , 'i18n' , $key ]) . '/' . $this -> getUrl ( 0 ) . '"><img ' . $select . ' alt="' . $value . '" src="' . helper :: baseUrl ( false ) . 'core/vendor/i18n/png/' . $key . '.png"/></a>' ;
echo '</li>' ;
2021-06-07 10:16:09 +02:00
}
}
}
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2022-10-04 14:06:52 +02:00
class core extends common
{
2021-06-07 10:16:09 +02:00
/**
2021-06-14 18:37:45 +02:00
* Constructeur du coeur
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function __construct ()
{
2021-06-14 18:37:45 +02:00
parent :: __construct ();
// Token CSRF
2022-10-04 14:06:52 +02:00
if ( empty ( $_SESSION [ 'csrf' ])) {
2021-06-14 18:37:45 +02:00
$_SESSION [ 'csrf' ] = bin2hex ( openssl_random_pseudo_bytes ( 32 ));
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +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 );
2022-10-04 14:06:52 +02:00
if ( $lastClearTmp > $this -> getData ([ 'core' , 'lastClearTmp' ]) + 86400 ) {
2021-06-14 18:37:45 +02:00
$iterator = new DirectoryIterator ( self :: TEMP_DIR );
2022-10-04 14:06:52 +02:00
foreach ( $iterator as $fileInfos ) {
if (
$fileInfos -> isFile () &&
2021-06-14 18:37:45 +02:00
$fileInfos -> getBasename () !== '.htaccess' &&
$fileInfos -> getBasename () !== '.gitkeep'
) {
@ unlink ( $fileInfos -> getPathname ());
2021-06-07 10:16:09 +02:00
}
}
2021-06-14 18:37:45 +02:00
// 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 );
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'config' , 'autoBackup' ])
2022-10-04 14:06:52 +02:00
and $lastBackup > $this -> getData ([ 'core' , 'lastBackup' ]) + 86400
and $this -> getData ([ 'user' ]) // Pas de backup pendant l'installation
2021-06-14 18:37:45 +02:00
) {
// Copie des fichier de données
2022-10-04 14:06:52 +02:00
helper :: autoBackup ( self :: BACKUP_DIR , [ 'backup' , 'tmp' , 'file' ]);
2021-06-14 18:37:45 +02:00
// Date du dernier backup
$this -> setData ([ 'core' , 'lastBackup' , $lastBackup ]);
// Supprime les backups de plus de 30 jours
$iterator = new DirectoryIterator ( self :: BACKUP_DIR );
2022-10-04 14:06:52 +02:00
foreach ( $iterator as $fileInfos ) {
if (
2021-06-14 18:37:45 +02:00
$fileInfos -> isFile ()
2022-10-04 14:06:52 +02:00
and $fileInfos -> getBasename () !== '.htaccess'
and $fileInfos -> getMTime () + ( 86400 * 30 ) < time ()
2021-06-14 18:37:45 +02:00
) {
@ unlink ( $fileInfos -> getPathname ());
2021-06-07 10:16:09 +02:00
}
}
}
2022-02-07 10:27:21 +01:00
2021-06-14 18:37:45 +02:00
// Crée le fichier de personnalisation avancée
2022-10-04 14:06:52 +02:00
if ( file_exists ( self :: DATA_DIR . 'custom.css' ) === false ) {
file_put_contents ( self :: DATA_DIR . 'custom.css' , file_get_contents ( 'core/module/theme/resource/custom.css' ));
chmod ( self :: DATA_DIR . 'custom.css' , 0755 );
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Crée le fichier de personnalisation
2022-10-04 14:06:52 +02:00
if ( file_exists ( self :: DATA_DIR . 'theme.css' ) === false ) {
file_put_contents ( self :: DATA_DIR . 'theme.css' , '' );
chmod ( self :: DATA_DIR . 'theme.css' , 0755 );
2021-06-14 18:37:45 +02:00
}
// Crée le fichier de personnalisation de l'administration
2022-10-04 14:06:52 +02:00
if ( file_exists ( self :: DATA_DIR . 'admin.css' ) === false ) {
file_put_contents ( self :: DATA_DIR . 'admin.css' , '' );
chmod ( self :: DATA_DIR . 'admin.css' , 0755 );
2021-06-14 18:37:45 +02:00
}
2022-03-09 12:50:05 +01:00
2021-06-14 18:37:45 +02:00
// Check la version rafraichissement du theme
2022-10-04 14:06:52 +02:00
$cssVersion = preg_split ( '/\*+/' , file_get_contents ( self :: DATA_DIR . 'theme.css' ));
if ( empty ( $cssVersion [ 1 ]) or $cssVersion [ 1 ] !== md5 ( json_encode ( $this -> getData ([ 'theme' ])))) {
2021-06-14 18:37:45 +02:00
// Version
$css = '/*' . md5 ( json_encode ( $this -> getData ([ 'theme' ]))) . '*/' ;
2022-02-06 11:32:29 +01:00
2022-02-06 12:16:51 +01:00
/**
2022-02-06 17:13:16 +01:00
* Import des polices de caractères
2022-02-06 12:16:51 +01:00
*/
2022-03-09 12:50:05 +01:00
2022-10-04 14:06:52 +02:00
$f [ 'files' ] = $this -> getData ([ 'fonts' , 'files' ]);
$f [ 'imported' ] = $this -> getData ([ 'fonts' , 'imported' ]);
$f [ 'websafe' ] = self :: $fontsWebSafe ;
2022-04-21 23:37:57 +02:00
// Construit un tableau avec leur ID et leur famille
2022-10-04 14:06:52 +02:00
foreach ([ 'websafe' , 'imported' , 'files' ] as $type ) {
if ( is_array ( $f [ $type ])) {
foreach ( $f [ $type ] as $fontId => $fontValue ) {
2022-04-21 23:37:57 +02:00
$fonts [ $fontId ] = $fontValue [ 'font-family' ];
2022-03-18 16:12:30 +01:00
}
2022-02-06 12:16:51 +01:00
}
}
2022-02-06 11:32:29 +01:00
2021-06-14 18:37:45 +02:00
// Fond du body
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'body' , 'backgroundColor' ]));
// Body
2022-03-11 09:17:13 +01:00
$css .= 'body{font-family:' . $fonts [ $this -> getData ([ 'theme' , 'text' , 'font' ])] . ';}' ;
2022-10-04 14:06:52 +02:00
if ( $themeBodyImage = $this -> getData ([ 'theme' , 'body' , 'image' ])) {
2021-06-14 18:37:45 +02:00
// Image dans html pour éviter les déformations.
2021-12-03 14:27:55 +01:00
$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' ]) . '}' ;
2021-06-14 18:37:45 +02:00
// Couleur du body transparente
2021-12-03 14:27:55 +01:00
$css .= 'body {background-color: rgba(0,0,0,0)}' ;
2021-06-14 18:37:45 +02:00
} else {
// Pas d'image couleur du body
2021-12-03 14:27:55 +01:00
$css .= 'html {background-color:' . $colors [ 'normal' ] . ';}' ;
2021-06-14 18:37:45 +02:00
// Même couleur dans le fond de l'éditeur
2021-12-03 14:27:55 +01:00
//$css .= '{background-color:' . $colors['normal'] . ' !important}';
2021-06-14 18:37:45 +02:00
}
// Icône BacktoTop
2022-10-04 14:06:52 +02:00
$css .= '#backToTop {background-color:' . $this -> getData ([ 'theme' , 'body' , 'toTopbackgroundColor' ]) . ';color:' . $this -> getData ([ 'theme' , 'body' , 'toTopColor' ]) . ';}' ;
2021-06-14 18:37:45 +02:00
// Site
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'text' , 'linkColor' ]));
$css .= 'a{color:' . $colors [ 'normal' ] . '}' ;
// Couleurs de site dans TinyMCe
2022-03-11 09:17:13 +01:00
$css .= 'div.mce-edit-area {font-family:' . $fonts [ $this -> getData ([ 'theme' , 'text' , 'font' ])] . ';}' ;
2021-06-14 18:37:45 +02:00
// Site dans TinyMCE
2021-12-03 17:10:53 +01:00
$css .= '.editorWysiwyg {background-color:' . $this -> getData ([ 'theme' , 'site' , 'backgroundColor' ]) . ';}' ;
$css .= 'span.mce-text{background-color: unset !important;}' ;
2021-06-14 18:37:45 +02:00
//$css .= 'a:hover:not(.inputFile, button){color:' . $colors['darken'] . '}';
$css .= 'body,.row > div{font-size:' . $this -> getData ([ 'theme' , 'text' , 'fontSize' ]) . '}' ;
$css .= 'body{color:' . $this -> getData ([ 'theme' , 'text' , 'textColor' ]) . '}' ;
2022-10-04 14:06:52 +02:00
$css .= 'select,input[type=\'password\'],input[type=\'email\'],input[type=\'text\'],.inputFile,select,textarea{color:' . $this -> getData ([ 'theme' , 'text' , 'textColor' ]) . ';background-color:' . $this -> getData ([ 'theme' , 'site' , 'backgroundColor' ]) . ';}' ;
2021-06-14 18:37:45 +02:00
// 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 .= '.button.buttonGrey,.button.buttonGrey:hover{color:' . $this->getData(['theme', 'text', 'textColor']) . '}';
2022-02-01 13:43:36 +01:00
$css .= '.container {max-width:' . $this -> getData ([ 'theme' , 'site' , 'width' ]) . '}' ;
2021-06-14 18:37:45 +02:00
$margin = $this -> getData ([ 'theme' , 'site' , 'margin' ]) ? '0' : '20px' ;
// Marge supplémentaire lorsque le pied de page est fixe
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'theme' , 'footer' , 'fixed' ]) === true &&
$this -> getData ([ 'theme' , 'footer' , 'position' ]) === 'body'
) {
2021-06-14 18:37:45 +02:00
//$css .= '@media (min-width: 769px) { #site {margin-bottom: ' . ((str_replace ('px', '', $this->getData(['theme', 'footer', 'height']) ) * 2 ) + 31 ) . 'px}}';
//$css .= '@media (max-width: 768px) { #site {margin-bottom: ' . ((str_replace ('px', '', $this->getData(['theme', 'footer', 'height']) ) * 2 ) + 93 ) . 'px}}';
2022-10-04 14:06:52 +02:00
$marginBottomLarge = (( str_replace ( 'px' , '' , $this -> getData ([ 'theme' , 'footer' , 'height' ])) * 2 ) + 31 ) . 'px' ;
$marginBottomSmall = (( str_replace ( 'px' , '' , $this -> getData ([ 'theme' , 'footer' , 'height' ])) * 2 ) + 93 ) . 'px' ;
2021-06-14 18:37:45 +02:00
} else {
$marginBottomSmall = $margin ;
$marginBottomLarge = $margin ;
}
$css .= $this -> getData ([ 'theme' , 'site' , 'width' ]) === '100%'
2022-10-04 14:06:52 +02:00
? '@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;} ' ;
2021-06-14 18:37:45 +02:00
$css .= $this -> getData ([ 'theme' , 'site' , 'width' ]) === '750px'
2022-10-04 14:06:52 +02:00
? '.button, button{font-size:0.8em;}'
: '' ;
2021-06-14 18:37:45 +02:00
$css .= '#site{background-color:' . $this -> getData ([ 'theme' , 'site' , 'backgroundColor' ]) . ';border-radius:' . $this -> getData ([ 'theme' , 'site' , 'radius' ]) . ';box-shadow:' . $this -> getData ([ 'theme' , 'site' , 'shadow' ]) . ' #212223;}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'button' , 'backgroundColor' ]));
$css .= '.speechBubble,.button,.button:hover,button[type=\'submit\'],.pagination a,.pagination a:hover,input[type=\'checkbox\']:checked + label:before,input[type=\'radio\']:checked + label:before,.helpContent{background-color:' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . '}' ;
$css .= '.helpButton span{color:' . $colors [ 'normal' ] . '}' ;
$css .= 'input[type=\'text\']:hover,input[type=\'password\']:hover,.inputFile:hover,select:hover,textarea:hover{border-color:' . $colors [ 'normal' ] . '}' ;
$css .= '.speechBubble:before{border-color:' . $colors [ 'normal' ] . ' transparent transparent transparent}' ;
$css .= '.button:hover,button[type=\'submit\']:hover,.pagination a:hover,input[type=\'checkbox\']:not(:active):checked:hover + label:before,input[type=\'checkbox\']:active + label:before,input[type=\'radio\']:checked:hover + label:before,input[type=\'radio\']:not(:checked):active + label:before{background-color:' . $colors [ 'darken' ] . '}' ;
$css .= '.helpButton span:hover{color:' . $colors [ 'darken' ] . '}' ;
$css .= '.button:active,button[type=\'submit\']:active,.pagination a:active{background-color:' . $colors [ 'veryDarken' ] . '}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'title' , 'textColor' ]));
2022-03-11 09:17:13 +01:00
$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' ]) . '}' ;
2021-06-14 18:37:45 +02:00
$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' ]));
2022-10-04 14:06:52 +02:00
$css .= '.block {border: 1px solid ' . $this -> getdata ([ 'theme' , 'block' , 'borderColor' ]) . ';}.block h4 {background-color:' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';}' ;
2021-12-03 15:08:21 +01:00
//$css .= '.mce-tinymce {border: 1px solid ' . $this->getdata(['theme','block','borderColor']) .' !important;}';
2021-11-21 16:11:40 +01:00
2021-06-14 18:37:45 +02:00
// Bannière
2021-11-27 08:47:00 +01:00
2021-11-26 12:05:07 +01:00
// Eléments communs
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'header' , 'margin' ])) {
if ( $this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'site-first' ) {
2021-06-14 18:37:45 +02:00
$css .= 'header{margin:0 20px}' ;
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$css .= 'header{margin:20px 20px 0 20px}' ;
}
}
2021-11-26 12:05:07 +01:00
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'header' , 'backgroundColor' ]));
$css .= 'header{background-color:' . $colors [ 'normal' ] . ';}' ;
2021-11-27 08:47:00 +01:00
2021-11-26 12:05:07 +01:00
// Bannière de type papier peint
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'header' , 'feature' ]) === 'wallpaper' ) {
$css .= 'header{background-size:' . $this -> getData ([ 'theme' , 'header' , 'imageContainer' ]) . '}' ;
2021-11-25 13:40:14 +01:00
$css .= 'header{background-color:' . $colors [ 'normal' ];
2021-11-18 11:34:19 +01:00
2021-11-07 15:50:24 +01:00
// Valeur de hauteur traditionnelle
2022-10-04 14:06:52 +02:00
$css .= ';height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . ';line-height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]);
2021-11-25 13:40:14 +01:00
$css .= ';text-align:' . $this -> getData ([ 'theme' , 'header' , 'textAlign' ]) . '}' ;
2022-10-04 14:06:52 +02:00
if ( $themeHeaderImage = $this -> getData ([ 'theme' , 'header' , 'image' ])) {
2021-11-07 15:50:24 +01:00
$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' ]));
2022-03-11 09:17:13 +01:00
$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' ]) . '}' ;
2021-06-14 18:37:45 +02:00
}
2021-11-26 12:05:07 +01:00
// Bannière au contenu personnalisé
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'header' , 'feature' ]) === 'feature' ) {
2021-11-12 11:44:40 +01:00
// Hauteur de la taille du contenu perso
2022-10-04 14:06:52 +02:00
$css .= 'header {height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . '; min-height:' . $this -> getData ([ 'theme' , 'header' , 'height' ]) . ';overflow: hidden;}' ;
2021-11-30 14:03:58 +01:00
//$css .= '.bannerDisplay img { width: auto;max-height:' . $this->getData(['theme', 'header', 'height']) . ';}';
2021-11-18 11:34:19 +01:00
2021-11-09 18:38:37 +01:00
}
2021-11-15 09:01:08 +01:00
2021-06-14 18:37:45 +02:00
// 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' ] . '}' ;
2022-10-04 14:06:52 +02:00
$css .= 'nav a.active{color:' . $this -> getData ([ 'theme' , 'menu' , 'activeTextColor' ]) . ';}' ;
if ( $this -> getData ([ 'theme' , 'menu' , 'activeColorAuto' ]) === true ) {
2021-06-14 18:37:45 +02:00
$css .= 'nav a.active{background-color:' . $colors [ 'veryDarken' ] . '}' ;
} else {
2022-10-04 14:06:52 +02:00
$css .= 'nav a.active{background-color:' . $this -> getData ([ 'theme' , 'menu' , 'activeColor' ]) . '}' ;
2021-06-14 18:37:45 +02:00
/* $color2 = helper :: colorVariants ( $this -> getData ([ 'theme' , 'menu' , 'textColor' ]));
$css .= 'nav a.active{color:' . $color2 [ 'text' ] . '}' ; */
}
$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' ]) . '}' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'menu' , 'margin' ])) {
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'site-first'
2022-10-04 14:06:52 +02:00
or $this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'site-second'
2021-06-14 18:37:45 +02:00
) {
$css .= 'nav{padding:10px 10px 0 10px;}' ;
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$css .= 'nav{padding:0 10px}' ;
}
} else {
$css .= 'nav{margin:0}' ;
}
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'theme' , 'menu' , 'position' ]) === 'top'
2022-10-04 14:06:52 +02:00
) {
$css .= 'nav{padding:0 10px;}' ;
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
2022-10-04 14:06:52 +02:00
$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' ]) . '}' ;
2021-06-14 18:37:45 +02:00
// Pied de page
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
$colors = helper :: colorVariants ( $this -> getData ([ 'theme' , 'footer' , 'backgroundColor' ]));
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'theme' , 'footer' , 'margin' ])) {
2021-06-14 18:37:45 +02:00
$css .= 'footer{padding:0 20px;}' ;
} else {
$css .= 'footer{padding:0}' ;
}
2021-06-07 10:16:09 +02:00
2022-03-11 09:17:13 +01:00
$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' ]) . '}' ;
2021-06-14 18:37:45 +02:00
$css .= 'footer {background-color:' . $colors [ 'normal' ] . ';color:' . $this -> getData ([ 'theme' , 'footer' , 'textColor' ]) . '}' ;
$css .= 'footer a{color:' . $this -> getData ([ 'theme' , 'footer' , 'textColor' ]) . '}' ;
$css .= 'footer #footersite > div {margin:' . $this -> getData ([ 'theme' , 'footer' , 'height' ]) . ' 0}' ;
2021-06-07 10:16:09 +02:00
2021-06-14 18:37:45 +02:00
$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' ]) . '}' ;
2022-02-06 17:13:16 +01:00
2021-06-14 18:37:45 +02:00
// Enregistre la personnalisation
2022-10-04 14:06:52 +02:00
file_put_contents ( self :: DATA_DIR . 'theme.css' , $css );
2022-03-15 09:57:56 +01:00
2021-06-14 18:37:45 +02:00
// 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 " );
2021-06-07 10:16:09 +02:00
}
2022-02-06 17:13:16 +01:00
2021-06-14 18:37:45 +02:00
// Check la version rafraichissement du theme admin
2022-10-04 14:06:52 +02:00
$cssVersion = preg_split ( '/\*+/' , file_get_contents ( self :: DATA_DIR . 'admin.css' ));
if ( empty ( $cssVersion [ 1 ]) or $cssVersion [ 1 ] !== md5 ( json_encode ( $this -> getData ([ 'admin' ])))) {
2022-02-06 17:13:16 +01:00
2021-06-14 18:37:45 +02:00
// Version
$css = '/*' . md5 ( json_encode ( $this -> getData ([ 'admin' ]))) . '*/' ;
2022-02-06 17:13:16 +01:00
/**
* Import des polices de caractères
*/
2022-03-05 15:49:03 +01:00
2022-10-04 14:06:52 +02:00
$f [ 'files' ] = $this -> getData ([ 'fonts' , 'files' ]);
$f [ 'imported' ] = $this -> getData ([ 'fonts' , 'imported' ]);
$f [ 'websafe' ] = self :: $fontsWebSafe ;
2022-04-21 23:37:57 +02:00
// Construit un tableau avec leur ID et leur famille
2022-10-04 14:06:52 +02:00
foreach ([ 'websafe' , 'imported' , 'files' ] as $type ) {
if ( is_array ( $f [ $type ])) {
foreach ( $f [ $type ] as $fontId => $fontValue ) {
2022-04-21 23:37:57 +02:00
$fonts [ $fontId ] = $fontValue [ 'font-family' ];
2022-03-18 18:19:21 +01:00
}
2022-02-06 17:13:16 +01:00
}
2022-02-11 11:50:28 +01:00
}
2022-02-06 17:13:16 +01:00
2022-02-11 11:50:28 +01:00
// Thème Administration
2022-10-04 14:06:52 +02:00
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColor' ]));
$css .= '#site{background-color:' . $colors [ 'normal' ] . ';}' ;
$css .= '.row > div {font:' . $fonts [ $this -> getData ([ 'admin' , 'fontText' ])] . ';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' ]) . ';}' ;
2022-02-06 17:13:16 +01:00
2021-12-03 17:10:53 +01:00
// TinyMCE
2022-10-04 14:06:52 +02:00
$css .= 'body:not(.editorWysiwyg),span .zwiico-help {color:' . $this -> getData ([ 'admin' , 'colorText' ]) . ';}' ;
$css .= 'table thead tr, table thead tr .zwiico-help{ background-color:' . $this -> getData ([ 'admin' , 'colorText' ]) . '; color:' . $colors [ 'normal' ] . ';}' ;
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButton' ]));
2021-06-14 18:37:45 +02:00
$css .= 'input[type="checkbox"]:checked + label::before,.speechBubble{background-color:' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';}' ;
$css .= '.speechBubble::before {border-color:' . $colors [ 'normal' ] . ' transparent transparent transparent;}' ;
$css .= '.button {background-color:' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';}.button:hover {background-color:' . $colors [ 'darken' ] . ';color:' . $colors [ 'text' ] . ';}.button:active {background-color:' . $colors [ 'veryDarken' ] . ';color:' . $colors [ 'text' ] . ';}' ;
2022-10-04 14:06:52 +02:00
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButtonGrey' ]));
2021-06-14 18:37:45 +02:00
$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' ] . ';}' ;
2022-10-04 14:06:52 +02:00
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButtonRed' ]));
2021-06-14 18:37:45 +02:00
$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' ] . ';}' ;
2022-10-04 14:06:52 +02:00
$colors = helper :: colorVariants ( $this -> getData ([ 'admin' , 'backgroundColorButtonHelp' ]));
2021-06-14 18:37:45 +02:00
$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' ] . ';}' ;
2022-10-04 14:06:52 +02:00
$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 .= '.block {border: 1px solid ' . $this -> getData ([ 'admin' , 'borderBlockColor' ]) . ';}.block h4 {background-color: ' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';}' ;
$css .= 'table tr,input[type=email],input[type=text],input[type=password],select:not(#barSelectPage),textarea:not(.editorWysiwyg),.inputFile{background-color: ' . $colors [ 'normal' ] . ';color:' . $colors [ 'text' ] . ';border: 1px solid ' . $this -> getData ([ 'admin' , 'borderBlockColor' ]) . ';}' ;
2021-06-14 18:37:45 +02:00
// Bordure du contour TinyMCE
2022-10-04 14:06:52 +02:00
$css .= '.mce-tinymce{border: 1px solid ' . $this -> getData ([ 'admin' , 'borderBlockColor' ]) . '!important;}' ;
2021-06-14 18:37:45 +02:00
// Enregistre la personnalisation
2022-10-04 14:06:52 +02:00
file_put_contents ( self :: DATA_DIR . 'admin.css' , $css );
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
}
/**
* Auto - chargement des classes
* @ param string $className Nom de la classe à charger
*/
2022-10-04 14:06:52 +02:00
public static function autoload ( $className )
{
2021-06-14 18:37:45 +02:00
$classPath = strtolower ( $className ) . '/' . strtolower ( $className ) . '.php' ;
// Module du coeur
2022-10-04 14:06:52 +02:00
if ( is_readable ( 'core/module/' . $classPath )) {
2021-06-14 18:37:45 +02:00
require 'core/module/' . $classPath ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Module
2022-10-04 14:06:52 +02:00
elseif ( is_readable ( 'module/' . $classPath )) {
2021-06-14 18:37:45 +02:00
require 'module/' . $classPath ;
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
// Librairie
2022-10-04 14:06:52 +02:00
elseif ( is_readable ( 'core/vendor/' . $classPath )) {
2021-06-14 18:37:45 +02:00
require 'core/vendor/' . $classPath ;
2021-06-07 10:16:09 +02:00
}
}
/**
2021-06-14 18:37:45 +02:00
* Routage des modules
2021-06-07 10:16:09 +02:00
*/
2022-10-04 14:06:52 +02:00
public function router ()
{
2021-06-14 18:37:45 +02:00
// Installation
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'user' ]) === []
2022-10-04 14:06:52 +02:00
and $this -> getUrl ( 0 ) !== 'install'
2021-06-14 18:37:45 +02:00
) {
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'install' );
exit ();
}
// Journalisation
2022-10-05 15:05:36 +02:00
$dataLog = mb_detect_encoding ( \PHP81_BC\strftime ( '%d/%m/%y' , time ()), 'UTF-8' , true )
? \PHP81_BC\strftime ( '%d/%m/%y' , time ()) . ';' . \PHP81_BC\strftime ( '%R' , time ()) . ';'
: utf8_encode ( \PHP81_BC\strftime ( '%d/%m/%y' , time ())) . ';' . utf8_encode ( \PHP81_BC\strftime ( '%R' , time ())) . ';' ;
2022-10-04 14:06:52 +02:00
$dataLog .= helper :: getIp ( $this -> getData ([ 'config' , 'connect' , 'anonymousIp' ])) . ';' ;
2021-06-14 18:37:45 +02:00
$dataLog .= $this -> getUser ( 'id' ) ? $this -> getUser ( 'id' ) . ';' : 'anonyme' . ';' ;
$dataLog .= $this -> getUrl ();
$dataLog .= PHP_EOL ;
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'config' , 'connect' , 'log' ])) {
2021-06-14 18:37:45 +02:00
file_put_contents ( self :: DATA_DIR . 'journal.log' , $dataLog , FILE_APPEND );
}
// Force la déconnexion des membres bannis ou d'une seconde session
if (
$this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
2022-10-04 14:06:52 +02:00
and ( $this -> getUser ( 'group' ) === self :: GROUP_BANNED
or ( $_SESSION [ 'csrf' ] !== $this -> getData ([ 'user' , $this -> getUser ( 'id' ), 'accessCsrf' ])
and $this -> getData ([ 'config' , 'connect' , 'autoDisconnect' ]) === true )
)
2021-06-14 18:37:45 +02:00
) {
$user = new user ;
$user -> logout ();
}
// Mode maintenance
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'config' , 'maintenance' ])
2022-10-04 14:06:52 +02:00
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
2021-06-14 18:37:45 +02:00
)
)
) {
// Déconnexion
$user = new user ;
$user -> logout ();
// Redirection
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'maintenance' );
exit ();
}
// Check l'accès à la page
$access = null ;
$accessInfo [ 'userName' ] = '' ;
$accessInfo [ 'pageId' ] = '' ;
2022-10-04 14:06:52 +02:00
if ( $this -> getData ([ 'page' , $this -> getUrl ( 0 )]) !== null ) {
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'group' ]) === self :: GROUP_VISITOR
2022-10-04 14:06:52 +02:00
or ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) >= $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'group' ])
2021-06-14 18:37:45 +02:00
)
) {
$access = true ;
2022-10-04 14:06:52 +02:00
} else {
if ( $this -> getUrl ( 0 ) === $this -> getData ([ 'locale' , 'homePageId' ])) {
2021-06-14 18:37:45 +02:00
$access = 'login' ;
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$access = false ;
}
}
// Empêcher l'accès aux pages désactivées par URL directe
2022-10-04 14:06:52 +02:00
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
2021-06-14 18:37:45 +02:00
)
2022-10-04 14:06:52 +02:00
) {
2021-06-14 18:37:45 +02:00
$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
*/
2022-10-04 09:39:48 +02:00
2022-10-04 14:06:52 +02:00
foreach ( $this -> getData ([ 'user' ]) as $userId => $userIds ) {
if ( ! is_null ( $this -> getData ([ 'user' , $userId , 'accessUrl' ]))) {
$t = explode ( '/' , $this -> getData ([ 'user' , $userId , 'accessUrl' ]));
}
if (
isset ( $t ) &&
2022-10-04 09:39:48 +02:00
$this -> getUser ( 'id' ) &&
2021-06-14 18:37:45 +02:00
$userId !== $this -> getUser ( 'id' ) &&
2022-10-04 14:06:52 +02:00
$this -> getData ([ 'user' , $userId , 'accessUrl' ]) === $this -> getUrl () &&
array_intersect ( $t , self :: $accessList ) &&
array_intersect ( $t , self :: $accessExclude ) !== false &&
time () < $this -> getData ([ 'user' , $userId , 'accessTimer' ]) + self :: ACCESS_TIMER
2021-06-14 18:37:45 +02:00
) {
2022-10-04 14:06:52 +02:00
$access = false ;
$accessInfo [ 'userName' ] = $this -> getData ([ 'user' , $userId , 'lastname' ]) . ' ' . $this -> getData ([ 'user' , $userId , 'firstname' ]);
$accessInfo [ 'pageId' ] = end ( $t );
2021-06-14 18:37:45 +02:00
}
}
2022-10-04 14:06:52 +02:00
2021-06-14 18:37:45 +02:00
// Accès concurrent stocke la page visitée
2022-10-04 14:06:52 +02:00
if (
$this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'id' )
) {
$this -> setData ([ 'user' , $this -> getUser ( 'id' ), 'accessUrl' , $this -> getUrl ()]);
$this -> setData ([ 'user' , $this -> getUser ( 'id' ), 'accessTimer' , time ()]);
2021-06-14 18:37:45 +02:00
}
// Breadcrumb
$title = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'title' ]);
2022-10-04 14:06:52 +02:00
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' ]);
2021-06-14 18:37:45 +02:00
}
2022-06-02 14:35:31 +02:00
// Importe la page simple sans module ou avec un module inexistant
2022-10-04 14:06:52 +02:00
if (
2021-06-14 18:37:45 +02:00
$this -> getData ([ 'page' , $this -> getUrl ( 0 )]) !== null
2022-10-04 14:06:52 +02:00
and ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]) === ''
or ! class_exists ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]))
)
and $access
2021-06-14 18:37:45 +02:00
) {
$this -> addOutput ([
'title' => $title ,
2021-08-17 08:24:12 +02:00
//'content' => file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getUrl(0), 'content'])),
2021-08-21 08:44:37 +02:00
'content' => $this -> getPage ( $this -> getUrl ( 0 ), self :: $i18n ),
2021-06-14 18:37:45 +02:00
'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' ]),
2022-10-04 14:06:52 +02:00
'contentRight' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ])
//file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getData(['page',$this->getUrl(0),'barRight']), 'content']))
? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), self :: $i18n )
: '' ,
'contentLeft' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ])
//file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getData(['page',$this->getUrl(0),'barLeft']), 'content']))
? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), self :: $i18n )
: '' ,
2021-06-14 18:37:45 +02:00
]);
}
// Importe le module
else {
// Id du module, et valeurs en sortie de la page si il s'agit d'un module de page
2022-10-04 14:06:52 +02:00
if ( $access and $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ])) {
2021-06-14 18:37:45 +02:00
$moduleId = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]);
$this -> addOutput ([
'title' => $title ,
// Meta description = 160 premiers caractères de l'article
2022-10-05 09:38:43 +02:00
'metaDescription' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'moduleId' ]) === 'blog' && ! empty ( $this -> getUrl ( 1 )) && in_array ( $this -> getUrl ( 1 ), $this -> getData ([ 'module' ]))
2022-10-04 14:06:52 +02:00
? strip_tags ( substr ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'posts' , $this -> getUrl ( 1 ), 'content' ]), 0 , 159 ))
: $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'metaDescription' ]),
2021-06-14 18:37:45 +02:00
'metaTitle' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'metaTitle' ]),
'typeMenu' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'typeMenu' ]),
'iconUrl' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'iconUrl' ]),
'disable' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'disable' ]),
2022-10-04 14:06:52 +02:00
'contentRight' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ])
//file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getData(['page',$this->getUrl(0),'barRight']), 'content']))
//? $this->getPage($this->getData(['page',$this->getUrl(0),'barRight']))
? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barRight' ]), self :: $i18n )
: '' ,
'contentLeft' => $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ])
// ? file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getData(['page',$this->getUrl(0),'barLeft']), 'content']))
? $this -> getPage ( $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'barLeft' ]), self :: $i18n )
: '' ,
2021-06-14 18:37:45 +02:00
]);
2021-08-17 08:24:12 +02:00
//$pageContent = file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $this->getUrl(0), 'content']));
2021-08-21 08:44:37 +02:00
$pageContent = $this -> getPage ( $this -> getUrl ( 0 ), self :: $i18n );
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$moduleId = $this -> getUrl ( 0 );
$pageContent = '' ;
}
// Check l'existence du module
2022-10-04 14:06:52 +02:00
if ( class_exists ( $moduleId )) {
2021-06-14 18:37:45 +02:00
/** @var common $module */
$module = new $moduleId ;
// Check l'existence de l'action
$action = '' ;
$ignore = true ;
2022-10-04 10:17:48 +02:00
if ( ! is_null ( $this -> getUrl ( 1 ))) {
2022-10-04 14:06:52 +02:00
foreach ( explode ( '-' , $this -> getUrl ( 1 )) as $actionPart ) {
if ( $ignore ) {
2022-10-04 10:17:48 +02:00
$action .= $actionPart ;
$ignore = false ;
2022-10-04 14:06:52 +02:00
} else {
2022-10-04 10:17:48 +02:00
$action .= ucfirst ( $actionPart );
}
2021-06-14 18:37:45 +02:00
}
}
$action = array_key_exists ( $action , $module :: $actions ) ? $action : 'index' ;
2022-10-04 14:06:52 +02:00
if ( array_key_exists ( $action , $module :: $actions )) {
2021-06-14 18:37:45 +02:00
$module -> $action ();
$output = $module -> output ;
// Check le groupe de l'utilisateur
2022-10-04 14:06:52 +02:00
if (
( $module :: $actions [ $action ] === self :: GROUP_VISITOR
or ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUser ( 'group' ) >= $module :: $actions [ $action ]
2021-06-14 18:37:45 +02:00
)
)
2022-10-04 14:06:52 +02:00
and $output [ 'access' ] === true
2021-06-14 18:37:45 +02:00
) {
// Enregistrement du contenu de la méthode POST lorsqu'une notice est présente
2022-10-04 14:06:52 +02:00
if ( common :: $inputNotices ) {
foreach ( $_POST as $postId => $postValue ) {
if ( is_array ( $postValue )) {
foreach ( $postValue as $subPostId => $subPostValue ) {
2021-06-14 18:37:45 +02:00
self :: $inputBefore [ $postId . '_' . $subPostId ] = $subPostValue ;
}
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
self :: $inputBefore [ $postId ] = $postValue ;
}
}
}
// Sinon traitement des données de sortie qui requiert qu'aucune notice ne soit présente
else {
// Notification
2022-10-04 14:06:52 +02:00
if ( $output [ 'notification' ]) {
if ( $output [ 'state' ] === true ) {
2021-06-14 18:37:45 +02:00
$notification = 'ZWII_NOTIFICATION_SUCCESS' ;
2022-10-04 14:06:52 +02:00
} elseif ( $output [ 'state' ] === false ) {
2021-06-14 18:37:45 +02:00
$notification = 'ZWII_NOTIFICATION_ERROR' ;
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$notification = 'ZWII_NOTIFICATION_OTHER' ;
}
$_SESSION [ $notification ] = $output [ 'notification' ];
}
// Redirection
2022-10-04 14:06:52 +02:00
if ( $output [ 'redirect' ]) {
2021-06-14 18:37:45 +02:00
http_response_code ( 301 );
header ( 'Location:' . $output [ 'redirect' ]);
exit ();
}
}
// Données en sortie applicables même lorsqu'une notice est présente
// Affichage
2022-10-04 14:06:52 +02:00
if ( $output [ 'display' ]) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'display' => $output [ 'display' ]
]);
}
// Contenu brut
2022-10-04 14:06:52 +02:00
if ( $output [ 'content' ]) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'content' => $output [ 'content' ]
]);
}
// Contenu par vue
2022-10-04 14:06:52 +02:00
elseif ( $output [ 'view' ]) {
2021-06-14 18:37:45 +02:00
// Chemin en fonction d'un module du coeur ou d'un module
$modulePath = in_array ( $moduleId , self :: $coreModuleIds ) ? 'core/' : '' ;
// CSS
$stylePath = $modulePath . 'module/' . $moduleId . '/view/' . $output [ 'view' ] . '/' . $output [ 'view' ] . '.css' ;
2022-10-04 14:06:52 +02:00
if ( file_exists ( $stylePath )) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'style' => file_get_contents ( $stylePath )
]);
}
2022-03-21 19:16:11 +01:00
if ( $output [ 'style' ]) {
2022-10-04 14:06:52 +02:00
$this -> addOutput ([
'style' => $this -> output [ 'style' ] . file_get_contents ( $output [ 'style' ])
]);
2021-06-14 18:37:45 +02:00
}
// JS
$scriptPath = $modulePath . 'module/' . $moduleId . '/view/' . $output [ 'view' ] . '/' . $output [ 'view' ] . '.js.php' ;
2022-10-04 14:06:52 +02:00
if ( file_exists ( $scriptPath )) {
2021-06-14 18:37:45 +02:00
ob_start ();
include $scriptPath ;
$this -> addOutput ([
'script' => ob_get_clean ()
]);
}
// Vue
$viewPath = $modulePath . 'module/' . $moduleId . '/view/' . $output [ 'view' ] . '/' . $output [ 'view' ] . '.php' ;
2022-10-04 14:06:52 +02:00
if ( file_exists ( $viewPath )) {
2021-06-14 18:37:45 +02:00
ob_start ();
include $viewPath ;
$modpos = $this -> getData ([ 'page' , $this -> getUrl ( 0 ), 'modulePosition' ]);
if ( $modpos === 'top' ) {
$this -> addOutput ([
2022-10-04 14:06:52 +02:00
'content' => ob_get_clean () . ( $output [ 'showPageContent' ] ? $pageContent : '' )
]);
} else if ( $modpos === 'free' ) {
if ( strstr ( $pageContent , '[MODULE]' , true ) === false ) {
$begin = strstr ( $pageContent , '[]' , true );
} else {
2021-06-14 18:37:45 +02:00
$begin = strstr ( $pageContent , '[MODULE]' , true );
}
2022-10-04 14:06:52 +02:00
if ( strstr ( $pageContent , '[MODULE]' ) === false ) {
$end = strstr ( $pageContent , '[]' );
} else {
2021-06-14 18:37:45 +02:00
$end = strstr ( $pageContent , '[MODULE]' );
2022-10-04 14:06:52 +02:00
}
$cut = 8 ;
$end = substr ( $end , - strlen ( $end ) + $cut );
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
2022-10-04 14:06:52 +02:00
'content' => ( $output [ 'showPageContent' ] ? $begin : '' ) . ob_get_clean () . ( $output [ 'showPageContent' ] ? $end : '' )
]);
} else {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
2022-10-04 14:06:52 +02:00
'content' => ( $output [ 'showPageContent' ] ? $pageContent : '' ) . ob_get_clean ()
]);
2021-06-14 18:37:45 +02:00
}
}
}
// Librairies
2022-10-04 14:06:52 +02:00
if ( $output [ 'vendor' ] !== $this -> output [ 'vendor' ]) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'vendor' => array_merge ( $this -> output [ 'vendor' ], $output [ 'vendor' ])
]);
}
2022-10-04 14:06:52 +02:00
if ( $output [ 'title' ] !== null ) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'title' => $output [ 'title' ]
]);
}
// Affiche le bouton d'édition de la page dans la barre de membre
2022-10-04 14:06:52 +02:00
if ( $output [ 'showBarEditButton' ]) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'showBarEditButton' => $output [ 'showBarEditButton' ]
]);
2021-06-07 10:16:09 +02:00
}
}
2021-06-14 18:37:45 +02:00
// Erreur 403
else {
$access = false ;
2021-06-07 10:16:09 +02:00
}
}
}
}
2021-06-14 18:37:45 +02:00
// Chargement de la bibliothèque googtrans
2021-11-29 11:30:54 +01:00
2021-06-14 18:37:45 +02:00
// Le script de traduction est sélectionné
2021-09-29 16:40:25 +02:00
if ( $this -> getData ([ 'config' , 'i18n' , 'enable' ]) === true ) {
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'config' , 'i18n' , 'scriptGoogle' ]) === true
// et la traduction de la langue courante est automatique
and ( $this -> getInput ( 'ZWII_I18N_SCRIPT' ) !== ''
// Ou traduction automatique
or $this -> getData ([ 'config' , 'i18n' , 'autoDetect' ]) === true
)
2021-11-29 11:30:54 +01:00
// Cas des pages d'administration
// Pas connecté
2022-10-04 14:06:52 +02:00
and $this -> getUser ( 'password' ) !== $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getUrl ( 1 ) !== 'login'
// Ou connecté avec option active
or ( $this -> getUser ( 'password' ) === $this -> getInput ( 'ZWII_USER_PASSWORD' )
and $this -> getData ([ 'config' , 'i18n' , 'admin' ]) === true
)
2021-11-29 17:29:59 +01:00
2022-10-04 14:06:52 +02:00
) {
2021-11-29 11:30:54 +01:00
2022-10-04 14:06:52 +02:00
// Chargement de la librairie
$this -> addOutput ([
'vendor' => array_merge ( $this -> output [ 'vendor' ], [ 'i18n' ])
]);
2021-11-29 11:30:54 +01:00
}
2021-06-07 10:16:09 +02:00
}
2021-12-09 18:28:37 +01:00
2021-06-14 18:37:45 +02:00
// Erreurs
2022-10-04 14:06:52 +02:00
if ( $access === 'login' ) {
2021-06-14 18:37:45 +02:00
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'user/login/' );
exit ();
2021-06-07 10:16:09 +02:00
}
2022-10-04 14:06:52 +02:00
if ( $access === false ) {
2021-06-14 18:37:45 +02:00
http_response_code ( 403 );
if ( $accessInfo [ 'userName' ]) {
$this -> addOutput ([
'title' => 'Accès verrouillé' ,
'content' => template :: speech ( 'La page <strong>' . $accessInfo [ 'pageId' ] . '</strong> est ouverte par l\'utilisateur <strong>' . $accessInfo [ 'userName' ] . '</strong>' )
]);
} else {
2022-04-18 14:51:10 +02:00
// Redirige vers la page de connexion si page de gestion demandée
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'config' , 'connect' , 'redirectLogin' ]) === true
&& in_array ( $this -> geturl ( 0 ), self :: $accessList )
) {
2022-04-18 14:51:10 +02:00
http_response_code ( 302 );
header ( 'Location:' . helper :: baseUrl () . 'user/login/' );
exit ();
2021-06-14 18:37:45 +02:00
} else {
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'locale' , 'page403' ]) !== 'none'
and $this -> getData ([ 'page' , $this -> getData ([ 'locale' , 'page403' ])])
) {
header ( 'Location:' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'page403' ]));
2022-04-18 14:51:10 +02:00
} else {
$this -> addOutput ([
'title' => 'Accès interdit' ,
'content' => template :: speech ( 'Vous n\'êtes pas autorisé à consulter cette page (erreur 403)' )
]);
}
2021-06-14 18:37:45 +02:00
}
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
} elseif ( $this -> output [ 'content' ] === '' ) {
http_response_code ( 404 );
2022-10-04 14:06:52 +02:00
if (
$this -> getData ([ 'locale' , 'page404' ]) !== 'none'
and $this -> getData ([ 'page' , $this -> getData ([ 'locale' , 'page404' ])])
) {
header ( 'Location:' . helper :: baseUrl () . $this -> getData ([ 'locale' , 'page404' ]));
2021-06-14 18:37:45 +02:00
} else {
$this -> addOutput ([
'title' => 'Page indisponible' ,
'content' => template :: speech ( 'Oups ! La page demandée n\'existe pas ou est introuvable (erreur 404)' )
]);
2021-06-07 10:16:09 +02:00
}
2021-06-14 18:37:45 +02:00
}
// Mise en forme des métas
2022-10-04 14:06:52 +02:00
if ( $this -> output [ 'metaTitle' ] === '' ) {
if ( $this -> output [ 'title' ]) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'metaTitle' => strip_tags ( $this -> output [ 'title' ]) . ' - ' . $this -> getData ([ 'locale' , 'title' ])
]);
2022-10-04 14:06:52 +02:00
} else {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'metaTitle' => $this -> getData ([ 'locale' , 'title' ])
]);
2021-06-07 10:16:09 +02:00
}
}
2022-10-04 14:06:52 +02:00
if ( $this -> output [ 'metaDescription' ] === '' ) {
2021-06-14 18:37:45 +02:00
$this -> addOutput ([
'metaDescription' => $this -> getData ([ 'locale' , 'metaDescription' ])
]);
};
2022-10-04 14:06:52 +02:00
switch ( $this -> output [ 'display' ]) {
// Layout brut
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_RAW :
echo $this -> output [ 'content' ];
break ;
2022-10-04 14:06:52 +02:00
// Layout vide
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_LAYOUT_BLANK :
require 'core/layout/blank.php' ;
break ;
2022-10-04 14:06:52 +02:00
// Affichage en JSON
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_JSON :
header ( 'Content-Type: application/json' );
echo json_encode ( $this -> output [ 'content' ]);
break ;
2022-10-04 14:06:52 +02:00
// RSS feed
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_RSS :
header ( 'Content-type: application/rss+xml; charset=UTF-8' );
echo $this -> output [ 'content' ];
break ;
2022-10-04 14:06:52 +02:00
// Layout allégé
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_LAYOUT_LIGHT :
require 'core/layout/light.php' ;
break ;
2022-10-04 14:06:52 +02:00
// Layout principal
2021-06-14 18:37:45 +02:00
case self :: DISPLAY_LAYOUT_MAIN :
require 'core/layout/main.php' ;
break ;
2021-06-07 10:16:09 +02:00
}
}
}