From 8e928f448c9e55f0d445906426b86f83e4a8ef1b Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 12 Aug 2023 18:06:51 +0200 Subject: [PATCH] upgrade to Dotclear 2.27 --- src/Backend.php | 19 ++++++------------- src/Frontend.php | 24 ++++++++---------------- src/Install.php | 18 +++++------------- src/My.php | 30 ++---------------------------- src/Uninstall.php | 10 ++++------ src/UrlHandler.php | 2 +- 6 files changed, 26 insertions(+), 77 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index 869a8cf..4540963 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -16,9 +16,8 @@ namespace Dotclear\Plugin\disclaimer; use ArrayObject; use dcCore; -use dcPage; -use dcNsProcess; use dcSettings; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -32,22 +31,16 @@ use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Html; use Exception; -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !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; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -70,7 +63,7 @@ class Backend extends dcNsProcess }, '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 { @@ -89,7 +82,7 @@ class Backend extends dcNsProcess echo (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 Para())->items([ (new Checkbox('disclaimer_active', (bool) $s->get('disclaimer_active')))->value(1), diff --git a/src/Frontend.php b/src/Frontend.php index 1f13eea..f991d0f 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -16,31 +16,23 @@ namespace Dotclear\Plugin\disclaimer; use ArrayObject; use dcCore; -use dcNsProcess; -use dcUtils; +use Dotclear\Core\Process; -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) { - return false; - } - - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + if (!self::status()) { return false; } # Is active - if (!dcCore::app()->blog->settings->get(My::id())->get('disclaimer_active')) { + if (!My::settings()->get('disclaimer_active')) { return false; } @@ -54,12 +46,12 @@ class Frontend extends dcNsProcess dcCore::app()->tpl->addValue('DisclaimerTitle', function (ArrayObject $attr): string { return '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 { - return 'blog->settings->get("disclaimer")->get("disclaimer_text"); ?>'; + return 'get("disclaimer_text"); ?>'; }); dcCore::app()->tpl->addValue('DisclaimerFormURL', function (ArrayObject $attr): string { @@ -69,7 +61,7 @@ class Frontend extends dcNsProcess # Behaviors dcCore::app()->addBehaviors([ 'publicHeadContent' => function (): void { - echo dcUtils::cssModuleLoad(My::id() . '/css/disclaimer.css'); + echo My::cssLoad('disclaimer'); }, 'publicBeforeDocumentV2' => [UrlHandler::class, 'publicBeforeDocumentV2'], ]); diff --git a/src/Install.php b/src/Install.php index 5d6bf63..3ae6b2d 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,27 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\disclaimer; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Exception; -class Install extends dcNsProcess +class Install extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - - return static::$init; + return self::status(My::checkContext(My::INSTALL)); } public static function process(): bool { - if (!static::$init) { - return false; - } - - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + if (!self::status()) { return false; } @@ -105,7 +97,7 @@ class Install extends dcNsProcess try { // Settings foreach ($mod_conf as $v) { - dcCore::app()->blog->settings->get(My::id())->put( + My::settings()->put( $v[0], $v[2], $v[3], diff --git a/src/My.php b/src/My.php index c69f581..f514806 100644 --- a/src/My.php +++ b/src/My.php @@ -14,12 +14,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\disclaimer; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var array Default list of bots agents */ public const DEFAULT_BOTS_AGENTS = [ @@ -45,30 +45,4 @@ class My /** @var string disclaimer specific session prefix */ 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__); - } } diff --git a/src/Uninstall.php b/src/Uninstall.php index a7966a8..01d783d 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\disclaimer; 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; } diff --git a/src/UrlHandler.php b/src/UrlHandler.php index 1b2e5cc..ec5f05a 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -50,7 +50,7 @@ class UrlHandler extends dcUrlHandlers return; } - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); # Test user-agent to see if it is a bot if (!$s->get('disclaimer_bots_unactive')) {