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-06 23:39:52 +00:00
|
|
|
if (!defined('DC_ADMIN_CONTEXT')) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
|
|
|
|
class behaviorsDcAdvancedCleaner
|
|
|
|
{
|
2021-09-06 22:09:09 +00:00
|
|
|
public static function pluginsBeforeDelete($plugin)
|
|
|
|
{
|
2021-09-06 23:39:52 +00:00
|
|
|
self::moduleBeforeDelete($plugin, 'plugins.php?removed=1');
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function themeBeforeDelete($theme)
|
|
|
|
{
|
2021-09-06 23:39:52 +00:00
|
|
|
self::moduleBeforeDelete($theme, 'blog_theme.php?del=1');
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
// Generic module before delete
|
|
|
|
public static function moduleBeforeDelete($module, $redir)
|
2021-09-06 22:09:09 +00:00
|
|
|
{
|
|
|
|
global $core;
|
|
|
|
$done = false;
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-06 22:09:09 +00:00
|
|
|
$uninstaller = new dcUninstaller($core);
|
|
|
|
$uninstaller->loadModule($module['root']);
|
|
|
|
|
|
|
|
$m_callbacks = $uninstaller->getDirectCallbacks($module['id']);
|
|
|
|
$m_actions = $uninstaller->getDirectActions($module['id']);
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
foreach($m_callbacks as $k => $callback) {
|
|
|
|
if (!isset($callback['func']) || !is_callable($callback['func'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
call_user_func($callback['func'], $module);
|
2021-09-06 22:09:09 +00:00
|
|
|
$done = true;
|
|
|
|
}
|
2021-09-06 23:39:52 +00:00
|
|
|
foreach($m_actions as $type => $actions) {
|
|
|
|
foreach($actions as $v) {
|
|
|
|
$uninstaller->execute($type, $v['action'], $v['ns']);
|
2021-09-06 22:09:09 +00:00
|
|
|
$done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($done) {
|
|
|
|
http::redirect($redir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 08:31:22 +00:00
|
|
|
public static function dcAdvancedCleanerAdminTabs($core)
|
2021-09-06 22:09:09 +00:00
|
|
|
{
|
2021-09-07 08:31:22 +00:00
|
|
|
self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugin.dcAdvancedCleaner', ['tab' => 'uninstaller']));
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function pluginsToolsTabs($core)
|
|
|
|
{
|
2021-09-07 08:31:22 +00:00
|
|
|
self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugins', ['tab' => 'uninstaller']));
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
public static function modulesTabs($core, $path, $redir, $title = '')
|
2021-09-06 22:09:09 +00:00
|
|
|
{
|
2021-09-06 23:39:52 +00:00
|
|
|
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-06 22:09:09 +00:00
|
|
|
$err = '';
|
|
|
|
$title = empty($title) ? __('Advanced uninstall') : $title;
|
|
|
|
|
|
|
|
$uninstaller = new dcUninstaller($core);
|
|
|
|
$uninstaller->loadModules($path);
|
|
|
|
$modules = $uninstaller->getModules();
|
|
|
|
$props = $uninstaller->getAllowedProperties();
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
// Execute
|
2021-09-06 22:09:09 +00:00
|
|
|
if (isset($_POST['action']) && $_POST['action'] == 'uninstall'
|
2021-09-06 23:39:52 +00:00
|
|
|
&& (!empty($_POST['extras']) || !empty($_POST['actions']))
|
|
|
|
) {
|
2021-09-06 22:09:09 +00:00
|
|
|
try {
|
2021-09-06 23:39:52 +00:00
|
|
|
// Extras
|
2021-09-06 22:09:09 +00:00
|
|
|
if (!empty($_POST['extras'])) {
|
2021-09-06 23:39:52 +00:00
|
|
|
foreach($_POST['extras'] as $module_id => $extras) {
|
|
|
|
foreach($extras as $k => $sentence) {
|
2021-09-06 22:09:09 +00:00
|
|
|
$extra = @unserialize(@base64_decode($sentence));
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
if (!$extra || !is_callable($extra)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
call_user_func($extra, $modul_id);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-06 23:39:52 +00:00
|
|
|
// Actions
|
2021-09-06 22:09:09 +00:00
|
|
|
if (!empty($_POST['actions'])) {
|
2021-09-06 23:39:52 +00:00
|
|
|
foreach($_POST['actions'] as $module_id => $actions) {
|
|
|
|
foreach($actions as $k => $sentence) {
|
2021-09-06 22:09:09 +00:00
|
|
|
$action = @unserialize(@base64_decode($sentence));
|
|
|
|
|
|
|
|
if (!$action
|
2021-09-06 23:39:52 +00:00
|
|
|
|| !isset($action['type'])
|
|
|
|
|| !isset($action['action'])
|
|
|
|
|| !isset($action['ns'])
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$uninstaller->execute($action['type'], $action['action'], $action['ns']);
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 08:31:22 +00:00
|
|
|
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
|
|
|
|
http::redirect($redir);
|
2021-09-06 23:39:52 +00:00
|
|
|
} catch(Exception $e) {
|
2021-09-06 22:09:09 +00:00
|
|
|
$err = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 08:31:22 +00:00
|
|
|
echo '<div class="multi-part" id="uninstaller" title="' . __($title) . '"><h3>' . __($title) . '</h3>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
if($err) {
|
|
|
|
echo '<p class="error">' . $err . '</p>';
|
|
|
|
}
|
2021-09-06 22:09:09 +00:00
|
|
|
if(!count($modules)) {
|
2021-09-06 23:39:52 +00:00
|
|
|
echo '<p>' . __('There is no module with uninstall features') . '</p></div>';
|
|
|
|
return null;
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
2021-09-06 23:39:52 +00:00
|
|
|
'<p>' . __('List of modules with advanced uninstall features') . '</p>' .
|
|
|
|
'<form method="post" action="' . $redir . '">' .
|
|
|
|
'<table class="clear"><tr>' .
|
|
|
|
'<th>' . __('id') . '</th>' .
|
|
|
|
'<th>' . __('v') . '</th>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
|
|
|
foreach($props as $pro_id => $prop) {
|
2021-09-06 23:39:52 +00:00
|
|
|
echo '<th>' . __($pro_id) . '</th>';
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
echo '<th>' . __('extra') . '</th>' . '</tr>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach($modules as $module_id => $module) {
|
|
|
|
echo
|
2021-09-06 23:39:52 +00:00
|
|
|
'<tr class="line">' .
|
|
|
|
'<td class="nowrap">' . $module_id . '</td>' .
|
|
|
|
'<td class="nowrap">' . $module['version'] . '</td>';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
|
|
|
$actions = $uninstaller->getUserActions($module_id);
|
|
|
|
|
|
|
|
foreach($props as $prop_id => $prop) {
|
|
|
|
echo '<td class="nowrap">';
|
|
|
|
|
|
|
|
if (!isset($actions[$prop_id])) {
|
|
|
|
echo '--</td>';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$j = 0;
|
|
|
|
foreach($actions[$prop_id] as $action_id => $action) {
|
|
|
|
|
2021-09-06 23:39:52 +00:00
|
|
|
if (!isset($props[$prop_id][$action['action']])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$ret = base64_encode(serialize([
|
2021-09-06 22:09:09 +00:00
|
|
|
'type' => $prop_id,
|
2021-09-06 23:39:52 +00:00
|
|
|
'action'=> $action['action'],
|
|
|
|
'ns'=> $action['ns']
|
|
|
|
]));
|
2021-09-06 22:09:09 +00:00
|
|
|
|
|
|
|
echo '<label class="classic">'.
|
2021-09-06 23:39:52 +00:00
|
|
|
form::checkbox(['actions[' . $module_id . '][' . $j . ']'], $ret) .
|
|
|
|
' ' . $action['desc'] . '</label><br />';
|
2021-09-06 22:09:09 +00:00
|
|
|
|
|
|
|
$j++;
|
|
|
|
}
|
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<td class="nowrap">';
|
|
|
|
|
|
|
|
$callbacks = $uninstaller->getUserCallbacks($module_id);
|
|
|
|
|
|
|
|
if (empty($callbacks)) {
|
|
|
|
echo '--';
|
|
|
|
}
|
|
|
|
|
|
|
|
$k = 0;
|
|
|
|
foreach($callbacks as $callback_id => $callback) {
|
|
|
|
|
|
|
|
$ret = base64_encode(serialize($callback['func']));
|
|
|
|
|
|
|
|
echo '<label class="classic">'.
|
2021-09-06 23:39:52 +00:00
|
|
|
form::checkbox(['extras[' . $module_id . '][' . $k . ']'], $ret) .
|
|
|
|
' ' . $callback['desc'] . '</label><br />';
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '</td></tr>';
|
|
|
|
}
|
|
|
|
echo
|
2021-09-06 23:39:52 +00:00
|
|
|
'</table>' .
|
|
|
|
'<p>' .
|
|
|
|
$core->formNonce() .
|
|
|
|
form::hidden(['redir'], $redir) .
|
|
|
|
form::hidden(['action'], 'uninstall') .
|
|
|
|
'<input type="submit" name="submit" value="' . __('Perform selected actions') . '" /> ' .
|
|
|
|
'</p>' .
|
2021-09-07 08:31:22 +00:00
|
|
|
'</form>';
|
|
|
|
|
|
|
|
echo '</div>';
|
2021-09-06 22:09:09 +00:00
|
|
|
}
|
2018-02-19 18:10:58 +00:00
|
|
|
}
|