ZwiiCMS/core/module/translate/translate.php

110 lines
4.3 KiB
PHP
Raw Normal View History

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-05-20 21:52:09 +02:00
'index' => self::GROUP_MODERATOR,
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-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-05-20 21:52:09 +02:00
// Edtion des langues
foreach (self::$i18nList as $keyi18n => $value) {
if ($keyi18n === 'fr') {continue;}
2021-05-20 21:52:09 +02:00
// Effacement d'une langue installée (dossier plus option désactivée précédemment)
2020-11-26 09:52:22 +01:00
if ( is_dir( self::DATA_DIR . $keyi18n ) === true
2021-05-20 21:52:09 +02:00
AND $this->getInput('translateSiteFlag' . strtoupper($keyi18n) , helper::FILTER_BOOLEAN) === false )
{
$this->removeDir( self::DATA_DIR . $keyi18n);
}
// Installation d'une langue
2021-05-20 21:52:09 +02:00
if ( $this->getInput('translateSiteFlag' . strtoupper($keyi18n) , helper::FILTER_BOOLEAN) === true )
{
2021-05-20 21:52:09 +02:00
// Créer le dossier
if (is_dir( self::DATA_DIR . $keyi18n ) === false ) {
mkdir( self::DATA_DIR . $keyi18n);
}
// Charger les modèles
require_once('core/module/install/ressource/defaultdata.php');
// Nouvelle instance des pages, module, locale
$files = ['page','module','locale'];
foreach ($files as $keyFile) {
echo $keyFile;
$e = new \Prowebcraft\JsonDb([
'name' => $keyFile . '.json',
2020-12-10 14:04:30 +01:00
'dir' => $this->dataPath ($keyFile,$keyi18n)
]);;
$e->set($keyFile, init::$defaultData[$keyFile]);
$e->save();
}
}
}
2020-11-25 18:25:16 +01: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-05-20 21:52:09 +02:00
'scriptGoogle' => $this->getInput('translateScriptGoogle', helper::FILTER_BOOLEAN),
'showCredits' => $this->getInput('translateCredits', helper::FILTER_BOOLEAN) ? $this->getInput('translateCredits', helper::FILTER_BOOLEAN) : false,
'autoDetect' => $this->getInput('translateAutoDetect', helper::FILTER_BOOLEAN),
'admin' => $this->getInput('translateAdmin', helper::FILTER_BOOLEAN),
'scriptFR' => $this->getInput('translateScriptFlagFR', helper::FILTER_BOOLEAN),
'scriptDE' => $this->getInput('translateScriptFlagDE', helper::FILTER_BOOLEAN),
'scriptEN' => $this->getInput('translateScriptFlagEN', helper::FILTER_BOOLEAN),
'scriptES' => $this->getInput('translateScriptFlagES', helper::FILTER_BOOLEAN),
'scriptIT' => $this->getInput('translateScriptFlagIT', helper::FILTER_BOOLEAN),
'scriptNL' => $this->getInput('translateScriptFlagNL', helper::FILTER_BOOLEAN),
'scriptPT' => $this->getInput('translateScriptFlagPT', helper::FILTER_BOOLEAN),
'site' => $this->getInput('translateSite', helper::FILTER_BOOLEAN),
'siteFR' => $this->getInput('translateSiteFlagFR', helper::FILTER_BOOLEAN),
'siteDE' => $this->getInput('translateSiteFlagDE', helper::FILTER_BOOLEAN),
'siteEN' => $this->getInput('translateSiteFlagEN', helper::FILTER_BOOLEAN),
'siteES' => $this->getInput('translateSiteFlagES', helper::FILTER_BOOLEAN),
'siteIT' => $this->getInput('translateSiteFlagIT', helper::FILTER_BOOLEAN),
'siteNL' => $this->getInput('translateSiteFlagNL', helper::FILTER_BOOLEAN),
'sitePT' => $this->getInput('translateSiteFlagPT', helper::FILTER_BOOLEAN)
2020-11-11 19:48:07 +01:00
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),
'notification' => 'Modifications enregistrées',
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
2021-05-20 21:52:09 +02:00
'title' => 'Paramètres',
2020-11-11 19:48:07 +01:00
'view' => 'index'
]);
2020-11-22 13:32:20 +01:00
}
2021-05-20 21:52:09 +02:00
/*
* Traitement du changement de langues
*/
2020-11-22 13:32:20 +01:00
public function language() {
2021-05-20 21:52:09 +02:00
// Transmettre le choix au noyau
setcookie('ZWII_USER_I18N', $this->getUrl(2), time() + 3600, helper::baseUrl(false, false) , '', helper::isHttps(), true);
// Valeurs en sortie sans post
2020-11-24 11:12:33 +01:00
$this->addOutput([
2021-05-20 21:52:09 +02:00
'redirect' => helper::baseUrl() . $this->getUrl(3)
2020-11-24 11:12:33 +01:00
]);
2020-11-22 13:32:20 +01:00
}
2020-11-11 19:48:07 +01:00
}