prepare to DC 2.24

master
Jean-Christian Paul Denis 2022-11-15 11:34:45 +01:00
parent 2bbeb2c0d7
commit c5a8f7088c
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
12 changed files with 146 additions and 159 deletions

View File

@ -14,15 +14,15 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$core->blog->settings->addNamespace('dcAdvancedCleaner'); dcCore::app()->blog->settings->addNamespace('dcAdvancedCleaner');
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Advanced cleaner'), __('Advanced cleaner'),
$core->adminurl->get('admin.plugin.dcAdvancedCleaner'), dcCore::app()->adminurl->get('admin.plugin.dcAdvancedCleaner'),
dcPage::getPF('dcAdvancedCleaner/icon.png'), dcPage::getPF('dcAdvancedCleaner/icon.png'),
preg_match( preg_match(
'/' . preg_quote($core->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/', '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.dcAdvancedCleaner')) . '(&.*)?$/',
$_SERVER['REQUEST_URI'] $_SERVER['REQUEST_URI']
), ),
$core->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );

View File

@ -14,16 +14,16 @@ if (!defined('DC_CONTEXT_MODULE')) {
return null; return null;
} }
if (!$core->auth->isSuperAdmin()) { if (!dcCore::app()->auth->isSuperAdmin()) {
return null; return null;
} }
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$core->blog->settings->dcAdvancedCleaner->dropEvery( dcCore::app()->blog->settings->dcAdvancedCleaner->dropEvery(
'dcAdvancedCleaner_behavior_active' 'dcAdvancedCleaner_behavior_active'
); );
$core->blog->settings->dcAdvancedCleaner->put( dcCore::app()->blog->settings->dcAdvancedCleaner->put(
'dcAdvancedCleaner_behavior_active', 'dcAdvancedCleaner_behavior_active',
!empty($_POST['behavior_active']), !empty($_POST['behavior_active']),
'boolean', 'boolean',
@ -31,10 +31,10 @@ if (!empty($_POST['save'])) {
true, true,
true true
); );
$core->blog->settings->dcAdvancedCleaner->dropEvery( dcCore::app()->blog->settings->dcAdvancedCleaner->dropEvery(
'dcAdvancedCleaner_dcproperty_hide' 'dcAdvancedCleaner_dcproperty_hide'
); );
$core->blog->settings->dcAdvancedCleaner->put( dcCore::app()->blog->settings->dcAdvancedCleaner->put(
'dcAdvancedCleaner_dcproperty_hide', 'dcAdvancedCleaner_dcproperty_hide',
!empty($_POST['dcproperty_hide']), !empty($_POST['dcproperty_hide']),
'boolean', 'boolean',
@ -42,19 +42,19 @@ if (!empty($_POST['save'])) {
true, true,
true true
); );
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
$core->adminurl->redirect( dcCore::app()->adminurl->redirect(
'admin.plugins', 'admin.plugins',
[ [
'module' => 'dcAdvancedCleaner', 'module' => 'dcAdvancedCleaner',
'conf' => 1, 'conf' => 1,
'redir' => empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir'] 'redir' => empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'],
] ]
); );
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
echo ' echo '
@ -62,14 +62,14 @@ echo '
form::checkbox( form::checkbox(
'behavior_active', 'behavior_active',
1, 1,
$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active
) . ' ' . __('Activate behaviors') . '</label></p> ) . ' ' . __('Activate behaviors') . '</label></p>
<p class="form-note">' . __('Enable actions set in _uninstall.php files.') . '</p> <p class="form-note">' . __('Enable actions set in _uninstall.php files.') . '</p>
<p><label class="classic" for="dcproperty_hide">' . <p><label class="classic" for="dcproperty_hide">' .
form::checkbox( form::checkbox(
'dcproperty_hide', 'dcproperty_hide',
1, 1,
$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide
) . ' ' . __('Hide Dotclear default properties in actions tabs') . '</label></p> ) . ' ' . __('Hide Dotclear default properties in actions tabs') . '</label></p>
<p class="form-note">' . <p class="form-note">' .
__('Prevent from deleting Dotclear important properties.') . '</p>'; __('Prevent from deleting Dotclear important properties.') . '</p>';

View File

@ -18,13 +18,13 @@ $this->registerModule(
'Advanced cleaner', 'Advanced cleaner',
'Make a huge cleaning of dotclear', 'Make a huge cleaning of dotclear',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'0.9', '0.10',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/dcAdvancedCleaner', 'support' => 'https://github.com/JcDenis/dcAdvancedCleaner',
'details' => 'https://plugins.dotaddict.org/dc2/details/dcAdvancedCleaner', 'details' => 'https://plugins.dotaddict.org/dc2/details/dcAdvancedCleaner',
'repository' => 'https://raw.githubusercontent.com/JcDenis/dcAdvancedCleaner/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcAdvancedCleaner/master/dcstore.xml',
] ]
); );

