register('dcAdvancedCleaner', [ 'title' => __('Advanced cleaner'), 'url' => $core->adminurl->get('admin.plugin.dcAdvancedCleaner'), 'small-icon' => dcPage::getPF('dcAdvancedCleaner/icon.png'), 'large-icon' => dcPage::getPF('dcAdvancedCleaner/icon-big.png'), 'permissions' => $core->auth->isSuperAdmin() ]); } public static function pluginsBeforeDelete($plugin) { self::moduleBeforeDelete($plugin, 'plugins.php?removed=1'); } public static function themeBeforeDelete($theme) { self::moduleBeforeDelete($theme, 'blog_theme.php?del=1'); } // Generic module before delete public static function moduleBeforeDelete($module, $redir) { global $core; $done = false; if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { return null; } $uninstaller = new dcUninstaller($core); $uninstaller->loadModule($module['root']); $m_callbacks = $uninstaller->getDirectCallbacks($module['id']); $m_actions = $uninstaller->getDirectActions($module['id']); foreach ($m_callbacks as $k => $callback) { if (!isset($callback['func']) || !is_callable($callback['func'])) { continue; } call_user_func($callback['func'], $module); $done = true; } foreach ($m_actions as $type => $actions) { foreach ($actions as $v) { $uninstaller->execute($type, $v['action'], $v['ns']); $done = true; } } if ($done) { http::redirect($redir); } } public static function pluginsToolsTabs($core) { self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugins') . '#uninstaller'); } public static function modulesTabs($core, $path, $redir, $title = '') { if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { return null; } $title = empty($title) ? __('Advanced uninstall') : $title; $uninstaller = new dcUninstaller($core); $uninstaller->loadModules($path); $modules = $uninstaller->getModules(); $props = $uninstaller->getAllowedActions(); echo '
' . __('There is no module with uninstall features') . '
' . __('List of modules with advanced uninstall features') . '
' . ''; echo ''; } public static function adminModulesListDoActions($list, $modules, $type) { if (!$list->core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { return null; } if (!isset($_POST['action']) || $_POST['action'] != 'uninstall' || (empty($_POST['extras']) && empty($_POST['actions'])) ) { return null; } $uninstaller = new dcUninstaller($list->core); $uninstaller->loadModules($_POST['path']); $modules = $uninstaller->getModules(); $props = $uninstaller->getAllowedActions(); try { // Extras if (!empty($_POST['extras'])) { foreach ($_POST['extras'] as $module_id => $extras) { foreach ($extras as $k => $sentence) { $extra = @unserialize(@base64_decode($sentence)); if (!$extra || !is_callable($extra)) { continue; } call_user_func($extra, $modul_id); } } } // Actions if (!empty($_POST['actions'])) { foreach ($_POST['actions'] as $module_id => $actions) { foreach ($actions as $k => $sentence) { $action = @unserialize(@base64_decode($sentence)); if (!$action || !isset($action['type']) || !isset($action['action']) || !isset($action['ns']) ) { continue; } $uninstaller->execute($action['type'], $action['action'], $action['ns']); } } } dcPage::addSuccessNotice(__('Action successfuly excecuted')); http::redirect($_POST['redir']); } catch (Exception $e) { $list->core->error->add($e->getMessage()); } } }