From 5529c4092255d44074d848b8e37c4e243af42b5a Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 7 Sep 2021 02:02:48 +0200 Subject: [PATCH] third pass to clean up code. --- index.php | 257 ++++++++++++++++++++++++++---------------------------- 1 file changed, 125 insertions(+), 132 deletions(-) diff --git a/index.php b/index.php index c072416..3174c99 100644 --- a/index.php +++ b/index.php @@ -11,104 +11,107 @@ * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')){return;} - -if (!$core->auth->isSuperAdmin()){return;} +if (!defined('DC_CONTEXT_ADMIN')) { + return null; +} +if (!$core->auth->isSuperAdmin()) { + return null; +} $page_title = __('Advanced cleaner'); # Lists -function drawDcAdvancedCleanerLists($core,$type) +function drawDcAdvancedCleanerLists($core, $type) { - $combo_funcs = array( - 'settings' => array('dcAdvancedCleaner','getSettings'), - 'tables' => array('dcAdvancedCleaner','getTables'), - 'plugins' => array('dcAdvancedCleaner','getPlugins'), - 'themes' => array('dcAdvancedCleaner','getThemes'), - 'caches' => array('dcAdvancedCleaner','getCaches'), - 'versions' => array('dcAdvancedCleaner','getVersions') - ); - $combo_actions = array( - 'settings' => array( + $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' => array( + ], + 'tables' => [ __('delete') => 'delete', __('empty') => 'empty' - ), - 'plugins' => array( + ], + 'plugins' => [ __('delete') => 'delete', __('empty') => 'empty' - ), - 'themes' => array( + ], + 'themes' => [ __('delete') => 'delete', __('empty') => 'empty' - ), - 'caches' => array( + ], + 'caches' => [ __('delete') => 'delete', __('empty') => 'empty' - ), - 'versions' => array( + ], + 'versions' => [ __('delete') => 'delete' - ) - ); - $combo_help = array( + ] + ]; + $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 ''; + if (!isset($combo_funcs[$type])) { + return ''; + } - $rs = call_user_func($combo_funcs[$type],$core); + $rs = call_user_func($combo_funcs[$type], $core); echo - '
'. - '

'.$combo_help[$type].'

'; + '
' . + '

' . $combo_help[$type] . '

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

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

'; + '

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

'; } else { - echo - '

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

'. - '
'. - ''. - ''. + '

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

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

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

'. + '' . + '

