Compare commits
No commits in common. "bcf4a26cd1b8d5f610a1d0027511aa83cf65c59b" and "7ca6e67ff8381144427313b2f42dfce3dea29860" have entirely different histories.
bcf4a26cd1
...
7ca6e67ff8
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,21 +1,3 @@
|
||||||
2023.05.13
|
|
||||||
- require dotclea r2.26
|
|
||||||
- require php 8.1
|
|
||||||
- use define php_min
|
|
||||||
- fix dump() method
|
|
||||||
|
|
||||||
2023.04.22
|
|
||||||
- require dotclea r2.26
|
|
||||||
- require php 8.1
|
|
||||||
- add plugin Uninstaller features
|
|
||||||
- use latest helper namespace
|
|
||||||
- fix nullsafe warnings
|
|
||||||
|
|
||||||
2023.03.25
|
|
||||||
- require dotclea r2.26
|
|
||||||
- require php 8.1
|
|
||||||
- use namespace
|
|
||||||
|
|
||||||
2022.12.22
|
2022.12.22
|
||||||
- add wtfpl license
|
- add wtfpl license
|
||||||
- use SVG icon
|
- use SVG icon
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[![Release](https://img.shields.io/github/v/release/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/releases)
|
[![Release](https://img.shields.io/github/v/release/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/releases)
|
||||||
[![Date](https://img.shields.io/github/release-date/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/releases)
|
[![Date](https://img.shields.io/github/release-date/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/releases)
|
||||||
[![Issues](https://img.shields.io/github/issues/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/issues)
|
[![Issues](https://img.shields.io/github/issues/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/issues)
|
||||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
|
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
|
||||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/licenseBootstrap)
|
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/licenseBootstrap)
|
||||||
[![License](https://img.shields.io/github/license/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/blob/master/LICENSE)
|
[![License](https://img.shields.io/github/license/JcDenis/licenseBootstrap)](https://github.com/JcDenis/licenseBootstrap/blob/master/LICENSE)
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@ themes and plugins from Dotclear administration pages.
|
||||||
licenseBootstrap requires:
|
licenseBootstrap requires:
|
||||||
|
|
||||||
* Super administrator permissions
|
* Super administrator permissions
|
||||||
* Dotclear 2.26
|
* Dotclear 2.24
|
||||||
* Php >= 8.1
|
|
||||||
|
|
||||||
## USAGE
|
## USAGE
|
||||||
|
|
||||||
|
@ -34,10 +33,6 @@ go to ''configure plugin'', fill in form.
|
||||||
Once it's done you can manage your modules license from menu
|
Once it's done you can manage your modules license from menu
|
||||||
''License bootstrap'' on sidebar or you can add dashboard icon.
|
''License bootstrap'' on sidebar or you can add dashboard icon.
|
||||||
|
|
||||||
By default, licenseBootstrap uses old style code blocs,
|
|
||||||
if you want a modern style you should use a more recent plugin
|
|
||||||
like the one called ''improve''.
|
|
||||||
|
|
||||||
## LINKS
|
## LINKS
|
||||||
|
|
||||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
|
|
||||||
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function ($favs) {
|
||||||
|
$favs->register(basename(__DIR__), [
|
||||||
|
'title' => __('License bootstrap'),
|
||||||
|
'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
|
||||||
|
'small-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')),
|
||||||
|
'large-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')),
|
||||||
|
//'permissions' => dcCore::app()->auth->isSuperAdmin(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
dcCore::app()->addBehavior('packmanBeforeCreatePackage', function ($module) {
|
||||||
|
if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('behavior_packman')) {
|
||||||
|
licenseBootstrap::addLicense($module);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||||
|
__('License bootstrap'),
|
||||||
|
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
|
||||||
|
urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')),
|
||||||
|
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||||
|
dcCore::app()->auth->isSuperAdmin()
|
||||||
|
);
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_MODULE')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$redir = empty($_REQUEST['redir']) ?
|
||||||
|
dcCore::app()->admin->__get('list')->getURL() . '#plugins' : $_REQUEST['redir'];
|
||||||
|
|
||||||
|
# -- Get settings --
|
||||||
|
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
|
|
||||||
|
$lb_overwrite = (bool) $s->get('overwrite');
|
||||||
|
$lb_write_full = (bool) $s->get('write_full');
|
||||||
|
$lb_write_php = (bool) $s->get('write_php');
|
||||||
|
$lb_write_js = (bool) $s->get('write_js');
|
||||||
|
$lb_exclude_locales = (bool) $s->get('exclude_locales');
|
||||||
|
$lb_license_name = licenseBootstrap::getName($s->get('license_name'));
|
||||||
|
$lb_license_head = licenseBootstrap::gethead($s->get('license_name'), licenseBootstrap::decode($s->get('license_head')));
|
||||||
|
|
||||||
|
# -- Set settings --
|
||||||
|
if (!empty($_POST['save'])) {
|
||||||
|
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] : '');
|
||||||
|
|
||||||
|
$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));
|
||||||
|
|
||||||
|
dcPage::addSuccessNotice(
|
||||||
|
__('Configuration has been successfully updated.')
|
||||||
|
);
|
||||||
|
http::redirect(
|
||||||
|
dcCore::app()->admin->__get('list')->getURL('module=' . basename(__DIR__) . '&conf=1&redir=' .
|
||||||
|
dcCore::app()->admin->__get('list')->getRedir())
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# -- Display form --
|
||||||
|
echo '
|
||||||
|
<div class="fieldset">
|
||||||
|
<h4>' . __('Files') . '</h4>
|
||||||
|
|
||||||
|
<p><label class="classic" for="lb_overwrite">' .
|
||||||
|
form::checkbox('lb_overwrite', 1, $lb_overwrite) . ' ' .
|
||||||
|
__('Overwrite existing licenses') .
|
||||||
|
'</label></p>
|
||||||
|
|
||||||
|
<p><label class="classic" for="lb_write_full">' .
|
||||||
|
form::checkbox('lb_write_full', 1, $lb_write_full) . ' ' .
|
||||||
|
__('Add full LICENSE file to module root') .
|
||||||
|
'</label></p>
|
||||||
|
|
||||||
|
<p><label class="classic" for="lb_write_php">' .
|
||||||
|
form::checkbox('lb_write_php', 1, $lb_write_php) . ' ' .
|
||||||
|
__('Add license block to PHP files') .
|
||||||
|
'</label></p>
|
||||||
|
|
||||||
|
<p><label class="classic" for="lb_write_js">' .
|
||||||
|
form::checkbox('lb_write_js', 1, $lb_write_js) . ' ' .
|
||||||
|
__('Add license block to JS files') .
|
||||||
|
'</label></p>
|
||||||
|
|
||||||
|
<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') .
|
||||||
|
'</label></p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="fieldset">
|
||||||
|
<h4>' . __('Licenses') . '</h4>';
|
||||||
|
|
||||||
|
foreach (licenseBootstrap::getLicenses() as $name) {
|
||||||
|
$check = false;
|
||||||
|
$head = licenseBootstrap::getHead($name);
|
||||||
|
if ($name == $lb_license_name) {
|
||||||
|
$check = true;
|
||||||
|
$head = licenseBootstrap::getHead($name, $lb_license_head);
|
||||||
|
}
|
||||||
|
echo '
|
||||||
|
<p><label class="classic" for="license_' . $name . '">' .
|
||||||
|
form::radio(['lb_license_name', 'license_' . $name], $name, $check) . ' ' .
|
||||||
|
sprintf(__('License %s:'), $name) . '</label></p>
|
||||||
|
<p class="area">' .
|
||||||
|
form::textarea('lb_license_head_' . $name, 50, 10, html::escapeHTML($head)) . '
|
||||||
|
</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '
|
||||||
|
</div>';
|
|
@ -18,12 +18,9 @@ $this->registerModule(
|
||||||
'License bootstrap',
|
'License bootstrap',
|
||||||
'Add license to your plugins and themes',
|
'Add license to your plugins and themes',
|
||||||
'Jean-Christian Denis',
|
'Jean-Christian Denis',
|
||||||
'2023.05.13',
|
'2022.12.22',
|
||||||
[
|
[
|
||||||
'requires' => [
|
'requires' => [['core', '2.24']],
|
||||||
['php', '8.1'],
|
|
||||||
['core', '2.26'],
|
|
||||||
],
|
|
||||||
'permissions' => null,
|
'permissions' => null,
|
||||||
'type' => 'plugin',
|
'type' => 'plugin',
|
||||||
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
# -- Module specs --
|
||||||
|
|
||||||
|
$mod_conf = [
|
||||||
|
[
|
||||||
|
'overwrite',
|
||||||
|
'Overwrite existing licence',
|
||||||
|
false,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'write_full',
|
||||||
|
'Add complete licence file',
|
||||||
|
true,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'write_php',
|
||||||
|
'Write license into php files',
|
||||||
|
true,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'write_js',
|
||||||
|
'Write license into js files',
|
||||||
|
false,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'exclude_locales',
|
||||||
|
'Exclude locales from license',
|
||||||
|
true,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'license_name',
|
||||||
|
'License short name',
|
||||||
|
'gpl2',
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'license_head',
|
||||||
|
'File header licence text',
|
||||||
|
licenseBootstrap::encode(
|
||||||
|
licenseBootstrap::getHead('gpl2')
|
||||||
|
),
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'behavior_packman',
|
||||||
|
'Add LicenceBootstrap to plugin pacKman',
|
||||||
|
false,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
# -- Nothing to change below --
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Check module version
|
||||||
|
if (!dcCore::app()->newVersion(
|
||||||
|
basename(__DIR__),
|
||||||
|
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// version < 2022.12.22 : upgrade settings ns and array
|
||||||
|
$current = dcCore::app()->getVersion(basename(__DIR__));
|
||||||
|
if ($current && version_compare($current, '2022.12.22', '<')) {
|
||||||
|
$record = dcCore::app()->con->select(
|
||||||
|
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
||||||
|
"WHERE setting_ns = 'licenseBootstrap' "
|
||||||
|
);
|
||||||
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
|
while ($record->fetch()) {
|
||||||
|
if (in_array($record->setting_id, ['license_head'])) {
|
||||||
|
$cur->setting_value = (string) unserialize(base64_decode($record->setting_value));
|
||||||
|
}
|
||||||
|
$cur->setting_ns = basename(__DIR__);
|
||||||
|
$cur->update(
|
||||||
|
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'licenseBootstrap' " .
|
||||||
|
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
||||||
|
);
|
||||||
|
$cur->clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Set module settings
|
||||||
|
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
|
foreach ($mod_conf as $v) {
|
||||||
|
dcCore::app()->blog->settings->__get(basename(__DIR__))->put(
|
||||||
|
$v[0],
|
||||||
|
$v[2],
|
||||||
|
$v[3],
|
||||||
|
$v[1],
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Clearbricks::lib()->autoload([
|
||||||
|
'licenseBootstrap' => __DIR__ . '/inc/class.license.bootstrap.php',
|
||||||
|
'libLicenseBootstrap' => __DIR__ . '/inc/lib.license.bootstrap.php',
|
||||||
|
]);
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addUserAction(
|
||||||
|
/* type */
|
||||||
|
'settings',
|
||||||
|
/* action */
|
||||||
|
'delete_all',
|
||||||
|
/* ns */
|
||||||
|
basename(__DIR__),
|
||||||
|
/* desc */
|
||||||
|
__('delete all settings')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addUserAction(
|
||||||
|
/* type */
|
||||||
|
'plugins',
|
||||||
|
/* action */
|
||||||
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
basename(__DIR__),
|
||||||
|
/* desc */
|
||||||
|
__('delete plugin files')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addDirectAction(
|
||||||
|
/* type */
|
||||||
|
'settings',
|
||||||
|
/* action */
|
||||||
|
'delete_all',
|
||||||
|
/* ns */
|
||||||
|
basename(__DIR__),
|
||||||
|
/* desc */
|
||||||
|
sprintf(__('delete all %s settings'), basename(__DIR__))
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addDirectAction(
|
||||||
|
/* type */
|
||||||
|
'plugins',
|
||||||
|
/* action */
|
||||||
|
'delete',
|
||||||
|
/* ns */
|
||||||
|
basename(__DIR__),
|
||||||
|
/* desc */
|
||||||
|
sprintf(__('delete %s plugin files'), basename(__DIR__))
|
||||||
|
);
|
|
@ -2,11 +2,11 @@
|
||||||
<modules xmlns:da="http://dotaddict.org/da/">
|
<modules xmlns:da="http://dotaddict.org/da/">
|
||||||
<module id="licenseBootstrap">
|
<module id="licenseBootstrap">
|
||||||
<name>License bootstrap</name>
|
<name>License bootstrap</name>
|
||||||
<version>2023.05.13</version>
|
<version>2022.12.22</version>
|
||||||
<author>Jean-Christian Denis</author>
|
<author>Jean-Christian Denis</author>
|
||||||
<desc>Add license to your plugins and themes</desc>
|
<desc>Add license to your plugins and themes</desc>
|
||||||
<file>https://github.com/JcDenis/licenseBootstrap/releases/download/v2023.05.13/plugin-licenseBootstrap.zip</file>
|
<file>https://github.com/JcDenis/licenseBootstrap/releases/download/v2022.12.22/plugin-licenseBootstrap.zip</file>
|
||||||
<da:dcmin>2.26</da:dcmin>
|
<da:dcmin>2.24</da:dcmin>
|
||||||
<da:details>https://plugins.dotaddict.org/dc2/details/licenseBootstrap</da:details>
|
<da:details>https://plugins.dotaddict.org/dc2/details/licenseBootstrap</da:details>
|
||||||
<da:support>https://github.com/JcDenis/licenseBootstrap</da:support>
|
<da:support>https://github.com/JcDenis/licenseBootstrap</da:support>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -10,19 +10,13 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
class licenseBootstrap
|
||||||
|
|
||||||
use dcAuth;
|
|
||||||
use dcCore;
|
|
||||||
use Dotclear\Helper\File\Files;
|
|
||||||
use Dotclear\Helper\File\Path;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Utils
|
|
||||||
{
|
{
|
||||||
protected static array $licenses = [];
|
protected static $licenses = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add license to a module.
|
* Add license to a module.
|
||||||
|
@ -32,13 +26,9 @@ class Utils
|
||||||
*
|
*
|
||||||
* @param array $module Module info
|
* @param array $module Module info
|
||||||
*/
|
*/
|
||||||
public static function addLicense(array $module): void
|
public static function addLicense($module)
|
||||||
{
|
{
|
||||||
if (is_null(dcCore::app()->auth)) {
|
$s = dcCore::app()->blog->settings->get(basename(__DIR__));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$s = Settings::init();
|
|
||||||
|
|
||||||
# --BEHAVIOR-- licenseBootstrapBeforeAddLicense
|
# --BEHAVIOR-- licenseBootstrapBeforeAddLicense
|
||||||
dcCore::app()->callBehavior(
|
dcCore::app()->callBehavior(
|
||||||
|
@ -46,22 +36,22 @@ class Utils
|
||||||
$module
|
$module
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($s->write_full) {
|
if ($s->get('write_full')) {
|
||||||
self::writeFullContent(
|
licenseBootstrap::writeFullContent(
|
||||||
$s->license_name,
|
$s->get('license_name'),
|
||||||
$module,
|
$module,
|
||||||
$s->overwrite
|
$s->get('overwrite')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
self::writeHeadContent(
|
licenseBootstrap::writeHeadContent(
|
||||||
$s->license_name,
|
$s->get('license_name'),
|
||||||
self::decode($s->license_head),
|
licenseBootstrap::decode($s->get('license_head')),
|
||||||
$module,
|
$module,
|
||||||
dcCore::app()->auth,
|
dcCore::app()->auth,
|
||||||
$s->overwrite,
|
$s->get('overwrite'),
|
||||||
$s->write_php,
|
$s->get('write_php'),
|
||||||
$s->write_js,
|
$s->get('write_js'),
|
||||||
$s->exclude_locales
|
$s->get('exclude_locales')
|
||||||
);
|
);
|
||||||
|
|
||||||
# --BEHAVIOR-- licenseBootstrapAfterAddLicense
|
# --BEHAVIOR-- licenseBootstrapAfterAddLicense
|
||||||
|
@ -76,20 +66,20 @@ class Utils
|
||||||
*
|
*
|
||||||
* @return array List of licenses names
|
* @return array List of licenses names
|
||||||
*/
|
*/
|
||||||
public static function getLicenses(): array
|
public static function getLicenses()
|
||||||
{
|
{
|
||||||
if (empty(self::$licenses)) {
|
if (empty(licenseBootstrap::$licenses)) {
|
||||||
$file_reg = '/^([a-z0-9]+)\.head\.txt$/';
|
$file_reg = '/^([a-z0-9]+)\.head\.txt$/';
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach (Files::scandir(__DIR__ . DIRECTORY_SEPARATOR . My::TEMPLATE_FOLDER . DIRECTORY_SEPARATOR) as $file) {
|
foreach (files::scandir(dirname(__FILE__) . '/licenses/') as $file) {
|
||||||
if (preg_match($file_reg, $file, $matches)) {
|
if (preg_match($file_reg, $file, $matches)) {
|
||||||
$res[] = $matches[1];
|
$res[] = $matches[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::$licenses = $res;
|
licenseBootstrap::$licenses = $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$licenses;
|
return licenseBootstrap::$licenses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +90,7 @@ class Utils
|
||||||
* @param string $name License name
|
* @param string $name License name
|
||||||
* @return string License name
|
* @return string License name
|
||||||
*/
|
*/
|
||||||
public static function getName(string $name = 'gpl2'): string
|
public static function getName($name = 'gpl2')
|
||||||
{
|
{
|
||||||
return in_array($name, self::getLicenses()) ? $name : 'gpl2';
|
return in_array($name, self::getLicenses()) ? $name : 'gpl2';
|
||||||
}
|
}
|
||||||
|
@ -112,7 +102,7 @@ class Utils
|
||||||
* @param string $content Header content
|
* @param string $content Header content
|
||||||
* @return string Header content
|
* @return string Header content
|
||||||
*/
|
*/
|
||||||
public static function getHead(string $name = 'gpl2', string $content = ''): string
|
public static function getHead($name = 'gpl2', $content = '')
|
||||||
{
|
{
|
||||||
if (!in_array($name, self::getLicenses())) {
|
if (!in_array($name, self::getLicenses())) {
|
||||||
$name = 'gpl2';
|
$name = 'gpl2';
|
||||||
|
@ -129,7 +119,7 @@ class Utils
|
||||||
* @param string $name License name
|
* @param string $name License name
|
||||||
* @return string Full license content
|
* @return string Full license content
|
||||||
*/
|
*/
|
||||||
public static function getFull(string $name = 'gpl2'): string
|
public static function getFull($name = 'gpl2')
|
||||||
{
|
{
|
||||||
return self::getContent($name, 'full');
|
return self::getContent($name, 'full');
|
||||||
}
|
}
|
||||||
|
@ -141,7 +131,7 @@ class Utils
|
||||||
* @param string $part License part (head or full)
|
* @param string $part License part (head or full)
|
||||||
* @return string License content
|
* @return string License content
|
||||||
*/
|
*/
|
||||||
public static function getContent(string $name = 'gpl2', string $part = 'head'): string
|
public static function getContent($name = 'gpl2', $part = 'head')
|
||||||
{
|
{
|
||||||
if (!in_array($name, self::getLicenses())) {
|
if (!in_array($name, self::getLicenses())) {
|
||||||
$name = 'gpl2';
|
$name = 'gpl2';
|
||||||
|
@ -150,8 +140,8 @@ class Utils
|
||||||
$part = 'head';
|
$part = 'head';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) file_get_contents(
|
return file_get_contents(
|
||||||
implode(DIRECTORY_SEPARATOR, [__DIR__, My::TEMPLATE_FOLDER, $name . '.' . $part . '.txt'])
|
dirname(__FILE__) . '/licenses/' . $name . '.' . $part . '.txt'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,13 +151,13 @@ class Utils
|
||||||
* @param string $name License name
|
* @param string $name License name
|
||||||
* @param string $content License block content
|
* @param string $content License block content
|
||||||
* @param array $module Module info
|
* @param array $module Module info
|
||||||
* @param dcAuth $user dcAuth instance
|
* @param object $user dcAuth instance
|
||||||
* @param boolean $overwrite Overwrite existing license
|
* @param boolean $overwrite Overwrite existing license
|
||||||
* @param boolean $php Write license in PHP
|
* @param boolean $php Write license in PHP
|
||||||
* @param boolean $js Write license in JS
|
* @param boolean $js Write license in JS
|
||||||
* @param boolean $locales Excludes locales folder
|
* @param boolean $locales Excludes locales folder
|
||||||
*/
|
*/
|
||||||
public static function writeHeadContent(string $name, string $content, array $module, dcAuth $user, bool $overwrite, bool $php, bool $js, bool $locales): void
|
public static function writeHeadContent($name, $content, $module, $user, $overwrite, $php, $js, $locales)
|
||||||
{
|
{
|
||||||
if (!isset($module['root']) || !is_writable($module['root'])) {
|
if (!isset($module['root']) || !is_writable($module['root'])) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
@ -184,14 +174,14 @@ class Utils
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $module['root'] . DIRECTORY_SEPARATOR . $file;
|
$path = $module['root'] . '/' . $file;
|
||||||
$extension = Files::getExtension($file);
|
$extension = files::getExtension($file);
|
||||||
|
|
||||||
if ($php && $extension == 'php') {
|
if ($php && $extension == 'php') {
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$file,
|
$file,
|
||||||
self::replacePhpContent(
|
self::replacePhpContent(
|
||||||
(string) file_get_contents($file),
|
file_get_contents($file),
|
||||||
$license,
|
$license,
|
||||||
$overwrite
|
$overwrite
|
||||||
)
|
)
|
||||||
|
@ -200,7 +190,7 @@ class Utils
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$file,
|
$file,
|
||||||
self::replaceJsContent(
|
self::replaceJsContent(
|
||||||
(string) file_get_contents($file),
|
file_get_contents($file),
|
||||||
$license,
|
$license,
|
||||||
$overwrite
|
$overwrite
|
||||||
)
|
)
|
||||||
|
@ -216,17 +206,17 @@ class Utils
|
||||||
* @param array $module Module info
|
* @param array $module Module info
|
||||||
* @param boolean $overwrite Overwrite existing license
|
* @param boolean $overwrite Overwrite existing license
|
||||||
*/
|
*/
|
||||||
public static function writeFullContent(string $name, array $module, bool $overwrite): void
|
public static function writeFullContent($name, $module, $overwrite)
|
||||||
{
|
{
|
||||||
if (!isset($module['root']) || !is_writable($module['root'])) {
|
if (!isset($module['root']) || !is_writable($module['root'])) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
if (file_exists($module['root'] . DIRECTORY_SEPARATOR . 'LICENSE') && !$overwrite) {
|
if (file_exists($module['root'] . '/LICENSE') && !$overwrite) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$module['root'] . DIRECTORY_SEPARATOR . 'LICENSE',
|
$module['root'] . '/LICENSE',
|
||||||
self::getFull($name)
|
self::getFull($name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -239,9 +229,9 @@ class Utils
|
||||||
* @param boolean $overwrite Overwrite existing license
|
* @param boolean $overwrite Overwrite existing license
|
||||||
* @return string File content
|
* @return string File content
|
||||||
*/
|
*/
|
||||||
protected static function replacePhpContent(string $content, string $license, bool $overwrite): string
|
protected static function replacePhpContent($content, $license, $overwrite)
|
||||||
{
|
{
|
||||||
$clean = (string) preg_replace(
|
$clean = preg_replace(
|
||||||
'/((# -- BEGIN LICENSE BLOCK ([-]+))(.*?)' .
|
'/((# -- BEGIN LICENSE BLOCK ([-]+))(.*?)' .
|
||||||
'(# -- END LICENSE BLOCK ([-]+))([\n|\r\n]+))/msi',
|
'(# -- END LICENSE BLOCK ([-]+))([\n|\r\n]+))/msi',
|
||||||
'',
|
'',
|
||||||
|
@ -252,7 +242,7 @@ class Utils
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) preg_replace(
|
return preg_replace(
|
||||||
'/(\<\?php)/',
|
'/(\<\?php)/',
|
||||||
'<?php' .
|
'<?php' .
|
||||||
"\r\n# -- BEGIN LICENSE BLOCK ----------------------------------\r\n" .
|
"\r\n# -- BEGIN LICENSE BLOCK ----------------------------------\r\n" .
|
||||||
|
@ -273,7 +263,7 @@ class Utils
|
||||||
* @param boolean $overwrite Overwrite existing license
|
* @param boolean $overwrite Overwrite existing license
|
||||||
* @return string File content
|
* @return string File content
|
||||||
*/
|
*/
|
||||||
protected static function replaceJsContent(string $content, string $license, bool $overwrite): string
|
protected static function replaceJsContent($content, $license, $overwrite)
|
||||||
{
|
{
|
||||||
$clean = preg_replace(
|
$clean = preg_replace(
|
||||||
'/((\/\* -- BEGIN LICENSE BLOCK ([-]+))(.*?)' .
|
'/((\/\* -- BEGIN LICENSE BLOCK ([-]+))(.*?)' .
|
||||||
|
@ -300,10 +290,10 @@ class Utils
|
||||||
*
|
*
|
||||||
* @param string $content License content
|
* @param string $content License content
|
||||||
* @param array $module Module info
|
* @param array $module Module info
|
||||||
* @param dcAuth $user User info
|
* @param object $user User info
|
||||||
* @return string License content
|
* @return string License content
|
||||||
*/
|
*/
|
||||||
protected static function replaceInfo(string $content, array $module, dcAuth $user): string
|
protected static function replaceInfo($content, $module, $user)
|
||||||
{
|
{
|
||||||
return str_replace(
|
return str_replace(
|
||||||
[
|
[
|
||||||
|
@ -340,10 +330,10 @@ class Utils
|
||||||
* @param array $res Ignore
|
* @param array $res Ignore
|
||||||
* @return array List of files
|
* @return array List of files
|
||||||
*/
|
*/
|
||||||
protected static function getModuleFiles(string $path, string $dir = '', array $res = []): array
|
protected static function getModuleFiles($path, $dir = '', $res = [])
|
||||||
{
|
{
|
||||||
$path = Path::real($path);
|
$path = path::real($path);
|
||||||
if ($path === false || !is_dir($path) || !is_readable($path)) {
|
if (!is_dir($path) || !is_readable($path)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,38 +341,34 @@ class Utils
|
||||||
$dir = $path;
|
$dir = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
$files = Files::scandir($path);
|
$files = files::scandir($path);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (substr($file, 0, 1) == '.') {
|
if (substr($file, 0, 1) == '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {
|
if (is_dir($path . '/' . $file)) {
|
||||||
$res = self::getModuleFiles(
|
$res = self::getModuleFiles(
|
||||||
$path . DIRECTORY_SEPARATOR . $file,
|
$path . '/' . $file,
|
||||||
$dir . DIRECTORY_SEPARATOR . $file,
|
$dir . '/' . $file,
|
||||||
$res
|
$res
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$res[] = empty($dir) ? $file : $dir . DIRECTORY_SEPARATOR . $file;
|
$res[] = empty($dir) ? $file : $dir . '/' . $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function encode(string $a): string
|
public static function encode($a)
|
||||||
{
|
{
|
||||||
$r = json_encode($a);
|
return json_encode($a);
|
||||||
|
|
||||||
return $r === false ? '' : $r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function decode(string $a): string
|
public static function decode($a)
|
||||||
{
|
{
|
||||||
$r = json_decode($a, true);
|
return json_decode($a, true);
|
||||||
|
|
||||||
return $r === false ? '' : $r;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class libLicenseBootstrap
|
||||||
|
{
|
||||||
|
public static function modules($modules, $type, $title)
|
||||||
|
{
|
||||||
|
$type = $type == 'themes' ? 'themes' : 'plugins';
|
||||||
|
|
||||||
|
echo
|
||||||
|
'<div class="multi-part" ' .
|
||||||
|
'id="packman-' . $type . '" title="' . $title . '">' .
|
||||||
|
'<h3>' . $title . '</h3>';
|
||||||
|
|
||||||
|
if (empty($modules) && !is_array($modules)) {
|
||||||
|
echo
|
||||||
|
'<p><strong>' . __('There are no modules.') . '</strong></p>' .
|
||||||
|
'<div>';
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
'<form action="plugin.php" method="post">' .
|
||||||
|
'<table class="clear"><tr>' .
|
||||||
|
'<th class="nowrap">' . __('Id') . '</th>' .
|
||||||
|
'<th class="nowrap">' . __('Version') . '</th>' .
|
||||||
|
'<th class="nowrap maximal">' . __('Name') . '</th>' .
|
||||||
|
'<th class="nowrap">' . __('Root') . '</th>' .
|
||||||
|
'</tr>';
|
||||||
|
|
||||||
|
foreach (self::sort($modules) as $id => $module) {
|
||||||
|
echo
|
||||||
|
'<tr class="line">' .
|
||||||
|
'<td class="nowrap"><label class="classic">' .
|
||||||
|
form::checkbox(['modules[' . html::escapeHTML($id) . ']'], 1) .
|
||||||
|
html::escapeHTML($id) .
|
||||||
|
'</label></td>' .
|
||||||
|
'<td class="nowrap count">' .
|
||||||
|
html::escapeHTML($module['version']) .
|
||||||
|
'</td>' .
|
||||||
|
'<td class="nowrap maximal">' .
|
||||||
|
__(html::escapeHTML($module['name'])) .
|
||||||
|
'</td>' .
|
||||||
|
'<td class="nowrap">' .
|
||||||
|
dirname(path::real($module['root'], false)) .
|
||||||
|
'</td>' .
|
||||||
|
'</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
'</table>' .
|
||||||
|
'<p class="checkboxes-helpers"></p>' .
|
||||||
|
'<p>' .
|
||||||
|
(
|
||||||
|
!empty($_REQUEST['redir']) ?
|
||||||
|
form::hidden(
|
||||||
|
['redir'],
|
||||||
|
html::escapeHTML($_REQUEST['redir'])
|
||||||
|
) : ''
|
||||||
|
) .
|
||||||
|
form::hidden(['p'], 'licenseBootstrap') .
|
||||||
|
form::hidden(['type'], $type) .
|
||||||
|
form::hidden(['action'], 'addlicense') .
|
||||||
|
'<input type="submit" name="addlicense" value="' .
|
||||||
|
__('Add license to selected modules') . '" />' .
|
||||||
|
dcCore::app()->formNonce() . '</p>' .
|
||||||
|
'</form>' .
|
||||||
|
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function sort($modules)
|
||||||
|
{
|
||||||
|
$sorter = [];
|
||||||
|
foreach ($modules as $id => $module) {
|
||||||
|
$sorter[$id] = $id;
|
||||||
|
}
|
||||||
|
array_multisort($sorter, SORT_ASC, $modules);
|
||||||
|
|
||||||
|
return $modules;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief licenseBootstrap, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcPage::checkSuper();
|
||||||
|
|
||||||
|
# Queries
|
||||||
|
$action = $_POST['action'] ?? '';
|
||||||
|
$type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes']) ? $_POST['type'] : '';
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
|
|
||||||
|
# Modules
|
||||||
|
if (!(dcCore::app()->themes instanceof dcThemes)) {
|
||||||
|
dcCore::app()->themes = new dcThemes();
|
||||||
|
dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null);
|
||||||
|
}
|
||||||
|
$themes = dcCore::app()->themes;
|
||||||
|
$plugins = dcCore::app()->plugins;
|
||||||
|
|
||||||
|
# Rights
|
||||||
|
$is_editable = !empty($type)
|
||||||
|
&& !empty($_POST['modules'])
|
||||||
|
&& is_array($_POST['modules']);
|
||||||
|
|
||||||
|
# Actions
|
||||||
|
try {
|
||||||
|
# Add license to modules
|
||||||
|
if ($action == 'addlicense' && $is_editable) {
|
||||||
|
$modules = array_keys($_POST['modules']);
|
||||||
|
|
||||||
|
foreach ($modules as $id) {
|
||||||
|
if (!${$type}->moduleExists($id)) {
|
||||||
|
throw new Exception('No such module');
|
||||||
|
}
|
||||||
|
|
||||||
|
$module = ${$type}->getModules($id);
|
||||||
|
$module['id'] = $id;
|
||||||
|
$module['type'] = $type == 'themes' ? 'theme' : 'plugin';
|
||||||
|
|
||||||
|
licenseBootstrap::addLicense($module);
|
||||||
|
}
|
||||||
|
|
||||||
|
dcAdminNotices::addSuccessNotice(
|
||||||
|
__('License successfully added.')
|
||||||
|
);
|
||||||
|
http::redirect(
|
||||||
|
empty($_POST['redir']) ?
|
||||||
|
dcCore::app()->admin->getPageURL() : $_POST['redir']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch(Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
# Display
|
||||||
|
echo
|
||||||
|
'<html><head><title>' . __('License bootstrap') . '</title>' .
|
||||||
|
dcPage::jsPageTabs() .
|
||||||
|
dcPage::jsModuleLoad(basename(__DIR__) . '/js/licensebootstrap.js') .
|
||||||
|
|
||||||
|
# --BEHAVIOR-- licenseBootstrapAdminHeader
|
||||||
|
dcCore::app()->callBehavior('licenseBootstrapAdminHeader') .
|
||||||
|
|
||||||
|
'</head><body>' .
|
||||||
|
|
||||||
|
dcPage::breadcrumb(
|
||||||
|
[
|
||||||
|
__('Plugins') => '',
|
||||||
|
__('License bootstrap') => '',
|
||||||
|
]
|
||||||
|
) .
|
||||||
|
dcPage::notices();
|
||||||
|
|
||||||
|
libLicenseBootstrap::modules(
|
||||||
|
$plugins->getModules(),
|
||||||
|
'plugins',
|
||||||
|
__('Installed plugins')
|
||||||
|
);
|
||||||
|
|
||||||
|
libLicenseBootstrap::modules(
|
||||||
|
$themes->getModules(),
|
||||||
|
'themes',
|
||||||
|
__('Installed themes')
|
||||||
|
);
|
||||||
|
|
||||||
|
dcPage::helpBlock('licenseBootstrap');
|
||||||
|
|
||||||
|
echo
|
||||||
|
'</body></html>';
|
|
@ -9,19 +9,17 @@
|
||||||
# DOT NOT MODIFY THIS FILE !
|
# DOT NOT MODIFY THIS FILE !
|
||||||
#
|
#
|
||||||
|
|
||||||
use Dotclear\Helper\L10n;
|
l10n::$locales['Configuration has been successfully updated.'] = 'La configuration a été mise à jour avec succés.';
|
||||||
|
l10n::$locales['Files'] = 'Fichiers';
|
||||||
L10n::$locales['Configuration has been successfully updated.'] = 'La configuration a été mise à jour avec succés.';
|
l10n::$locales['Overwrite existing licenses'] = 'Écraser les licences existantes';
|
||||||
L10n::$locales['Files'] = 'Fichiers';
|
l10n::$locales['Add full LICENSE file to module root'] = 'Ajouter le fichier de licence complet à la racine du module';
|
||||||
L10n::$locales['Overwrite existing licenses'] = 'Écraser les licences existantes';
|
l10n::$locales['Add license block to PHP files'] = 'Ajouter le bloc de licence aux ficheirs PHP';
|
||||||
L10n::$locales['Add full LICENSE file to module root'] = 'Ajouter le fichier de licence complet à la racine du module';
|
l10n::$locales['Add license block to JS files'] = 'Ajouter le bloc de licence aux ficheirs JS';
|
||||||
L10n::$locales['Add license block to PHP files'] = 'Ajouter le bloc de licence aux ficheirs PHP';
|
l10n::$locales['Do not add license block to files from locales folder'] = 'Ne pas ajouter la licence aux fichiers du dossier locales';
|
||||||
L10n::$locales['Add license block to JS files'] = 'Ajouter le bloc de licence aux ficheirs JS';
|
l10n::$locales['Licenses'] = 'Licences';
|
||||||
L10n::$locales['Do not add license block to files from locales folder'] = 'Ne pas ajouter la licence aux fichiers du dossier locales';
|
l10n::$locales['License %s:'] = 'Licence %s :';
|
||||||
L10n::$locales['Licenses'] = 'Licences';
|
l10n::$locales['Id'] = 'Id';
|
||||||
L10n::$locales['License %s:'] = 'Licence %s :';
|
l10n::$locales['Root'] = 'Racine';
|
||||||
L10n::$locales['Id'] = 'Id';
|
l10n::$locales['Add license to selected modules'] = 'Ajouter la licence aux modules selectionner';
|
||||||
L10n::$locales['Root'] = 'Racine';
|
l10n::$locales['License successfully added.'] = 'Licence ajouter avec succès';
|
||||||
L10n::$locales['Add license to selected modules'] = 'Ajouter la licence aux modules selectionner';
|
l10n::$locales['Configuration'] = 'Configuration';
|
||||||
L10n::$locales['License successfully added.'] = 'Licence ajouter avec succès';
|
|
||||||
L10n::$locales['Configuration'] = 'Configuration';
|
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcAdmin;
|
|
||||||
use dcCore;
|
|
||||||
use dcFavorites;
|
|
||||||
use dcNsProcess;
|
|
||||||
use dcPage;
|
|
||||||
|
|
||||||
class Backend extends dcNsProcess
|
|
||||||
{
|
|
||||||
public static function init(): bool
|
|
||||||
{
|
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
||||||
&& dcCore::app()->auth?->isSuperAdmin();
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function process(): bool
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
|
||||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
|
||||||
$favs->register(My::id(), [
|
|
||||||
'title' => My::name(),
|
|
||||||
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
|
||||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
|
||||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
|
||||||
//'permissions' => dcCore::app()->auth->isSuperAdmin(),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
'packmanBeforeCreatePackage' => function ($module) {
|
|
||||||
if (Settings::init()->behavior_packman) {
|
|
||||||
Utils::addLicense($module);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
|
||||||
My::name(),
|
|
||||||
dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
|
||||||
dcPage::getPF(My::id() . '/icon.svg'),
|
|
||||||
preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
|
||||||
dcCore::app()->auth?->isSuperAdmin()
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
148
src/Config.php
148
src/Config.php
|
@ -1,148 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
use dcPage;
|
|
||||||
use dcNsProcess;
|
|
||||||
use Dotclear\Helper\Html\Form\{
|
|
||||||
Checkbox,
|
|
||||||
Div,
|
|
||||||
Fieldset,
|
|
||||||
Label,
|
|
||||||
Legend,
|
|
||||||
Para,
|
|
||||||
Radio,
|
|
||||||
Textarea
|
|
||||||
};
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Config extends dcNsProcess
|
|
||||||
{
|
|
||||||
public static function init(): bool
|
|
||||||
{
|
|
||||||
static::$init == defined('DC_CONTEXT_ADMIN')
|
|
||||||
&& dcCore::app()->auth?->isSuperAdmin();
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function process(): bool
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($_POST['save'])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$s = Settings::init();
|
|
||||||
|
|
||||||
# -- Set settings --
|
|
||||||
try {
|
|
||||||
$license_name = $_POST['lb_license_name'];
|
|
||||||
$license_head = Utils::gethead(
|
|
||||||
$license_name,
|
|
||||||
!empty($_POST['lb_license_head_' . $license_name]) ? $_POST['lb_license_head_' . $license_name] : ''
|
|
||||||
);
|
|
||||||
|
|
||||||
$s->writeSetting('hide_distrib', !empty($_POST['lb_hide_distrib']));
|
|
||||||
$s->writeSetting('overwrite', !empty($_POST['lb_overwrite']));
|
|
||||||
$s->writeSetting('write_full', !empty($_POST['lb_write_full']));
|
|
||||||
$s->writeSetting('write_php', !empty($_POST['lb_write_php']));
|
|
||||||
$s->writeSetting('write_js', !empty($_POST['lb_write_js']));
|
|
||||||
$s->writeSetting('exclude_locales', !empty($_POST['lb_exclude_locales']));
|
|
||||||
$s->writeSetting('license_name', Utils::getName($license_name));
|
|
||||||
$s->writeSetting('license_head', Utils::encode($license_head));
|
|
||||||
|
|
||||||
dcPage::addSuccessNotice(
|
|
||||||
__('Configuration has been 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function render(): void
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$s = Settings::init();
|
|
||||||
|
|
||||||
$licences = [];
|
|
||||||
foreach (Utils::getLicenses() as $name) {
|
|
||||||
$check = false;
|
|
||||||
$head = Utils::getHead($name);
|
|
||||||
if ($name == Utils::getName($s->license_name)) {
|
|
||||||
$check = true;
|
|
||||||
$head = Utils::getHead($name, Utils::getHead($s->license_name, Utils::decode($s->license_head)));
|
|
||||||
}
|
|
||||||
$licences[] = (new Para())->items([
|
|
||||||
(new Radio(['lb_license_name', 'license_' . $name], $check))->value($name),
|
|
||||||
(new Label(sprintf(__('License %s:'), $name), Label::OUTSIDE_LABEL_AFTER))->for('license_' . $name)->class('classic'),
|
|
||||||
]);
|
|
||||||
$licences[] = (new Para())->items([
|
|
||||||
(new Textarea('lb_license_head_' . $name, $head))->class('maximal')->cols(50)->rows(10),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
(new Div())->items([
|
|
||||||
(new Fieldset())->class('fieldset')->legend((new Legend(__('Files'))))->fields([
|
|
||||||
// hide_distrib
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_hide_distrib', $s->hide_distrib))->value(1),
|
|
||||||
(new Label(__('Hide distributed modules from lists'), Label::OUTSIDE_LABEL_AFTER))->for('lb_hide_distrib')->class('classic'),
|
|
||||||
]),
|
|
||||||
// overwrite
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_overwrite', $s->overwrite))->value(1),
|
|
||||||
(new Label(__('Overwrite existing licenses'), Label::OUTSIDE_LABEL_AFTER))->for('lb_overwrite')->class('classic'),
|
|
||||||
]),
|
|
||||||
// write_full
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_write_full', $s->write_full))->value(1),
|
|
||||||
(new Label(__('Add full LICENSE file to module root'), Label::OUTSIDE_LABEL_AFTER))->for('lb_write_full')->class('classic'),
|
|
||||||
]),
|
|
||||||
// write_php
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_write_php', $s->write_php))->value(1),
|
|
||||||
(new Label(__('Add license block to PHP files'), Label::OUTSIDE_LABEL_AFTER))->for('lb_write_php')->class('classic'),
|
|
||||||
]),
|
|
||||||
// write_js
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_write_js', $s->write_js))->value(1),
|
|
||||||
(new Label(__('Add license block to JS files'), Label::OUTSIDE_LABEL_AFTER))->for('lb_write_js')->class('classic'),
|
|
||||||
]),
|
|
||||||
// exclude_locales
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox('lb_exclude_locales', $s->exclude_locales))->value(1),
|
|
||||||
(new Label(__('Do not add license block to files from locales folder'), Label::OUTSIDE_LABEL_AFTER))->for('lb_exclude_locales')->class('classic'),
|
|
||||||
]),
|
|
||||||
]),
|
|
||||||
(new Fieldset())->class('fieldset')->legend((new Legend(__('Licenses'))))->fields($licences),
|
|
||||||
])->render();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
use dcNamespace;
|
|
||||||
use dcNsProcess;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Install extends dcNsProcess
|
|
||||||
{
|
|
||||||
public static function init(): bool
|
|
||||||
{
|
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
||||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function process(): bool
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Upgrade
|
|
||||||
self::growUp();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function growUp(): void
|
|
||||||
{
|
|
||||||
$current = dcCore::app()->getVersion(My::id());
|
|
||||||
|
|
||||||
// Update settings id, ns
|
|
||||||
if ($current && version_compare($current, '2022.12.22', '<')) {
|
|
||||||
$record = dcCore::app()->con->select(
|
|
||||||
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
|
||||||
"WHERE setting_ns = 'licenseBootstrap' "
|
|
||||||
);
|
|
||||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
|
||||||
while ($record->fetch()) {
|
|
||||||
if (in_array($record->f('setting_id'), ['license_head'])) {
|
|
||||||
$cur->setField('setting_value', (string) unserialize(base64_decode($record->f('setting_value'))));
|
|
||||||
}
|
|
||||||
$cur->setField('setting_ns', My::id());
|
|
||||||
$cur->update(
|
|
||||||
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'licenseBootstrap' " .
|
|
||||||
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr($record->f('blog_id')) . "' "))
|
|
||||||
);
|
|
||||||
$cur->clean();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
222
src/Manage.php
222
src/Manage.php
|
@ -1,222 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
use dcPage;
|
|
||||||
use dcThemes;
|
|
||||||
use dcNsProcess;
|
|
||||||
use Dotclear\Helper\Html\Html;
|
|
||||||
use Dotclear\Helper\Html\Form\{
|
|
||||||
Checkbox,
|
|
||||||
Hidden,
|
|
||||||
Label,
|
|
||||||
Para,
|
|
||||||
Submit,
|
|
||||||
Text
|
|
||||||
};
|
|
||||||
use Dotclear\Helper\File\Path;
|
|
||||||
use Dotclear\Helper\Network\Http;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Manage extends dcNsProcess
|
|
||||||
{
|
|
||||||
public static function init(): bool
|
|
||||||
{
|
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
||||||
&& dcCore::app()->auth?->isSuperAdmin();
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function process(): bool
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = in_array($_POST['type'] ?? '', ['plugins', 'themes']) ? $_POST['type'] : '';
|
|
||||||
|
|
||||||
if (($_POST['action'] ?? '') != 'addlicense'
|
|
||||||
|| empty($type)
|
|
||||||
|| empty($_POST['modules'])
|
|
||||||
|| !is_array($_POST['modules'])
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$m = self::loadModules();
|
|
||||||
|
|
||||||
# Actions
|
|
||||||
try {
|
|
||||||
$modules = array_values($_POST['modules']);
|
|
||||||
|
|
||||||
foreach ($modules as $id) {
|
|
||||||
if (!$m[$type]->moduleExists($id)) {
|
|
||||||
throw new Exception('No such module');
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = $m[$type]->getModules($id);
|
|
||||||
$module['id'] = $id;
|
|
||||||
$module['type'] = $type == 'themes' ? 'theme' : 'plugin';
|
|
||||||
|
|
||||||
Utils::addLicense($module);
|
|
||||||
}
|
|
||||||
|
|
||||||
dcPage::addSuccessNotice(
|
|
||||||
__('License successfully added.')
|
|
||||||
);
|
|
||||||
Http::redirect(
|
|
||||||
empty($_POST['redir']) ?
|
|
||||||
dcCore::app()->admin->getPageURL() : $_POST['redir']
|
|
||||||
);
|
|
||||||
} catch(Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function render(): void
|
|
||||||
{
|
|
||||||
if (!static::$init) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$m = self::loadModules();
|
|
||||||
|
|
||||||
# Display
|
|
||||||
dcPage::openModule(
|
|
||||||
My::name(),
|
|
||||||
dcPage::jsPageTabs() .
|
|
||||||
dcPage::jsModuleLoad(My::id() . '/js/licensebootstrap.js') .
|
|
||||||
|
|
||||||
# --BEHAVIOR-- licenseBootstrapAdminHeader
|
|
||||||
dcCore::app()->callBehavior('licenseBootstrapAdminHeader')
|
|
||||||
);
|
|
||||||
|
|
||||||
echo
|
|
||||||
dcPage::breadcrumb([
|
|
||||||
__('Plugins') => '',
|
|
||||||
My::name() => '',
|
|
||||||
]) .
|
|
||||||
dcPage::notices();
|
|
||||||
|
|
||||||
self::displayModulesList(
|
|
||||||
$m['plugins']->getModules(),
|
|
||||||
'plugins',
|
|
||||||
__('Installed plugins')
|
|
||||||
);
|
|
||||||
|
|
||||||
self::displayModulesList(
|
|
||||||
$m['themes']->getModules(),
|
|
||||||
'themes',
|
|
||||||
__('Installed themes')
|
|
||||||
);
|
|
||||||
|
|
||||||
dcPage::helpBlock('licenseBootstrap');
|
|
||||||
|
|
||||||
dcPage::closeModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function displayModulesList(array $modules, string $type, string $title): void
|
|
||||||
{
|
|
||||||
if (Settings::init()->hide_distrib) {
|
|
||||||
$modules = array_diff_key($modules, array_flip(array_values(array_merge(explode(',', DC_DISTRIB_PLUGINS), explode(',', DC_DISTRIB_THEMES)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'<div class="multi-part" ' .
|
|
||||||
'id="packman-' . $type . '" title="' . $title . '">' .
|
|
||||||
'<h3>' . $title . '</h3>';
|
|
||||||
|
|
||||||
if (empty($modules)) {
|
|
||||||
echo
|
|
||||||
'<p><strong>' . __('There are no modules.') . '</strong></p>' .
|
|
||||||
'<div>';
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'<form action="plugin.php" method="post">' .
|
|
||||||
'<table class="clear"><tr>' .
|
|
||||||
'<th class="nowrap">' . __('Id') . '</th>' .
|
|
||||||
'<th class="nowrap">' . __('Version') . '</th>' .
|
|
||||||
'<th class="nowrap maximal">' . __('Name') . '</th>' .
|
|
||||||
'<th class="nowrap">' . __('Root') . '</th>' .
|
|
||||||
'</tr>';
|
|
||||||
|
|
||||||
foreach (self::sortModules($modules) as $id => $module) {
|
|
||||||
echo
|
|
||||||
'<tr class="line">' .
|
|
||||||
'<td class="nowrap">' .
|
|
||||||
(new Para())->items([
|
|
||||||
(new Checkbox(['modules[]', 'modules_' . Html::escapeHTML($id)], false))->value(Html::escapeHTML($id)),
|
|
||||||
(new Label(Html::escapeHTML($id), Label::OUTSIDE_LABEL_AFTER))->for('modules_' . Html::escapeHTML($id))->class('classic'),
|
|
||||||
])->render() .
|
|
||||||
'</label></td>' .
|
|
||||||
'<td class="nowrap count">' .
|
|
||||||
Html::escapeHTML($module['version']) .
|
|
||||||
'</td>' .
|
|
||||||
'<td class="nowrap maximal">' .
|
|
||||||
__(Html::escapeHTML($module['name'])) .
|
|
||||||
'</td>' .
|
|
||||||
'<td class="nowrap">' .
|
|
||||||
dirname((string) Path::real($module['root'], false)) .
|
|
||||||
'</td>' .
|
|
||||||
'</tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'</table>' .
|
|
||||||
'<p class="checkboxes-helpers"></p>' .
|
|
||||||
(new Para())->items([
|
|
||||||
(new Hidden(['redir'], empty($_REQUEST['redir']) ? '' : Html::escapeHTML($_REQUEST['redir']))),
|
|
||||||
(new Hidden(['p'], My::id())),
|
|
||||||
(new Hidden(['type'], $type)),
|
|
||||||
(new Hidden(['action'], 'addlicense')),
|
|
||||||
(new Submit('addlicense'))->accesskey('s')->value(__('Add license to selected modules')),
|
|
||||||
dcCore::app()->formNonce(false),
|
|
||||||
])->render() .
|
|
||||||
'</form>' .
|
|
||||||
|
|
||||||
'</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function sortModules(array $modules): array
|
|
||||||
{
|
|
||||||
$sorter = [];
|
|
||||||
foreach ($modules as $id => $module) {
|
|
||||||
$sorter[$id] = $id;
|
|
||||||
}
|
|
||||||
array_multisort($sorter, SORT_ASC, $modules);
|
|
||||||
|
|
||||||
return $modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function loadModules(): array
|
|
||||||
{
|
|
||||||
if (!(dcCore::app()->themes instanceof dcThemes)) {
|
|
||||||
dcCore::app()->themes = new dcThemes();
|
|
||||||
dcCore::app()->themes->loadModules((string) dcCore::app()->blog?->themes_path, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'themes' => dcCore::app()->themes,
|
|
||||||
'plugins' => dcCore::app()->plugins,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
52
src/My.php
52
src/My.php
|
@ -1,52 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module definitions.
|
|
||||||
*/
|
|
||||||
class My
|
|
||||||
{
|
|
||||||
/** @var string Licenses default templates folder name */
|
|
||||||
public const TEMPLATE_FOLDER = 'licenses';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module id.
|
|
||||||
*/
|
|
||||||
public static function id(): string
|
|
||||||
{
|
|
||||||
return basename(dirname(__DIR__));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module name.
|
|
||||||
*/
|
|
||||||
public static function name(): string
|
|
||||||
{
|
|
||||||
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
|
|
||||||
|
|
||||||
return __(is_string($name) ? $name : self::id());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module path.
|
|
||||||
*/
|
|
||||||
public static function path(): string
|
|
||||||
{
|
|
||||||
return dirname(__DIR__);
|
|
||||||
}
|
|
||||||
}
|
|
112
src/Settings.php
112
src/Settings.php
|
@ -1,112 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
|
|
||||||
class Settings
|
|
||||||
{
|
|
||||||
/** @var Settings self instance */
|
|
||||||
private static $settings;
|
|
||||||
|
|
||||||
// Hide distributed modules from lists
|
|
||||||
public readonly bool $hide_distrib;
|
|
||||||
|
|
||||||
// Overwrite existing licence
|
|
||||||
public readonly bool $overwrite;
|
|
||||||
|
|
||||||
// Add complete licence file
|
|
||||||
public readonly bool $write_full;
|
|
||||||
|
|
||||||
// Write license into php files
|
|
||||||
public readonly bool $write_php;
|
|
||||||
|
|
||||||
// Write license into js files
|
|
||||||
public readonly bool $write_js;
|
|
||||||
|
|
||||||
// Exclude locales from license
|
|
||||||
public readonly bool $exclude_locales;
|
|
||||||
|
|
||||||
// License short name
|
|
||||||
public readonly string $license_name;
|
|
||||||
|
|
||||||
// File header licence text
|
|
||||||
public readonly string $license_head;
|
|
||||||
|
|
||||||
// Add LicenceBootstrap to plugin pacKman
|
|
||||||
public readonly bool $behavior_packman;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor set up plugin settings
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$s = dcCore::app()->blog?->settings->get(My::id());
|
|
||||||
|
|
||||||
$this->hide_distrib = (bool) ($s?->get('hide_distrib') ?? false);
|
|
||||||
$this->overwrite = (bool) ($s?->get('overwrite') ?? false);
|
|
||||||
$this->write_full = (bool) ($s?->get('write_full') ?? true);
|
|
||||||
$this->write_php = (bool) ($s?->get('pack_overwrite') ?? true);
|
|
||||||
$this->write_js = (bool) ($s?->get('pack_filename') ?? false);
|
|
||||||
$this->exclude_locales = (bool) ($s?->get('exclude_locales') ?? true);
|
|
||||||
$this->license_name = (string) ($s?->get('license_name') ?? 'gpl2');
|
|
||||||
$this->license_head = (string) ($s?->get('license_head') ?? Utils::encode(Utils::getHead('gpl2')));
|
|
||||||
$this->behavior_packman = (bool) ($s?->get('behavior_packman') ?? false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function init(): Settings
|
|
||||||
{
|
|
||||||
if (!(self::$settings instanceof self)) {
|
|
||||||
self::$settings = new self();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSetting(string $key): mixed
|
|
||||||
{
|
|
||||||
return $this->{$key} ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrite a plugin settings (in db)
|
|
||||||
*
|
|
||||||
* @param string $key The setting ID
|
|
||||||
* @param mixed $value The setting value
|
|
||||||
*
|
|
||||||
* @return bool True on success
|
|
||||||
*/
|
|
||||||
public function writeSetting(string $key, mixed $value): bool
|
|
||||||
{
|
|
||||||
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
|
|
||||||
dcCore::app()->blog?->settings->get(My::id())->drop($key);
|
|
||||||
dcCore::app()->blog?->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List defined settings keys
|
|
||||||
*
|
|
||||||
* @return array The settings keys
|
|
||||||
*/
|
|
||||||
public function listSettings(): array
|
|
||||||
{
|
|
||||||
return array_diff_key(get_object_vars($this), ['settings' => '']);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief licenseBootstrap, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dotclear\Plugin\licenseBootstrap;
|
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
use dcNsProcess;
|
|
||||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
|
||||||
|
|
||||||
class Uninstall extends dcNsProcess
|
|
||||||
{
|
|
||||||
public static function init(): bool
|
|
||||||
{
|
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function process(): bool
|
|
||||||
{
|
|
||||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uninstaller::instance()
|
|
||||||
->addUserAction(
|
|
||||||
'settings',
|
|
||||||
'delete_all',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
->addUserAction(
|
|
||||||
'plugins',
|
|
||||||
'delete',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
->addUserAction(
|
|
||||||
'versions',
|
|
||||||
'delete',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
->addDirectAction(
|
|
||||||
'settings',
|
|
||||||
'delete_all',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
->addDirectAction(
|
|
||||||
'plugins',
|
|
||||||
'delete',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
->addDirectAction(
|
|
||||||
'versions',
|
|
||||||
'delete',
|
|
||||||
My::id()
|
|
||||||
)
|
|
||||||
;
|
|
||||||
|
|
||||||
// no custom action
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue