From 4c0e33c83fe668802b51d7ee619494c75a96d6e6 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 5 Nov 2021 22:52:46 +0100 Subject: [PATCH] add settings to disable (hide) modules --- CHANGELOG.md | 4 +++ _config.php | 57 +++++++++++++++++++++++++++++ _install.php | 77 +++++++++++++++++++++++++++++++++++++++ _uninstall.php | 83 +++++++++++++++++++++++++++++++++++++++++++ inc/class.improve.php | 21 ++++++++--- 5 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 _config.php create mode 100644 _install.php create mode 100644 _uninstall.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ff9f53..cf96881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ dev - [ ] add module to check directory structure - [ ] 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 - add module to use php-cs-fixer diff --git a/_config.php b/_config.php new file mode 100644 index 0000000..e7a13a9 --- /dev/null +++ b/_config.php @@ -0,0 +1,57 @@ +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 '

' . __('List of disabled actions:') . '

'; + +foreach ($combo_actions as $name => $id) { + echo + '

'; +} +echo '
'; diff --git a/_install.php b/_install.php new file mode 100644 index 0000000..8951d3b --- /dev/null +++ b/_install.php @@ -0,0 +1,77 @@ +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; +} diff --git a/_uninstall.php b/_uninstall.php new file mode 100644 index 0000000..979f815 --- /dev/null +++ b/_uninstall.php @@ -0,0 +1,83 @@ +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) +); diff --git a/inc/class.improve.php b/inc/class.improve.php index c608ce5..27fbff5 100644 --- a/inc/class.improve.php +++ b/inc/class.improve.php @@ -19,22 +19,28 @@ class Improve 'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md' ]; private $core; - private $actions = []; - private $logs = []; - private $has_log = ['success' => false, 'warning' => false, 'error' => false]; + private $actions = []; + private $disabled = []; + private $logs = []; + private $has_log = ['success' => false, 'warning' => false, 'error' => false]; public function __construct(dcCore $core) { $this->core = &$core; $core->blog->settings->addNamespace('improve'); - $list = new arrayObject(); + $disabled = explode(';', (string) $core->blog->settings->improve->disabled); + $list = new arrayObject(); try { $this->core->callBehavior('improveAddAction', $list, $this->core); foreach ($list as $action) { if ($action instanceof ImproveAction && !isset($this->actions[$action->id])) { - $this->actions[$action->id] = $action; + if (in_array($action->id, $disabled)) { + $this->disabled[$action->id] = $action->name; + } else { + $this->actions[$action->id] = $action; + } } } } catch (Exception $e) { @@ -129,6 +135,11 @@ class Improve return $this->actions[$id] ?? null; } + public function disabled(): array + { + return $this->disabled; + } + public function fixModule(string $type, string $id, array $properties, array $actions): float { $time_start = microtime(true);