diff --git a/src/Manage.php b/src/Manage.php index 14eae84..b931e36 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -76,9 +76,20 @@ class Manage extends dcNsProcess if (!empty($vars->entries) && !empty($vars->action)) { try { - foreach ($vars->entries as $ns) { + // special related + if (!empty($vars->related) && $vars->action == 'delete_related') { + $ns = ''; + foreach ($vars->entries as $id) { + $ns .= $vars->related . ':' . $id . ';'; + } $vars->cleaners->execute($vars->cleaner->id, $vars->action, $ns); + // other actions + } elseif ($vars->action != 'delete_related') { + foreach ($vars->entries as $ns) { + $vars->cleaners->execute($vars->cleaner->id, $vars->action, $ns); + } } + dcPage::addSuccessNotice(__('Action successfuly excecuted')); dcCore::app()->adminurl?->redirect( 'admin.plugin.' . My::id(), @@ -110,102 +121,169 @@ class Manage extends dcNsProcess # --BEHAVIOR-- dcAdvancedCleanerAdminHeader dcCore::app()->callBehavior('dcAdvancedCleanerAdminHeader'); - echo - dcPage::breadcrumb([ + $breadcrumb = [ __('Plugins') => '', My::name() => '', - ]) . - dcPage::notices(); + ]; + // something went wrong ! if (null === $vars->cleaner) { + echo + dcPage::breadcrumb($breadcrumb) . + dcPage::notices(); echo (new Text('p', __('There is nothing to display')))->class('error')->render(); dcPage::closeModule(); return; } - echo - (new Form('parts_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ - (new Para())->class('anchor-nav')->items([ - (new Label(__('Goto:'), Label::OUTSIDE_LABEL_BEFORE))->for('part')->class('classic'), - (new Select(['part', 'select_part']))->default($vars->cleaner->id)->items($vars->combo), - (new Submit('go'))->value(__('Ok')), - (new Hidden(['p'], My::id())), - ]), - ])->render() . + $breadcrumb[My::name()] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id()); + $breadcrumb[$vars->cleaner->name] = ''; - '
' . $vars->cleaner->desc . '
'; - - $rs = $vars->cleaner->values(); - - if (empty($rs)) { - echo (new Text('p', __('There is nothing to display')))->class('error')->render(); - } else { - $combo_actions = []; - foreach ($vars->cleaner->actions as $descriptor) { - // exception - if ($descriptor->id == 'delete_related') { - continue; - } - $combo_actions[$descriptor->select] = $descriptor->id; - } - - echo - ''; + if (!empty($vars->related)) { + $breadcrumb[$vars->cleaner->name] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => $vars->cleaner->id]); + $breadcrumb[$vars->related] = ''; } echo - (new Form('option'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ - (new Para())->items([ - (new Submit('option-action'))->value(dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide') ? __('Show Dotclear default properties') : __('Hide Dotclear default properties')), - (new Hidden('dcproperty_hide', (string) (int) !dcCore::app()->blog->settings->get(My::id())->get('dcproperty_hide'))), - (new Hidden(['p'], My::id())), - (new Hidden(['part'], $vars->cleaner->id)), - dcCore::app()->formNonce(false), - ]), - ])->render(); + dcPage::breadcrumb($breadcrumb) . + dcPage::notices(); + + if (empty($vars->related)) { + echo + (new Form('parts_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ + (new Para())->class('anchor-nav')->items([ + (new Label(__('Goto:'), Label::OUTSIDE_LABEL_BEFORE))->for('part')->class('classic'), + (new Select(['part', 'select_part']))->default($vars->cleaner->id)->items($vars->combo), + (new Submit('go'))->value(__('Ok')), + (new Hidden(['p'], My::id())), + ]), + ])->render() . + + '' . $vars->cleaner->desc . '
'; + + $rs = $vars->cleaner->values(); + if (empty($rs)) { + echo (new Text('p', __('There is nothing to display')))->class('error')->render(); + } else { + $combo_actions = []; + $has_related = false; + foreach ($vars->cleaner->actions as $descriptor) { + // exception + if ($descriptor->id == 'delete_related') { + $has_related = true; + + continue; + } + $combo_actions[$descriptor->select] = $descriptor->id; + } + + echo + ''; + } + + echo + (new Form('option'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ + (new Para())->items([ + (new Submit('option-action'))->value(dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide') ? __('Show Dotclear default properties') : __('Hide Dotclear default properties')), + (new Hidden('dcproperty_hide', (string) (int) !dcCore::app()->blog->settings->get(My::id())->get('dcproperty_hide'))), + (new Hidden(['p'], My::id())), + (new Hidden(['part'], $vars->cleaner->id)), + dcCore::app()->formNonce(false), + ]), + ])->render(); + } else { + echo + '' . + '' . $vars->cleaner->desc . '
'; + + $distrib = in_array($vars->related, $vars->cleaner->distributed()); + $rs = $vars->cleaner->related($vars->related); + if (empty($rs)) { + echo (new Text('p', __('There is nothing to display')))->class('error')->render(); + } else { + echo + ''; + } + } dcPage::closeModule(); } diff --git a/src/ManageVars.php b/src/ManageVars.php index c1e7129..799ba62 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -30,6 +30,7 @@ class ManageVars public readonly Cleaners $cleaners; public readonly ?AbstractCleaner $cleaner; + public readonly string $related; public readonly array $entries; public readonly string $action; public readonly array $combo; @@ -38,6 +39,7 @@ class ManageVars { $this->cleaners = Uninstaller::instance()->cleaners; + $related = $_REQUEST['related'] ?? ''; $entries = $_REQUEST['entries'] ?? []; $action = $_POST['action'] ?? ''; @@ -50,12 +52,14 @@ class ManageVars } } if ($cleaner === null) { + $related = ''; if (!($cleaner = $this->cleaners->get('caches'))) { throw new Exception(__('Failed to load cleaner')); } } $this->cleaner = $cleaner; + $this->related = $related; $this->entries = is_array($entries) ? $entries : []; $this->action = is_string($action) ? $action : ''; $this->combo = $combo;