diff --git a/CHANGES.md b/CHANGES.md index 28da2a7..e49dcef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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, diff --git a/core/module/addon/addon.php b/core/module/addon/addon.php index 55bf508..bc46a1f 100644 --- a/core/module/addon/addon.php +++ b/core/module/addon/addon.php @@ -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'], + ''.$store[$key]['title'].'', + $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'], - ''.$store[$key]['title'].'', - $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' - ]); } } diff --git a/core/module/config/config.php b/core/module/config/config.php index f522673..49fdafd 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -167,20 +167,30 @@ class config extends common { * Robots.txt */ public function generateFiles() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['generateFiles'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - // Mettre à jour le site map - $successSitemap=$this->createSitemap(); + // Mettre à jour le site map + $successSitemap=$this->createSitemap(); - // Valeurs en sortie - $this->addOutput([ - /*'title' => 'Configuration', - 'view' => 'index',*/ - 'redirect' => helper::baseUrl() . 'config', - 'notification' => $successSitemap ? $text['core_config']['generateFiles'][0] : $text['core_config']['generateFiles'][1], - 'state' => $successSitemap - ]); + // Valeurs en sortie + $this->addOutput([ + /*'title' => 'Configuration', + 'view' => 'index',*/ + 'redirect' => helper::baseUrl() . 'config', + 'notification' => $successSitemap ? $text['core_config']['generateFiles'][0] : $text['core_config']['generateFiles'][1], + 'state' => $successSitemap + ]); + } } @@ -188,33 +198,43 @@ class config extends common { * Sauvegarde des données */ public function backup() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - // Soumission du formulaire - if($this->isPost()) { - // Creation du ZIP - $filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file']; - $fileName = helper::autoBackup(self::TEMP_DIR,$filter); - // Créer le répertoire manquant - if (!is_dir(self::FILE_DIR.'source/backup')) { - mkdir(self::FILE_DIR.'source/backup', 0755); - } - // Copie dans les fichiers - $success = copy (self::TEMP_DIR . $fileName , self::FILE_DIR.'source/backup/' . $fileName); - // Détruire le temporaire - unlink(self::TEMP_DIR . $fileName); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['backup'] ) { // Valeurs en sortie $this->addOutput([ - 'display' => self::DISPLAY_JSON, - 'content' => json_encode($success) - ]); + 'access' => false + ]); } else { - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['backup'][0], - 'view' => 'backup' - ]); + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + // Soumission du formulaire + if($this->isPost()) { + // Creation du ZIP + $filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file']; + $fileName = helper::autoBackup(self::TEMP_DIR,$filter); + // Créer le répertoire manquant + if (!is_dir(self::FILE_DIR.'source/backup')) { + mkdir(self::FILE_DIR.'source/backup', 0755); + } + // Copie dans les fichiers + $success = copy (self::TEMP_DIR . $fileName , self::FILE_DIR.'source/backup/' . $fileName); + // Détruire le temporaire + unlink(self::TEMP_DIR . $fileName); + // Valeurs en sortie + $this->addOutput([ + 'display' => self::DISPLAY_JSON, + 'content' => json_encode($success) + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['backup'][0], + 'view' => 'backup' + ]); + } } } @@ -222,100 +242,120 @@ class config extends common { * Active ou désactive le mode Open Graph */ public function configOpenGraph() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['configOpenGraph'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - $texte=''; - if( isset($_SESSION['screenshot']) && $_SESSION['screenshot'] === 'on'){ - $_SESSION['screenshot'] = 'off'; - $texte = $text['core_config']['configOpenGraph'][0]; + $texte=''; + if( isset($_SESSION['screenshot']) && $_SESSION['screenshot'] === 'on'){ + $_SESSION['screenshot'] = 'off'; + $texte = $text['core_config']['configOpenGraph'][0]; + } + else{ + $_SESSION['screenshot'] = 'on'; + $texte = $text['core_config']['configOpenGraph'][1]; + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'config', + 'notification' => $texte, + 'state' => true + ]); } - else{ - $_SESSION['screenshot'] = 'on'; - $texte = $text['core_config']['configOpenGraph'][1]; - } - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'config', - 'notification' => $texte, - 'state' => true - ]); } /** * Procédure d'importation */ public function restore() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - // Soumission du formulaire - if($this->isPost() ) { - - $success = false; - - if ($this->getInput('configRestoreImportFile', null, true) ) { - - $fileZip = $this->getInput('configRestoreImportFile'); - $file_parts = pathinfo($fileZip); - $folder = date('Y-m-d-h-i-s', time()); - $zip = new ZipArchive(); - if ($file_parts['extension'] !== 'zip') { - // Valeurs en sortie erreur - $this->addOutput([ - 'title' => $text['core_config']['restore'][0], - 'view' => 'restore', - 'notification' => $text['core_config']['restore'][1], - 'state' => false - ]); - } - $successOpen = $zip->open(self::FILE_DIR . 'source/' . $fileZip); - if ($successOpen === FALSE) { - // Valeurs en sortie erreur - $this->addOutput([ - 'title' => $text['core_config']['restore'][0], - 'view' => 'restore', - 'notification' => $text['core_config']['restore'][2], - 'state' => false - ]); - } - // Lire le contenu de l'archive dans le tableau files - for( $i = 0; $i < $zip->numFiles; $i++ ){ - $stat = $zip->statIndex( $i ); - $files [] = ( basename( $stat['name'] )); - } - - // Option active, les users sont stockées - if ($this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ) $users = $this->getData(['user']); - - // Extraire le zip ou 'site/' - $this->removeDir(self::DATA_DIR); - $success = $zip->extractTo( 'site/' ); - // Fermer l'archive - $zip->close(); - - // Restaurer les users originaux d'une v10 si option cochée - if (!empty($users) && $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true) $this->setData(['user',$users]); - } - - // Message de notification - $notification = $success === true ? $text['core_config']['restore'][4] : $text['core_config']['restore'][5] ; - $redirect = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/restore' : helper::baseUrl() . 'user/login/'; - // Valeurs en sortie erreur + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['restore'] ) { + // Valeurs en sortie $this->addOutput([ - /*'title' => $text['core_config']['restore'][0], - 'view' => 'restore',*/ - 'redirect' => $redirect, - 'notification' => $notification, - 'state' => $success + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + // Soumission du formulaire + if($this->isPost() ) { + + $success = false; + + if ($this->getInput('configRestoreImportFile', null, true) ) { + + $fileZip = $this->getInput('configRestoreImportFile'); + $file_parts = pathinfo($fileZip); + $folder = date('Y-m-d-h-i-s', time()); + $zip = new ZipArchive(); + if ($file_parts['extension'] !== 'zip') { + // Valeurs en sortie erreur + $this->addOutput([ + 'title' => $text['core_config']['restore'][0], + 'view' => 'restore', + 'notification' => $text['core_config']['restore'][1], + 'state' => false + ]); + } + $successOpen = $zip->open(self::FILE_DIR . 'source/' . $fileZip); + if ($successOpen === FALSE) { + // Valeurs en sortie erreur + $this->addOutput([ + 'title' => $text['core_config']['restore'][0], + 'view' => 'restore', + 'notification' => $text['core_config']['restore'][2], + 'state' => false + ]); + } + // Lire le contenu de l'archive dans le tableau files + for( $i = 0; $i < $zip->numFiles; $i++ ){ + $stat = $zip->statIndex( $i ); + $files [] = ( basename( $stat['name'] )); + } + + // Option active, les users sont stockées + if ($this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ) $users = $this->getData(['user']); + + // Extraire le zip ou 'site/' + $this->removeDir(self::DATA_DIR); + $success = $zip->extractTo( 'site/' ); + // Fermer l'archive + $zip->close(); + + // Restaurer les users originaux d'une v10 si option cochée + if (!empty($users) && $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true) $this->setData(['user',$users]); + } + + // Message de notification + $notification = $success === true ? $text['core_config']['restore'][4] : $text['core_config']['restore'][5] ; + $redirect = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/restore' : helper::baseUrl() . 'user/login/'; + // Valeurs en sortie erreur + $this->addOutput([ + /*'title' => $text['core_config']['restore'][0], + 'view' => 'restore',*/ + 'redirect' => $redirect, + 'notification' => $notification, + 'state' => $success + ]); + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['restore'][0], + 'view' => 'restore' ]); } - - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['restore'][0], - 'view' => 'restore' - ]); } @@ -323,249 +363,278 @@ class config extends common { * Configuration */ public function index() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - // Soumission du formulaire - if($this->isPost()) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['index'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + // Soumission du formulaire + if($this->isPost()) { - // Basculement en mise à jour auto, remise à 0 du compteur - if ($this->getData(['config','autoUpdate']) === false && - $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN) === true) { - $this->setData(['core','lastAutoUpdate',0]); - } - - // Eviter déconnexion automatique après son activation - if ( $this->getData(['config','connect', 'autoDisconnect']) === false - AND $this->getInput('configAutoDisconnect',helper::FILTER_BOOLEAN) === true ) { - $this->setData(['user',$this->getuser('id'),'accessCsrf',$_SESSION['csrf']]); - } - // Répercuter la suppression de la page dans la configuration du footer - if ( $this->getData(['theme','footer','displaySearch']) === true - AND $this->getInput('configSearchPageId') === 'none' - ){ - $this->setData(['theme', 'footer', 'displaySearch', false]); - } - if ( $this->getData(['theme','footer','displayLegal']) === true - AND $this->getInput('configLegalPageId') === 'none' - ){ - $this->setData(['theme', 'footer', 'displayLegal', false]); - } - - // Sauvegarder les locales - $this->setData([ - 'locale', - [ - 'homePageId' => $this->getInput('localeHomePageId', helper::FILTER_ID, true), - 'page404' => $this->getInput('localePage404'), - 'page403' => $this->getInput('localePage403'), - 'page302' => $this->getInput('localePage302'), - 'legalPageId' => $this->getInput('localeLegalPageId'), - 'searchPageId' => $this->getInput('localeSearchPageId'), - 'searchPageLabel' => empty($this->getInput('localeSearchPageLabel', helper::FILTER_STRING_SHORT)) ? 'Rechercher' : $this->getInput('localeSearchPageLabel', helper::FILTER_STRING_SHORT), - 'legalPageLabel' => empty($this->getInput('localeLegalPageLabel', helper::FILTER_STRING_SHORT)) ? 'Mentions légales' : $this->getInput('localeLegalPageLabel', helper::FILTER_STRING_SHORT), - 'sitemapPageLabel' => empty($this->getInput('localeSitemapPageLabel', helper::FILTER_STRING_SHORT)) ? 'Plan du site' : $this->getInput('localeSitemapPageLabel', helper::FILTER_STRING_SHORT), - 'visitorLabel' => $this->getInput('localeVisitorLabel', helper::FILTER_STRING_SHORT), - 'memberLabel' => $this->getInput('localeMemberLabel', helper::FILTER_STRING_SHORT), - 'editorLabel' => $this->getInput('localeEditorLabel', helper::FILTER_STRING_SHORT), - 'moderatorLabel' => $this->getInput('localeModeratorLabel', helper::FILTER_STRING_SHORT), - 'administratorLabel' => $this->getInput('localeAdministratorLabel', helper::FILTER_STRING_SHORT), - 'metaDescription' => $this->getInput('localeMetaDescription', helper::FILTER_STRING_LONG, true), - 'title' => $this->getInput('localeTitle', helper::FILTER_STRING_SHORT, true), - 'captchaSimpleText' => $this->getInput('localeCaptchaSimpleText', helper::FILTER_STRING_LONG), - 'captchaSimpleHelp' => $this->getInput('localeCaptchaSimpleHelp', helper::FILTER_STRING_LONG), - 'cookies' => [ - // Les champs sont obligatoires si l'option consentement des cookies est active - 'cookiesDeltaText' => $this->getInput('localeCookiesDeltaText', helper::FILTER_STRING_LONG, $this->getData(['config', 'cookieConsent'])), - 'cookiesExtText' => $this->getInput('localeCookiesExtText', helper::FILTER_STRING_LONG), - 'cookiesTitleText' => $this->getInput('localeCookiesTitleText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), - 'cookiesLinkMlText' => $this->getInput('localeCookiesLinkMlText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), - 'cookiesCheckboxExtText' => $this->getInput('localeCookiesCheckboxExtText', helper::FILTER_STRING_SHORT), - 'cookiesFooterText' => $this->getInput('localeCookiesFooterText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), - 'cookiesButtonText' =>$this->getInput('localeCookiesButtonText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])) - ] - ] - ]); - - // Sauvegarder la configuration - $this->setData([ - 'config', - [ - 'favicon' => $this->getInput('configFavicon'), - 'faviconDark' => $this->getInput('configFaviconDark'), - 'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true), - 'autoUpdate' => $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN), - 'autoUpdateHtaccess' => $this->getInput('configAutoUpdateHtaccess', helper::FILTER_BOOLEAN), - 'autoBackup' => $this->getInput('configAutoBackup', helper::FILTER_BOOLEAN), - 'maintenance' => $this->getInput('configMaintenance', helper::FILTER_BOOLEAN), - 'cookieConsent' => $this->getInput('configCookieConsent', helper::FILTER_BOOLEAN), - 'proxyType' => $this->getInput('configProxyType'), - 'proxyUrl' => $this->getInput('configProxyUrl'), - 'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT), - 'social' => [ - 'facebookId' => $this->getInput('socialFacebookId'), - 'linkedinId' => $this->getInput('socialLinkedinId'), - 'instagramId' => $this->getInput('socialInstagramId'), - 'pinterestId' => $this->getInput('socialPinterestId'), - 'twitterId' => $this->getInput('socialTwitterId'), - 'youtubeId' => $this->getInput('socialYoutubeId'), - 'youtubeUserId' => $this->getInput('socialYoutubeUserId'), - 'githubId' => $this->getInput('socialGithubId'), - 'headFacebook' => $this->getInput('socialHeadFacebook', helper::FILTER_BOOLEAN) - ], - 'smtp' => [ - 'enable' => $this->getInput('smtpEnable',helper::FILTER_BOOLEAN), - 'host' => $this->getInput('smtpHost',helper::FILTER_STRING_SHORT,$this->getInput('smtpEnable',helper::FILTER_BOOLEAN)), - 'port' => $this->getInput('smtpPort',helper::FILTER_INT,$this->getInput('smtpEnable',helper::FILTER_BOOLEAN)), - 'auth' => $this->getInput('smtpAuth',helper::FILTER_BOOLEAN), - 'secure' => $this->getInput('smtpSecure',helper::FILTER_BOOLEAN), - 'username' => $this->getInput('smtpUsername',helper::FILTER_STRING_SHORT,$this->getInput('smtpAuth',helper::FILTER_BOOLEAN)), - 'password' =>helper::encrypt($this->getData(['config','smtp','username']),$this->getInput('smtpPassword',null,$this->getInput('smtpAuth',helper::FILTER_BOOLEAN))), - 'sender' => $this->getInput('smtpSender',helper::FILTER_MAIL) - ], - 'seo' => [ - 'robots' => $this->getInput('seoRobots',helper::FILTER_BOOLEAN), - 'analyticsId' => $this->getInput('seoAnalyticsId') - ], - 'connect' => [ - 'attempt' => $this->getInput('connectAttempt',helper::FILTER_INT), - 'timeout' => $this->getInput('connectTimeout',helper::FILTER_INT), - 'log' => $this->getInput('connectLog',helper::FILTER_BOOLEAN), - 'anonymousIp' => $this->getInput('connectAnonymousIp',helper::FILTER_INT), - 'captcha' => $this->getInput('connectCaptcha',helper::FILTER_BOOLEAN), - 'captchaBot' => $this->getInput('connectCaptchaBot',helper::FILTER_BOOLEAN), - 'autoDisconnect' => $this->getInput('connectAutoDisconnect',helper::FILTER_BOOLEAN), - 'passwordVisibility' => $this->getInput('connectPasswordVisibility',helper::FILTER_BOOLEAN) - ], - 'i18n' => [ - 'enable' => $this->getInput('localei18n',helper::FILTER_BOOLEAN), - 'scriptGoogle' => $this->getData(['config', 'i18n', 'scriptGoogle']), - 'showCredits' => $this->getData(['config', 'i18n', 'showCredits']), - 'autoDetect' => $this->getData(['config', 'i18n', 'autoDetect']), - //'admin' => $this->getData(['config', 'i18n', 'admin']), - 'langAdmin' => $this->getData(['config', 'i18n', 'langAdmin']), - 'langBase' => $this->getData(['config', 'i18n', 'langBase']), - 'fr' => $this->getData(['config', 'i18n', 'fr']), - 'de' => $this->getData(['config', 'i18n', 'de']), - 'en' => $this->getData(['config', 'i18n', 'en']), - 'es' => $this->getData(['config', 'i18n', 'es']), - 'it' => $this->getData(['config', 'i18n', 'it']), - 'nl' => $this->getData(['config', 'i18n', 'nl']), - 'pt' => $this->getData(['config', 'i18n', 'pt']), - 'el' => $this->getData(['config', 'i18n', 'el']), - 'da' => $this->getData(['config', 'i18n', 'da']), - 'fi' => $this->getData(['config', 'i18n', 'fi']), - 'ga' => $this->getData(['config', 'i18n', 'ga']), - 'sv' => $this->getData(['config', 'i18n', 'sv']), - 'br' => $this->getData(['config', 'i18n', 'br']), - 'ca' => $this->getData(['config', 'i18n', 'ca']), - 'co' => $this->getData(['config', 'i18n', 'co']), - 'eu' => $this->getData(['config', 'i18n', 'eu']) - ], - 'statislite' => [ - 'enable' => $this->getData(['config', 'statislite', 'enable']) - ] - ] - ]); - - // Efface les fichiers de backup lorsque l'option est désactivée - if ($this->getInput('configFileBackup', helper::FILTER_BOOLEAN) === false) { - $path = realpath('site/data'); - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename) - { - if (strpos($filename,'backup.json')) { - unlink($filename); + // Basculement en mise à jour auto, remise à 0 du compteur + if ($this->getData(['config','autoUpdate']) === false && + $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN) === true) { + $this->setData(['core','lastAutoUpdate',0]); } + + // Eviter déconnexion automatique après son activation + if ( $this->getData(['config','connect', 'autoDisconnect']) === false + AND $this->getInput('configAutoDisconnect',helper::FILTER_BOOLEAN) === true ) { + $this->setData(['user',$this->getuser('id'),'accessCsrf',$_SESSION['csrf']]); } - if (file_exists('site/data/.backup')) unlink('site/data/.backup'); - } else { - touch('site/data/.backup'); + // Répercuter la suppression de la page dans la configuration du footer + if ( $this->getData(['theme','footer','displaySearch']) === true + AND $this->getInput('configSearchPageId') === 'none' + ){ + $this->setData(['theme', 'footer', 'displaySearch', false]); + } + if ( $this->getData(['theme','footer','displayLegal']) === true + AND $this->getInput('configLegalPageId') === 'none' + ){ + $this->setData(['theme', 'footer', 'displayLegal', false]); + } + + // Sauvegarder les locales + $this->setData([ + 'locale', + [ + 'homePageId' => $this->getInput('localeHomePageId', helper::FILTER_ID, true), + 'page404' => $this->getInput('localePage404'), + 'page403' => $this->getInput('localePage403'), + 'page302' => $this->getInput('localePage302'), + 'legalPageId' => $this->getInput('localeLegalPageId'), + 'searchPageId' => $this->getInput('localeSearchPageId'), + 'searchPageLabel' => empty($this->getInput('localeSearchPageLabel', helper::FILTER_STRING_SHORT)) ? 'Rechercher' : $this->getInput('localeSearchPageLabel', helper::FILTER_STRING_SHORT), + 'legalPageLabel' => empty($this->getInput('localeLegalPageLabel', helper::FILTER_STRING_SHORT)) ? 'Mentions légales' : $this->getInput('localeLegalPageLabel', helper::FILTER_STRING_SHORT), + 'sitemapPageLabel' => empty($this->getInput('localeSitemapPageLabel', helper::FILTER_STRING_SHORT)) ? 'Plan du site' : $this->getInput('localeSitemapPageLabel', helper::FILTER_STRING_SHORT), + 'visitorLabel' => $this->getInput('localeVisitorLabel', helper::FILTER_STRING_SHORT), + 'memberLabel' => $this->getInput('localeMemberLabel', helper::FILTER_STRING_SHORT), + 'editorLabel' => $this->getInput('localeEditorLabel', helper::FILTER_STRING_SHORT), + 'moderatorLabel' => $this->getInput('localeModeratorLabel', helper::FILTER_STRING_SHORT), + 'administratorLabel' => $this->getInput('localeAdministratorLabel', helper::FILTER_STRING_SHORT), + 'metaDescription' => $this->getInput('localeMetaDescription', helper::FILTER_STRING_LONG, true), + 'title' => $this->getInput('localeTitle', helper::FILTER_STRING_SHORT, true), + 'captchaSimpleText' => $this->getInput('localeCaptchaSimpleText', helper::FILTER_STRING_LONG), + 'captchaSimpleHelp' => $this->getInput('localeCaptchaSimpleHelp', helper::FILTER_STRING_LONG), + 'cookies' => [ + // Les champs sont obligatoires si l'option consentement des cookies est active + 'cookiesDeltaText' => $this->getInput('localeCookiesDeltaText', helper::FILTER_STRING_LONG, $this->getData(['config', 'cookieConsent'])), + 'cookiesExtText' => $this->getInput('localeCookiesExtText', helper::FILTER_STRING_LONG), + 'cookiesTitleText' => $this->getInput('localeCookiesTitleText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), + 'cookiesLinkMlText' => $this->getInput('localeCookiesLinkMlText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), + 'cookiesCheckboxExtText' => $this->getInput('localeCookiesCheckboxExtText', helper::FILTER_STRING_SHORT), + 'cookiesFooterText' => $this->getInput('localeCookiesFooterText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])), + 'cookiesButtonText' =>$this->getInput('localeCookiesButtonText', helper::FILTER_STRING_SHORT, $this->getData(['config', 'cookieConsent'])) + ] + ] + ]); + + // Sauvegarder la configuration + $this->setData([ + 'config', + [ + 'favicon' => $this->getInput('configFavicon'), + 'faviconDark' => $this->getInput('configFaviconDark'), + 'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true), + 'autoUpdate' => $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN), + 'autoUpdateHtaccess' => $this->getInput('configAutoUpdateHtaccess', helper::FILTER_BOOLEAN), + 'autoBackup' => $this->getInput('configAutoBackup', helper::FILTER_BOOLEAN), + 'maintenance' => $this->getInput('configMaintenance', helper::FILTER_BOOLEAN), + 'cookieConsent' => $this->getInput('configCookieConsent', helper::FILTER_BOOLEAN), + 'proxyType' => $this->getInput('configProxyType'), + 'proxyUrl' => $this->getInput('configProxyUrl'), + 'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT), + 'social' => [ + 'facebookId' => $this->getInput('socialFacebookId'), + 'linkedinId' => $this->getInput('socialLinkedinId'), + 'instagramId' => $this->getInput('socialInstagramId'), + 'pinterestId' => $this->getInput('socialPinterestId'), + 'twitterId' => $this->getInput('socialTwitterId'), + 'youtubeId' => $this->getInput('socialYoutubeId'), + 'youtubeUserId' => $this->getInput('socialYoutubeUserId'), + 'githubId' => $this->getInput('socialGithubId'), + 'headFacebook' => $this->getInput('socialHeadFacebook', helper::FILTER_BOOLEAN) + ], + 'smtp' => [ + 'enable' => $this->getInput('smtpEnable',helper::FILTER_BOOLEAN), + 'host' => $this->getInput('smtpHost',helper::FILTER_STRING_SHORT,$this->getInput('smtpEnable',helper::FILTER_BOOLEAN)), + 'port' => $this->getInput('smtpPort',helper::FILTER_INT,$this->getInput('smtpEnable',helper::FILTER_BOOLEAN)), + 'auth' => $this->getInput('smtpAuth',helper::FILTER_BOOLEAN), + 'secure' => $this->getInput('smtpSecure',helper::FILTER_BOOLEAN), + 'username' => $this->getInput('smtpUsername',helper::FILTER_STRING_SHORT,$this->getInput('smtpAuth',helper::FILTER_BOOLEAN)), + 'password' =>helper::encrypt($this->getData(['config','smtp','username']),$this->getInput('smtpPassword',null,$this->getInput('smtpAuth',helper::FILTER_BOOLEAN))), + 'sender' => $this->getInput('smtpSender',helper::FILTER_MAIL) + ], + 'seo' => [ + 'robots' => $this->getInput('seoRobots',helper::FILTER_BOOLEAN), + 'analyticsId' => $this->getInput('seoAnalyticsId') + ], + 'connect' => [ + 'attempt' => $this->getInput('connectAttempt',helper::FILTER_INT), + 'timeout' => $this->getInput('connectTimeout',helper::FILTER_INT), + 'log' => $this->getInput('connectLog',helper::FILTER_BOOLEAN), + 'anonymousIp' => $this->getInput('connectAnonymousIp',helper::FILTER_INT), + 'captcha' => $this->getInput('connectCaptcha',helper::FILTER_BOOLEAN), + 'captchaBot' => $this->getInput('connectCaptchaBot',helper::FILTER_BOOLEAN), + 'autoDisconnect' => $this->getInput('connectAutoDisconnect',helper::FILTER_BOOLEAN), + 'passwordVisibility' => $this->getInput('connectPasswordVisibility',helper::FILTER_BOOLEAN) + ], + 'i18n' => [ + 'enable' => $this->getInput('localei18n',helper::FILTER_BOOLEAN), + 'scriptGoogle' => $this->getData(['config', 'i18n', 'scriptGoogle']), + 'showCredits' => $this->getData(['config', 'i18n', 'showCredits']), + 'autoDetect' => $this->getData(['config', 'i18n', 'autoDetect']), + //'admin' => $this->getData(['config', 'i18n', 'admin']), + 'langAdmin' => $this->getData(['config', 'i18n', 'langAdmin']), + 'langBase' => $this->getData(['config', 'i18n', 'langBase']), + 'fr' => $this->getData(['config', 'i18n', 'fr']), + 'de' => $this->getData(['config', 'i18n', 'de']), + 'en' => $this->getData(['config', 'i18n', 'en']), + 'es' => $this->getData(['config', 'i18n', 'es']), + 'it' => $this->getData(['config', 'i18n', 'it']), + 'nl' => $this->getData(['config', 'i18n', 'nl']), + 'pt' => $this->getData(['config', 'i18n', 'pt']), + 'el' => $this->getData(['config', 'i18n', 'el']), + 'da' => $this->getData(['config', 'i18n', 'da']), + 'fi' => $this->getData(['config', 'i18n', 'fi']), + 'ga' => $this->getData(['config', 'i18n', 'ga']), + 'sv' => $this->getData(['config', 'i18n', 'sv']), + 'br' => $this->getData(['config', 'i18n', 'br']), + 'ca' => $this->getData(['config', 'i18n', 'ca']), + 'co' => $this->getData(['config', 'i18n', 'co']), + 'eu' => $this->getData(['config', 'i18n', 'eu']) + ], + 'statislite' => [ + 'enable' => $this->getData(['config', 'statislite', 'enable']) + ] + ] + ]); + + // Efface les fichiers de backup lorsque l'option est désactivée + if ($this->getInput('configFileBackup', helper::FILTER_BOOLEAN) === false) { + $path = realpath('site/data'); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename) + { + if (strpos($filename,'backup.json')) { + unlink($filename); + } + } + if (file_exists('site/data/.backup')) unlink('site/data/.backup'); + } else { + touch('site/data/.backup'); + } + // Notice + if(self::$inputNotices === []) { + // Active la réécriture d'URL + $rewrite = $this->getInput('configRewrite', helper::FILTER_BOOLEAN); + if( + $rewrite + AND helper::checkRewrite() === false + ) { + // Ajout des lignes dans le .htaccess + file_put_contents( + '.htaccess', + PHP_EOL . + '' . 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 . + '', + FILE_APPEND + ); + // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) + helper::$rewriteStatus = true; + } + // Désactive la réécriture d'URL + elseif( + $rewrite === false + AND helper::checkRewrite() + ) { + // Suppression des lignes dans le .htaccess + $htaccess = explode('# URL rewriting', file_get_contents('.htaccess')); + file_put_contents('.htaccess', $htaccess[0] . '# URL rewriting'); + // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) + helper::$rewriteStatus = false; + } + // Met à jour la baseUrl + $this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]); + } + // Générer robots.txt et sitemap + // $this->generateFiles(); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['index'][0], + 'redirect' => helper::baseUrl() . 'config', + 'notification' => $text['core_config']['index'][1] , + 'state' => true + ]); } - // Notice - if(self::$inputNotices === []) { - // Active la réécriture d'URL - $rewrite = $this->getInput('configRewrite', helper::FILTER_BOOLEAN); - if( - $rewrite - AND helper::checkRewrite() === false - ) { - // Ajout des lignes dans le .htaccess - file_put_contents( - '.htaccess', - PHP_EOL . - '' . 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 . - '', - FILE_APPEND - ); - // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) - helper::$rewriteStatus = true; + // Générer la list des pages disponibles + self::$pagesList = $this->getData(['page']); + foreach(self::$pagesList as $page => $pageId) { + if ($this->getData(['page',$page,'block']) === 'bar' || + $this->getData(['page',$page,'disable']) === true) { + unset(self::$pagesList[$page]); + } + } + + self::$orphansList = $this->getData(['page']); + foreach(self::$orphansList as $page => $pageId) { + if ($this->getData(['page',$page,'block']) === 'bar' || + $this->getData(['page',$page,'disable']) === true || + $this->getdata(['page',$page, 'position']) !== 0) { + unset(self::$orphansList[$page]); } - // Désactive la réécriture d'URL - elseif( - $rewrite === false - AND helper::checkRewrite() - ) { - // Suppression des lignes dans le .htaccess - $htaccess = explode('# URL rewriting', file_get_contents('.htaccess')); - file_put_contents('.htaccess', $htaccess[0] . '# URL rewriting'); - // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) - helper::$rewriteStatus = false; - } - // Met à jour la baseUrl - $this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]); } - // Générer robots.txt et sitemap - // $this->generateFiles(); // Valeurs en sortie $this->addOutput([ 'title' => $text['core_config']['index'][0], - 'redirect' => helper::baseUrl() . 'config', - 'notification' => $text['core_config']['index'][1] , - 'state' => true + 'view' => 'index' ]); } - // Générer la list des pages disponibles - self::$pagesList = $this->getData(['page']); - foreach(self::$pagesList as $page => $pageId) { - if ($this->getData(['page',$page,'block']) === 'bar' || - $this->getData(['page',$page,'disable']) === true) { - unset(self::$pagesList[$page]); - } - } - - self::$orphansList = $this->getData(['page']); - foreach(self::$orphansList as $page => $pageId) { - if ($this->getData(['page',$page,'block']) === 'bar' || - $this->getData(['page',$page,'disable']) === true || - $this->getdata(['page',$page, 'position']) !== 0) { - unset(self::$orphansList[$page]); - } - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['index'][0], - 'view' => 'index' - ]); } public function script() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['script'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - // Soumission du formulaire - if($this->isPost()) { - // Ecrire les fichiers de script - if ($this->geturl(2) === 'head') { - file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null)); - } - if ($this->geturl(2) === 'body') { - file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null)); + // Soumission du formulaire + if($this->isPost()) { + // Ecrire les fichiers de script + if ($this->geturl(2) === 'head') { + file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null)); + } + if ($this->geturl(2) === 'body') { + file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null)); + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['script'][0] . ucfirst($this->geturl(2)) , + 'vendor' => [ + 'tinymce/plugins/codemirror/codemirror' + ], + 'view' => 'script', + 'state' => true + ]); } // Valeurs en sortie $this->addOutput([ @@ -573,18 +642,9 @@ class config extends common { 'vendor' => [ 'tinymce/plugins/codemirror/codemirror' ], - 'view' => 'script', - 'state' => true + 'view' => 'script' ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['script'][0] . ucfirst($this->geturl(2)) , - 'vendor' => [ - 'tinymce/plugins/codemirror/codemirror' - ], - 'view' => 'script' - ]); } @@ -593,31 +653,40 @@ class config extends common { */ public function logReset() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - if ( file_exists(self::DATA_DIR . 'journal.log') ) { - unlink(self::DATA_DIR . 'journal.log'); - // Créer les en-têtes des journaux - $d = 'Date;Heure;IP;Id;Action' . PHP_EOL; - file_put_contents(self::DATA_DIR . 'journal.log',$d); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['logReset'][0], - 'view' => 'index', - 'notification' => $text['core_config']['logReset'][1], - 'state' => true - ]); - } else { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['logReset'] ) { // Valeurs en sortie $this->addOutput([ - 'title' => $text['core_config']['logReset'][0], - 'view' => 'index', - 'notification' => $text['core_config']['logReset'][2], - 'state' => false - ]); - } + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + if ( file_exists(self::DATA_DIR . 'journal.log') ) { + unlink(self::DATA_DIR . 'journal.log'); + // Créer les en-têtes des journaux + $d = 'Date;Heure;IP;Id;Action' . PHP_EOL; + file_put_contents(self::DATA_DIR . 'journal.log',$d); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['logReset'][0], + 'view' => 'index', + 'notification' => $text['core_config']['logReset'][1], + 'state' => true + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['logReset'][0], + 'view' => 'index', + 'notification' => $text['core_config']['logReset'][2], + 'state' => false + ]); + } + } } @@ -626,27 +695,37 @@ class config extends common { * Télécharger le fichier de log */ public function logDownload() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - $fileName = self::DATA_DIR . 'journal.log'; - 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); - exit(); - } else { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['logDownload'] ) { // Valeurs en sortie $this->addOutput([ - 'title' => $text['core_config']['logDownload'][0], - 'view' => 'index', - 'notification' => $text['core_config']['logDownload'][1], - 'state' => false - ]); + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + $fileName = self::DATA_DIR . 'journal.log'; + 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); + exit(); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['logDownload'][0], + 'view' => 'index', + 'notification' => $text['core_config']['logDownload'][1], + 'state' => false + ]); + } } } @@ -654,39 +733,49 @@ class config extends common { * Tableau des IP blacklistés */ public function blacklistDownload () { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - ob_start(); - $fileName = self::TEMP_DIR . 'blacklist.log'; - $d = $text['core_config']['blacklistDownload'][0]. PHP_EOL; - file_put_contents($fileName,$d); - if ( file_exists($fileName) ) { - $d = $this->getData(['blacklist']); - $data = ''; - foreach ($d as $key => $item) { - $data .= mb_detect_encoding(strftime('%d/%m/%y',$item['lastFail']), 'UTF-8', true) - ? strftime('%d/%m/%y',$item['lastFail']) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' - : utf8_encode(strftime('%d/%m/%y',$item['lastFail'])) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' ; - $data .= $key . ';' . $item['ip'] . ';' . $item['connectFail'] . PHP_EOL; - } - file_put_contents($fileName,$data,FILE_APPEND); - 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(self::TEMP_DIR . 'blacklist.log'); - exit(); - } else { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['blacklistDownload'] ) { // Valeurs en sortie $this->addOutput([ - 'title' => $text['core_config']['blacklistDownload'][1], - 'view' => 'index', - 'notification' => $text['core_config']['blacklistDownload'][2], - 'state' => false - ]); + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + ob_start(); + $fileName = self::TEMP_DIR . 'blacklist.log'; + $d = $text['core_config']['blacklistDownload'][0]. PHP_EOL; + file_put_contents($fileName,$d); + if ( file_exists($fileName) ) { + $d = $this->getData(['blacklist']); + $data = ''; + foreach ($d as $key => $item) { + $data .= mb_detect_encoding(strftime('%d/%m/%y',$item['lastFail']), 'UTF-8', true) + ? strftime('%d/%m/%y',$item['lastFail']) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' + : utf8_encode(strftime('%d/%m/%y',$item['lastFail'])) . ';' . utf8_encode(strftime('%R',$item['lastFail'])) . ';' ; + $data .= $key . ';' . $item['ip'] . ';' . $item['connectFail'] . PHP_EOL; + } + file_put_contents($fileName,$data,FILE_APPEND); + 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(self::TEMP_DIR . 'blacklist.log'); + exit(); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['blacklistDownload'][1], + 'view' => 'index', + 'notification' => $text['core_config']['blacklistDownload'][2], + 'state' => false + ]); + } } } @@ -695,26 +784,36 @@ class config extends common { */ public function blacklistReset() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - if ( file_exists(self::DATA_DIR . 'blacklist.json') ) { - $this->setData(['blacklist',[]]); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['blacklistReset'][0], - 'view' => 'index', - 'notification' => $text['core_config']['blacklistReset'][1], - 'state' => true - ]); - } else { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['blacklistReset'] ) { // Valeurs en sortie $this->addOutput([ - 'title' => $text['core_config']['blacklistReset'][0], - 'view' => 'index', - 'notification' => $text['core_config']['blacklistReset'][2], - 'state' => false - ]); + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + if ( file_exists(self::DATA_DIR . 'blacklist.json') ) { + $this->setData(['blacklist',[]]); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['blacklistReset'][0], + 'view' => 'index', + 'notification' => $text['core_config']['blacklistReset'][1], + 'state' => true + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['blacklistReset'][0], + 'view' => 'index', + 'notification' => $text['core_config']['blacklistReset'][2], + 'state' => false + ]); + } } } @@ -722,21 +821,31 @@ class config extends common { * Récupération des backups auto dans le gestionnaire de fichiers */ public function copyBackups() { - // Lexique - include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); - - // Créer le répertoire manquant - if (!is_dir(self::FILE_DIR.'source/backup')) { - mkdir(self::FILE_DIR.'source/backup', 0755); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < config::$actions['copyBackups'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/config/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_config.php'); + + // Créer le répertoire manquant + if (!is_dir(self::FILE_DIR.'source/backup')) { + mkdir(self::FILE_DIR.'source/backup', 0755); + } + $this->copyDir(self::BACKUP_DIR, self::FILE_DIR . 'source/backup' ); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_config']['copyBackups'][0], + 'view' => 'index', + 'notification' => $text['core_config']['copyBackups'][1], + 'state' => true + ]); } - $this->copyDir(self::BACKUP_DIR, self::FILE_DIR . 'source/backup' ); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_config']['copyBackups'][0], - 'view' => 'index', - 'notification' => $text['core_config']['copyBackups'][1], - 'state' => true - ]); } diff --git a/core/module/install/install.php b/core/module/install/install.php index 7d6d30f..e03e9ba 100644 --- a/core/module/install/install.php +++ b/core/module/install/install.php @@ -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 . - '' . 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 . - '', - 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 . + '' . 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 . + '', + 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' + ]); + } } diff --git a/core/module/page/lang/en/lex_page.php b/core/module/page/lang/en/lex_page.php index 1250348..f6b37c0 100644 --- a/core/module/page/lang/en/lex_page.php +++ b/core/module/page/lang/en/lex_page.php @@ -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"; diff --git a/core/module/page/lang/es/lex_page.php b/core/module/page/lang/es/lex_page.php index 2120c3f..b6ce2fb 100644 --- a/core/module/page/lang/es/lex_page.php +++ b/core/module/page/lang/es/lex_page.php @@ -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"; diff --git a/core/module/page/lang/fr/lex_page.php b/core/module/page/lang/fr/lex_page.php index 0a26514..3657c66 100644 --- a/core/module/page/lang/fr/lex_page.php +++ b/core/module/page/lang/fr/lex_page.php @@ -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"; diff --git a/core/module/page/page.php b/core/module/page/page.php index 87081af..c0c91bb 100644 --- a/core/module/page/page.php +++ b/core/module/page/page.php @@ -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, '

'.$text['core_page']['add'][1].'

', 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, '

'.$text['core_page']['add'][1].'

', 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)) ? '

' : str_replace('

', '

 

', $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)) ? '

' : str_replace('

', '

 

', $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' - ]); } } } diff --git a/core/module/theme/theme.php b/core/module/theme/theme.php index 4d22a53..7900af5 100644 --- a/core/module/theme/theme.php +++ b/core/module/theme/theme.php @@ -65,247 +65,307 @@ class theme extends common { * Thème des écrans d'administration */ public function admin() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - $this->setData(['admin', [ - 'backgroundColor' => $this->getInput('adminBackgroundColor'), - 'colorTitle' => $this->getInput('adminColorTitle'), - 'colorText' => $this->getInput('adminColorText'), - 'colorButtonText' => $this->getInput('adminColorButtonText'), - 'backgroundColorButton' => $this->getInput('adminColorButton'), - 'backgroundColorButtonGrey' => $this->getInput('adminColorGrey'), - 'backgroundColorButtonRed' => $this->getInput('adminColorRed'), - 'backgroundColorButtonGreen'=> $this->getInput('adminColorGreen'), - 'backgroundColorButtonHelp'=> $this->getInput('adminColorHelp'), - 'fontText' => $this->getInput('adminFontText'), - 'fontSize' => $this->getInput('adminFontTextSize'), - 'fontTitle' => $this->getInput('adminFontTitle'), - 'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'), - 'borderBlockColor' => $this->getInput('adminBorderBlockColor'), - 'maj' => true - ]]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['admin'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['core_theme']['admin'][0], - 'redirect' => helper::baseUrl() . 'theme/admin', - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['admin', [ + 'backgroundColor' => $this->getInput('adminBackgroundColor'), + 'colorTitle' => $this->getInput('adminColorTitle'), + 'colorText' => $this->getInput('adminColorText'), + 'colorButtonText' => $this->getInput('adminColorButtonText'), + 'backgroundColorButton' => $this->getInput('adminColorButton'), + 'backgroundColorButtonGrey' => $this->getInput('adminColorGrey'), + 'backgroundColorButtonRed' => $this->getInput('adminColorRed'), + 'backgroundColorButtonGreen'=> $this->getInput('adminColorGreen'), + 'backgroundColorButtonHelp'=> $this->getInput('adminColorHelp'), + 'fontText' => $this->getInput('adminFontText'), + 'fontSize' => $this->getInput('adminFontTextSize'), + 'fontTitle' => $this->getInput('adminFontTitle'), + 'backgroundBlockColor' => $this->getInput('adminBackGroundBlockColor'), + 'borderBlockColor' => $this->getInput('adminBorderBlockColor'), + 'maj' => true + ]]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['admin'][0], + 'redirect' => helper::baseUrl() . 'theme/admin', + 'state' => true + ]); + } + self::$fonts = $this->extract('./site/data/fonts.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['admin'][1], + 'view' => 'admin', + 'vendor' => [ + 'tinycolorpicker' + ], ]); } - self::$fonts = $this->extract('./site/data/fonts.json'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['admin'][1], - 'view' => 'admin', - 'vendor' => [ - 'tinycolorpicker' - ], - ]); } /** * Mode avancé */ public function advanced() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - // Enregistre le CSS - file_put_contents(self::DATA_DIR.'custom.css', $this->getInput('themeAdvancedCss', null)); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['advanced'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['core_theme']['advanced'][0], - 'redirect' => helper::baseUrl() . 'theme/advanced', - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + // Enregistre le CSS + file_put_contents(self::DATA_DIR.'custom.css', $this->getInput('themeAdvancedCss', null)); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['advanced'][0], + 'redirect' => helper::baseUrl() . 'theme/advanced', + 'state' => true + ]); + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['advanced'][1], + 'vendor' => [ + 'tinymce/plugins/codemirror/codemirror' + ], + 'view' => 'advanced' ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['advanced'][1], - 'vendor' => [ - 'tinymce/plugins/codemirror/codemirror' - ], - 'view' => 'advanced' - ]); } /** * Gestion des polices / affichage principal */ public function fonts() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Préparation du tableau d'affichage des polices - $fontsName = helper::arrayCollumn($this->getData(['fonts']), 'name'); - ksort($fontsName); - foreach($fontsName as $fontsId => $value) { - - self::$fonts[] = [ - ''.$fontsId.'', - ''.$this->getData(['fonts', $fontsId, 'name']).'', - ''.$this->getData(['fonts', $fontsId, 'file']).'', - 'TPQtpq741àéèôüç', - template::button('fontsEdit' . $fontsId, [ - 'href' => helper::baseUrl() . 'theme/editFonts/' . $fontsId, - 'value' => template::ico('pencil') - ]), - template::button('fontsDelete' . $fontsId, [ - 'class' => 'fontDelete buttonRed', - 'href' => helper::baseUrl() . 'theme/deleteFonts/' . $fontsId, - 'value' => template::ico('cancel') - ]) - ]; - + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['fonts'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Préparation du tableau d'affichage des polices + $fontsName = helper::arrayCollumn($this->getData(['fonts']), 'name'); + ksort($fontsName); + foreach($fontsName as $fontsId => $value) { + + self::$fonts[] = [ + ''.$fontsId.'', + ''.$this->getData(['fonts', $fontsId, 'name']).'', + ''.$this->getData(['fonts', $fontsId, 'file']).'', + 'TPQtpq741àéèôüç', + template::button('fontsEdit' . $fontsId, [ + 'href' => helper::baseUrl() . 'theme/editFonts/' . $fontsId, + 'value' => template::ico('pencil') + ]), + template::button('fontsDelete' . $fontsId, [ + 'class' => 'fontDelete buttonRed', + 'href' => helper::baseUrl() . 'theme/deleteFonts/' . $fontsId, + 'value' => template::ico('cancel') + ]) + ]; + + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['fonts'][0], + 'view' => 'fonts' + ]); } - - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['fonts'][0], - 'view' => 'fonts' - ]); } /** * Gestion des polices / édition */ public function editfonts() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Retour du formulaire - if($this->isPost()) { - if( $this->getInput('typeEditFont') === 'file' && $this->getInput('fileEditFont') === $text['core_theme']['editFonts'][0]){ - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['editFonts'][1], - 'redirect' => helper::baseUrl() . 'theme/fonts', - 'state' => false - ]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['editfonts'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Retour du formulaire + if($this->isPost()) { + if( $this->getInput('typeEditFont') === 'file' && $this->getInput('fileEditFont') === $text['core_theme']['editFonts'][0]){ + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['editFonts'][1], + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => false + ]); + } + else{ + $file = $this->getInput('typeEditFont') === 'none' ? '' : $this->getInput('fileEditFont'); + $key = strtolower(str_replace(' ','-',$this->getInput('nameEditFont'))); + $this->setData(['fonts', $key, [ + 'name' => $this->getInput('nameEditFont'), + 'type' => $this->getInput('typeEditFont'), + 'file' => $file, + 'link' => '', + 'license' => $this->getInput('licenseEditFont') + ]]); + // Force une maj de admin.css + $this-> setData(['admin', 'maj', true]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['editFonts'][2], + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => true + ]); + } } - else{ - $file = $this->getInput('typeEditFont') === 'none' ? '' : $this->getInput('fileEditFont'); - $key = strtolower(str_replace(' ','-',$this->getInput('nameEditFont'))); - $this->setData(['fonts', $key, [ - 'name' => $this->getInput('nameEditFont'), - 'type' => $this->getInput('typeEditFont'), - 'file' => $file, - 'link' => '', - 'license' => $this->getInput('licenseEditFont') - ]]); - // Force une maj de admin.css - $this-> setData(['admin', 'maj', true]); - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['editFonts'][2], - 'redirect' => helper::baseUrl() . 'theme/fonts', - 'state' => true - ]); + + // Fichiers site/file/fonts/ + if(is_dir(self::FILE_DIR.'source/fonts')) { + $dir=self::FILE_DIR.'source/fonts'; + $values = scandir($dir); + $values[0] = $text['core_theme']['editFonts'][0]; + unset($values[array_search('..', $values)]); + if (count($values) <= 1){ + self::$icsFiles = array(0 => $text['core_theme']['editFonts'][3].self::FILE_DIR.'source/fonts'); + } + else{ + //Modifier les clefs (qui sont les valeurs de retour du formulaire avec clef = valeur + self::$fontFiles = array_combine($values,$values); + } } + else { + self::$fontFiles = array(0 => $text['core_theme']['editFonts'][4].self::FILE_DIR.'source/fonts '.$text['core_theme']['editFonts'][5]); + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['editFonts'][6], + 'view' => 'editFonts' + ]); } - - // Fichiers site/file/fonts/ - if(is_dir(self::FILE_DIR.'source/fonts')) { - $dir=self::FILE_DIR.'source/fonts'; - $values = scandir($dir); - $values[0] = $text['core_theme']['editFonts'][0]; - unset($values[array_search('..', $values)]); - if (count($values) <= 1){ - self::$icsFiles = array(0 => $text['core_theme']['editFonts'][3].self::FILE_DIR.'source/fonts'); - } - else{ - //Modifier les clefs (qui sont les valeurs de retour du formulaire avec clef = valeur - self::$fontFiles = array_combine($values,$values); - } - } - else { - self::$fontFiles = array(0 => $text['core_theme']['editFonts'][4].self::FILE_DIR.'source/fonts '.$text['core_theme']['editFonts'][5]); - } - - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['editFonts'][6], - 'view' => 'editFonts' - ]); } /** * Gestion des polices / suppression */ public function deleteFonts() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - //Suppression de la police passée en paramètre - $this->deleteData(['fonts', $this->getUrl(2)]); - // Force une maj de admin.css - $this-> setData(['admin', 'maj', true]); - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['deleteFonts'][0], - 'redirect' => helper::baseUrl() . 'theme/fonts', - 'state' => true + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['deleteFonts'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + //Suppression de la police passée en paramètre + $this->deleteData(['fonts', $this->getUrl(2)]); + // Force une maj de admin.css + $this-> setData(['admin', 'maj', true]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['deleteFonts'][0], + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => true ]); + } } /** * Gestion des polices / ajout */ public function addFonts() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Retour du formulaire - if($this->isPost()) { - if( $this->getInput('typeAddFont') === 'file' && $this->getInput('fileAddFont') === $text['core_theme']['addFonts'][0]){ - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['addFonts'][1], - 'redirect' => helper::baseUrl() . 'theme/addFonts', - 'state' => false - ]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['addFonts'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Retour du formulaire + if($this->isPost()) { + if( $this->getInput('typeAddFont') === 'file' && $this->getInput('fileAddFont') === $text['core_theme']['addFonts'][0]){ + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['addFonts'][1], + 'redirect' => helper::baseUrl() . 'theme/addFonts', + 'state' => false + ]); + } + else{ + $file = $this->getInput('typeAddFont') === 'none' ? '' : $this->getInput('fileAddFont'); + $key = strtolower(str_replace(' ','-',$this->getInput('nameAddFont'))); + $this->setData(['fonts', $key, [ + 'name' => $this->getInput('nameAddFont'), + 'type' => $this->getInput('typeAddFont'), + 'file' => $file, + 'link' => '', + 'license' => $this->getInput('licenseAddFont') + ]]); + // Force une maj de admin.css + $this-> setData(['admin', 'maj', true]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['addFonts'][2], + 'redirect' => helper::baseUrl() . 'theme/fonts', + 'state' => true + ]); + } } - else{ - $file = $this->getInput('typeAddFont') === 'none' ? '' : $this->getInput('fileAddFont'); - $key = strtolower(str_replace(' ','-',$this->getInput('nameAddFont'))); - $this->setData(['fonts', $key, [ - 'name' => $this->getInput('nameAddFont'), - 'type' => $this->getInput('typeAddFont'), - 'file' => $file, - 'link' => '', - 'license' => $this->getInput('licenseAddFont') - ]]); - // Force une maj de admin.css - $this-> setData(['admin', 'maj', true]); - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['addFonts'][2], - 'redirect' => helper::baseUrl() . 'theme/fonts', - 'state' => true - ]); + // Fichiers site/file/fonts/ + if(is_dir(self::FILE_DIR.'source/fonts')) { + $dir=self::FILE_DIR.'source/fonts'; + $values = scandir($dir); + $values[0] = $text['core_theme']['addFonts'][0]; + unset($values[array_search('..', $values)]); + if (count($values) <= 1){ + self::$icsFiles = array(0 => $text['core_theme']['addFonts'][3].self::FILE_DIR.'source/fonts'); + } + else{ + //Modifier les clefs (qui sont les valeurs de retour du formulaire avec clef = valeur + self::$fontFiles = array_combine($values,$values); + } } - } - // Fichiers site/file/fonts/ - if(is_dir(self::FILE_DIR.'source/fonts')) { - $dir=self::FILE_DIR.'source/fonts'; - $values = scandir($dir); - $values[0] = $text['core_theme']['addFonts'][0]; - unset($values[array_search('..', $values)]); - if (count($values) <= 1){ - self::$icsFiles = array(0 => $text['core_theme']['addFonts'][3].self::FILE_DIR.'source/fonts'); + else { + self::$fontFiles = array(0 => $text['core_theme']['addFonts'][4].self::FILE_DIR.'source/fonts '.$text['core_theme']['addFonts'][5]); } - else{ - //Modifier les clefs (qui sont les valeurs de retour du formulaire avec clef = valeur - self::$fontFiles = array_combine($values,$values); - } - } - else { - self::$fontFiles = array(0 => $text['core_theme']['addFonts'][4].self::FILE_DIR.'source/fonts '.$text['core_theme']['addFonts'][5]); - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['addFonts'][6], - 'view' => 'addFonts' - ]); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['addFonts'][6], + 'view' => 'addFonts' + ]); + } } @@ -313,371 +373,431 @@ class theme extends common { * Options de l'arrière plan */ public function body() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - $this->setData([ 'theme', 'update', true]); - $this->setData(['theme', 'body', [ - 'backgroundColor' => $this->getInput('themeBodyBackgroundColor'), - 'image' => $this->getInput('themeBodyImage'), - 'imageAttachment' => $this->getInput('themeBodyImageAttachment'), - 'imagePosition' => $this->getInput('themeBodyImagePosition'), - 'imageRepeat' => $this->getInput('themeBodyImageRepeat'), - 'imageSize' => $this->getInput('themeBodyImageSize'), - 'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'), - 'toTopColor' => $this->getInput('themeBodyToTopColor') - ]]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['body'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['core_theme']['body'][0], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + $this->setData([ 'theme', 'update', true]); + $this->setData(['theme', 'body', [ + 'backgroundColor' => $this->getInput('themeBodyBackgroundColor'), + 'image' => $this->getInput('themeBodyImage'), + 'imageAttachment' => $this->getInput('themeBodyImageAttachment'), + 'imagePosition' => $this->getInput('themeBodyImagePosition'), + 'imageRepeat' => $this->getInput('themeBodyImageRepeat'), + 'imageSize' => $this->getInput('themeBodyImageSize'), + 'toTopbackgroundColor' => $this->getInput('themeBodyToTopBackground'), + 'toTopColor' => $this->getInput('themeBodyToTopColor') + ]]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['body'][0], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => true + ]); + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['body'][1], + 'vendor' => [ + 'tinycolorpicker' + ], + 'view' => 'body' ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['body'][1], - 'vendor' => [ - 'tinycolorpicker' - ], - 'view' => 'body' - ]); } /** * Options du pied de page */ public function footer() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - $this->setData([ 'theme', 'update', true]); - if ( $this->getInput('themeFooterCopyrightPosition') === 'hide' && - $this->getInput('themeFooterSocialsPosition') === 'hide' && - $this->getInput('themeFooterTextPosition') === 'hide' ) { - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['footer'][0], - 'redirect' => helper::baseUrl() . 'theme/footer', - 'state' => false - ]); - } else { - $this->setData(['theme', 'footer', [ - 'backgroundColor' => $this->getInput('themeFooterBackgroundColor'), - 'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'), - 'height' => $this->getInput('themeFooterHeight'), - 'loginLink' => $this->getInput('themeFooterLoginLink'), - 'margin' => $this->getInput('themeFooterMargin', helper::FILTER_BOOLEAN), - 'position' => $this->getInput('themeFooterPosition'), - 'fixed' => $this->getInput('themeFooterFixed', helper::FILTER_BOOLEAN), - 'socialsAlign' => $this->getInput('themeFooterSocialsAlign'), - 'text' => $this->getInput('themeFooterText', null), - 'textAlign' => $this->getInput('themeFooterTextAlign'), - 'textColor' => $this->getInput('themeFooterTextColor'), - 'copyrightPosition' => $this->getInput('themeFooterCopyrightPosition'), - 'textPosition' => $this->getInput('themeFooterTextPosition'), - 'socialsPosition' => $this->getInput('themeFooterSocialsPosition'), - 'textTransform' => $this->getInput('themeFooterTextTransform'), - 'font' => $this->getInput('themeFooterFont'), - 'fontSize' => $this->getInput('themeFooterFontSize'), - 'fontWeight' => $this->getInput('themeFooterFontWeight'), - 'displayVersion' => $this->getInput('themefooterDisplayVersion', helper::FILTER_BOOLEAN), - 'displaySiteMap' => $this->getInput('themefooterDisplaySiteMap', helper::FILTER_BOOLEAN), - 'displayCopyright' => $this->getInput('themefooterDisplayCopyright', helper::FILTER_BOOLEAN), - 'displayCookie' => $this->getInput('themefooterDisplayCookie', helper::FILTER_BOOLEAN), - 'displayLegal' => $this->getInput('themeFooterDisplayLegal', helper::FILTER_BOOLEAN), - 'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN), - 'displayMemberBar'=> $this->getInput('themeFooterDisplayMemberBar', helper::FILTER_BOOLEAN), - 'template' => $this->getInput('themeFooterTemplate'), - 'displayWhois' => $this->getInput('themeFooterDisplayWhois', helper::FILTER_BOOLEAN) - ]]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['footer'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + $this->setData([ 'theme', 'update', true]); + if ( $this->getInput('themeFooterCopyrightPosition') === 'hide' && + $this->getInput('themeFooterSocialsPosition') === 'hide' && + $this->getInput('themeFooterTextPosition') === 'hide' ) { + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['footer'][0], + 'redirect' => helper::baseUrl() . 'theme/footer', + 'state' => false + ]); + } else { + $this->setData(['theme', 'footer', [ + 'backgroundColor' => $this->getInput('themeFooterBackgroundColor'), + 'copyrightAlign' => $this->getInput('themeFooterCopyrightAlign'), + 'height' => $this->getInput('themeFooterHeight'), + 'loginLink' => $this->getInput('themeFooterLoginLink'), + 'margin' => $this->getInput('themeFooterMargin', helper::FILTER_BOOLEAN), + 'position' => $this->getInput('themeFooterPosition'), + 'fixed' => $this->getInput('themeFooterFixed', helper::FILTER_BOOLEAN), + 'socialsAlign' => $this->getInput('themeFooterSocialsAlign'), + 'text' => $this->getInput('themeFooterText', null), + 'textAlign' => $this->getInput('themeFooterTextAlign'), + 'textColor' => $this->getInput('themeFooterTextColor'), + 'copyrightPosition' => $this->getInput('themeFooterCopyrightPosition'), + 'textPosition' => $this->getInput('themeFooterTextPosition'), + 'socialsPosition' => $this->getInput('themeFooterSocialsPosition'), + 'textTransform' => $this->getInput('themeFooterTextTransform'), + 'font' => $this->getInput('themeFooterFont'), + 'fontSize' => $this->getInput('themeFooterFontSize'), + 'fontWeight' => $this->getInput('themeFooterFontWeight'), + 'displayVersion' => $this->getInput('themefooterDisplayVersion', helper::FILTER_BOOLEAN), + 'displaySiteMap' => $this->getInput('themefooterDisplaySiteMap', helper::FILTER_BOOLEAN), + 'displayCopyright' => $this->getInput('themefooterDisplayCopyright', helper::FILTER_BOOLEAN), + 'displayCookie' => $this->getInput('themefooterDisplayCookie', helper::FILTER_BOOLEAN), + 'displayLegal' => $this->getInput('themeFooterDisplayLegal', helper::FILTER_BOOLEAN), + 'displaySearch' => $this->getInput('themeFooterDisplaySearch', helper::FILTER_BOOLEAN), + 'displayMemberBar'=> $this->getInput('themeFooterDisplayMemberBar', helper::FILTER_BOOLEAN), + 'template' => $this->getInput('themeFooterTemplate'), + 'displayWhois' => $this->getInput('themeFooterDisplayWhois', helper::FILTER_BOOLEAN) + ]]); - // Sauvegarder la configuration localisée - $this->setData(['locale','legalPageId', $this->getInput('configLegalPageId')]); - $this->setData(['locale','searchPageId', $this->getInput('configSearchPageId')]); - - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['footer'][1], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => true - ]); + // Sauvegarder la configuration localisée + $this->setData(['locale','legalPageId', $this->getInput('configLegalPageId')]); + $this->setData(['locale','searchPageId', $this->getInput('configSearchPageId')]); + + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['footer'][1], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => true + ]); + } } - } - // Liste des pages - self::$pagesList = $this->getData(['page']); - foreach(self::$pagesList as $page => $pageId) { - if ($this->getData(['page',$page,'block']) === 'bar' || - $this->getData(['page',$page,'disable']) === true) { - unset(self::$pagesList[$page]); + // Liste des pages + self::$pagesList = $this->getData(['page']); + foreach(self::$pagesList as $page => $pageId) { + if ($this->getData(['page',$page,'block']) === 'bar' || + $this->getData(['page',$page,'disable']) === true) { + unset(self::$pagesList[$page]); + } } + self::$fonts = $this->extract('./site/data/fonts.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['footer'][2], + 'vendor' => [ + 'tinycolorpicker' + ], + 'view' => 'footer' + ]); } - self::$fonts = $this->extract('./site/data/fonts.json'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['footer'][2], - 'vendor' => [ - 'tinycolorpicker' - ], - 'view' => 'footer' - ]); } /** * Options de la bannière */ public function header() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Liste des dossiers dans site/file/source triés et non vides - $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; - self::$listDirs = helper::scanDir(self::FILE_DIR.'source', $filter); - sort(self::$listDirs); - // Soumission du formulaire - if($this->isPost()) { - $this->setData([ 'theme', 'update', true]); - // Modification des URL des images dans la bannière perso - $featureContent = $this->getInput('themeHeaderText', null); - // Bannière animée avec swiper - if( $this->getInput('themeHeaderFeature') === 'swiper' ){ - $swiperContent = $this->swiperContent('header'); - $headerHeight = 'unset'; - } else { - $headerHeight = $this->getInput('themeHeaderHeight'); - } - // $featureContent = str_replace(helper::baseUrl(false,false), './', $featureContent); - // Si une image est positionnée, l'arrière en transparent. - $this->setData(['theme', 'header', [ - 'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'), - 'font' => $this->getInput('themeHeaderFont'), - 'fontSize' => $this->getInput('themeHeaderFontSize'), - 'fontWeight' => $this->getInput('themeHeaderFontWeight'), - 'heightSelect' => $headerHeight, - 'wide' => $this->getInput('themeHeaderWide'), - 'image' => $this->getInput('themeHeaderImage'), - 'imagePosition' => $this->getInput('themeHeaderImagePosition'), - 'imageRepeat' => $this->getInput('themeHeaderImageRepeat'), - 'margin' => $this->getInput('themeHeaderMargin', helper::FILTER_BOOLEAN), - 'position' => $this->getInput('themeHeaderPosition'), - 'textAlign' => $this->getInput('themeHeaderTextAlign'), - 'textColor' => $this->getInput('themeHeaderTextColor'), - 'textHide' => $this->getInput('themeHeaderTextHide', helper::FILTER_BOOLEAN), - 'textTransform' => $this->getInput('themeHeaderTextTransform'), - 'linkHomePage' => $this->getInput('themeHeaderlinkHomePage',helper::FILTER_BOOLEAN), - 'imageContainer' => $this->getInput('themeHeaderImageContainer'), - 'tinyHidden' => $this->getInput('themeHeaderTinyHidden', helper::FILTER_BOOLEAN), - 'feature' => $this->getInput('themeHeaderFeature'), - 'featureContent' => $featureContent, - 'homePageOnly' => $this->getInput('themeHeaderHomePageOnly', helper::FILTER_BOOLEAN), - 'swiperImagesDir' => self::$listDirs[$this->getInput('themeHeaderDirectory')], - 'swiperContent' => $swiperContent, - 'swiperEffects' => $this->getInput('themeHeaderSwiperEffects'), - 'swiperDirection' => $this->getInput('themeHeaderSwiperDirection', helper::FILTER_BOOLEAN), - 'swiperTime' => $this->getInput('themeHeaderSwiperTime'), - 'swiperTransition' => $this->getInput('themeHeaderSwiperTransition') - ]]); - // Modification de la position du menu selon la position de la bannière - if ( $this->getData(['theme','header','position']) == 'site' ) - { - $this->setData(['theme', 'menu', 'position',str_replace ('body-','site-',$this->getData(['theme','menu','position']))]); - } - if ( $this->getData(['theme','header','position']) == 'body') - { - $this->setData(['theme', 'menu', 'position',str_replace ('site-','body-',$this->getData(['theme','menu','position']))]); - } - // Menu accroché à la bannière qui devient cachée - if ( $this->getData(['theme','header','position']) == 'hide' && - in_array( $this->getData(['theme','menu','position']) , ['body-first', 'site-first', 'body-first' , 'site-second']) - ) { - $this->setData(['theme', 'menu', 'position','site']); - } - // Suppression de l'image en contenu personnalisé - if( $this->getData(['theme','header','feature']) == 'feature'){ - $this->setData(['theme','header', 'image',""]); - } - // Application de la hauteur de l'image sélectionnée si hauteur de l'image sur hauteur du contenu - if( $this->getData(['theme', 'header', 'feature']) ==='wallpaper' && - $this->getData(['theme', 'header', 'image']) !== '' && - $this->getData(['theme', 'header', 'heightSelect']) === 'unset' ){ - $infoImage = getimagesize( self::FILE_DIR.'source/'. $this->getData(['theme', 'header', 'image']) ); - $this->setData(['theme', 'header', 'height', $infoImage[1]."px"]); - } else { - // Si pas d'image ou bannière personnalisée - $this->setData(['theme', 'header', 'height', $this->getData(['theme', 'header', 'heightSelect']) ]); - } + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['header'] ) { // Valeurs en sortie - if (isset($_POST['themeHeaderSubmit'])){ - $this->addOutput([ - 'notification' => $text['core_theme']['header'][0], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => true - ]); - } else { //Preview - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'theme/header' - ]); + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Liste des dossiers dans site/file/source triés et non vides + $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; + self::$listDirs = helper::scanDir(self::FILE_DIR.'source', $filter); + sort(self::$listDirs); + // Soumission du formulaire + if($this->isPost()) { + $this->setData([ 'theme', 'update', true]); + // Modification des URL des images dans la bannière perso + $featureContent = $this->getInput('themeHeaderText', null); + // Bannière animée avec swiper + if( $this->getInput('themeHeaderFeature') === 'swiper' ){ + $swiperContent = $this->swiperContent('header'); + $headerHeight = 'unset'; + } else { + $headerHeight = $this->getInput('themeHeaderHeight'); + } + // $featureContent = str_replace(helper::baseUrl(false,false), './', $featureContent); + // Si une image est positionnée, l'arrière en transparent. + $this->setData(['theme', 'header', [ + 'backgroundColor' => $this->getInput('themeHeaderBackgroundColor'), + 'font' => $this->getInput('themeHeaderFont'), + 'fontSize' => $this->getInput('themeHeaderFontSize'), + 'fontWeight' => $this->getInput('themeHeaderFontWeight'), + 'heightSelect' => $headerHeight, + 'wide' => $this->getInput('themeHeaderWide'), + 'image' => $this->getInput('themeHeaderImage'), + 'imagePosition' => $this->getInput('themeHeaderImagePosition'), + 'imageRepeat' => $this->getInput('themeHeaderImageRepeat'), + 'margin' => $this->getInput('themeHeaderMargin', helper::FILTER_BOOLEAN), + 'position' => $this->getInput('themeHeaderPosition'), + 'textAlign' => $this->getInput('themeHeaderTextAlign'), + 'textColor' => $this->getInput('themeHeaderTextColor'), + 'textHide' => $this->getInput('themeHeaderTextHide', helper::FILTER_BOOLEAN), + 'textTransform' => $this->getInput('themeHeaderTextTransform'), + 'linkHomePage' => $this->getInput('themeHeaderlinkHomePage',helper::FILTER_BOOLEAN), + 'imageContainer' => $this->getInput('themeHeaderImageContainer'), + 'tinyHidden' => $this->getInput('themeHeaderTinyHidden', helper::FILTER_BOOLEAN), + 'feature' => $this->getInput('themeHeaderFeature'), + 'featureContent' => $featureContent, + 'homePageOnly' => $this->getInput('themeHeaderHomePageOnly', helper::FILTER_BOOLEAN), + 'swiperImagesDir' => self::$listDirs[$this->getInput('themeHeaderDirectory')], + 'swiperContent' => $swiperContent, + 'swiperEffects' => $this->getInput('themeHeaderSwiperEffects'), + 'swiperDirection' => $this->getInput('themeHeaderSwiperDirection', helper::FILTER_BOOLEAN), + 'swiperTime' => $this->getInput('themeHeaderSwiperTime'), + 'swiperTransition' => $this->getInput('themeHeaderSwiperTransition') + ]]); + // Modification de la position du menu selon la position de la bannière + if ( $this->getData(['theme','header','position']) == 'site' ) + { + $this->setData(['theme', 'menu', 'position',str_replace ('body-','site-',$this->getData(['theme','menu','position']))]); + } + if ( $this->getData(['theme','header','position']) == 'body') + { + $this->setData(['theme', 'menu', 'position',str_replace ('site-','body-',$this->getData(['theme','menu','position']))]); + } + // Menu accroché à la bannière qui devient cachée + if ( $this->getData(['theme','header','position']) == 'hide' && + in_array( $this->getData(['theme','menu','position']) , ['body-first', 'site-first', 'body-first' , 'site-second']) + ) { + $this->setData(['theme', 'menu', 'position','site']); + } + // Suppression de l'image en contenu personnalisé + if( $this->getData(['theme','header','feature']) == 'feature'){ + $this->setData(['theme','header', 'image',""]); + } + // Application de la hauteur de l'image sélectionnée si hauteur de l'image sur hauteur du contenu + if( $this->getData(['theme', 'header', 'feature']) ==='wallpaper' && + $this->getData(['theme', 'header', 'image']) !== '' && + $this->getData(['theme', 'header', 'heightSelect']) === 'unset' ){ + $infoImage = getimagesize( self::FILE_DIR.'source/'. $this->getData(['theme', 'header', 'image']) ); + $this->setData(['theme', 'header', 'height', $infoImage[1]."px"]); + } else { + // Si pas d'image ou bannière personnalisée + $this->setData(['theme', 'header', 'height', $this->getData(['theme', 'header', 'heightSelect']) ]); + } + // Valeurs en sortie + if (isset($_POST['themeHeaderSubmit'])){ + $this->addOutput([ + 'notification' => $text['core_theme']['header'][0], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => true + ]); + } else { //Preview + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'theme/header' + ]); + } } + self::$fonts = $this->extract('./site/data/fonts.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['header'][1], + 'vendor' => [ + 'tinycolorpicker', + 'tinymce' + ], + 'view' => 'header' + ]); } - self::$fonts = $this->extract('./site/data/fonts.json'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['header'][1], - 'vendor' => [ - 'tinycolorpicker', - 'tinymce' - ], - 'view' => 'header' - ]); } /** * Accueil de la personnalisation */ public function index() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['index'][0], - 'view' => 'index' - ]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['index'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['index'][0], + 'view' => 'index' + ]); + } } /** * Options du menu */ public function menu() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - $this->setData([ 'theme', 'update', true]); - $this->setData(['theme', 'menu', [ - 'backgroundColor' => $this->getInput('themeMenuBackgroundColor'), - 'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'), - 'font' => $this->getInput('themeMenuFont'), - 'fontSize' => $this->getInput('themeMenuFontSize'), - 'fontWeight' => $this->getInput('themeMenuFontWeight'), - 'height' => $this->getInput('themeMenuHeight'), - 'wide' => $this->getInput('themeMenuWide'), - 'loginLink' => $this->getInput('themeMenuLoginLink', helper::FILTER_BOOLEAN), - 'margin' => $this->getInput('themeMenuMargin', helper::FILTER_BOOLEAN), - 'position' => $this->getInput('themeMenuPosition'), - 'textAlign' => $this->getInput('themeMenuTextAlign'), - 'textColor' => $this->getInput('themeMenuTextColor'), - 'textTransform' => $this->getInput('themeMenuTextTransform'), - 'fixed' => $this->getInput('themeMenuFixed', helper::FILTER_BOOLEAN), - 'activeColorAuto' => $this->getInput('themeMenuActiveColorAuto', helper::FILTER_BOOLEAN), - 'activeColor' => $this->getInput('themeMenuActiveColor'), - 'activeTextColor' => $this->getInput('themeMenuActiveTextColor'), - 'radius' => $this->getInput('themeMenuRadius'), - 'burgerTitle' => $this->getInput('themeMenuBurgerTitle', helper::FILTER_BOOLEAN), - 'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN), - 'burgerIcon1' => $this->getInput('themeMenuBurgerIcon1'), - 'burgerIcon2' => $this->getInput('themeMenuBurgerIcon2'), - 'burgerContent' => $this->getInput('themeMenuBurgerContent'), - 'burgerTextColor' => $this->getInput('themeMenuBurgerTextColor'), - 'burgerFontSize' => $this->getInput('themeMenuBurgerFontSize'), - 'minWidthTab' => $this->getInput('themeMenuMinWidthTab'), - 'minWidthParentOrAll' => $this->getInput('themeMenuMinWidthParentOrAll', helper::FILTER_BOOLEAN), - 'burgerFixed' => $this->getInput('themeMenuBurgerFixed', helper::FILTER_BOOLEAN), - 'burgerIconColor' => $this->getInput('themeMenuBurgerIconColor'), - 'burgerIconBgColor' => $this->getInput('themeMenuBurgerIconBgColor'), - 'burgerBannerColor' => $this->getInput('themeMenuBurgerBannerColor'), - 'burgerTextMenuColor' => $this->getInput('themeMenuBurgerTextMenuColor'), - 'burgerActiveTextColor' => $this->getInput('themeMenuBurgerActiveTextColor'), - 'burgerBackgroundColor' => $this->getInput('themeMenuBurgerBackgroundColor'), - 'burgerActiveColorAuto' => $this->getInput('themeMenuBurgerActiveColorAuto', helper::FILTER_BOOLEAN), - 'burgerActiveColor' => $this->getInput('themeMenuBurgerActiveColor'), - 'burgerBackgroundColorSub' => $this->getInput('themeMenuBurgerBackgroundColorSub'), - 'burgerIconLink1' => $this->getInput('themeMenuBurgerIconLink1'), - 'burgerIconLink2' => $this->getInput('themeMenuBurgerIconLink2'), - 'burgerOverlay' => $this->getInput('themeMenuBurgerOverlay', helper::FILTER_BOOLEAN) - ]]); - + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['menu'] ) { // Valeurs en sortie - if (isset($_POST['themeMenuSubmit'])){ - $this->addOutput([ - 'notification' => $text['core_theme']['menu'][0], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => true - ]); - } else { // Preview - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'theme/menu' - ]); + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + $this->setData([ 'theme', 'update', true]); + $this->setData(['theme', 'menu', [ + 'backgroundColor' => $this->getInput('themeMenuBackgroundColor'), + 'backgroundColorSub' => $this->getInput('themeMenuBackgroundColorSub'), + 'font' => $this->getInput('themeMenuFont'), + 'fontSize' => $this->getInput('themeMenuFontSize'), + 'fontWeight' => $this->getInput('themeMenuFontWeight'), + 'height' => $this->getInput('themeMenuHeight'), + 'wide' => $this->getInput('themeMenuWide'), + 'loginLink' => $this->getInput('themeMenuLoginLink', helper::FILTER_BOOLEAN), + 'margin' => $this->getInput('themeMenuMargin', helper::FILTER_BOOLEAN), + 'position' => $this->getInput('themeMenuPosition'), + 'textAlign' => $this->getInput('themeMenuTextAlign'), + 'textColor' => $this->getInput('themeMenuTextColor'), + 'textTransform' => $this->getInput('themeMenuTextTransform'), + 'fixed' => $this->getInput('themeMenuFixed', helper::FILTER_BOOLEAN), + 'activeColorAuto' => $this->getInput('themeMenuActiveColorAuto', helper::FILTER_BOOLEAN), + 'activeColor' => $this->getInput('themeMenuActiveColor'), + 'activeTextColor' => $this->getInput('themeMenuActiveTextColor'), + 'radius' => $this->getInput('themeMenuRadius'), + 'burgerTitle' => $this->getInput('themeMenuBurgerTitle', helper::FILTER_BOOLEAN), + 'memberBar' => $this->getInput('themeMenuMemberBar', helper::FILTER_BOOLEAN), + 'burgerIcon1' => $this->getInput('themeMenuBurgerIcon1'), + 'burgerIcon2' => $this->getInput('themeMenuBurgerIcon2'), + 'burgerContent' => $this->getInput('themeMenuBurgerContent'), + 'burgerTextColor' => $this->getInput('themeMenuBurgerTextColor'), + 'burgerFontSize' => $this->getInput('themeMenuBurgerFontSize'), + 'minWidthTab' => $this->getInput('themeMenuMinWidthTab'), + 'minWidthParentOrAll' => $this->getInput('themeMenuMinWidthParentOrAll', helper::FILTER_BOOLEAN), + 'burgerFixed' => $this->getInput('themeMenuBurgerFixed', helper::FILTER_BOOLEAN), + 'burgerIconColor' => $this->getInput('themeMenuBurgerIconColor'), + 'burgerIconBgColor' => $this->getInput('themeMenuBurgerIconBgColor'), + 'burgerBannerColor' => $this->getInput('themeMenuBurgerBannerColor'), + 'burgerTextMenuColor' => $this->getInput('themeMenuBurgerTextMenuColor'), + 'burgerActiveTextColor' => $this->getInput('themeMenuBurgerActiveTextColor'), + 'burgerBackgroundColor' => $this->getInput('themeMenuBurgerBackgroundColor'), + 'burgerActiveColorAuto' => $this->getInput('themeMenuBurgerActiveColorAuto', helper::FILTER_BOOLEAN), + 'burgerActiveColor' => $this->getInput('themeMenuBurgerActiveColor'), + 'burgerBackgroundColorSub' => $this->getInput('themeMenuBurgerBackgroundColorSub'), + 'burgerIconLink1' => $this->getInput('themeMenuBurgerIconLink1'), + 'burgerIconLink2' => $this->getInput('themeMenuBurgerIconLink2'), + 'burgerOverlay' => $this->getInput('themeMenuBurgerOverlay', helper::FILTER_BOOLEAN) + ]]); + + // Valeurs en sortie + if (isset($_POST['themeMenuSubmit'])){ + $this->addOutput([ + 'notification' => $text['core_theme']['menu'][0], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => true + ]); + } else { // Preview + $this->addOutput([ + 'redirect' => helper::baseUrl() . 'theme/menu' + ]); + } } + // Liste des pages pour les liens sur icônes + foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { + // Exclusions les barres, les pages masquées ou non publiques + if ($this->getData(['page',$parentKey,'group']) !== 0 || + $this->getData(['page', $parentKey, 'block']) === 'bar' ) { + continue; + } + self::$pageList [$parentKey] = $parentKey; + foreach ($parentValue as $childKey) { + self::$pageList [$childKey] = $childKey; + } + } + + + self::$fonts = $this->extract('./site/data/fonts.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['menu'][1], + 'vendor' => [ + 'tinycolorpicker' + ], + 'view' => 'menu' + ]); } - // Liste des pages pour les liens sur icônes - foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { - // Exclusions les barres, les pages masquées ou non publiques - if ($this->getData(['page',$parentKey,'group']) !== 0 || - $this->getData(['page', $parentKey, 'block']) === 'bar' ) { - continue; - } - self::$pageList [$parentKey] = $parentKey; - foreach ($parentValue as $childKey) { - self::$pageList [$childKey] = $childKey; - } - } - - - self::$fonts = $this->extract('./site/data/fonts.json'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['menu'][1], - 'vendor' => [ - 'tinycolorpicker' - ], - 'view' => 'menu' - ]); } /** * Réinitialisation de la personnalisation avancée */ public function reset() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // $url prend l'adresse sans le token - $url = explode('&',$this->getUrl(2)); - - if ( isset($_GET['csrf']) - AND $_GET['csrf'] === $_SESSION['csrf'] - ) { - // Réinitialisation - $redirect =''; - switch ($url[0]) { - case 'admin': - $this->initData('admin'); - $redirect = helper::baseUrl() . 'theme/admin'; - break; - case 'manage': - $this->initData('theme'); - $redirect = helper::baseUrl() . 'theme/manage'; - break; - case 'custom': - unlink(self::DATA_DIR.'custom.css'); - $redirect = helper::baseUrl() . 'theme/advanced'; - break; - default : - $redirect = helper::baseUrl() . 'theme'; - } - + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['reset'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['core_theme']['reset'][0], - 'redirect' => $redirect, - 'state' => true - ]); + 'access' => false + ]); } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['reset'][1] - ]); + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // $url prend l'adresse sans le token + $url = explode('&',$this->getUrl(2)); + + if ( isset($_GET['csrf']) + AND $_GET['csrf'] === $_SESSION['csrf'] + ) { + // Réinitialisation + $redirect =''; + switch ($url[0]) { + case 'admin': + $this->initData('admin'); + $redirect = helper::baseUrl() . 'theme/admin'; + break; + case 'manage': + $this->initData('theme'); + $redirect = helper::baseUrl() . 'theme/manage'; + break; + case 'custom': + unlink(self::DATA_DIR.'custom.css'); + $redirect = helper::baseUrl() . 'theme/advanced'; + break; + default : + $redirect = helper::baseUrl() . 'theme'; + } + + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['reset'][0], + 'redirect' => $redirect, + 'state' => true + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['reset'][1] + ]); + } } } @@ -686,103 +806,123 @@ class theme extends common { * Options du site */ public function site() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Soumission du formulaire - if($this->isPost()) { - $this->setData([ 'theme', 'update', true]); - $this->setData(['theme', 'title', [ - 'font' => $this->getInput('themeTitleFont'), - 'textColor' => $this->getInput('themeTitleTextColor'), - 'fontWeight' => $this->getInput('themeTitleFontWeight'), - 'textTransform' => $this->getInput('themeTitleTextTransform') - ]]); - $this->setData(['theme', 'text', [ - 'font' => $this->getInput('themeTextFont'), - 'fontSize' => $this->getInput('themeTextFontSize'), - 'textColor' => $this->getInput('themeTextTextColor'), - 'linkColor'=> $this->getInput('themeTextLinkColor') - ]]); - $this->setData(['theme', 'site', [ - 'backgroundColor' => $this->getInput('themeSiteBackgroundColor'), - 'radius' => $this->getInput('themeSiteRadius'), - 'shadow' => $this->getInput('themeSiteShadow'), - 'width' => $this->getInput('themeSiteWidth'), - 'margin' => $this->getInput('themeSiteMargin',helper::FILTER_BOOLEAN) - ]]); - $this->setData(['theme', 'button', [ - 'backgroundColor' => $this->getInput('themeButtonBackgroundColor') - ]]); - $this->setData(['theme', 'block', [ - 'backgroundColor' => $this->getInput('themeBlockBackgroundColor'), - 'borderColor' => $this->getInput('themeBlockBorderColor'), - 'backgroundTitleColor' => $this->getInput('themeBlockBackgroundTitleColor'), - 'blockBorderRadius' => $this->getInput('themeBlockBorderRadius'), - 'blockBorderShadow' => $this->getInput('themeBlockBorderShadow') - ]]); - // Si barrière animée nouveau swiperContent - if($this->getData(['theme', 'header', 'feature']) === 'swiper' ) $this->swiperContent('site'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['site'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['core_theme']['site'][0], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Soumission du formulaire + if($this->isPost()) { + $this->setData([ 'theme', 'update', true]); + $this->setData(['theme', 'title', [ + 'font' => $this->getInput('themeTitleFont'), + 'textColor' => $this->getInput('themeTitleTextColor'), + 'fontWeight' => $this->getInput('themeTitleFontWeight'), + 'textTransform' => $this->getInput('themeTitleTextTransform') + ]]); + $this->setData(['theme', 'text', [ + 'font' => $this->getInput('themeTextFont'), + 'fontSize' => $this->getInput('themeTextFontSize'), + 'textColor' => $this->getInput('themeTextTextColor'), + 'linkColor'=> $this->getInput('themeTextLinkColor') + ]]); + $this->setData(['theme', 'site', [ + 'backgroundColor' => $this->getInput('themeSiteBackgroundColor'), + 'radius' => $this->getInput('themeSiteRadius'), + 'shadow' => $this->getInput('themeSiteShadow'), + 'width' => $this->getInput('themeSiteWidth'), + 'margin' => $this->getInput('themeSiteMargin',helper::FILTER_BOOLEAN) + ]]); + $this->setData(['theme', 'button', [ + 'backgroundColor' => $this->getInput('themeButtonBackgroundColor') + ]]); + $this->setData(['theme', 'block', [ + 'backgroundColor' => $this->getInput('themeBlockBackgroundColor'), + 'borderColor' => $this->getInput('themeBlockBorderColor'), + 'backgroundTitleColor' => $this->getInput('themeBlockBackgroundTitleColor'), + 'blockBorderRadius' => $this->getInput('themeBlockBorderRadius'), + 'blockBorderShadow' => $this->getInput('themeBlockBorderShadow') + ]]); + // Si barrière animée nouveau swiperContent + if($this->getData(['theme', 'header', 'feature']) === 'swiper' ) $this->swiperContent('site'); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['site'][0], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => true + ]); + } + self::$fonts = $this->extract('./site/data/fonts.json'); + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['site'][1], + 'vendor' => [ + 'tinycolorpicker' + ], + 'view' => 'site' ]); } - self::$fonts = $this->extract('./site/data/fonts.json'); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['site'][1], - 'vendor' => [ - 'tinycolorpicker' - ], - 'view' => 'site' - ]); } /** * Import du thème */ public function manage() { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['manage'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - if($this->isPost() ) { - if( isset( $_POST['themeSaveTheme'])){ - $this->save('theme',$this->getInput('themeSaveName')); - } elseif( isset( $_POST['themeSaveAdmin'])){ - $this->save('admin',$this->getInput('themeSaveName')); - } elseif( isset( $_POST['themeExportTheme'])){ - $this->export('theme',$this->getInput('themeExportName')); - } elseif( isset( $_POST['themeExportAdmin'])){ - $this->export('admin',$this->getInput('themeExportName')); - }else { - $zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true); - $data = $this->import(self::FILE_DIR.'source/' . $zipFilename); - if ($data['success']) { - // Refresh: 0 bien contenu dans la réponse envoyée au navigateur mais sans l'effet attendu - header("Refresh: 0"); - $this->addOutput([ - 'notification' => $data['notification'], - 'redirect' => helper::baseUrl() . 'theme', - 'state' => $data['success'] - ]); - } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => $data['notification'], - 'state' => $data['success'], - 'title' => $text['core_theme']['manage'][0], - 'view' => 'manage' - ]);; + if($this->isPost() ) { + if( isset( $_POST['themeSaveTheme'])){ + $this->save('theme',$this->getInput('themeSaveName')); + } elseif( isset( $_POST['themeSaveAdmin'])){ + $this->save('admin',$this->getInput('themeSaveName')); + } elseif( isset( $_POST['themeExportTheme'])){ + $this->export('theme',$this->getInput('themeExportName')); + } elseif( isset( $_POST['themeExportAdmin'])){ + $this->export('admin',$this->getInput('themeExportName')); + }else { + $zipFilename = $this->getInput('themeManageImport', helper::FILTER_STRING_SHORT, true); + $data = $this->import(self::FILE_DIR.'source/' . $zipFilename); + if ($data['success']) { + // Refresh: 0 bien contenu dans la réponse envoyée au navigateur mais sans l'effet attendu + header("Refresh: 0"); + $this->addOutput([ + 'notification' => $data['notification'], + 'redirect' => helper::baseUrl() . 'theme', + 'state' => $data['success'] + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'notification' => $data['notification'], + 'state' => $data['success'], + 'title' => $text['core_theme']['manage'][0], + 'view' => 'manage' + ]);; + } } } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['core_theme']['manage'][0], + 'view' => 'manage' + ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['core_theme']['manage'][0], - 'view' => 'manage' - ]); } /** @@ -792,70 +932,80 @@ class theme extends common { */ public function import($zipName = '') { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['import'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - if ($zipName !== '' && - file_exists($zipName)) { - // Init variables de retour - $success = false; - $notification = ''; - // Dossier temporaire - $tempFolder = uniqid(); - // Ouvrir le zip - $zip = new ZipArchive(); - if ($zip->open($zipName) === TRUE) { - mkdir (self::TEMP_DIR . $tempFolder, 0755); - $zip->extractTo(self::TEMP_DIR . $tempFolder ); - $modele = ''; - // Archive de thème ? - if ( - file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css') - AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css') - AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json') - ) { - $modele = 'theme'; - $this->sauve( $modele ); - } - if( - file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json') - AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css') - ) { - $modele = 'admin'; - $this->sauve( $modele ); - } - if (!empty($modele) - ) { - // traiter l'archive - $importFolder = './site/file/import'; - mkdir ($importFolder, 0755); - $success = $zip->extractTo($importFolder); - // $path = $importFolder.'/site/file/source/'; - // Modifie le nom de tous les fichiers de $path et leur nom dans theme.json - // $this->changeName($path); - $this->copyDir( $importFolder, './'); - $this->removeDir($importFolder); - // traitement de l'erreur - $notification = $success ? $text['core_theme']['import'][0] : $text['core_theme']['import'][1]; - - - } else { - // pas une archive de thème - $success = false; - $notification = $text['core_theme']['import'][2]; - } - // Supprimer le dossier temporaire même si le thème est invalide - $this->removeDir(self::TEMP_DIR . $tempFolder); - $zip->close(); - } else { - // erreur à l'ouverture + if ($zipName !== '' && + file_exists($zipName)) { + // Init variables de retour $success = false; - $notification = $text['core_theme']['import'][3]; - } - return (['success' => $success, 'notification' => $notification]); - } + $notification = ''; + // Dossier temporaire + $tempFolder = uniqid(); + // Ouvrir le zip + $zip = new ZipArchive(); + if ($zip->open($zipName) === TRUE) { + mkdir (self::TEMP_DIR . $tempFolder, 0755); + $zip->extractTo(self::TEMP_DIR . $tempFolder ); + $modele = ''; + // Archive de thème ? + if ( + file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css') + AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css') + AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json') + ) { + $modele = 'theme'; + $this->sauve( $modele ); + } + if( + file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json') + AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css') + ) { + $modele = 'admin'; + $this->sauve( $modele ); + } + if (!empty($modele) + ) { + // traiter l'archive + $importFolder = './site/file/import'; + mkdir ($importFolder, 0755); + $success = $zip->extractTo($importFolder); + // $path = $importFolder.'/site/file/source/'; + // Modifie le nom de tous les fichiers de $path et leur nom dans theme.json + // $this->changeName($path); + $this->copyDir( $importFolder, './'); + $this->removeDir($importFolder); + // traitement de l'erreur + $notification = $success ? $text['core_theme']['import'][0] : $text['core_theme']['import'][1]; - return (['success' => false, 'notification' => $text['core_theme']['import'][4]]); + + } else { + // pas une archive de thème + $success = false; + $notification = $text['core_theme']['import'][2]; + } + // Supprimer le dossier temporaire même si le thème est invalide + $this->removeDir(self::TEMP_DIR . $tempFolder); + $zip->close(); + } else { + // erreur à l'ouverture + $success = false; + $notification = $text['core_theme']['import'][3]; + } + return (['success' => $success, 'notification' => $notification]); + } + + return (['success' => false, 'notification' => $text['core_theme']['import'][4]]); + } } @@ -864,7 +1014,16 @@ class theme extends common { * Export du thème */ public function export($modele, $name) { - // Make zip + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['export'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Make zip $zipFilename = $this->zipTheme($modele, $name); // Téléchargement du ZIP header('Content-Description: File Transfer'); @@ -876,29 +1035,40 @@ class theme extends common { // Nettoyage du dossier unlink (self::TEMP_DIR . $zipFilename); exit(); + } } /** * Export du thème */ public function save($modele, $name) { - // Lexique - include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); - // Make zip - $zipFilename = $this->zipTheme($modele, $name); - // Téléchargement du ZIP - if (!is_dir(self::FILE_DIR.'source/theme')) { - mkdir(self::FILE_DIR.'source/theme', 0755); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < theme::$actions['save'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php'); + // Make zip + $zipFilename = $this->zipTheme($modele, $name); + // Téléchargement du ZIP + if (!is_dir(self::FILE_DIR.'source/theme')) { + mkdir(self::FILE_DIR.'source/theme', 0755); + } + copy (self::TEMP_DIR . $zipFilename , self::FILE_DIR.'source/theme/' . $zipFilename); + // Nettoyage du dossier + unlink (self::TEMP_DIR . $zipFilename); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['core_theme']['save'][0].''.$zipFilename.''. $text['core_theme']['save'][1], + 'redirect' => helper::baseUrl() . 'theme/manage', + 'state' => true + ]); } - copy (self::TEMP_DIR . $zipFilename , self::FILE_DIR.'source/theme/' . $zipFilename); - // Nettoyage du dossier - unlink (self::TEMP_DIR . $zipFilename); - // Valeurs en sortie - $this->addOutput([ - 'notification' => $text['core_theme']['save'][0].''.$zipFilename.''. $text['core_theme']['save'][1], - 'redirect' => helper::baseUrl() . 'theme/manage', - 'state' => true - ]); } /** diff --git a/core/module/translate/translate.php b/core/module/translate/translate.php index 4dbde5d..f39e555 100644 --- a/core/module/translate/translate.php +++ b/core/module/translate/translate.php @@ -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' - ]); } diff --git a/core/module/user/user.php b/core/module/user/user.php index 665a802..b93f041 100644 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -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].'' . $userFirstname . ' ' . $userLastname . ',

' . - $text['core_user']['add'][4] . $this->getData(['locale', 'title']) . $text['core_user']['add'][5].'

' . - ''.$text['core_user']['add'][6].' ' . $this->getInput('userAddId') . '
' . - ''.$text['core_user']['add'][7].'', - 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].'' . $userFirstname . ' ' . $userLastname . ',

' . + $text['core_user']['add'][4] . $this->getData(['locale', 'title']) . $text['core_user']['add'][5].'

' . + ''.$text['core_user']['add'][6].' ' . $this->getInput('userAddId') . '
' . + ''.$text['core_user']['add'][7].'', + 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].' ' . $item['prenom'] . ' ' . $item['nom'] . ',

' . - $text['core_user']['import'][2]. $this->getData(['locale', 'title']) . $text['core_user']['import'][3].'

' . - ''.$text['core_user']['import'][4].' ' . $userId . '
' . - ''.$text['core_user']['import'][5].'' - ); - 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].' ' . $item['prenom'] . ' ' . $item['nom'] . ',

' . + $text['core_user']['import'][2]. $this->getData(['locale', 'title']) . $text['core_user']['import'][3].'

' . + ''.$text['core_user']['import'][4].' ' . $userId . '
' . + ''.$text['core_user']['import'][5].'' + ); + 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 - ]); } }