' . __('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 @@ -138,7 +141,6 @@ __('delete %s theme file'); __('delete %s cache files'); # vars -$msg = isset($_GET['msg']) ? true : false; $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'dcac'; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'caches'; $entries = isset($_POST['entries']) ? $_POST['entries'] : ''; @@ -147,32 +149,32 @@ $type = isset($_POST['type']) ? $_POST['type'] : ''; $s = $core->blog->settings->dcAdvancedCleaner; # Combos -$combo_title = array( +$combo_title = [ 'settings' => __('Settings'), 'tables' => __('Tables'), 'plugins' => __('Extensions'), 'themes' => __('Themes'), 'caches' => __('Cache'), 'versions' => __('Versions') -); +]; -$combo_type = array( - 'settings' => array('delete_global','delete_local','delete_all'), - 'tables' => array('empty','delete'), - 'plugins' => array('empty','delete'), - 'themes' => array('empty','delete'), - 'caches' => array('empty','delete'), - 'versions' => array('delete') -); +$combo_type = [ + 'settings' => ['delete_global','delete_local','delete_all'], + 'tables' => ['empty','delete'], + 'plugins' => ['empty','delete'], + 'themes' => ['empty','delete'], + 'caches' => ['empty','delete'], + 'versions' => ['delete'] +]; # This plugin settings -if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings') -{ +if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings') { try { - $s->put('dcAdvancedCleaner_behavior_active',isset($_POST['dcadvancedcleaner_behavior_active']),'boolean'); - $s->put('dcAdvancedCleaner_dcproperty_hide',isset($_POST['dcadvancedcleaner_dcproperty_hide']),'boolean'); + $s->put('dcAdvancedCleaner_behavior_active', isset($_POST['dcadvancedcleaner_behavior_active']), 'boolean'); + $s->put('dcAdvancedCleaner_dcproperty_hide', isset($_POST['dcadvancedcleaner_dcproperty_hide']), 'boolean'); - http::redirect($p_url.'&tab=dcac&part=dcac&part=&msg=done'); + dcPage::addSuccessNotice(__('Settings successfuly updated')); + $core->adminurl->redirect('admin.plugin.dcAdvancedCleaner', ['tab' => 'dcac', 'part' => '']); } catch(Exception $e) { $core->error->add($e->getMessage()); @@ -186,10 +188,11 @@ if ($tab == 'lists' && !empty($entries) try { foreach($entries as $v) { - dcAdvancedCleaner::execute($core,$type,$action,$v); + dcAdvancedCleaner::execute($core, $type, $action, $v); } - http::redirect($p_url.'&tab=lists&part='.$part.'&msg=done'); + dcPage::addSuccessNotice(__('Action successfuly excecuted')); + $core->adminurl->redirect('admin.plugin.dcAdvancedCleaner', ['tab' => 'list', 'part' => $part]); } catch(Exception $e) { $core->error->add($e->getMessage()); @@ -198,85 +201,75 @@ if ($tab == 'lists' && !empty($entries) echo ' -'.$page_title.' -'. -dcPage::jsToolBar(). -dcPage::jsPageTabs($tab).' +' . $page_title . ' +' . +dcPage::jsToolBar() . +dcPage::jsPageTabs($tab) . ' '; # --BEHAVIOR-- dcAdvancedCleanerAdminHeader -$core->callBehavior('dcAdvancedCleanerAdminHeader',$core,$p_url,$tab); +$core->callBehavior('dcAdvancedCleanerAdminHeader', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]), $tab); echo ' -'. - dcPage::breadcrumb( - array( +' . + dcPage::breadcrumb([ html::escapeHTML($core->blog->name) => '', - ''.$page_title.'' => '' - )); + '' . $page_title . '' => '' + ]); echo -'

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

'; +'

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

'; -# Information message -if (!empty($msg)) { - dcPage::success(__('Action successfully done')); -} - -echo '
'. +echo '
' . '

'; -foreach($combo_title as $k => $v) -{ - echo ''.$v.' '; +foreach($combo_title as $k => $v) { + echo '' . $v . ' '; } echo '

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

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

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

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

'; } echo '
'; # --BEHAVIOR-- dcAdvancedCleanerAdminTabs -$core->callBehavior('dcAdvancedCleanerAdminTabs',$core,$p_url); +$core->callBehavior('dcAdvancedCleanerAdminTabs', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part])); echo ' -
-
'.__('This plugin settings').' -
-

-

'.__('Enable actions set in _uninstall.php files.').'

-

+
' . __('This plugin settings') . ' + +

+

' . __('Enable actions set in _uninstall.php files.') . '

+

-

'.__('Prevent from deleting Dotclear important properties.').'

-

'. -form::hidden(array('p'),'dcAdvancedCleaner'). -form::hidden(array('tab'),'dcac'). -form::hidden(array('part'),''). -form::hidden(array('action'),'dcadvancedcleaner_settings'). -$core->formNonce().'

+

' . __('Prevent from deleting Dotclear important properties.') . '

+

' . +form::hidden(['p'],'dcAdvancedCleaner') . +form::hidden(['tab'],'dcac') . +form::hidden(['part'],'') . +form::hidden(['action'], 'dcadvancedcleaner_settings') . +$core->formNonce() . '

'; dcPage::helpBlock('dcAdvancedCleaner'); -echo ' -
-

-'.__('settings').' - -dcAdvancedCleaner - '.$core->plugins->moduleInfo('dcAdvancedCleaner','version').'  -dcMiniUrl -

-'; \ No newline at end of file + +echo ''; \ No newline at end of file