From bdd295d5ceaed19bf6f041d4103d3025f6ecfa0d Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 21 Dec 2022 15:41:27 +0100 Subject: [PATCH] rebuild namespace (ns playground) --- inc/Admin.php | 60 +++----- inc/Config.php | 65 ++++---- inc/Install.php | 55 ++++--- inc/Manage.php | 171 +++++++++++---------- inc/Prepend.php | 38 +++-- inc/Uninstall.php | 157 ++++++++++--------- inc/core/Action.php | 16 +- inc/core/Core.php | 15 +- inc/core/Module.php | 4 +- inc/module/dcdeprecated.php | 6 +- inc/module/dcdeprecated/dc2.21.php | 2 +- inc/module/dcstore.php | 6 +- inc/module/endoffile.php | 6 +- inc/module/gitshields.php | 6 +- inc/module/licensefile.php | 8 +- inc/module/newline.php | 10 +- inc/module/phpcsfixer.php | 19 +-- inc/module/phpcsfixer/phpcsfixer.rules.php | 8 +- inc/module/phpheader.php | 6 +- inc/module/phpstan.php | 21 +-- inc/module/po2php.php | 6 +- inc/module/tab.php | 4 +- inc/module/zip.php | 4 +- 23 files changed, 360 insertions(+), 333 deletions(-) diff --git a/inc/Admin.php b/inc/Admin.php index fddc4cd..7303a9b 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; - -if (!defined('DC_CONTEXT_ADMIN')) { - return; -} +namespace Dotclear\Plugin\improve; /* dotclear */ use dcAdmin; @@ -33,58 +29,52 @@ use files; * * Add menu and dashboard icons, load Improve action modules. */ -class admin +class Admin { - public static function process(): void + private static $init = false; + + public static function init(): bool { - self::addSettingsNamespace(); - self::addAdminBehaviors(); - self::addAdminMenu(); - self::addImproveActions(); + if (defined('DC_CONTEXT_ADMIN')) { + dcCore::app()->blog->settings->addNamespace(Core::id()); + self::$init = true; + } + + return self::$init; } - private static function addSettingsNamespace(): void + public static function process() { - dcCore::app()->blog->settings->addNamespace('improve'); - } + if (!self::$init) { + return false; + } - private static function addAdminBehaviors(): void - { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { $favs->register( 'improve', [ 'title' => __('improve'), - 'url' => dcCore::app()->adminurl->get('admin.plugin.improve'), - 'small-icon' => dcPage::getPF('improve/icon.svg'), - 'large-icon' => dcPage::getPF('improve/icon.svg'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . Core::id()), + 'small-icon' => dcPage::getPF(Core::id() . '/icon.svg'), + 'large-icon' => dcPage::getPF(Core::id() . '/icon.svg'), //'permissions' => null, ] ); }); - } - private static function addAdminMenu(): void - { dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('improve'), - dcCore::app()->adminurl->get('admin.plugin.improve'), - dcPage::getPF('improve/icon.svg'), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->adminurl->get('admin.plugin.' . Core::id()), + dcPage::getPF(Core::id() . '/icon.svg'), + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . Core::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth->isSuperAdmin() ); - } - private static function addImproveActions(): void - { - foreach (files::scandir(prepend::getActionsDir()) as $file) { - if (is_file(prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) { - Clearbricks::lib()->autoload([prepend::getActionsNS() . substr($file, 0, -4) => prepend::getActionsDir() . $file]); - dcCore::app()->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ + foreach (files::scandir(Prepend::getActionsDir()) as $file) { + if (is_file(Prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) { + Clearbricks::lib()->autoload([Prepend::getActionsNS() . substr($file, 0, -4) => Prepend::getActionsDir() . $file]); + dcCore::app()->addBehavior('improveAddAction', [Prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ } } } } - -/* process */ -admin::process(); diff --git a/inc/Config.php b/inc/Config.php index b52bf51..754fcd2 100644 --- a/inc/Config.php +++ b/inc/Config.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; - -if (!defined('DC_CONTEXT_ADMIN')) { - return; -} +namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; @@ -33,34 +29,28 @@ use Exception; * * Set preference for this plugin. */ -class config +class Config { - /** @var improve $improve improve core instance */ - private $improve = null; + private static $init = false; - public function __construct() + public static function init(): bool { - dcPage::checkSuper(); + if (defined('DC_CONTEXT_ADMIN')) { + dcPage::checkSuper(); - $this->improve = new improve(); - - $this->saveConfig(); - $this->displayConfig(); - } - - private function getModules(): array - { - $modules = []; - foreach ($this->improve->modules() as $action) { - $modules[$action->name()] = $action->id(); + dcCore::app()->blog->settings->addNamespace(Core::id()); + self::$init = true; } - $modules = array_merge($modules, array_flip($this->improve->disabled())); - return $modules; + return self::$init; } - private function saveConfig(): void + public static function process(): void { + if (!self::$init) { + return; + } + if (empty($_POST['save'])) { return; } @@ -70,8 +60,8 @@ class config if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) { $pdisabled = implode(';', $_POST['disabled']); } - dcCore::app()->blog->settings->improve->put('disabled', $pdisabled); - dcCore::app()->blog->settings->improve->put('nodetails', !empty($_POST['nodetails'])); + dcCore::app()->blog->settings->get(Core::id())->put('disabled', $pdisabled); + dcCore::app()->blog->settings->get(Core::id())->put('nodetails', !empty($_POST['nodetails'])); dcPage::addSuccessNotice(__('Configuration successfully updated')); @@ -84,24 +74,33 @@ class config } } - private function displayConfig(): void + public static function render() { + if (!self::$init) { + return; + } + + $improve = new Core(); + + $modules = []; + foreach ($improve->modules() as $action) { + $modules[$action->name()] = $action->id(); + } + $modules = array_merge($modules, array_flip($improve->disabled())); + echo '

' . __('List of disabled actions:') . '

'; - foreach ($this->getModules() as $name => $id) { + foreach ($modules as $name => $id) { echo '

'; } echo '

' . __('Options') . '

' . '

' . '
'; } } - -/* process */ -new config(); diff --git a/inc/Install.php b/inc/Install.php index 81a78da..31f5793 100644 --- a/inc/Install.php +++ b/inc/Install.php @@ -12,15 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve; - -if (!defined('DC_CONTEXT_ADMIN')) { - return; -} +namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; -use dcUtils; /* php */ use Exception; @@ -31,7 +26,7 @@ use Exception; * Set default settings and version * and manage changes on updates. */ -class install +class Install { /** @var array Improve default settings */ private static $default_settings = [[ @@ -41,26 +36,37 @@ class install 'string', ]]; + // Nothing to change below + private static $init = false; + + public static function init(): bool + { + self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version')); + + return self::$init; + } + public static function process(): ?bool { - if (!dcCore::app()->newVersion( - basename(__DIR__), - dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') - )) { - return null; + if (!self::$init) { + return false; } - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - self::update_0_8_0(); - self::putSettings(); + try { + self::update_0_8_0(); + self::putSettings(); + return true; + } catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); - return true; + return false; + } } private static function putSettings(): void { foreach (self::$default_settings as $v) { - dcCore::app()->blog->settings->__get(basename(__DIR__))->put( + dcCore::app()->blog->settings->get(Core::id())->put( $v[0], $v[2], $v[3], @@ -74,22 +80,13 @@ class install /** Update improve < 0.8 : action modules settings name */ private static function update_0_8_0(): void { - if (version_compare(dcCore::app()->getVersion(basename(__DIR__)) ?? '0', '0.8', '<')) { - foreach (dcCore::app()->blog->settings->__get(basename(__DIR__))->dumpGlobalSettings() as $id => $values) { + if (version_compare(dcCore::app()->getVersion(Core::id()) ?? '0', '0.8', '<')) { + foreach (dcCore::app()->blog->settings->get(Core::id())->dumpGlobalSettings() as $id => $values) { $newId = str_replace('ImproveAction', '', $id); if ($id != $newId) { - dcCore::app()->blog->settings->__get(basename(__DIR__))->rename($id, strtolower($newId)); + dcCore::app()->blog->settings->get(Core::id())->rename($id, strtolower($newId)); } } } } } - -/* process */ -try { - return install::process(); -} catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); - - return false; -} diff --git a/inc/Manage.php b/inc/Manage.php index d9981c1..c6b7645 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -12,11 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; - -if (!defined('DC_CONTEXT_ADMIN')) { - return; -} +namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; @@ -38,59 +34,63 @@ use Exception; * Display page and configure modules * and launch action. */ -class index +class Manage { /** @var improve $improve improve core instance */ - private $improve = null; + private static $improve = null; /** @var string $type Current module(s) type */ - private $type = 'plugin'; + private static $type = 'plugin'; /** @var string $module Current module id */ - private $module = '-'; + private static $module = '-'; /** @var action|null $action Current action module */ - private $action = null; + private static $action = null; - public function __construct() + private static $init = false; + + public static function init(): bool { - dcPage::checkSuper(); + if (defined('DC_CONTEXT_ADMIN')) { + dcPage::checkSuper(); - $this->improve = new improve(); - $this->type = $this->getType(); - $this->module = $this->getModule(); - $this->action = $this->getAction(); + self::$improve = new Core(); + self::$type = self::getType(); + self::$module = self::getModule(); + self::$action = self::getAction(); + self::$init = true; + } - $this->doAction(); - $this->displayPage(); + return self::$init; } - private function getType(): string + private static function getType(): string { return $_REQUEST['type'] ?? 'plugin'; } - private function getModule(): string + private static function getModule(): string { $module = $_REQUEST['module'] ?? ''; - if (!in_array($module, $this->comboModules())) { + if (!in_array($module, self::comboModules())) { $module = '-'; } return $module; } - private function getAction(): ?action + private static function getAction(): ?action { - return empty($_REQUEST['config']) ? null : $this->improve->module($_REQUEST['config']); + return empty($_REQUEST['config']) ? null : self::$improve->module($_REQUEST['config']); } - private function getPreference(): array + private static function getPreference(): array { try { - if (!empty($this->type)) { - $preferences = dcCore::app()->blog->settings->improve->preferences; + if (!empty(self::$type)) { + $preferences = dcCore::app()->blog->settings->get(Core::id())->get('preferences'); if (is_string($preferences)) { $preferences = unserialize($preferences); if (is_array($preferences)) { - return array_key_exists($this->type, $preferences) ? $preferences[$this->type] : []; + return array_key_exists(self::$type, $preferences) ? $preferences[self::$type] : []; } } } @@ -100,18 +100,18 @@ class index return []; } - private function setPreferences(): bool + private static function setPreferences(): bool { if (!empty($_POST['save_preferences'])) { - $preferences[$this->type] = []; + $preferences[self::$type] = []; if (!empty($_POST['actions'])) { - foreach ($this->improve->modules() as $action) { - if (in_array($this->type, $action->types()) && in_array($action->id(), $_POST['actions'])) { - $preferences[$this->type][] = $action->id(); + foreach (self::$improve->modules() as $action) { + if (in_array(self::$type, $action->types()) && in_array($action->id(), $_POST['actions'])) { + $preferences[self::$type][] = $action->id(); } } } - dcCore::app()->blog->settings->improve->put('preferences', serialize($preferences), 'string', null, true, true); + dcCore::app()->blog->settings->get(Core::id())->put('preferences', serialize($preferences), 'string', null, true, true); dcAdminNotices::addSuccessNotice(__('Configuration successfully updated')); return true; @@ -120,9 +120,9 @@ class index return false; } - private function comboModules(): array + private static function comboModules(): array { - $allow_distrib = (bool) dcCore::app()->blog->settings->improve->allow_distrib; + $allow_distrib = (bool) dcCore::app()->blog->settings->get(Core::id())->get('allow_distrib'); $official = [ 'plugin' => explode(',', DC_DISTRIB_PLUGINS), 'theme' => explode(',', DC_DISTRIB_THEMES), @@ -134,9 +134,9 @@ class index } $combo_modules = []; - $modules = self::getModules($this->type == 'plugin' ? 'plugins' : 'themes'); + $modules = self::getModules(self::$type == 'plugin' ? 'plugins' : 'themes'); 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[self::$type])) { continue; } $combo_modules[sprintf(__('%s (%s)'), __($m['name']), $id)] = $id; @@ -161,37 +161,41 @@ class index return null; } - private function doAction(): void + public static function process(): void { + if (!self::$init) { + return; + } + $log_id = ''; - $done = $this->setPreferences(); + $done = self::setPreferences(); if (!empty($_POST['fix'])) { if (empty($_POST['actions'])) { dcAdminNotices::addWarningNotice(__('No action selected')); - } elseif ($this->module == '-') { + } elseif (self::$module == '-') { dcAdminNotices::addWarningNotice(__('No module selected')); } else { try { - $time = $this->improve->fixModule( - $this->type, - $this->module, - self::getModules($this->type == 'plugin' ? 'plugins' : 'themes', $this->module), + $time = self::$improve->fixModule( + self::$type, + self::$module, + self::getModules(self::$type == 'plugin' ? 'plugins' : 'themes', self::$module), $_POST['actions'] ); - $log_id = $this->improve->writeLogs(); + $log_id = self::$improve->writeLogs(); dcCore::app()->blog->triggerBlog(); - if ($this->improve->hasLog('error')) { + if (self::$improve->hasLog('error')) { $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; - } elseif ($this->improve->hasLog('warning')) { + } elseif (self::$improve->hasLog('warning')) { $notice = ['type' => dcAdminNotices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; - } elseif ($this->improve->hasLog('success')) { + } elseif (self::$improve->hasLog('success')) { $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes')]; } else { $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; } - dcAdminNotices::addNotice($notice['type'], sprintf($notice['msg'], $this->module, $time)); + dcAdminNotices::addNotice($notice['type'], sprintf($notice['msg'], self::$module, $time)); $done = true; } catch (Exception $e) { @@ -202,19 +206,23 @@ class index } if ($done) { - dcCore::app()->adminurl->redirect('admin.plugin.improve', ['type' => $this->type, 'module' => $this->module, 'upd' => $log_id]); + dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); } } - private function displayPage(): void + public static function render(): void { + if (!self::$init) { + return; + } + $bc = empty($_REQUEST['config']) ? - ($this->type == 'theme' ? __('Themes actions') : __('Plugins actions')) : + (self::$type == 'theme' ? __('Themes actions') : __('Plugins actions')) : __('Configure module'); echo '' . __('improve') . '' . - dcPage::jsLoad(dcPage::getPF('improve/js/index.js')) . - ($this->action === null ? '' : $this->action->header()) . + dcPage::jsModuleLoad(Core::id() . '/js/index.js') . + (self::$action === null ? '' : self::$action->header()) . '' . dcPage::notices() . dcPage::breadcrumb([ @@ -224,64 +232,64 @@ class index ]); if (empty($_REQUEST['config'])) { - $this->displayActions(); + self::displayActions(); } else { - $this->displayConfigurator(); + self::displayConfigurator(); } echo ''; } - private function displayConfigurator(): void + private static function displayConfigurator(): void { - $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type]); + $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type]); - if (null === $this->action) { + if (null === self::$action) { echo '

' . __('Unknow module') . '

' . __('Back') . '

'; } else { - $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $this->action->id()]); - $res = $this->action->configure($redir); + $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type, 'config' => self::$action->id()]); + $res = self::$action->configure($redir); echo ' -

' . sprintf(__('Configure module "%s"'), $this->action->name()) . '

+

' . sprintf(__('Configure module "%s"'), self::$action->name()) . '

' . __('Back') . '

-

' . html::escapeHTML($this->action->description()) . '

-
' . +

' . html::escapeHTML(self::$action->description()) . '

+ ' . (empty($res) ? '

' . __('Nothing to configure') . '

' : $res) . '

' . - form::hidden('type', $this->type) . - form::hidden('config', $this->action->id()) . + form::hidden('type', self::$type) . + form::hidden('config', self::$action->id()) . form::hidden('redir', $redir) . dcCore::app()->formNonce() . '

' . '
'; } } - private function displayActions(): void + private static function displayActions(): void { echo - '
' . + '' . '

' . - form::combo('type', [__('Plugins') => 'plugin', __('Themes') => 'theme'], $this->type) . ' ' . + form::combo('type', [__('Plugins') => 'plugin', __('Themes') => 'theme'], self::$type) . ' ' . '' . form::hidden('p', 'improve') . '

' . '
'; - $combo_modules = $this->comboModules(); + $combo_modules = self::comboModules(); if (count($combo_modules) == 1) { echo '

' . __('No module to manage') . '

'; } else { - echo '
' . + echo '' . '' . ''; - foreach ($this->improve->modules() as $action) { - if (!in_array($this->type, $action->types())) { + foreach (self::$improve->modules() as $action) { + if (!in_array(self::$type, $action->types())) { continue; } echo @@ -290,7 +298,7 @@ class index ['actions[]', 'action_' . $action->id(), ], $action->id(), - in_array($action->id(), $this->getPreference()) && $action->isConfigured(), + in_array($action->id(), self::getPreference()) && $action->isConfigured(), '', '', !$action->isConfigured() @@ -301,7 +309,7 @@ class index '' . '' . (DC_DEBUG ? '' : '') . /* @phpstan-ignore-line */ @@ -314,17 +322,17 @@ class index form::checkbox('save_preferences', 1, !empty($_POST['save_preferences'])) . __('Save fields selection as preference') . '

' . - form::combo('module', $combo_modules, $this->module) . + form::combo('module', $combo_modules, self::$module) . ' ' . - form::hidden(['type'], $this->type) . + form::hidden(['type'], self::$type) . dcCore::app()->formNonce() . '


'; - if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->improve->nodetails) { - $logs = $this->improve->parseLogs((int) $_REQUEST['upd']); + if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->get(Core::id())->get('nodetails')) { + $logs = self::$improve->parseLogs((int) $_REQUEST['upd']); if (!empty($logs)) { echo '

' . __('Details') . '

'; @@ -333,7 +341,7 @@ class index foreach ($types as $type => $tools) { echo '
    '; foreach ($tools as $tool => $msgs) { - $a = $this->improve->module($tool); + $a = self::$improve->module($tool); if (null !== $a) { echo '
  • ' . $a->name() . '
      '; foreach ($msgs as $msg) { @@ -352,6 +360,3 @@ class index } } } - -/* process */ -new index(); diff --git a/inc/Prepend.php b/inc/Prepend.php index d559923..801afb5 100644 --- a/inc/Prepend.php +++ b/inc/Prepend.php @@ -12,14 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve; +namespace Dotclear\Plugin\improve; use Clearbricks; -if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) { - return; -} - /** * Improve prepend class * @@ -27,23 +23,39 @@ if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) { */ class prepend { - public static function process(): void + private static $init = false; + + public static function init(): bool { - foreach (['improve', 'action', 'module'] as $class) { - Clearbricks::lib()->autoload(['plugins\\improve\\' . $class => __DIR__ . '/inc/core/' . $class . '.php']); + self::$init = defined('DC_RC_PATH') && defined('DC_CONTEXT_ADMIN'); + + return self::$init; + } + + public static function process() + { + if (!self::$init) { + return false; + } + + // Core plugin class + foreach (['Core', 'Action', 'Module'] as $class) { + Clearbricks::lib()->autoload(['Dotclear\\Plugin\\improve\\' . $class => implode(DIRECTORY_SEPARATOR, [__DIR__, 'core', $class . '.php'])]); + } + + // Dotclear plugin class + foreach (['Admin', 'Config', 'Install', 'Manage', 'Prepend', 'Uninstall'] as $class) { + Clearbricks::lib()->autoload(['Dotclear\\Plugin\\improve\\' . $class => implode(DIRECTORY_SEPARATOR, [__DIR__, $class . '.php'])]); } } public static function getActionsDir(): string { - return __DIR__ . '/inc/module/'; + return __DIR__ . '/module/'; } public static function getActionsNS(): string { - return 'plugins\\improve\\module\\'; + return 'Dotclear\\Plugin\\improve\\Module\\'; } } - -/* process */ -prepend::process(); diff --git a/inc/Uninstall.php b/inc/Uninstall.php index 979f815..49abd65 100644 --- a/inc/Uninstall.php +++ b/inc/Uninstall.php @@ -10,74 +10,91 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; +declare(strict_types=1); + +namespace Dotclear\Plugin\improve; + +class Uninstall +{ + private static $init = false; + + public static function init(): bool + { + self::$init = defined('DC_RC_PATH'); + + return self::$init; + } + + public static function process($uninstaller) + { + if (!self::$init) { + return false; + } + + $uninstaller->addUserAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + Core::id(), + /* desc */ + __('delete all settings') + ); + + $uninstaller->addUserAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + __('delete plugin files') + ); + + $uninstaller->addUserAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + __('delete the version number') + ); + + $uninstaller->addDirectAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete all %s settings'), Core::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete %s plugin files'), Core::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + Core::id(), + /* desc */ + sprintf(__('delete %s version number'), Core::id()) + ); + } } - -$mod_id = 'improve'; - -$this->addUserAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - $mod_id, - /* desc */ - __('delete all settings') -); - -$this->addUserAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - $mod_id, - /* desc */ - __('delete plugin files') -); - -$this->addUserAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - $mod_id, - /* desc */ - __('delete the version number') -); - -$this->addDirectAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - $mod_id, - /* desc */ - sprintf(__('delete all %s settings'), $mod_id) -); - -$this->addDirectAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - $mod_id, - /* desc */ - sprintf(__('delete %s plugin files'), $mod_id) -); - -$this->addDirectAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - $mod_id, - /* desc */ - sprintf(__('delete %s version number'), $mod_id) -); diff --git a/inc/core/Action.php b/inc/core/Action.php index 7fb0b1f..d94e7fe 100644 --- a/inc/core/Action.php +++ b/inc/core/Action.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; +namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; @@ -22,7 +22,7 @@ use dcPage; use http; /* php */ -use arrayObject; +use ArrayObject; /** * Improve action class helper @@ -34,7 +34,7 @@ use arrayObject; * then function init() of your class wil be called. * One class must manage only one action. */ -abstract class action +abstract class Action { /** @var array Current module */ protected $module = []; @@ -83,9 +83,9 @@ abstract class action */ final public function __construct() { - $this->class_name = str_replace(prepend::getActionsNS(), '', get_called_class()); + $this->class_name = str_replace(Prepend::getActionsNS(), '', get_called_class()); - $settings = dcCore::app()->blog->settings->improve->get('settings_' . $this->class_name); + $settings = dcCore::app()->blog->settings->get(Core::id())->get('settings_' . $this->class_name); if (null != $settings) { $settings = unserialize($settings); } @@ -94,7 +94,7 @@ abstract class action $this->init(); // can overload priority by settings - if (1 < ($p = (int) dcCore::app()->blog->settings->improve->get('priority_' . $this->class_name))) { + if (1 < ($p = (int) dcCore::app()->blog->settings->get(Core::id())->get('priority_' . $this->class_name))) { $this->priority = $p; } } @@ -104,7 +104,7 @@ abstract class action * * @param ArrayObject $list ArrayObject of actions list */ - final public static function create(arrayObject $list): void + final public static function create(ArrayObject $list): void { $child = static::class; $class = new $child(); @@ -235,7 +235,7 @@ abstract class action */ final protected function redirect(string $url): bool { - dcCore::app()->blog->settings->improve->put( + dcCore::app()->blog->settings->get(Core::id())->put( 'settings_' . $this->class_name, serialize($this->settings), 'string', diff --git a/inc/core/Core.php b/inc/core/Core.php index 91943b8..46d3ec7 100644 --- a/inc/core/Core.php +++ b/inc/core/Core.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; +namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; @@ -29,7 +29,7 @@ use Exception; /** * Improve main class */ -class improve +class Core { /** @var array Allowed file extensions to open */ private static $readfile_extensions = [ @@ -53,7 +53,7 @@ class improve */ public function __construct() { - $disabled = explode(';', (string) dcCore::app()->blog->settings->improve->disabled); + $disabled = explode(';', (string) dcCore::app()->blog->settings->get(self::id())->get('disabled')); $list = new ArrayObject(); try { @@ -74,6 +74,11 @@ class improve uasort($this->actions, [$this, 'sortModules']); } + public static function id() + { + return basename(dirname(dirname(__DIR__))); + } + public function getLogs(): array { return $this->logs; @@ -183,7 +188,7 @@ class improve public function fixModule(string $type, string $id, array $properties, array $actions): float { $time_start = microtime(true); - $module = module::clean($type, $id, $properties); + $module = Module::clean($type, $id, $properties); $workers = []; foreach ($actions as $action) { @@ -303,7 +308,7 @@ class improve public function getURL(array $params = []): string { - return dcCore::app()->adminurl->get('admin.plugin.improve', $params, '&'); + return dcCore::app()->adminurl->get('admin.plugin.' . self::id(), $params, '&'); } /** diff --git a/inc/core/Module.php b/inc/core/Module.php index ff256b4..18ee735 100644 --- a/inc/core/Module.php +++ b/inc/core/Module.php @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace plugins\improve; +namespace Dotclear\Plugin\improve; /* clearbricks */ use path; @@ -23,7 +23,7 @@ use path; * Help to load module configuration file (_define.php) * and gather information about it. */ -class module +class Module { /** @var array Current module properties */ private $properties = []; diff --git a/inc/module/dcdeprecated.php b/inc/module/dcdeprecated.php index 4265838..2c0e21d 100644 --- a/inc/module/dcdeprecated.php +++ b/inc/module/dcdeprecated.php @@ -12,10 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use files; @@ -24,7 +24,7 @@ use path; /** * Improve action module Dotclear depreciated */ -class dcdeprecated extends action +class dcdeprecated extends Action { /** @var array Deprecated functions [filetype [pattern, deprecated, replacement, version, help link]] */ private $deprecated = ['php' => [], 'js' => []]; diff --git a/inc/module/dcdeprecated/dc2.21.php b/inc/module/dcdeprecated/dc2.21.php index b526b3f..9dae5f0 100644 --- a/inc/module/dcdeprecated/dc2.21.php +++ b/inc/module/dcdeprecated/dc2.21.php @@ -44,7 +44,7 @@ return [ ['three-cols', 'three-cols', 'three-boxes', '2.6', ''], ], - 'js' => [ + 'js' => [ ['\sstoreLocalData', 'storeLocalData', 'dotclear.storeLocalData', '2.21', ''], ['\sdropLocalData', 'dropLocalData', 'dotclear.dropLocalData', '2.21', ''], ['\sreadLocalData', 'readLocalData', 'dotclear.readLocalData', '2.21', ''], diff --git a/inc/module/dcstore.php b/inc/module/dcstore.php index 6414fcc..492784c 100644 --- a/inc/module/dcstore.php +++ b/inc/module/dcstore.php @@ -12,10 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use form; @@ -30,7 +30,7 @@ use Exception; /** * Improve action module dcstore.xml */ -class dcstore extends action +class dcstore extends Action { /** @var string Settings dcstore zip url pattern */ private $pattern = ''; diff --git a/inc/module/endoffile.php b/inc/module/endoffile.php index 96c2b25..c5a0046 100644 --- a/inc/module/endoffile.php +++ b/inc/module/endoffile.php @@ -12,10 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use form; @@ -23,7 +23,7 @@ use form; /** * Improve action module end of file */ -class endoffile extends action +class endoffile extends Action { protected function init(): bool { diff --git a/inc/module/gitshields.php b/inc/module/gitshields.php index e9270d0..ec9d76f 100644 --- a/inc/module/gitshields.php +++ b/inc/module/gitshields.php @@ -12,13 +12,13 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* dotclear */ use dcCore; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use form; @@ -26,7 +26,7 @@ use form; /** * Improve action module Github shields.io */ -class gitshields extends action +class gitshields extends Action { /** @var string Username of git repo */ private $username = ''; diff --git a/inc/module/licensefile.php b/inc/module/licensefile.php index a5085c8..6dd569b 100644 --- a/inc/module/licensefile.php +++ b/inc/module/licensefile.php @@ -12,10 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use form; @@ -27,7 +27,7 @@ use Exception; /** * Improve action module license file */ -class licensefile extends action +class licensefile extends Action { /** @var array Possible license filenames */ protected static $license_filenames = [ @@ -115,7 +115,7 @@ class licensefile extends action private function writeFullLicense(): ?bool { try { - $full = file_get_contents(dirname(__FILE__) . '/licensefile/' . $this->getSetting('action_version') . '.full.txt'); + $full = file_get_contents(__DIR__ . '/licensefile/' . $this->getSetting('action_version') . '.full.txt'); if (empty($full)) { $this->setError(__('Failed to load license content')); diff --git a/inc/module/newline.php b/inc/module/newline.php index e36b727..200a2e6 100644 --- a/inc/module/newline.php +++ b/inc/module/newline.php @@ -12,11 +12,11 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; -use plugins\improve\improve; +use Dotclear\Plugin\improve\Action; +use Dotclear\Plugin\improve\Core; /* clearbricks */ use form; @@ -24,7 +24,7 @@ use form; /** * Improve action module new line */ -class newline extends action +class newline extends Action { protected function init(): bool { @@ -56,7 +56,7 @@ class newline extends action if (!empty($_POST['save']) && !empty($_POST['newline_extensions'])) { $this->setSettings( 'extensions', - improve::cleanExtensions($_POST['newline_extensions']) + Core::cleanExtensions($_POST['newline_extensions']) ); $this->redirect($url); } diff --git a/inc/module/phpcsfixer.php b/inc/module/phpcsfixer.php index 9273db3..ebf6d7a 100644 --- a/inc/module/phpcsfixer.php +++ b/inc/module/phpcsfixer.php @@ -12,10 +12,11 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; +use Dotclear\Plugin\improve\Core; /* dotclear */ use dcCore; @@ -32,7 +33,7 @@ use Exception; /** * Improve action module PHP CS Fixer */ -class phpcsfixer extends action +class phpcsfixer extends Action { /** @var array Type of runtime errors */ protected static $errors = [ @@ -68,8 +69,8 @@ class phpcsfixer extends action $this->getPhpPath(); dcCore::app()->auth->user_prefs->addWorkspace('interface'); - self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax; - self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme; + self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); + self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); return true; } @@ -96,7 +97,7 @@ class phpcsfixer extends action ]); $this->redirect($url); } - $content = (string) file_get_contents(dirname(__FILE__) . '/phpcsfixer/phpcsfixer.rules.php'); + $content = (string) file_get_contents(__DIR__ . '/phpcsfixer/phpcsfixer.rules.php'); return '

      ' . ( !self::$user_ui_colorsyntax ? '' : - dcPage::jsLoad(dcPage::getPF('improve/inc/module/phpcsfixer/phpcsfixer.improve.js')) . + dcPage::jsModuleLoad(Core::id() . '/inc/module/phpcsfixer/phpcsfixer.improve.js') . dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', self::$user_ui_colorsyntax_theme) ); } @@ -125,9 +126,9 @@ class phpcsfixer extends action $command = sprintf( '%sphp %s/phpcsfixer/libs/php-cs-fixer.phar fix %s --config=%s/phpcsfixer/phpcsfixer.rules.php --using-cache=no', $this->phpexe_path, - dirname(__FILE__), + __DIR__, $this->module['sroot'], - dirname(__FILE__) + __DIR__ ); try { diff --git a/inc/module/phpcsfixer/phpcsfixer.rules.php b/inc/module/phpcsfixer/phpcsfixer.rules.php index 0797d3f..de84988 100644 --- a/inc/module/phpcsfixer/phpcsfixer.rules.php +++ b/inc/module/phpcsfixer/phpcsfixer.rules.php @@ -23,10 +23,10 @@ $config = new PhpCsFixer\Config(); /* @phpstan-ignore-next-line */ return $config ->setRules([ - '@PSR12' => true, - '@PHP81Migration' => true, - 'array_indentation' => true, - 'binary_operator_spaces' => [ + '@PSR12' => true, + '@PHP81Migration' => true, + 'array_indentation' => true, + 'binary_operator_spaces' => [ 'default' => 'align_single_space_minimal', 'operators' => [ '=>' => 'align_single_space_minimal', diff --git a/inc/module/phpheader.php b/inc/module/phpheader.php index a81e353..46f3ce4 100644 --- a/inc/module/phpheader.php +++ b/inc/module/phpheader.php @@ -12,13 +12,13 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* dotclear */ use dcCore; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use form; @@ -30,7 +30,7 @@ use Exception; /** * Improve action module php header */ -class phpheader extends action +class phpheader extends Action { /** @var string Exemple of header */ private static $exemple = <<ignored_vars = is_string($ignored_vars) ? $ignored_vars : ''; dcCore::app()->auth->user_prefs->addWorkspace('interface'); - self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax; - self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme; + self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); + self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); return true; } @@ -100,7 +101,7 @@ class phpstan extends action ]); $this->redirect($url); } - $content = (string) file_get_contents(dirname(__FILE__) . '/phpstan/phpstan.rules.conf'); + $content = (string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.conf'); return '

      ' . __('You must enable improve details to view analyse results !') . '

      ' . @@ -134,7 +135,7 @@ class phpstan extends action ]) . '

      ' . ( !self::$user_ui_colorsyntax ? '' : - dcPage::jsLoad(dcPage::getPF('improved/inc/module/phpstan/phpstan.improve.js')) . + dcPage::jsModuleLoad(Core::id() . '/inc/module/phpstan/phpstan.improve.js') . dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', self::$user_ui_colorsyntax_theme) ); } @@ -182,7 +183,7 @@ class phpstan extends action $command = sprintf( '%sphp %s/phpstan/libs/phpstan.phar analyse ' . $path . '--configuration=%s', $this->phpexe_path, - dirname(__FILE__), + __DIR__, DC_VAR . '/phpstan.neon' ); @@ -238,9 +239,9 @@ class phpstan extends action $this->run_level, $this->module['sroot'], DC_ROOT, - dirname(__FILE__) . '/phpstan', + __DIR__ . '/phpstan', ], - (string) file_get_contents(dirname(__FILE__) . '/phpstan/phpstan.rules.conf') + (string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.conf') ); $ignored = explode(';', $this->ignored_vars); diff --git a/inc/module/po2php.php b/inc/module/po2php.php index 58262f7..bae84fc 100644 --- a/inc/module/po2php.php +++ b/inc/module/po2php.php @@ -12,10 +12,10 @@ */ declare(strict_types=1); -namespace plugins\improve\module; +namespace Dotclear\Plugin\improve\Module; /* improve */ -use plugins\improve\action; +use Dotclear\Plugin\improve\Action; /* clearbricks */ use l10n; @@ -25,7 +25,7 @@ use l10n; /** * Improve action module dcstore.xml */ -class po2php extends action +class po2php extends Action { /** @var string License bloc */ private $license = <<
' . __('Action') . '' . '' . __('Description') . '' . '' . __('Configuration') . '' . (DC_DEBUG ? '' . __('Priority') . '' : '') . /* @phpstan-ignore-line */ '
' . $action->description() . '' . ( false === $action->configurator() ? '' : - 'name()) . '">' . __('Configure') . '' ) . '' . $action->priority() . '