pacKman/src/Config.php

147 lines
5.2 KiB
PHP
Raw Normal View History

2021-08-16 20:48:26 +00:00
<?php
2021-09-02 20:14:32 +00:00
/**
* @brief pacKman, a plugin for Dotclear 2
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @author Jean-Christian Denis
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2022-12-17 21:12:10 +00:00
declare(strict_types=1);
2022-12-18 23:21:11 +00:00
namespace Dotclear\Plugin\pacKman;
2021-08-16 20:48:26 +00:00
2022-12-17 21:12:10 +00:00
use dcCore;
use dcPage;
2023-01-20 20:54:39 +00:00
use dcNsProcess;
2023-03-11 17:46:23 +00:00
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Fieldset,
Input,
Label,
Legend,
Note,
Para
};
2022-12-17 21:12:10 +00:00
use Exception;
2023-01-20 20:54:39 +00:00
class Config extends dcNsProcess
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
public static function init(): bool
2022-12-17 21:12:10 +00:00
{
2023-03-16 22:56:25 +00:00
if (defined('DC_CONTEXT_ADMIN')) {
if (version_compare(phpversion(), My::PHP_MIN, '>=')) {
self::$init = true;
} else {
dcCore::app()->error->add(sprintf(__('%s required php >= %s'), My::id(), My::PHP_MIN));
}
}
2022-12-18 23:21:11 +00:00
return self::$init;
2022-12-17 21:12:10 +00:00
}
2023-01-20 20:54:39 +00:00
public static function process(): bool
2022-12-17 21:12:10 +00:00
{
2023-03-11 17:46:23 +00:00
if (!self::$init) {
return false;
2022-12-18 23:21:11 +00:00
}
2022-12-17 21:12:10 +00:00
if (empty($_POST['save'])) {
2023-01-20 20:54:39 +00:00
return true;
2022-12-17 21:12:10 +00:00
}
2023-03-16 22:56:53 +00:00
$s = new Settings();
2022-12-17 21:12:10 +00:00
# -- Set settings --
try {
2023-03-16 22:56:53 +00:00
foreach ($s->listSettings() as $key) {
$s->writeSetting($key, $_POST[$key] ?? '');
}
2022-12-17 21:12:10 +00:00
2023-03-16 22:56:53 +00:00
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
2021-08-17 21:12:33 +00:00
);
2023-03-16 22:56:53 +00:00
dcCore::app()->adminurl->redirect('admin.plugins', [
'module' => My::id(),
'conf' => '1',
'redir' => dcCore::app()->admin->__get('list')->getRedir(),
]);
2022-12-17 21:12:10 +00:00
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
2021-08-17 21:12:33 +00:00
}
2023-01-20 20:54:39 +00:00
return true;
2022-12-17 21:12:10 +00:00
}
2023-01-20 20:54:39 +00:00
public static function render(): void
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
if (!self::$init) {
2023-01-20 20:54:39 +00:00
return;
2022-12-18 23:21:11 +00:00
}
2022-12-17 21:12:10 +00:00
2022-12-18 23:21:11 +00:00
# -- Get settings --
2023-03-16 22:56:53 +00:00
$s = new Settings();
2022-12-17 21:12:10 +00:00
# -- Display form --
2023-03-11 17:46:23 +00:00
echo
(new Div())->items([
(new Fieldset())->class('fieldset')->legend((new Legend(__('Root'))))->fields([
// pack_repository
(new Para())->items([
(new Label(__('Path to repository:')))->for('pack_repository'),
2023-03-16 22:56:53 +00:00
(new Input('pack_repository'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_repository),
2023-03-11 17:46:23 +00:00
]),
(new Note())->class('form-note')->text(
sprintf(
__('Preconization: %s'),
dcCore::app()->blog->public_path ?
dcCore::app()->blog->public_path : __("Blog's public directory")
) . ' ' . __('Leave it empty to use Dotclear VAR directory')
),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Files'))))->fields([
// pack_filename
(new Para())->items([
(new Label(__('Name of exported package:')))->for('pack_filename'),
2023-03-16 22:56:53 +00:00
(new Input('pack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_filename),
2023-03-11 17:46:23 +00:00
]),
(new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%'))->class('form-note'),
// secondpack_filename
(new Para())->items([
(new Label(__('Name of second exported package:')))->for('secondpack_filename'),
2023-03-16 22:56:53 +00:00
(new Input('secondpack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->secondpack_filename),
2023-03-11 17:46:23 +00:00
]),
(new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%-%version%'))->class('form-note'),
// pack_overwrite
(new Para())->items([
2023-03-16 22:56:53 +00:00
(new Checkbox('pack_overwrite', $s->pack_overwrite))->value(1),
2023-03-11 17:46:23 +00:00
(new Label(__('Overwrite existing package'), Label::OUTSIDE_LABEL_AFTER))->for('pack_overwrite')->class('classic'),
]),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Content'))))->fields([
// pack_excludefiles
(new Para())->items([
(new Label(__('Extra files to exclude from package:')))->for('pack_excludefiles'),
2023-03-16 22:56:53 +00:00
(new Input('pack_excludefiles'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_excludefiles),
2023-03-11 17:46:23 +00:00
]),
(new Note())->text(sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz'))->class('form-note'),
// pack_nocomment
(new Para())->items([
2023-03-16 22:56:53 +00:00
(new Checkbox('pack_nocomment', $s->pack_nocomment))->value(1),
2023-03-11 17:46:23 +00:00
(new Label(__('Remove comments from files'), Label::OUTSIDE_LABEL_AFTER))->for('pack_nocomment')->class('classic'),
]),
// pack_fixnewline
(new Para())->items([
2023-03-16 22:56:53 +00:00
(new Checkbox('pack_fixnewline', $s->pack_fixnewline))->value(1),
2023-03-11 17:46:23 +00:00
(new Label(__('Fix newline style from files content'), Label::OUTSIDE_LABEL_AFTER))->for('pack_fixnewline')->class('classic'),
]),
]),
])->render();
2021-08-17 21:12:33 +00:00
}
2021-08-16 20:48:26 +00:00
}