translater/src/Config.php

180 lines
6.9 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
{
2023-03-19 23:20:41 +00:00
static::$init = defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->auth?->isSuperAdmin()
&& My::phpCompliant();
2023-03-14 23:26:31 +00:00
2023-03-19 23:20:41 +00:00
return static::$init;
2023-03-14 23:26:31 +00:00
}
2021-08-18 22:51:40 +00:00
2023-03-14 23:26:31 +00:00
public static function process(): bool
{
2023-03-19 23:20:41 +00:00
if (!static::$init) {
2023-03-14 23:26:31 +00:00
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.')
);
2023-03-19 23:21:13 +00:00
dcCore::app()->adminurl?->redirect(
2023-03-14 23:26:31 +00:00
'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
{
2023-03-19 23:20:41 +00:00
if (!static::$init) {
2023-03-14 23:26:31 +00:00
return;
}
2023-03-16 21:55:10 +00:00
$s = new Settings();
2023-03-14 23:26:31 +00:00
echo (new Div())->items([
(new Fieldset())->class('fieldset')->legend((new Legend(__('Translation'))))->fields([
// write_langphp
(new Para())->items([
2023-03-16 21:55:10 +00:00
(new Checkbox('write_langphp', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('scan_tpl', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('parse_nodc', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('hide_default', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('parse_comment', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('parse_user', $s->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'),
2023-03-16 21:55:10 +00:00
(new Input('parse_userinfo'))->size(65)->maxlenght(255)->value($s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('import_overwrite', $s->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'),
2023-03-16 21:55:10 +00:00
(new Input('export_filename'))->size(65)->maxlenght(255)->value($s->export_filename),
2023-03-14 23:26:31 +00:00
]),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Backups'))))->fields([
// backup_auto
(new Para())->items([
2023-03-16 21:55:10 +00:00
(new Checkbox('backup_auto', $s->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'),
2023-03-16 21:55:10 +00:00
(new Number('backup_limit'))->min(0)->max(50)->value($s->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'),
2023-03-16 21:55:10 +00:00
(new Select('backup_folder'))->default($s->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'),
2023-03-16 21:55:10 +00:00
(new Select('start_page'))->default($s->start_page)->items(My::startPageCombo()),
2023-03-14 23:26:31 +00:00
]),
// plugin_menu
(new Para())->items([
2023-03-16 21:55:10 +00:00
(new Checkbox('plugin_menu', $s->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([
2023-03-16 21:55:10 +00:00
(new Checkbox('theme_menu', $s->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');
}
}