diff --git a/CHANGELOG.md b/CHANGELOG.md index 908031b..24adbb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ 0.7.3.1 - dev - [ ] orphan media cleaner - [ ] ajouter dossier /var dans la liste des caches -- [ ] update DC official values (themes,settings,tables...) -- [ ] fix admin design -- [ ] fix php7.3+ and php8.0 -- [ ] fix PSR(1)2 coding style +- [x] update DC official values (themes,settings,tables...) +- [x] fix admin design +- [x] fix php7.3+ and php8.0 +- [x] fix PSR(1)2 coding style - [ ] fix translation - [x] add dcstore (pre release) - [x] update license diff --git a/_config.php b/_config.php index 647f8e6..f2c6f3a 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1,15 @@ activityReport->addAction( diff --git a/inc/lib.dc.advanced.cleaner.behaviors.php b/inc/lib.dc.advanced.cleaner.behaviors.php index f7c095c..a43f2a4 100644 --- a/inc/lib.dc.advanced.cleaner.behaviors.php +++ b/inc/lib.dc.advanced.cleaner.behaviors.php @@ -60,17 +60,16 @@ class behaviorsDcAdvancedCleaner } } - public static function dcAdvancedCleanerAdminTabs($core, $p_url) + public static function dcAdvancedCleanerAdminTabs($core) { - self::modulesTabs($core,DC_PLUGINS_ROOT,$p_url.'&tab=uninstaller'); + self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'uninstaller'])); } public static function pluginsToolsTabs($core) { - self::modulesTabs($core, DC_PLUGINS_ROOT, 'plugins.php?tab=uninstaller'); + self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugins', ['tab' => 'uninstaller'])); } - // Generic module tabs public static function modulesTabs($core, $path, $redir, $title = '') { if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { @@ -119,13 +118,14 @@ class behaviorsDcAdvancedCleaner } } } - http::redirect($redir . '&msg=1'); + dcPage::addSuccessNotice(__('Action successfuly excecuted')); + http::redirect($redir); } catch(Exception $e) { $err = $e->getMessage(); } } - echo '
'; + echo '

' . __($title) . '

'; if($err) { echo '

' . $err . '

'; @@ -214,7 +214,8 @@ class behaviorsDcAdvancedCleaner form::hidden(['action'], 'uninstall') . ' ' . '

' . - '' . - '
'; + ''; + + echo '
'; } } \ No newline at end of file diff --git a/index.php b/index.php index 81461d0..be65f00 100644 --- a/index.php +++ b/index.php @@ -18,107 +18,6 @@ if (!$core->auth->isSuperAdmin()) { return null; } -$page_title = __('Advanced cleaner'); - -# Lists -function drawDcAdvancedCleanerLists($core, $type) -{ - $combo_funcs = [ - 'settings' => ['dcAdvancedCleaner','getSettings'], - 'tables' => ['dcAdvancedCleaner','getTables'], - 'plugins' => ['dcAdvancedCleaner','getPlugins'], - 'themes' => ['dcAdvancedCleaner','getThemes'], - 'caches' => ['dcAdvancedCleaner','getCaches'], - 'versions' => ['dcAdvancedCleaner','getVersions'] - ]; - $combo_actions = [ - 'settings' => [ - __('delete global settings') => 'delete_global', - __('delete blog settings') => 'delete_local', - __('delete all settings') =>'delete_all' - ], - 'tables' => [ - __('delete') => 'delete', - __('empty') => 'empty' - ], - 'plugins' => [ - __('delete') => 'delete', - __('empty') => 'empty' - ], - 'themes' => [ - __('delete') => 'delete', - __('empty') => 'empty' - ], - 'caches' => [ - __('delete') => 'delete', - __('empty') => 'empty' - ], - 'versions' => [ - __('delete') => 'delete' - ] - ]; - $combo_help = [ - 'settings' => __('Namespaces registered in dcSettings'), - 'tables' => __('All database tables of Dotclear'), - 'plugins' => __('Folders from plugins directories'), - 'themes' => __('Folders from blog themes directory'), - 'caches' => __('Folders from cache directory'), - 'versions' => __('Versions registered in table "version" of Dotclear') - ]; - - if (!isset($combo_funcs[$type])) { - return ''; - } - - $rs = call_user_func($combo_funcs[$type], $core); - - echo - '
' . - '

' . $combo_help[$type] . '

'; - - if (empty($rs)) { - echo - '

' . sprintf(__('There is no %s'), __(substr($type, 0, -1))) . '

'; - } else { - echo - '

' . sprintf(__('There are %s %s'), count($rs), __($type)) . '

' . - '
' . - '' . - '' . - ''; - - $official = dcAdvancedCleaner::getOfficial($type); - foreach($rs as $k => $v) { - $offline = in_array($v['key'], $official); - - if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide && $offline) { - continue; - } - echo - '' . - '' . - '' . - ''; - } - echo - '
' . __('Name') . '' . __('Objects') . '
' . $v['value'] . '
' . - '

' . __('Action on selected rows:') . '
' . - form::combo(['action'], $combo_actions[$type]) . - '' . - form::hidden(['p'], 'dcAdvancedCleaner') . - form::hidden(['tab'], 'lists') . - form::hidden(['part'], $type) . - form::hidden(['type'], $type) . - $core->formNonce() . '

' . - '
'; - } - echo - '
'; -} - # Localized l10n __('Settings'); __('settings'); __('setting'); __('Tables'); __('tables'); __('table'); @@ -142,12 +41,12 @@ __('delete %s theme file'); __('delete %s cache files'); # vars -$tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'dcac'; -$part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'caches'; -$entries = isset($_POST['entries']) ? $_POST['entries'] : ''; -$action = isset($_POST['action']) ? $_POST['action'] : ''; -$type = isset($_POST['type']) ? $_POST['type'] : ''; +$tab = $_REQUEST['tab'] ?? 'lists'; +$part = $_REQUEST['part'] ?? 'caches'; +$entries = $_POST['entries'] ?? []; +$action = $_POST['action'] ?? ''; $s = $core->blog->settings->dcAdvancedCleaner; +$p_url = $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]); # Combos $combo_title = [ @@ -158,74 +57,166 @@ $combo_title = [ 'caches' => __('Cache'), 'versions' => __('Versions') ]; - $combo_type = [ - 'settings' => ['delete_global','delete_local','delete_all'], - 'tables' => ['empty','delete'], - 'plugins' => ['empty','delete'], - 'themes' => ['empty','delete'], - 'caches' => ['empty','delete'], + 'settings' => ['delete_global', 'delete_local', 'delete_all'], + 'tables' => ['empty', 'delete'], + 'plugins' => ['empty', 'delete'], + 'themes' => ['empty', 'delete'], + 'caches' => ['empty', 'delete'], 'versions' => ['delete'] ]; +$combo_funcs = [ + 'settings' => ['dcAdvancedCleaner', 'getSettings'], + 'tables' => ['dcAdvancedCleaner', 'getTables'], + 'plugins' => ['dcAdvancedCleaner', 'getPlugins'], + 'themes' => ['dcAdvancedCleaner', 'getThemes'], + 'caches' => ['dcAdvancedCleaner', 'getCaches'], + 'versions' => ['dcAdvancedCleaner', 'getVersions'] +]; +$combo_actions = [ + 'settings' => [ + __('delete global settings') => 'delete_global', + __('delete blog settings') => 'delete_local', + __('delete all settings') =>'delete_all' + ], + 'tables' => [ + __('delete') => 'delete', + __('empty') => 'empty' + ], + 'plugins' => [ + __('delete') => 'delete', + __('empty') => 'empty' + ], + 'themes' => [ + __('delete') => 'delete', + __('empty') => 'empty' + ], + 'caches' => [ + __('delete') => 'delete', + __('empty') => 'empty' + ], + 'versions' => [ + __('delete') => 'delete' + ] +]; +$combo_help = [ + 'settings' => __('Namespaces registered in dcSettings'), + 'tables' => __('All database tables of Dotclear'), + 'plugins' => __('Folders from plugins directories'), + 'themes' => __('Folders from blog themes directory'), + 'caches' => __('Folders from cache directory'), + 'versions' => __('Versions registered in table "version" of Dotclear') +]; # Actions -if ($tab == 'lists' && !empty($entries) - && isset($combo_type[$type]) - && in_array($action,$combo_type[$type])) { - +if ($tab == 'lists' + && !empty($entries) + && isset($combo_type[$part]) + && in_array($action, $combo_type[$part]) +) { try { foreach($entries as $v) { - dcAdvancedCleaner::execute($core, $type, $action, $v); + dcAdvancedCleaner::execute($core, $part, $action, $v); } - dcPage::addSuccessNotice(__('Action successfuly excecuted')); - $core->adminurl->redirect('admin.plugin.dcAdvancedCleaner', ['tab' => 'list', 'part' => $part]); + $core->adminurl->redirect( + 'admin.plugin.dcAdvancedCleaner', + ['tab' => 'lists', 'part' => $part] + ); } catch(Exception $e) { $core->error->add($e->getMessage()); } } -echo ' - -' . $page_title . ' -' . -dcPage::jsToolBar() . -dcPage::jsPageTabs($tab) . ' -'; +echo '' . __('Advanced cleaner') . '' . +dcPage::cssLoad('index.php?pf=dcAdvancedCleaner/style.css') . +dcPage::jsPageTabs($tab); # --BEHAVIOR-- dcAdvancedCleanerAdminHeader -$core->callBehavior('dcAdvancedCleanerAdminHeader', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]), $tab); +$core->callBehavior('dcAdvancedCleanerAdminHeader', $core, $p_url, $tab); -echo ' -' . - dcPage::breadcrumb([ +echo '' . +dcPage::breadcrumb([ html::escapeHTML($core->blog->name) => '', - '' . $page_title . '' => '' - ]); -echo -'

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

'; + '' . __('Advanced cleaner') . '' => '' +]) . +dcPage::notices() . ' +
+

'. __('Records and folders') .'

'; -echo '

' . -'

'; foreach($combo_title as $k => $v) { - echo '' . $v . ' '; + echo sprintf( + '%s', + $core->adminurl->get( + 'admin.plugin.dcAdvancedCleaner', + ['tab' => 'lists', 'part' => $k] + ), + $v + ); } echo '

'; -# Load "part" page -if (isset($combo_title[$part])) { - echo '
' . $combo_title[$part] . ''; - drawDcAdvancedCleanerLists($core, $part); - echo '
'; +if (isset($combo_funcs[$part])) { + echo '

' . $combo_title[$part] . '

' . $combo_help[$part] . '

'; + + $rs = call_user_func($combo_funcs[$part], $core); + + if (empty($rs)) { + echo '

' . sprintf(__('There is no %s'), __(substr($part, 0, -1))) . '

'; + } else { + echo + '

' . sprintf(__('There are %s %s'), count($rs), __($part)) . '

' . + '
' . + '
' . + '' . + '' . + ''; + + $official = dcAdvancedCleaner::getOfficial($part); + foreach($rs as $k => $v) { + $offline = in_array($v['key'], $official); + + if ($s->dcAdvancedCleaner_dcproperty_hide && $offline) { + continue; + } + echo + '' . + '' . + '' . + ''; + } + echo + '
' . __('Name') . '' . __('Objects') . '
' . $v['value'] . '
' . + '

' . __('Action on selected rows:') . ' ' . + form::combo(['action'], $combo_actions[$part]) . + '' . + form::hidden(['p'], 'dcAdvancedCleaner') . + form::hidden(['tab'], 'lists') . + form::hidden(['part'], $part) . + $core->formNonce() . '

' . + '

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

' . + '
'; + } } if ($s->dcAdvancedCleaner_dcproperty_hide) { - echo '

' . __('Default values of Dotclear are hidden. You can change this in settings tab') . '

'; + echo '

' . + __('Default values of Dotclear are hidden. You can change this in settings tab') . + '

'; } + echo '
'; # --BEHAVIOR-- dcAdvancedCleanerAdminTabs -$core->callBehavior('dcAdvancedCleanerAdminTabs', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part])); +$core->callBehavior('dcAdvancedCleanerAdminTabs', $core); dcPage::helpBlock('dcAdvancedCleaner');