upgrade to Dotclear 2.27
This commit is contained in:
parent
721a12e15c
commit
8e928f448c
@ -16,9 +16,8 @@ namespace Dotclear\Plugin\disclaimer;
|
|||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcPage;
|
|
||||||
use dcNsProcess;
|
|
||||||
use dcSettings;
|
use dcSettings;
|
||||||
|
use Dotclear\Core\Process;
|
||||||
use Dotclear\Helper\Html\Form\{
|
use Dotclear\Helper\Html\Form\{
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Div,
|
Div,
|
||||||
@ -32,22 +31,16 @@ use Dotclear\Helper\Html\Form\{
|
|||||||
use Dotclear\Helper\Html\Html;
|
use Dotclear\Helper\Html\Html;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
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));
|
||||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe PHP < 8.0
|
|
||||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
|
||||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
|
||||||
]), dcCore::app()->blog->id);
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function process(): bool
|
public static function process(): bool
|
||||||
{
|
{
|
||||||
if (!static::$init) {
|
if (!self::status()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +63,7 @@ class Backend extends dcNsProcess
|
|||||||
},
|
},
|
||||||
|
|
||||||
'adminBlogPreferencesHeaders' => function (): string {
|
'adminBlogPreferencesHeaders' => function (): string {
|
||||||
return dcPage::jsModuleLoad(My::id() . '/js/backend.js');
|
return My::jsLoad('backend');
|
||||||
},
|
},
|
||||||
|
|
||||||
'adminPostEditorTags' => function (string $editor, string $context, ArrayObject $alt_tags, string $format): void {
|
'adminPostEditorTags' => function (string $editor, string $context, ArrayObject $alt_tags, string $format): void {
|
||||||
@ -89,7 +82,7 @@ class Backend extends dcNsProcess
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
(new Div())->class('fieldset')->items([
|
(new Div())->class('fieldset')->items([
|
||||||
(new Text('h4', My::name()))->id('disclaimerParam'),
|
(new Text('h4', My::name()))->id(My::id() . 'Param'),
|
||||||
(new Div())->class('two-boxes even')->items([
|
(new Div())->class('two-boxes even')->items([
|
||||||
(new Para())->items([
|
(new Para())->items([
|
||||||
(new Checkbox('disclaimer_active', (bool) $s->get('disclaimer_active')))->value(1),
|
(new Checkbox('disclaimer_active', (bool) $s->get('disclaimer_active')))->value(1),
|
||||||
|
@ -16,31 +16,23 @@ namespace Dotclear\Plugin\disclaimer;
|
|||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use Dotclear\Core\Process;
|
||||||
use dcUtils;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// nullsafe PHP < 8.0
|
|
||||||
if (is_null(dcCore::app()->blog)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Is active
|
# Is active
|
||||||
if (!dcCore::app()->blog->settings->get(My::id())->get('disclaimer_active')) {
|
if (!My::settings()->get('disclaimer_active')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,12 +46,12 @@ class Frontend extends dcNsProcess
|
|||||||
dcCore::app()->tpl->addValue('DisclaimerTitle', function (ArrayObject $attr): string {
|
dcCore::app()->tpl->addValue('DisclaimerTitle', function (ArrayObject $attr): string {
|
||||||
return '<?php echo ' . sprintf(
|
return '<?php echo ' . sprintf(
|
||||||
dcCore::app()->tpl->getFilters($attr),
|
dcCore::app()->tpl->getFilters($attr),
|
||||||
'dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_title")'
|
My::class . '::settings()->get("disclaimer_title")'
|
||||||
) . '; ?>';
|
) . '; ?>';
|
||||||
});
|
});
|
||||||
|
|
||||||
dcCore::app()->tpl->addValue('DisclaimerText', function (ArrayObject $attr): string {
|
dcCore::app()->tpl->addValue('DisclaimerText', function (ArrayObject $attr): string {
|
||||||
return '<?php echo dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_text"); ?>';
|
return '<?php echo ' . My::class . '::settings()->get("disclaimer_text"); ?>';
|
||||||
});
|
});
|
||||||
|
|
||||||
dcCore::app()->tpl->addValue('DisclaimerFormURL', function (ArrayObject $attr): string {
|
dcCore::app()->tpl->addValue('DisclaimerFormURL', function (ArrayObject $attr): string {
|
||||||
@ -69,7 +61,7 @@ class Frontend extends dcNsProcess
|
|||||||
# Behaviors
|
# Behaviors
|
||||||
dcCore::app()->addBehaviors([
|
dcCore::app()->addBehaviors([
|
||||||
'publicHeadContent' => function (): void {
|
'publicHeadContent' => function (): void {
|
||||||
echo dcUtils::cssModuleLoad(My::id() . '/css/disclaimer.css');
|
echo My::cssLoad('disclaimer');
|
||||||
},
|
},
|
||||||
'publicBeforeDocumentV2' => [UrlHandler::class, 'publicBeforeDocumentV2'],
|
'publicBeforeDocumentV2' => [UrlHandler::class, 'publicBeforeDocumentV2'],
|
||||||
]);
|
]);
|
||||||
|
@ -15,27 +15,19 @@ declare(strict_types=1);
|
|||||||
namespace Dotclear\Plugin\disclaimer;
|
namespace Dotclear\Plugin\disclaimer;
|
||||||
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use Dotclear\Core\Process;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class Install extends dcNsProcess
|
class Install extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
{
|
{
|
||||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
return self::status(My::checkContext(My::INSTALL));
|
||||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
|
||||||
|
|
||||||
return static::$init;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function process(): bool
|
public static function process(): bool
|
||||||
{
|
{
|
||||||
if (!static::$init) {
|
if (!self::status()) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// nullsafe PHP < 8.0
|
|
||||||
if (is_null(dcCore::app()->blog)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +97,7 @@ class Install extends dcNsProcess
|
|||||||
try {
|
try {
|
||||||
// Settings
|
// Settings
|
||||||
foreach ($mod_conf as $v) {
|
foreach ($mod_conf as $v) {
|
||||||
dcCore::app()->blog->settings->get(My::id())->put(
|
My::settings()->put(
|
||||||
$v[0],
|
$v[0],
|
||||||
$v[2],
|
$v[2],
|
||||||
$v[3],
|
$v[3],
|
||||||
|
30
src/My.php
30
src/My.php
@ -14,12 +14,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\disclaimer;
|
namespace Dotclear\Plugin\disclaimer;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\Module\MyPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module definitions.
|
* This module definitions.
|
||||||
*/
|
*/
|
||||||
class My
|
class My extends MyPlugin
|
||||||
{
|
{
|
||||||
/** @var array Default list of bots agents */
|
/** @var array Default list of bots agents */
|
||||||
public const DEFAULT_BOTS_AGENTS = [
|
public const DEFAULT_BOTS_AGENTS = [
|
||||||
@ -45,30 +45,4 @@ class My
|
|||||||
|
|
||||||
/** @var string disclaimer specific session prefix */
|
/** @var string disclaimer specific session prefix */
|
||||||
public const SESSION_PREFIX = 'dc_disclaimer_sess_';
|
public const SESSION_PREFIX = 'dc_disclaimer_sess_';
|
||||||
|
|
||||||
/**
|
|
||||||
* 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__);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||||||
namespace Dotclear\Plugin\disclaimer;
|
namespace Dotclear\Plugin\disclaimer;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class UrlHandler extends dcUrlHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$s = dcCore::app()->blog->settings->get(My::id());
|
$s = My::settings();
|
||||||
|
|
||||||
# Test user-agent to see if it is a bot
|
# Test user-agent to see if it is a bot
|
||||||
if (!$s->get('disclaimer_bots_unactive')) {
|
if (!$s->get('disclaimer_bots_unactive')) {
|
||||||
|
Loading…
Reference in New Issue
Block a user