update to Dotclear 2.24, phpstan 1.9.2, php-cs-fixer 3.13.0

This commit is contained in:
Jean-Christian Denis 2022-11-12 22:58:44 +01:00
parent 6da2f9d3e6
commit 5d32b5c410
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
18 changed files with 144 additions and 152 deletions

View file

@ -5,6 +5,11 @@ dev
- [ ] add module to create full README file - [ ] add module to create full README file
- [ ] write documentation of php class - [ ] write documentation of php class
0.9 - 2022.11.12
- update to Dotclear 2.24
- update to php-cs-fixer.phar 3.13.0
- update to phpstan.phar 1.9.2
0.8.2 - 2021.11.18 0.8.2 - 2021.11.18
- update php-cs-fixer.phar to 3.3.2 - update php-cs-fixer.phar to 3.3.2
- update phpstan.phar to 1.2.0 - update phpstan.phar to 1.2.0

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/improve)](https://github.com/JcDenis/improve/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/improve)](https://github.com/JcDenis/improve/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/improve)](https://github.com/JcDenis/improve/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/improve)](https://github.com/JcDenis/improve/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/improve)](https://github.com/JcDenis/improve/issues) [![Issues](https://img.shields.io/github/issues/JcDenis/improve)](https://github.com/JcDenis/improve/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.19-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/improve) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/improve)
[![License](https://img.shields.io/github/license/JcDenis/improve)](https://github.com/JcDenis/improve/blob/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/improve)](https://github.com/JcDenis/improve/blob/master/LICENSE)
@ -23,7 +23,7 @@ It helps dev to clean up plugin or theme before publishing code.
**improve** requires: **improve** requires:
* admin permission * admin permission
* Dotclear 2.19 * Dotclear 2.24
## USAGE ## USAGE

View file

@ -19,16 +19,15 @@ if (!defined('DC_CONTEXT_ADMIN')) {
} }
/* dotclear */ /* dotclear */
use dcAdmin;
use dcCore; use dcCore;
use dcPage; use dcPage;
use dcFavorites; use dcFavorites;
/* clearbricks */ /* clearbricks */
use Clearbricks;
use files; use files;
/* php */
use ArrayObject;
/** /**
* Improve admin class * Improve admin class
* *
@ -36,54 +35,52 @@ use ArrayObject;
*/ */
class admin class admin
{ {
public static function process(dcCore $core, ArrayObject $_menu): void public static function process(): void
{ {
self::addSettingsNamespace($core); self::addSettingsNamespace();
self::addAdminBehaviors($core); self::addAdminBehaviors();
self::addAdminMenu($core, $_menu); self::addAdminMenu();
self::addImproveActions($core); self::addImproveActions();
} }
private static function addSettingsNamespace(dcCore $core): void private static function addSettingsNamespace(): void
{ {
$core->blog->settings->addNamespace('improve'); dcCore::app()->blog->settings->addNamespace('improve');
} }
private static function addAdminBehaviors(dcCore $core): void private static function addAdminBehaviors(): void
{ {
$core->addBehavior('adminDashboardFavorites', __NAMESPACE__ . '\admin::adminDashboardFavorites'); dcCore::app()->addBehavior('adminDashboardFavoritesV2', __NAMESPACE__ . '\admin::adminDashboardFavorites');
} }
private static function addAdminMenu(dcCore $core, ArrayObject $_menu): void private static function addAdminMenu(): void
{ {
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('improve'), __('improve'),
$core->adminurl->get('admin.plugin.improve'), dcCore::app()->adminurl->get('admin.plugin.improve'),
dcPage::getPF('improve/icon.png'), dcPage::getPF('improve/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );
} }
private static function addImproveActions(dcCore $core): void private static function addImproveActions(): void
{ {
global $__autoload;
foreach (files::scandir(prepend::getActionsDir()) as $file) { foreach (files::scandir(prepend::getActionsDir()) as $file) {
if (is_file(prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) { if (is_file(prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) {
$__autoload[prepend::getActionsNS() . substr($file, 0, -4)] = prepend::getActionsDir() . $file; Clearbricks::lib()->autoload([prepend::getActionsNS() . substr($file, 0, -4) => prepend::getActionsDir() . $file]);
$core->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ dcCore::app()->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */
} }
} }
} }
public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs): void public static function adminDashboardFavorites(dcFavorites $favs): void
{ {
$favs->register( $favs->register(
'improve', 'improve',
[ [
'title' => __('improve'), 'title' => __('improve'),
'url' => $core->adminurl->get('admin.plugin.improve'), 'url' => dcCore::app()->adminurl->get('admin.plugin.improve'),
'small-icon' => dcPage::getPF('improve/icon.png'), 'small-icon' => dcPage::getPF('improve/icon.png'),
'large-icon' => dcPage::getPF('improve/icon-b.png'), 'large-icon' => dcPage::getPF('improve/icon-b.png'),
'permissions' => null, 'permissions' => null,
@ -93,4 +90,4 @@ class admin
} }
/* process */ /* process */
admin::process($core, $_menu); admin::process();

View file

@ -20,7 +20,6 @@ if (!defined('DC_CONTEXT_ADMIN')) {
/* dotclear */ /* dotclear */
use dcCore; use dcCore;
use adminModulesList;
use dcPage; use dcPage;
/* clearbricks */ /* clearbricks */
@ -36,20 +35,14 @@ use Exception;
*/ */
class config class config
{ {
/** @var dcCore $core dcCore instance */
private $core = null;
/** @var adminModulesList $list adminModulesList instance */
private $list = null;
/** @var improve $improve improve core instance */ /** @var improve $improve improve core instance */
private $improve = null; private $improve = null;
public function __construct(dcCore $core, adminModulesList $list) public function __construct()
{ {
dcPage::checkSuper(); dcPage::checkSuper();
$this->core = $core; $this->improve = new improve();
$this->list = $list;
$this->improve = new improve($core);
$this->saveConfig(); $this->saveConfig();
$this->displayConfig(); $this->displayConfig();
@ -77,17 +70,17 @@ class config
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) { if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
$pdisabled = implode(';', $_POST['disabled']); $pdisabled = implode(';', $_POST['disabled']);
} }
$this->core->blog->settings->improve->put('disabled', $pdisabled); dcCore::app()->blog->settings->improve->put('disabled', $pdisabled);
$this->core->blog->settings->improve->put('nodetails', !empty($_POST['nodetails'])); dcCore::app()->blog->settings->improve->put('nodetails', !empty($_POST['nodetails']));
dcPage::addSuccessNotice(__('Configuration successfully updated')); dcPage::addSuccessNotice(__('Configuration successfully updated'));
$this->core->adminurl->redirect( dcCore::app()->adminurl->redirect(
'admin.plugins', 'admin.plugins',
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => $this->list->getRedir()] ['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()]
); );
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -104,11 +97,11 @@ class config
echo echo
'</div><div class="fieldset"><h4>' . __('Options') . '</h4>' . '</div><div class="fieldset"><h4>' . __('Options') . '</h4>' .
'<p><label class="classic">' . '<p><label class="classic">' .
form::checkbox('nodetails', '1', ['checked' => $this->core->blog->settings->improve->nodetails]) . form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->improve->nodetails]) .
__('Hide details of rendered actions') . '</label></p>' . __('Hide details of rendered actions') . '</label></p>' .
'</div>'; '</div>';
} }
} }
/* process */ /* process */
new config($core, $list); new config();

View file

@ -18,9 +18,9 @@ $this->registerModule(
'improve', 'improve',
'Tiny tools to fix things for module devs', 'Tiny tools to fix things for module devs',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'0.8.2', '0.9',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/improve', 'support' => 'https://github.com/JcDenis/improve',

View file

@ -34,7 +34,7 @@ use Exception;
class install class install
{ {
/** @var string Dotclear minimal version */ /** @var string Dotclear minimal version */
private static $dotclear_version = '2.19'; private static $dotclear_version = '2.24';
/** @var array Improve default settings */ /** @var array Improve default settings */
private static $default_settings = [[ private static $default_settings = [[
'disabled', 'disabled',
@ -43,12 +43,12 @@ class install
'string', 'string',
]]; ]];
public static function process(dcCore $core): ?bool public static function process(): ?bool
{ {
if (!self::checkModuleVersion($core)) { if (!self::checkModuleVersion()) {
return null; return null;
} }
if (!self::checkDotclearVersion($core)) { if (!self::checkDotclearVersion()) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', '%s requires Dotclear %s',
'improve', 'improve',
@ -56,40 +56,40 @@ class install
)); ));
} }
$core->blog->settings->addNamespace('improve'); dcCore::app()->blog->settings->addNamespace('improve');
self::update_0_8_0($core); self::update_0_8_0();
self::putSettings($core); self::putSettings();
self::setVersion($core); self::setVersion();
return true; return true;
} }
private static function getInstalledVersion(dcCore $core): string private static function getInstalledVersion(): string
{ {
$version = $core->getVersion('improve'); $version = dcCore::app()->getVersion('improve');
return is_string($version) ? $version : '0'; return is_string($version) ? $version : '0';
} }
private static function checkModuleVersion(dcCore $core): bool private static function checkModuleVersion(): bool
{ {
return version_compare( return version_compare(
self::getInstalledVersion($core), self::getInstalledVersion(),
$core->plugins->moduleInfo('improve', 'version'), dcCore::app()->plugins->moduleInfo('improve', 'version'),
'<' '<'
); );
} }
private static function checkDotclearVersion(dcCore $core): bool private static function checkDotclearVersion(): bool
{ {
return method_exists('dcUtils', 'versionsCompare') return method_exists('dcUtils', 'versionsCompare')
&& dcUtils::versionsCompare(DC_VERSION, self::$dotclear_version, '>=', false); && dcUtils::versionsCompare(DC_VERSION, self::$dotclear_version, '>=', false);
} }
private static function putSettings(dcCore $core): void private static function putSettings(): void
{ {
foreach (self::$default_settings as $v) { foreach (self::$default_settings as $v) {
$core->blog->settings->improve->put( dcCore::app()->blog->settings->improve->put(
$v[0], $v[0],
$v[2], $v[2],
$v[3], $v[3],
@ -100,19 +100,19 @@ class install
} }
} }
private static function setVersion(dcCore $core): void private static function setVersion(): void
{ {
$core->setVersion('improve', $core->plugins->moduleInfo('improve', 'version')); dcCore::app()->setVersion('improve', dcCore::app()->plugins->moduleInfo('improve', 'version'));
} }
/** Update improve < 0.8 : action modules settings name */ /** Update improve < 0.8 : action modules settings name */
private static function update_0_8_0(dcCore $core): void private static function update_0_8_0(): void
{ {
if (version_compare(self::getInstalledVersion($core), '0.8', '<')) { if (version_compare(self::getInstalledVersion(), '0.8', '<')) {
foreach ($core->blog->settings->improve->dumpGlobalSettings() as $id => $values) { foreach (dcCore::app()->blog->settings->improve->dumpGlobalSettings() as $id => $values) {
$newId = str_replace('ImproveAction', '', $id); $newId = str_replace('ImproveAction', '', $id);
if ($id != $newId) { if ($id != $newId) {
$core->blog->settings->improve->rename($id, strtolower($newId)); dcCore::app()->blog->settings->improve->rename($id, strtolower($newId));
} }
} }
} }
@ -121,7 +121,7 @@ class install
/* process */ /* process */
try { try {
return install::process($core); return install::process();
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());

View file

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace plugins\improve; namespace plugins\improve;
use Clearbricks;
if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
@ -25,16 +27,16 @@ if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) {
*/ */
class prepend class prepend
{ {
public static function process(array &$__autoload): void public static function process(): void
{ {
foreach (['improve', 'action', 'module'] as $class) { foreach (['improve', 'action', 'module'] as $class) {
$__autoload['plugins\\improve\\' . $class] = dirname(__FILE__) . '/inc/core/' . $class . '.php'; Clearbricks::lib()->autoload(['plugins\\improve\\' . $class => __DIR__ . '/inc/core/' . $class . '.php']);
} }
} }
public static function getActionsDir(): string public static function getActionsDir(): string
{ {
return dirname(__FILE__) . '/inc/module/'; return __DIR__ . '/inc/module/';
} }
public static function getActionsNS(): string public static function getActionsNS(): string
@ -44,4 +46,4 @@ class prepend
} }
/* process */ /* process */
prepend::process($__autoload); prepend::process();

View file

@ -29,16 +29,13 @@ use arrayObject;
* *
* Action class must extends class action. * Action class must extends class action.
* If your class signature is myActionClass extends plugins\improve\class\action, * If your class signature is myActionClass extends plugins\improve\class\action,
* do $core->addBehavior('ImproveAddAction'), ['myClass', 'create']); * do dcCore::app()->addBehavior('ImproveAddAction'), ['myClass', 'create']);
* your action class is automatically created, * your action class is automatically created,
* then function init() of your class wil be called. * then function init() of your class wil be called.
* One class must manage only one action. * One class must manage only one action.
*/ */
abstract class action abstract class action
{ {
/** @var dcCore dcCore instance */
protected $core;
/** @var array<string> Current module */ /** @var array<string> Current module */
protected $module = []; protected $module = [];
@ -83,15 +80,12 @@ abstract class action
/** /**
* Action constructor inits properties and settings of a child class. * Action constructor inits properties and settings of a child class.
*
* @param dcCore $core dcCore instance
*/ */
final public function __construct(dcCore $core) final public function __construct()
{ {
$this->core = $core;
$this->class_name = str_replace(prepend::getActionsNS(), '', get_called_class()); $this->class_name = str_replace(prepend::getActionsNS(), '', get_called_class());
$settings = $core->blog->settings->improve->get('settings_' . $this->class_name); $settings = dcCore::app()->blog->settings->improve->get('settings_' . $this->class_name);
if (null != $settings) { if (null != $settings) {
$settings = unserialize($settings); $settings = unserialize($settings);
} }
@ -100,7 +94,7 @@ abstract class action
$this->init(); $this->init();
// can overload priority by settings // can overload priority by settings
if (1 < ($p = (int) $core->blog->settings->improve->get('priority_' . $this->class_name))) { if (1 < ($p = (int) dcCore::app()->blog->settings->improve->get('priority_' . $this->class_name))) {
$this->priority = $p; $this->priority = $p;
} }
} }
@ -109,12 +103,11 @@ abstract class action
* Helper to create an instance of a ImproveAction child class. * Helper to create an instance of a ImproveAction child class.
* *
* @param ArrayObject $list ArrayObject of actions list * @param ArrayObject $list ArrayObject of actions list
* @param dcCore $core dcCore instance
*/ */
final public static function create(arrayObject $list, dcCore $core): void final public static function create(arrayObject $list): void
{ {
$child = static::class; $child = static::class;
$class = new $child($core); $class = new $child();
$list->append($class); $list->append($class);
} }
@ -242,7 +235,7 @@ abstract class action
*/ */
final protected function redirect(string $url): bool final protected function redirect(string $url): bool
{ {
$this->core->blog->settings->improve->put( dcCore::app()->blog->settings->improve->put(
'settings_' . $this->class_name, 'settings_' . $this->class_name,
serialize($this->settings), serialize($this->settings),
'string', 'string',
@ -250,7 +243,7 @@ abstract class action
true, true,
true true
); );
$this->core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice(__('Configuration successfully updated')); dcPage::addSuccessNotice(__('Configuration successfully updated'));
http::redirect($url); http::redirect($url);

View file

@ -35,9 +35,6 @@ class improve
'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md', 'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md',
]; ];
/** @var dcCore $core dcCore instance */
private $core;
/** @var array<action> $actions Loaded actions modules */ /** @var array<action> $actions Loaded actions modules */
private $actions = []; private $actions = [];
@ -52,17 +49,14 @@ class improve
/** /**
* Constructor * Constructor
*
* @param dcCore $core dcCore instance
*/ */
public function __construct(dcCore $core) public function __construct()
{ {
$this->core = &$core; $disabled = explode(';', (string) dcCore::app()->blog->settings->improve->disabled);
$disabled = explode(';', (string) $core->blog->settings->improve->disabled); $list = new arrayObject();
$list = new arrayObject();
try { try {
$this->core->callBehavior('improveAddAction', $list, $this->core); dcCore::app()->callBehavior('improveAddAction', $list);
foreach ($list as $action) { foreach ($list as $action) {
if ($action instanceof action && !isset($this->actions[$action->id()])) { if ($action instanceof action && !isset($this->actions[$action->id()])) {
@ -74,7 +68,7 @@ class improve
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
uasort($this->actions, [$this, 'sortModules']); uasort($this->actions, [$this, 'sortModules']);
} }
@ -94,21 +88,21 @@ class improve
if (empty($this->logs)) { if (empty($this->logs)) {
return 0; return 0;
} }
$cur = $this->core->con->openCursor($this->core->prefix . 'log'); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'log');
$cur->log_msg = serialize($this->logs); $cur->log_msg = serialize($this->logs);
$cur->log_table = 'improve'; $cur->log_table = 'improve';
$id = $this->core->log->addLog($cur); $id = dcCore::app()->log->addLog($cur);
return $id; return $id;
} }
public function readLogs(int $id): array public function readLogs(int $id): array
{ {
$rs = $this->core->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]); $rs = dcCore::app()->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return []; return [];
} }
$this->core->log->delLogs($rs->log_id); dcCore::app()->log->delLogs($rs->log_id);
$res = unserialize($rs->log_msg); $res = unserialize($rs->log_msg);
@ -308,7 +302,7 @@ class improve
public function getURL(array $params = []): string public function getURL(array $params = []): string
{ {
return $this->core->adminurl->get('admin.plugin.improve', $params, '&'); return dcCore::app()->adminurl->get('admin.plugin.improve', $params, '&');
} }
/** /**

View file

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace plugins\improve\module; namespace plugins\improve\module;
/* dotclear */
use dcCore;
/* improve */ /* improve */
use plugins\improve\action; use plugins\improve\action;
@ -165,7 +168,7 @@ class gitshields extends action
$version = $this->module['dc_min']; $version = $this->module['dc_min'];
} }
return $version ?: $this->core->getVersion('core'); return $version ?: dcCore::app()->getVersion('core');
} }
private function writeShieldsBloc(string $content): string private function writeShieldsBloc(string $content): string

View file

@ -37,7 +37,7 @@ class newline extends action
'types' => ['plugin', 'theme'], 'types' => ['plugin', 'theme'],
]); ]);
/* /*
$ext = @unserialize($this->core->blog->settings->improve->newline_extensions); $ext = @unserialize(dcCore::app()->blog->settings->improve->newline_extensions);
$ext = Improve::cleanExtensions($ext); $ext = Improve::cleanExtensions($ext);
if (!empty($ext)) { if (!empty($ext)) {
$this->extensions = $ext; $this->extensions = $ext;

View file

@ -18,6 +18,7 @@ namespace plugins\improve\module;
use plugins\improve\action; use plugins\improve\action;
/* dotclear */ /* dotclear */
use dcCore;
use dcPage; use dcPage;
/* clearbricks */ /* clearbricks */
@ -66,9 +67,9 @@ class phpcsfixer extends action
$this->getPhpPath(); $this->getPhpPath();
$this->core->auth->user_prefs->addWorkspace('interface'); dcCore::app()->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax; self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme; self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme;
return true; return true;
} }

View file

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace plugins\improve\module; namespace plugins\improve\module;
/* dotclear */
use dcCore;
/* improve */ /* improve */
use plugins\improve\action; use plugins\improve\action;
@ -162,10 +165,10 @@ class phpheader extends action
$this->module['name'], $this->module['name'],
$this->module['author'], $this->module['author'],
$this->module['type'], $this->module['type'],
$this->core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$this->core->auth->getinfo('user_name'), dcCore::app()->auth->getinfo('user_name'),
$this->core->auth->getInfo('user_email'), dcCore::app()->auth->getInfo('user_email'),
$this->core->auth->getInfo('user_url'), dcCore::app()->auth->getInfo('user_url'),
], ],
(string) $bloc (string) $bloc
) )

