upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian Paul Denis 2023-08-12 18:52:47 +02:00
parent 961db69605
commit 34e98978f0
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
5 changed files with 28 additions and 71 deletions

View File

@ -19,6 +19,6 @@ class initEmailOptionnel
/** @var string Default email */ /** @var string Default email */
public const DEFAULT_EMAIL = 'invalid@invalid.fr'; public const DEFAULT_EMAIL = 'invalid@invalid.fr';
/** @var string This plugin setting name */ /** @var string NO MORE USED */
public const SETTING_NAME = 'emailoptionnel'; public const SETTING_NAME = 'emailoptionnel';
} }

View File

@ -15,49 +15,42 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel; namespace Dotclear\Plugin\emailOptionnel;
use dcCore; use dcCore;
use dcNsProcess;
use dcSettings; use dcSettings;
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Label, Label,
Para Para
}; };
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::BACKEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (): void { dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return;
}
echo echo
'<div class="fieldset">' . '<div class="fieldset">' .
'<h4 id="emailOptionnelParam">' . __('Optional e-mail address') . '</h4>' . '<h4 id="emailOptionnelParam">' . __('Optional e-mail address') . '</h4>' .
(new Para())->__call('items', [[ (new Para())->__call('items', [[
(new Checkbox(My::SETTING_NAME, (bool) dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')))->__call('value', [1]), (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::SETTING_NAME])->__call('class', ['classic']), (new Label(__('Make e-mail address optional in comments'), Label::OUTSIDE_LABEL_AFTER))->__call('for', [My::id() . '_enabled'])->__call('class', ['classic']),
]])->render() . ]])->render() .
'</div>'; '</div>';
}); });
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings): void { dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings): void {
$blog_settings->get(My::SETTING_NAME)->put( $blog_settings->get(My::id())->put(
'enabled', 'enabled',
!empty($_POST[My::SETTING_NAME]), !empty($_POST[My::id() . '_enabled']),
'boolean', 'boolean',
__('Make e-mail address optional in comments') __('Make e-mail address optional in comments')
); );

View File

@ -16,22 +16,19 @@ namespace Dotclear\Plugin\emailOptionnel;
use ArrayObject; use ArrayObject;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process:
use dcUtils;
use Dotclear\Database\Cursor; use Dotclear\Database\Cursor;
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH'); return self::status(My::checkContext(My::FRONTEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -45,7 +42,7 @@ class Frontend extends dcNsProcess
if (!isset($_POST['c_content']) if (!isset($_POST['c_content'])
|| !empty($_POST['preview']) || !empty($_POST['preview'])
|| !empty($_POST['c_mail']) || !empty($_POST['c_mail'])
|| !dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled') || !My::settings()->get('enabled')
) { ) {
return; return;
} }
@ -57,7 +54,7 @@ class Frontend extends dcNsProcess
return; return;
} }
if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled') if (My::settings()->get('enabled')
&& $cur->getField('comment_email') == My::DEFAULT_EMAIL && $cur->getField('comment_email') == My::DEFAULT_EMAIL
) { ) {
# désactive l'affichage du mail dans le template # désactive l'affichage du mail dans le template
@ -85,16 +82,8 @@ class Frontend extends dcNsProcess
} }
}, },
'publicHeadContent' => function (): void { 'publicHeadContent' => function (): void {
// nullsafe PHP < 8.0 if (My::settings()->get('enabled')) {
if (is_null(dcCore::app()->blog)) { echo My::jsLoad('frontend', dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
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')
);
} }
}, },
]); ]);

View File

@ -14,36 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel; namespace Dotclear\Plugin\emailOptionnel;
use dcCore; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My extends \initEmailOptionnel class My extends MyPlugin
{ {
/** /** @var string Default email */
* This module id. public const DEFAULT_EMAIL = 'invalid@invalid.fr';
*/
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__);
}
} }

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel; namespace Dotclear\Plugin\emailOptionnel;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }
@ -37,7 +35,7 @@ class Uninstall extends dcNsProcess
->addUserAction( ->addUserAction(
'settings', 'settings',
'delete_all', 'delete_all',
My::SETTING_NAME My::id()
) )
->addUserAction( ->addUserAction(
'plugins', 'plugins',
@ -52,7 +50,7 @@ class Uninstall extends dcNsProcess
->addDirectAction( ->addDirectAction(
'settings', 'settings',
'delete_all', 'delete_all',
My::SETTING_NAME My::id()
) )
->addDirectAction( ->addDirectAction(
'plugins', 'plugins',