View File

@ -14,17 +14,17 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$new_version = $core->plugins->moduleInfo('dcAdvancedCleaner', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('dcAdvancedCleaner', 'version');
$old_version = $core->getVersion('dcAdvancedCleaner'); $old_version = dcCore::app()->getVersion('dcAdvancedCleaner');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
} }
try { try {
$core->blog->settings->addNamespace('dcAdvancedCleaner'); dcCore::app()->blog->settings->addNamespace('dcAdvancedCleaner');
$core->blog->settings->dcAdvancedCleaner->put( dcCore::app()->blog->settings->dcAdvancedCleaner->put(
'dcAdvancedCleaner_behavior_active', 'dcAdvancedCleaner_behavior_active',
true, true,
'boolean', 'boolean',
@ -32,7 +32,7 @@ try {
false, false,
true true
); );
$core->blog->settings->dcAdvancedCleaner->put( dcCore::app()->blog->settings->dcAdvancedCleaner->put(
'dcAdvancedCleaner_dcproperty_hide', 'dcAdvancedCleaner_dcproperty_hide',
true, true,
'boolean', 'boolean',
@ -41,11 +41,11 @@ try {
true true
); );
$core->setVersion('dcAdvancedCleaner', $new_version); dcCore::app()->setVersion('dcAdvancedCleaner', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return false; return false;
} }

View File

@ -17,39 +17,37 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$d = dirname(__FILE__) . '/inc/';
# dcac class # dcac class
$__autoload['advancedCleaner'] = $d . 'class.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleaner' => __DIR__ . '/inc/class.advanced.cleaner.php']);
$__autoload['dcAdvancedCleaner'] = $d . 'class.dc.advanced.cleaner.php'; Clearbricks::lib()->autoload(['dcAdvancedCleaner' => __DIR__ . '/inc/class.dc.advanced.cleaner.php']);
$__autoload['behaviorsDcAdvancedCleaner'] = $d . 'lib.dc.advanced.cleaner.behaviors.php'; Clearbricks::lib()->autoload(['behaviorsDcAdvancedCleaner' => __DIR__ . '/inc/lib.dc.advanced.cleaner.behaviors.php']);
$__autoload['dcUninstaller'] = $d . 'class.dc.uninstaller.php'; Clearbricks::lib()->autoload(['dcUninstaller' => __DIR__ . '/inc/class.dc.uninstaller.php']);
$__autoload['dcAdvancedCleanerActivityReportBehaviors'] = $d . 'lib.dc.advanced.cleaner.activityreport.php'; Clearbricks::lib()->autoload(['dcAdvancedCleanerActivityReportBehaviors' => __DIR__ . '/inc/lib.dc.advanced.cleaner.activityreport.php']);
# cleaners class # cleaners class
$__autoload['advancedCleanerVersions'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerVersions' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerSettings'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerSettings' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerTables'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerTables' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerThemes'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerThemes' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerPlugins'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerPlugins' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerCaches'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerCaches' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$__autoload['advancedCleanerVars'] = $d . 'lib.advanced.cleaner.php'; Clearbricks::lib()->autoload(['advancedCleanerVars' => __DIR__ . '/inc/lib.advanced.cleaner.php']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerVersions', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerVersions', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerSettings', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerSettings', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerTables', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerTables', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerThemes', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerThemes', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerPlugins', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerPlugins', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerCaches', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerCaches', 'create']);
$core->addBehavior('advancedCleanerAdd', ['advancedCleanerVars', 'create']); dcCore::app()->addBehavior('advancedCleanerAdd', ['advancedCleanerVars', 'create']);
# dcac behaviors # dcac behaviors
$core->addBehavior('adminDashboardFavorites', ['behaviorsDcAdvancedCleaner', 'adminDashboardFavorites']); dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['behaviorsDcAdvancedCleaner', 'adminDashboardFavorites']);
$core->addBehavior('pluginsToolsTabs', ['behaviorsDcAdvancedCleaner', 'pluginsToolsTabs']); dcCore::app()->addBehavior('pluginsToolsTabsV2', ['behaviorsDcAdvancedCleaner', 'pluginsToolsTabs']);
$core->addBehavior('adminModulesListDoActions', ['behaviorsDcAdvancedCleaner', 'adminModulesListDoActions']); dcCore::app()->addBehavior('adminModulesListDoActions', ['behaviorsDcAdvancedCleaner', 'adminModulesListDoActions']);
$core->addBehavior('pluginsBeforeDelete', ['behaviorsDcAdvancedCleaner', 'pluginsBeforeDelete']); dcCore::app()->addBehavior('pluginsBeforeDelete', ['behaviorsDcAdvancedCleaner', 'pluginsBeforeDelete']);
$core->addBehavior('themeBeforeDelete', ['behaviorsDcAdvancedCleaner', 'themeBeforeDelete']); dcCore::app()->addBehavior('themeBeforeDelete', ['behaviorsDcAdvancedCleaner', 'themeBeforeDelete']);
if (defined('ACTIVITY_REPORT')) { if (defined('ACTIVITY_REPORT')) {
dcAdvancedCleanerActivityReportBehaviors::add($core); dcAdvancedCleanerActivityReportBehaviors::add();
} }

View File

@ -12,31 +12,27 @@
*/ */
abstract class advancedCleaner abstract class advancedCleaner
{ {
protected $core;
private static $exclude = [ private static $exclude = [
'.', '..', '__MACOSX', '.svn', 'CVS', '.DS_Store', 'Thumbs.db' '.', '..', '__MACOSX', '.svn', 'CVS', '.DS_Store', 'Thumbs.db',
]; ];
private $properties = [ private $properties = [
'id' => '', 'id' => '',
'name' => '', 'name' => '',
'desc' => '' 'desc' => '',
]; ];
private $actions = []; private $actions = [];
final public function __construct(dcCore $core) final public function __construct()
{ {
$this->core = $core;
$this->init(); $this->init();
} }
public static function create(arrayObject $o, dcCore $core) public static function create(arrayObject $o)
{ {
$c = get_called_class(); $c = get_called_class();
$o->append(new $c($core)); $o->append(new $c());
} }
final public function __get(string $property) final public function __get(string $property)

View File

@ -16,16 +16,14 @@ if (!defined('DC_ADMIN_CONTEXT')) {
class dcAdvancedCleaner class dcAdvancedCleaner
{ {
protected $core;
protected $cleaners = []; protected $cleaners = [];
public function __construct($core) public function __construct()
{ {
$this->core = $core; $cleaners = new arrayObject();
$cleaners = new arrayObject();
try { try {
$this->core->callBehavior('advancedCleanerAdd', $cleaners, $this->core); dcCore::app()->callBehavior('advancedCleanerAdd', $cleaners);
foreach ($cleaners as $cleaner) { foreach ($cleaners as $cleaner) {
if ($cleaner instanceof advancedCleaner && !isset($this->cleaners[$cleaner->id])) { if ($cleaner instanceof advancedCleaner && !isset($this->cleaners[$cleaner->id])) {
@ -33,7 +31,7 @@ class dcAdvancedCleaner
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -62,7 +60,7 @@ class dcAdvancedCleaner
} }
# BEHAVIOR dcAdvancedCleanerBeforeAction # BEHAVIOR dcAdvancedCleanerBeforeAction
$this->core->callBehavior('dcAdvancedCleanerBeforeAction', $type, $action, $ns); dcCore::app()->callBehavior('dcAdvancedCleanerBeforeAction', $type, $action, $ns);
$ret = $this->cleaners[$type]->set($action, $ns); $ret = $this->cleaners[$type]->set($action, $ns);

View File

@ -48,19 +48,15 @@ class dcUninstaller
protected $id = null; protected $id = null;
protected $mroot = null; protected $mroot = null;
public $core;
private $ac; private $ac;
private $allowed_actions = null; private $allowed_actions = null;
/** /**
* Object constructor. * Object constructor.
*
* @param dcCore $core dcCore instance
*/ */
public function __construct(dcCore $core) public function __construct()
{ {
$this->core = & $core; $this->ac = new dcAdvancedCleaner();
$this->ac = new dcAdvancedCleaner($core);
$res = []; $res = [];
foreach ($this->ac->get() as $cleaner) { foreach ($this->ac->get() as $cleaner) {
@ -151,7 +147,7 @@ class dcUninstaller
'desc' => $desc, 'desc' => $desc,
'author' => $author, 'author' => $author,
'version' => $version, 'version' => $version,
'root_writable' => is_writable($this->mroot) 'root_writable' => is_writable($this->mroot),
]; ];
} }
} }
@ -176,7 +172,7 @@ class dcUninstaller
/** /**
* Returns true if the module with ID <var>$id</var> exists. * Returns true if the module with ID <var>$id</var> exists.
* *
* @param string $idModule ID * @param string $id Module ID
* *
* @return boolean Success * @return boolean Success
*/ */
@ -224,7 +220,7 @@ class dcUninstaller
$this->actions[$group][$this->id][$type][] = [ $this->actions[$group][$this->id][$type][] = [
'ns' => $ns, 'ns' => $ns,
'action' => $action, 'action' => $action,
'desc' => $desc 'desc' => $desc,
]; ];
} }
@ -295,7 +291,7 @@ class dcUninstaller
} }
$this->callbacks[$group][$this->id][] = [ $this->callbacks[$group][$this->id][] = [
'func' => $func, 'func' => $func,
'desc' => $desc 'desc' => $desc,
]; ];
} }

View File

@ -17,13 +17,13 @@ class advancedCleanerSettings extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'settings', 'id' => 'settings',
'name' => __('Settings'), 'name' => __('Settings'),
'desc' => __('Namespaces registered in dcSettings') 'desc' => __('Namespaces registered in dcSettings'),
]); ]);
$this->setActions([ $this->setActions([
'delete_global' => __('delete global settings'), 'delete_global' => __('delete global settings'),
'delete_local' => __('delete blog settings'), 'delete_local' => __('delete blog settings'),
'delete_all' => __('delete all settings') 'delete_all' => __('delete all settings'),
]); ]);
return true; return true;
@ -57,15 +57,15 @@ class advancedCleanerSettings extends advancedCleaner
'pings', 'pings',
'system', 'system',
'themes', 'themes',
'widgets' 'widgets',
]; ];
} }
public function get(): array public function get(): array
{ {
$res = $this->core->con->select( $res = dcCore::app()->con->select(
'SELECT setting_ns ' . 'SELECT setting_ns ' .
'FROM ' . $this->core->prefix . 'setting ' . 'FROM ' . dcCore::app()->prefix . 'setting ' .
'WHERE blog_id IS NULL ' . 'WHERE blog_id IS NULL ' .
'OR blog_id IS NOT NULL ' . 'OR blog_id IS NOT NULL ' .
'GROUP BY setting_ns' 'GROUP BY setting_ns'
@ -75,8 +75,8 @@ class advancedCleanerSettings extends advancedCleaner
$i = 0; $i = 0;
while ($res->fetch()) { while ($res->fetch()) {
$rs[$i]['key'] = $res->setting_ns; $rs[$i]['key'] = $res->setting_ns;
$rs[$i]['value'] = $this->core->con->select( $rs[$i]['value'] = dcCore::app()->con->select(
'SELECT count(*) FROM ' . $this->core->prefix . 'setting ' . 'SELECT count(*) FROM ' . dcCore::app()->prefix . 'setting ' .
"WHERE setting_ns = '" . $res->setting_ns . "' " . "WHERE setting_ns = '" . $res->setting_ns . "' " .
'AND (blog_id IS NULL OR blog_id IS NOT NULL) ' . 'AND (blog_id IS NULL OR blog_id IS NOT NULL) ' .
'GROUP BY setting_ns ' 'GROUP BY setting_ns '
@ -90,27 +90,27 @@ class advancedCleanerSettings extends advancedCleaner
public function set($action, $ns): bool public function set($action, $ns): bool
{ {
if ($action == 'delete_global') { if ($action == 'delete_global') {
$this->core->con->execute( dcCore::app()->con->execute(
'DELETE FROM ' . $this->core->prefix . 'setting ' . 'DELETE FROM ' . dcCore::app()->prefix . 'setting ' .
'WHERE blog_id IS NULL ' . 'WHERE blog_id IS NULL ' .
"AND setting_ns = '" . $this->core->con->escape($ns) . "' " "AND setting_ns = '" . dcCore::app()->con->escape($ns) . "' "
); );
return true; return true;
} }
if ($action == 'delete_local') { if ($action == 'delete_local') {
$this->core->con->execute( dcCore::app()->con->execute(
'DELETE FROM ' . $this->core->prefix . 'setting ' . 'DELETE FROM ' . dcCore::app()->prefix . 'setting ' .
"WHERE blog_id = '" . $this->core->con->escape($this->core->blog->id) . "' " . "WHERE blog_id = '" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
"AND setting_ns = '" . $this->core->con->escape($ns) . "' " "AND setting_ns = '" . dcCore::app()->con->escape($ns) . "' "
); );
return true; return true;
} }
if ($action == 'delete_all') { if ($action == 'delete_all') {
$this->core->con->execute( dcCore::app()->con->execute(
'DELETE FROM ' . $this->core->prefix . 'setting ' . 'DELETE FROM ' . dcCore::app()->prefix . 'setting ' .
"WHERE setting_ns = '" . $this->core->con->escape($ns) . "' " . "WHERE setting_ns = '" . dcCore::app()->con->escape($ns) . "' " .
"AND (blog_id IS NULL OR blog_id != '') " "AND (blog_id IS NULL OR blog_id != '') "
); );
@ -128,12 +128,12 @@ class advancedCleanerTables extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'tables', 'id' => 'tables',
'name' => __('Tables'), 'name' => __('Tables'),
'desc' => __('All database tables of Dotclear') 'desc' => __('All database tables of Dotclear'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete'), 'delete' => __('delete'),
'empty' => __('empty') 'empty' => __('empty'),
]); ]);
return true; return true;
@ -170,26 +170,26 @@ class advancedCleanerTables extends advancedCleaner
'setting', 'setting',
'spamrule', 'spamrule',
'user', 'user',
'version' 'version',
]; ];
} }
public function get(): array public function get(): array
{ {
$object = dbSchema::init($this->core->con); $object = dbSchema::init(dcCore::app()->con);
$res = $object->getTables(); $res = $object->getTables();
$rs = []; $rs = [];
$i = 0; $i = 0;
foreach ($res as $k => $v) { foreach ($res as $k => $v) {
if ('' != $this->core->prefix) { if ('' != dcCore::app()->prefix) {
if (!preg_match('/^' . preg_quote($this->core->prefix) . '(.*?)$/', $v, $m)) { if (!preg_match('/^' . preg_quote(dcCore::app()->prefix) . '(.*?)$/', $v, $m)) {
continue; continue;
} }
$v = $m[1]; $v = $m[1];
} }
$rs[$i]['key'] = $v; $rs[$i]['key'] = $v;
$rs[$i]['value'] = $this->core->con->select('SELECT count(*) FROM ' . $res[$k])->f(0); $rs[$i]['value'] = dcCore::app()->con->select('SELECT count(*) FROM ' . $res[$k])->f(0);
$i++; $i++;
} }
@ -199,16 +199,16 @@ class advancedCleanerTables extends advancedCleaner
public function set($action, $ns): bool public function set($action, $ns): bool
{ {
if (in_array($action, ['empty', 'delete'])) { if (in_array($action, ['empty', 'delete'])) {
$this->core->con->execute( dcCore::app()->con->execute(
'DELETE FROM ' . $this->core->con->escapeSystem($this->core->prefix . $ns) 'DELETE FROM ' . dcCore::app()->con->escapeSystem(dcCore::app()->prefix . $ns)
); );
} }
if ($action == 'empty') { if ($action == 'empty') {
return true; return true;
} }
if ($action == 'delete') { if ($action == 'delete') {
$this->core->con->execute( dcCore::app()->con->execute(
'DROP TABLE ' . $this->core->con->escapeSystem($this->core->prefix . $ns) 'DROP TABLE ' . dcCore::app()->con->escapeSystem(dcCore::app()->prefix . $ns)
); );
return true; return true;
@ -225,11 +225,11 @@ class advancedCleanerVersions extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'versions', 'id' => 'versions',
'name' => __('Versions'), 'name' => __('Versions'),
'desc' => __('Versions registered in table "version" of Dotclear') 'desc' => __('Versions registered in table "version" of Dotclear'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete') 'delete' => __('delete'),
]); ]);
return true; return true;
@ -257,13 +257,13 @@ class advancedCleanerVersions extends advancedCleaner
'pings', 'pings',
'simpleMenu', 'simpleMenu',
'tags', 'tags',
'widgets' 'widgets',
]; ];
} }
public function get(): array public function get(): array
{ {
$res = $this->core->con->select('SELECT * FROM ' . $this->core->prefix . 'version'); $res = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . 'version');
$rs = []; $rs = [];
$i = 0; $i = 0;
@ -279,9 +279,9 @@ class advancedCleanerVersions extends advancedCleaner
public function set($action, $ns): bool public function set($action, $ns): bool
{ {
if ($action == 'delete') { if ($action == 'delete') {
$this->core->con->execute( dcCore::app()->con->execute(
'DELETE FROM ' . $this->core->prefix . 'version ' . 'DELETE FROM ' . dcCore::app()->prefix . 'version ' .
"WHERE module = '" . $this->core->con->escape($ns) . "' " "WHERE module = '" . dcCore::app()->con->escape($ns) . "' "
); );
return true; return true;
@ -298,12 +298,12 @@ class advancedCleanerPlugins extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'plugins', 'id' => 'plugins',
'name' => __('Plugins'), 'name' => __('Plugins'),
'desc' => __('Folders from plugins directories') 'desc' => __('Folders from plugins directories'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete'), 'delete' => __('delete'),
'empty' => __('empty') 'empty' => __('empty'),
]); ]);
return true; return true;
@ -360,12 +360,12 @@ class advancedCleanerThemes extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'themes', 'id' => 'themes',
'name' => __('Themes'), 'name' => __('Themes'),
'desc' => __('Folders from blog themes directory') 'desc' => __('Folders from blog themes directory'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete'), 'delete' => __('delete'),
'empty' => __('empty') 'empty' => __('empty'),
]); ]);
return true; return true;
@ -390,7 +390,7 @@ class advancedCleanerThemes extends advancedCleaner
public function get(): array public function get(): array
{ {
$res = self::getDirs($this->core->blog->themes_path); $res = self::getDirs(dcCore::app()->blog->themes_path);
sort($res); sort($res);
return $res; return $res;
@ -399,12 +399,12 @@ class advancedCleanerThemes extends advancedCleaner
public function set($action, $ns): bool public function set($action, $ns): bool
{ {
if ($action == 'empty') { if ($action == 'empty') {
self::delDir($this->core->blog->themes_path, $ns, false); self::delDir(dcCore::app()->blog->themes_path, $ns, false);
return true; return true;
} }
if ($action == 'delete') { if ($action == 'delete') {
self::delDir($this->core->blog->themes_path, $ns, true); self::delDir(dcCore::app()->blog->themes_path, $ns, true);
return true; return true;
} }
@ -420,12 +420,12 @@ class advancedCleanerCaches extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'caches', 'id' => 'caches',
'name' => __('Cache'), 'name' => __('Cache'),
'desc' => __('Folders from cache directory') 'desc' => __('Folders from cache directory'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete'), 'delete' => __('delete'),
'empty' => __('empty') 'empty' => __('empty'),
]); ]);
return true; return true;
@ -477,11 +477,11 @@ class advancedCleanerVars extends advancedCleaner
$this->setProperties([ $this->setProperties([
'id' => 'vars', 'id' => 'vars',
'name' => __('Var'), 'name' => __('Var'),
'desc' => __('Folders from Dotclear VAR directory') 'desc' => __('Folders from Dotclear VAR directory'),
]); ]);
$this->setActions([ $this->setActions([
'delete' => __('delete') 'delete' => __('delete'),
]); ]);
return true; return true;

View File

@ -18,20 +18,20 @@ class dcAdvancedCleanerActivityReportBehaviors
{ {
public static function maintenance($type, $action, $ns) public static function maintenance($type, $action, $ns)
{ {
$GLOBALS['core']->activityReport->addLog('dcadvancedcleaner', 'maintenance', [$type,$action, $ns]); dcCore::app()->activityReport->addLog('dcadvancedcleaner', 'maintenance', [$type,$action, $ns]);
} }
public static function add($core) public static function add()
{ {
// This file is used with plugin activityReport // This file is used with plugin activityReport
$core->activityReport->addGroup( dcCore::app()->activityReport->addGroup(
'dcadvancedcleaner', 'dcadvancedcleaner',
__('Plugin dcAdvancedCleaner') __('Plugin dcAdvancedCleaner')
); );
// from BEHAVIOR dcAdvancedCleanerBeforeAction // from BEHAVIOR dcAdvancedCleanerBeforeAction
// in dcAdvancedCleaner/inc/class.dc.advanced.cleaner.php // in dcAdvancedCleaner/inc/class.dc.advanced.cleaner.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'dcadvancedcleaner', 'dcadvancedcleaner',
'maintenance', 'maintenance',
__('Maintenance'), __('Maintenance'),

View File

@ -16,14 +16,14 @@ if (!defined('DC_ADMIN_CONTEXT')) {
class behaviorsDcAdvancedCleaner class behaviorsDcAdvancedCleaner
{ {
public static function adminDashboardFavorites(dcCore $core, $favs) public static function adminDashboardFavorites($favs)
{ {
$favs->register('dcAdvancedCleaner', [ $favs->register('dcAdvancedCleaner', [
'title' => __('Advanced cleaner'), 'title' => __('Advanced cleaner'),
'url' => $core->adminurl->get('admin.plugin.dcAdvancedCleaner'), 'url' => dcCore::app()->adminurl->get('admin.plugin.dcAdvancedCleaner'),
'small-icon' => dcPage::getPF('dcAdvancedCleaner/icon.png'), 'small-icon' => dcPage::getPF('dcAdvancedCleaner/icon.png'),
'large-icon' => dcPage::getPF('dcAdvancedCleaner/icon-big.png'), 'large-icon' => dcPage::getPF('dcAdvancedCleaner/icon-big.png'),
'permissions' => $core->auth->isSuperAdmin() 'permissions' => dcCore::app()->auth->isSuperAdmin(),
]); ]);
} }
@ -40,13 +40,12 @@ class behaviorsDcAdvancedCleaner
// Generic module before delete // Generic module before delete
public static function moduleBeforeDelete($module, $redir) public static function moduleBeforeDelete($module, $redir)
{ {
global $core;
$done = false; $done = false;
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { if (!dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
return null; return null;
} }
$uninstaller = new dcUninstaller($core); $uninstaller = new dcUninstaller();
$uninstaller->loadModule($module['root']); $uninstaller->loadModule($module['root']);
$m_callbacks = $uninstaller->getDirectCallbacks($module['id']); $m_callbacks = $uninstaller->getDirectCallbacks($module['id']);
@ -70,19 +69,19 @@ class behaviorsDcAdvancedCleaner
} }
} }
public static function pluginsToolsTabs($core) public static function pluginsToolsTabs()
{ {
self::modulesTabs($core, DC_PLUGINS_ROOT, $core->adminurl->get('admin.plugins') . '#uninstaller'); self::modulesTabs(DC_PLUGINS_ROOT, dcCore::app()->adminurl->get('admin.plugins') . '#uninstaller');
} }
public static function modulesTabs($core, $path, $redir, $title = '') public static function modulesTabs($path, $redir, $title = '')
{ {
if (!$core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { if (!dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
return null; return null;
} }
$title = empty($title) ? __('Advanced uninstall') : $title; $title = empty($title) ? __('Advanced uninstall') : $title;
$uninstaller = new dcUninstaller($core); $uninstaller = new dcUninstaller();
$uninstaller->loadModules($path); $uninstaller->loadModules($path);
$modules = $uninstaller->getModules(); $modules = $uninstaller->getModules();
$props = $uninstaller->getAllowedActions(); $props = $uninstaller->getAllowedActions();
@ -133,7 +132,7 @@ class behaviorsDcAdvancedCleaner
$ret = base64_encode(serialize([ $ret = base64_encode(serialize([
'type' => $prop_id, 'type' => $prop_id,
'action' => $action['action'], 'action' => $action['action'],
'ns' => $action['ns'] 'ns' => $action['ns'],
])); ]));
echo '<label class="classic">' . echo '<label class="classic">' .
@ -167,7 +166,7 @@ class behaviorsDcAdvancedCleaner
echo echo
'</table>' . '</table>' .
'<p>' . '<p>' .
$core->formNonce() . dcCore::app()->formNonce() .
form::hidden(['path'], $path) . form::hidden(['path'], $path) .
form::hidden(['redir'], $redir) . form::hidden(['redir'], $redir) .
form::hidden(['action'], 'uninstall') . form::hidden(['action'], 'uninstall') .
@ -180,17 +179,17 @@ class behaviorsDcAdvancedCleaner
public static function adminModulesListDoActions($list, $modules, $type) public static function adminModulesListDoActions($list, $modules, $type)
{ {
if (!$list->core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) { if (!dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_behavior_active) {
return null; return null;
} }
if (!isset($_POST['action']) || $_POST['action'] != 'uninstall' if (!isset($_POST['action']) || $_POST['action'] != 'uninstall'
|| (empty($_POST['extras']) && empty($_POST['actions'])) || (empty($_POST['extras']) && empty($_POST['actions']))
) { ) {
return null; return null;
} }
$uninstaller = new dcUninstaller($list->core); $uninstaller = new dcUninstaller();
$uninstaller->loadModules($_POST['path']); $uninstaller->loadModules($_POST['path']);
$modules = $uninstaller->getModules(); $modules = $uninstaller->getModules();
$props = $uninstaller->getAllowedActions(); $props = $uninstaller->getAllowedActions();
@ -205,7 +204,7 @@ class behaviorsDcAdvancedCleaner
if (!$extra || !is_callable($extra)) { if (!$extra || !is_callable($extra)) {
continue; continue;
} }
call_user_func($extra, $modul_id); call_user_func($extra, $module_id);
} }
} }
} }
@ -226,10 +225,10 @@ class behaviorsDcAdvancedCleaner
} }
} }
} }
dcPage::addSuccessNotice(__('Action successfuly excecuted')); dcAdminNotices::addSuccessNotice(__('Action successfuly excecuted'));
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} catch (Exception $e) { } catch (Exception $e) {
$list->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
} }

View File

@ -16,7 +16,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper(); dcPage::checkSuper();
$ac = new dcAdvancedCleaner($core); $ac = new dcAdvancedCleaner();
$cleaner = false; $cleaner = false;
$select_menu = []; $select_menu = [];
@ -38,13 +38,13 @@ if (!empty($_POST['entries']) && !empty($_POST['action'])) {
foreach ($_POST['entries'] as $ns) { foreach ($_POST['entries'] as $ns) {
$ac->set($cleaner->id, $_POST['action'], $ns); $ac->set($cleaner->id, $_POST['action'], $ns);
} }
dcPage::addSuccessNotice(__('Action successfuly excecuted')); dcAdminNotices::addSuccessNotice(__('Action successfuly excecuted'));
$core->adminurl->redirect( dcCore::app()->adminurl->redirect(
'admin.plugin.dcAdvancedCleaner', 'admin.plugin.dcAdvancedCleaner',
['part' => $cleaner->id] ['part' => $cleaner->id]
); );
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -54,16 +54,16 @@ dcPage::cssLoad(dcPage::getPF('dcAdvancedCleaner/style.css')) .
dcPage::jsLoad(dcPage::getPF('dcAdvancedCleaner/js/index.js')); dcPage::jsLoad(dcPage::getPF('dcAdvancedCleaner/js/index.js'));
# --BEHAVIOR-- dcAdvancedCleanerAdminHeader # --BEHAVIOR-- dcAdvancedCleanerAdminHeader
$core->callBehavior('dcAdvancedCleanerAdminHeader', $core); dcCore::app()->callBehavior('dcAdvancedCleanerAdminHeader');
echo '</head><body>' . echo '</head><body>' .
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Advanced cleaner') => '' __('Advanced cleaner') => '',
]) . ]) .
dcPage::notices() . dcPage::notices() .
'<form method="get" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="parts_menu">' . '<form method="get" action="' . dcCore::app()->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="parts_menu">' .
'<p class="anchor-nav"><label for="part" class="classic">' . __('Goto:') . ' </label>' . '<p class="anchor-nav"><label for="part" class="classic">' . __('Goto:') . ' </label>' .
form::combo('part', $select_menu, $cleaner->id) . ' ' . form::combo('part', $select_menu, $cleaner->id) . ' ' .
'<input type="submit" value="' . __('Ok') . '" />' . '<input type="submit" value="' . __('Ok') . '" />' .
@ -78,7 +78,7 @@ if (empty($rs)) {
echo '<p>' . __('There is nothing to display') . '</p>'; echo '<p>' . __('There is nothing to display') . '</p>';
} else { } else {
echo echo
'<form method="post" action="' . $core->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="form-funcs">' . '<form method="post" action="' . dcCore::app()->adminurl->get('admin.plugin.dcAdvancedCleaner') . '" id="form-funcs">' .
'<div class="table-outer">' . '<div class="table-outer">' .
'<table><caption>' . sprintf(__('There are %s %s'), count($rs), __($cleaner->id)) . '</caption><thead><tr>' . '<table><caption>' . sprintf(__('There are %s %s'), count($rs), __($cleaner->id)) . '</caption><thead><tr>' .
'<th colspan="2">' . __('Name') . '</th><th>' . __('Objects') . '</th>' . '<th colspan="2">' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
@ -87,7 +87,7 @@ if (empty($rs)) {
foreach ($rs as $k => $v) { foreach ($rs as $k => $v) {
$offline = in_array($v['key'], $cleaner->official()); $offline = in_array($v['key'], $cleaner->official());
if ($offline && $core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) { if ($offline && dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) {
continue; continue;
} }
echo echo
@ -108,14 +108,14 @@ if (empty($rs)) {
'<input id="do-action" type="submit" value="' . __('ok') . '" />' . '<input id="do-action" type="submit" value="' . __('ok') . '" />' .
form::hidden(['p'], 'dcAdvancedCleaner') . form::hidden(['p'], 'dcAdvancedCleaner') .
form::hidden(['part'], $cleaner->id) . form::hidden(['part'], $cleaner->id) .
$core->formNonce() . '</p>' . dcCore::app()->formNonce() . '</p>' .
'<p class="info">' . '<p class="info">' .
__('Beware: All actions done here are irreversible and are directly applied') . __('Beware: All actions done here are irreversible and are directly applied') .
'</p>' . '</p>' .
'</form>'; '</form>';
} }
if ($core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) { if (dcCore::app()->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) {
echo '<p class="info">' . echo '<p class="info">' .
__('Default values of Dotclear are hidden. You can change this in settings') . __('Default values of Dotclear are hidden. You can change this in settings') .
'</p>'; '</p>';