View file

@ -18,6 +18,7 @@ namespace plugins\improve\module;
use plugins\improve\action; use plugins\improve\action;
/* dotclear */ /* dotclear */
use dcCore;
use dcPage; use dcPage;
/* clearbricks */ /* clearbricks */
@ -67,9 +68,9 @@ class phpstan extends action
$ignored_vars = $this->getSetting('ignored_vars'); $ignored_vars = $this->getSetting('ignored_vars');
$this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : ''; $this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : '';
$this->core->auth->user_prefs->addWorkspace('interface'); dcCore::app()->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax; self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme; self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme;
return true; return true;
} }
@ -200,7 +201,6 @@ class phpstan extends action
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$this->setError(__('Failed to run phpstan')); $this->setError(__('Failed to run phpstan'));
pdump($e);
return false; return false;
} }

Binary file not shown.

View file

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace plugins\improve\module; namespace plugins\improve\module;
/* dotclear */
use dcCore;
/* improve */ /* improve */
use plugins\improve\action; use plugins\improve\action;
@ -111,8 +114,8 @@ class zip extends action
'</label></p>' . '</label></p>' .
'<p class="form-note">' . sprintf( '<p class="form-note">' . sprintf(
__('Preconization: %s'), __('Preconization: %s'),
$this->core->blog->public_path ? dcCore::app()->blog->public_path ?
path::real($this->core->blog->public_path) : __("Blog's public directory") path::real(dcCore::app()->blog->public_path) : __("Blog's public directory")
) . '</p> ) . '</p>
</div> </div>

View file

@ -21,6 +21,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
/* dotclear */ /* dotclear */
use dcCore; use dcCore;
use dcPage; use dcPage;
use dcAdminNotices;
use dcThemes; use dcThemes;
use dcUtils; use dcUtils;
@ -39,8 +40,6 @@ use Exception;
*/ */
class index class index
{ {
/** @var dcCore $core dcCore instance */
private $core = null;
/** @var improve $improve improve core instance */ /** @var improve $improve improve core instance */
private $improve = null; private $improve = null;
/** @var string $type Current module(s) type */ /** @var string $type Current module(s) type */
@ -50,12 +49,11 @@ class index
/** @var action|null $action Current action module */ /** @var action|null $action Current action module */
private $action = null; private $action = null;
public function __construct(dcCore $core) public function __construct()
{ {
dcPage::checkSuper(); dcPage::checkSuper();
$this->core = $core; $this->improve = new improve();
$this->improve = new improve($core);
$this->type = $this->getType(); $this->type = $this->getType();
$this->module = $this->getModule(); $this->module = $this->getModule();
$this->action = $this->getAction(); $this->action = $this->getAction();
@ -88,7 +86,7 @@ class index
{ {
try { try {
if (!empty($this->type)) { if (!empty($this->type)) {
$preferences = $this->core->blog->settings->improve->preferences; $preferences = dcCore::app()->blog->settings->improve->preferences;
if (is_string($preferences)) { if (is_string($preferences)) {
$preferences = unserialize($preferences); $preferences = unserialize($preferences);
if (is_array($preferences)) { if (is_array($preferences)) {
@ -113,8 +111,8 @@ class index
} }
} }
} }
$this->core->blog->settings->improve->put('preferences', serialize($preferences), 'string', null, true, true); dcCore::app()->blog->settings->improve->put('preferences', serialize($preferences), 'string', null, true, true);
dcPage::addSuccessNotice(__('Configuration successfully updated')); dcAdminNotices::addSuccessNotice(__('Configuration successfully updated'));
return true; return true;
} }
@ -124,19 +122,19 @@ class index
private function comboModules(): array private function comboModules(): array
{ {
$allow_distrib = (bool) $this->core->blog->settings->improve->allow_distrib; $allow_distrib = (bool) dcCore::app()->blog->settings->improve->allow_distrib;
$official = [ $official = [
'plugin' => explode(',', DC_DISTRIB_PLUGINS), 'plugin' => explode(',', DC_DISTRIB_PLUGINS),
'theme' => explode(',', DC_DISTRIB_THEMES), 'theme' => explode(',', DC_DISTRIB_THEMES),
]; ];
if (!isset($this->core->themes)) { if (!isset(dcCore::app()->themes)) {
$this->core->themes = new dcThemes($this->core); dcCore::app()->themes = new dcThemes();
$this->core->themes->loadModules($this->core->blog->themes_path, null); dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null);
} }
$combo_modules = []; $combo_modules = [];
$modules = $this->type == 'plugin' ? $this->core->plugins->getModules() : $this->core->themes->getModules(); $modules = $this->type == 'plugin' ? dcCore::app()->plugins->getModules() : dcCore::app()->themes->getModules();
foreach ($modules as $id => $m) { foreach ($modules as $id => $m) {
if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[$this->type])) { if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[$this->type])) {
continue; continue;
@ -155,41 +153,41 @@ class index
if (!empty($_POST['fix'])) { if (!empty($_POST['fix'])) {
if (empty($_POST['actions'])) { if (empty($_POST['actions'])) {
dcPage::addWarningNotice(__('No action selected')); dcAdminNotices::addWarningNotice(__('No action selected'));
} elseif ($this->module == '-') { } elseif ($this->module == '-') {
dcPage::addWarningNotice(__('No module selected')); dcAdminNotices::addWarningNotice(__('No module selected'));
} else { } else {
try { try {
$time = $this->improve->fixModule( $time = $this->improve->fixModule(
$this->type, $this->type,
$this->module, $this->module,
$this->type == 'plugin' ? $this->core->plugins->getModules($this->module) : $this->core->themes->getModules($this->module), $this->type == 'plugin' ? dcCore::app()->plugins->getModules($this->module) : dcCore::app()->themes->getModules($this->module),
$_POST['actions'] $_POST['actions']
); );
$log_id = $this->improve->writeLogs(); $log_id = $this->improve->writeLogs();
$this->core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
if ($this->improve->hasLog('error')) { if ($this->improve->hasLog('error')) {
$notice = ['type' => 'error', 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')];
} elseif ($this->improve->hasLog('warning')) { } elseif ($this->improve->hasLog('warning')) {
$notice = ['type' => 'warning', 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; $notice = ['type' => dcAdminNotices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')];
} elseif ($this->improve->hasLog('success')) { } elseif ($this->improve->hasLog('success')) {
$notice = ['type' => 'success', 'msg' => __('Fix of "%s" complete in %s secondes')]; $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes')];
} else { } else {
$notice = ['type' => 'success', 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes without messages')];
} }
dcPage::addNotice($notice['type'], sprintf($notice['msg'], $this->module, $time)); dcAdminNotices::addNotice($notice['type'], sprintf($notice['msg'], $this->module, $time));
$done = true; $done = true;
} catch (Exception $e) { } catch (Exception $e) {
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
$done = false; $done = false;
} }
} }
} }
if ($done) { if ($done) {
$this->core->adminurl->redirect('admin.plugin.improve', ['type' => $this->type, 'module' => $this->module, 'upd' => $log_id]); dcCore::app()->adminurl->redirect('admin.plugin.improve', ['type' => $this->type, 'module' => $this->module, 'upd' => $log_id]);
} }
} }
@ -221,27 +219,27 @@ class index
private function displayConfigurator(): void private function displayConfigurator(): void
{ {
$back_url = $_REQUEST['redir'] ?? $this->core->adminurl->get('admin.plugin.improve', ['type' => $this->type]); $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type]);
if (null === $this->action) { if (null === $this->action) {
echo ' echo '
<p class="warning">' . __('Unknow module') . '</p> <p class="warning">' . __('Unknow module') . '</p>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>'; <p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>';
} else { } else {
$redir = $_REQUEST['redir'] ?? $this->core->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $this->action->id()]); $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $this->action->id()]);
$res = $this->action->configure($redir); $res = $this->action->configure($redir);
echo ' echo '
<h3>' . sprintf(__('Configure module "%s"'), $this->action->name()) . '</h3> <h3>' . sprintf(__('Configure module "%s"'), $this->action->name()) . '</h3>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p> <p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>
<p class="info">' . html::escapeHTML($this->action->description()) . '</p> <p class="info">' . html::escapeHTML($this->action->description()) . '</p>
<form action="' . $this->core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' . <form action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
(empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . ' (empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . '
<p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' . <p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' .
form::hidden('type', $this->type) . form::hidden('type', $this->type) .
form::hidden('config', $this->action->id()) . form::hidden('config', $this->action->id()) .
form::hidden('redir', $redir) . form::hidden('redir', $redir) .
$this->core->formNonce() . '</p>' . dcCore::app()->formNonce() . '</p>' .
'</form>'; '</form>';
} }
} }
@ -249,7 +247,7 @@ class index
private function displayActions(): void private function displayActions(): void
{ {
echo echo
'<form method="get" action="' . $this->core->adminurl->get('admin.plugin.improve') . '" id="improve_menu">' . '<form method="get" action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" id="improve_menu">' .
'<p class="anchor-nav"><label for="type" class="classic">' . __('Goto:') . ' </label>' . '<p class="anchor-nav"><label for="type" class="classic">' . __('Goto:') . ' </label>' .
form::combo('type', [__('Plugins') => 'plugin', __('Themes') => 'theme'], $this->type) . ' ' . form::combo('type', [__('Plugins') => 'plugin', __('Themes') => 'theme'], $this->type) . ' ' .
'<input type="submit" value="' . __('Ok') . '" />' . '<input type="submit" value="' . __('Ok') . '" />' .
@ -260,7 +258,7 @@ class index
if (count($combo_modules) == 1) { if (count($combo_modules) == 1) {
echo '<p class="message">' . __('No module to manage') . '</p>'; echo '<p class="message">' . __('No module to manage') . '</p>';
} else { } else {
echo '<form action="' . $this->core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' . echo '<form action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
'<table><caption class="hidden">' . __('Actions') . '</caption><thead><tr>' . '<table><caption class="hidden">' . __('Actions') . '</caption><thead><tr>' .
'<th colspan="2" class="first">' . __('Action') . '</td>' . '<th colspan="2" class="first">' . __('Action') . '</td>' .
'<th scope="col">' . __('Description') . '</td>' . '<th scope="col">' . __('Description') . '</td>' .
@ -288,7 +286,7 @@ class index
'<td class="maximal">' . $action->description() . '</td>' . '<td class="maximal">' . $action->description() . '</td>' .
'<td class="minimal nowrap modules">' . ( '<td class="minimal nowrap modules">' . (
false === $action->configurator() ? '' : false === $action->configurator() ? '' :
'<a class="module-config" href="' . $this->core->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $action->id()]) . '<a class="module-config" href="' . dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $action->id()]) .
'" title="' . sprintf(__("Configure action '%s'"), $action->name()) . '">' . __('Configure') . '</a>' '" title="' . sprintf(__("Configure action '%s'"), $action->name()) . '">' . __('Configure') . '</a>'
) . '</td>' . ) . '</td>' .
(DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->priority() . '</span></td>' : '') . /* @phpstan-ignore-line */ (DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->priority() . '</span></td>' : '') . /* @phpstan-ignore-line */
@ -304,13 +302,13 @@ class index
form::combo('module', $combo_modules, $this->module) . form::combo('module', $combo_modules, $this->module) .
' <input type="submit" name="fix" value="' . __('Fix it') . '" />' . ' <input type="submit" name="fix" value="' . __('Fix it') . '" />' .
form::hidden(['type'], $this->type) . form::hidden(['type'], $this->type) .
$this->core->formNonce() . ' dcCore::app()->formNonce() . '
</p> </p>
</div> </div>
<br class="clear" /> <br class="clear" />
</form>'; </form>';
if (!empty($_REQUEST['upd']) && !$this->core->blog->settings->improve->nodetails) { if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->improve->nodetails) {
$logs = $this->improve->parseLogs((int) $_REQUEST['upd']); $logs = $this->improve->parseLogs((int) $_REQUEST['upd']);
if (!empty($logs)) { if (!empty($logs)) {
@ -341,4 +339,4 @@ class index
} }
/* process */ /* process */
new index($core); new index();