upgrade to Dotclear 2.27
This commit is contained in:
parent
961db69605
commit
34e98978f0
5 changed files with 28 additions and 71 deletions
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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
|
||||
'<div class="fieldset">' .
|
||||
'<h4 id="emailOptionnelParam">' . __('Optional e-mail address') . '</h4>' .
|
||||
(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() .
|
||||
'</div>';
|
||||
});
|
||||
|
||||
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')
|
||||
);
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
|
31
src/My.php
31
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';
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue