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>
|
|
|
|
* @copyright Copyright (C) 2018-2021, Frédéric Tempez
|
2020-11-11 19:48:07 +01:00
|
|
|
* @license GNU General Public License, version 3
|
|
|
|
* @link http://zwiicms.fr/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class translate extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
/*'config' => self::GROUP_MODERATOR,*/
|
2021-06-04 13:57:44 +02:00
|
|
|
'index' => self::GROUP_ADMIN,
|
|
|
|
'copy' => self::GROUP_ADMIN,
|
2020-11-22 13:32:20 +01:00
|
|
|
'language' => self::GROUP_VISITOR
|
2020-11-11 19:48:07 +01:00
|
|
|
];
|
2020-11-26 08:59:04 +01:00
|
|
|
|
2021-06-04 13:57:44 +02:00
|
|
|
public static $translateOptions = [];
|
|
|
|
|
|
|
|
// Liste des langues installées
|
|
|
|
public static $languagesInstalled = [];
|
|
|
|
// Liste des langues cibles
|
|
|
|
public static $languagesTarget = [];
|
|
|
|
// Activation du bouton de copie
|
|
|
|
public static $siteTranslate = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration avancée des langues
|
|
|
|
*/
|
|
|
|
public function copy() {
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
} 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;
|
|
|
|
// Enregistrer la langue
|
|
|
|
if ($success) {
|
|
|
|
$this->setData(['config', 'i18n', $toCreate, 'site' ]);
|
|
|
|
$notification = 'Données ' . self::$i18nList[$copyFrom] . ' copiées vers ' . self::$i18nList[$toCreate];
|
|
|
|
} else {
|
|
|
|
$notification = "Quelque chose n\'a pas fonctionné, vérifiez les permissions.";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$success = false;
|
|
|
|
$notification = 'Les langues doivent être différentes.';
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => $notification,
|
|
|
|
'title' => 'Utilitaire de copie',
|
|
|
|
'view' => 'index',
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Tableau des langues installées
|
|
|
|
foreach (self::$i18nList as $key => $value) {
|
|
|
|
if ($this->getData(['config','i18n', $key]) === 'site') {
|
|
|
|
self::$languagesTarget[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Langues cibles fr en plus
|
|
|
|
self::$languagesInstalled = array_merge(['fr' => 'Français (fr)'],self::$languagesTarget);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Utilitaire de copie',
|
|
|
|
'view' => 'copy'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-11-11 19:48:07 +01:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function index() {
|
2020-11-25 08:21:52 +01:00
|
|
|
|
2020-11-11 19:48:07 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2021-06-04 13:57:44 +02:00
|
|
|
// Désactivation du script Google
|
2021-06-18 19:50:41 +02:00
|
|
|
$script = $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN);
|
|
|
|
if ($script === false) {
|
2021-06-04 13:57:44 +02:00
|
|
|
setrawcookie('googtrans', '/fr/fr', time() + 3600, helper::baseUrl(false,false));
|
|
|
|
$_SESSION['googtrans'] = '/fr/fr';
|
|
|
|
}
|
|
|
|
// Edition des langues
|
2020-11-25 10:01:13 +01:00
|
|
|
foreach (self::$i18nList as $keyi18n => $value) {
|
2021-06-18 21:10:16 +02:00
|
|
|
if ($keyi18n === 'fr') continue;
|
2021-06-04 13:57:44 +02:00
|
|
|
// Effacement d'une langue installée
|
2020-11-26 09:52:22 +01:00
|
|
|
if ( is_dir( self::DATA_DIR . $keyi18n ) === true
|
2021-06-04 13:57:44 +02:00
|
|
|
AND $this->getInput('translate' . strtoupper($keyi18n)) === 'delete')
|
2020-11-25 10:01:13 +01:00
|
|
|
{
|
|
|
|
$this->removeDir( self::DATA_DIR . $keyi18n);
|
|
|
|
}
|
|
|
|
// Installation d'une langue
|
2021-06-04 13:57:44 +02:00
|
|
|
if ( $this->getInput('translate' . strtoupper($keyi18n)) === 'site'
|
2021-06-18 19:50:41 +02:00
|
|
|
// Pas d'initialisation si la langue existe déjà
|
2021-06-04 13:57:44 +02:00
|
|
|
AND is_dir(self::DATA_DIR . $keyi18n) === false )
|
2020-11-25 10:01:13 +01:00
|
|
|
{
|
2021-06-18 19:50:41 +02:00
|
|
|
|
2021-06-18 21:10:16 +02:00
|
|
|
helper::deleteCookie('ZWII_I18N_SITE');
|
|
|
|
helper::deleteCookie('ZWII_I18N_SCRIPT');
|
|
|
|
setcookie('ZWII_I18N_SITE', $keyi18n, time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
|
2021-06-18 19:50:41 +02:00
|
|
|
|
2020-11-25 10:01:13 +01:00
|
|
|
}
|
2021-06-04 13:57:44 +02:00
|
|
|
// Active le script si une langue est en trad auto
|
|
|
|
if ($script === false
|
|
|
|
AND $this->getInput('translate'. strtoupper($keyi18n)) === 'script') {
|
|
|
|
$script = true;
|
|
|
|
}
|
2020-11-25 10:01:13 +01:00
|
|
|
}
|
2021-06-18 21:10:16 +02:00
|
|
|
|
2021-05-20 21:52:09 +02:00
|
|
|
// Enregistrement des données
|
2021-06-04 13:41:21 +02:00
|
|
|
$this->setData(['config','i18n', [
|
2021-06-14 16:55:17 +02:00
|
|
|
'active' => $this->getData(['config', 'i18n', 'active']),
|
2021-06-04 13:57:44 +02:00
|
|
|
'scriptGoogle' => $script,
|
|
|
|
'showCredits' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateCredits', helper::FILTER_BOOLEAN) : false,
|
|
|
|
'autoDetect' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN) : false,
|
|
|
|
'admin' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) ? $this->getInput('translateAdmin', helper::FILTER_BOOLEAN) : false,
|
|
|
|
'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')
|
|
|
|
|
2020-11-11 19:48:07 +01:00
|
|
|
]]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
2021-06-04 13:57:44 +02:00
|
|
|
// 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' => 'Drapeau masqué',
|
|
|
|
'script' => 'Traduction automatique',
|
|
|
|
'site' => 'Traduction rédigée',
|
|
|
|
'delete' => 'Supprimer la traduction'
|
|
|
|
];
|
|
|
|
self::$siteTranslate = $key !== 'fr' ? false : true;
|
|
|
|
} else {
|
|
|
|
self::$translateOptions [$key] = [
|
|
|
|
'none' => 'Drapeau masqué',
|
|
|
|
'script' => 'Traduction automatique',
|
|
|
|
'site' => 'Traduction rédigée'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 19:48:07 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2021-06-04 13:57:44 +02:00
|
|
|
'title' => 'Gestion des langues',
|
2020-11-11 19:48:07 +01:00
|
|
|
'view' => 'index'
|
|
|
|
]);
|
2020-11-22 13:32:20 +01:00
|
|
|
}
|
|
|
|
|
2021-06-04 13:57:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Traitement du changement de langue
|
|
|
|
* Fonction utilisée par le noyau
|
|
|
|
*/
|
2020-11-22 13:32:20 +01:00
|
|
|
public function language() {
|
2021-06-04 13:57:44 +02:00
|
|
|
|
2021-06-18 19:50:41 +02:00
|
|
|
// Activation du drapeau
|
2021-06-04 13:57:44 +02:00
|
|
|
if ( $this->getInput('ZWII_I18N_' . strtoupper($this->getUrl(3))) !== $this->getUrl(2) ) {
|
|
|
|
// Nettoyer et stocker le choix de l'utilisateur
|
|
|
|
helper::deleteCookie('ZWII_I18N_SITE');
|
|
|
|
helper::deleteCookie('ZWII_I18N_SCRIPT');
|
|
|
|
// Sélectionner
|
2021-06-18 19:50:41 +02:00
|
|
|
setcookie('ZWII_I18N_' . strtoupper($this->getUrl(3)) , $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
|
2021-06-04 13:57:44 +02:00
|
|
|
// Désactivation du drapeau, langue FR par défaut
|
|
|
|
} else {
|
|
|
|
setcookie('ZWII_I18N_SITE' , 'fr', time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
|
|
|
|
helper::deleteCookie('ZWII_I18N_SCRIPT');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
2020-11-24 11:12:33 +01:00
|
|
|
$this->addOutput([
|
2021-06-04 13:57:44 +02:00
|
|
|
'redirect' => helper::baseUrl()
|
2020-11-24 11:12:33 +01:00
|
|
|
]);
|
2020-11-22 13:32:20 +01:00
|
|
|
}
|
2020-11-11 19:48:07 +01:00
|
|
|
}
|