menu[dcAdmin::MENU_PLUGINS]->addItem( __('Advanced cleaner'), dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), dcPage::getPF(basename(__DIR__) . '/icon.svg'), preg_match( '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), dcCore::app()->auth->isSuperAdmin() ); dcCore::app()->addBehaviors([ 'adminDashboardFavoritesV2' => function ($favs) { $favs->register(basename(__DIR__), [ 'title' => __('Advanced cleaner'), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), 'small-icon' => dcPage::getPF(basename(__DIR__) . '/icon.svg'), 'large-icon' => dcPage::getPF(basename(__DIR__) . '/icon-big.svg'), //'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); }, 'pluginsToolsTabsV2' => function () { if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->dcAdvancedCleaner_behavior_active) { return null; } $path = DC_PLUGINS_ROOT; $redir = dcCore::app()->adminurl->get('admin.plugins', [], '#uninstaller'); $title = ''; $uninstaller = new dcUninstaller(); $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 ''; }, 'adminModulesListDoActions' => function ($list, $modules, $type) { if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->dcAdvancedCleaner_behavior_active) { return null; } if (!isset($_POST['action']) || $_POST['action'] != 'uninstall' || (empty($_POST['extras']) && empty($_POST['actions'])) ) { return null; } $uninstaller = new dcUninstaller(); $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, $module_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']); } } } dcAdminNotices::addSuccessNotice(__('Action successfuly excecuted')); http::redirect($_POST['redir']); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } }, 'pluginsBeforeDelete' => function ($plugin) { dcAdvancedCleanerModuleBeforeDelete($plugin); }, 'themeBeforeDelete' => function ($theme) { dcAdvancedCleanerModuleBeforeDelete($theme); }, ]); function dcAdvancedCleanerModuleBeforeDelete($module) { if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->dcAdvancedCleaner_behavior_active) { return null; } $done = false; $uninstaller = new dcUninstaller(); $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) { if ('theme' == $module['type']) { dcCore::app()->adminurl->redirect('admin.blog.theme', ['del' => 1]); } else { dcCore::app()->adminurl->redirect('admin.plugins', ['removed' => 1]); } } }