rebuild namespace (ns playground)

master
Jean-Christian Paul Denis 2022-12-21 15:41:27 +01:00
parent c928eca287
commit bdd295d5ce
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
23 changed files with 360 additions and 333 deletions

View File

@ -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();

View File

@ -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 '<div class="fieldset"><h4>' . __('List of disabled actions:') . '</h4>';
foreach ($this->getModules() as $name => $id) {
foreach ($modules as $name => $id) {
echo
'<p><label class="classic" title="' . $id . '">' .
form::checkbox(['disabled[]'], $id, ['checked' => array_key_exists($id, $this->improve->disabled())]) .
form::checkbox(['disabled[]'], $id, ['checked' => array_key_exists($id, $improve->disabled())]) .
__($name) . '</label></p>';
}
echo
'</div><div class="fieldset"><h4>' . __('Options') . '</h4>' .
'<p><label class="classic">' .
form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->improve->nodetails]) .
form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->get(Core::id())->get('nodetails')]) .
__('Hide details of rendered actions') . '</label></p>' .
'</div>';
}
}
/* process */
new config();

View File

@ -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;
}

View File

@ -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 '<html><head><title>' . __('improve') . '</title>' .
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()) .
'</head><body>' .
dcPage::notices() .
dcPage::breadcrumb([
@ -224,64 +232,64 @@ class index
]);
if (empty($_REQUEST['config'])) {
$this->displayActions();
self::displayActions();
} else {
$this->displayConfigurator();
self::displayConfigurator();
}
echo '</body></html>';
}
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 '
<p class="warning">' . __('Unknow module') . '</p>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>';
} 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 '
<h3>' . sprintf(__('Configure module "%s"'), $this->action->name()) . '</h3>
<h3>' . sprintf(__('Configure module "%s"'), self::$action->name()) . '</h3>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>
<p class="info">' . html::escapeHTML($this->action->description()) . '</p>
<form action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
<p class="info">' . html::escapeHTML(self::$action->description()) . '</p>
<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . Core::id()) . '" method="post" id="form-actions">' .
(empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . '
<p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' .
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() . '</p>' .
'</form>';
}
}
private function displayActions(): void
private static function displayActions(): void
{
echo
'<form method="get" action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" id="improve_menu">' .
'<form method="get" action="' . dcCore::app()->adminurl->get('admin.plugin.' . Core::id()) . '" id="improve_menu">' .
'<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'], self::$type) . ' ' .
'<input type="submit" value="' . __('Ok') . '" />' .
form::hidden('p', 'improve') . '</p>' .
'</form>';
$combo_modules = $this->comboModules();
$combo_modules = self::comboModules();
if (count($combo_modules) == 1) {
echo '<p class="message">' . __('No module to manage') . '</p>';
} else {
echo '<form action="' . dcCore::app()->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
echo '<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . Core::id()) . '" method="post" id="form-actions">' .
'<table><caption class="hidden">' . __('Actions') . '</caption><thead><tr>' .
'<th colspan="2" class="first">' . __('Action') . '</td>' .
'<th scope="col">' . __('Description') . '</td>' .
'<th scope="col">' . __('Configuration') . '</td>' .
(DC_DEBUG ? '<th scope="col">' . __('Priority') . '</td>' : '') . /* @phpstan-ignore-line */
'</tr></thead><tbody>';
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
'<td class="maximal">' . $action->description() . '</td>' .
'<td class="minimal nowrap modules">' . (
false === $action->configurator() ? '' :
'<a class="module-config" href="' . dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $action->id()]) .
'<a class="module-config" href="' . dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type, 'config' => $action->id()]) .
'" title="' . sprintf(__("Configure action '%s'"), $action->name()) . '">' . __('Configure') . '</a>'
) . '</td>' .
(DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->priority() . '</span></td>' : '') . /* @phpstan-ignore-line */
@ -314,17 +322,17 @@ class index
form::checkbox('save_preferences', 1, !empty($_POST['save_preferences'])) .
__('Save fields selection as preference') . '</label></p>
<p class="col right"><label for="module" class="classic">' . __('Select a module:') . ' </label>' .
form::combo('module', $combo_modules, $this->module) .
form::combo('module', $combo_modules, self::$module) .
' <input type="submit" name="fix" value="' . __('Fix it') . '" />' .
form::hidden(['type'], $this->type) .
form::hidden(['type'], self::$type) .
dcCore::app()->formNonce() . '
</p>
</div>
<br class="clear" />
</form>';
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 '<div class="fieldset"><h4>' . __('Details') . '</h4>';
@ -333,7 +341,7 @@ class index
foreach ($types as $type => $tools) {
echo '<div class="' . $type . '"><ul>';
foreach ($tools as $tool => $msgs) {
$a = $this->improve->module($tool);
$a = self::$improve->module($tool);
if (null !== $a) {
echo '<li>' . $a->name() . '<ul>';
foreach ($msgs as $msg) {
@ -352,6 +360,3 @@ class index
}
}
}
/* process */
new index();

View File

@ -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();

View File

@ -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)
);

View File

@ -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<string> 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',

View File

@ -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, '&');
}
/**

View File

@ -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 = [];

View File

@ -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' => []];

View File

@ -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', ''],

View File

@ -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 = '';

View File

@ -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
{

View File

@ -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 = '';

View File

@ -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'));

View File

@ -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);
}

View File

@ -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<int,string> 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
'<p><label class="classic" for="phpexe_path">' .
@ -115,7 +116,7 @@ class phpcsfixer extends action
]) . '</p>' .
(
!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 {

View File

@ -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',

View File

@ -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 = <<<EOF

View File

@ -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 PHPStan
*/
class phpstan extends action
class phpstan extends Action
{
/** @var boolean User pref to use colored synthax */
protected static $user_ui_colorsyntax = false;
@ -69,8 +70,8 @@ class phpstan extends action
$this->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
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>' .
@ -134,7 +135,7 @@ class phpstan extends action
]) . '</p>' .
(
!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);

View File

@ -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 = <<<EOF

View File

@ -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;
/**
* Improve action module tab

View File

@ -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;