update to PSR12

This commit is contained in:
Jean-Christian Paul Denis 2021-11-06 16:19:49 +01:00
parent 2a3323b79d
commit 7c0d3f45e5
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
15 changed files with 240 additions and 232 deletions

View File

@ -1,8 +1,11 @@
0.8.1 - dev
- [ ] orphan media cleaner
- fix permissions
- move actions to independent tools
- add var folder
- update admin page to a lighter interface
- update translation (and remove .lang.php file)
- update to PSR12
0.8 - 2021.09.07
- update DC official values (themes,settings,tables...)

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
@ -54,8 +53,7 @@ if (!empty($_POST['save'])) {
'redir' => empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir']
]
);
}
catch(Exception $e) {
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -47,5 +46,6 @@ try {
return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
return false;
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
abstract class advancedCleaner
{
protected $core;
@ -32,7 +31,6 @@ abstract class advancedCleaner
$this->core = $core;
$this->init();
}
public static function create(arrayObject $o, dcCore $core)
@ -54,11 +52,12 @@ abstract class advancedCleaner
final protected function setProperties($property, $value = null): bool
{
$properties = is_array($property) ? $property : [$property => $value];
foreach($properties as $k => $v) {
foreach ($properties as $k => $v) {
if (isset($this->properties[$k])) {
$this->properties[$k] = (string) $v;
}
}
return true;
}
@ -70,7 +69,7 @@ abstract class advancedCleaner
final protected function setActions($action, $name = null): bool
{
$actions = is_array($action) ? $action : [$action => $name];
foreach($actions as $k => $v) {
foreach ($actions as $k => $v) {
$this->actions[$k] = (string) $v;
}
@ -98,8 +97,8 @@ abstract class advancedCleaner
$i = 0;
foreach ($roots as $root) {
$dirs = files::scanDir($root);
foreach($dirs as $k) {
if ('.' == $k || '..' == $k || !is_dir($root .'/' . $k)) {
foreach ($dirs as $k) {
if ('.' == $k || '..' == $k || !is_dir($root . '/' . $k)) {
continue;
}
$rs[$i]['key'] = $k;
@ -107,21 +106,24 @@ abstract class advancedCleaner
$i++;
}
}
return $rs;
}
protected static function delDir($roots, $folder, $delfolder = true)
{
if (strpos($folder,'/')) {
if (strpos($folder, '/')) {
return false;
}
if (!is_array($roots)) {
$roots = [$roots];
}
foreach ($roots as $root) {
if (file_exists($root . '/' . $folder))
if (file_exists($root . '/' . $folder)) {
return self::delTree($root . '/' . $folder, $delfolder);
}
}
return false;
}
@ -135,7 +137,7 @@ abstract class advancedCleaner
}
$files = files::scandir($path);
foreach($files AS $file) {
foreach ($files as $file) {
if (in_array($file, $exclude)) {
continue;
}
@ -146,6 +148,7 @@ abstract class advancedCleaner
$res[] = empty($dir) ? $file : $dir . '/' . $file;
}
}
return $res;
}
@ -154,7 +157,7 @@ abstract class advancedCleaner
if (!is_dir($dir) || !is_readable($dir)) {
return false;
}
if (substr($dir,-1) != '/') {
if (substr($dir, -1) != '/') {
$dir .= '/';
}
if (($d = @dir($dir)) === false) {
@ -163,7 +166,8 @@ abstract class advancedCleaner
while (($entryname = $d->read()) !== false) {
if ($entryname != '.' && $entryname != '..') {
if (is_dir($dir . '/' . $entryname)) {
if (!self::delTree($dir . '/' . $entryname)) {return false;
if (!self::delTree($dir . '/' . $entryname)) {
return false;
}
} else {
if (!@unlink($dir . '/' . $entryname)) {
@ -176,8 +180,8 @@ abstract class advancedCleaner
if ($delroot) {
return @rmdir($dir);
} else {
}
return true;
}
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_ADMIN_CONTEXT')) {
return null;
}
@ -28,8 +27,8 @@ class dcAdvancedCleaner
try {
$this->core->callBehavior('advancedCleanerAdd', $cleaners, $this->core);
foreach($cleaners as $cleaner) {
if ($cleaner instanceOf advancedCleaner && !isset($this->cleaners[$cleaner->id])) {
foreach ($cleaners as $cleaner) {
if ($cleaner instanceof advancedCleaner && !isset($this->cleaners[$cleaner->id])) {
$this->cleaners[$cleaner->id] = $cleaner;
}
}
@ -49,6 +48,7 @@ class dcAdvancedCleaner
if ($silent) {
return false;
}
throw new exception(sprintf(__('unknow cleaner type %s'), $type));
}
@ -68,6 +68,7 @@ class dcAdvancedCleaner
if ($ret === false) {
$msg = $this->cleaners[$type]->error($action);
throw new Exception($msg ?? __('Unknow error'));
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_ADMIN_CONTEXT')) {
return null;
}
@ -60,11 +59,11 @@ class dcUninstaller
*/
public function __construct(dcCore $core)
{
$this->core =& $core;
$this->core = & $core;
$this->ac = new dcAdvancedCleaner($core);
$res = [];
foreach($this->ac->get() as $cleaner) {
foreach ($this->ac->get() as $cleaner) {
$res[$cleaner->id] = $cleaner->getActions();
}
$this->allowed_actions = $res;
@ -86,7 +85,7 @@ class dcUninstaller
*/
public function loadModules($path)
{
$this->path = explode(PATH_SEPARATOR,$path);
$this->path = explode(PATH_SEPARATOR, $path);
foreach ($this->path as $root) {
if (!is_dir($root) || !is_readable($root)) {
@ -124,7 +123,6 @@ class dcUninstaller
{
if (file_exists($root . '/_define.php')
&& file_exists($root . '/_uninstall.php')) {
$this->id = basename($root);
$this->mroot = $root;
@ -171,6 +169,7 @@ class dcUninstaller
if ($id && isset($this->modules[$id])) {
return $this->modules[$id];
}
return $this->modules;
}
@ -253,12 +252,13 @@ class dcUninstaller
return [];
}
$res = [];
foreach($this->allowed_actions as $k => $v) {
foreach ($this->allowed_actions as $k => $v) {
if (!isset($this->actions[$group][$id][$k])) {
continue;
}
$res[$k] = $this->actions[$group][$id][$k];
}
return $res;
}
@ -270,7 +270,7 @@ class dcUninstaller
* @param string $func Callable function
* @param string $desc Description of action
*/
protected function addUserCallback($func, $desc= '')
protected function addUserCallback($func, $desc = '')
{
$this->addCallback('user', $func, $desc);
}
@ -323,6 +323,7 @@ class dcUninstaller
if (!isset($this->callbacks[$group][$id])) {
return [];
}
return $this->callbacks[$group][$id];
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class advancedCleanerSettings extends advancedCleaner
{
protected function init(): bool
@ -68,19 +67,19 @@ class advancedCleanerSettings extends advancedCleaner
'SELECT setting_ns ' .
'FROM ' . $this->core->prefix . 'setting ' .
'WHERE blog_id IS NULL ' .
"OR blog_id IS NOT NULL " .
'OR blog_id IS NOT NULL ' .
'GROUP BY setting_ns'
);
$rs = [];
$i = 0;
while($res->fetch()) {
while ($res->fetch()) {
$rs[$i]['key'] = $res->setting_ns;
$rs[$i]['value'] = $this->core->con->select(
'SELECT count(*) FROM ' . $this->core->prefix .'setting ' .
"WHERE setting_ns = '" . $res->setting_ns ."' " .
"AND (blog_id IS NULL OR blog_id IS NOT NULL) " .
"GROUP BY setting_ns "
'SELECT count(*) FROM ' . $this->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);
$i++;
}
@ -92,7 +91,7 @@ class advancedCleanerSettings extends advancedCleaner
{
if ($action == 'delete_global') {
$this->core->con->execute(
'DELETE FROM ' .$this->core->prefix . 'setting ' .
'DELETE FROM ' . $this->core->prefix . 'setting ' .
'WHERE blog_id IS NULL ' .
"AND setting_ns = '" . $this->core->con->escape($ns) . "' "
);
@ -110,7 +109,7 @@ class advancedCleanerSettings extends advancedCleaner
}
if ($action == 'delete_all') {
$this->core->con->execute(
'DELETE FROM ' .$this->core->prefix . 'setting ' .
'DELETE FROM ' . $this->core->prefix . 'setting ' .
"WHERE setting_ns = '" . $this->core->con->escape($ns) . "' " .
"AND (blog_id IS NULL OR blog_id != '') "
);
@ -148,6 +147,7 @@ class advancedCleanerTables extends advancedCleaner
if ($action == 'delete') {
return __('Failed to delete table');
}
return '';
}
@ -181,7 +181,7 @@ class advancedCleanerTables extends advancedCleaner
$rs = [];
$i = 0;
foreach($res as $k => $v) {
foreach ($res as $k => $v) {
if ('' != $this->core->prefix) {
if (!preg_match('/^' . preg_quote($this->core->prefix) . '(.*?)$/', $v, $m)) {
continue;
@ -280,7 +280,7 @@ class advancedCleanerVersions extends advancedCleaner
{
if ($action == 'delete') {
$this->core->con->execute(
'DELETE FROM '. $this->core->prefix . 'version ' .
'DELETE FROM ' . $this->core->prefix . 'version ' .
"WHERE module = '" . $this->core->con->escape($ns) . "' "
);
@ -317,6 +317,7 @@ class advancedCleanerPlugins extends advancedCleaner
if ($action == 'delete') {
return __('Failed to delete plugin folder');
}
return '';
}
@ -378,6 +379,7 @@ class advancedCleanerThemes extends advancedCleaner
if ($action == 'delete') {
return __('Failed to delete themes folder');
}
return '';
}
@ -437,6 +439,7 @@ class advancedCleanerCaches extends advancedCleaner
if ($action == 'delete') {
return __('Failed to delete cache folder');
}
return '';
}
@ -489,6 +492,7 @@ class advancedCleanerVars extends advancedCleaner
if ($action == 'delete') {
return __('Failed to delete var folder');
}
return '';
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
@ -19,7 +18,7 @@ class dcAdvancedCleanerActivityReportBehaviors
{
public static function maintenance($type, $action, $ns)
{
$GLOBALS['core']->activityReport->addLog('dcadvancedcleaner', 'maintenance', [$type ,$action, $ns]);
$GLOBALS['core']->activityReport->addLog('dcadvancedcleaner', 'maintenance', [$type,$action, $ns]);
}
public static function add($core)

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_ADMIN_CONTEXT')) {
return null;
}
@ -53,15 +52,15 @@ class behaviorsDcAdvancedCleaner
$m_callbacks = $uninstaller->getDirectCallbacks($module['id']);
$m_actions = $uninstaller->getDirectActions($module['id']);
foreach($m_callbacks as $k => $callback) {
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;
}
@ -90,8 +89,9 @@ class behaviorsDcAdvancedCleaner
echo '<div class="multi-part" id="uninstaller" title="' . __($title) . '"><h3>' . __($title) . '</h3>';
if(!count($modules)) {
if (!count($modules)) {
echo '<p>' . __('There is no module with uninstall features') . '</p></div>';
return null;
}
@ -101,14 +101,14 @@ class behaviorsDcAdvancedCleaner
'<table class="clear"><tr>' .
'<th colspan="2">' . __('module') . '</th>';
foreach($props as $pro_id => $prop) {
foreach ($props as $pro_id => $prop) {
echo '<th>' . __($pro_id) . '</th>';
}
echo '<th>' . __('other') . '</th>' . '</tr>';
$i = 0;
foreach($modules as $module_id => $module) {
foreach ($modules as $module_id => $module) {
echo
'<tr class="line">' .
'<td class="nowrap">' . $module_id . '</td>' .
@ -116,27 +116,27 @@ class behaviorsDcAdvancedCleaner
$actions = $uninstaller->getUserActions($module_id);
foreach($props as $prop_id => $prop) {
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) {
foreach ($actions[$prop_id] as $action_id => $action) {
if (!isset($props[$prop_id][$action['action']])) {
continue;
}
$ret = base64_encode(serialize([
'type' => $prop_id,
'action'=> $action['action'],
'ns'=> $action['ns']
'action' => $action['action'],
'ns' => $action['ns']
]));
echo '<label class="classic">'.
echo '<label class="classic">' .
form::checkbox(['actions[' . $module_id . '][' . $j . ']'], $ret) .
' ' . $action['desc'] . '</label><br />';
@ -154,11 +154,10 @@ class behaviorsDcAdvancedCleaner
}
$k = 0;
foreach($callbacks as $callback_id => $callback) {
foreach ($callbacks as $callback_id => $callback) {
$ret = base64_encode(serialize($callback['func']));
echo '<label class="classic">'.
echo '<label class="classic">' .
form::checkbox(['extras[' . $module_id . '][' . $k . ']'], $ret) .
' ' . $callback['desc'] . '</label><br />';
}
@ -199,8 +198,8 @@ class behaviorsDcAdvancedCleaner
try {
// 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)) {
@ -212,8 +211,8 @@ class behaviorsDcAdvancedCleaner
}
// 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
@ -229,7 +228,7 @@ class behaviorsDcAdvancedCleaner
}
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
http::redirect($_POST['redir']);
} catch(Exception $e) {
} catch (Exception $e) {
$list->core->error->add($e->getMessage());
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
@ -21,7 +20,7 @@ $ac = new dcAdvancedCleaner($core);
$cleaner = false;
$select_menu = [];
foreach($ac->get() as $k) {
foreach ($ac->get() as $k) {
$select_menu[$k->name] = $k->id;
if ($k->id == $_REQUEST['part']) {
$cleaner = $k;
@ -36,7 +35,7 @@ if (!$cleaner) {
# Actions
if (!empty($_POST['entries']) && !empty($_POST['action'])) {
try {
foreach($_POST['entries'] as $ns) {
foreach ($_POST['entries'] as $ns) {
$ac->set($cleaner->id, $_POST['action'], $ns);
}
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
@ -44,8 +43,7 @@ if (!empty($_POST['entries']) && !empty($_POST['action'])) {
'admin.plugin.dcAdvancedCleaner',
['part' => $cleaner->id]
);
}
catch(Exception $e) {
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
@ -86,7 +84,7 @@ if (empty($rs)) {
'<th colspan="2">' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
'</tr></thead><tbody>';
foreach($rs as $k => $v) {
foreach ($rs as $k => $v) {
$offline = in_array($v['key'], $cleaner->official());
if ($offline && $core->blog->settings->dcAdvancedCleaner->dcAdvancedCleaner_dcproperty_hide) {

View File

@ -1,16 +1,18 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of dcAdvancedCleaner, a plugin for Dotclear 2.
#
# Copyright (c) 2009 JC Denis and contributors
# jcdenis@gdwd.com
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;}
if (!isset($__resources['help']['dcAdvancedCleaner']))
{
$__resources['help']['dcAdvancedCleaner'] = dirname(__FILE__).'/help/dcAdvancedCleaner.html';
/**
* @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
*/
if (!defined('DC_RC_PATH')) {
return;
}
if (!isset($__resources['help']['dcAdvancedCleaner'])) {
$__resources['help']['dcAdvancedCleaner'] = dirname(__FILE__) . '/help/dcAdvancedCleaner.html';
}

View File

@ -1,16 +1,18 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of dcAdvancedCleaner, a plugin for Dotclear 2.
#
# Copyright (c) 2009 JC Denis and contributors
# jcdenis@gdwd.com
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;}
if (!isset($__resources['help']['dcAdvancedCleaner']))
{
$__resources['help']['dcAdvancedCleaner'] = dirname(__FILE__).'/help/dcAdvancedCleaner.html';
/**
* @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
*/
if (!defined('DC_RC_PATH')) {
return;
}
if (!isset($__resources['help']['dcAdvancedCleaner'])) {
$__resources['help']['dcAdvancedCleaner'] = dirname(__FILE__) . '/help/dcAdvancedCleaner.html';
}