securité des modules du coeur
This commit is contained in:
parent
1bd9cf41ef
commit
b0e8cfbb9e
|
@ -4,6 +4,7 @@
|
|||
- Modifications :
|
||||
- Une troisième langue d'administration est disponible : espagnol / castillan,
|
||||
- Thème / Menu : le menu en petit écran (burger) dispose maintenant de ses propres paramètres,
|
||||
- Modules du coeur et de page : renforcement de la sécurité,
|
||||
- Langues : la traduction automatique est supprimée, ce qui parachève la dégooglisation de Deltacms,
|
||||
- Edition de page / emplacement dans le menu : une page désactivée est signalée par le curseur 'not-allowed' et par une typographie italique en petit écran, son lien est inactif,
|
||||
- Nouveaux gabarits pour l'éditeur Tinymce : accordéon à 3 et 4 paragraphes,
|
||||
|
|
|
@ -48,42 +48,52 @@ class addon extends common {
|
|||
* Effacement d'un module installé et non utilisé
|
||||
*/
|
||||
public function delete() {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['delete'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['delete'][0]
|
||||
]);
|
||||
}
|
||||
else{
|
||||
// Suppression des dossiers
|
||||
$infoModules = helper::getModules();
|
||||
$module = $this->getUrl(2);
|
||||
//Liste des dossiers associés au module non effacés
|
||||
if( $this->removeDir('./module/'.$module ) === true ){
|
||||
$success = true;
|
||||
$notification = 'Module '. $module .$text['core_addon']['delete'][1];
|
||||
if( is_dir($infoModules[$this->getUrl(2)]['dataDirectory']) ) {
|
||||
if (!$this->removeDir($infoModules[$this->getUrl(2)]['dataDirectory'])){
|
||||
$notification = 'Module '.$module .$text['core_addon']['delete'][2] . $infoModules[$this->getUrl(2)]['dataDirectory'];
|
||||
}
|
||||
}
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['delete'][0]
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$success = false;
|
||||
$notification = $text['core_addon']['delete'][3];
|
||||
// Suppression des dossiers
|
||||
$infoModules = helper::getModules();
|
||||
$module = $this->getUrl(2);
|
||||
//Liste des dossiers associés au module non effacés
|
||||
if( $this->removeDir('./module/'.$module ) === true ){
|
||||
$success = true;
|
||||
$notification = 'Module '. $module .$text['core_addon']['delete'][1];
|
||||
if( is_dir($infoModules[$this->getUrl(2)]['dataDirectory']) ) {
|
||||
if (!$this->removeDir($infoModules[$this->getUrl(2)]['dataDirectory'])){
|
||||
$notification = 'Module '.$module .$text['core_addon']['delete'][2] . $infoModules[$this->getUrl(2)]['dataDirectory'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$success = false;
|
||||
$notification = $text['core_addon']['delete'][3];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'notification' => $notification,
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'notification' => $notification,
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,308 +216,367 @@ class addon extends common {
|
|||
* Installation d'un module à partir du gestionnaire de fichier
|
||||
*/
|
||||
public function upload() {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Installation d'un module
|
||||
$checkValidMaj = $this->getInput('configModulesCheck', helper::FILTER_BOOLEAN);
|
||||
$zipFilename = $this->getInput('configModulesInstallation', helper::FILTER_STRING_SHORT);
|
||||
if( $zipFilename !== ''){
|
||||
$success = [
|
||||
'success' => false,
|
||||
'notification'=> ''
|
||||
];
|
||||
$state = $this->install(self::FILE_DIR.'source/'.$zipFilename, $checkValidMaj);
|
||||
}
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['upload'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(),
|
||||
'notification' => $state['notification'],
|
||||
'state' => $state['success']
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Installation d'un module
|
||||
$checkValidMaj = $this->getInput('configModulesCheck', helper::FILTER_BOOLEAN);
|
||||
$zipFilename = $this->getInput('configModulesInstallation', helper::FILTER_STRING_SHORT);
|
||||
if( $zipFilename !== ''){
|
||||
$success = [
|
||||
'success' => false,
|
||||
'notification'=> ''
|
||||
];
|
||||
$state = $this->install(self::FILE_DIR.'source/'.$zipFilename, $checkValidMaj);
|
||||
}
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(),
|
||||
'notification' => $state['notification'],
|
||||
'state' => $state['success']
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_addon']['upload'][0],
|
||||
'view' => 'upload'
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_addon']['upload'][0],
|
||||
'view' => 'upload'
|
||||
]);
|
||||
}
|
||||
|
||||
/***
|
||||
* Installation d'un module par le catalogue
|
||||
*/
|
||||
public function uploadItem() {
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['uploadItem'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'store',
|
||||
'state' => false,
|
||||
'notification' => 'Action non autorisée'
|
||||
]);
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Récupérer le module en ligne
|
||||
$moduleName = $this->getUrl(2);
|
||||
// Informations sur les module en ligne
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
// Url du module à télécharger
|
||||
$moduleFilePath = $store[$moduleName]['file'];
|
||||
// Télécharger le fichier
|
||||
$moduleData = helper::urlGetContents(self::BASEURL_STORE . self::FILE_DIR . 'source/' . $moduleFilePath);
|
||||
// Extraire de l'arborescence
|
||||
$d = explode('/',$moduleFilePath);
|
||||
$moduleFile = $d[count($d)-1];
|
||||
// Créer le dossier modules
|
||||
if (!is_dir(self::FILE_DIR . 'source/modules')) {
|
||||
mkdir (self::FILE_DIR . 'source/modules', 0755);
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'store',
|
||||
'state' => false,
|
||||
'notification' => 'Action non autorisée'
|
||||
]);
|
||||
} else {
|
||||
// Récupérer le module en ligne
|
||||
$moduleName = $this->getUrl(2);
|
||||
// Informations sur les module en ligne
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
// Url du module à télécharger
|
||||
$moduleFilePath = $store[$moduleName]['file'];
|
||||
// Télécharger le fichier
|
||||
$moduleData = helper::urlGetContents(self::BASEURL_STORE . self::FILE_DIR . 'source/' . $moduleFilePath);
|
||||
// Extraire de l'arborescence
|
||||
$d = explode('/',$moduleFilePath);
|
||||
$moduleFile = $d[count($d)-1];
|
||||
// Créer le dossier modules
|
||||
if (!is_dir(self::FILE_DIR . 'source/modules')) {
|
||||
mkdir (self::FILE_DIR . 'source/modules', 0755);
|
||||
}
|
||||
// Sauver les données du fichiers
|
||||
file_put_contents(self::FILE_DIR . 'source/modules/' . $moduleFile, $moduleData);
|
||||
|
||||
/**
|
||||
* $if( $moduleFile !== ''){
|
||||
* $success = [
|
||||
* 'success' => false,
|
||||
* 'notification'=> ''
|
||||
* ];
|
||||
* $state = $this->install(self::FILE_DIR.'source/modules/'.$moduleFile, false);
|
||||
*}
|
||||
*/
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon/store',
|
||||
'notification' => $moduleFile . ' téléchargé dans le dossier modules du gestionnaire de fichiers',
|
||||
'state' => true
|
||||
]);
|
||||
|
||||
}
|
||||
// Sauver les données du fichiers
|
||||
file_put_contents(self::FILE_DIR . 'source/modules/' . $moduleFile, $moduleData);
|
||||
|
||||
/**
|
||||
* $if( $moduleFile !== ''){
|
||||
* $success = [
|
||||
* 'success' => false,
|
||||
* 'notification'=> ''
|
||||
* ];
|
||||
* $state = $this->install(self::FILE_DIR.'source/modules/'.$moduleFile, false);
|
||||
*}
|
||||
*/
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon/store',
|
||||
'notification' => $moduleFile . ' téléchargé dans le dossier modules du gestionnaire de fichiers',
|
||||
'state' => true
|
||||
'title' => 'Catalogue de modules',
|
||||
'view' => 'store'
|
||||
]);
|
||||
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Catalogue de modules',
|
||||
'view' => 'store'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalogue des modules sur le site DeltaCMS.fr
|
||||
*/
|
||||
public function store() {
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
if ($store) {
|
||||
// Modules installés
|
||||
$infoModules = helper::getModules();
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
foreach( $inPages as $key=>$value){
|
||||
$inPagesTitle[ $this->getData(['page', $key, 'title' ]) ] = $value;
|
||||
}
|
||||
// Parcourir les données des modules
|
||||
foreach ($store as $key=>$value) {
|
||||
// Module non installé
|
||||
$ico = template::ico('download');
|
||||
$class = '';
|
||||
// Le module est installé
|
||||
if (array_key_exists($key,$infoModules) === true) {
|
||||
$class = 'buttonGreen';
|
||||
$ico = template::ico('update');
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['store'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
if ($store) {
|
||||
// Modules installés
|
||||
$infoModules = helper::getModules();
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
foreach( $inPages as $key=>$value){
|
||||
$inPagesTitle[ $this->getData(['page', $key, 'title' ]) ] = $value;
|
||||
}
|
||||
// Le module est installé et utilisé
|
||||
if (in_array($key,$inPages) === true) {
|
||||
$class = 'buttonRed';
|
||||
$ico = template::ico('update');
|
||||
// Parcourir les données des modules
|
||||
foreach ($store as $key=>$value) {
|
||||
// Module non installé
|
||||
$ico = template::ico('download');
|
||||
$class = '';
|
||||
// Le module est installé
|
||||
if (array_key_exists($key,$infoModules) === true) {
|
||||
$class = 'buttonGreen';
|
||||
$ico = template::ico('update');
|
||||
}
|
||||
// Le module est installé et utilisé
|
||||
if (in_array($key,$inPages) === true) {
|
||||
$class = 'buttonRed';
|
||||
$ico = template::ico('update');
|
||||
}
|
||||
self::$storeList [] = [
|
||||
$store[$key]['category'],
|
||||
'<a href="' . self::BASEURL_STORE . self::MODULE_STORE . $key . '" target="_blank" >'.$store[$key]['title'].'</a>',
|
||||
$store[$key]['version'],
|
||||
mb_detect_encoding(strftime('%d %B %Y', $store[$key]['versionDate']), 'UTF-8', true)
|
||||
? strftime('%d %B %Y', $store[$key]['versionDate'])
|
||||
: utf8_encode(strftime('%d %B %Y', $store[$key]['versionDate'])),
|
||||
implode(', ', array_keys($inPagesTitle,$key)),
|
||||
template::button('moduleExport' . $key, [
|
||||
'class' => $class,
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/uploadItem/' . $key.'/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => $ico
|
||||
])
|
||||
];
|
||||
}
|
||||
self::$storeList [] = [
|
||||
$store[$key]['category'],
|
||||
'<a href="' . self::BASEURL_STORE . self::MODULE_STORE . $key . '" target="_blank" >'.$store[$key]['title'].'</a>',
|
||||
$store[$key]['version'],
|
||||
mb_detect_encoding(strftime('%d %B %Y', $store[$key]['versionDate']), 'UTF-8', true)
|
||||
? strftime('%d %B %Y', $store[$key]['versionDate'])
|
||||
: utf8_encode(strftime('%d %B %Y', $store[$key]['versionDate'])),
|
||||
implode(', ', array_keys($inPagesTitle,$key)),
|
||||
template::button('moduleExport' . $key, [
|
||||
'class' => $class,
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/uploadItem/' . $key.'/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => $ico
|
||||
])
|
||||
];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Catalogue de modules en ligne',
|
||||
'view' => 'store'
|
||||
]);
|
||||
}
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => 'Catalogue de modules en ligne',
|
||||
'view' => 'store'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Détail d'un objet du catalogue
|
||||
*/
|
||||
public function item() {
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
self::$storeItem = $store [$this->getUrl(2)] ;
|
||||
self::$storeItem ['fileDate'] = mb_detect_encoding(strftime('%d %B %Y',self::$storeItem ['fileDate']), 'UTF-8', true)
|
||||
? strftime('%d %B %Y', self::$storeItem ['fileDate'])
|
||||
: utf8_encode(strftime('%d %B %Y', self::$storeItem ['fileDate']));
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' =>'Module ' . self::$storeItem['title'],
|
||||
'view' => 'item'
|
||||
]);
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['item'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
$store = json_decode(helper::urlGetContents(self::BASEURL_STORE . self::MODULE_STORE . 'list'), true);
|
||||
self::$storeItem = $store [$this->getUrl(2)] ;
|
||||
self::$storeItem ['fileDate'] = mb_detect_encoding(strftime('%d %B %Y',self::$storeItem ['fileDate']), 'UTF-8', true)
|
||||
? strftime('%d %B %Y', self::$storeItem ['fileDate'])
|
||||
: utf8_encode(strftime('%d %B %Y', self::$storeItem ['fileDate']));
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' =>'Module ' . self::$storeItem['title'],
|
||||
'view' => 'item'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestion des modules
|
||||
*/
|
||||
public function index() {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['index'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Lister les modules
|
||||
// $infoModules[nom_module]['realName'], ['version'], ['update'], ['delete'], ['dataDirectory']
|
||||
$infoModules = helper::getModules();
|
||||
// Lister les modules
|
||||
// $infoModules[nom_module]['realName'], ['version'], ['update'], ['delete'], ['dataDirectory']
|
||||
$infoModules = helper::getModules();
|
||||
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
foreach( $inPages as $key=>$value){
|
||||
$inPagesTitle[ $this->getData(['page', $key, 'title' ]) ] = $value;
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
foreach( $inPages as $key=>$value){
|
||||
$inPagesTitle[ $this->getData(['page', $key, 'title' ]) ] = $value;
|
||||
}
|
||||
|
||||
// Parcourir les données des modules
|
||||
foreach ($infoModules as $key=>$value) {
|
||||
// Construire le tableau de sortie
|
||||
self::$modInstal[] = [
|
||||
$key,
|
||||
$infoModules[$key]['realName'],
|
||||
$infoModules[$key]['version'],
|
||||
implode(', ', array_keys($inPagesTitle,$key)),
|
||||
//|| ('delete',$infoModules[$key]) && $infoModules[$key]['delete'] === true && implode(', ',array_keys($inPages,$key)) === ''
|
||||
$infoModules[$key]['delete'] === true && implode(', ',array_keys($inPages,$key)) === ''
|
||||
? template::button('moduleDelete' . $key, [
|
||||
'class' => 'moduleDelete buttonRed',
|
||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $key . '/' . $_SESSION['csrf'],
|
||||
'value' => template::ico('cancel')
|
||||
])
|
||||
: '',
|
||||
implode(', ',array_keys($inPages,$key)) !== ''
|
||||
? template::button('moduleExport' . $key, [
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/export/' . $key . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => template::ico('download')
|
||||
])
|
||||
: '',
|
||||
implode(', ',array_keys($inPages,$key)) === ''
|
||||
? template::button('moduleExport' . $key, [
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/import/' . $key . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => template::ico('upload')
|
||||
])
|
||||
: ''
|
||||
];
|
||||
}
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_addon']['index'][0],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
|
||||
// Parcourir les données des modules
|
||||
foreach ($infoModules as $key=>$value) {
|
||||
// Construire le tableau de sortie
|
||||
self::$modInstal[] = [
|
||||
$key,
|
||||
$infoModules[$key]['realName'],
|
||||
$infoModules[$key]['version'],
|
||||
implode(', ', array_keys($inPagesTitle,$key)),
|
||||
//|| ('delete',$infoModules[$key]) && $infoModules[$key]['delete'] === true && implode(', ',array_keys($inPages,$key)) === ''
|
||||
$infoModules[$key]['delete'] === true && implode(', ',array_keys($inPages,$key)) === ''
|
||||
? template::button('moduleDelete' . $key, [
|
||||
'class' => 'moduleDelete buttonRed',
|
||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $key . '/' . $_SESSION['csrf'],
|
||||
'value' => template::ico('cancel')
|
||||
])
|
||||
: '',
|
||||
implode(', ',array_keys($inPages,$key)) !== ''
|
||||
? template::button('moduleExport' . $key, [
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/export/' . $key . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => template::ico('download')
|
||||
])
|
||||
: '',
|
||||
implode(', ',array_keys($inPages,$key)) === ''
|
||||
? template::button('moduleExport' . $key, [
|
||||
'href' => helper::baseUrl(). $this->getUrl(0) . '/import/' . $key . '/' . $_SESSION['csrf'],// appel de fonction vaut exécution, utiliser un paramètre
|
||||
'value' => template::ico('upload')
|
||||
])
|
||||
: ''
|
||||
];
|
||||
}
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_addon']['index'][0],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Export des données d'un module externes ou interne à module.json
|
||||
*/
|
||||
public function export(){
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['export'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['export'][0]
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// Lire les données du module
|
||||
$infoModules = helper::getModules();
|
||||
// Créer un dossier par défaut
|
||||
$tmpFolder = self::TEMP_DIR . uniqid();
|
||||
//$tmpFolder = self::TEMP_DIR . 'test';
|
||||
if (!is_dir($tmpFolder)) {
|
||||
mkdir($tmpFolder, 0755);
|
||||
}
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
// Parcourir les pages utilisant le module
|
||||
foreach (array_keys($inPages,$this->getUrl(2)) as $pageId) {
|
||||
// Export des pages hébergeant le module
|
||||
$pageParam[$pageId] = $this->getData(['page',$pageId]);
|
||||
// Export du contenu de la page
|
||||
//$pageContent[$pageId] = file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $pageId, 'content']));
|
||||
$pageContent[$pageId] = $this->getPage($pageId, self::$i18n);
|
||||
// Export de base/module.json
|
||||
$moduleId = 'base/module.json';
|
||||
$moduleDir = str_replace('site/data/','',$infoModules[$this->getUrl(2)]['dataDirectory']);
|
||||
// Création de l'arborescence des langues
|
||||
// Pas de nom dossier de langue - dossier par défaut
|
||||
$t = explode ('/',$moduleId);
|
||||
if ( is_array($t)) {
|
||||
$lang = 'base';
|
||||
} else {
|
||||
$lang = $t[0];
|
||||
}
|
||||
// Créer le dossier temporaire si inexistant sinon le nettoyer et le créer
|
||||
if (!is_dir($tmpFolder . '/' . $lang)) {
|
||||
mkdir ($tmpFolder . '/' . $lang, 0755, true);
|
||||
} else {
|
||||
$this->removeDir($tmpFolder . '/' . $lang);
|
||||
mkdir ($tmpFolder . '/' . $lang, 0755, true);
|
||||
}
|
||||
// Créer le dossier temporaire des données du module
|
||||
if ($infoModules[$this->getUrl(2)]['dataDirectory']) {
|
||||
if (!is_dir($tmpFolder . '/' . $moduleDir)) {
|
||||
mkdir ($tmpFolder . '/' . $moduleDir, 0755, true) ;
|
||||
}
|
||||
}
|
||||
// Sauvegarde si données non vides
|
||||
$tmpData [$pageId] = $this->getData(['module',$pageId ]);
|
||||
if ($tmpData [$pageId] !== null) {
|
||||
file_put_contents($tmpFolder . '/' . $moduleId, json_encode($tmpData));
|
||||
}
|
||||
// Export des données localisées dans le dossier de données du module
|
||||
if ($infoModules[$this->getUrl(2)]['dataDirectory'] &&
|
||||
is_dir($infoModules[$this->getUrl(2)]['dataDirectory'])) {
|
||||
$this->copyDir ($infoModules[$this->getUrl(2)]['dataDirectory'], $tmpFolder . '/' . $moduleDir);
|
||||
}
|
||||
}
|
||||
// Enregistrement des pages dans le dossier de langue identique à module
|
||||
if (!file_exists($tmpFolder . '/' . $lang . '/page.json')) {
|
||||
file_put_contents($tmpFolder . '/' . $lang . '/page.json', json_encode($pageParam));
|
||||
mkdir ($tmpFolder . '/' . $lang . '/content', 0755);
|
||||
file_put_contents($tmpFolder . '/' . $lang . '/content/' . $this->getData(['page', $pageId, 'content']), $pageContent);
|
||||
}
|
||||
// création du zip
|
||||
$fileName = $this->getUrl(2) . '.zip';
|
||||
$this->makeZip ($fileName, $tmpFolder, []);
|
||||
if (file_exists($fileName)) {
|
||||
ob_start();
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
ob_clean();
|
||||
ob_end_flush();
|
||||
readfile( $fileName);
|
||||
unlink($fileName);
|
||||
$this->removeDir($tmpFolder);
|
||||
exit();
|
||||
} else {
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'notification' => $text['core_addon']['export'][1],
|
||||
'state' => false
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['export'][0]
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// Lire les données du module
|
||||
$infoModules = helper::getModules();
|
||||
// Créer un dossier par défaut
|
||||
$tmpFolder = self::TEMP_DIR . uniqid();
|
||||
//$tmpFolder = self::TEMP_DIR . 'test';
|
||||
if (!is_dir($tmpFolder)) {
|
||||
mkdir($tmpFolder, 0755);
|
||||
}
|
||||
// Clés moduleIds dans les pages
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
// Parcourir les pages utilisant le module
|
||||
foreach (array_keys($inPages,$this->getUrl(2)) as $pageId) {
|
||||
// Export des pages hébergeant le module
|
||||
$pageParam[$pageId] = $this->getData(['page',$pageId]);
|
||||
// Export du contenu de la page
|
||||
//$pageContent[$pageId] = file_get_contents(self::DATA_DIR . self::$i18n . '/content/' . $this->getData(['page', $pageId, 'content']));
|
||||
$pageContent[$pageId] = $this->getPage($pageId, self::$i18n);
|
||||
// Export de base/module.json
|
||||
$moduleId = 'base/module.json';
|
||||
$moduleDir = str_replace('site/data/','',$infoModules[$this->getUrl(2)]['dataDirectory']);
|
||||
// Création de l'arborescence des langues
|
||||
// Pas de nom dossier de langue - dossier par défaut
|
||||
$t = explode ('/',$moduleId);
|
||||
if ( is_array($t)) {
|
||||
$lang = 'base';
|
||||
} else {
|
||||
$lang = $t[0];
|
||||
}
|
||||
// Créer le dossier temporaire si inexistant sinon le nettoyer et le créer
|
||||
if (!is_dir($tmpFolder . '/' . $lang)) {
|
||||
mkdir ($tmpFolder . '/' . $lang, 0755, true);
|
||||
} else {
|
||||
$this->removeDir($tmpFolder . '/' . $lang);
|
||||
mkdir ($tmpFolder . '/' . $lang, 0755, true);
|
||||
}
|
||||
// Créer le dossier temporaire des données du module
|
||||
if ($infoModules[$this->getUrl(2)]['dataDirectory']) {
|
||||
if (!is_dir($tmpFolder . '/' . $moduleDir)) {
|
||||
mkdir ($tmpFolder . '/' . $moduleDir, 0755, true) ;
|
||||
}
|
||||
}
|
||||
// Sauvegarde si données non vides
|
||||
$tmpData [$pageId] = $this->getData(['module',$pageId ]);
|
||||
if ($tmpData [$pageId] !== null) {
|
||||
file_put_contents($tmpFolder . '/' . $moduleId, json_encode($tmpData));
|
||||
}
|
||||
// Export des données localisées dans le dossier de données du module
|
||||
if ($infoModules[$this->getUrl(2)]['dataDirectory'] &&
|
||||
is_dir($infoModules[$this->getUrl(2)]['dataDirectory'])) {
|
||||
$this->copyDir ($infoModules[$this->getUrl(2)]['dataDirectory'], $tmpFolder . '/' . $moduleDir);
|
||||
}
|
||||
}
|
||||
// Enregistrement des pages dans le dossier de langue identique à module
|
||||
if (!file_exists($tmpFolder . '/' . $lang . '/page.json')) {
|
||||
file_put_contents($tmpFolder . '/' . $lang . '/page.json', json_encode($pageParam));
|
||||
mkdir ($tmpFolder . '/' . $lang . '/content', 0755);
|
||||
file_put_contents($tmpFolder . '/' . $lang . '/content/' . $this->getData(['page', $pageId, 'content']), $pageContent);
|
||||
}
|
||||
// création du zip
|
||||
$fileName = $this->getUrl(2) . '.zip';
|
||||
$this->makeZip ($fileName, $tmpFolder, []);
|
||||
if (file_exists($fileName)) {
|
||||
ob_start();
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
ob_clean();
|
||||
ob_end_flush();
|
||||
readfile( $fileName);
|
||||
unlink($fileName);
|
||||
$this->removeDir($tmpFolder);
|
||||
exit();
|
||||
} else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'notification' => $text['core_addon']['export'][1],
|
||||
'state' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,94 +584,104 @@ class addon extends common {
|
|||
* Importer des données d'un module externes ou interne à module.json
|
||||
*/
|
||||
public function import(){
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < addon::$actions['import'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['import'][0]
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Récupérer le fichier et le décompacter
|
||||
$zipFilename = $this->getInput('addonImportFile', helper::FILTER_STRING_SHORT, true);
|
||||
$tempFolder = uniqid();
|
||||
mkdir (self::TEMP_DIR . $tempFolder, 0755);
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open(self::FILE_DIR . 'source/' . $zipFilename) === TRUE) {
|
||||
$zip->extractTo(self::TEMP_DIR . $tempFolder );
|
||||
}
|
||||
// Import des données localisées page.json et module.json
|
||||
// Pour chaque dossier localisé
|
||||
$dataTarget = array();
|
||||
$dataSource = array();
|
||||
// Liste des pages de même nom dans l'archive et le site
|
||||
$list = '';
|
||||
// Tableau des langues avec langue originale
|
||||
$origin = ['base'=>'Langue originale'];
|
||||
$i18nListComplet = array_merge( self::$i18nList, $origin);
|
||||
foreach ($i18nListComplet as $key=>$value) {
|
||||
// Les Pages et les modules
|
||||
foreach (['page','module'] as $fileTarget){
|
||||
if (file_exists(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json')) {
|
||||
// Le dossier de langue existe
|
||||
// faire la fusion
|
||||
$dataSource = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'), true);
|
||||
// Des pages de même nom que celles de l'archive existent
|
||||
if( $fileTarget === 'page' ){
|
||||
foreach( $dataSource as $keydataSource=>$valuedataSource ){
|
||||
foreach( $this->getData(['page']) as $keypage=>$valuepage ){
|
||||
if( $keydataSource === $keypage){
|
||||
$list === '' ? $list .= ' '.$this->getData(['page', $keypage, 'title']) : $list .= ', '.$this->getData(['page', $keypage, 'title']);
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/addon/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_addon.php');
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => false,
|
||||
'notification' => $text['core_addon']['import'][0]
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Récupérer le fichier et le décompacter
|
||||
$zipFilename = $this->getInput('addonImportFile', helper::FILTER_STRING_SHORT, true);
|
||||
$tempFolder = uniqid();
|
||||
mkdir (self::TEMP_DIR . $tempFolder, 0755);
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open(self::FILE_DIR . 'source/' . $zipFilename) === TRUE) {
|
||||
$zip->extractTo(self::TEMP_DIR . $tempFolder );
|
||||
}
|
||||
// Import des données localisées page.json et module.json
|
||||
// Pour chaque dossier localisé
|
||||
$dataTarget = array();
|
||||
$dataSource = array();
|
||||
// Liste des pages de même nom dans l'archive et le site
|
||||
$list = '';
|
||||
// Tableau des langues avec langue originale
|
||||
$origin = ['base'=>'Langue originale'];
|
||||
$i18nListComplet = array_merge( self::$i18nList, $origin);
|
||||
foreach ($i18nListComplet as $key=>$value) {
|
||||
// Les Pages et les modules
|
||||
foreach (['page','module'] as $fileTarget){
|
||||
if (file_exists(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json')) {
|
||||
// Le dossier de langue existe
|
||||
// faire la fusion
|
||||
$dataSource = json_decode(file_get_contents(self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json'), true);
|
||||
// Des pages de même nom que celles de l'archive existent
|
||||
if( $fileTarget === 'page' ){
|
||||
foreach( $dataSource as $keydataSource=>$valuedataSource ){
|
||||
foreach( $this->getData(['page']) as $keypage=>$valuepage ){
|
||||
if( $keydataSource === $keypage){
|
||||
$list === '' ? $list .= ' '.$this->getData(['page', $keypage, 'title']) : $list .= ', '.$this->getData(['page', $keypage, 'title']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$dataTarget = json_decode(file_get_contents(self::DATA_DIR . $key . '/' . $fileTarget . '.json'), true);
|
||||
$data [$fileTarget] = array_merge($dataTarget[$fileTarget], $dataSource);
|
||||
if( $list === ''){
|
||||
file_put_contents(self::DATA_DIR . '/' .$key . '/' . $fileTarget . '.json', json_encode( $data ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX) );
|
||||
}
|
||||
// copie du contenu de la page
|
||||
$this->copyDir (self::TEMP_DIR . $tempFolder . '/' .$key . '/content', self::DATA_DIR . '/' .$key . '/content');
|
||||
// Supprimer les fichiers importés
|
||||
unlink (self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json');
|
||||
}
|
||||
$dataTarget = json_decode(file_get_contents(self::DATA_DIR . $key . '/' . $fileTarget . '.json'), true);
|
||||
$data [$fileTarget] = array_merge($dataTarget[$fileTarget], $dataSource);
|
||||
if( $list === ''){
|
||||
file_put_contents(self::DATA_DIR . '/' .$key . '/' . $fileTarget . '.json', json_encode( $data ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX) );
|
||||
}
|
||||
// copie du contenu de la page
|
||||
$this->copyDir (self::TEMP_DIR . $tempFolder . '/' .$key . '/content', self::DATA_DIR . '/' .$key . '/content');
|
||||
// Supprimer les fichiers importés
|
||||
unlink (self::TEMP_DIR . $tempFolder . '/' .$key . '/' . $fileTarget . '.json');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Import des fichiers placés ailleurs que dans les dossiers localisés.
|
||||
$this->copyDir (self::TEMP_DIR . $tempFolder,self::DATA_DIR );
|
||||
// Import des fichiers placés ailleurs que dans les dossiers localisés.
|
||||
$this->copyDir (self::TEMP_DIR . $tempFolder,self::DATA_DIR );
|
||||
|
||||
// Supprimer le dossier temporaire
|
||||
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
||||
$zip->close();
|
||||
if( $list !== '' ){
|
||||
$success = false;
|
||||
strpos( $list, ',') === false ? $notification = $text['core_addon']['import'][1].$list : $notification = $text['core_addon']['import'][2].$list;
|
||||
}
|
||||
else{
|
||||
$success = true;
|
||||
$notification = $text['core_addon']['import'][3];
|
||||
// Supprimer le dossier temporaire
|
||||
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
||||
$zip->close();
|
||||
if( $list !== '' ){
|
||||
$success = false;
|
||||
strpos( $list, ',') === false ? $notification = $text['core_addon']['import'][1].$list : $notification = $text['core_addon']['import'][2].$list;
|
||||
}
|
||||
else{
|
||||
$success = true;
|
||||
$notification = $text['core_addon']['import'][3];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => $success,
|
||||
'notification' => $notification
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'addon',
|
||||
'state' => $success,
|
||||
'notification' => $notification
|
||||
'title' => $text['core_addon']['import'][4],
|
||||
'view' => 'import'
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_addon']['import'][4],
|
||||
'view' => 'import'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -205,114 +205,124 @@ class install extends common {
|
|||
* Étapes de mise à jour
|
||||
*/
|
||||
public function steps() {
|
||||
switch($this->getInput('step', helper::FILTER_INT)) {
|
||||
// Préparation
|
||||
case 1:
|
||||
$success = true;
|
||||
// RAZ la mise à jour auto
|
||||
$this->setData(['core','updateAvailable', false]);
|
||||
// Backup du dossier Data
|
||||
helper::autoBackup(self::BACKUP_DIR,['backup','tmp','file']);
|
||||
// Sauvegarde htaccess
|
||||
if ($this->getData(['config','autoUpdateHtaccess'])) {
|
||||
$success = copy('.htaccess', '.htaccess' . '.bak');
|
||||
}
|
||||
// Nettoyage des fichiers d'installation précédents
|
||||
if(file_exists(self::TEMP_DIR.'update.tar.gz') && $success) {
|
||||
$success = unlink(self::TEMP_DIR.'update.tar.gz');
|
||||
}
|
||||
if(file_exists(self::TEMP_DIR.'update.tar') && $success) {
|
||||
$success = unlink(self::TEMP_DIR.'update.tar');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Téléchargement
|
||||
case 2:
|
||||
$success = (file_put_contents(self::TEMP_DIR.'update.tar.gz', helper::urlGetContents(common::DELTA_UPDATE_URL . common::DELTA_UPDATE_CHANNEL . '/update.tar.gz')) !== false);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Installation
|
||||
case 3:
|
||||
$success = true;
|
||||
// Check la réécriture d'URL avant d'écraser les fichiers
|
||||
$rewrite = helper::checkRewrite();
|
||||
// Décompression et installation
|
||||
try {
|
||||
// Décompression dans le dossier de fichier temporaires
|
||||
$pharData = new PharData(self::TEMP_DIR.'update.tar.gz');
|
||||
$pharData->decompress();
|
||||
// Installation
|
||||
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
||||
} catch (Exception $e) {
|
||||
$success = $e->getMessage();
|
||||
}
|
||||
// Nettoyage du dossier
|
||||
if(file_exists(self::TEMP_DIR.'update.tar.gz')) {
|
||||
unlink(self::TEMP_DIR.'update.tar.gz');
|
||||
}
|
||||
if(file_exists(self::TEMP_DIR.'update.tar')) {
|
||||
unlink(self::TEMP_DIR.'update.tar');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => $rewrite
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Configuration
|
||||
case 4:
|
||||
$success = true;
|
||||
$rewrite = $this->getInput('data');
|
||||
// Réécriture d'URL
|
||||
if ($rewrite === "true") {
|
||||
$success = (file_put_contents(
|
||||
'.htaccess',
|
||||
PHP_EOL .
|
||||
'<IfModule mod_rewrite.c>' . PHP_EOL .
|
||||
"\tRewriteEngine on" . PHP_EOL .
|
||||
"\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL .
|
||||
"\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL .
|
||||
"\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL .
|
||||
"\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL .
|
||||
'</IfModule>',
|
||||
FILE_APPEND
|
||||
) !== false);
|
||||
}
|
||||
// Recopie htaccess
|
||||
if ($this->getData(['config','autoUpdateHtaccess']) &&
|
||||
$success && file_exists( '.htaccess.bak')
|
||||
) {
|
||||
// L'écraser avec le backup
|
||||
$success = copy( '.htaccess.bak' ,'.htaccess' );
|
||||
// Effacer l ebackup
|
||||
unlink('.htaccess.bak');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < install::$actions['steps'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
switch($this->getInput('step', helper::FILTER_INT)) {
|
||||
// Préparation
|
||||
case 1:
|
||||
$success = true;
|
||||
// RAZ la mise à jour auto
|
||||
$this->setData(['core','updateAvailable', false]);
|
||||
// Backup du dossier Data
|
||||
helper::autoBackup(self::BACKUP_DIR,['backup','tmp','file']);
|
||||
// Sauvegarde htaccess
|
||||
if ($this->getData(['config','autoUpdateHtaccess'])) {
|
||||
$success = copy('.htaccess', '.htaccess' . '.bak');
|
||||
}
|
||||
// Nettoyage des fichiers d'installation précédents
|
||||
if(file_exists(self::TEMP_DIR.'update.tar.gz') && $success) {
|
||||
$success = unlink(self::TEMP_DIR.'update.tar.gz');
|
||||
}
|
||||
if(file_exists(self::TEMP_DIR.'update.tar') && $success) {
|
||||
$success = unlink(self::TEMP_DIR.'update.tar');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Téléchargement
|
||||
case 2:
|
||||
$success = (file_put_contents(self::TEMP_DIR.'update.tar.gz', helper::urlGetContents(common::DELTA_UPDATE_URL . common::DELTA_UPDATE_CHANNEL . '/update.tar.gz')) !== false);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Installation
|
||||
case 3:
|
||||
$success = true;
|
||||
// Check la réécriture d'URL avant d'écraser les fichiers
|
||||
$rewrite = helper::checkRewrite();
|
||||
// Décompression et installation
|
||||
try {
|
||||
// Décompression dans le dossier de fichier temporaires
|
||||
$pharData = new PharData(self::TEMP_DIR.'update.tar.gz');
|
||||
$pharData->decompress();
|
||||
// Installation
|
||||
$pharData->extractTo(__DIR__ . '/../../../', null, true);
|
||||
} catch (Exception $e) {
|
||||
$success = $e->getMessage();
|
||||
}
|
||||
// Nettoyage du dossier
|
||||
if(file_exists(self::TEMP_DIR.'update.tar.gz')) {
|
||||
unlink(self::TEMP_DIR.'update.tar.gz');
|
||||
}
|
||||
if(file_exists(self::TEMP_DIR.'update.tar')) {
|
||||
unlink(self::TEMP_DIR.'update.tar');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => $rewrite
|
||||
]
|
||||
]);
|
||||
break;
|
||||
// Configuration
|
||||
case 4:
|
||||
$success = true;
|
||||
$rewrite = $this->getInput('data');
|
||||
// Réécriture d'URL
|
||||
if ($rewrite === "true") {
|
||||
$success = (file_put_contents(
|
||||
'.htaccess',
|
||||
PHP_EOL .
|
||||
'<IfModule mod_rewrite.c>' . PHP_EOL .
|
||||
"\tRewriteEngine on" . PHP_EOL .
|
||||
"\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL .
|
||||
"\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL .
|
||||
"\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL .
|
||||
"\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL .
|
||||
'</IfModule>',
|
||||
FILE_APPEND
|
||||
) !== false);
|
||||
}
|
||||
// Recopie htaccess
|
||||
if ($this->getData(['config','autoUpdateHtaccess']) &&
|
||||
$success && file_exists( '.htaccess.bak')
|
||||
) {
|
||||
// L'écraser avec le backup
|
||||
$success = copy( '.htaccess.bak' ,'.htaccess' );
|
||||
// Effacer l ebackup
|
||||
unlink('.htaccess.bak');
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_JSON,
|
||||
'content' => [
|
||||
'success' => $success,
|
||||
'data' => null
|
||||
]
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,16 +330,26 @@ class install extends common {
|
|||
* Mise à jour
|
||||
*/
|
||||
public function update() {
|
||||
// Lexique
|
||||
include('./core/module/install/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_install.php');
|
||||
// Nouvelle version
|
||||
self::$newVersion = helper::urlGetContents(common::DELTA_UPDATE_URL . common::DELTA_UPDATE_CHANNEL . '/version');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
||||
'title' => $text['core_install']['update'][0],
|
||||
'view' => 'update'
|
||||
]);
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < install::$actions['update'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/install/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_install.php');
|
||||
// Nouvelle version
|
||||
self::$newVersion = helper::urlGetContents(common::DELTA_UPDATE_URL . common::DELTA_UPDATE_CHANNEL . '/version');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'display' => self::DISPLAY_LAYOUT_LIGHT,
|
||||
'title' => $text['core_install']['update'][0],
|
||||
'view' => 'update'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ $text['core_page_view']['edit'][43] = " will be deleted. Do you confirm?";
|
|||
$text['core_page_view']['edit'][44] = "Group required to edit the page :";
|
||||
$text['core_page_view']['edit'][45] = "You do not have editing rights, contact an administrator.";
|
||||
$text['core_page']['duplicate'][0] = "Invalid token";
|
||||
$text['core_page']['duplicate'][1] = "Unauthorized deletion";
|
||||
$text['core_page']['duplicate'][1] = "Unauthorised duplication";
|
||||
$text['core_page']['duplicate'][2] = "The page has been duplicated";
|
||||
$text['core_page']['duplicate'][3] = "The page and its module have been duplicated";
|
||||
$text['core_page']['add'][0] = "New page";
|
||||
|
|
|
@ -47,7 +47,7 @@ $text['core_page_view']['edit'][43] = "será eliminado. ¿Confirmas?";
|
|||
$text['core_page_view']['edit'][44] = "Se requiere grupo para editar la página:";
|
||||
$text['core_page_view']['edit'][45] = "No tiene derechos de edición, póngase en contacto con un administrador.";
|
||||
$text['core_page']['duplicate'][0] = "Token no válido";
|
||||
$text['core_page']['duplicate'][1] = "Eliminación no autorizada";
|
||||
$text['core_page']['duplicate'][1] = "Duplicación no autorizada";
|
||||
$text['core_page']['duplicate'][2] = "La página ha sido duplicada";
|
||||
$text['core_page']['duplicate'][3] = "La página y su módulo han sido duplicados";
|
||||
$text['core_page']['add'][0] = "Nueva página";
|
||||
|
|
|
@ -47,7 +47,7 @@ $text['core_page_view']['edit'][43] = " seront effacées. Confirmez-vous ?";
|
|||
$text['core_page_view']['edit'][44] = "Groupe requis pour modifier la page :";
|
||||
$text['core_page_view']['edit'][45] = "Vous n'avez pas les droits d'édition, contactez un administrateur.";
|
||||
$text['core_page']['duplicate'][0] = "Jeton invalide";
|
||||
$text['core_page']['duplicate'][1] = "Suppression non autorisée";
|
||||
$text['core_page']['duplicate'][1] = "Duplication non autorisée";
|
||||
$text['core_page']['duplicate'][2] = "La page a été dupliquée";
|
||||
$text['core_page']['duplicate'][3] = "La page et son module ont été dupliqués";
|
||||
$text['core_page']['add'][0] = "Nouvelle page";
|
||||
|
|
|
@ -33,59 +33,70 @@ class page extends common {
|
|||
* Duplication
|
||||
*/
|
||||
public function duplicate() {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// Adresse sans le token
|
||||
$url = explode('&',$this->getUrl(2));
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $url[0]]) === null) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < page::$actions['duplicate'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} // Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['duplicate'][0]
|
||||
]);
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// Adresse sans le token
|
||||
$url = explode('&',$this->getUrl(2));
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $url[0]]) === null) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} // Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['duplicate'][0]
|
||||
]);
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['duplicate'][1]
|
||||
]);
|
||||
} else {
|
||||
// Duplication de la page
|
||||
$pageTitle = $this->getData(['page',$url[0],'title']);
|
||||
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
||||
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
||||
$pageId = helper::increment($pageId, self::$moduleIds);
|
||||
$data = $this->getData([
|
||||
'page',
|
||||
$url[0]
|
||||
]);
|
||||
// Ecriture
|
||||
$this->setData (['page',$pageId,$data]);
|
||||
$notification = $text['core_page']['duplicate'][2];
|
||||
// Duplication du module présent
|
||||
if ($this->getData(['page',$url[0],'moduleId'])) {
|
||||
$data = $this->getData([
|
||||
'module',
|
||||
$url[0]
|
||||
]);
|
||||
// Ecriture
|
||||
$this->setData (['module',$pageId,$data]);
|
||||
$notification = $text['core_page']['duplicate'][3];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $pageId,
|
||||
'notification' => $notification,
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['duplicate'][1]
|
||||
]);
|
||||
}
|
||||
// Duplication de la page
|
||||
$pageTitle = $this->getData(['page',$url[0],'title']);
|
||||
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
||||
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
||||
$pageId = helper::increment($pageId, self::$moduleIds);
|
||||
$data = $this->getData([
|
||||
'page',
|
||||
$url[0]
|
||||
]);
|
||||
// Ecriture
|
||||
$this->setData (['page',$pageId,$data]);
|
||||
$notification = $text['core_page']['duplicate'][2];
|
||||
// Duplication du module présent
|
||||
if ($this->getData(['page',$url[0],'moduleId'])) {
|
||||
$data = $this->getData([
|
||||
'module',
|
||||
$url[0]
|
||||
]);
|
||||
// Ecriture
|
||||
$this->setData (['module',$pageId,$data]);
|
||||
$notification = $text['core_page']['duplicate'][3];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $pageId,
|
||||
'notification' => $notification,
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,184 +104,204 @@ class page extends common {
|
|||
* Création
|
||||
*/
|
||||
public function add() {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
$pageTitle = $text['core_page']['add'][0];
|
||||
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
||||
$this->setData([
|
||||
'page',
|
||||
$pageId,
|
||||
[
|
||||
'typeMenu' => 'text',
|
||||
'iconUrl' => '',
|
||||
'disable' => false,
|
||||
'content' => $pageId . '.html',
|
||||
'hideTitle' => false,
|
||||
'breadCrumb' => false,
|
||||
'metaDescription' => '',
|
||||
'metaTitle' => '',
|
||||
'moduleId' => '',
|
||||
'parentPageId' => '',
|
||||
'modulePosition' => 'bottom',
|
||||
'position' => 100,
|
||||
'group' => self::GROUP_VISITOR,
|
||||
'targetBlank' => false,
|
||||
'title' => $pageTitle,
|
||||
'shortTitle' => $pageTitle,
|
||||
'block' => '12',
|
||||
'barLeft' => '',
|
||||
'barRight' => '',
|
||||
'displayMenu' => '0',
|
||||
'hideMenuSide' => false,
|
||||
'hideMenuHead' => false,
|
||||
'hideMenuChildren' => false
|
||||
]
|
||||
]);
|
||||
// Creation du contenu de la page
|
||||
if (!is_dir(self::DATA_DIR . self::$i18n . '/content')) {
|
||||
mkdir(self::DATA_DIR . self::$i18n . '/content', 0755);
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < page::$actions['add'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
$pageTitle = $text['core_page']['add'][0];
|
||||
$pageId = helper::increment(helper::filter($pageTitle, helper::FILTER_ID), $this->getData(['page']));
|
||||
$this->setData([
|
||||
'page',
|
||||
$pageId,
|
||||
[
|
||||
'typeMenu' => 'text',
|
||||
'iconUrl' => '',
|
||||
'disable' => false,
|
||||
'content' => $pageId . '.html',
|
||||
'hideTitle' => false,
|
||||
'breadCrumb' => false,
|
||||
'metaDescription' => '',
|
||||
'metaTitle' => '',
|
||||
'moduleId' => '',
|
||||
'parentPageId' => '',
|
||||
'modulePosition' => 'bottom',
|
||||
'position' => 100,
|
||||
'group' => self::GROUP_VISITOR,
|
||||
'targetBlank' => false,
|
||||
'title' => $pageTitle,
|
||||
'shortTitle' => $pageTitle,
|
||||
'block' => '12',
|
||||
'barLeft' => '',
|
||||
'barRight' => '',
|
||||
'displayMenu' => '0',
|
||||
'hideMenuSide' => false,
|
||||
'hideMenuHead' => false,
|
||||
'hideMenuChildren' => false
|
||||
]
|
||||
]);
|
||||
// Creation du contenu de la page
|
||||
if (!is_dir(self::DATA_DIR . self::$i18n . '/content')) {
|
||||
mkdir(self::DATA_DIR . self::$i18n . '/content', 0755);
|
||||
}
|
||||
$this->setPage($pageId, '<p>'.$text['core_page']['add'][1].'</p>', self::$i18n);
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId,
|
||||
'notification' => $text['core_page']['add'][2],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
$this->setPage($pageId, '<p>'.$text['core_page']['add'][1].'</p>', self::$i18n);
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId,
|
||||
'notification' => $text['core_page']['add'][2],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppression
|
||||
*/
|
||||
public function delete() {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// $url prend l'adresse sans le token
|
||||
$url = explode('&',$this->getUrl(2));
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $url[0]]) === null) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < page::$actions['delete'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} // Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][0]
|
||||
]);
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page d'accueil
|
||||
elseif($url[0] === $this->getData(['locale', 'homePageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page de recherche affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'searchPageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'legalPageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page404'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page403'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page302'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][0]
|
||||
]);
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer une page contenant des enfants
|
||||
elseif($this->getHierarchy($url[0],null)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][3]
|
||||
]);
|
||||
}
|
||||
// Suppression
|
||||
else {
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// $url prend l'adresse sans le token
|
||||
$url = explode('&',$this->getUrl(2));
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $url[0]]) === null) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} // Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][0]
|
||||
]);
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page d'accueil
|
||||
elseif($url[0] === $this->getData(['locale', 'homePageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page de recherche affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'searchPageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'legalPageId'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page404'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page403'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer la page des mentions légales affectée
|
||||
elseif($url[0] === $this->getData(['locale', 'page302'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'config',
|
||||
'notification' => $text['core_page']['delete'][2]
|
||||
]);
|
||||
}
|
||||
// Jeton incorrect
|
||||
elseif(!isset($_GET['csrf'])) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][0]
|
||||
]);
|
||||
}
|
||||
elseif ($_GET['csrf'] !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Impossible de supprimer une page contenant des enfants
|
||||
elseif($this->getHierarchy($url[0],null)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'page/edit/' . $url[0],
|
||||
'notification' => $text['core_page']['delete'][3]
|
||||
]);
|
||||
}
|
||||
// Suppression
|
||||
else {
|
||||
|
||||
// Effacer le dossier du module
|
||||
$moduleId = $this->getData(['page',$url[0],'moduleId']);
|
||||
$modulesData = helper::getModules();
|
||||
if (is_dir($modulesData[$moduleId]['dataDirectory']. $url[0])) {
|
||||
$this->removeDir( $modulesData[$moduleId]['dataDirectory']. $url[0] );
|
||||
// Effacer le dossier du module
|
||||
$moduleId = $this->getData(['page',$url[0],'moduleId']);
|
||||
$modulesData = helper::getModules();
|
||||
if (is_dir($modulesData[$moduleId]['dataDirectory']. $url[0])) {
|
||||
$this->removeDir( $modulesData[$moduleId]['dataDirectory']. $url[0] );
|
||||
}
|
||||
// Effacer la page
|
||||
$this->deleteData(['page', $url[0]]);
|
||||
if (file_exists(self::DATA_DIR . self::$i18n . '/content/' . $url[0] . '.html')) {
|
||||
unlink(self::DATA_DIR . self::$i18n . '/content/' . $url[0] . '.html');
|
||||
}
|
||||
$this->deleteData(['module', $url[0]]);
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Met à jour 'config', 'statislite', 'enable' si aucume page utilise le module Statislite
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
$statislite = 'off';
|
||||
foreach($inPages as $key=>$value){
|
||||
if( $value === 'statislite') $statislite = 'on';
|
||||
}
|
||||
if( $statislite === 'off') $this->setData(['config', 'statislite', 'enable', false ]);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(false),
|
||||
'notification' => $text['core_page']['delete'][4],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
// Effacer la page
|
||||
$this->deleteData(['page', $url[0]]);
|
||||
if (file_exists(self::DATA_DIR . self::$i18n . '/content/' . $url[0] . '.html')) {
|
||||
unlink(self::DATA_DIR . self::$i18n . '/content/' . $url[0] . '.html');
|
||||
}
|
||||
$this->deleteData(['module', $url[0]]);
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Met à jour 'config', 'statislite', 'enable' si aucume page utilise le module Statislite
|
||||
$inPages = helper::arrayCollumn($this->getData(['page']),'moduleId', 'SORT_DESC');
|
||||
$statislite = 'off';
|
||||
foreach($inPages as $key=>$value){
|
||||
if( $value === 'statislite') $statislite = 'on';
|
||||
}
|
||||
if( $statislite === 'off') $this->setData(['config', 'statislite', 'enable', false ]);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl(false),
|
||||
'notification' => $text['core_page']['delete'][4],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,221 +310,231 @@ class page extends common {
|
|||
* Édition
|
||||
*/
|
||||
public function edit() {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $this->getUrl(2)]) === null) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < page::$actions['edit'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// La page existe
|
||||
else {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Si le Title n'est pas vide, premier test pour positionner la notification du champ obligatoire
|
||||
if( $this->getInput('pageEditTitle', helper::FILTER_ID, true) !== null && $this->getInput('pageEditTitle') !== '' ){
|
||||
// Génére l'ID si le titre de la page a changé
|
||||
if ( $this->getInput('pageEditTitle') !== $this->getData(['page',$this->getUrl(2),'title']) ) {
|
||||
$pageId = $this->getInput('pageEditTitle', helper::FILTER_ID, true);
|
||||
} else {
|
||||
$pageId = $this->getUrl(2);
|
||||
}
|
||||
// un dossier existe du même nom (erreur en cas de redirection)
|
||||
if (file_exists($pageId)) {
|
||||
$pageId = uniqid($pageId);
|
||||
}
|
||||
// Si l'id a changée
|
||||
if ($pageId !== $this->getUrl(2)) {
|
||||
// Incrémente le nouvel id de la page
|
||||
$pageId = helper::increment($pageId, $this->getData(['page']));
|
||||
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
||||
$pageId = helper::increment($pageId, self::$moduleIds);
|
||||
// Met à jour les enfants
|
||||
foreach($this->getHierarchy($this->getUrl(2),null) as $childrenPageId) {
|
||||
$this->setData(['page', $childrenPageId, 'parentPageId', $pageId]);
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/page/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_page.php');
|
||||
// La page n'existe pas
|
||||
if($this->getData(['page', $this->getUrl(2)]) === null) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// La page existe
|
||||
else {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Si le Title n'est pas vide, premier test pour positionner la notification du champ obligatoire
|
||||
if( $this->getInput('pageEditTitle', helper::FILTER_ID, true) !== null && $this->getInput('pageEditTitle') !== '' ){
|
||||
// Génére l'ID si le titre de la page a changé
|
||||
if ( $this->getInput('pageEditTitle') !== $this->getData(['page',$this->getUrl(2),'title']) ) {
|
||||
$pageId = $this->getInput('pageEditTitle', helper::FILTER_ID, true);
|
||||
} else {
|
||||
$pageId = $this->getUrl(2);
|
||||
}
|
||||
// Change l'id de page dans les données des modules
|
||||
if ($this->getData(['module', $this->getUrl(2)]) !== null ) {
|
||||
$this->setData(['module', $pageId, $this->getData(['module', $this->getUrl(2)])]);
|
||||
$this->deleteData(['module', $this->getUrl(2)]);
|
||||
// Renommer le dossier du module
|
||||
$moduleId = $this->getData(['page',$this->getUrl(2),'moduleId']);
|
||||
$modulesData = helper::getModules();
|
||||
if (is_dir($modulesData[$moduleId]['dataDirectory']. $this->getUrl(2))) {
|
||||
// Placer la feuille de style dans un dossier au nom de la nouvelle instance
|
||||
mkdir( $modulesData[$moduleId]['dataDirectory']. $pageId, 0755 );
|
||||
copy( $modulesData[$moduleId]['dataDirectory']. $this->getUrl(2), $modulesData[$moduleId]['dataDirectory']. $pageId);
|
||||
$this->removeDir($modulesData[$moduleId]['dataDirectory']. $this->getUrl(2));
|
||||
// Mettre à jour le nom de la feuille de style
|
||||
$this->setData(['module',$pageId,'theme','style', $modulesData[$moduleId]['dataDirectory']. $pageId]);
|
||||
// un dossier existe du même nom (erreur en cas de redirection)
|
||||
if (file_exists($pageId)) {
|
||||
$pageId = uniqid($pageId);
|
||||
}
|
||||
// Si l'id a changée
|
||||
if ($pageId !== $this->getUrl(2)) {
|
||||
// Incrémente le nouvel id de la page
|
||||
$pageId = helper::increment($pageId, $this->getData(['page']));
|
||||
$pageId = helper::increment($pageId, self::$coreModuleIds);
|
||||
$pageId = helper::increment($pageId, self::$moduleIds);
|
||||
// Met à jour les enfants
|
||||
foreach($this->getHierarchy($this->getUrl(2),null) as $childrenPageId) {
|
||||
$this->setData(['page', $childrenPageId, 'parentPageId', $pageId]);
|
||||
}
|
||||
// Change l'id de page dans les données des modules
|
||||
if ($this->getData(['module', $this->getUrl(2)]) !== null ) {
|
||||
$this->setData(['module', $pageId, $this->getData(['module', $this->getUrl(2)])]);
|
||||
$this->deleteData(['module', $this->getUrl(2)]);
|
||||
// Renommer le dossier du module
|
||||
$moduleId = $this->getData(['page',$this->getUrl(2),'moduleId']);
|
||||
$modulesData = helper::getModules();
|
||||
if (is_dir($modulesData[$moduleId]['dataDirectory']. $this->getUrl(2))) {
|
||||
// Placer la feuille de style dans un dossier au nom de la nouvelle instance
|
||||
mkdir( $modulesData[$moduleId]['dataDirectory']. $pageId, 0755 );
|
||||
copy( $modulesData[$moduleId]['dataDirectory']. $this->getUrl(2), $modulesData[$moduleId]['dataDirectory']. $pageId);
|
||||
$this->removeDir($modulesData[$moduleId]['dataDirectory']. $this->getUrl(2));
|
||||
// Mettre à jour le nom de la feuille de style
|
||||
$this->setData(['module',$pageId,'theme','style', $modulesData[$moduleId]['dataDirectory']. $pageId]);
|
||||
}
|
||||
}
|
||||
// Si la page correspond à la page d'accueil, change l'id dans la configuration du site
|
||||
if($this->getData(['locale', 'homePageId']) === $this->getUrl(2)) {
|
||||
$this->setData(['locale', 'homePageId', $pageId]);
|
||||
}
|
||||
}
|
||||
// Si la page correspond à la page d'accueil, change l'id dans la configuration du site
|
||||
if($this->getData(['locale', 'homePageId']) === $this->getUrl(2)) {
|
||||
$this->setData(['locale', 'homePageId', $pageId]);
|
||||
// Supprime les données du module en cas de changement de module
|
||||
if($this->getInput('pageEditModuleId') !== $this->getData(['page', $this->getUrl(2), 'moduleId'])) {
|
||||
$this->deleteData(['module', $pageId]);
|
||||
}
|
||||
}
|
||||
// Supprime les données du module en cas de changement de module
|
||||
if($this->getInput('pageEditModuleId') !== $this->getData(['page', $this->getUrl(2), 'moduleId'])) {
|
||||
$this->deleteData(['module', $pageId]);
|
||||
}
|
||||
// Supprime l'ancienne page si l'id a changée
|
||||
if($pageId !== $this->getUrl(2)) {
|
||||
$this->deleteData(['page', $this->getUrl(2)]);
|
||||
unlink (self::DATA_DIR . self::$i18n . '/content/' . $this->getUrl(2) . '.html');
|
||||
}
|
||||
// Traitement des pages spéciales affectées dans la config :
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'legalPageId']) ) {
|
||||
$this->setData(['locale','legalPageId', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'searchPageId']) ) {
|
||||
$this->setData(['locale','searchPageId', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page404']) ) {
|
||||
$this->setData(['locale','page404', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page403']) ) {
|
||||
$this->setData(['locale','page403', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page302']) ) {
|
||||
$this->setData(['locale','page302', $pageId]);
|
||||
}
|
||||
// Si la page est une page enfant, actualise les positions des autres enfants du parent, sinon actualise les pages sans parents
|
||||
$lastPosition = 1;
|
||||
$hierarchy = $this->getInput('pageEditParentPageId') ? $this->getHierarchy($this->getInput('pageEditParentPageId')) : array_keys($this->getHierarchy());
|
||||
$position = $this->getInput('pageEditPosition', helper::FILTER_INT);
|
||||
foreach($hierarchy as $hierarchyPageId) {
|
||||
// Ignore la page en cours de modification
|
||||
if($hierarchyPageId === $this->getUrl(2)) {
|
||||
continue;
|
||||
// Supprime l'ancienne page si l'id a changée
|
||||
if($pageId !== $this->getUrl(2)) {
|
||||
$this->deleteData(['page', $this->getUrl(2)]);
|
||||
unlink (self::DATA_DIR . self::$i18n . '/content/' . $this->getUrl(2) . '.html');
|
||||
}
|
||||
// Incrémente de +1 pour laisser la place à la position de la page en cours de modification
|
||||
if($lastPosition === $position) {
|
||||
// Traitement des pages spéciales affectées dans la config :
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'legalPageId']) ) {
|
||||
$this->setData(['locale','legalPageId', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'searchPageId']) ) {
|
||||
$this->setData(['locale','searchPageId', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page404']) ) {
|
||||
$this->setData(['locale','page404', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page403']) ) {
|
||||
$this->setData(['locale','page403', $pageId]);
|
||||
}
|
||||
if ($this->getUrl(2) === $this->getData(['locale', 'page302']) ) {
|
||||
$this->setData(['locale','page302', $pageId]);
|
||||
}
|
||||
// Si la page est une page enfant, actualise les positions des autres enfants du parent, sinon actualise les pages sans parents
|
||||
$lastPosition = 1;
|
||||
$hierarchy = $this->getInput('pageEditParentPageId') ? $this->getHierarchy($this->getInput('pageEditParentPageId')) : array_keys($this->getHierarchy());
|
||||
$position = $this->getInput('pageEditPosition', helper::FILTER_INT);
|
||||
foreach($hierarchy as $hierarchyPageId) {
|
||||
// Ignore la page en cours de modification
|
||||
if($hierarchyPageId === $this->getUrl(2)) {
|
||||
continue;
|
||||
}
|
||||
// Incrémente de +1 pour laisser la place à la position de la page en cours de modification
|
||||
if($lastPosition === $position) {
|
||||
$lastPosition++;
|
||||
}
|
||||
// Change la position
|
||||
$this->setData(['page', $hierarchyPageId, 'position', $lastPosition]);
|
||||
// Incrémente pour la prochaine position
|
||||
$lastPosition++;
|
||||
}
|
||||
// Change la position
|
||||
$this->setData(['page', $hierarchyPageId, 'position', $lastPosition]);
|
||||
// Incrémente pour la prochaine position
|
||||
$lastPosition++;
|
||||
}
|
||||
if ($this->getinput('pageEditBlock') !== 'bar') {
|
||||
$barLeft = $this->getinput('pageEditBarLeft');
|
||||
$barRight = $this->getinput('pageEditBarRight');
|
||||
$hideTitle = $this->getInput('pageEditHideTitle', helper::FILTER_BOOLEAN);
|
||||
if ($this->getinput('pageEditBlock') !== 'bar') {
|
||||
$barLeft = $this->getinput('pageEditBarLeft');
|
||||
$barRight = $this->getinput('pageEditBarRight');
|
||||
$hideTitle = $this->getInput('pageEditHideTitle', helper::FILTER_BOOLEAN);
|
||||
|
||||
} else {
|
||||
// Une barre ne peut pas avoir de barres
|
||||
$barLeft = "";
|
||||
$barRight = "";
|
||||
// Une barre est masquée
|
||||
$position = 0;
|
||||
$hideTitle = true;
|
||||
}
|
||||
// Modifie la page ou en crée une nouvelle si l'id a changé
|
||||
$this->setData([
|
||||
'page',
|
||||
$pageId,
|
||||
[
|
||||
'typeMenu' => $this->getinput('pageTypeMenu'),
|
||||
'iconUrl' => $this->getinput('pageIconUrl'),
|
||||
'disable'=> $this->getinput('pageEditDisable', helper::FILTER_BOOLEAN),
|
||||
'content' => $pageId . '.html',
|
||||
'hideTitle' => $hideTitle,
|
||||
'breadCrumb' => $this->getInput('pageEditbreadCrumb', helper::FILTER_BOOLEAN),
|
||||
'metaDescription' => $this->getInput('pageEditMetaDescription', helper::FILTER_STRING_LONG),
|
||||
'metaTitle' => $this->getInput('pageEditMetaTitle'),
|
||||
'moduleId' => $this->getInput('pageEditModuleId'),
|
||||
'modulePosition' => $this->getInput('configModulePosition'),
|
||||
'parentPageId' => $this->getInput('pageEditParentPageId'),
|
||||
'position' => $position,
|
||||
'group' => $this->getinput('pageEditBlock') !== 'bar' ? $this->getInput('pageEditGroup', helper::FILTER_INT) : 0,
|
||||
'groupEdit' => $this->getInput('pageEditGroupEdit', helper::FILTER_INT),
|
||||
'targetBlank' => $this->getInput('pageEditTargetBlank', helper::FILTER_BOOLEAN),
|
||||
'title' => $this->getInput('pageEditTitle', helper::FILTER_STRING_SHORT),
|
||||
'shortTitle' => $this->getInput('pageEditShortTitle', helper::FILTER_STRING_SHORT, true),
|
||||
'block' => $this->getinput('pageEditBlock'),
|
||||
'barLeft' => $barLeft,
|
||||
'barRight' => $barRight,
|
||||
'displayMenu' => $this->getinput('pageEditDisplayMenu'),
|
||||
'hideMenuSide' => $this->getinput('pageEditHideMenuSide', helper::FILTER_BOOLEAN),
|
||||
'hideMenuHead' => $this->getinput('pageEditHideMenuHead', helper::FILTER_BOOLEAN),
|
||||
'hideMenuChildren' => $this->getinput('pageEditHideMenuChildren', helper::FILTER_BOOLEAN),
|
||||
]
|
||||
]);
|
||||
// Creation du contenu de la page
|
||||
if (!is_dir(self::DATA_DIR . self::$i18n . '/content')) {
|
||||
mkdir(self::DATA_DIR . self::$i18n . '/content', 0755);
|
||||
}
|
||||
$content = empty($this->getInput('pageEditContent', null)) ? '<p></p>' : str_replace('<p></p>', '<p> </p>', $this->getInput('pageEditContent', null));
|
||||
//file_put_contents( self::DATA_DIR . self::$i18n . '/content/' . $pageId . '.html' , $content );
|
||||
$this->setPage($pageId , $content, self::$i18n);
|
||||
// Barre renommée : changement le nom de la barre dans les pages mères
|
||||
if ($this->getinput('pageEditBlock') === 'bar') {
|
||||
foreach ($this->getHierarchy() as $eachPageId=>$parentId) {
|
||||
if ($this->getData(['page',$eachPageId,'barRight']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$eachPageId,'barRight',$pageId]);
|
||||
}
|
||||
if ($this->getData(['page',$eachPageId,'barLeft']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$eachPageId,'barLeft',$pageId]);
|
||||
}
|
||||
foreach ($parentId as $childId) {
|
||||
if ($this->getData(['page',$childId,'barRight']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$childId,'barRight',$pageId]);
|
||||
} else {
|
||||
// Une barre ne peut pas avoir de barres
|
||||
$barLeft = "";
|
||||
$barRight = "";
|
||||
// Une barre est masquée
|
||||
$position = 0;
|
||||
$hideTitle = true;
|
||||
}
|
||||
// Modifie la page ou en crée une nouvelle si l'id a changé
|
||||
$this->setData([
|
||||
'page',
|
||||
$pageId,
|
||||
[
|
||||
'typeMenu' => $this->getinput('pageTypeMenu'),
|
||||
'iconUrl' => $this->getinput('pageIconUrl'),
|
||||
'disable'=> $this->getinput('pageEditDisable', helper::FILTER_BOOLEAN),
|
||||
'content' => $pageId . '.html',
|
||||
'hideTitle' => $hideTitle,
|
||||
'breadCrumb' => $this->getInput('pageEditbreadCrumb', helper::FILTER_BOOLEAN),
|
||||
'metaDescription' => $this->getInput('pageEditMetaDescription', helper::FILTER_STRING_LONG),
|
||||
'metaTitle' => $this->getInput('pageEditMetaTitle'),
|
||||
'moduleId' => $this->getInput('pageEditModuleId'),
|
||||
'modulePosition' => $this->getInput('configModulePosition'),
|
||||
'parentPageId' => $this->getInput('pageEditParentPageId'),
|
||||
'position' => $position,
|
||||
'group' => $this->getinput('pageEditBlock') !== 'bar' ? $this->getInput('pageEditGroup', helper::FILTER_INT) : 0,
|
||||
'groupEdit' => $this->getInput('pageEditGroupEdit', helper::FILTER_INT),
|
||||
'targetBlank' => $this->getInput('pageEditTargetBlank', helper::FILTER_BOOLEAN),
|
||||
'title' => $this->getInput('pageEditTitle', helper::FILTER_STRING_SHORT),
|
||||
'shortTitle' => $this->getInput('pageEditShortTitle', helper::FILTER_STRING_SHORT, true),
|
||||
'block' => $this->getinput('pageEditBlock'),
|
||||
'barLeft' => $barLeft,
|
||||
'barRight' => $barRight,
|
||||
'displayMenu' => $this->getinput('pageEditDisplayMenu'),
|
||||
'hideMenuSide' => $this->getinput('pageEditHideMenuSide', helper::FILTER_BOOLEAN),
|
||||
'hideMenuHead' => $this->getinput('pageEditHideMenuHead', helper::FILTER_BOOLEAN),
|
||||
'hideMenuChildren' => $this->getinput('pageEditHideMenuChildren', helper::FILTER_BOOLEAN),
|
||||
]
|
||||
]);
|
||||
// Creation du contenu de la page
|
||||
if (!is_dir(self::DATA_DIR . self::$i18n . '/content')) {
|
||||
mkdir(self::DATA_DIR . self::$i18n . '/content', 0755);
|
||||
}
|
||||
$content = empty($this->getInput('pageEditContent', null)) ? '<p></p>' : str_replace('<p></p>', '<p> </p>', $this->getInput('pageEditContent', null));
|
||||
//file_put_contents( self::DATA_DIR . self::$i18n . '/content/' . $pageId . '.html' , $content );
|
||||
$this->setPage($pageId , $content, self::$i18n);
|
||||
// Barre renommée : changement le nom de la barre dans les pages mères
|
||||
if ($this->getinput('pageEditBlock') === 'bar') {
|
||||
foreach ($this->getHierarchy() as $eachPageId=>$parentId) {
|
||||
if ($this->getData(['page',$eachPageId,'barRight']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$eachPageId,'barRight',$pageId]);
|
||||
}
|
||||
if ($this->getData(['page',$childId,'barLeft']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$childId,'barLeft',$pageId]);
|
||||
if ($this->getData(['page',$eachPageId,'barLeft']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$eachPageId,'barLeft',$pageId]);
|
||||
}
|
||||
foreach ($parentId as $childId) {
|
||||
if ($this->getData(['page',$childId,'barRight']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$childId,'barRight',$pageId]);
|
||||
}
|
||||
if ($this->getData(['page',$childId,'barLeft']) === $this->getUrl(2)) {
|
||||
$this->setData(['page',$childId,'barLeft',$pageId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Redirection vers la configuration
|
||||
if($this->getInput('pageEditModuleRedirect', helper::FILTER_BOOLEAN)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId . '/config',
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
// Redirection vers la page
|
||||
else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId,
|
||||
'notification' => $text['core_page']['edit'][0],
|
||||
'state' => true
|
||||
]);
|
||||
// Met à jour le site map
|
||||
// $this->createSitemap('all');
|
||||
// Redirection vers la configuration
|
||||
if($this->getInput('pageEditModuleRedirect', helper::FILTER_BOOLEAN)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId . '/config',
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
// Redirection vers la page
|
||||
else {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $pageId,
|
||||
'notification' => $text['core_page']['edit'][0],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self::$moduleIds = array_merge( ['' => $text['core_page']['edit'][1]] , helper::arrayCollumn(helper::getModules(),'realName','SORT_ASC')); // Pages sans parent
|
||||
self::$pagesNoParentId = $pagesNoParentId;
|
||||
foreach($this->getHierarchy() as $parentPageId => $childrenPageIds) {
|
||||
if($parentPageId !== $this->getUrl(2)) {
|
||||
self::$pagesNoParentId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
//self::$pagesNoParentId_en[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
}
|
||||
}
|
||||
// Pages barre latérales
|
||||
self::$pagesBarId = $pagesBarId;
|
||||
foreach($this->getHierarchy(null,false,true) as $parentPageId => $childrenPageIds) {
|
||||
if($parentPageId !== $this->getUrl(2) &&
|
||||
$this->getData(['page', $parentPageId, 'block']) === 'bar') {
|
||||
self::$pagesBarId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
//self::$pagesBarId_en[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
self::$moduleIds = array_merge( ['' => $text['core_page']['edit'][1]] , helper::arrayCollumn(helper::getModules(),'realName','SORT_ASC')); // Pages sans parent
|
||||
self::$pagesNoParentId = $pagesNoParentId;
|
||||
foreach($this->getHierarchy() as $parentPageId => $childrenPageIds) {
|
||||
if($parentPageId !== $this->getUrl(2)) {
|
||||
self::$pagesNoParentId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
//self::$pagesNoParentId_en[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
}
|
||||
}
|
||||
// Pages barre latérales
|
||||
self::$pagesBarId = $pagesBarId;
|
||||
foreach($this->getHierarchy(null,false,true) as $parentPageId => $childrenPageIds) {
|
||||
if($parentPageId !== $this->getUrl(2) &&
|
||||
$this->getData(['page', $parentPageId, 'block']) === 'bar') {
|
||||
self::$pagesBarId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
//self::$pagesBarId_en[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
}
|
||||
}
|
||||
// Mise à jour de la liste des pages pour TinyMCE
|
||||
$this->pages2Json();
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $this->getData(['page', $this->getUrl(2), 'title']),
|
||||
'vendor' => ['tinymce'],
|
||||
'view' => 'edit'
|
||||
]);
|
||||
}
|
||||
// Mise à jour de la liste des pages pour TinyMCE
|
||||
$this->pages2Json();
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $this->getData(['page', $this->getUrl(2), 'title']),
|
||||
'vendor' => ['tinymce'],
|
||||
'view' => 'edit'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -37,155 +37,175 @@ class translate extends common {
|
|||
* Configuration avancée des langues
|
||||
*/
|
||||
public function copy() {
|
||||
// Lexique
|
||||
include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_translate.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if ($this->isPost()) {
|
||||
// Initialisation
|
||||
$success = false;
|
||||
$copyFrom = $this->getInput('translateFormCopySource');
|
||||
$toCreate = $this->getInput('translateFormCopyTarget');
|
||||
if ($copyFrom !== $toCreate) {
|
||||
// Création du dossier
|
||||
if (is_dir(self::DATA_DIR . $toCreate) === false ) { // Si le dossier est déjà créé
|
||||
$success = mkdir (self::DATA_DIR . $toCreate, 0755);
|
||||
$success = mkdir (self::DATA_DIR . $toCreate.'/content', 0755);
|
||||
} else {
|
||||
$success = true;
|
||||
}
|
||||
// Copier les données par défaut avec gestion des erreurs
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/locale.json', self::DATA_DIR . $toCreate . '/locale.json') === true && $success === true) ? true : false;
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/module.json', self::DATA_DIR . $toCreate . '/module.json') === true && $success === true) ? true : false;
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/page.json', self::DATA_DIR . $toCreate . '/page.json') === true && $success === true) ? true : false;
|
||||
$success = ($this->copyDir (self::DATA_DIR . $copyFrom . '/content', self::DATA_DIR . $toCreate . '/content') === true && $success === true) ? true : false;
|
||||
// Enregistrer la langue
|
||||
if ($success) {
|
||||
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
|
||||
$i18nListBase = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$i18nList);
|
||||
$notification = $text['core_translate']['copy'][3] . $i18nListBase[$copyFrom] . $text['core_translate']['copy'][4] . self::$i18nList[$toCreate];
|
||||
} else {
|
||||
$notification = $text['core_translate']['copy'][0];
|
||||
}
|
||||
} else {
|
||||
$success = false;
|
||||
$notification = $text['core_translate']['copy'][1];
|
||||
}
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < translate::$actions['copy'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'notification' => $notification,
|
||||
'title' => $text['core_translate']['copy'][2],
|
||||
'view' => 'index',
|
||||
'state' => $success
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_translate.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if ($this->isPost()) {
|
||||
// Initialisation
|
||||
$success = false;
|
||||
$copyFrom = $this->getInput('translateFormCopySource');
|
||||
$toCreate = $this->getInput('translateFormCopyTarget');
|
||||
if ($copyFrom !== $toCreate) {
|
||||
// Création du dossier
|
||||
if (is_dir(self::DATA_DIR . $toCreate) === false ) { // Si le dossier est déjà créé
|
||||
$success = mkdir (self::DATA_DIR . $toCreate, 0755);
|
||||
$success = mkdir (self::DATA_DIR . $toCreate.'/content', 0755);
|
||||
} else {
|
||||
$success = true;
|
||||
}
|
||||
// Copier les données par défaut avec gestion des erreurs
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/locale.json', self::DATA_DIR . $toCreate . '/locale.json') === true && $success === true) ? true : false;
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/module.json', self::DATA_DIR . $toCreate . '/module.json') === true && $success === true) ? true : false;
|
||||
$success = (copy (self::DATA_DIR . $copyFrom . '/page.json', self::DATA_DIR . $toCreate . '/page.json') === true && $success === true) ? true : false;
|
||||
$success = ($this->copyDir (self::DATA_DIR . $copyFrom . '/content', self::DATA_DIR . $toCreate . '/content') === true && $success === true) ? true : false;
|
||||
// Enregistrer la langue
|
||||
if ($success) {
|
||||
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
|
||||
$i18nListBase = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$i18nList);
|
||||
$notification = $text['core_translate']['copy'][3] . $i18nListBase[$copyFrom] . $text['core_translate']['copy'][4] . self::$i18nList[$toCreate];
|
||||
} else {
|
||||
$notification = $text['core_translate']['copy'][0];
|
||||
}
|
||||
} else {
|
||||
$success = false;
|
||||
$notification = $text['core_translate']['copy'][1];
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'notification' => $notification,
|
||||
'title' => $text['core_translate']['copy'][2],
|
||||
'view' => 'index',
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
// Tableau des langues installées
|
||||
foreach ($i18nList as $key => $value) {
|
||||
if ($this->getData(['config','i18n', $key]) === 'site') {
|
||||
self::$languagesTarget[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Langues cibles base en plus
|
||||
self::$languagesInstalled = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$languagesTarget);
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_translate']['copy'][2],
|
||||
'view' => 'copy'
|
||||
]);
|
||||
}
|
||||
// Tableau des langues installées
|
||||
foreach ($i18nList as $key => $value) {
|
||||
if ($this->getData(['config','i18n', $key]) === 'site') {
|
||||
self::$languagesTarget[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Langues cibles base en plus
|
||||
self::$languagesInstalled = array_merge(['base' => $text['core_translate']['copy'][5] ],self::$languagesTarget);
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_translate']['copy'][2],
|
||||
'view' => 'copy'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
*/
|
||||
public function index() {
|
||||
// Lexique
|
||||
include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_translate.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Edition des langues
|
||||
foreach (self::$i18nList as $keyi18n => $value) {
|
||||
if ($keyi18n === 'base') continue;
|
||||
|
||||
// Effacement d'une langue installée
|
||||
if ( is_dir( self::DATA_DIR . $keyi18n ) === true
|
||||
AND $this->getInput('translate' . strtoupper($keyi18n)) === 'delete')
|
||||
{
|
||||
$this->removeDir( self::DATA_DIR . $keyi18n);
|
||||
// Au cas ou la langue est sélectionnée
|
||||
helper::deleteCookie('DELTA_I18N_SITE');
|
||||
}
|
||||
}
|
||||
// 'langBase' mémorise le code ISO de la langue sélectionnée ou de la valeur saisie si la langue sélectionnée est Autre langue
|
||||
$requiredOtherLang = false;
|
||||
$langBase = $this->getInput('translateLangBase');
|
||||
if( $langBase === 'none'){
|
||||
$langBase = $this->getInput('translateOtherBase');
|
||||
$requiredOtherLang = true;
|
||||
}
|
||||
|
||||
// Enregistrement des données
|
||||
$this->setData(['config','i18n', [
|
||||
'enable' => $this->getData(['config', 'i18n', 'enable']),
|
||||
'langAdmin' => $this->getInput('translateLangAdmin'),
|
||||
'langBase' => $langBase,
|
||||
'otherLangBase' => $this->getInput('translateOtherBase', helper::FILTER_STRING_SHORT,$requiredOtherLang),
|
||||
'fr' => $this->getInput('translateFR'),
|
||||
'de' => $this->getInput('translateDE'),
|
||||
'en' => $this->getInput('translateEN'),
|
||||
'es' => $this->getInput('translateES'),
|
||||
'it' => $this->getInput('translateIT'),
|
||||
'nl' => $this->getInput('translateNL'),
|
||||
'pt' => $this->getInput('translatePT'),
|
||||
'el' => $this->getInput('translateEL'),
|
||||
'da' => $this->getInput('translateDA'),
|
||||
'fi' => $this->getInput('translateFI'),
|
||||
'ga' => $this->getInput('translateGA'),
|
||||
'sv' => $this->getInput('translateSV'),
|
||||
'br' => $this->getInput('translateBR'),
|
||||
'ca' => $this->getInput('translateCA'),
|
||||
'co' => $this->getInput('translateCO'),
|
||||
'eu' => $this->getInput('translateEU')
|
||||
|
||||
]]);
|
||||
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < translate::$actions['index'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(),
|
||||
'notification' => $text['core_translate']['index'][0],
|
||||
'state' => true
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/translate/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_translate.php');
|
||||
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Edition des langues
|
||||
foreach (self::$i18nList as $keyi18n => $value) {
|
||||
if ($keyi18n === 'base') continue;
|
||||
|
||||
// Effacement d'une langue installée
|
||||
if ( is_dir( self::DATA_DIR . $keyi18n ) === true
|
||||
AND $this->getInput('translate' . strtoupper($keyi18n)) === 'delete')
|
||||
{
|
||||
$this->removeDir( self::DATA_DIR . $keyi18n);
|
||||
// Au cas ou la langue est sélectionnée
|
||||
helper::deleteCookie('DELTA_I18N_SITE');
|
||||
}
|
||||
}
|
||||
// 'langBase' mémorise le code ISO de la langue sélectionnée ou de la valeur saisie si la langue sélectionnée est Autre langue
|
||||
$requiredOtherLang = false;
|
||||
$langBase = $this->getInput('translateLangBase');
|
||||
if( $langBase === 'none'){
|
||||
$langBase = $this->getInput('translateOtherBase');
|
||||
$requiredOtherLang = true;
|
||||
}
|
||||
|
||||
// Enregistrement des données
|
||||
$this->setData(['config','i18n', [
|
||||
'enable' => $this->getData(['config', 'i18n', 'enable']),
|
||||
'langAdmin' => $this->getInput('translateLangAdmin'),
|
||||
'langBase' => $langBase,
|
||||
'otherLangBase' => $this->getInput('translateOtherBase', helper::FILTER_STRING_SHORT,$requiredOtherLang),
|
||||
'fr' => $this->getInput('translateFR'),
|
||||
'de' => $this->getInput('translateDE'),
|
||||
'en' => $this->getInput('translateEN'),
|
||||
'es' => $this->getInput('translateES'),
|
||||
'it' => $this->getInput('translateIT'),
|
||||
'nl' => $this->getInput('translateNL'),
|
||||
'pt' => $this->getInput('translatePT'),
|
||||
'el' => $this->getInput('translateEL'),
|
||||
'da' => $this->getInput('translateDA'),
|
||||
'fi' => $this->getInput('translateFI'),
|
||||
'ga' => $this->getInput('translateGA'),
|
||||
'sv' => $this->getInput('translateSV'),
|
||||
'br' => $this->getInput('translateBR'),
|
||||
'ca' => $this->getInput('translateCA'),
|
||||
'co' => $this->getInput('translateCO'),
|
||||
'eu' => $this->getInput('translateEU')
|
||||
|
||||
]]);
|
||||
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(),
|
||||
'notification' => $text['core_translate']['index'][0],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
// Modification des options de suppression de la langue installée.
|
||||
foreach (self::$i18nList as $key => $value) {
|
||||
if ($this->getData(['config','i18n',$key]) === 'site') {
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][3],
|
||||
'delete' => $text['core_translate']['index'][4]
|
||||
];
|
||||
self::$siteTranslate = $key !== $this->getData(['config', 'i18n', 'langBase']) ? false : true;
|
||||
} else {
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][3]
|
||||
];
|
||||
}
|
||||
// Limitation du choix pour la langue d'origine
|
||||
if ( $key === $this->getData(['config', 'i18n', 'langBase'])){
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][5]
|
||||
];
|
||||
}
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_translate']['index'][6],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
// Modification des options de suppression de la langue installée.
|
||||
foreach (self::$i18nList as $key => $value) {
|
||||
if ($this->getData(['config','i18n',$key]) === 'site') {
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][3],
|
||||
'delete' => $text['core_translate']['index'][4]
|
||||
];
|
||||
self::$siteTranslate = $key !== $this->getData(['config', 'i18n', 'langBase']) ? false : true;
|
||||
} else {
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][3]
|
||||
];
|
||||
}
|
||||
// Limitation du choix pour la langue d'origine
|
||||
if ( $key === $this->getData(['config', 'i18n', 'langBase'])){
|
||||
self::$translateOptions [$key] = [
|
||||
'none' => $text['core_translate']['index'][1],
|
||||
'site' => $text['core_translate']['index'][5]
|
||||
];
|
||||
}
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_translate']['index'][6],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,257 +47,81 @@ class user extends common {
|
|||
* Ajout
|
||||
*/
|
||||
public function add() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
$check=true;
|
||||
// L'identifiant d'utilisateur est indisponible
|
||||
$userId = $this->getInput('userAddId', helper::FILTER_ID, true);
|
||||
if($this->getData(['user', $userId])) {
|
||||
self::$inputNotices['userAddId'] = $text['core_user']['add'][0];
|
||||
$check=false;
|
||||
}
|
||||
// Double vérification pour le mot de passe
|
||||
if($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
|
||||
self::$inputNotices['userAddConfirmPassword'] = $text['core_user']['add'][1];
|
||||
$check = false;
|
||||
}
|
||||
// Crée l'utilisateur
|
||||
$userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true);
|
||||
$userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true);
|
||||
$userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true);
|
||||
|
||||
// Stockage des données
|
||||
$this->setData([
|
||||
'user',
|
||||
$userId,
|
||||
[
|
||||
'firstname' => $userFirstname,
|
||||
'forgot' => 0,
|
||||
'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true),
|
||||
'lastname' => $userLastname,
|
||||
'pseudo' => $this->getInput('userAddPseudo', helper::FILTER_STRING_SHORT, true),
|
||||
'signature' => $this->getInput('userAddSignature', helper::FILTER_INT, true),
|
||||
'mail' => $userMail,
|
||||
'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true),
|
||||
"connectFail" => null,
|
||||
"connectTimeout" => null,
|
||||
"accessUrl" => null,
|
||||
"accessTimer" => null,
|
||||
"accessCsrf" => null,
|
||||
"files" => $this->getInput('userAddFiles', helper::FILTER_BOOLEAN),
|
||||
"redirectPageId" => $this->getInput('userRedirectPageId', helper::FILTER_STRING_SHORT)
|
||||
]
|
||||
]);
|
||||
|
||||
// Envoie le mail
|
||||
$sent = true;
|
||||
if($this->getInput('userAddSendMail', helper::FILTER_BOOLEAN) && $check === true) {
|
||||
$sent = $this->sendMail(
|
||||
$userMail,
|
||||
$text['core_user']['add'][2] . $this->getData(['locale', 'title']),
|
||||
$text['core_user']['add'][3].'<strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
|
||||
$text['core_user']['add'][4] . $this->getData(['locale', 'title']) . $text['core_user']['add'][5].'<br><br>' .
|
||||
'<strong>'.$text['core_user']['add'][6].'</strong> ' . $this->getInput('userAddId') . '<br>' .
|
||||
'<small>'.$text['core_user']['add'][7].'</small>',
|
||||
null
|
||||
);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $sent === true ? $text['core_user']['add'][8] : $sent,
|
||||
'state' => $sent === true ? true : null
|
||||
]);
|
||||
}
|
||||
// Générer la liste des pages disponibles
|
||||
$redirectPage = array( 'noRedirect'=> array( 'title'=>$text['core_user']['add'][10]));
|
||||
self::$pagesList = $this->getData(['page']);
|
||||
foreach(self::$pagesList as $page => $pageId) {
|
||||
if ($this->getData(['page',$page,'block']) === 'bar' ||
|
||||
$this->getData(['page',$page,'disable']) === true ||
|
||||
$this->getData(['page',$page,'title']) === null ) {
|
||||
unset(self::$pagesList[$page]);
|
||||
}
|
||||
}
|
||||
self::$pagesList = array_merge( $redirectPage, self::$pagesList);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_user']['add'][9],
|
||||
'view' => 'add'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppression
|
||||
*/
|
||||
public function delete() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Accès refusé
|
||||
if(
|
||||
// L'utilisateur n'existe pas
|
||||
$this->getData(['user', $this->getUrl(2)]) === null
|
||||
// Groupe insuffisant
|
||||
AND ($this->getUrl('group') < self::GROUP_MODERATOR)
|
||||
) {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['add'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// Jeton incorrect
|
||||
elseif ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][0]
|
||||
]);
|
||||
}
|
||||
// Bloque la suppression de son propre compte
|
||||
elseif($this->getUser('id') === $this->getUrl(2)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Suppression
|
||||
else {
|
||||
$this->deleteData(['user', $this->getUrl(2)]);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][2],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Édition
|
||||
*/
|
||||
public function edit() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf'] &&
|
||||
$this->getUrl(4) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['edit'][0]
|
||||
]);
|
||||
}
|
||||
// Accès refusé
|
||||
if(
|
||||
// L'utilisateur n'existe pas
|
||||
$this->getData(['user', $this->getUrl(2)]) === null
|
||||
// Droit d'édition
|
||||
AND (
|
||||
// Impossible de s'auto-éditer
|
||||
(
|
||||
$this->getUser('id') === $this->getUrl(2)
|
||||
AND $this->getUrl('group') <= self::GROUP_VISITOR
|
||||
)
|
||||
// Impossible d'éditer un autre utilisateur
|
||||
OR ($this->getUrl('group') < self::GROUP_MODERATOR)
|
||||
)
|
||||
) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// Accès autorisé
|
||||
else {
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
$check=true;
|
||||
// L'identifiant d'utilisateur est indisponible
|
||||
$userId = $this->getInput('userAddId', helper::FILTER_ID, true);
|
||||
if($this->getData(['user', $userId])) {
|
||||
self::$inputNotices['userAddId'] = $text['core_user']['add'][0];
|
||||
$check=false;
|
||||
}
|
||||
// Double vérification pour le mot de passe
|
||||
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
|
||||
if($this->getInput('userEditNewPassword')) {
|
||||
// L'ancien mot de passe est correct
|
||||
if(password_verify($this->getInput('userEditOldPassword'), $this->getData(['user', $this->getUrl(2), 'password']))) {
|
||||
// La confirmation correspond au mot de passe
|
||||
if($this->getInput('userEditNewPassword') === $this->getInput('userEditConfirmPassword')) {
|
||||
$newPassword = $this->getInput('userEditNewPassword', helper::FILTER_PASSWORD, true);
|
||||
// Déconnexion de l'utilisateur si il change le mot de passe de son propre compte
|
||||
if($this->getUser('id') === $this->getUrl(2)) {
|
||||
helper::deleteCookie('DELTA_USER_ID');
|
||||
helper::deleteCookie('DELTA_USER_PASSWORD');
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$inputNotices['userEditConfirmPassword'] = $text['core_user']['edit'][1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$inputNotices['userEditOldPassword'] = $text['core_user']['edit'][1];
|
||||
}
|
||||
if($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
|
||||
self::$inputNotices['userAddConfirmPassword'] = $text['core_user']['add'][1];
|
||||
$check = false;
|
||||
}
|
||||
// Modification du groupe
|
||||
if(
|
||||
$this->getUser('group') === self::GROUP_ADMIN
|
||||
AND $this->getUrl(2) !== $this->getUser('id')
|
||||
) {
|
||||
$newGroup = $this->getInput('userEditGroup', helper::FILTER_INT, true);
|
||||
}
|
||||
else {
|
||||
$newGroup = $this->getData(['user', $this->getUrl(2), 'group']);
|
||||
}
|
||||
// Modification de nom Prénom
|
||||
if($this->getUser('group') === self::GROUP_ADMIN){
|
||||
$newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true);
|
||||
$newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true);
|
||||
}
|
||||
else{
|
||||
$newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']);
|
||||
$newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']);
|
||||
}
|
||||
// Modifie l'utilisateur
|
||||
// Crée l'utilisateur
|
||||
$userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true);
|
||||
$userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true);
|
||||
$userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true);
|
||||
|
||||
// Stockage des données
|
||||
$this->setData([
|
||||
'user',
|
||||
$this->getUrl(2),
|
||||
$userId,
|
||||
[
|
||||
'firstname' => $newfirstname,
|
||||
'firstname' => $userFirstname,
|
||||
'forgot' => 0,
|
||||
'group' => $newGroup,
|
||||
'lastname' => $newlastname,
|
||||
'pseudo' => $this->getInput('userEditPseudo', helper::FILTER_STRING_SHORT, true),
|
||||
'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true),
|
||||
'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true),
|
||||
'password' => $newPassword,
|
||||
'connectFail' => $this->getData(['user',$this->getUrl(2),'connectFail']),
|
||||
'connectTimeout' => $this->getData(['user',$this->getUrl(2),'connectTimeout']),
|
||||
'accessUrl' => $this->getData(['user',$this->getUrl(2),'accessUrl']),
|
||||
'accessTimer' => $this->getData(['user',$this->getUrl(2),'accessTimer']),
|
||||
'accessCsrf' => $this->getData(['user',$this->getUrl(2),'accessCsrf']),
|
||||
'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN),
|
||||
'redirectPageId' => $this->getInput('userRedirectPageId', helper::FILTER_STRING_SHORT)
|
||||
'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true),
|
||||
'lastname' => $userLastname,
|
||||
'pseudo' => $this->getInput('userAddPseudo', helper::FILTER_STRING_SHORT, true),
|
||||
'signature' => $this->getInput('userAddSignature', helper::FILTER_INT, true),
|
||||
'mail' => $userMail,
|
||||
'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true),
|
||||
"connectFail" => null,
|
||||
"connectTimeout" => null,
|
||||
"accessUrl" => null,
|
||||
"accessTimer" => null,
|
||||
"accessCsrf" => null,
|
||||
"files" => $this->getInput('userAddFiles', helper::FILTER_BOOLEAN),
|
||||
"redirectPageId" => $this->getInput('userRedirectPageId', helper::FILTER_STRING_SHORT)
|
||||
]
|
||||
]);
|
||||
// Redirection spécifique si l'utilisateur change son mot de passe
|
||||
if($this->getUser('id') === $this->getUrl(2) AND $this->getInput('userEditNewPassword')) {
|
||||
$redirect = helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl());
|
||||
}
|
||||
// Redirection si retour en arrière possible
|
||||
elseif($this->getUser('group') === self::GROUP_ADMIN) {
|
||||
$redirect = helper::baseUrl() . 'user';
|
||||
}
|
||||
// Redirection normale
|
||||
else {
|
||||
$redirect = helper::baseUrl();
|
||||
|
||||
// Envoie le mail
|
||||
$sent = true;
|
||||
if($this->getInput('userAddSendMail', helper::FILTER_BOOLEAN) && $check === true) {
|
||||
$sent = $this->sendMail(
|
||||
$userMail,
|
||||
$text['core_user']['add'][2] . $this->getData(['locale', 'title']),
|
||||
$text['core_user']['add'][3].'<strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
|
||||
$text['core_user']['add'][4] . $this->getData(['locale', 'title']) . $text['core_user']['add'][5].'<br><br>' .
|
||||
'<strong>'.$text['core_user']['add'][6].'</strong> ' . $this->getInput('userAddId') . '<br>' .
|
||||
'<small>'.$text['core_user']['add'][7].'</small>',
|
||||
null
|
||||
);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => $redirect,
|
||||
'notification' => $text['core_user']['edit'][2],
|
||||
'state' => true
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $sent === true ? $text['core_user']['add'][8] : $sent,
|
||||
'state' => $sent === true ? true : null
|
||||
]);
|
||||
}
|
||||
// Générer la liste des pages disponibles
|
||||
$redirectPage = array( 'noRedirect'=> array( 'title'=> $text['core_user']['edit'][3]) );
|
||||
$redirectPage = array( 'noRedirect'=> array( 'title'=>$text['core_user']['add'][10]));
|
||||
self::$pagesList = $this->getData(['page']);
|
||||
foreach(self::$pagesList as $page => $pageId) {
|
||||
if ($this->getData(['page',$page,'block']) === 'bar' ||
|
||||
|
@ -309,12 +133,218 @@ class user extends common {
|
|||
self::$pagesList = array_merge( $redirectPage, self::$pagesList);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']),
|
||||
'view' => 'edit'
|
||||
'title' => $text['core_user']['add'][9],
|
||||
'view' => 'add'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppression
|
||||
*/
|
||||
public function delete() {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['delete'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Accès refusé
|
||||
if(
|
||||
// L'utilisateur n'existe pas
|
||||
$this->getData(['user', $this->getUrl(2)]) === null
|
||||
// Groupe insuffisant
|
||||
AND ($this->getUrl('group') < self::GROUP_MODERATOR)
|
||||
) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// Jeton incorrect
|
||||
elseif ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][0]
|
||||
]);
|
||||
}
|
||||
// Bloque la suppression de son propre compte
|
||||
elseif($this->getUser('id') === $this->getUrl(2)) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][1]
|
||||
]);
|
||||
}
|
||||
// Suppression
|
||||
else {
|
||||
$this->deleteData(['user', $this->getUrl(2)]);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['delete'][2],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Édition
|
||||
*/
|
||||
public function edit() {
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['edit'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf'] &&
|
||||
$this->getUrl(4) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . 'user',
|
||||
'notification' => $text['core_user']['edit'][0]
|
||||
]);
|
||||
}
|
||||
// Accès refusé
|
||||
if(
|
||||
// L'utilisateur n'existe pas
|
||||
$this->getData(['user', $this->getUrl(2)]) === null
|
||||
// Droit d'édition
|
||||
AND (
|
||||
// Impossible de s'auto-éditer
|
||||
(
|
||||
$this->getUser('id') === $this->getUrl(2)
|
||||
AND $this->getUrl('group') <= self::GROUP_VISITOR
|
||||
)
|
||||
// Impossible d'éditer un autre utilisateur
|
||||
OR ($this->getUrl('group') < self::GROUP_MODERATOR)
|
||||
)
|
||||
) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
}
|
||||
// Accès autorisé
|
||||
else {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
// Double vérification pour le mot de passe
|
||||
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
|
||||
if($this->getInput('userEditNewPassword')) {
|
||||
// L'ancien mot de passe est correct
|
||||
if(password_verify($this->getInput('userEditOldPassword'), $this->getData(['user', $this->getUrl(2), 'password']))) {
|
||||
// La confirmation correspond au mot de passe
|
||||
if($this->getInput('userEditNewPassword') === $this->getInput('userEditConfirmPassword')) {
|
||||
$newPassword = $this->getInput('userEditNewPassword', helper::FILTER_PASSWORD, true);
|
||||
// Déconnexion de l'utilisateur si il change le mot de passe de son propre compte
|
||||
if($this->getUser('id') === $this->getUrl(2)) {
|
||||
helper::deleteCookie('DELTA_USER_ID');
|
||||
helper::deleteCookie('DELTA_USER_PASSWORD');
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$inputNotices['userEditConfirmPassword'] = $text['core_user']['edit'][1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$inputNotices['userEditOldPassword'] = $text['core_user']['edit'][1];
|
||||
}
|
||||
}
|
||||
// Modification du groupe
|
||||
if(
|
||||
$this->getUser('group') === self::GROUP_ADMIN
|
||||
AND $this->getUrl(2) !== $this->getUser('id')
|
||||
) {
|
||||
$newGroup = $this->getInput('userEditGroup', helper::FILTER_INT, true);
|
||||
}
|
||||
else {
|
||||
$newGroup = $this->getData(['user', $this->getUrl(2), 'group']);
|
||||
}
|
||||
// Modification de nom Prénom
|
||||
if($this->getUser('group') === self::GROUP_ADMIN){
|
||||
$newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true);
|
||||
$newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true);
|
||||
}
|
||||
else{
|
||||
$newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']);
|
||||
$newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']);
|
||||
}
|
||||
// Modifie l'utilisateur
|
||||
$this->setData([
|
||||
'user',
|
||||
$this->getUrl(2),
|
||||
[
|
||||
'firstname' => $newfirstname,
|
||||
'forgot' => 0,
|
||||
'group' => $newGroup,
|
||||
'lastname' => $newlastname,
|
||||
'pseudo' => $this->getInput('userEditPseudo', helper::FILTER_STRING_SHORT, true),
|
||||
'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true),
|
||||
'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true),
|
||||
'password' => $newPassword,
|
||||
'connectFail' => $this->getData(['user',$this->getUrl(2),'connectFail']),
|
||||
'connectTimeout' => $this->getData(['user',$this->getUrl(2),'connectTimeout']),
|
||||
'accessUrl' => $this->getData(['user',$this->getUrl(2),'accessUrl']),
|
||||
'accessTimer' => $this->getData(['user',$this->getUrl(2),'accessTimer']),
|
||||
'accessCsrf' => $this->getData(['user',$this->getUrl(2),'accessCsrf']),
|
||||
'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN),
|
||||
'redirectPageId' => $this->getInput('userRedirectPageId', helper::FILTER_STRING_SHORT)
|
||||
]
|
||||
]);
|
||||
// Redirection spécifique si l'utilisateur change son mot de passe
|
||||
if($this->getUser('id') === $this->getUrl(2) AND $this->getInput('userEditNewPassword')) {
|
||||
$redirect = helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl());
|
||||
}
|
||||
// Redirection si retour en arrière possible
|
||||
elseif($this->getUser('group') === self::GROUP_ADMIN) {
|
||||
$redirect = helper::baseUrl() . 'user';
|
||||
}
|
||||
// Redirection normale
|
||||
else {
|
||||
$redirect = helper::baseUrl();
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'redirect' => $redirect,
|
||||
'notification' => $text['core_user']['edit'][2],
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
// Générer la liste des pages disponibles
|
||||
$redirectPage = array( 'noRedirect'=> array( 'title'=> $text['core_user']['edit'][3]) );
|
||||
self::$pagesList = $this->getData(['page']);
|
||||
foreach(self::$pagesList as $page => $pageId) {
|
||||
if ($this->getData(['page',$page,'block']) === 'bar' ||
|
||||
$this->getData(['page',$page,'disable']) === true ||
|
||||
$this->getData(['page',$page,'title']) === null ) {
|
||||
unset(self::$pagesList[$page]);
|
||||
}
|
||||
}
|
||||
self::$pagesList = array_merge( $redirectPage, self::$pagesList);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']),
|
||||
'view' => 'edit'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mot de passe perdu
|
||||
*/
|
||||
|
@ -365,34 +395,44 @@ class user extends common {
|
|||
* Liste des utilisateurs
|
||||
*/
|
||||
public function index() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['index'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
|
||||
$userIdsFirstnames = helper::arrayCollumn($this->getData(['user']), 'firstname');
|
||||
ksort($userIdsFirstnames);
|
||||
foreach($userIdsFirstnames as $userId => $userFirstname) {
|
||||
if ($this->getData(['user', $userId, 'group'])) {
|
||||
self::$users[] = [
|
||||
$userId,
|
||||
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
|
||||
$groups[$this->getData(['user', $userId, 'group'])],
|
||||
template::button('userEdit' . $userId, [
|
||||
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/back/'. $_SESSION['csrf'],
|
||||
'value' => template::ico('pencil')
|
||||
]),
|
||||
template::button('userDelete' . $userId, [
|
||||
'class' => 'userDelete buttonRed',
|
||||
'href' => helper::baseUrl() . 'user/delete/' . $userId. '/' . $_SESSION['csrf'],
|
||||
'value' => template::ico('cancel')
|
||||
])
|
||||
];
|
||||
$userIdsFirstnames = helper::arrayCollumn($this->getData(['user']), 'firstname');
|
||||
ksort($userIdsFirstnames);
|
||||
foreach($userIdsFirstnames as $userId => $userFirstname) {
|
||||
if ($this->getData(['user', $userId, 'group'])) {
|
||||
self::$users[] = [
|
||||
$userId,
|
||||
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
|
||||
$groups[$this->getData(['user', $userId, 'group'])],
|
||||
template::button('userEdit' . $userId, [
|
||||
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/back/'. $_SESSION['csrf'],
|
||||
'value' => template::ico('pencil')
|
||||
]),
|
||||
template::button('userDelete' . $userId, [
|
||||
'class' => 'userDelete buttonRed',
|
||||
'href' => helper::baseUrl() . 'user/delete/' . $userId. '/' . $_SESSION['csrf'],
|
||||
'value' => template::ico('cancel')
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_user']['index'][0],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_user']['index'][0],
|
||||
'view' => 'index'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -581,22 +621,32 @@ class user extends common {
|
|||
* Déconnexion
|
||||
*/
|
||||
public function logout() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Ne pas effacer l'identifiant mais seulement le mot de passe
|
||||
if (array_key_exists('DELTA_USER_LONGTIME',$_COOKIE)
|
||||
AND $_COOKIE['DELTA_USER_LONGTIME'] !== 'true' ) {
|
||||
helper::deleteCookie('DELTA_USER_ID');
|
||||
helper::deleteCookie('DELTA_USER_LONGTIME');
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['logout'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Ne pas effacer l'identifiant mais seulement le mot de passe
|
||||
if (array_key_exists('DELTA_USER_LONGTIME',$_COOKIE)
|
||||
AND $_COOKIE['DELTA_USER_LONGTIME'] !== 'true' ) {
|
||||
helper::deleteCookie('DELTA_USER_ID');
|
||||
helper::deleteCookie('DELTA_USER_LONGTIME');
|
||||
}
|
||||
helper::deleteCookie('DELTA_USER_PASSWORD');
|
||||
session_destroy();
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'notification' => $text['core_user']['logout'][0],
|
||||
'redirect' => helper::baseUrl(false),
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
helper::deleteCookie('DELTA_USER_PASSWORD');
|
||||
session_destroy();
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'notification' => $text['core_user']['logout'][0],
|
||||
'redirect' => helper::baseUrl(false),
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -662,128 +712,138 @@ class user extends common {
|
|||
* Importation CSV d'utilisateurs
|
||||
*/
|
||||
public function import() {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Soumission du formulaire
|
||||
$notification = '';
|
||||
$success = true;
|
||||
if($this->isPost()) {
|
||||
// Lecture du CSV et construction du tableau
|
||||
$file = $this->getInput('userImportCSVFile',helper::FILTER_STRING_SHORT, true);
|
||||
$filePath = self::FILE_DIR . 'source/' . $file;
|
||||
if ($file AND file_exists($filePath)) {
|
||||
// Analyse et extraction du CSV
|
||||
$rows = array_map(function($row) { return str_getcsv($row, $this->getInput('userImportSeparator') ); }, file($filePath));
|
||||
$header = array_shift($rows);
|
||||
$csv = array();
|
||||
foreach($rows as $row) {
|
||||
$csv[] = array_combine($header, $row);
|
||||
}
|
||||
// Traitement des données
|
||||
foreach($csv as $item ) {
|
||||
// Données valides
|
||||
if( array_key_exists('id', $item)
|
||||
AND array_key_exists('prenom',$item)
|
||||
AND array_key_exists('nom',$item)
|
||||
AND array_key_exists('groupe',$item)
|
||||
AND array_key_exists('email',$item)
|
||||
AND $item['nom']
|
||||
AND $item['prenom']
|
||||
AND $item['id']
|
||||
AND $item['email']
|
||||
AND $item['groupe']
|
||||
) {
|
||||
// Validation du groupe
|
||||
$item['groupe'] = (int) $item['groupe'];
|
||||
$item['groupe'] = ( $item['groupe'] >= self::GROUP_BANNED AND $item['groupe'] <= self::GROUP_ADMIN )
|
||||
? $item['groupe'] : 1;
|
||||
// L'utilisateur existe
|
||||
if ( $this->getData(['user',helper::filter($item['id'] , helper::FILTER_ID)]))
|
||||
{
|
||||
// Notification du doublon
|
||||
$item['notification'] = template::ico('cancel');
|
||||
// Création du tableau de confirmation
|
||||
self::$users[] = [
|
||||
helper::filter($item['id'] , helper::FILTER_ID),
|
||||
$item['nom'],
|
||||
$item['prenom'],
|
||||
$groups[$item['groupe']],
|
||||
$item['prenom'],
|
||||
helper::filter($item['email'] , helper::FILTER_MAIL),
|
||||
$item['notification']
|
||||
];
|
||||
// L'utilisateur n'existe pas
|
||||
} else {
|
||||
// Nettoyage de l'identifiant
|
||||
$userId = helper::filter($item['id'] , helper::FILTER_ID);
|
||||
// Enregistre le user
|
||||
$create = $this->setData([
|
||||
'user',
|
||||
$userId, [
|
||||
'firstname' => $item['prenom'],
|
||||
'forgot' => 0,
|
||||
'group' => $item['groupe'] ,
|
||||
'lastname' => $item['nom'],
|
||||
'mail' => $item['email'],
|
||||
'pseudo' => $item['prenom'],
|
||||
'signature' => 1, // Pseudo
|
||||
'password' => uniqid(), // A modifier à la première connexion
|
||||
"connectFail" => null,
|
||||
"connectTimeout" => null,
|
||||
"accessUrl" => null,
|
||||
"accessTimer" => null,
|
||||
"accessCsrf" => null
|
||||
]]);
|
||||
// Icône de notification
|
||||
$item['notification'] = $create ? template::ico('check') : template::ico('cancel');
|
||||
// Envoi du mail
|
||||
if ($create
|
||||
AND $this->getInput('userImportNotification',helper::FILTER_BOOLEAN) === true) {
|
||||
$sent = $this->sendMail(
|
||||
$item['email'],
|
||||
$text['core_user']['import'][0] . $this->getData(['locale', 'title']),
|
||||
$text['core_user']['import'][0].' <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' .
|
||||
$text['core_user']['import'][2]. $this->getData(['locale', 'title']) . $text['core_user']['import'][3].'<br><br>' .
|
||||
'<strong>'.$text['core_user']['import'][4].'</strong> ' . $userId . '<br>' .
|
||||
'<small>'.$text['core_user']['import'][5].'</small>'
|
||||
);
|
||||
if ($sent === true) {
|
||||
// Mail envoyé changement de l'icône
|
||||
$item['notification'] = template::ico('mail') ;
|
||||
// Autorisation
|
||||
$group = $this->getUser('group');
|
||||
if ($group === false ) $group = 0;
|
||||
if( $group < user::$actions['import'] ) {
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'access' => false
|
||||
]);
|
||||
} else {
|
||||
// Lexique
|
||||
include('./core/module/user/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_user.php');
|
||||
// Soumission du formulaire
|
||||
$notification = '';
|
||||
$success = true;
|
||||
if($this->isPost()) {
|
||||
// Lecture du CSV et construction du tableau
|
||||
$file = $this->getInput('userImportCSVFile',helper::FILTER_STRING_SHORT, true);
|
||||
$filePath = self::FILE_DIR . 'source/' . $file;
|
||||
if ($file AND file_exists($filePath)) {
|
||||
// Analyse et extraction du CSV
|
||||
$rows = array_map(function($row) { return str_getcsv($row, $this->getInput('userImportSeparator') ); }, file($filePath));
|
||||
$header = array_shift($rows);
|
||||
$csv = array();
|
||||
foreach($rows as $row) {
|
||||
$csv[] = array_combine($header, $row);
|
||||
}
|
||||
// Traitement des données
|
||||
foreach($csv as $item ) {
|
||||
// Données valides
|
||||
if( array_key_exists('id', $item)
|
||||
AND array_key_exists('prenom',$item)
|
||||
AND array_key_exists('nom',$item)
|
||||
AND array_key_exists('groupe',$item)
|
||||
AND array_key_exists('email',$item)
|
||||
AND $item['nom']
|
||||
AND $item['prenom']
|
||||
AND $item['id']
|
||||
AND $item['email']
|
||||
AND $item['groupe']
|
||||
) {
|
||||
// Validation du groupe
|
||||
$item['groupe'] = (int) $item['groupe'];
|
||||
$item['groupe'] = ( $item['groupe'] >= self::GROUP_BANNED AND $item['groupe'] <= self::GROUP_ADMIN )
|
||||
? $item['groupe'] : 1;
|
||||
// L'utilisateur existe
|
||||
if ( $this->getData(['user',helper::filter($item['id'] , helper::FILTER_ID)]))
|
||||
{
|
||||
// Notification du doublon
|
||||
$item['notification'] = template::ico('cancel');
|
||||
// Création du tableau de confirmation
|
||||
self::$users[] = [
|
||||
helper::filter($item['id'] , helper::FILTER_ID),
|
||||
$item['nom'],
|
||||
$item['prenom'],
|
||||
$groups[$item['groupe']],
|
||||
$item['prenom'],
|
||||
helper::filter($item['email'] , helper::FILTER_MAIL),
|
||||
$item['notification']
|
||||
];
|
||||
// L'utilisateur n'existe pas
|
||||
} else {
|
||||
// Nettoyage de l'identifiant
|
||||
$userId = helper::filter($item['id'] , helper::FILTER_ID);
|
||||
// Enregistre le user
|
||||
$create = $this->setData([
|
||||
'user',
|
||||
$userId, [
|
||||
'firstname' => $item['prenom'],
|
||||
'forgot' => 0,
|
||||
'group' => $item['groupe'] ,
|
||||
'lastname' => $item['nom'],
|
||||
'mail' => $item['email'],
|
||||
'pseudo' => $item['prenom'],
|
||||
'signature' => 1, // Pseudo
|
||||
'password' => uniqid(), // A modifier à la première connexion
|
||||
"connectFail" => null,
|
||||
"connectTimeout" => null,
|
||||
"accessUrl" => null,
|
||||
"accessTimer" => null,
|
||||
"accessCsrf" => null
|
||||
]]);
|
||||
// Icône de notification
|
||||
$item['notification'] = $create ? template::ico('check') : template::ico('cancel');
|
||||
// Envoi du mail
|
||||
if ($create
|
||||
AND $this->getInput('userImportNotification',helper::FILTER_BOOLEAN) === true) {
|
||||
$sent = $this->sendMail(
|
||||
$item['email'],
|
||||
$text['core_user']['import'][0] . $this->getData(['locale', 'title']),
|
||||
$text['core_user']['import'][0].' <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' .
|
||||
$text['core_user']['import'][2]. $this->getData(['locale', 'title']) . $text['core_user']['import'][3].'<br><br>' .
|
||||
'<strong>'.$text['core_user']['import'][4].'</strong> ' . $userId . '<br>' .
|
||||
'<small>'.$text['core_user']['import'][5].'</small>'
|
||||
);
|
||||
if ($sent === true) {
|
||||
// Mail envoyé changement de l'icône
|
||||
$item['notification'] = template::ico('mail') ;
|
||||
}
|
||||
}
|
||||
// Création du tableau de confirmation
|
||||
self::$users[] = [
|
||||
$userId,
|
||||
$item['nom'],
|
||||
$item['prenom'],
|
||||
$groups[$item['groupe']],
|
||||
$item['prenom'],
|
||||
$item['email'],
|
||||
$item['notification']
|
||||
];
|
||||
}
|
||||
// Création du tableau de confirmation
|
||||
self::$users[] = [
|
||||
$userId,
|
||||
$item['nom'],
|
||||
$item['prenom'],
|
||||
$groups[$item['groupe']],
|
||||
$item['prenom'],
|
||||
$item['email'],
|
||||
$item['notification']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty(self::$users)) {
|
||||
$notification = $text['core_user']['import'][6] ;
|
||||
$success = false;
|
||||
if (empty(self::$users)) {
|
||||
$notification = $text['core_user']['import'][6] ;
|
||||
$success = false;
|
||||
} else {
|
||||
$notification = $text['core_user']['import'][7] ;
|
||||
$success = true;
|
||||
}
|
||||
} else {
|
||||
$notification = $text['core_user']['import'][7] ;
|
||||
$success = true;
|
||||
$notification = $text['core_user']['import'][8];
|
||||
$success = false;
|
||||
}
|
||||
} else {
|
||||
$notification = $text['core_user']['import'][8];
|
||||
$success = false;
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_user']['import'][9],
|
||||
'view' => 'import',
|
||||
'notification' => $notification,
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'title' => $text['core_user']['import'][9],
|
||||
'view' => 'import',
|
||||
'notification' => $notification,
|
||||
'state' => $success
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue