From ee4d06413caf0e52705de1573bd42c9b4a61e041 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Thu, 20 Oct 2022 20:29:00 +0200 Subject: [PATCH] Choix de la langue de l'interface au niveau de l'ulisateur et pas de la config --- core/core.php | 19 ++--- core/include/update.inc.php | 3 +- core/module/config/config.php | 3 - core/module/install/install.php | 1 - core/module/install/ressource/defaultdata.php | 3 - core/module/install/view/index/index.php | 3 +- core/module/translate/translate.php | 30 +------- core/module/translate/view/index/index.php | 2 +- core/module/user/user.php | 47 ++++++++++-- core/module/user/view/add/add.php | 65 ++++++++++------ core/module/user/view/edit/edit.php | 74 ++++++++++++------- core/vendor/filemanager/config/config.php | 4 +- 12 files changed, 139 insertions(+), 115 deletions(-) diff --git a/core/core.php b/core/core.php index 74e720d0..ac754ecc 100644 --- a/core/core.php +++ b/core/core.php @@ -302,19 +302,15 @@ class common $this->input['_COOKIE'] = $_COOKIE; } - // Lire la langue de l'UI sans passer par les méthodes - $t = json_decode(file_get_contents('site/data/config.json'), true); - self::$i18nUI = $t['config']['i18n']['interface']; - // Déterminer la langue du contenu du site if (isset($this->input['_COOKIE']['ZWII_CONTENT'])) { // Déterminé par le cookie self::$i18nContent = $this->input['_COOKIE']['ZWII_CONTENT']; \setlocale(LC_TIME, self::$i18nContent . '.UTF8'); } else { - // Absence du cookie, la langue par défaut est celle de l'interface. - self::$i18nContent = (isset(self::$i18nUI)) ? self::$i18nUI : 'fr_FR'; - \setlocale(LC_TIME, self::$i18nUI . '.UTF8'); + // Absence du cookie, la langue par défaut est fr + self::$i18nContent = 'fr_FR'; + \setlocale(LC_TIME, self::$i18nContent . '.UTF8'); } // Instanciation de la classe des entrées / sorties @@ -342,11 +338,10 @@ class common } // Langue de l'administration - self::$i18nUI = $this->getData(['config', 'i18n', 'interface']); + self::$i18nUI = $this->getData(['user', $this->getUser('id'), 'language']); // La langue par défaut du contenu est celle du site si le cookie est absent. self::$i18nUI = (empty(self::$i18nUI) || is_null(self::$i18nUI)) ? self::$i18nUI = 'fr_FR' : self::$i18nUI; - // Le fichier existe-t-il ? if (!file_exists(self::I18N_DIR . self::$i18nUI . '.json')) { self::$i18nUI = 'fr_FR'; @@ -1590,7 +1585,7 @@ class common $this->getData(['user', $this->getUser('id'), 'files']) === true ) { $items .= '' . template::ico('folder', [ - 'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['config', 'i18n', 'interface']), + 'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['user', $this->getUser('id'), 'language']), 'margin' => 'all', 'attr' => 'data-lity', 'help' => 'Fichiers du site' @@ -1724,7 +1719,7 @@ class common $this->getData(['user', $this->getUser('id'), 'files']) === true ) { $itemsRight .= '
  • ' . template::ico('folder', [ - 'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['config', 'i18n', 'interface']), + 'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['user', $this->getUser('id'), 'language']), 'attr' => 'data-lity', 'help' => 'Fichiers du site' ]) . '
  • '; @@ -2170,7 +2165,7 @@ class common // Items de droite $rightItems = ''; if ($this->getUser('group') >= self::GROUP_MODERATOR) { - $rightItems .= '
  • ' . template::ico('folder') . '
  • '; + $rightItems .= '
  • ' . template::ico('folder') . '
  • '; } if ($this->getUser('group') >= self::GROUP_ADMIN) { $rightItems .= '
  • ' . template::ico('brush', [ diff --git a/core/include/update.inc.php b/core/include/update.inc.php index e1385870..0673831e 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -919,7 +919,8 @@ if ($this->getData(['core', 'dataVersion']) < 12000) { $this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR); } // Langue de l'interface - $this->setData(['config', 'i18n', 'interface', 'fr_FR']); + $this->deleteData(['config', 'i18n']); + $this->setData(['user', $this->getUser('id'), 'language', 'fr_FR']); // Mise à jour $this->setData(['core', 'dataVersion', 12000]); } diff --git a/core/module/config/config.php b/core/module/config/config.php index 3603d7fa..80b5cecd 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -495,9 +495,6 @@ class config extends common 'captchaType' => $this->getInput('connectCaptchaType'), 'showPassword' => $this->getInput('connectShowPassword', helper::FILTER_BOOLEAN), 'redirectLogin' => $this->getInput('connectRedirectLogin', helper::FILTER_BOOLEAN) - ], - 'i18n' => [ - 'interface' => $this->getData(['config', 'i18n', 'interface']) ] ] ]); diff --git a/core/module/install/install.php b/core/module/install/install.php index 0f67594e..e3a583b5 100644 --- a/core/module/install/install.php +++ b/core/module/install/install.php @@ -59,7 +59,6 @@ class install extends common self::$i18nUI = $this->getInput('installLanguage'); // Par défaut la langue du contenu est celle du site self::$i18nContent = self::$i18nUI; - $this->setData(['config', 'i18n', 'interface', self::$i18nUI]); // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . 'install/postinstall' diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index 2341716a..49c124a7 100644 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -40,9 +40,6 @@ class init extends common { 'autoDisconnect' => true, 'showPassword' => true, 'redirectLogin' => true - ], - 'i18n' => [ - 'interface' => 'fr_FR' ] ], 'core' => [ diff --git a/core/module/install/view/index/index.php b/core/module/install/view/index/index.php index 9a70f299..930aca8a 100644 --- a/core/module/install/view/index/index.php +++ b/core/module/install/view/index/index.php @@ -5,8 +5,7 @@
    'Langues installées', - 'selected' => $this->getData(['config', 'i18n', 'interface']) + 'label' => 'Langues installées' ]); ?>
    diff --git a/core/module/translate/translate.php b/core/module/translate/translate.php index 383b993a..e98d5a4b 100644 --- a/core/module/translate/translate.php +++ b/core/module/translate/translate.php @@ -80,7 +80,6 @@ class translate extends common $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']); $notification = sprintf(helper::translate('Données %s copiées vers %s'), self::$languages[$copyFrom], self::$languages[$toCreate]); } else { $notification = helper::translate('Erreur de copie, vérifiez les permissions'); @@ -122,23 +121,6 @@ class translate extends common public function index() { - // Soumission du formulaire - // Jeton incorrect ou URl avec le code langue incorrecte - if ( - $this->getUrl(3) === $_SESSION['csrf'] - || array_key_exists($this->getUrl(2), self::$languages) - ) { - - // Sauvegarder les langues de contenu - $this->setData(['config', 'i18n', 'interface', $this->getUrl(2)]); - - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . 'translate', - 'notification' => helper::translate('Modifications enregistrées'), - 'state' => true - ]); - } // Préparation du formulaire // ------------------------- @@ -193,14 +175,7 @@ class translate extends common 'value' => template::ico('pencil'), 'help' => 'Éditer', 'disabled' => 'fr_FR' === $selected - ]), - template::button('translateContentLanguageEnable' . $file, [ - 'href' => helper::baseUrl() . $this->getUrl(0) . '/index/' . $selected . '/' . $_SESSION['csrf'], - 'value' => template::ico('check'), - 'help' => 'Activer', - 'class' => 'buttonGreen', - 'disabled' => self::$i18nUI === $selected - ]), + ]) ]; } } @@ -329,9 +304,6 @@ class translate extends common file_put_contents(self::DATA_DIR . $this->getUrl(2) . '/locale.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX); } - // Sauvegarde la langue de l'UI - $this->setData(['config', 'i18n', 'interface', $this->getInput('translateUI', null)]); - // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(), diff --git a/core/module/translate/view/index/index.php b/core/module/translate/view/index/index.php index 1048b765..687d1049 100644 --- a/core/module/translate/view/index/index.php +++ b/core/module/translate/view/index/index.php @@ -49,7 +49,7 @@
    - +
    diff --git a/core/module/user/user.php b/core/module/user/user.php index 9b3094f0..7a9f85d9 100644 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -48,6 +48,8 @@ class user extends common ':' => ':' ]; + public static $languagesInstalled = []; + /** * Ajout */ @@ -90,7 +92,8 @@ class user extends common "accessUrl" => null, "accessTimer" => null, "accessCsrf" => null, - "files" => $this->getInput('userAddFiles', helper::FILTER_BOOLEAN) + "files" => $this->getInput('userAddFiles', helper::FILTER_BOOLEAN), + 'language' => $this->getInput('userEditLanguage', helper::FILTER_STRING_SHORT), ] ]); @@ -114,6 +117,19 @@ class user extends common 'state' => $sent === true ? true : null ]); } + // Langues disponibles pour l'interface de l'utilisateur + if (is_dir(self::I18N_DIR)) { + $dir = getcwd(); + chdir(self::I18N_DIR); + $files = glob('*.json'); + chdir($dir); + } + foreach ($files as $file) { + // La langue est-elle référencée ? + if (array_key_exists(basename($file, '.json'), self::$languages)) { + self::$languagesInstalled[basename($file, '.json')] = self::$languages[basename($file, '.json')]; + } + } // Valeurs en sortie $this->addOutput([ 'title' => helper::translate('Nouvel utilisateur'), @@ -172,9 +188,9 @@ class user extends common public function edit() { if ( - $this->getUrl(3) !== $_SESSION['csrf'] && - $this->getUrl(4) !== $_SESSION['csrf'] + $this->getUrl(3) !== $_SESSION['csrf'] ) { + // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . 'user', @@ -259,7 +275,8 @@ class user extends common '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) + 'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN), + 'language' => $this->getInput('userEditLanguage', helper::FILTER_STRING_SHORT), ] ]); // Redirection spécifique si l'utilisateur change son mot de passe @@ -281,6 +298,20 @@ class user extends common 'state' => true ]); } + + // Langues disponibles pour l'interface de l'utilisateur + if (is_dir(self::I18N_DIR)) { + $dir = getcwd(); + chdir(self::I18N_DIR); + $files = glob('*.json'); + chdir($dir); + } + foreach ($files as $file) { + // La langue est-elle référencée ? + if (array_key_exists(basename($file, '.json'), self::$languages)) { + self::$languagesInstalled[basename($file, '.json')] = self::$languages[basename($file, '.json')]; + } + } // Valeurs en sortie $this->addOutput([ 'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']), @@ -348,7 +379,7 @@ class user extends common $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']), self::$groups[$this->getData(['user', $userId, 'group'])], template::button('userEdit' . $userId, [ - 'href' => helper::baseUrl() . 'user/edit/' . $userId . '/back/' . $_SESSION['csrf'], + 'href' => helper::baseUrl() . 'user/edit/' . $userId . '/' . $_SESSION['csrf'], 'value' => template::ico('pencil'), 'help' => 'Éditer' ]), @@ -391,7 +422,7 @@ class user extends common * Aucun compte existant */ if (!$this->getData(['user', $userId])) { - $logStatus ='Compte inconnu'; + $logStatus = 'Compte inconnu'; //Stockage de l'IP $this->setData([ 'blacklist', @@ -484,7 +515,7 @@ class user extends common } // Cas 3 le délai de bloquage court if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) { - $notification = sprintf(helper::translate('Accès bloqué %d minutes', ($this->getData(['config', 'connect', 'timeout']) / 60) )); + $notification = sprintf(helper::translate('Accès bloqué %d minutes', ($this->getData(['config', 'connect', 'timeout']) / 60))); } // Valeurs en sortie @@ -526,7 +557,7 @@ class user extends common session_destroy(); // Valeurs en sortie $this->addOutput([ - 'notification' =>helper::translate('Déconnexion !'), + 'notification' => helper::translate('Déconnexion !'), 'redirect' => helper::baseUrl(false), 'state' => true ]); diff --git a/core/module/user/view/add/add.php b/core/module/user/view/add/add.php index 1bbe9248..1dce798e 100644 --- a/core/module/user/view/add/add.php +++ b/core/module/user/view/add/add.php @@ -42,30 +42,6 @@ 'autocomplete' => 'off', 'label' => 'Adresse mail' ]); ?> - 'Groupe', - 'selected' => self::GROUP_MEMBER - ]); ?> -
    - false, - 'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers' - ]); ?> -
    -
    - -
    - - -
    @@ -93,4 +69,45 @@
    +
    +
    +
    +

    +

    +
    +
    + 'Langues' + ]); ?> +
    +
    + 'Groupe', + 'selected' => self::GROUP_MEMBER + ]); ?> +
    + false, + 'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers' + ]); ?> +
    +
    + +
    +
      +
    • +
    +
      +
    • +
    • +
    • +
    +
      +
    • +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/core/module/user/view/edit/edit.php b/core/module/user/view/edit/edit.php index 802ea714..0f0aba30 100644 --- a/core/module/user/view/edit/edit.php +++ b/core/module/user/view/edit/edit.php @@ -56,34 +56,6 @@ 'label' => 'Adresse mail', 'value' => $this->getData(['user', $this->getUrl(2), 'mail']) ]); ?> - getUser('group') === self::GROUP_ADMIN) : ?> - ($this->getUrl(2) === $this->getUser('id')), - 'help' => ($this->getUrl(2) === $this->getUser('id') ? 'Impossible de modifier votre propre groupe.' : ''), - 'label' => 'Groupe', - 'selected' => $this->getData(['user', $this->getUrl(2), 'group']) - ]); ?> -
    - $this->getData(['user', $this->getUrl(2), 'files']), - 'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers' - ]); ?> -
    -
    - -
    - - - -
    @@ -112,4 +84,50 @@
    +
    +
    +
    +

    +

    +
    +
    + 'Langues', + 'selected' => $this->getData(['user', $this->getUrl(2), 'language']) + ]); ?> +
    +
    + getUser('group') === self::GROUP_ADMIN) : ?> + ($this->getUrl(2) === $this->getUser('id')), + 'help' => ($this->getUrl(2) === $this->getUser('id') ? 'Impossible de modifier votre propre groupe.' : ''), + 'label' => 'Groupe', + 'selected' => $this->getData(['user', $this->getUrl(2), 'group']) + ]); ?> +
    + $this->getData(['user', $this->getUrl(2), 'files']), + 'help' => 'Ce membre pourra téléverser ou télécharger des fichiers dans le dossier \'partage\' et ses sous-dossiers' + ]); ?> +
    +
    + +
    +
      +
    • +
    +
      +
    • +
    • +
    • +
    +
      +
    • +
    + +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/core/vendor/filemanager/config/config.php b/core/vendor/filemanager/config/config.php index 12530b5c..f0a80afe 100644 --- a/core/vendor/filemanager/config/config.php +++ b/core/vendor/filemanager/config/config.php @@ -13,9 +13,7 @@ ob_start('mb_output_handler'); date_default_timezone_set('Europe/Paris'); // Lire la langue installée -$tab = json_decode(file_get_contents('../../../site/data/config.json'), true); -$lang = $tab['config']['i18n']['interface']; -setlocale(LC_CTYPE, $lang); //correct transliteration +setlocale(LC_CTYPE, $_GET['lang']); //correct transliteration /* Lecture du groupe de l'utilisateur connecté pour attribuer les droits et les dossiers */ $userId = $_COOKIE['ZWII_USER_ID'];