second pass to clean up code
This commit is contained in:
parent
bbdd672463
commit
3d158267b5
27
_admin.php
27
_admin.php
@ -11,25 +11,30 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')){return;}
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$_menu['Plugins']->addItem(
|
||||
__('Advanced cleaner'),
|
||||
'plugin.php?p=dcAdvancedCleaner',
|
||||
'index.php?pf=dcAdvancedCleaner/icon.png',
|
||||
preg_match('/plugin.php\?p=dcAdvancedCleaner(&.*)?$/',$_SERVER['REQUEST_URI']),
|
||||
$core->adminurl->get('admin.plugin.dcAdvancedCleaner'),
|
||||
dcPage::getPF('dcAdvancedCleaner/icon.png'),
|
||||
preg_match(
|
||||
'/' . preg_quote($core->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/',
|
||||
$_SERVER['REQUEST_URI']
|
||||
),
|
||||
$core->auth->isSuperAdmin()
|
||||
);
|
||||
|
||||
$core->addBehavior('adminDashboardFavorites', 'dcAdvancedCleanerDashboardFavorites');
|
||||
|
||||
function dcAdvancedCleanerDashboardFavorites($core,$favs)
|
||||
function dcAdvancedCleanerDashboardFavorites(dcCore $core, $favs)
|
||||
{
|
||||
$favs->register('dcAdvancedCleaner', array(
|
||||
$favs->register('dcAdvancedCleaner', [
|
||||
'title' => __('Advanced cleaner'),
|
||||
'url' => 'plugin.php?p=dcAdvancedCleaner',
|
||||
'small-icon' => 'index.php?pf=dcAdvancedCleaner/icon.png',
|
||||
'large-icon' => 'index.php?pf=dcAdvancedCleaner/icon-big.png',
|
||||
'permissions' => 'usage,contentadmin'
|
||||
));
|
||||
'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()
|
||||
]);
|
||||
}
|
43
_install.php
43
_install.php
@ -11,36 +11,41 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')){return;}
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
# Get new version
|
||||
$new_version = $core->plugins->moduleInfo('dcAdvancedCleaner', 'version');
|
||||
$old_version = $core->getVersion('dcAdvancedCleaner');
|
||||
|
||||
# Compare versions
|
||||
if (version_compare($old_version,$new_version,'>=')) {return;}
|
||||
|
||||
# Install or update
|
||||
try
|
||||
{
|
||||
# Check DC version
|
||||
if (version_compare(str_replace("-r","-p",DC_VERSION),'2.2-alpha','<'))
|
||||
{
|
||||
throw new Exception('dcAdvancedCleaner requires Dotclear 2.2');
|
||||
if (version_compare($old_version, $new_version, '>=')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
# Settings
|
||||
try {
|
||||
$core->blog->settings->addNamespace('dcAdvancedCleaner');
|
||||
$core->blog->settings->dcAdvancedCleaner->put('dcAdvancedCleaner_behavior_active',true,'boolean','',false,true);
|
||||
$core->blog->settings->dcAdvancedCleaner->put('dcAdvancedCleaner_dcproperty_hide',true,'boolean','',false,true);
|
||||
|
||||
# Version
|
||||
$core->blog->settings->dcAdvancedCleaner->put(
|
||||
'dcAdvancedCleaner_behavior_active',
|
||||
true,
|
||||
'boolean',
|
||||
'',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$core->blog->settings->dcAdvancedCleaner->put(
|
||||
'dcAdvancedCleaner_dcproperty_hide',
|
||||
true,
|
||||
'boolean',
|
||||
'',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$core->setVersion('dcAdvancedCleaner', $new_version);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
return false;
|
||||
}
|
43
_prepend.php
43
_prepend.php
@ -11,41 +11,28 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) return;
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$d = dirname(__FILE__) . '/inc/';
|
||||
|
||||
global $__autoload, $core;
|
||||
$core->blog->settings->addNamespace('dcAdvancedCleaner');
|
||||
|
||||
# Main class
|
||||
$__autoload['dcAdvancedCleaner'] =
|
||||
dirname(__FILE__).'/inc/class.dc.advanced.cleaner.php';
|
||||
$__autoload['dcAdvancedCleaner'] = $d . 'class.dc.advanced.cleaner.php';
|
||||
$__autoload['behaviorsDcAdvancedCleaner'] = $d . 'lib.dc.advanced.cleaner.behaviors.php';
|
||||
$__autoload['dcUninstaller'] = $d . 'class.dc.uninstaller.php';
|
||||
$__autoload['dcAdvancedCleanerActivityReportBehaviors'] = $d . 'lib.dc.advanced.cleaner.activityreport.php';
|
||||
|
||||
# Behaviors class
|
||||
$__autoload['behaviorsDcAdvancedCleaner'] =
|
||||
dirname(__FILE__).'/inc/lib.dc.advanced.cleaner.behaviors.php';
|
||||
|
||||
# Unsintaller class
|
||||
$__autoload['dcUninstaller'] =
|
||||
dirname(__FILE__).'/inc/class.dc.uninstaller.php';
|
||||
|
||||
# Add tab on plugin admin page
|
||||
$core->addBehavior('pluginsToolsTabs',
|
||||
array('behaviorsDcAdvancedCleaner','pluginsToolsTabs'));
|
||||
|
||||
# Action on plugin deletion
|
||||
['behaviorsDcAdvancedCleaner', 'pluginsToolsTabs']);
|
||||
$core->addBehavior('pluginsBeforeDelete',
|
||||
array('behaviorsDcAdvancedCleaner','pluginsBeforeDelete'));
|
||||
|
||||
# Action on theme deletion
|
||||
['behaviorsDcAdvancedCleaner', 'pluginsBeforeDelete']);
|
||||
$core->addBehavior('themeBeforeDelete',
|
||||
array('behaviorsDcAdvancedCleaner','themeBeforeDelete'));
|
||||
|
||||
# Tabs of dcAvdancedCleaner admin page
|
||||
['behaviorsDcAdvancedCleaner', 'themeBeforeDelete']);
|
||||
$core->addBehavior('dcAdvancedCleanerAdminTabs',
|
||||
array('behaviorsDcAdvancedCleaner','dcAdvancedCleanerAdminTabs'));
|
||||
['behaviorsDcAdvancedCleaner', 'dcAdvancedCleanerAdminTabs']);
|
||||
|
||||
# Add dcac events on plugin activityReport
|
||||
if (defined('ACTIVITY_REPORT'))
|
||||
{
|
||||
require_once dirname(__FILE__).'/inc/lib.dc.advanced.cleaner.activityreport.php';
|
||||
if (defined('ACTIVITY_REPORT')) {
|
||||
dcAdvancedCleanerActivityReportBehaviors::add($core);
|
||||
}
|
@ -11,66 +11,68 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_ADMIN_CONTEXT')){return;}
|
||||
if (!defined('DC_ADMIN_CONTEXT')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class dcAdvancedCleaner
|
||||
{
|
||||
protected static $errors = array(
|
||||
'settings' => array(
|
||||
protected static $errors = [
|
||||
'settings' => [
|
||||
'delete_global' => 'Failed to delete global settings',
|
||||
'delete_local' => 'Failed to delete local settings',
|
||||
'delete_all' => 'Failed to delete all settings'
|
||||
),
|
||||
'tables' => array(
|
||||
],
|
||||
'tables' => [
|
||||
'empty' => 'Failed to empty table',
|
||||
'delete' => 'Failed to delete table'
|
||||
),
|
||||
'plugins' => array(
|
||||
],
|
||||
'plugins' => [
|
||||
'empty' => 'Failed to empty plugin folder',
|
||||
'delete' => 'Failed to delete plugin folder'
|
||||
),
|
||||
'themes' => array(
|
||||
],
|
||||
'themes' => [
|
||||
'empty' => 'Failed to empty themes folder',
|
||||
'delete' => 'Failed to delete themes folder'
|
||||
),
|
||||
'caches' => array(
|
||||
],
|
||||
'caches' => [
|
||||
'empty' => 'Failed to empty cache folder',
|
||||
'delete' => 'Failed to delete cache folder'
|
||||
),
|
||||
'versions' => array(
|
||||
],
|
||||
'versions' => [
|
||||
'delete' => 'Failed to delete version'
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
public static $dotclear = array(
|
||||
'settings' => array(
|
||||
public static $dotclear = [
|
||||
'settings' => [
|
||||
'akismet', 'antispam', 'breadcrumb', 'dcckeditor', 'dclegacyeditor', 'maintenance',
|
||||
'pages', 'pings', 'system', 'themes', 'widgets'
|
||||
),
|
||||
'tables' => array(
|
||||
],
|
||||
'tables' => [
|
||||
'blog', 'category', 'comment', 'link', 'log', 'media',
|
||||
'meta', 'permissions', 'ping', 'post','post_media', 'pref', 'session',
|
||||
'setting', 'spamrule', 'user', 'version'
|
||||
),
|
||||
'plugins' => array(
|
||||
],
|
||||
'plugins' => [
|
||||
'aboutConfig', 'akismet', 'antispam', 'attachments', 'blogroll', 'blowupConfig',
|
||||
'breadcrumb', 'dcCKEditor', 'dclegacy', 'dcLegacyEditor', 'fairTrackbacks', 'importExport', 'maintenance',
|
||||
'pages', 'pings', 'simpleMenu', 'tags', 'themeEditor', 'userPref', 'widgets'
|
||||
),
|
||||
'themes' => array(
|
||||
],
|
||||
'themes' => [
|
||||
'default', 'customCSS', 'blueSilence', 'berlin', 'ductile'
|
||||
),
|
||||
'caches' => array(
|
||||
],
|
||||
'caches' => [
|
||||
'cbfeed', 'dcrepo', 'versions'
|
||||
),
|
||||
'versions' => array(
|
||||
],
|
||||
'versions' => [
|
||||
'antispam', 'blogroll', 'blowupConfig', 'core', 'dcCKEditor', 'dcLegacyEditor', 'pages', 'pings', 'simpleMenu', 'tags', 'widgets'
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
public static $exclude = array(
|
||||
public static $exclude = [
|
||||
'.', '..', '__MACOSX', '.svn', 'CVS', '.DS_Store', 'Thumbs.db'
|
||||
);
|
||||
];
|
||||
|
||||
public static function getSettings($core)
|
||||
{
|
||||
@ -79,18 +81,19 @@ class dcAdvancedCleaner
|
||||
'FROM ' . $core->prefix . 'setting ' .
|
||||
'WHERE blog_id IS NULL ' .
|
||||
"OR blog_id IS NOT NULL " .
|
||||
'GROUP BY setting_ns');
|
||||
'GROUP BY setting_ns'
|
||||
);
|
||||
|
||||
$rs = array();
|
||||
$rs = [];
|
||||
$i = 0;
|
||||
while($res->fetch()) {
|
||||
|
||||
$rs[$i]['key'] = $res->setting_ns;
|
||||
$rs[$i]['value'] = $core->con->select(
|
||||
'SELECT count(*) FROM ' . $core->prefix .'setting ' .
|
||||
"WHERE setting_ns = '" . $res->setting_ns ."' " .
|
||||
"AND (blog_id IS NULL OR blog_id IS NOT NULL) " .
|
||||
"GROUP BY setting_ns ")->f(0);
|
||||
"GROUP BY setting_ns "
|
||||
)->f(0);
|
||||
$i++;
|
||||
}
|
||||
return $rs;
|
||||
@ -128,13 +131,13 @@ class dcAdvancedCleaner
|
||||
$object = dbSchema::init($core->con);
|
||||
$res = $object->getTables();
|
||||
|
||||
$rs = array();
|
||||
$rs = [];
|
||||
$i = 0;
|
||||
foreach($res as $k => $v)
|
||||
{
|
||||
if ('' != $core->prefix)
|
||||
{
|
||||
if (!preg_match('/^'.preg_quote($core->prefix).'(.*?)$/',$v,$m)) continue;
|
||||
foreach($res as $k => $v) {
|
||||
if ('' != $core->prefix) {
|
||||
if (!preg_match('/^' . preg_quote($core->prefix) . '(.*?)$/', $v, $m)) {
|
||||
continue;
|
||||
}
|
||||
$v = $m[1];
|
||||
}
|
||||
$rs[$i]['key'] = $v;
|
||||
@ -164,10 +167,9 @@ class dcAdvancedCleaner
|
||||
{
|
||||
$res = $core->con->select('SELECT * FROM ' . $core->prefix . 'version');
|
||||
|
||||
$rs = array();
|
||||
$rs = [];
|
||||
$i = 0;
|
||||
while ($res->fetch()) {
|
||||
|
||||
$rs[$i]['key'] = $res->module;
|
||||
$rs[$i]['value'] = $res->version;
|
||||
$i++;
|
||||
@ -233,64 +235,64 @@ class dcAdvancedCleaner
|
||||
|
||||
public static function execute($core, $type, $action, $ns)
|
||||
{
|
||||
if (strtolower($ns) == 'dcadvancedcleaner')
|
||||
if (strtolower($ns) == 'dcadvancedcleaner') {
|
||||
throw new exception("dcAdvancedCleaner can't remove itself");
|
||||
}
|
||||
|
||||
# BEHAVIOR dcAdvancedCleanerBeforeAction
|
||||
$core->callBehavior('dcAdvancedCleanerBeforeAction', $type, $action, $ns);
|
||||
|
||||
try {
|
||||
# Delete global settings
|
||||
if ($type == 'settings' && $action == 'delete_global')
|
||||
if ($type == 'settings' && $action == 'delete_global') {
|
||||
self::deleteGlobalSettings($core, $ns);
|
||||
|
||||
# Delete local settings
|
||||
if ($type == 'settings' && $action == 'delete_local')
|
||||
self::deleteLocalSettings($core,$ns);
|
||||
|
||||
# Delete all settings
|
||||
if ($type == 'settings' && $action == 'delete_all')
|
||||
self::deleteAllSettings($core,$ns);
|
||||
|
||||
# Empty tables
|
||||
if ($type == 'tables' && $action == 'empty')
|
||||
self::emptyTable($core,$ns);
|
||||
|
||||
# Delete tables
|
||||
if ($type == 'tables' && $action == 'delete')
|
||||
self::deleteTable($core,$ns);
|
||||
|
||||
# Delete versions
|
||||
if ($type == 'versions' && $action == 'delete')
|
||||
self::deleteVersion($core,$ns);
|
||||
|
||||
# Empty plugins
|
||||
if ($type == 'plugins' && $action == 'empty')
|
||||
self::emptyPlugin($core,$ns);
|
||||
|
||||
# Delete plugins
|
||||
if ($type == 'plugins' && $action == 'delete')
|
||||
self::deletePlugin($core,$ns);
|
||||
|
||||
# Empty themes
|
||||
if ($type == 'themes' && $action == 'empty')
|
||||
self::emptyTheme($core,$ns);
|
||||
|
||||
# Delete themes
|
||||
if ($type == 'themes' && $action == 'delete')
|
||||
self::deleteTheme($core,$ns);
|
||||
|
||||
# Empty caches
|
||||
if ($type == 'caches' && $action == 'empty')
|
||||
self::emptyCache($core,$ns);
|
||||
|
||||
# Delete caches
|
||||
if ($type == 'caches' && $action == 'delete')
|
||||
self::deleteCache($core,$ns);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception $e) {
|
||||
# Delete local settings
|
||||
if ($type == 'settings' && $action == 'delete_local') {
|
||||
self::deleteLocalSettings($core, $ns);
|
||||
}
|
||||
# Delete all settings
|
||||
if ($type == 'settings' && $action == 'delete_all') {
|
||||
self::deleteAllSettings($core, $ns);
|
||||
}
|
||||
# Empty tables
|
||||
if ($type == 'tables' && $action == 'empty') {
|
||||
self::emptyTable($core, $ns);
|
||||
}
|
||||
# Delete tables
|
||||
if ($type == 'tables' && $action == 'delete') {
|
||||
self::deleteTable($core, $ns);
|
||||
}
|
||||
# Delete versions
|
||||
if ($type == 'versions' && $action == 'delete') {
|
||||
self::deleteVersion($core, $ns);
|
||||
}
|
||||
# Empty plugins
|
||||
if ($type == 'plugins' && $action == 'empty') {
|
||||
self::emptyPlugin($core, $ns);
|
||||
}
|
||||
# Delete plugins
|
||||
if ($type == 'plugins' && $action == 'delete') {
|
||||
self::deletePlugin($core, $ns);
|
||||
}
|
||||
# Empty themes
|
||||
if ($type == 'themes' && $action == 'empty') {
|
||||
self::emptyTheme($core, $ns);
|
||||
}
|
||||
# Delete themes
|
||||
if ($type == 'themes' && $action == 'delete') {
|
||||
self::deleteTheme($core, $ns);
|
||||
}
|
||||
# Empty caches
|
||||
if ($type == 'caches' && $action == 'empty') {
|
||||
self::emptyCache($core, $ns);
|
||||
}
|
||||
# Delete caches
|
||||
if ($type == 'caches' && $action == 'delete') {
|
||||
self::deleteCache($core, $ns);
|
||||
}
|
||||
return true;
|
||||
} catch(Exception $e) {
|
||||
$errors = self::$errors;
|
||||
if (isset($errors[$type][$action])) {
|
||||
throw new Exception(__($errors[$type][$action]));
|
||||
@ -304,18 +306,17 @@ class dcAdvancedCleaner
|
||||
|
||||
protected static function getDirs($roots)
|
||||
{
|
||||
if (!is_array($roots))
|
||||
$roots = array($roots);
|
||||
|
||||
$rs = array();
|
||||
if (!is_array($roots)) {
|
||||
$roots = [$roots];
|
||||
}
|
||||
$rs = [];
|
||||
$i = 0;
|
||||
foreach ($roots as $root) {
|
||||
|
||||
$dirs = files::scanDir($root);
|
||||
foreach($dirs as $k) {
|
||||
|
||||
if ('.' == $k || '..' == $k || !is_dir($root.'/'.$k)) continue;
|
||||
|
||||
if ('.' == $k || '..' == $k || !is_dir($root .'/' . $k)) {
|
||||
continue;
|
||||
}
|
||||
$rs[$i]['key'] = $k;
|
||||
$rs[$i]['value'] = count(self::scanDir($root . '/' . $k));
|
||||
$i++;
|
||||
@ -326,38 +327,37 @@ class dcAdvancedCleaner
|
||||
|
||||
protected static function delDir($roots, $folder, $delfolder = true)
|
||||
{
|
||||
if (strpos($folder,'/'))
|
||||
if (strpos($folder,'/')) {
|
||||
return false;
|
||||
|
||||
if (!is_array($roots))
|
||||
$roots = array($roots);
|
||||
|
||||
foreach ($roots as $root)
|
||||
{
|
||||
}
|
||||
if (!is_array($roots)) {
|
||||
$roots = [$roots];
|
||||
}
|
||||
foreach ($roots as $root) {
|
||||
if (file_exists($root . '/' . $folder))
|
||||
return self::delTree($root . '/' . $folder, $delfolder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static function scanDir($path,$dir='',$res=array())
|
||||
protected static function scanDir($path, $dir = '', $res = [])
|
||||
{
|
||||
$exclude = self::$exclude;
|
||||
|
||||
$path = path::real($path);
|
||||
if (!is_dir($path) || !is_readable($path)) return array();
|
||||
|
||||
if (!is_dir($path) || !is_readable($path)) {
|
||||
return [];
|
||||
}
|
||||
$files = files::scandir($path);
|
||||
|
||||
foreach($files AS $file) {
|
||||
if (in_array($file,$exclude)) continue;
|
||||
|
||||
if (in_array($file,$exclude)) {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($path . '/' . $file)) {
|
||||
|
||||
$res[] = $file;
|
||||
$res = self::scanDir($path . '/' . $file, $dir . '/' . $file, $res);
|
||||
} else {
|
||||
|
||||
$res[] = empty($dir) ? $file : $dir . '/' . $file;
|
||||
}
|
||||
}
|
||||
@ -366,31 +366,33 @@ class dcAdvancedCleaner
|
||||
|
||||
protected static function delTree($dir, $delroot = true)
|
||||
{
|
||||
if (!is_dir($dir) || !is_readable($dir)) return false;
|
||||
|
||||
if (substr($dir,-1) != '/') $dir .= '/';
|
||||
|
||||
if (($d = @dir($dir)) === false) return false;
|
||||
|
||||
while (($entryname = $d->read()) !== false)
|
||||
{
|
||||
if ($entryname != '.' && $entryname != '..')
|
||||
{
|
||||
if (is_dir($dir.'/'.$entryname))
|
||||
{
|
||||
if (!self::delTree($dir.'/'.$entryname)) return false;
|
||||
if (!is_dir($dir) || !is_readable($dir)) {
|
||||
return false;
|
||||
}
|
||||
if (substr($dir,-1) != '/') {
|
||||
$dir .= '/';
|
||||
}
|
||||
if (($d = @dir($dir)) === false) {
|
||||
return false;
|
||||
}
|
||||
while (($entryname = $d->read()) !== false) {
|
||||
if ($entryname != '.' && $entryname != '..') {
|
||||
if (is_dir($dir . '/' . $entryname)) {
|
||||
if (!self::delTree($dir . '/' . $entryname)) {return false;
|
||||
}
|
||||
} else {
|
||||
if (!@unlink($dir . '/' . $entryname)) {
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!@unlink($dir.'/'.$entryname)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
|
||||
if ($delroot)
|
||||
if ($delroot) {
|
||||
return @rmdir($dir);
|
||||
else
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,9 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_ADMIN_CONTEXT')){return;}
|
||||
if (!defined('DC_ADMIN_CONTEXT')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Modules uninstall features handler
|
||||
@ -24,9 +26,9 @@ class dcUninstaller
|
||||
{
|
||||
protected $path;
|
||||
|
||||
protected $modules = array(); ///< <b>array</b> Modules informations array
|
||||
protected $actions = array('user'=>array(),'callback'=>array());
|
||||
protected $callbacks = array('user'=>array(),'callback'=>array());
|
||||
protected $modules = []; ///< <b>array</b> Modules informations array
|
||||
protected $actions = ['user' => [], 'callback' => []];
|
||||
protected $callbacks = ['user' => [], 'callback' => []];
|
||||
|
||||
protected $id = null;
|
||||
protected $mroot = null;
|
||||
@ -40,36 +42,36 @@ class dcUninstaller
|
||||
'caches' : if module has files on DC caches path,
|
||||
'versions' : if module set a versions on DC table 'version'
|
||||
*/
|
||||
protected static $allowed_properties = array(
|
||||
'versions' => array(
|
||||
protected static $allowed_properties = [
|
||||
'versions' => [
|
||||
'delete' => 'delete version in dc'
|
||||
),
|
||||
'settings' => array(
|
||||
],
|
||||
'settings' => [
|
||||
'delete_global' => 'delete global settings',
|
||||
'delete_local' => 'delete local settings',
|
||||
'delete_all' => 'delete all settings'
|
||||
),
|
||||
'tables' => array(
|
||||
],
|
||||
'tables' => [
|
||||
'empty' => 'empty table',
|
||||
'delete' => 'delete table'
|
||||
),
|
||||
'plugins' => array(
|
||||
],
|
||||
'plugins' => [
|
||||
'empty' => 'empty plugin folder',
|
||||
'delete' => 'delete plugin folder'
|
||||
),
|
||||
'themes' => array(
|
||||
],
|
||||
'themes' => [
|
||||
'empty' => 'empty theme folder',
|
||||
'delete' => 'delete theme folder'
|
||||
),
|
||||
'caches' => array(
|
||||
],
|
||||
'caches' => [
|
||||
'empty' => 'empty cache folder',
|
||||
'delete' => 'delete cache folder'
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
protected static $priority_properties = array(
|
||||
protected static $priority_properties = [
|
||||
'versions','settings','tables','themes','plugins','caches'
|
||||
);
|
||||
];
|
||||
|
||||
public $core; ///< <b>dcCore</b> dcCore instance
|
||||
|
||||
@ -78,7 +80,7 @@ class dcUninstaller
|
||||
|
||||
@param core <b>dcCore</b> dcCore instance
|
||||
*/
|
||||
public function __construct($core)
|
||||
public function __construct(dcCore $core)
|
||||
{
|
||||
$this->core =& $core;
|
||||
}
|
||||
@ -100,20 +102,20 @@ class dcUninstaller
|
||||
{
|
||||
$this->path = explode(PATH_SEPARATOR,$path);
|
||||
|
||||
foreach ($this->path as $root)
|
||||
{
|
||||
if (!is_dir($root) || !is_readable($root)) continue;
|
||||
|
||||
if (substr($root,-1) != '/') $root .= '/';
|
||||
|
||||
if (($d = @dir($root)) === false) continue;
|
||||
|
||||
while (($entry = $d->read()) !== false)
|
||||
{
|
||||
foreach ($this->path as $root) {
|
||||
if (!is_dir($root) || !is_readable($root)) {
|
||||
continue;
|
||||
}
|
||||
if (substr($root, -1) != '/') {
|
||||
$root .= '/';
|
||||
}
|
||||
if (($d = @dir($root)) === false) {
|
||||
continue;
|
||||
}
|
||||
while (($entry = $d->read()) !== false) {
|
||||
$full_entry = $root . '/' . $entry;
|
||||
|
||||
if ($entry != '.' && $entry != '..' && is_dir($full_entry))
|
||||
{
|
||||
if ($entry != '.' && $entry != '..' && is_dir($full_entry)) {
|
||||
$this->loadModule($full_entry);
|
||||
}
|
||||
}
|
||||
@ -121,7 +123,7 @@ class dcUninstaller
|
||||
}
|
||||
|
||||
# Sort modules by name
|
||||
uasort($this->modules,array($this,'sortModules'));
|
||||
uasort($this->modules, [$this, 'sortModules']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,25 +150,24 @@ class dcUninstaller
|
||||
}
|
||||
|
||||
/**
|
||||
This method registers a module in modules list. You should use
|
||||
this to register a new module.
|
||||
This method registers a module in modules list.
|
||||
|
||||
@param name <b>string</b> Module name
|
||||
@param desc <b>string</b> Module description
|
||||
@param author <b>string</b> Module author name
|
||||
@param version <b>string</b> Module version
|
||||
*/
|
||||
public function registerModule($name,$desc,$author,$version)
|
||||
public function registerModule($name, $desc, $author, $version, $properties = [])
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->modules[$this->id] = array(
|
||||
$this->modules[$this->id] = [
|
||||
'root' => $this->mroot,
|
||||
'name' => $name,
|
||||
'desc' => $desc,
|
||||
'author' => $author,
|
||||
'version' => $version,
|
||||
'root_writable' => is_writable($this->mroot)
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,19 +220,23 @@ class dcUninstaller
|
||||
{
|
||||
$group = self::group($group);
|
||||
|
||||
if (null === $this->id) return;
|
||||
|
||||
if (empty($type) || empty($ns)) return;
|
||||
|
||||
if (!isset(self::$allowed_properties[$type][$action])) return;
|
||||
|
||||
if (empty($desc)) $desc = __($action);
|
||||
|
||||
$this->actions[$group][$this->id][$type][] = array(
|
||||
if (null === $this->id) {
|
||||
return null;
|
||||
}
|
||||
if (empty($type) || empty($ns)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset(self::$allowed_properties[$type][$action])) {
|
||||
return null;
|
||||
}
|
||||
if (empty($desc)) {
|
||||
$desc = __($action);
|
||||
}
|
||||
$this->actions[$group][$this->id][$type][] = [
|
||||
'ns' => $ns,
|
||||
'action' => $action,
|
||||
'desc' => $desc
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,15 +260,16 @@ class dcUninstaller
|
||||
{
|
||||
$group = self::group($group);
|
||||
|
||||
if (!isset($this->actions[$group][$id])) return array();
|
||||
|
||||
$res = array();
|
||||
foreach(self::$priority_properties as $k => $v)
|
||||
{
|
||||
if (!isset($this->actions[$group][$id][$v])) continue;
|
||||
if (!isset($this->actions[$group][$id])) {
|
||||
return [];
|
||||
}
|
||||
$res = [];
|
||||
foreach(self::$priority_properties as $k => $v) {
|
||||
if (!isset($this->actions[$group][$id][$v])) {
|
||||
continue;
|
||||
}
|
||||
$res[$v] = $this->actions[$group][$id][$v];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -288,16 +294,19 @@ class dcUninstaller
|
||||
{
|
||||
$group = self::group($group);
|
||||
|
||||
if (null === $this->id) return;
|
||||
|
||||
if (empty($desc)) $desc = __('extra action');
|
||||
|
||||
if (!is_callable($func)) return;
|
||||
|
||||
$this->callbacks[$group][$this->id][] = array(
|
||||
if (null === $this->id) {
|
||||
return null;
|
||||
}
|
||||
if (empty($desc)) {
|
||||
$desc = __('extra action');
|
||||
}
|
||||
if (!is_callable($func)) {
|
||||
return null;
|
||||
}
|
||||
$this->callbacks[$group][$this->id][] = [
|
||||
'func' => $func,
|
||||
'desc' => $desc
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,8 +329,9 @@ class dcUninstaller
|
||||
{
|
||||
$group = self::group($group);
|
||||
|
||||
if (!isset($this->callbacks[$group][$id])) return array();
|
||||
|
||||
if (!isset($this->callbacks[$group][$id])) {
|
||||
return [];
|
||||
}
|
||||
return $this->callbacks[$group][$id];
|
||||
}
|
||||
|
||||
@ -338,8 +348,9 @@ class dcUninstaller
|
||||
{
|
||||
$prop = $this->getAllowedProperties();
|
||||
|
||||
if (!isset($prop[$type][$action]) || empty($ns)) return;
|
||||
|
||||
if (!isset($prop[$type][$action]) || empty($ns)) {
|
||||
return null;
|
||||
}
|
||||
dcAdvancedCleaner::execute($this->core, $type, $action, $ns);
|
||||
}
|
||||
|
||||
@ -350,6 +361,6 @@ class dcUninstaller
|
||||
|
||||
private function group($group)
|
||||
{
|
||||
return in_array($group,array('user','direct')) ? $group : null;
|
||||
return in_array($group, ['user','direct']) ? $group : null;
|
||||
}
|
||||
}
|
@ -11,21 +11,9 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
|
||||
# This file is used with plugin activityReport
|
||||
$core->activityReport->addGroup('dcadvancedcleaner',__('Plugin dcAdvancedCleaner'));
|
||||
|
||||
# from BEHAVIOR dcAdvancedCleanerBeforeAction
|
||||
# in dcAdvancedCleaner/inc/class.dc.advanced.cleaner.php
|
||||
$core->activityReport->addAction(
|
||||
'dcadvancedcleaner',
|
||||
'maintenance',
|
||||
__('Maintenance'),
|
||||
__('New action from dcAdvancedCleaner has been made with type="%s", action="%s", ns="%s".'),
|
||||
'dcAdvancedCleanerBeforeAction',
|
||||
array('dcAdvancedCleanerActivityReportBehaviors','maintenance')
|
||||
);
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class dcAdvancedCleanerActivityReportBehaviors
|
||||
{
|
||||
@ -35,4 +23,24 @@ class dcAdvancedCleanerActivityReportBehaviors
|
||||
|
||||
$GLOBALS['core']->activityReport->addLog('dcadvancedcleaner', 'maintenance', $logs);
|
||||
}
|
||||
|
||||
public static function add($core)
|
||||
{
|
||||
// This file is used with plugin activityReport
|
||||
$core->activityReport->addGroup(
|
||||
'dcadvancedcleaner',
|
||||
__('Plugin dcAdvancedCleaner')
|
||||
);
|
||||
|
||||
// from BEHAVIOR dcAdvancedCleanerBeforeAction
|
||||
// in dcAdvancedCleaner/inc/class.dc.advanced.cleaner.php
|
||||
$core->activityReport->addAction(
|
||||
'dcadvancedcleaner',
|
||||
'maintenance',
|
||||
__('Maintenance'),
|
||||
__('New action from dcAdvancedCleaner has been made with type="%s", action="%s", ns="%s".'),
|
||||
'dcAdvancedCleanerBeforeAction',
|
||||
['dcAdvancedCleanerActivityReportBehaviors', 'maintenance']
|
||||
);
|
||||
}
|
||||
}
|
@ -11,7 +11,9 @@
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_ADMIN_CONTEXT')){return;}
|
||||
if (!defined('DC_ADMIN_CONTEXT')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class behaviorsDcAdvancedCleaner
|
||||
{
|
||||
@ -25,37 +27,34 @@ class behaviorsDcAdvancedCleaner
|
||||
self::moduleBeforeDelete($theme, 'blog_theme.php?del=1');
|
||||
}
|
||||
|
||||
# Generic module before delete
|
||||
// Generic module before delete
|
||||
public static function moduleBeforeDelete($module, $redir)
|
||||
{
|
||||
global $core;
|
||||
$done = false;
|
||||
|
||||
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return;
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
foreach($m_actions as $type => $actions) {
|
||||
foreach($actions as $v) {
|
||||
$uninstaller->execute($type, $v['action'], $v['ns']);
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($done) {
|
||||
http::redirect($redir);
|
||||
}
|
||||
@ -71,11 +70,12 @@ class behaviorsDcAdvancedCleaner
|
||||
self::modulesTabs($core, DC_PLUGINS_ROOT, 'plugins.php?tab=uninstaller');
|
||||
}
|
||||
|
||||
# Generic module tabs
|
||||
// Generic module tabs
|
||||
public static function modulesTabs($core, $path, $redir, $title = '')
|
||||
{
|
||||
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) return;
|
||||
|
||||
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
|
||||
return null;
|
||||
}
|
||||
$err = '';
|
||||
$title = empty($title) ? __('Advanced uninstall') : $title;
|
||||
|
||||
@ -84,58 +84,55 @@ class behaviorsDcAdvancedCleaner
|
||||
$modules = $uninstaller->getModules();
|
||||
$props = $uninstaller->getAllowedProperties();
|
||||
|
||||
# Execute
|
||||
// Execute
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'uninstall'
|
||||
&& (!empty($_POST['extras']) || !empty($_POST['actions']))) {
|
||||
|
||||
&& (!empty($_POST['extras']) || !empty($_POST['actions']))
|
||||
) {
|
||||
try {
|
||||
# Extras
|
||||
// Extras
|
||||
if (!empty($_POST['extras'])) {
|
||||
foreach($_POST['extras'] as $module_id => $extras)
|
||||
{
|
||||
foreach($extras as $k => $sentence)
|
||||
{
|
||||
foreach($_POST['extras'] as $module_id => $extras) {
|
||||
foreach($extras as $k => $sentence) {
|
||||
$extra = @unserialize(@base64_decode($sentence));
|
||||
|
||||
if (!$extra || !is_callable($extra)) continue;
|
||||
|
||||
if (!$extra || !is_callable($extra)) {
|
||||
continue;
|
||||
}
|
||||
call_user_func($extra, $modul_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
# Actions
|
||||
// Actions
|
||||
if (!empty($_POST['actions'])) {
|
||||
foreach($_POST['actions'] as $module_id => $actions)
|
||||
{
|
||||
foreach($actions as $k => $sentence)
|
||||
{
|
||||
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;
|
||||
|
||||
|| !isset($action['ns'])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$uninstaller->execute($action['type'], $action['action'], $action['ns']);
|
||||
}
|
||||
}
|
||||
}
|
||||
http::redirect($redir . '&msg=1');
|
||||
}
|
||||
catch(Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
echo
|
||||
'<div class="multi-part" id="uninstaller" title="'.__($title).'">';
|
||||
echo '<div class="multi-part" id="uninstaller" title="' . __($title) . '">';
|
||||
|
||||
if($err)
|
||||
if($err) {
|
||||
echo '<p class="error">' . $err . '</p>';
|
||||
|
||||
}
|
||||
if(!count($modules)) {
|
||||
echo '<p>' . __('There is no module with uninstall features') . '</p></div>';
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
echo
|
||||
@ -143,19 +140,16 @@ class behaviorsDcAdvancedCleaner
|
||||
'<form method="post" action="' . $redir . '">' .
|
||||
'<table class="clear"><tr>' .
|
||||
'<th>' . __('id') . '</th>' .
|
||||
'<th>'.__('n°').'</th>';
|
||||
'<th>' . __('v') . '</th>';
|
||||
|
||||
foreach($props as $pro_id => $prop) {
|
||||
echo '<th>' . __($pro_id) . '</th>';
|
||||
}
|
||||
|
||||
echo
|
||||
'<th>'.__('extra').'</th>'.
|
||||
'</tr>';
|
||||
echo '<th>' . __('extra') . '</th>' . '</tr>';
|
||||
|
||||
$i = 0;
|
||||
foreach($modules as $module_id => $module) {
|
||||
|
||||
echo
|
||||
'<tr class="line">' .
|
||||
'<td class="nowrap">' . $module_id . '</td>' .
|
||||
@ -174,16 +168,17 @@ class behaviorsDcAdvancedCleaner
|
||||
$j = 0;
|
||||
foreach($actions[$prop_id] as $action_id => $action) {
|
||||
|
||||
if (!isset($props[$prop_id][$action['action']])) continue;
|
||||
|
||||
$ret = base64_encode(serialize(array(
|
||||
if (!isset($props[$prop_id][$action['action']])) {
|
||||
continue;
|
||||
}
|
||||
$ret = base64_encode(serialize([
|
||||
'type' => $prop_id,
|
||||
'action'=> $action['action'],
|
||||
'ns'=> $action['ns']
|
||||
)));
|
||||
]));
|
||||
|
||||
echo '<label class="classic">'.
|
||||
form::checkbox(array('actions['.$module_id.']['.$j.']'),$ret).
|
||||
form::checkbox(['actions[' . $module_id . '][' . $j . ']'], $ret) .
|
||||
' ' . $action['desc'] . '</label><br />';
|
||||
|
||||
$j++;
|
||||
@ -205,7 +200,7 @@ class behaviorsDcAdvancedCleaner
|
||||
$ret = base64_encode(serialize($callback['func']));
|
||||
|
||||
echo '<label class="classic">'.
|
||||
form::checkbox(array('extras['.$module_id.']['.$k.']'),$ret).
|
||||
form::checkbox(['extras[' . $module_id . '][' . $k . ']'], $ret) .
|
||||
' ' . $callback['desc'] . '</label><br />';
|
||||
}
|
||||
|
||||
@ -215,8 +210,8 @@ class behaviorsDcAdvancedCleaner
|
||||
'</table>' .
|
||||
'<p>' .
|
||||
$core->formNonce() .
|
||||
form::hidden(array('redir'),$redir).
|
||||
form::hidden(array('action'),'uninstall').
|
||||
form::hidden(['redir'], $redir) .
|
||||
form::hidden(['action'], 'uninstall') .
|
||||
'<input type="submit" name="submit" value="' . __('Perform selected actions') . '" /> ' .
|
||||
'</p>' .
|
||||
'</form>' .
|
||||
|
Loading…
Reference in New Issue
Block a user