2020-11-11 19:48:07 +01:00
< ? php
/**
* This file is part of Zwii .
* For full copyright and license information , please see the LICENSE
* file that was distributed with this source code .
*
* @ author Rémi Jean < remi . jean @ outlook . com >
* @ copyright Copyright ( C ) 2008 - 2018 , Rémi Jean
2021-02-17 13:49:58 +01:00
* @ author Frédéric Tempez < frederic . tempez @ outlook . com >
2021-12-18 10:25:33 +01:00
* @ copyright Copyright ( C ) 2018 - 2022 , Frédéric Tempez
2020-11-11 19:48:07 +01:00
* @ license GNU General Public License , version 3
* @ link http :// zwiicms . fr /
*/
2022-09-29 08:45:59 +02:00
class translate extends common
{
2020-11-11 19:48:07 +01:00
public static $actions = [
2021-06-04 13:57:44 +02:00
'index' => self :: GROUP_ADMIN ,
'copy' => self :: GROUP_ADMIN ,
2022-09-26 14:54:15 +02:00
'add' => self :: GROUP_ADMIN , // Ajouter une langue de contenu
2022-10-14 19:18:48 +02:00
'ui' => self :: GROUP_ADMIN , // Éditer une langue de l'UI
'locale' => self :: GROUP_ADMIN , // Éditer une langue de contenu
2022-09-26 14:54:15 +02:00
'delete' => self :: GROUP_ADMIN , // Effacer une langue de contenu
2022-09-29 19:08:32 +02:00
'content' => self :: GROUP_VISITOR ,
2020-11-11 19:48:07 +01:00
];
2020-11-26 08:59:04 +01:00
2022-09-27 11:25:05 +02:00
// Language contents
2021-06-04 13:57:44 +02:00
public static $translateOptions = [];
2022-09-24 17:27:15 +02:00
// Page pour la configuration dans la langue
2022-08-29 22:04:57 +02:00
public static $pagesList = [];
public static $orphansList = [];
2021-06-04 13:57:44 +02:00
// Liste des langues installées
2022-10-14 19:18:48 +02:00
public static $languagesUiInstalled = [];
2021-06-04 13:57:44 +02:00
public static $languagesInstalled = [];
// Liste des langues cibles
public static $languagesTarget = [];
// Activation du bouton de copie
2022-09-28 15:58:35 +02:00
public static $siteCopy = true ;
2022-09-27 11:25:05 +02:00
// Localisation en cours d'édition
public static $locales = [];
2021-06-04 13:57:44 +02:00
2022-09-24 17:27:15 +02:00
//UI
2022-09-21 09:53:50 +02:00
// Fichiers des langues de l'interface
public static $i18nFiles = [];
2022-09-19 11:40:39 +02:00
2021-06-04 13:57:44 +02:00
/**
* Configuration avancée des langues
*/
2022-09-29 08:45:59 +02:00
public function copy ()
{
2021-06-04 13:57:44 +02:00
// Soumission du formulaire
if ( $this -> isPost ()) {
// Initialisation
$success = false ;
$copyFrom = $this -> getInput ( 'translateFormCopySource' );
$toCreate = $this -> getInput ( 'translateFormCopyTarget' );
if ( $copyFrom !== $toCreate ) {
// Création du dossier
2022-09-29 08:45:59 +02:00
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 );
2021-06-04 13:57:44 +02:00
} else {
$success = true ;
}
2022-09-29 10:55:20 +02:00
// Copier les données par défaut
2022-09-29 08:45:59 +02:00
$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 ;
2021-06-04 13:57:44 +02:00
// Enregistrer la langue
if ( $success ) {
2022-09-29 08:45:59 +02:00
$this -> setData ([ 'config' , 'i18n' , $toCreate , 'site' ]);
2022-10-11 10:33:44 +02:00
$notification = sprintf ( helper :: translate ( 'Données %s copiées vers %s' ), self :: $languages [ $copyFrom ], self :: $languages [ $toCreate ]);
2021-06-04 13:57:44 +02:00
} else {
2022-10-11 10:33:44 +02:00
$notification = helper :: translate ( 'Erreur de copie, vérifiez les permissions' );
2021-06-04 13:57:44 +02:00
}
} else {
$success = false ;
2022-10-11 10:33:44 +02:00
$notification = helper :: translate ( 'Les langues sélectionnées sont identiques' );
2021-06-04 13:57:44 +02:00
}
// Valeurs en sortie
$this -> addOutput ([
'notification' => $notification ,
'title' => 'Utilitaire de copie' ,
'view' => 'index' ,
'state' => $success
]);
}
2022-09-29 10:55:20 +02:00
2021-06-04 13:57:44 +02:00
// Tableau des langues installées
2022-09-26 14:54:15 +02:00
foreach ( self :: $languages as $key => $value ) {
2022-09-29 10:55:20 +02:00
// tableau des langues installées
if ( is_dir ( self :: DATA_DIR . $key )) {
2022-09-29 19:08:32 +02:00
self :: $languagesTarget [ $key ] = self :: $languages [ $key ];
2021-06-04 13:57:44 +02:00
}
}
2022-09-29 10:55:20 +02:00
2021-06-04 13:57:44 +02:00
// Langues cibles fr en plus
2022-09-29 10:55:20 +02:00
self :: $languagesInstalled = self :: $languagesTarget ;
2021-06-04 13:57:44 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Copie de contenus localisés' ),
2021-06-04 13:57:44 +02:00
'view' => 'copy'
]);
}
2020-11-11 19:48:07 +01:00
/**
* Configuration
*/
2022-09-29 08:45:59 +02:00
public function index ()
{
2020-11-25 08:21:52 +01:00
2020-11-11 19:48:07 +01:00
// Soumission du formulaire
2022-10-14 19:18:48 +02:00
// Jeton incorrect ou URl avec le code langue incorrecte
if (
$this -> getUrl ( 3 ) === $_SESSION [ 'csrf' ]
|| array_key_exists ( $this -> getUrl ( 2 ), self :: $languages ) ) {
2021-06-18 19:50:41 +02:00
2022-09-26 14:54:15 +02:00
// Sauvegarder les langues de contenu
2022-10-14 19:18:48 +02:00
$this -> setData ([ 'config' , 'i18n' , 'interface' , $this -> getUrl ( 2 )]);
2022-09-26 14:54:15 +02:00
2022-10-14 19:18:48 +02:00
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Langues' ),
'view' => 'index' ,
'notification' => helper :: translate ( 'Modifications enregistrées' ),
'state' => true
]);
2022-09-26 14:54:15 +02:00
}
// Préparation du formulaire
// -------------------------
2022-09-26 16:30:40 +02:00
// Onglet des langues de contenu
2022-09-29 10:55:20 +02:00
foreach ( self :: $languages as $key => $value ) {
2022-09-26 14:54:15 +02:00
// tableau des langues installées
2022-09-29 10:55:20 +02:00
if ( is_dir ( self :: DATA_DIR . $key )) {
2022-09-29 08:45:59 +02:00
self :: $languagesInstalled [] = [
2022-09-30 11:43:14 +02:00
template :: flag ( $key , '20 %' ),
2022-09-29 10:55:20 +02:00
$value . ' (' . $key . ')' ,
2022-09-29 19:14:03 +02:00
self :: $i18nUI === $key ? 'Interface' : '' ,
2022-09-26 16:30:40 +02:00
'' ,
2022-09-29 10:55:20 +02:00
template :: button ( 'translateContentLanguageEdit' . $key , [
2022-10-14 19:18:48 +02:00
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/locale/' . $key . '/' . $_SESSION [ 'csrf' ],
'value' => template :: ico ( 'pencil' ),
2022-10-02 10:59:42 +02:00
'help' => 'Éditer'
2022-09-26 14:54:15 +02:00
]),
2022-09-29 10:55:20 +02:00
template :: button ( 'translateContentLanguageDelete' . $key , [
'class' => 'translateDelete buttonRed' . ( self :: $i18nUI === $key ? ' disabled' : '' ),
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/delete/' . $key . '/' . $_SESSION [ 'csrf' ],
2022-09-26 14:54:15 +02:00
'value' => template :: ico ( 'trash' ),
2022-09-30 11:43:14 +02:00
'help' => 'Supprimer'
2022-09-26 14:54:15 +02:00
])
];
}
2022-09-26 16:30:40 +02:00
}
2022-09-28 15:58:35 +02:00
// Activation du bouton de copie
self :: $siteCopy = count ( self :: $languagesInstalled ) > 1 ? false : true ;
2022-10-14 19:18:48 +02:00
// Onglet des langues de l'interface
2022-09-26 14:54:15 +02:00
if ( is_dir ( self :: I18N_DIR )) {
$dir = getcwd ();
chdir ( self :: I18N_DIR );
$files = glob ( '*.json' );
chdir ( $dir );
}
2022-10-14 19:18:48 +02:00
// Construit le tableau des langues de l'UI
foreach ( $files as $file ) {
// La langue est-elle référencée ?
if ( array_key_exists ( basename ( $file , '.json' ), self :: $languages )) {
//self::$i18nFiles[basename($file, '.json')] = self::$languages[basename($file, '.json')];
$selected = basename ( $file , '.json' );
self :: $languagesUiInstalled [ $file ] = [
self :: $languages [ $selected ],
template :: flag ( $selected , '20 %' ),
self :: $i18nUI === $selected ? 'Interface' : '' ,
'' ,
template :: button ( 'translateContentLanguageEdit' . $file , [
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/ui/' . $selected . '/' . $_SESSION [ 'csrf' ],
'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
]),
];
}
}
2022-09-26 14:54:15 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Langues' ),
2022-09-26 14:54:15 +02:00
'view' => 'index'
]);
}
2021-06-18 21:10:16 +02:00
2022-09-26 14:54:15 +02:00
/***
2022-09-27 16:42:10 +02:00
* Ajouter une langue de contenu
2022-09-26 14:54:15 +02:00
*/
2022-09-29 08:45:59 +02:00
public function add ()
{
2022-09-26 14:54:15 +02:00
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ( $this -> isPost ()) {
2022-08-29 22:04:57 +02:00
2022-09-28 14:15:06 +02:00
// Création du contenu
$lang = $this -> getInput ( 'translateAddContent' );
// Tableau avec les données vierges
require_once ( 'core/module/install/ressource/defaultdata.php' );
// Créer la structure
foreach ([ 'page' , 'module' , 'locale' ] as $key ) {
// Sus-dossier localisé
if ( ! file_exists ( self :: DATA_DIR . $lang )) {
2022-09-29 08:45:59 +02:00
mkdir ( self :: DATA_DIR . $lang , 0755 );
2022-09-28 14:15:06 +02:00
}
// Initialiser la classe
$db = new \Prowebcraft\JsonDb ([
'name' => $key . '.json' ,
'dir' => self :: DATA_DIR . $lang ,
'backup' => file_exists ( 'site/data/.backup' )
]);;
// Capturer et sauver
2022-09-29 08:45:59 +02:00
$db -> set ( $key , init :: $defaultData [ $key ]);
2022-09-28 14:15:06 +02:00
$db -> save ;
}
2022-08-29 22:04:57 +02:00
2020-11-11 19:48:07 +01:00
// Valeurs en sortie
$this -> addOutput ([
2022-09-28 15:13:42 +02:00
'redirect' => helper :: baseUrl () . 'translate' ,
2022-10-11 10:33:44 +02:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2020-11-11 19:48:07 +01:00
'state' => true
]);
}
2022-09-24 17:27:15 +02:00
2022-09-26 14:54:15 +02:00
2022-09-12 22:14:51 +02:00
// Préparation de l'affichage du formulaire
2022-09-24 18:06:32 +02:00
//-----------------------------------------
2022-09-26 14:54:15 +02:00
2022-09-28 14:15:06 +02:00
// Tableau des langues non installées
foreach ( self :: $languages as $key => $value ) {
2022-09-29 08:45:59 +02:00
if ( ! is_dir ( self :: DATA_DIR . $key ))
self :: $i18nFiles [ $key ] = $value ;
2021-06-04 13:57:44 +02:00
}
2022-09-26 14:54:15 +02:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Nouveau contenu localisé' ),
2022-09-26 14:54:15 +02:00
'view' => 'add'
]);
}
2022-10-14 19:18:48 +02:00
/**
* Edition des paramètres de la langue de contenu
*/
public function locale ()
2022-09-29 08:45:59 +02:00
{
2022-09-27 16:42:10 +02:00
// Jeton incorrect ou URl avec le code langue incorrecte
2022-09-29 08:45:59 +02:00
if (
$this -> getUrl ( 3 ) !== $_SESSION [ 'csrf' ]
2022-09-27 16:42:10 +02:00
|| ! array_key_exists ( $this -> getUrl ( 2 ), self :: $languages )
) {
2022-09-27 11:25:05 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'translate' ,
'state' => false ,
2022-10-11 10:33:44 +02:00
'notification' => helper :: translate ( 'Action interdite' )
2022-09-27 11:25:05 +02:00
]);
}
2022-09-26 14:54:15 +02:00
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ( $this -> isPost ()) {
2022-09-26 14:54:15 +02:00
2022-09-28 10:18:58 +02:00
// Sauvegarder les locales
2022-09-29 08:45:59 +02:00
$data = [
'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 ),
'metaDescription' => $this -> getInput ( 'localeMetaDescription' , helper :: FILTER_STRING_LONG , true ),
'title' => $this -> getInput ( 'localeTitle' , helper :: FILTER_STRING_SHORT , true ),
'cookies' => [
// Les champs sont obligatoires si l'option consentement des cookies est active
'mainLabel' => $this -> getInput ( 'localeCookiesZwiiText' , helper :: FILTER_STRING_LONG , $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN )),
'titleLabel' => $this -> getInput ( 'localeCookiesTitleText' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN )),
'linkLegalLabel' => $this -> getInput ( 'localeCookiesLinkMlText' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN )),
'cookiesFooterText' => $this -> getInput ( 'localeCookiesFooterText' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN )),
'buttonValidLabel' => $this -> getInput ( 'localeCookiesButtonText' , helper :: FILTER_STRING_SHORT , $this -> getInput ( 'configCookieConsent' , helper :: FILTER_BOOLEAN ))
]
2022-09-28 10:18:58 +02:00
]
];
2022-09-28 14:15:06 +02:00
2022-09-28 10:18:58 +02:00
// Sauvegarde hors méthodes si la langue n'est pas celle de l'UI
2022-09-29 08:45:59 +02:00
if ( $this -> getUrl ( 2 ) === self :: $i18nUI ) {
2022-09-27 16:42:10 +02:00
// Enregistrer les données par lecture directe du formulaire
2022-09-29 08:45:59 +02:00
$this -> setData ([ 'locale' , $data [ 'locale' ]]);
2022-09-27 16:42:10 +02:00
} else {
// Sauver sur le disque
2022-09-29 08:45:59 +02:00
file_put_contents ( self :: DATA_DIR . $this -> getUrl ( 2 ) . '/locale.json' , json_encode ( $data , JSON_UNESCAPED_UNICODE ), LOCK_EX );
2022-09-27 16:42:10 +02:00
}
2022-09-26 14:54:15 +02:00
2022-10-07 18:47:30 +02:00
// Sauvegarde la langue de l'UI
$this -> setData ([ 'config' , 'i18n' , 'interface' , $this -> getInput ( 'translateUI' , null )]);
2022-09-26 14:54:15 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl (),
2022-10-11 10:33:44 +02:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2022-09-26 14:54:15 +02:00
'state' => true
]);
}
// Préparation de l'affichage du formulaire
//-----------------------------------------
2022-09-27 11:25:05 +02:00
// Récupération des locales de la langue sélectionnée
// Vérifier la conformité de l'URL
2022-09-29 08:45:59 +02:00
if ( ! array_key_exists ( $this -> getUrl ( 2 ), self :: $languages )) {
2022-09-27 11:25:05 +02:00
// Bidouillage de l'URL, on sort
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'translate' ,
2022-10-11 10:33:44 +02:00
'notification' => helper :: translate ( 'Erreur d\'URL' ),
2022-09-27 11:25:05 +02:00
'state' => false
]);
}
2022-09-27 16:42:10 +02:00
//Lecture des données pour transmission au formulaire
// La locale est-elle celle de la langue de l'UI ?
2022-09-29 08:45:59 +02:00
if ( $this -> getUrl ( 2 ) === self :: $i18nUI ) {
self :: $locales [ $this -> getUrl ( 2 )][ 'locale' ] = $this -> getData ([ 'locale' ]);
2022-09-27 16:42:10 +02:00
} else {
// Lire les locales sans passer par les méthodes
2022-09-29 08:45:59 +02:00
self :: $locales [ $this -> getUrl ( 2 )] = json_decode ( file_get_contents ( self :: DATA_DIR . $this -> getUrl ( 2 ) . '/locale.json' ), true );
2022-09-27 16:42:10 +02:00
}
2022-09-27 11:25:05 +02:00
2022-09-21 15:09:13 +02:00
// Générer la liste des pages disponibles
2022-08-29 22:04:57 +02:00
self :: $pagesList = $this -> getData ([ 'page' ]);
2022-09-29 08:45:59 +02:00
foreach ( self :: $pagesList as $page => $pageId ) {
if (
$this -> getData ([ 'page' , $page , 'block' ]) === 'bar' ||
$this -> getData ([ 'page' , $page , 'disable' ]) === true
) {
2022-08-29 22:04:57 +02:00
unset ( self :: $pagesList [ $page ]);
}
}
self :: $orphansList = $this -> getData ([ 'page' ]);
2022-09-29 08:45:59 +02:00
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
) {
2022-08-29 22:04:57 +02:00
unset ( self :: $orphansList [ $page ]);
}
}
2022-09-26 14:54:15 +02:00
2020-11-11 19:48:07 +01:00
// Valeurs en sortie
$this -> addOutput ([
2022-10-02 10:59:42 +02:00
'title' => helper :: translate ( 'Paramètres de la localisation' ) . ' ' . template :: flag ( $this -> getUrl ( 2 ), '20 %' ),
2022-10-14 19:18:48 +02:00
'view' => 'locale'
]);
}
/**
* Edition de la langue de l ' interface
*/
public function ui ()
{
// Jeton incorrect ou URl avec le code langue incorrecte
if (
$this -> getUrl ( 3 ) !== $_SESSION [ 'csrf' ]
|| ! array_key_exists ( $this -> getUrl ( 2 ), self :: $languages )
) {
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'translate' ,
'state' => false ,
'notification' => helper :: translate ( 'Action interdite' )
]);
}
// Soumission du formulaire
if ( $this -> isPost ()) {
$data = json_decode ( file_get_contents ( self :: I18N_DIR . $this -> getUrl ( 2 ) . '.json' ), true );
foreach ( $data as $key => $value ) {
$data [ $key ] = $this -> getInput ( 'translateString' . array_search ( $key , array_keys ( $data ), helper :: FILTER_STRING_SHORT ));
}
file_put_contents ( self :: I18N_DIR . $this -> getUrl ( 2 ) . '.json' , json_encode ( $data , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ), LOCK_EX );
// Valeurs en sortie
$this -> addOutput ([
'notification' => helper :: translate ( 'Modifications enregistrées' ),
'state' => true
]);
}
// Construction du formulaire
// Ajout des champs absents selon la langue de référence
$dataFr = json_decode ( file_get_contents ( self :: I18N_DIR . 'fr_FR.json' ), true );
foreach ( $dataFr as $key => $value ) {
if ( ! array_key_exists ( $key , $data )) {
$data [ $key ] = '' ;
}
}
file_put_contents ( self :: I18N_DIR . $this -> getUrl ( 2 ) . '.json' , json_encode ( $data , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ), LOCK_EX );
// Tableau des chaines à traduire dans la langue sélectionnée
if ( ! isset ( $data )) {
$data = json_decode ( file_get_contents ( self :: I18N_DIR . $this -> getUrl ( 2 ) . '.json' ), true );
}
foreach ( $data as $key => $value ) {
self :: $languagesUiInstalled [ $key ] = $value ;
}
// Valeurs en sortie
$this -> addOutput ([
'title' => helper :: translate ( 'Paramètres' ) . ' ' . template :: flag ( $this -> getUrl ( 2 ), '20 %' ),
'view' => 'ui'
2020-11-11 19:48:07 +01:00
]);
2020-11-22 13:32:20 +01:00
}
2022-09-26 14:54:15 +02:00
/***
2022-09-26 16:30:40 +02:00
* Effacer une langue de contenu
2022-09-26 14:54:15 +02:00
*/
2022-09-29 08:45:59 +02:00
public function delete ()
{
2022-09-27 16:42:10 +02:00
// Jeton incorrect ou URl avec le code langue incorrecte
2022-09-29 08:45:59 +02:00
if (
$this -> getUrl ( 3 ) !== $_SESSION [ 'csrf' ]
|| ! array_key_exists ( $this -> getUrl ( 2 ), self :: $languages )
) {
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'translate' ,
'state' => false ,
2022-10-11 10:33:44 +02:00
'notification' => helper :: translate ( 'Action interdite' )
2022-09-29 08:45:59 +02:00
]);
2022-09-27 16:42:10 +02:00
}
// Effacement d'une langue installée
2022-09-29 08:45:59 +02:00
if ( is_dir ( self :: DATA_DIR . $this -> getUrl ( 2 )) === true ) {
$success = $this -> removeDir ( self :: DATA_DIR . $this -> getUrl ( 2 ));
2022-09-26 14:54:15 +02:00
}
2022-09-27 16:42:10 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . 'translate' ,
2022-10-11 10:33:44 +02:00
'notification' => $success ? helper :: translate ( 'Traduction supprimée' ) : helper :: translate ( 'Erreur inconnue' ),
2022-09-27 16:42:10 +02:00
'state' => $success
]);
2022-09-26 14:54:15 +02:00
}
2021-06-04 13:57:44 +02:00
/*
* Traitement du changement de langue
* Fonction utilisée par le noyau
*/
2022-09-29 19:08:32 +02:00
public function content ()
2022-09-29 08:45:59 +02:00
{
2021-06-18 19:50:41 +02:00
// Activation du drapeau
2022-09-29 19:08:32 +02:00
$lang = $this -> getUrl ( 2 );
// Changement ?
if ( $this -> getInput ( 'ZWII_CONTENT' ) !== $lang ) {
// Nettoyer le cookie
helper :: deleteCookie ( 'ZWII_CONTENT' );
// Stocker le choix
setcookie ( 'ZWII_CONTENT' , $lang , time () + 3600 , helper :: baseUrl ( false , false ), '' , helper :: isHttps (), true );
2021-06-04 13:57:44 +02:00
}
2022-09-29 19:08:32 +02:00
2021-06-04 13:57:44 +02:00
// Valeurs en sortie
2020-11-24 11:12:33 +01:00
$this -> addOutput ([
2022-09-29 08:45:59 +02:00
'redirect' => helper :: baseUrl () . $this -> getData ([ 'locale' , $this -> getUrl ( 2 ), 'homePageId' ])
2020-11-24 11:12:33 +01:00
]);
2020-11-22 13:32:20 +01:00
}
2022-09-29 08:45:59 +02:00
}