third pass to clean up code.

master
Jean-Christian Paul Denis 2021-09-07 02:02:48 +02:00
parent 3d158267b5
commit 5529c40922
1 changed files with 125 additions and 132 deletions

257
index.php
View File

@ -11,104 +11,107 @@
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
if (!$core->auth->isSuperAdmin()){return;} }
if (!$core->auth->isSuperAdmin()) {
return null;
}
$page_title = __('Advanced cleaner'); $page_title = __('Advanced cleaner');
# Lists # Lists
function drawDcAdvancedCleanerLists($core,$type) function drawDcAdvancedCleanerLists($core, $type)
{ {
$combo_funcs = array( $combo_funcs = [
'settings' => array('dcAdvancedCleaner','getSettings'), 'settings' => ['dcAdvancedCleaner','getSettings'],
'tables' => array('dcAdvancedCleaner','getTables'), 'tables' => ['dcAdvancedCleaner','getTables'],
'plugins' => array('dcAdvancedCleaner','getPlugins'), 'plugins' => ['dcAdvancedCleaner','getPlugins'],
'themes' => array('dcAdvancedCleaner','getThemes'), 'themes' => ['dcAdvancedCleaner','getThemes'],
'caches' => array('dcAdvancedCleaner','getCaches'), 'caches' => ['dcAdvancedCleaner','getCaches'],
'versions' => array('dcAdvancedCleaner','getVersions') 'versions' => ['dcAdvancedCleaner','getVersions']
); ];
$combo_actions = array( $combo_actions = [
'settings' => array( 'settings' => [
__('delete global settings') => 'delete_global', __('delete global settings') => 'delete_global',
__('delete blog settings') => 'delete_local', __('delete blog settings') => 'delete_local',
__('delete all settings') =>'delete_all' __('delete all settings') =>'delete_all'
), ],
'tables' => array( 'tables' => [
__('delete') => 'delete', __('delete') => 'delete',
__('empty') => 'empty' __('empty') => 'empty'
), ],
'plugins' => array( 'plugins' => [
__('delete') => 'delete', __('delete') => 'delete',
__('empty') => 'empty' __('empty') => 'empty'
), ],
'themes' => array( 'themes' => [
__('delete') => 'delete', __('delete') => 'delete',
__('empty') => 'empty' __('empty') => 'empty'
), ],
'caches' => array( 'caches' => [
__('delete') => 'delete', __('delete') => 'delete',
__('empty') => 'empty' __('empty') => 'empty'
), ],
'versions' => array( 'versions' => [
__('delete') => 'delete' __('delete') => 'delete'
) ]
); ];
$combo_help = array( $combo_help = [
'settings' => __('Namespaces registered in dcSettings'), 'settings' => __('Namespaces registered in dcSettings'),
'tables' => __('All database tables of Dotclear'), 'tables' => __('All database tables of Dotclear'),
'plugins' => __('Folders from plugins directories'), 'plugins' => __('Folders from plugins directories'),
'themes' => __('Folders from blog themes directory'), 'themes' => __('Folders from blog themes directory'),
'caches' => __('Folders from cache directory'), 'caches' => __('Folders from cache directory'),
'versions' => __('Versions registered in table "version" of Dotclear') '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 echo
'<div class="listDcAdvancedCleaner">'. '<div class="listDcAdvancedCleaner">' .
'<p class="form-note">'.$combo_help[$type].'</p>'; '<p class="form-note">' . $combo_help[$type] . '</p>';
if (empty($rs)) { if (empty($rs)) {
echo echo
'<p>'.sprintf(__('There is no %s'),__(substr($type,0,-1))).'</p>'; '<p>' . sprintf(__('There is no %s'), __(substr($type, 0, -1))) . '</p>';
} else { } else {
echo echo
'<p>'.sprintf(__('There are %s %s'),count($rs),__($type)).'</p>'. '<p>' . sprintf(__('There are %s %s'), count($rs), __($type)) . '</p>' .
'<form method="post" action="plugin.php?p=dcAdvancedCleaner&amp;tab=lists&amp;part='.$type.'">'. '<form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'lists', 'part' => $type]) . '">' .
'<table><thead><tr>'. '<table><thead><tr>' .
'<th>'.__('Name').'</th><th>'.__('Objects').'</th>'. '<th>' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
'</tr></thead><tbody>'; '</tr></thead><tbody>';
foreach($rs as $k => $v) foreach($rs as $k => $v) {
{ $offline = in_array($v['key'], dcAdvancedCleaner::$dotclear[$type]);
$offline = in_array($v['key'],dcAdvancedCleaner::$dotclear[$type]);
if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide && $offline) continue;
if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide && $offline) {
continue;
}
echo echo
'<tr class="line'. '<tr class="line' .
($offline ? ' offline' : ''). ($offline ? ' offline' : '') .
'">'. '">' .
'<td class="nowrap"><label class="classic">'. '<td class="nowrap"><label class="classic">' .
form::checkbox(array('entries['.$k.']'),html::escapeHTML($v['key'])).' '.$v['key'].'</label></td>'. form::checkbox(['entries[' . $k . ']'], html::escapeHTML($v['key'])) . ' ' . $v['key'] . '</label></td>' .
'<td class="nowrap">'.$v['value'].'</td>'. '<td class="nowrap">' . $v['value'] . '</td>' .
'</tr>'; '</tr>';
} }
echo echo
'</tbody></table>'. '</tbody></table>' .
'<p>'.__('Action on selected rows:').'<br />'. '<p>' . __('Action on selected rows:') . '<br />' .
form::combo(array('action'),$combo_actions[$type]). form::combo(['action'], $combo_actions[$type]) .
'<input type="submit" value="'.__('ok').'" />'. '<input type="submit" value="' . __('save') . '" />' .
form::hidden(array('p'),'dcAdvancedCleaner'). form::hidden(['p'], 'dcAdvancedCleaner') .
form::hidden(array('tab'),'lists'). form::hidden(['tab'], 'lists') .
form::hidden(array('part'),$type). form::hidden(['part'], $type) .
form::hidden(array('type'),$type). form::hidden(['type'], $type) .
$core->formNonce().'</p>'. $core->formNonce() . '</p>' .
'</form>'; '</form>';
} }
echo echo
@ -138,7 +141,6 @@ __('delete %s theme file');
__('delete %s cache files'); __('delete %s cache files');
# vars # vars
$msg = isset($_GET['msg']) ? true : false;
$tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'dcac'; $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'dcac';
$part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'caches'; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'caches';
$entries = isset($_POST['entries']) ? $_POST['entries'] : ''; $entries = isset($_POST['entries']) ? $_POST['entries'] : '';
@ -147,32 +149,32 @@ $type = isset($_POST['type']) ? $_POST['type'] : '';
$s = $core->blog->settings->dcAdvancedCleaner; $s = $core->blog->settings->dcAdvancedCleaner;
# Combos # Combos
$combo_title = array( $combo_title = [
'settings' => __('Settings'), 'settings' => __('Settings'),
'tables' => __('Tables'), 'tables' => __('Tables'),
'plugins' => __('Extensions'), 'plugins' => __('Extensions'),
'themes' => __('Themes'), 'themes' => __('Themes'),
'caches' => __('Cache'), 'caches' => __('Cache'),
'versions' => __('Versions') 'versions' => __('Versions')
); ];
$combo_type = array( $combo_type = [
'settings' => array('delete_global','delete_local','delete_all'), 'settings' => ['delete_global','delete_local','delete_all'],
'tables' => array('empty','delete'), 'tables' => ['empty','delete'],
'plugins' => array('empty','delete'), 'plugins' => ['empty','delete'],
'themes' => array('empty','delete'), 'themes' => ['empty','delete'],
'caches' => array('empty','delete'), 'caches' => ['empty','delete'],
'versions' => array('delete') 'versions' => ['delete']
); ];
# This plugin settings # This plugin settings
if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings') if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings') {
{
try { try {
$s->put('dcAdvancedCleaner_behavior_active',isset($_POST['dcadvancedcleaner_behavior_active']),'boolean'); $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_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) { catch(Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
@ -186,10 +188,11 @@ if ($tab == 'lists' && !empty($entries)
try { try {
foreach($entries as $v) { 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) { catch(Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
@ -198,85 +201,75 @@ if ($tab == 'lists' && !empty($entries)
echo ' echo '
<html><head> <html><head>
<title>'.$page_title.'</title> <title>' . $page_title . '</title>
<link rel="stylesheet" type="text/css" href="index.php?pf=dcAdvancedCleaner/style.css" />'. <link rel="stylesheet" type="text/css" href="index.php?pf=dcAdvancedCleaner/style.css" />' .
dcPage::jsToolBar(). dcPage::jsToolBar() .
dcPage::jsPageTabs($tab).' dcPage::jsPageTabs($tab) . '
</style>'; </style>';
# --BEHAVIOR-- dcAdvancedCleanerAdminHeader # --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 ' echo '
</head><body>'. </head><body>' .
dcPage::breadcrumb( dcPage::breadcrumb([
array(
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
'<span class="page-title">'.$page_title.'</span>' => '' '<span class="page-title">' . $page_title . '</span>' => ''
)); ]);
echo echo
'<p class="error">'.__('Beware: All actions done here are irreversible and are directly applied').'</p>'; '<p class="warning">' . __('Beware: All actions done here are irreversible and are directly applied') . '</p>';
# Information message echo '<div class="multi-part" id="lists" title="' . __('Records and folders') . '">' .
if (!empty($msg)) {
dcPage::success(__('Action successfully done'));
}
echo '<div class="multi-part" id="lists" title="'.__('Records and folders').'">'.
'<p>'; '<p>';
foreach($combo_title as $k => $v) foreach($combo_title as $k => $v) {
{ echo '<a class="button" href="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'lists', 'part' => $k]) . '">' . $v . '</a> ';
echo '<a class="button" href="'.$p_url.'&amp;tab=lists&part='.$k.'">'.$v.'</a> ';
} }
echo '</p>'; echo '</p>';
# Load "part" page # Load "part" page
if (isset($combo_title[$part])) if (isset($combo_title[$part])) {
{ echo '<fieldset><legend>' . $combo_title[$part] . '</legend>';
echo '<fieldset><legend>'.$combo_title[$part].'</legend>'; drawDcAdvancedCleanerLists($core, $part);
drawDcAdvancedCleanerLists($core,$part);
echo '</fieldset>'; echo '</fieldset>';
} }
if ($s->dcAdvancedCleaner_dcproperty_hide) if ($s->dcAdvancedCleaner_dcproperty_hide) {
{ echo '<p class="info">' . __('Default values of Dotclear are hidden. You can change this in settings tab') . '</p>';
echo '<p class="info">'.__('Default values of Dotclear are hidden. You can change this in settings tab').'</p>';
} }
echo '</div>'; echo '</div>';
# --BEHAVIOR-- dcAdvancedCleanerAdminTabs # --BEHAVIOR-- dcAdvancedCleanerAdminTabs
$core->callBehavior('dcAdvancedCleanerAdminTabs',$core,$p_url); $core->callBehavior('dcAdvancedCleanerAdminTabs', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]));
echo ' echo '
<div class="multi-part" id="dcac" title="'.__('This plugin settings').'"> <div class="multi-part" id="dcac" title="' . __('This plugin settings') . '">
<fieldset><legend>'.__('This plugin settings').'</legend> <fieldset><legend>' . __('This plugin settings') . '</legend>
<form method="post" action="'.$p_url.'&amp;tab=dcac&part="> <form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'dcac', 'part' => '']) . '">
<p><label class="classic" for="dcadvancedcleaner_behavior_active">'. <p><label class="classic" for="dcadvancedcleaner_behavior_active">' .
form::checkbox('dcadvancedcleaner_behavior_active',1, form::checkbox(
$s->dcAdvancedCleaner_behavior_active). 'dcadvancedcleaner_behavior_active',
__('Activate behaviors').'</label></p> 1,
<p class="form-note">'.__('Enable actions set in _uninstall.php files.').'</p> $s->dcAdvancedCleaner_behavior_active
<p><label class="classic" for="dcadvancedcleaner_dcproperty_hide">'. ) . __('Activate behaviors') . '</label></p>
form::checkbox('dcadvancedcleaner_dcproperty_hide',1, <p class="form-note">' . __('Enable actions set in _uninstall.php files.') . '</p>
$s->dcAdvancedCleaner_dcproperty_hide). <p><label class="classic" for="dcadvancedcleaner_dcproperty_hide">' .
__('Hide Dotclear default properties in actions tabs').' form::checkbox(
'dcadvancedcleaner_dcproperty_hide',
1,
$s->dcAdvancedCleaner_dcproperty_hide
).
__('Hide Dotclear default properties in actions tabs') . '
</label></p> </label></p>
<p class="form-note">'.__('Prevent from deleting Dotclear important properties.').'</p> <p class="form-note">' . __('Prevent from deleting Dotclear important properties.') . '</p>
<p><input type="submit" name="submit" value="'.__('Save').'" />'. <p><input type="submit" name="submit" value="' . __('Save') . '" />' .
form::hidden(array('p'),'dcAdvancedCleaner'). form::hidden(['p'],'dcAdvancedCleaner') .
form::hidden(array('tab'),'dcac'). form::hidden(['tab'],'dcac') .
form::hidden(array('part'),''). form::hidden(['part'],'') .
form::hidden(array('action'),'dcadvancedcleaner_settings'). form::hidden(['action'], 'dcadvancedcleaner_settings') .
$core->formNonce().'</p> $core->formNonce() . '</p>
</form> </form>
</fieldset> </fieldset>
</div>'; </div>';
dcPage::helpBlock('dcAdvancedCleaner'); dcPage::helpBlock('dcAdvancedCleaner');
echo '
<hr class="clear"/> echo '</body></html>';
<p class="right">
<a class="button" href="'.$p_url.'&amp;part=dcac">'.__('settings').'</a> -
dcAdvancedCleaner - '.$core->plugins->moduleInfo('dcAdvancedCleaner','version').'&nbsp;
<img alt="dcMiniUrl" src="index.php?pf=dcAdvancedCleaner/icon.png" />
</p>
</body></html>';