diff --git a/_init.php b/_init.php
index d7df0f1..927753b 100644
--- a/_init.php
+++ b/_init.php
@@ -19,6 +19,6 @@ class initEmailOptionnel
/** @var string Default email */
public const DEFAULT_EMAIL = 'invalid@invalid.fr';
- /** @var string This plugin setting name */
+ /** @var string NO MORE USED */
public const SETTING_NAME = 'emailoptionnel';
}
diff --git a/src/Backend.php b/src/Backend.php
index 628658c..504db8f 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -15,49 +15,42 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel;
use dcCore;
-use dcNsProcess;
use dcSettings;
+use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{
Checkbox,
Label,
Para
};
-class Backend extends dcNsProcess
+class Backend extends Process
{
public static function init(): bool
{
- static::$init = defined('DC_CONTEXT_ADMIN');
-
- return static::$init;
+ return self::status(My::checkContext(My::BACKEND));
}
public static function process(): bool
{
- if (!static::$init) {
+ if (!self::status()) {
return false;
}
- dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (): void {
- // nullsafe PHP < 8.0
- if (is_null(dcCore::app()->blog)) {
- return;
- }
-
+ dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings): void {
echo
'
' .
'
' . __('Optional e-mail address') . '
' .
(new Para())->__call('items', [[
- (new Checkbox(My::SETTING_NAME, (bool) dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')))->__call('value', [1]),
- (new Label(__('Make e-mail address optional in comments'), Label::OUTSIDE_LABEL_AFTER))->__call('for', [My::SETTING_NAME])->__call('class', ['classic']),
+ (new Checkbox(My::id() . '_enabled', (bool) $blog_settings->get(My::id())->get('enabled')))->__call('value', [1]),
+ (new Label(__('Make e-mail address optional in comments'), Label::OUTSIDE_LABEL_AFTER))->__call('for', [My::id() . '_enabled'])->__call('class', ['classic']),
]])->render() .
'';
});
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings): void {
- $blog_settings->get(My::SETTING_NAME)->put(
+ $blog_settings->get(My::id())->put(
'enabled',
- !empty($_POST[My::SETTING_NAME]),
+ !empty($_POST[My::id() . '_enabled']),
'boolean',
__('Make e-mail address optional in comments')
);
diff --git a/src/Frontend.php b/src/Frontend.php
index d8676fe..2233e9a 100644
--- a/src/Frontend.php
+++ b/src/Frontend.php
@@ -16,22 +16,19 @@ namespace Dotclear\Plugin\emailOptionnel;
use ArrayObject;
use dcCore;
-use dcNsProcess;
-use dcUtils;
+use Dotclear\Core\Process:
use Dotclear\Database\Cursor;
-class Frontend extends dcNsProcess
+class Frontend extends Process
{
public static function init(): bool
{
- static::$init = defined('DC_RC_PATH');
-
- return static::$init;
+ return self::status(My::checkContext(My::FRONTEND));
}
public static function process(): bool
{
- if (!static::$init) {
+ if (!self::status()) {
return false;
}
@@ -45,7 +42,7 @@ class Frontend extends dcNsProcess
if (!isset($_POST['c_content'])
|| !empty($_POST['preview'])
|| !empty($_POST['c_mail'])
- || !dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')
+ || !My::settings()->get('enabled')
) {
return;
}
@@ -57,7 +54,7 @@ class Frontend extends dcNsProcess
return;
}
- if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')
+ if (My::settings()->get('enabled')
&& $cur->getField('comment_email') == My::DEFAULT_EMAIL
) {
# désactive l'affichage du mail dans le template
@@ -85,16 +82,8 @@ class Frontend extends dcNsProcess
}
},
'publicHeadContent' => function (): void {
- // nullsafe PHP < 8.0
- if (is_null(dcCore::app()->blog)) {
- return;
- }
-
- if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')) {
- echo dcUtils::jsLoad(
- dcCore::app()->blog->getPF(My::id() . '/js/frontend.js'),
- dcCore::app()->plugins->moduleInfo(My::id(), 'version')
- );
+ if (My::settings()->get('enabled')) {
+ echo My::jsLoad('frontend', dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
}
},
]);
diff --git a/src/My.php b/src/My.php
index 8b43147..fbff05b 100644
--- a/src/My.php
+++ b/src/My.php
@@ -14,36 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel;
-use dcCore;
+use Dotclear\Module\MyPlugin;
/**
* This module definitions.
*/
-class My extends \initEmailOptionnel
+class My extends MyPlugin
{
- /**
- * This module id.
- */
- public static function id(): string
- {
- return basename(dirname(__DIR__));
- }
-
- /**
- * This module name.
- */
- public static function name(): string
- {
- $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
-
- return __(is_string($name) ? $name : self::id());
- }
-
- /**
- * This module path.
- */
- public static function path(): string
- {
- return dirname(__DIR__);
- }
+ /** @var string Default email */
+ public const DEFAULT_EMAIL = 'invalid@invalid.fr';
}
diff --git a/src/Uninstall.php b/src/Uninstall.php
index e97ce88..f6e1b4a 100644
--- a/src/Uninstall.php
+++ b/src/Uninstall.php
@@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel;
use dcCore;
-use dcNsProcess;
+use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller;
-class Uninstall extends dcNsProcess
+class Uninstall extends Process
{
public static function init(): bool
{
- static::$init = defined('DC_CONTEXT_ADMIN');
-
- return static::$init;
+ return self::status(My::checkContext(My::UNINSTALL));
}
public static function process(): bool
{
- if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
+ if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false;
}
@@ -37,7 +35,7 @@ class Uninstall extends dcNsProcess
->addUserAction(
'settings',
'delete_all',
- My::SETTING_NAME
+ My::id()
)
->addUserAction(
'plugins',
@@ -52,7 +50,7 @@ class Uninstall extends dcNsProcess
->addDirectAction(
'settings',
'delete_all',
- My::SETTING_NAME
+ My::id()
)
->addDirectAction(
'plugins',