From 061b69e803abe863778464c4bfc00fef0cfa46fd Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis
Date: Sat, 18 Mar 2023 23:04:27 +0100
Subject: [PATCH] use My class for plugin def
---
src/Action.php | 6 +++---
src/Backend.php | 18 ++++++++---------
src/Config.php | 8 ++++----
src/Core.php | 24 +++++++++++-----------
src/Install.php | 14 ++++++-------
src/Manage.php | 30 ++++++++++++++--------------
src/My.php | 42 +++++++++++++++++++++++++++++++++++++++
src/module/phpcsfixer.php | 4 ++--
src/module/phpstan.php | 4 ++--
9 files changed, 96 insertions(+), 54 deletions(-)
create mode 100644 src/My.php
diff --git a/src/Action.php b/src/Action.php
index 843060d..e2050c2 100644
--- a/src/Action.php
+++ b/src/Action.php
@@ -85,7 +85,7 @@ abstract class Action
{
$this->class_name = str_replace(Utils::getActionsNS(), '', get_called_class());
- $settings = dcCore::app()->blog->settings->get(Core::id())->get('settings_' . $this->class_name);
+ $settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name);
if (null != $settings) {
$settings = json_decode($settings, true);
}
@@ -94,7 +94,7 @@ abstract class Action
$this->init();
// can overload priority by settings
- if (1 < ($p = (int) dcCore::app()->blog->settings->get(Core::id())->get('priority_' . $this->class_name))) {
+ if (1 < ($p = (int) dcCore::app()->blog->settings->get(My::id())->get('priority_' . $this->class_name))) {
$this->priority = $p;
}
}
@@ -235,7 +235,7 @@ abstract class Action
*/
final protected function redirect(string $url): bool
{
- dcCore::app()->blog->settings->get(Core::id())->put(
+ dcCore::app()->blog->settings->get(My::id())->put(
'settings_' . $this->class_name,
json_encode($this->settings),
'string',
diff --git a/src/Backend.php b/src/Backend.php
index 38cbd5a..aa243fe 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -49,22 +49,22 @@ class Backend extends dcNsProcess
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(
- Core::id(),
+ My::id(),
[
- 'title' => Core::name(),
- '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'),
+ 'title' => My::name(),
+ 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
+ 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
+ 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
//'permissions' => null,
]
);
});
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
- Core::name(),
- 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']),
+ My::name(),
+ dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
+ dcPage::getPF(My::id() . '/icon.svg'),
+ preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);
diff --git a/src/Config.php b/src/Config.php
index ed9d42b..cf23682 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -65,14 +65,14 @@ class Config extends dcNsProcess
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
$pdisabled = implode(';', $_POST['disabled']);
}
- dcCore::app()->blog->settings->get(Core::id())->put('disabled', $pdisabled);
- dcCore::app()->blog->settings->get(Core::id())->put('nodetails', !empty($_POST['nodetails']));
+ dcCore::app()->blog->settings->get(My::id())->put('disabled', $pdisabled);
+ dcCore::app()->blog->settings->get(My::id())->put('nodetails', !empty($_POST['nodetails']));
dcPage::addSuccessNotice(__('Configuration successfully updated'));
dcCore::app()->adminurl->redirect(
'admin.plugins',
- ['module' => Core::id(), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
+ ['module' => My::id(), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@@ -106,7 +106,7 @@ class Config extends dcNsProcess
(new Fieldset())->class('fieldset')->legend(new Legend(__('List of disabled actions')))->fields($items),
(new Fieldset())->class('fieldset')->legend(new Legend(__('Options')))->fields([
(new Para())->items([
- (new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(Core::id())->get('nodetails')))->value('1'),
+ (new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'),
(new Label(__('Hide details of rendered actions')))->class('classic')->for('nodetails'),
]),
]),
diff --git a/src/Core.php b/src/Core.php
index dd5ef3a..50f2bab 100644
--- a/src/Core.php
+++ b/src/Core.php
@@ -53,7 +53,7 @@ class Core
*/
public function __construct()
{
- $disabled = explode(';', (string) dcCore::app()->blog->settings->get(self::id())->get('disabled'));
+ $disabled = explode(';', (string) dcCore::app()->blog->settings->get(My::id())->get('disabled'));
$list = new ArrayObject();
try {
@@ -74,14 +74,14 @@ class Core
uasort($this->actions, [$this, 'sortModules']);
}
- public static function id()
+ public static function id(): string
{
return basename(dirname(__DIR__));
}
- public static function name()
+ public static function name(): string
{
- return __('improve');
+ return __((string) dcCore::app()->plugins->moduleInfo(My::id(), 'name'));
}
public function getLogs(): array
@@ -101,7 +101,7 @@ class Core
}
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcLog::LOG_TABLE_NAME);
$cur->log_msg = json_encode($this->logs);
- $cur->log_table = self::id();
+ $cur->log_table = My::id();
$id = dcCore::app()->log->addLog($cur);
return $id;
@@ -109,7 +109,7 @@ class Core
public function readLogs(int $id): array
{
- $rs = dcCore::app()->log->getLogs(['log_table' => self::id(), 'log_id' => $id, 'limit' => 1]);
+ $rs = dcCore::app()->log->getLogs(['log_table' => My::id(), 'log_id' => $id, 'limit' => 1]);
if ($rs->isEmpty()) {
return [];
}
@@ -120,14 +120,14 @@ class Core
return is_array($res) ? $res : [];
}
- public function parselogs(int $id): array
+ public function parseLogs(int $id): array
{
$logs = $this->readLogs($id);
if (empty($logs)) {
return [];
}
$lines = [];
- foreach ($logs[self::id()] as $path => $tools) {
+ foreach ($logs[My::id()] as $path => $tools) {
$l_types = [];
foreach (['success', 'warning', 'error'] as $type) {
$l_tools = [];
@@ -203,7 +203,7 @@ class Core
}
foreach ($workers as $action) {
// trace all path and action in logs
- $this->logs[self::id()][__('Begin')][] = $action->id();
+ $this->logs[My::id()][__('Begin')][] = $action->id();
// info: set current module
$action->setModule($module);
$action->setPath(__('Begin'), '', true);
@@ -220,7 +220,7 @@ class Core
}
foreach ($workers as $action) {
// trace all path and action in logs
- $this->logs[self::id()][$file[0]][] = $action->id();
+ $this->logs[My::id()][$file[0]][] = $action->id();
// info: set current path
$action->setPath($file[0], $file[1], $file[2]);
}
@@ -259,7 +259,7 @@ class Core
}
foreach ($workers as $action) {
// trace all path and action in logs
- $this->logs[self::id()][__('End')][] = $action->id();
+ $this->logs[My::id()][__('End')][] = $action->id();
// info: set current module
$action->setPath(__('End'), '', true);
// action: close module
@@ -313,7 +313,7 @@ class Core
public function getURL(array $params = []): string
{
- return dcCore::app()->adminurl->get('admin.plugin.' . self::id(), $params, '&');
+ return dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $params, '&');
}
/**
diff --git a/src/Install.php b/src/Install.php
index 8c3af44..a873835 100644
--- a/src/Install.php
+++ b/src/Install.php
@@ -40,7 +40,7 @@ class Install extends dcNsProcess
public static function init(): bool
{
- self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version'));
+ self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return self::$init;
}
@@ -67,7 +67,7 @@ class Install extends dcNsProcess
private static function putSettings(): void
{
foreach (self::$default_settings as $v) {
- dcCore::app()->blog->settings->get(Core::id())->put(
+ dcCore::app()->blog->settings->get(My::id())->put(
$v[0],
$v[2],
$v[3],
@@ -81,11 +81,11 @@ class Install extends dcNsProcess
/** Update improve < 0.8 : action modules settings name */
private static function update_0_8_0(): void
{
- if (version_compare(dcCore::app()->getVersion(Core::id()) ?? '0', '0.8', '<')) {
- foreach (dcCore::app()->blog->settings->get(Core::id())->dumpGlobalSettings() as $id => $values) {
+ if (version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) {
+ foreach (dcCore::app()->blog->settings->get(My::id())->dumpGlobalSettings() as $id => $values) {
$newId = str_replace('ImproveAction', '', $id);
if ($id != $newId) {
- dcCore::app()->blog->settings->get(Core::id())->rename($id, strtolower($newId));
+ dcCore::app()->blog->settings->get(My::id())->rename($id, strtolower($newId));
}
}
}
@@ -94,11 +94,11 @@ class Install extends dcNsProcess
/** Update improve < 1.1 : use json_(en|de)code rather than (un)serialize */
private static function update_1_1_0(): void
{
- if (version_compare(dcCore::app()->getVersion(Core::id()) ?? '0', '1.1', '<')) {
+ if (version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '1.1', '<')) {
foreach (['setting_', 'preferences'] as $key) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
- "WHERE setting_ns = '" . dcCore::app()->con->escape(Core::id()) . "' " .
+ "WHERE setting_ns = '" . dcCore::app()->con->escape(My::id()) . "' " .
"AND setting_id LIKE '" . $key . "%' "
);
diff --git a/src/Manage.php b/src/Manage.php
index b01c898..182082e 100644
--- a/src/Manage.php
+++ b/src/Manage.php
@@ -87,7 +87,7 @@ class Manage extends dcNsProcess
{
try {
if (!empty(self::$type)) {
- $preferences = dcCore::app()->blog->settings->get(Core::id())->get('preferences');
+ $preferences = dcCore::app()->blog->settings->get(My::id())->get('preferences');
if (is_string($preferences)) {
$preferences = json_decode($preferences, true);
if (is_array($preferences)) {
@@ -113,7 +113,7 @@ class Manage extends dcNsProcess
}
}
}
- dcCore::app()->blog->settings->get(Core::id())->put('preferences', json_encode($preferences), 'string', null, true, true);
+ dcCore::app()->blog->settings->get(My::id())->put('preferences', json_encode($preferences), 'string', null, true, true);
dcAdminNotices::addSuccessNotice(__('Configuration successfully updated'));
return true;
@@ -124,7 +124,7 @@ class Manage extends dcNsProcess
private static function comboModules(): array
{
- $allow_distrib = (bool) dcCore::app()->blog->settings->get(Core::id())->get('allow_distrib');
+ $allow_distrib = (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib');
$official = [
'plugin' => explode(',', DC_DISTRIB_PLUGINS),
'theme' => explode(',', DC_DISTRIB_THEMES),
@@ -208,7 +208,7 @@ class Manage extends dcNsProcess
}
if ($done) {
- dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]);
+ dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]);
}
return true;
@@ -221,15 +221,15 @@ class Manage extends dcNsProcess
}
dcPage::openModule(
- Core::name(),
- dcPage::jsModuleLoad(Core::id() . '/js/index.js') .
+ My::name(),
+ dcPage::jsModuleLoad(My::id() . '/js/index.js') .
(self::$action === null ? '' : self::$action->header())
);
echo
dcPage::breadcrumb([
__('Plugins') => '',
- Core::name() => '',
+ My::name() => '',
empty($_REQUEST['config']) ? (self::$type == 'theme' ? __('Themes actions') : __('Plugins actions')) : __('Configure module') => '',
]) .
dcPage::notices();
@@ -245,21 +245,21 @@ class Manage extends dcNsProcess
private static function displayConfigurator(): void
{
- $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type]);
+ $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type]);
if (null === self::$action) {
echo '
' . __('Unknow module') . '
' . __('Back') . '
';
} else {
- $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type, 'config' => self::$action->id()]);
+ $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$action->id()]);
$res = self::$action->configure($redir);
echo '
' . sprintf(__('Configure module "%s"'), self::$action->name()) . '
' . __('Back') . '
' . html::escapeHTML(self::$action->description()) . '
-
' .
'';
$combo_modules = self::comboModules();
if (count($combo_modules) == 1) {
echo '' . __('No module to manage') . '
';
} else {
- echo '