2018-02-19 18:10:58 +00:00
|
|
|
<?php
|
2021-09-06 22:09:09 +00:00
|
|
|
/**
|
|
|
|
* @brief dcAdvancedCleaner, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis and Contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-26 22:10:42 +00:00
|
|
|
|
|
|
|
dcPage::checkSuper();
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
# Localized l10n
|
|
|
|
__('Settings'); __('settings'); __('setting');
|
|
|
|
__('Tables'); __('tables'); __('table');
|
|
|
|
__('Plugins'); __('plugins'); __('plugin');
|
|
|
|
__('Themes'); __('themes'); __('theme');
|
|
|
|
__('Caches'); __('caches'); __('cache');
|
|
|
|
__('Versions'); __('versions'); __('version');
|
|
|
|
__('delete table');
|
|
|
|
__('delete cache files');
|
|
|
|
__('delete plugin files');
|
|
|
|
__('delete theme files');
|
|
|
|
__('delete the version number');
|
|
|
|
__('Uninstall extensions');
|
|
|
|
__('delete %s blog settings');
|
|
|
|
__('delete %s global settings');
|
|
|
|
__('delete all %s settings');
|
|
|
|
__('delete %s table');
|
|
|
|
__('delete %s version number');
|
|
|
|
__('delete %s plugin files');
|
|
|
|
__('delete %s theme file');
|
|
|
|
__('delete %s cache files');
|
|
|
|
|
|
|
|
# vars
|
2021-10-26 22:10:42 +00:00
|
|
|
$part = $_REQUEST['part'] ?? 'caches';
|
2021-09-07 08:31:22 +00:00
|
|
|
$entries = $_POST['entries'] ?? [];
|
2021-10-26 22:10:42 +00:00
|
|
|
$action = $_POST['action'] ?? '';
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
# Combos
|
2021-09-07 00:02:48 +00:00
|
|
|
$combo_title = [
|
2021-09-06 22:09:09 +00:00
|
|
|
'settings' => __('Settings'),
|
2021-10-26 22:10:42 +00:00
|
|
|
'tables' => __('Tables'),
|
|
|
|
'plugins' => __('Extensions'),
|
|
|
|
'themes' => __('Themes'),
|
|
|
|
'caches' => __('Cache'),
|
2021-09-06 22:09:09 +00:00
|
|
|
'versions' => __('Versions')
|
2021-09-07 00:02:48 +00:00
|
|
|
];
|
|
|
|
$combo_type = [
|
2021-09-07 08:31:22 +00:00
|
|
|
'settings' => ['delete_global', 'delete_local', 'delete_all'],
|
2021-10-26 22:10:42 +00:00
|
|
|
'tables' => ['empty', 'delete'],
|
|
|
|
'plugins' => ['empty', 'delete'],
|
|
|
|
'themes' => ['empty', 'delete'],
|
|
|
|
'caches' => ['empty', 'delete'],
|
2021-09-07 00:02:48 +00:00
|
|
|
'versions' => ['delete']
|
|
|
|
];
|
2021-09-07 08:31:22 +00:00
|
|
|
$combo_funcs = [
|
|
|
|
'settings' => ['dcAdvancedCleaner', 'getSettings'],
|
2021-10-26 22:10:42 +00:00
|
|
|
'tables' => ['dcAdvancedCleaner', 'getTables'],
|
|
|
|
'plugins' => ['dcAdvancedCleaner', 'getPlugins'],
|
|
|
|
'themes' => ['dcAdvancedCleaner', 'getThemes'],
|
|
|
|
'caches' => ['dcAdvancedCleaner', 'getCaches'],
|
2021-09-07 08:31:22 +00:00
|
|
|
'versions' => ['dcAdvancedCleaner', 'getVersions']
|
|
|
|
];
|
|
|
|
$combo_actions = [
|
|
|
|
'settings' => [
|
|
|
|
__('delete global settings') => 'delete_global',
|
2021-10-26 22:10:42 +00:00
|
|
|
__('delete blog settings') => 'delete_local',
|
|
|
|
__('delete all settings') =>'delete_all'
|
2021-09-07 08:31:22 +00:00
|
|
|
],
|
2021-10-26 22:10:42 +00:00
|
|
|
'tables' => [
|
2021-09-07 08:31:22 +00:00
|
|
|
__('delete') => 'delete',
|
2021-10-26 22:10:42 +00:00
|
|
|
__('empty') => 'empty'
|
2021-09-07 08:31:22 +00:00
|
|
|
],
|
2021-10-26 22:10:42 +00:00
|
|
|
'plugins' => [
|
2021-09-07 08:31:22 +00:00
|
|
|
__('delete') => 'delete',
|
2021-10-26 22:10:42 +00:00
|
|
|
__('empty') => 'empty'
|
2021-09-07 08:31:22 +00:00
|
|
|
],
|
2021-10-26 22:10:42 +00:00
|
|
|
'themes' => [
|
2021-09-07 08:31:22 +00:00
|
|
|
__('delete') => 'delete',
|
2021-10-26 22:10:42 +00:00
|
|
|
__('empty') => 'empty'
|
2021-09-07 08:31:22 +00:00
|
|
|
],
|
2021-10-26 22:10:42 +00:00
|
|
|
'caches' => [
|
2021-09-07 08:31:22 +00:00
|
|
|
__('delete') => 'delete',
|
2021-10-26 22:10:42 +00:00
|
|
|
__('empty') => 'empty'
|
2021-09-07 08:31:22 +00:00
|
|
|
],
|
|
|
|
'versions' => [
|
|
|
|
__('delete') => 'delete'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$combo_help = [
|
|
|
|
'settings' => __('Namespaces registered in dcSettings'),
|
2021-10-26 22:10:42 +00:00
|
|
|
'tables' => __('All database tables of Dotclear'),
|
|
|
|
'plugins' => __('Folders from plugins directories'),
|
|
|
|
'themes' => __('Folders from blog themes directory'),
|
|
|
|
'caches' => __('Folders from cache directory'),
|
2021-09-07 08:31:22 +00:00
|
|
|
'versions' => __('Versions registered in table "version" of Dotclear')
|
|
|
|
];
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
# Actions
|
2021-10-26 22:10:42 +00:00
|
|
|
if (!empty($entries)
|
2021-09-07 08:31:22 +00:00
|
|
|
&& isset($combo_type[$part])
|
|
|
|
&& in_array($action, $combo_type[$part])
|
|
|
|
) {
|
2021-09-06 22:09:09 +00:00
|
|
|
try {
|
|
|
|
foreach($entries as $v) {
|
2021-09-07 08:31:22 +00:00
|
|
|
dcAdvancedCleaner::execute($core, $part, $action, $v);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
2021-09-07 00:02:48 +00:00
|
|
|
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
|
2021-09-07 08:31:22 +00:00
|
|
|
$core->adminurl->redirect(
|
|
|
|
'admin.plugin.dcAdvancedCleaner',
|
2021-10-26 22:10:42 +00:00
|
|
|
['part' => $part]
|
2021-09-07 08:31:22 +00:00
|
|
|
);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 08:31:22 +00:00
|
|
|
echo '<html><head><title>' . __('Advanced cleaner') . '</title>' .
|
2021-10-26 22:10:42 +00:00
|
|
|
dcPage::cssLoad(dcPage::getPF('dcAdvancedCleaner/style.css')) .
|
|
|
|
dcPage::jsLoad(dcPage::getPF('dcAdvancedCleaner/js/index.js'));
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
# --BEHAVIOR-- dcAdvancedCleanerAdminHeader
|
2021-10-26 22:10:42 +00:00
|
|
|
$core->callBehavior('dcAdvancedCleanerAdminHeader', $core);
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 08:31:22 +00:00
|
|
|
echo '</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2021-10-26 22:10:42 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Advanced cleaner') => ''
|
2021-09-07 08:31:22 +00:00
|
|
|
]) .
|
2021-10-26 22:10:42 +00:00
|
|
|
dcPage::notices();
|
|
|
|
|
|
|
|
# select menu list
|
|
|
|
echo
|
|
|
|
'<form method="get" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="parts_menu">' .
|
|
|
|
'<p class="anchor-nav"><label for="part" class="classic">' . __('Goto:') . ' </label>' .
|
|
|
|
form::combo('part', array_flip($combo_title), $part) . ' ' .
|
|
|
|
'<input type="submit" value="' . __('Ok') . '" />' .
|
|
|
|
form::hidden('p', 'dcAdvancedCleaner') . '</p>' .
|
|
|
|
'</form>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
2021-09-07 08:31:22 +00:00
|
|
|
if (isset($combo_funcs[$part])) {
|
2021-10-26 22:10:42 +00:00
|
|
|
echo '<h3>' . $combo_title[$part] . '</h3><p>' . $combo_help[$part] . '</p>';
|
2021-09-07 08:31:22 +00:00
|
|
|
|
|
|
|
$rs = call_user_func($combo_funcs[$part], $core);
|
|
|
|
|
|
|
|
if (empty($rs)) {
|
|
|
|
echo '<p>' . sprintf(__('There is no %s'), __(substr($part, 0, -1))) . '</p>';
|
|
|
|
} else {
|
|
|
|
echo
|
2021-10-26 22:10:42 +00:00
|
|
|
'<form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="form-funcs">' .
|
2021-09-07 08:31:22 +00:00
|
|
|
'<div class="table-outer">' .
|
2021-10-26 22:10:42 +00:00
|
|
|
'<table><caption>' . sprintf(__('There are %s %s'), count($rs), __($part)) . '</caption><thead><tr>' .
|
|
|
|
'<th colspan="2">' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
|
2021-09-07 08:31:22 +00:00
|
|
|
'</tr></thead><tbody>';
|
|
|
|
|
|
|
|
$official = dcAdvancedCleaner::getOfficial($part);
|
|
|
|
foreach($rs as $k => $v) {
|
|
|
|
$offline = in_array($v['key'], $official);
|
|
|
|
|
2021-10-26 22:10:42 +00:00
|
|
|
if ($offline && $core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) {
|
2021-09-07 08:31:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo
|
2021-10-26 22:10:42 +00:00
|
|
|
'<tr class="line' . ($offline ? ' offline' : '') . '">' .
|
|
|
|
'<td class="nowrap">' .
|
|
|
|
form::checkbox(
|
|
|
|
['entries[' . $k . ']', 'entries_' . $k],
|
|
|
|
html::escapeHTML($v['key'])
|
|
|
|
) . '</td> ' .
|
|
|
|
'<td class="nowrap"><label for="entries_' . $k . '" class="classic">' . $v['key'] . '</label></td>' .
|
|
|
|
'<td class="nowrap maximal">' . $v['value'] . '</td>' .
|
2021-09-07 08:31:22 +00:00
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
'</tbody></table></div>' .
|
|
|
|
'<p class="field">' . __('Action on selected rows:') . ' ' .
|
|
|
|
form::combo(['action'], $combo_actions[$part]) .
|
2021-10-26 22:10:42 +00:00
|
|
|
'<input id="do-action" type="submit" value="' . __('ok') . '" />' .
|
2021-09-07 08:31:22 +00:00
|
|
|
form::hidden(['p'], 'dcAdvancedCleaner') .
|
|
|
|
form::hidden(['part'], $part) .
|
|
|
|
$core->formNonce() . '</p>' .
|
|
|
|
'<p class="info">' .
|
|
|
|
__('Beware: All actions done here are irreversible and are directly applied') .
|
|
|
|
'</p>' .
|
|
|
|
'</form>';
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
2021-10-26 22:10:42 +00:00
|
|
|
if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) {
|
2021-09-07 08:31:22 +00:00
|
|
|
echo '<p class="info">' .
|
2021-10-26 22:10:42 +00:00
|
|
|
__('Default values of Dotclear are hidden. You can change this in settings') .
|
2021-09-07 08:31:22 +00:00
|
|
|
'</p>';
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
2021-09-07 08:31:22 +00:00
|
|
|
|
2018-02-19 18:10:58 +00:00
|
|
|
dcPage::helpBlock('dcAdvancedCleaner');
|
2021-09-07 00:02:48 +00:00
|
|
|
|
|
|
|
echo '</body></html>';
|