pacKman/inc/Config.php

154 lines
5.1 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
/* dotclear ns */
use dcCore;
use dcPage;
/* clearbricks ns */
use form;
use http;
use path;
/* php ns */
use Exception;
2022-12-17 21:21:01 +00:00
class Config
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
private static $init = false;
public static function init(): bool
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
if (defined('DC_CONTEXT_ADMIN')) {
dcCore::app()->blog->settings->addNamespace(Core::id());
self::$init = true;
}
return self::$init;
2022-12-17 21:12:10 +00:00
}
public static function process(): void
{
2022-12-18 23:21:11 +00:00
if (!self::$init) {
return;
}
2022-12-17 21:12:10 +00:00
if (empty($_POST['save'])) {
return;
}
# -- Set settings --
try {
2022-12-19 11:04:34 +00:00
$pack_nocomment = !empty($_POST['pack_nocomment']);
$pack_fixnewline = !empty($_POST['pack_fixnewline']);
$pack_overwrite = !empty($_POST['pack_overwrite']);
$pack_filename = (string) $_POST['pack_filename'];
$secondpack_filename = (string) $_POST['secondpack_filename'];
$pack_repository = (string) $_POST['pack_repository'];
2022-12-19 11:04:34 +00:00
$pack_excludefiles = (string) $_POST['pack_excludefiles'];
2022-12-17 21:12:10 +00:00
$check = Utils::is_configured(
Utils::getRepositoryDir($pack_repository),
2022-12-19 11:04:34 +00:00
$pack_filename,
$secondpack_filename
2021-08-17 21:12:33 +00:00
);
2022-12-17 21:12:10 +00:00
if ($check) {
2022-12-18 23:21:11 +00:00
$s = dcCore::app()->blog->settings->__get(Core::id());
2022-12-19 11:04:34 +00:00
$s->put('pack_nocomment', $pack_nocomment);
$s->put('pack_fixnewline', $pack_fixnewline);
$s->put('pack_overwrite', $pack_overwrite);
$s->put('pack_filename', $pack_filename);
$s->put('secondpack_filename', $secondpack_filename);
$s->put('pack_repository', $pack_repository);
$s->put('pack_excludefiles', $pack_excludefiles);
2022-12-17 21:12:10 +00:00
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
);
http::redirect(
2022-12-18 23:21:11 +00:00
dcCore::app()->admin->__get('list')->getURL('module=' . Core::id() . '&conf=1&redir=' .
2022-12-17 21:12:10 +00:00
dcCore::app()->admin->__get('list')->getRedir())
);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
2021-08-17 21:12:33 +00:00
}
2022-12-17 21:12:10 +00:00
}
2022-12-18 23:21:11 +00:00
public static function render()
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
if (!self::$init) {
return false;
}
2022-12-17 21:12:10 +00:00
2022-12-18 23:21:11 +00:00
# -- Get settings --
$s = dcCore::app()->blog->settings->__get(Core::id());
2022-12-17 21:12:10 +00:00
# -- Display form --
echo '
<div class="fieldset">
<h4>' . __('Root') . '</h4>
2022-12-19 11:04:34 +00:00
<p><label for="pack_repository">' . __('Path to repository:') . ' ' .
form::field('pack_repository', 65, 255, (string) $s->get('pack_repository'), 'maximal') .
2022-12-17 21:12:10 +00:00
'</label></p>' .
'<p class="form-note">' . sprintf(
__('Preconization: %s'),
dcCore::app()->blog->public_path ?
dcCore::app()->blog->public_path : __("Blog's public directory")
) . '<br />' . __('Leave it empty to use Dotclear VAR directory') . '</p>
2022-12-17 21:12:10 +00:00
</div>
<div class="fieldset">
<h4>' . __('Files') . '</h4>
2022-12-19 11:04:34 +00:00
<p><label for="pack_filename">' . __('Name of exported package:') . ' ' .
form::field('pack_filename', 65, 255, (string) $s->get('pack_filename'), 'maximal') .
2022-12-17 21:12:10 +00:00
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p>
2022-12-19 11:04:34 +00:00
<p><label for="secondpack_filename">' . __('Name of second exported package:') . ' ' .
form::field('secondpack_filename', 65, 255, (string) $s->get('secondpack_filename'), 'maximal') .
2022-12-17 21:12:10 +00:00
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '</p>
2022-12-19 11:04:34 +00:00
<p><label class="classic" for="pack_overwrite">' .
form::checkbox('pack_overwrite', 1, (bool) $s->get('pack_overwrite')) . ' ' .
2022-12-17 21:12:10 +00:00
__('Overwrite existing package') . '</label></p>
</div>
<div class="fieldset">
<h4>' . __('Content') . '</h4>
2022-12-19 11:04:34 +00:00
<p><label for="pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' .
form::field('pack_excludefiles', 65, 255, (string) $s->get('pack_excludefiles'), 'maximal') .
2022-12-17 21:12:10 +00:00
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '</p>
2022-12-19 11:04:34 +00:00
<p><label class="classic" for="pack_nocomment">' .
form::checkbox('pack_nocomment', 1, (bool) $s->get('pack_nocomment')) . ' ' .
2022-12-17 21:12:10 +00:00
__('Remove comments from files') . '</label></p>
2022-12-19 11:04:34 +00:00
<p><label class="classic" for="pack_fixnewline">' .
form::checkbox('pack_fixnewline', 1, (bool) $s->get('pack_fixnewline')) . ' ' .
2022-12-17 21:12:10 +00:00
__('Fix newline style from files content') . '</label></p>
</div>';
2021-08-17 21:12:33 +00:00
}
2021-08-16 20:48:26 +00:00
}