add settings to disable (hide) modules

This commit is contained in:
Jean-Christian Denis 2021-11-05 22:52:46 +01:00
parent e127b460e9
commit 4c0e33c83f
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 237 additions and 5 deletions

View file

@ -4,6 +4,10 @@ dev
- [ ] add module to check directory structure - [ ] add module to check directory structure
- [ ] write documentation of php class - [ ] write documentation of php class
0.5 - 2021.11.05
- add settings to disable (hide) modules
- fix dcstore xml rendering (thanks Franck Paul)
0.4 - 2021.11.02 0.4 - 2021.11.02
- add module to use php-cs-fixer - add module to use php-cs-fixer

57
_config.php Normal file
View file

@ -0,0 +1,57 @@
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
# Check user perms
dcPage::checkSuper();
$improve = new Improve($core);
$combo_actions = [];
foreach ($improve->modules() as $action) {
$combo_actions[$action->name] = $action->id;
}
$disabled = $improve->disabled();
if (!empty($disabled)) {
$combo_actions = array_merge($combo_actions, array_flip($disabled));
}
if (!empty($_POST['save'])) {
try {
$pdisabled = '';
if (!empty($_POST['disabled'])) {
$pdisabled = implode(';', $_POST['disabled']);
}
$core->blog->settings->improve->put('disabled', $pdisabled);
dcPage::addSuccessNotice(__('Configuration successfully updated.'));
$core->adminurl->redirect(
'admin.plugins',
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => $list->getRedir()]
);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
echo '<div class="fieldset"><h4>' . __('List of disabled actions:') . '</h4>';
foreach ($combo_actions as $name => $id) {
echo
'<p><label class="classic" title="' . $id . '">' .
form::checkbox(['disabled[]'], $id, ['checked' => isset($disabled[$id])]) .
__($name) . '</label></p>';
}
echo '</div>';

77
_install.php Normal file
View file

@ -0,0 +1,77 @@
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @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 --
$dc_min = '2.19';
$mod_id = 'improve';
$mod_conf = [
[
'disabled',
'List of hidden action modules',
'tab;newline;endoffile',
'string'
]
];
# -- Nothing to change below --
try {
# Check module version
if (version_compare(
$core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
return null;
}
# Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf(
'%s requires Dotclear %s',
$mod_id,
$dc_min
));
}
# Set module settings
$core->blog->settings->addNamespace($mod_id);
foreach ($mod_conf as $v) {
$core->blog->settings->{$mod_id}->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
# Set module version
$core->setVersion(
$mod_id,
$core->plugins->moduleInfo($mod_id, 'version')
);
return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
return false;
}

83
_uninstall.php Normal file
View file

@ -0,0 +1,83 @@
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$mod_id = 'improve';
$this->addUserAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
$mod_id,
/* desc */
__('delete all settings')
);
$this->addUserAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
__('delete plugin files')
);
$this->addUserAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
__('delete the version number')
);
$this->addDirectAction(
/* type */
'settings',
/* action */
'delete_all',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete all %s settings'), $mod_id)
);
$this->addDirectAction(
/* type */
'plugins',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s plugin files'), $mod_id)
);
$this->addDirectAction(
/* type */
'versions',
/* action */
'delete',
/* ns */
$mod_id,
/* desc */
sprintf(__('delete %s version number'), $mod_id)
);

View file

@ -20,6 +20,7 @@ class Improve
]; ];
private $core; private $core;
private $actions = []; private $actions = [];
private $disabled = [];
private $logs = []; private $logs = [];
private $has_log = ['success' => false, 'warning' => false, 'error' => false]; private $has_log = ['success' => false, 'warning' => false, 'error' => false];
@ -27,6 +28,7 @@ class Improve
{ {
$this->core = &$core; $this->core = &$core;
$core->blog->settings->addNamespace('improve'); $core->blog->settings->addNamespace('improve');
$disabled = explode(';', (string) $core->blog->settings->improve->disabled);
$list = new arrayObject(); $list = new arrayObject();
try { try {
@ -34,9 +36,13 @@ class Improve
foreach ($list as $action) { foreach ($list as $action) {
if ($action instanceof ImproveAction && !isset($this->actions[$action->id])) { if ($action instanceof ImproveAction && !isset($this->actions[$action->id])) {
if (in_array($action->id, $disabled)) {
$this->disabled[$action->id] = $action->name;
} else {
$this->actions[$action->id] = $action; $this->actions[$action->id] = $action;
} }
} }
}
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
@ -129,6 +135,11 @@ class Improve
return $this->actions[$id] ?? null; return $this->actions[$id] ?? null;
} }
public function disabled(): array
{
return $this->disabled;
}
public function fixModule(string $type, string $id, array $properties, array $actions): float public function fixModule(string $type, string $id, array $properties, array $actions): float
{ {
$time_start = microtime(true); $time_start = microtime(true);