licenseBootstrap/_config.php

116 lines
3.8 KiB
PHP
Raw Normal View History

2021-08-17 21:25:45 +00:00
<?php
2021-09-02 19:43:35 +00:00
/**
* @brief licenseBootstrap, a plugin for Dotclear 2
2022-11-20 21:36:32 +00:00
*
2021-09-02 19:43:35 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-20 21:36:32 +00:00
*
2021-09-02 19:43:35 +00:00
* @author Jean-Christian Denis
2022-11-20 21:36:32 +00:00
*
2021-09-02 19:43:35 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-08-17 21:25:45 +00:00
if (!defined('DC_CONTEXT_MODULE')) {
2021-08-17 21:46:17 +00:00
return null;
2021-08-17 21:25:45 +00:00
}
2022-11-20 21:36:32 +00:00
$redir = empty($_REQUEST['redir']) ?
dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
2021-08-17 21:25:45 +00:00
# -- Get settings --
2022-11-20 21:36:32 +00:00
dcCore::app()->blog->settings->addNamespace('licenseBootstrap');
$s = dcCore::app()->blog->settings->licenseBootstrap;
$lb_overwrite = (bool) $s->overwrite;
$lb_write_full = (bool) $s->write_full;
$lb_write_php = (bool) $s->write_php;
$lb_write_js = (bool) $s->write_js;
$lb_exclude_locales = (bool) $s->exclude_locales;
2021-08-17 21:46:17 +00:00
$lb_license_name = licenseBootstrap::getName($s->license_name);
$lb_license_head = licenseBootstrap::gethead($s->license_name, licenseBootstrap::decode($s->license_head));
2021-08-17 21:25:45 +00:00
# -- Set settings --
if (!empty($_POST['save'])) {
2021-08-17 21:46:17 +00:00
try {
$lb_overwrite = !empty($_POST['lb_overwrite']);
$lb_write_full = !empty($_POST['lb_write_full']);
$lb_write_php = !empty($_POST['lb_write_php']);
$lb_write_js = !empty($_POST['lb_write_js']);
$lb_exclude_locales = !empty($_POST['lb_exclude_locales']);
$lb_license_name = $_POST['lb_license_name'];
$lb_license_head = licenseBootstrap::gethead($lb_license_name, !empty($_POST['lb_license_head_' . $lb_license_name]) ? $_POST['lb_license_head_' . $lb_license_name] : '');
2022-11-20 21:36:32 +00:00
$s->put('overwrite', $lb_overwrite);
$s->put('write_full', $lb_write_full);
$s->put('write_php', $lb_write_php);
$s->put('write_js', $lb_write_js);
$s->put('exclude_locales', $lb_exclude_locales);
$s->put('license_name', licenseBootstrap::getName($lb_license_name));
$s->put('license_head', licenseBootstrap::encode($lb_license_head));
2021-08-17 21:46:17 +00:00
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
);
http::redirect(
2022-11-20 21:36:32 +00:00
dcCore::app()->admin->list->getURL('module=licenseBootstrap&conf=1&redir=' .
dcCore::app()->admin->list->getRedir())
2021-08-17 21:46:17 +00:00
);
2022-11-20 21:36:32 +00:00
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
2021-08-17 21:46:17 +00:00
}
2021-08-17 21:25:45 +00:00
}
# -- Display form --
echo '
<div class="fieldset">
2021-08-17 21:46:17 +00:00
<h4>' . __('Files') . '</h4>
2021-08-17 21:25:45 +00:00
2021-08-17 21:46:17 +00:00
<p><label class="classic" for="lb_overwrite">' .
form::checkbox('lb_overwrite', 1, $lb_overwrite) . ' ' .
__('Overwrite existing licenses') .
2021-08-17 21:25:45 +00:00
'</label></p>
2021-08-17 21:46:17 +00:00
<p><label class="classic" for="lb_write_full">' .
2022-11-20 21:36:32 +00:00
form::checkbox('lb_write_full', 1, $lb_write_full) . ' ' .
2021-08-17 21:46:17 +00:00
__('Add full LICENSE file to module root') .
2021-08-17 21:25:45 +00:00
'</label></p>
2021-08-17 21:46:17 +00:00
<p><label class="classic" for="lb_write_php">' .
form::checkbox('lb_write_php', 1, $lb_write_php) . ' ' .
__('Add license block to PHP files') .
2021-08-17 21:25:45 +00:00
'</label></p>
2021-08-17 21:46:17 +00:00
<p><label class="classic" for="lb_write_js">' .
form::checkbox('lb_write_js', 1, $lb_write_js) . ' ' .
__('Add license block to JS files') .
2021-08-17 21:25:45 +00:00
'</label></p>
2021-08-17 21:46:17 +00:00
<p><label class="classic" for="lb_exclude_locales">' .
form::checkbox('lb_exclude_locales', 1, $lb_exclude_locales) . ' ' .
__('Do not add license block to files from locales folder') .
2021-08-17 21:25:45 +00:00
'</label></p>
</div>
<div class="fieldset">
2021-08-17 21:46:17 +00:00
<h4>' . __('Licenses') . '</h4>';
2021-08-17 21:25:45 +00:00
2022-11-20 21:36:32 +00:00
foreach (licenseBootstrap::getLicenses() as $name) {
2021-08-17 21:46:17 +00:00
$check = false;
2022-11-20 21:36:32 +00:00
$head = licenseBootstrap::getHead($name);
2021-08-17 21:46:17 +00:00
if ($name == $lb_license_name) {
$check = true;
2022-11-20 21:36:32 +00:00
$head = licenseBootstrap::getHead($name, $lb_license_head);
2021-08-17 21:46:17 +00:00
}
echo '
<p><label class="classic" for="license_' . $name . '">' .
2022-11-20 21:36:32 +00:00
form::radio(['lb_license_name', 'license_' . $name], $name, $check) . ' ' .
2021-08-17 21:46:17 +00:00
sprintf(__('License %s:'), $name) . '</label></p>
<p class="area">' .
form::textarea('lb_license_head_' . $name, 50, 10, html::escapeHTML($head)) . '
</p>';
2021-08-17 21:25:45 +00:00
}
echo '
2022-11-20 21:36:32 +00:00
</div>';