translater/src/Config.php

184 lines
7.2 KiB
PHP
Raw Normal View History

2021-08-18 22:51:40 +00:00
<?php
2021-09-02 21:44:01 +00:00
/**
* @brief translater, a plugin for Dotclear 2
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @author Jean-Christian Denis & contributors
2021-11-01 21:32:32 +00:00
*
2021-09-02 21:44:01 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-03-14 23:26:31 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\translater;
use dcCore;
use dcNsProcess;
use dcPage;
2021-08-18 22:51:40 +00:00
2023-03-14 23:26:31 +00:00
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Fieldset,
Input,
Label,
Legend,
Note,
Number,
Para,
Select
};
class Config extends dcNsProcess
{
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
if (version_compare(phpversion(), My::PHP_MIN, '>=')) {
self::$init = true;
} else {
dcCore::app()->error->add(sprintf(__('Translater required php >= %s'), My::PHP_MIN));
}
}
2023-03-14 23:26:31 +00:00
return self::$init;
}
2021-08-18 22:51:40 +00:00
2023-03-14 23:26:31 +00:00
public static function process(): bool
{
if (!self::$init) {
return false;
}
2023-03-14 23:26:31 +00:00
// nothing to process
if (empty($_POST['save'])) {
return true;
}
$s = new Settings();
2023-03-14 23:26:31 +00:00
try {
foreach ($s->listSettings() as $key) {
$s->writeSetting($key, $_POST[$key] ?? '');
2023-03-14 23:26:31 +00:00
}
dcPage::addSuccessNotice(
__('Configuration successfully updated.')
);
dcCore::app()->adminurl->redirect(
'admin.plugins',
['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
return true;
}
2021-08-18 22:51:40 +00:00
2023-03-14 23:26:31 +00:00
public static function render(): void
{
if (!self::$init) {
return;
}
$translater = new Translater();
echo (new Div())->items([
(new Fieldset())->class('fieldset')->legend((new Legend(__('Translation'))))->fields([
// write_langphp
(new Para())->items([
(new Checkbox('write_langphp', $translater->write_langphp))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Write .lang.php files'), Label::OUTSIDE_LABEL_AFTER))->for('write_langphp')->class('classic'),
]),
// scan_tpl
(new Para())->items([
(new Checkbox('scan_tpl', $translater->scan_tpl))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Translate also strings of template files'), Label::OUTSIDE_LABEL_AFTER))->for('scan_tpl')->class('classic'),
]),
// parse_nodc
(new Para())->items([
(new Checkbox('parse_nodc', $translater->parse_nodc))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Translate only unknow strings'), Label::OUTSIDE_LABEL_AFTER))->for('parse_nodc')->class('classic'),
]),
// hide_default
(new Para())->items([
(new Checkbox('hide_default', $translater->hide_default))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Hide default modules of Dotclear'), Label::OUTSIDE_LABEL_AFTER))->for('hide_default')->class('classic'),
]),
// parse_comment
(new Para())->items([
(new Checkbox('parse_comment', $translater->parse_comment))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Write comments in files'), Label::OUTSIDE_LABEL_AFTER))->for('parse_comment')->class('classic'),
]),
// parse_user
(new Para())->items([
(new Checkbox('parse_user', $translater->parse_user))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Write informations about author in files'), Label::OUTSIDE_LABEL_AFTER))->for('parse_user')->class('classic'),
]),
// parse_userinfo
(new Para())->items([
(new Label(__('User info:')))->for('parse_userinfo'),
(new Input('parse_userinfo'))->size(65)->maxlenght(255)->value($translater->parse_userinfo),
2023-03-14 23:26:31 +00:00
]),
(new Note())->text(sprintf(
__('Following informations can be used: %s'),
implode(', ', My::defaultUserInformations())
))->class('form-note'),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Import/Export'))))->fields([
// import_overwrite
(new Para())->items([
(new Checkbox('import_overwrite', $translater->import_overwrite))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Overwrite existing languages'), Label::OUTSIDE_LABEL_AFTER))->for('import_overwrite')->class('classic'),
]),
// export_filename
(new Para())->items([
(new Label(__('Name of exported package:')))->for('export_filename'),
(new Input('export_filename'))->size(65)->maxlenght(255)->value($translater->export_filename),
2023-03-14 23:26:31 +00:00
]),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Backups'))))->fields([
// backup_auto
(new Para())->items([
(new Checkbox('backup_auto', $translater->backup_auto))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Make backups when changes are made'), Label::OUTSIDE_LABEL_AFTER))->for('backup_auto')->class('classic'),
]),
// backup_limit
(new Para())->items([
(new Label(__('Limit backups per module to:')))->for('backup_limit')->class('classic'),
(new Number('backup_limit'))->min(0)->max(50)->value($translater->backup_limit),
2023-03-14 23:26:31 +00:00
]),
(new Note())->text(__('Set to 0 for no limit.'))->class('form-note'),
// backup_folder
(new Para())->items([
(new Label(__('Store backups in:')))->for('backup_folder'),
(new Select('backup_folder'))->default($translater->backup_folder)->items(My::backupFoldersCombo()),
2023-03-14 23:26:31 +00:00
]),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Behaviors'))))->fields([
// start_page
(new Para())->items([
(new Label(__('Default start menu:')))->for('start_page'),
(new Select('start_page'))->default($translater->start_page)->items(My::startPageCombo()),
2023-03-14 23:26:31 +00:00
]),
// plugin_menu
(new Para())->items([
(new Checkbox('plugin_menu', $translater->plugin_menu))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Enable menu on plugins page'), Label::OUTSIDE_LABEL_AFTER))->for('plugin_menu')->class('classic'),
]),
// theme_menu
(new Para())->items([
(new Checkbox('theme_menu', $translater->theme_menu))->value(1),
2023-03-14 23:26:31 +00:00
(new Label(__('Enable menu on themes page'), Label::OUTSIDE_LABEL_AFTER))->for('theme_menu')->class('classic'),
]),
]),
])->render();
dcPage::helpBlock('translater.config');
}
}