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;
|
|
|
|
}
|
|
|
|
if (!$core->auth->isSuperAdmin()) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
$page_title = __('Advanced cleaner');
|
|
|
|
|
|
|
|
# Lists
|
2021-09-07 00:02:48 +00:00
|
|
|
function drawDcAdvancedCleanerLists($core, $type)
|
2018-02-19 18:10:58 +00:00
|
|
|
{
|
2021-09-07 00:02:48 +00:00
|
|
|
$combo_funcs = [
|
|
|
|
'settings' => ['dcAdvancedCleaner','getSettings'],
|
|
|
|
'tables' => ['dcAdvancedCleaner','getTables'],
|
|
|
|
'plugins' => ['dcAdvancedCleaner','getPlugins'],
|
|
|
|
'themes' => ['dcAdvancedCleaner','getThemes'],
|
|
|
|
'caches' => ['dcAdvancedCleaner','getCaches'],
|
|
|
|
'versions' => ['dcAdvancedCleaner','getVersions']
|
|
|
|
];
|
|
|
|
$combo_actions = [
|
|
|
|
'settings' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete global settings') => 'delete_global',
|
|
|
|
__('delete blog settings') => 'delete_local',
|
|
|
|
__('delete all settings') =>'delete_all'
|
2021-09-07 00:02:48 +00:00
|
|
|
],
|
|
|
|
'tables' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete') => 'delete',
|
|
|
|
__('empty') => 'empty'
|
2021-09-07 00:02:48 +00:00
|
|
|
],
|
|
|
|
'plugins' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete') => 'delete',
|
|
|
|
__('empty') => 'empty'
|
2021-09-07 00:02:48 +00:00
|
|
|
],
|
|
|
|
'themes' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete') => 'delete',
|
|
|
|
__('empty') => 'empty'
|
2021-09-07 00:02:48 +00:00
|
|
|
],
|
|
|
|
'caches' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete') => 'delete',
|
|
|
|
__('empty') => 'empty'
|
2021-09-07 00:02:48 +00:00
|
|
|
],
|
|
|
|
'versions' => [
|
2021-09-06 22:09:09 +00:00
|
|
|
__('delete') => 'delete'
|
2021-09-07 00:02:48 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$combo_help = [
|
2021-09-06 22:09:09 +00:00
|
|
|
'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')
|
2021-09-07 00:02:48 +00:00
|
|
|
];
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
if (!isset($combo_funcs[$type])) {
|
|
|
|
return '';
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
$rs = call_user_func($combo_funcs[$type], $core);
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-06 22:09:09 +00:00
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'<div class="listDcAdvancedCleaner">' .
|
|
|
|
'<p class="form-note">' . $combo_help[$type] . '</p>';
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-06 22:09:09 +00:00
|
|
|
if (empty($rs)) {
|
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'<p>' . sprintf(__('There is no %s'), __(substr($type, 0, -1))) . '</p>';
|
2021-09-06 22:09:09 +00:00
|
|
|
} else {
|
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'<p>' . sprintf(__('There are %s %s'), count($rs), __($type)) . '</p>' .
|
|
|
|
'<form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'lists', 'part' => $type]) . '">' .
|
|
|
|
'<table><thead><tr>' .
|
|
|
|
'<th>' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
|
2021-09-06 22:09:09 +00:00
|
|
|
'</tr></thead><tbody>';
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:04:13 +00:00
|
|
|
$official = dcAdvancedCleaner::getOfficial($type);
|
2021-09-07 00:02:48 +00:00
|
|
|
foreach($rs as $k => $v) {
|
2021-09-07 00:04:13 +00:00
|
|
|
$offline = in_array($v['key'], $official);
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide && $offline) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-06 22:09:09 +00:00
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'<tr class="line' .
|
|
|
|
($offline ? ' offline' : '') .
|
|
|
|
'">' .
|
|
|
|
'<td class="nowrap"><label class="classic">' .
|
|
|
|
form::checkbox(['entries[' . $k . ']'], html::escapeHTML($v['key'])) . ' ' . $v['key'] . '</label></td>' .
|
|
|
|
'<td class="nowrap">' . $v['value'] . '</td>' .
|
2021-09-06 22:09:09 +00:00
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'</tbody></table>' .
|
|
|
|
'<p>' . __('Action on selected rows:') . '<br />' .
|
|
|
|
form::combo(['action'], $combo_actions[$type]) .
|
|
|
|
'<input type="submit" value="' . __('save') . '" />' .
|
|
|
|
form::hidden(['p'], 'dcAdvancedCleaner') .
|
|
|
|
form::hidden(['tab'], 'lists') .
|
|
|
|
form::hidden(['part'], $type) .
|
|
|
|
form::hidden(['type'], $type) .
|
|
|
|
$core->formNonce() . '</p>' .
|
2021-09-06 22:09:09 +00:00
|
|
|
'</form>';
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
'<div>';
|
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
|
|
|
|
$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'] : '';
|
|
|
|
$s = $core->blog->settings->dcAdvancedCleaner;
|
|
|
|
|
|
|
|
# Combos
|
2021-09-07 00:02:48 +00:00
|
|
|
$combo_title = [
|
2021-09-06 22:09:09 +00:00
|
|
|
'settings' => __('Settings'),
|
|
|
|
'tables' => __('Tables'),
|
|
|
|
'plugins' => __('Extensions'),
|
|
|
|
'themes' => __('Themes'),
|
|
|
|
'caches' => __('Cache'),
|
|
|
|
'versions' => __('Versions')
|
2021-09-07 00:02:48 +00:00
|
|
|
];
|
2021-09-06 22:09:09 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
$combo_type = [
|
|
|
|
'settings' => ['delete_global','delete_local','delete_all'],
|
|
|
|
'tables' => ['empty','delete'],
|
|
|
|
'plugins' => ['empty','delete'],
|
|
|
|
'themes' => ['empty','delete'],
|
|
|
|
'caches' => ['empty','delete'],
|
|
|
|
'versions' => ['delete']
|
|
|
|
];
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
# This plugin settings
|
2021-09-07 00:02:48 +00:00
|
|
|
if ($tab == 'dcac' && $action == 'dcadvancedcleaner_settings') {
|
2021-09-06 22:09:09 +00:00
|
|
|
try {
|
2021-09-07 00:02:48 +00:00
|
|
|
$s->put('dcAdvancedCleaner_behavior_active', isset($_POST['dcadvancedcleaner_behavior_active']), 'boolean');
|
|
|
|
$s->put('dcAdvancedCleaner_dcproperty_hide', isset($_POST['dcadvancedcleaner_dcproperty_hide']), 'boolean');
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
dcPage::addSuccessNotice(__('Settings successfuly updated'));
|
|
|
|
$core->adminurl->redirect('admin.plugin.dcAdvancedCleaner', ['tab' => 'dcac', 'part' => '']);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Actions
|
|
|
|
if ($tab == 'lists' && !empty($entries)
|
|
|
|
&& isset($combo_type[$type])
|
|
|
|
&& in_array($action,$combo_type[$type])) {
|
|
|
|
|
2021-09-06 22:09:09 +00:00
|
|
|
try {
|
|
|
|
foreach($entries as $v) {
|
2021-09-07 00:02:48 +00:00
|
|
|
dcAdvancedCleaner::execute($core, $type, $action, $v);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
|
|
|
|
$core->adminurl->redirect('admin.plugin.dcAdvancedCleaner', ['tab' => 'list', 'part' => $part]);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<html><head>
|
2021-09-07 00:02:48 +00:00
|
|
|
<title>' . $page_title . '</title>
|
|
|
|
<link rel="stylesheet" type="text/css" href="index.php?pf=dcAdvancedCleaner/style.css" />' .
|
|
|
|
dcPage::jsToolBar() .
|
|
|
|
dcPage::jsPageTabs($tab) . '
|
2018-02-19 18:10:58 +00:00
|
|
|
</style>';
|
|
|
|
|
|
|
|
# --BEHAVIOR-- dcAdvancedCleanerAdminHeader
|
2021-09-07 00:02:48 +00:00
|
|
|
$core->callBehavior('dcAdvancedCleanerAdminHeader', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]), $tab);
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
echo '
|
2021-09-07 00:02:48 +00:00
|
|
|
</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2018-02-19 18:10:58 +00:00
|
|
|
html::escapeHTML($core->blog->name) => '',
|
2021-09-07 00:02:48 +00:00
|
|
|
'<span class="page-title">' . $page_title . '</span>' => ''
|
|
|
|
]);
|
2018-02-19 18:10:58 +00:00
|
|
|
echo
|
2021-09-07 00:02:48 +00:00
|
|
|
'<p class="warning">' . __('Beware: All actions done here are irreversible and are directly applied') . '</p>';
|
2018-02-19 18:10:58 +00:00
|
|
|
|
2021-09-07 00:02:48 +00:00
|
|
|
echo '<div class="multi-part" id="lists" title="' . __('Records and folders') . '">' .
|
2018-02-19 18:10:58 +00:00
|
|
|
'<p>';
|
2021-09-07 00:02:48 +00:00
|
|
|
foreach($combo_title as $k => $v) {
|
|
|
|
echo '<a class="button" href="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'lists', 'part' => $k]) . '">' . $v . '</a> ';
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
|
|
|
echo '</p>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
2018-02-19 18:10:58 +00:00
|
|
|
# Load "part" page
|
2021-09-07 00:02:48 +00:00
|
|
|
if (isset($combo_title[$part])) {
|
|
|
|
echo '<fieldset><legend>' . $combo_title[$part] . '</legend>';
|
|
|
|
drawDcAdvancedCleanerLists($core, $part);
|
2021-09-06 22:09:09 +00:00
|
|
|
echo '</fieldset>';
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
2021-09-07 00:02:48 +00:00
|
|
|
if ($s->dcAdvancedCleaner_dcproperty_hide) {
|
|
|
|
echo '<p class="info">' . __('Default values of Dotclear are hidden. You can change this in settings tab') . '</p>';
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
# --BEHAVIOR-- dcAdvancedCleanerAdminTabs
|
2021-09-07 00:02:48 +00:00
|
|
|
$core->callBehavior('dcAdvancedCleanerAdminTabs', $core, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => $tab, 'part' => $part]));
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
echo '
|
2021-09-07 00:02:48 +00:00
|
|
|
<div class="multi-part" id="dcac" title="' . __('This plugin settings') . '">
|
|
|
|
<fieldset><legend>' . __('This plugin settings') . '</legend>
|
|
|
|
<form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'dcac', 'part' => '']) . '">
|
|
|
|
<p><label class="classic" for="dcadvancedcleaner_behavior_active">' .
|
|
|
|
form::checkbox(
|
|
|
|
'dcadvancedcleaner_behavior_active',
|
|
|
|
1,
|
|
|
|
$s->dcAdvancedCleaner_behavior_active
|
|
|
|
) . __('Activate behaviors') . '</label></p>
|
|
|
|
<p class="form-note">' . __('Enable actions set in _uninstall.php files.') . '</p>
|
|
|
|
<p><label class="classic" for="dcadvancedcleaner_dcproperty_hide">' .
|
|
|
|
form::checkbox(
|
|
|
|
'dcadvancedcleaner_dcproperty_hide',
|
|
|
|
1,
|
|
|
|
$s->dcAdvancedCleaner_dcproperty_hide
|
|
|
|
).
|
|
|
|
__('Hide Dotclear default properties in actions tabs') . '
|
2018-02-19 18:10:58 +00:00
|
|
|
</label></p>
|
2021-09-07 00:02:48 +00:00
|
|
|
<p class="form-note">' . __('Prevent from deleting Dotclear important properties.') . '</p>
|
|
|
|
<p><input type="submit" name="submit" value="' . __('Save') . '" />' .
|
|
|
|
form::hidden(['p'],'dcAdvancedCleaner') .
|
|
|
|
form::hidden(['tab'],'dcac') .
|
|
|
|
form::hidden(['part'],'') .
|
|
|
|
form::hidden(['action'], 'dcadvancedcleaner_settings') .
|
|
|
|
$core->formNonce() . '</p>
|
2018-02-19 18:10:58 +00:00
|
|
|
</form>
|
|
|
|
</fieldset>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
dcPage::helpBlock('dcAdvancedCleaner');
|
2021-09-07 00:02:48 +00:00
|
|
|
|
|
|
|
echo '</body></html>';
|