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
|
|
|
|
* @license GNU General Public License, version 3
|
|
|
|
* @link http://zwiicms.fr/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class translate extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
/*'config' => self::GROUP_MODERATOR,*/
|
2020-12-06 17:45:37 +01:00
|
|
|
'index' => self::GROUP_ADMIN,
|
|
|
|
'advanced' => 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
|
|
|
|
2020-12-06 17:45:37 +01:00
|
|
|
public static $translateOptions = [];
|
|
|
|
|
|
|
|
// Liste des langues installées
|
|
|
|
public static $languagesInstalled = [];
|
|
|
|
// Liste des langues cibles
|
|
|
|
public static $languagesTarget = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration avancée des langues
|
|
|
|
*/
|
|
|
|
public function advanced() {
|
|
|
|
|
|
|
|
// Soumission du formulaire
|
|
|
|
if ($this->isPost()) {
|
|
|
|
// Initialisation
|
|
|
|
$success = false;
|
|
|
|
$copyFrom = $this->getInput('translateFormAdvancedSource');
|
|
|
|
$toCreate = $this->getInput('translateFormAdvancedTarget');
|
|
|
|
// 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', 'translate', $toCreate, 'site' ]);
|
|
|
|
$notification = 'Données ' . self::$i18nList[$copyFrom] . ' copiées vers ' . self::$i18nList[$toCreate];
|
|
|
|
} else {
|
|
|
|
$notification = "Quelque chose n\'a pas foncitionné, vérifiez les permissions.";
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => $notification,
|
|
|
|
'title' => 'Gestion avancée',
|
|
|
|
'view' => 'index',
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Tableau des langues installées
|
|
|
|
foreach (self::$i18nList as $key => $value) {
|
|
|
|
if ($this->getData(['config','translate',$key]) === 'site') {
|
|
|
|
self::$languagesInstalled[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Tableau des langues cibles
|
|
|
|
self::$languagesTarget = array_diff (self::$i18nList,self::$languagesInstalled);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Gestion avancée',
|
|
|
|
'view' => 'advanced'
|
|
|
|
]);
|
|
|
|
}
|
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()) {
|
2020-11-26 16:21:40 +01:00
|
|
|
// Désactivation du script Google
|
|
|
|
if ($this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN) === false) {
|
|
|
|
setrawcookie('googtrans', '/fr/fr', time() + 3600, helper::baseUrl());
|
2020-11-26 16:38:34 +01:00
|
|
|
$_SESSION['googtrans'] = '/fr/fr';
|
2020-11-26 16:21:40 +01:00
|
|
|
}
|
2020-11-29 08:48:29 +01:00
|
|
|
$script = $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN);
|
2020-11-25 18:25:16 +01:00
|
|
|
// Edition des langues
|
2020-11-25 10:01:13 +01:00
|
|
|
foreach (self::$i18nList as $keyi18n => $value) {
|
|
|
|
if ($keyi18n === 'fr') {continue;}
|
2020-11-25 18:25:16 +01:00
|
|
|
// Effacement d'une langue installée
|
2020-11-26 09:52:22 +01:00
|
|
|
if ( is_dir( self::DATA_DIR . $keyi18n ) === true
|
2020-12-06 17:45:37 +01: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
|
2020-11-25 18:25:16 +01:00
|
|
|
if ( $this->getInput('translate' . strtoupper($keyi18n)) === 'site')
|
2020-11-25 10:01:13 +01:00
|
|
|
{
|
2020-11-26 09:52:22 +01:00
|
|
|
// Créer les données absentes
|
2020-11-25 10:01:13 +01:00
|
|
|
if (is_dir( self::DATA_DIR . $keyi18n ) === false ) {
|
|
|
|
mkdir( self::DATA_DIR . $keyi18n);
|
2020-11-26 09:52:22 +01:00
|
|
|
// Charger les modèles
|
|
|
|
require_once('core/module/install/ressource/defaultdata.php');
|
|
|
|
// Nouvelle instance page, module, locale
|
|
|
|
$files = ['page','module','locale'];
|
|
|
|
foreach ($files as $keyFile) {
|
|
|
|
echo $keyFile;
|
|
|
|
$e = new \Prowebcraft\JsonDb([
|
|
|
|
'name' => $keyFile . '.json',
|
|
|
|
'dir' => $this->dirData ($keyFile,$keyi18n)
|
|
|
|
]);;
|
|
|
|
$e->set($keyFile, init::$defaultData[$keyFile]);
|
|
|
|
$e->save();
|
|
|
|
}
|
2020-11-25 10:01:13 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-29 08:48:29 +01: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
|
|
|
}
|
|
|
|
// Enregistrement des données
|
2020-11-24 09:13:49 +01:00
|
|
|
$this->setData(['config','translate', [
|
2020-11-29 08:48:29 +01:00
|
|
|
'scriptGoogle' => $script,
|
2020-11-26 16:21:40 +01:00
|
|
|
'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,
|
2020-11-29 08:48:29 +01:00
|
|
|
'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-25 18:25:16 +01:00
|
|
|
|
2020-11-11 19:48:07 +01:00
|
|
|
]]);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
2020-12-06 17:45:37 +01:00
|
|
|
// Modification de option de suppression de la langue installée.
|
|
|
|
foreach (self::$i18nList as $key => $value) {
|
|
|
|
if ($this->getData(['config','translate',$key]) === 'site') {
|
|
|
|
self::$translateOptions [$key] = [
|
|
|
|
'none' => 'Drapeau masqué',
|
|
|
|
'script' => 'Traduction automatique',
|
|
|
|
'site' => 'Traduction rédigée',
|
|
|
|
'delete' => 'Supprimer la traduction'
|
|
|
|
];
|
|
|
|
} 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([
|
2020-11-29 08:48:29 +01:00
|
|
|
'title' => 'Gestion des langues',
|
2020-11-11 19:48:07 +01:00
|
|
|
'view' => 'index'
|
|
|
|
]);
|
2020-11-22 13:32:20 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 17:45:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Traitement du changement de langue
|
|
|
|
* Fonction utilisée par le noyau
|
|
|
|
*/
|
2020-11-22 13:32:20 +01:00
|
|
|
public function language() {
|
2020-11-24 11:12:33 +01:00
|
|
|
// Transmettre le choix au noyau
|
2020-11-25 18:25:16 +01:00
|
|
|
if ($this->getUrl(3) === 'script') {
|
|
|
|
setrawcookie("googtrans", '/fr/'. $this->getUrl(2), time() + 3600, helper::baseUrl());
|
2020-11-26 09:52:22 +01:00
|
|
|
helper::deleteCookie('ZWII_I18N_SITE');
|
2020-11-26 10:56:03 +01:00
|
|
|
} elseif ($this->getUrl(3) === 'site') {
|
2020-11-26 09:52:22 +01:00
|
|
|
setcookie('ZWII_I18N_SITE', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
|
2020-11-26 10:56:03 +01:00
|
|
|
setrawcookie("googtrans", '/fr/fr', time() + 3600, helper::baseUrl());
|
2020-11-25 18:25:16 +01:00
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
2020-11-24 11:12:33 +01:00
|
|
|
$this->addOutput([
|
2020-11-25 18:25:16 +01: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
|
|
|
}
|