From 3352cefc92b6a77b7863c11bef69f792eaf7b6fe Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 24 Apr 2023 13:37:49 +0200 Subject: [PATCH] add namespace related values from Uninstaller 0.6, fix #1 --- src/Manage.php | 244 ++++++++++++++++++++++++++++++--------------- src/ManageVars.php | 4 + 2 files changed, 165 insertions(+), 83 deletions(-) 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->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 - '
' . - '
' . - '' . - '' . - ''; - - foreach ($rs as $k => $v) { - $distrib = in_array($v['key'], $vars->cleaner->distributed()); - - if ($distrib && dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide')) { - continue; - } - echo - '' . - ' ' . - '' . - '' . - '' . - ''; - } - - echo - '
' . sprintf(__('There are %s entries'), count($rs)) . '
' . __('Name') . '' . __('Objects') . '
' . - (new Checkbox(['entries[' . $k . ']', 'entries_' . $k]))->value(Html::escapeHTML($v['key']))->render() . - '' . - (new Label($v['key'], Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $k)->class('classic')->render() . - '' . $v['value'] . '' . ($distrib ? - '' .
-                    __('Values from official distribution') . '' - : '') . '
' . - (new Para())->items([ - (new Label(__('Action on selected rows:'), Label::OUTSIDE_LABEL_BEFORE))->for('select_action'), - (new Select(['action', 'select_action']))->items($combo_actions), - (new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')), - (new Hidden(['p'], My::id())), - (new Hidden(['part'], $vars->cleaner->id)), - dcCore::app()->formNonce(false), - ])->render() . - '

' . - __('Beware: All actions done here are irreversible and are directly applied') . - '

' . - '
'; + 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->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 = []; + $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 + '
' . + '
' . + '' . + '' . + '' . + ''; + + foreach ($rs as $key => $value) { + $distrib = in_array($value->ns, $vars->cleaner->distributed()); + + if ($distrib && dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide')) { + continue; + } + echo + '' . + ' ' . + '' . + '' . + '' . + '' . + ''; + } + + echo + '
' . sprintf(__('There are %s entries'), count($rs)) . '
' . __('Name') . '' . __('Objects') . '
' . + (new Checkbox(['entries[' . $key . ']', 'entries_' . $key]))->value(Html::escapeHTML($value->ns))->render() . + '' . + (new Label($value->ns, Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $key)->class('classic')->render() . + '' . ($value->id != '' ? $value->id : $value->count) . '' . ($distrib ? + '' .
+                        __('Values from official distribution') . '' + : '') . '' . ($has_related ? ' ' . __('Details') . '' : '') . '
' . + (new Para())->items([ + (new Label(__('Action on selected rows:'), Label::OUTSIDE_LABEL_BEFORE))->for('select_action'), + (new Select(['action', 'select_action']))->items($combo_actions), + (new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')), + (new Hidden(['p'], My::id())), + (new Hidden(['part'], $vars->cleaner->id)), + dcCore::app()->formNonce(false), + ])->render() . + '

' . + __('Beware: All actions done here are irreversible and are directly applied') . + '

' . + '
'; + } + + 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 + '

' . __('Back') . '

' . + '

' . $vars->cleaner->name . ' : ' . $vars->related . '

' . $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 + '
' . + '
' . + '' . + '' . + ''; + + foreach ($rs as $key => $value) { + echo + '' . + ' ' . + '' . + '' . + ''; + } + + echo + '
' . sprintf(__('There are %s related entries for the group "%s"'), count($rs), $vars->related) . '
' . __('Name') . '' . __('Objects') . '
' . + (new Checkbox(['entries[' . $key . ']', 'entries_' . $key]))->value(Html::escapeHTML($value->id))->render() . + '' . + (new Label($value->id, Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $key)->class('classic')->render() . + '' . $value->count . '
' . + (new Para())->items([ + (new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')), + (new Hidden(['p'], My::id())), + (new Hidden(['related'], $vars->related)), + (new Hidden(['part'], $vars->cleaner->id)), + (new Hidden(['action'], 'delete_related')), + dcCore::app()->formNonce(false), + ])->render() . + '

' . + __('Beware: All actions done here are irreversible and are directly applied') . + '

' . + '
'; + } + } 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;