From a30c43b882628039c58bb0e161b9114beed4d131 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 3 Dec 2022 14:40:00 +0100 Subject: [PATCH] cope with disabled modules, fix #4 --- inc/class.dc.packman.php | 1 + inc/lib.packman.php | 22 ++++++++++++++++++++++ index.php | 11 +++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/inc/class.dc.packman.php b/inc/class.dc.packman.php index 807c086..7f88807 100644 --- a/inc/class.dc.packman.php +++ b/inc/class.dc.packman.php @@ -27,6 +27,7 @@ class dcPackman 'CVS', '.DS_Store', 'Thumbs.db', + '_disabled', ]; public static function quote_exclude(array $exclude): array diff --git a/inc/lib.packman.php b/inc/lib.packman.php index a4e3ba5..3a3b199 100644 --- a/inc/lib.packman.php +++ b/inc/lib.packman.php @@ -55,6 +55,28 @@ class libPackman return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file))); } + public static function getModules(string $type, ?string $id = null): ?array + { + $type = $type == 'themes' ? 'themes' : 'plugins'; + + $modules = array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules()); + + if (empty($id)) { + return $modules; + } elseif (array_key_exists($id, $modules)) { + return $modules[$id]; + } + + return null; + } + + public static function moduleExists(string $type, ?string $id): bool + { + $type = $type == 'themes' ? 'themes' : 'plugins'; + + return array_key_exists($id, array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules())); + } + public static function modules(array $modules, string $type, string $title): ?bool { if (empty($modules) || !is_array($modules)) { diff --git a/index.php b/index.php index b331a9b..41b0f18 100644 --- a/index.php +++ b/index.php @@ -99,11 +99,11 @@ try { # Pack } elseif ($action == 'packup') { foreach ($_POST['modules'] as $root => $id) { - if (!${$type}->moduleExists($id)) { + if (!libPackman::moduleExists($type, $id)) { throw new Exception('No such module'); } - $module = ${$type}->getModules($id); + $module = libPackman::getModules($type, $id); $module['id'] = $id; $module['type'] = $type == 'themes' ? 'theme' : 'plugin'; @@ -261,8 +261,7 @@ dcPage::notices(); if (dcCore::app()->error->flag() || !$is_configured) { echo '
' . __('pacKman is not well configured.') . ' ' . - '' . __('Configuration') . '' . + '' . __('Configuration') . '' . '
'; } else { $repo_path_modules = array_merge( @@ -273,13 +272,13 @@ if (dcCore::app()->error->flag() || !$is_configured) { $themes_path_modules = dcPackman::getPackages($themes_path); libPackman::modules( - $plugins->getModules(), + libPackman::getModules('plugins'), 'plugins', __('Installed plugins') ); libPackman::modules( - $themes->getModules(), + libPackman::getModules('themes'), 'themes', __('Installed themes') );