diff --git a/src/Backend.php b/src/Backend.php index 282cab3..f791679 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,46 +14,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; -use dcAdmin; -use dcCore; -use dcMenu; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; -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) - && 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; } - if (is_null(dcCore::app()->auth) - || is_null(dcCore::app()->blog) - || is_null(dcCore::app()->adminurl) - || !(dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu) - ) { - return false; - } - - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id) - ); + My::addBackendMenuItem(); return true; } diff --git a/src/Frontend.php b/src/Frontend.php index ffd6ef4..58334dd 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; 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) { + if (!self::status()) { return false; } diff --git a/src/Install.php b/src/Install.php index 001fcb5..4d5e975 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,28 +15,24 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; 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') - && is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version')) - && 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) { + if (!self::status()) { return false; } try { - $s = dcCore::app()->blog?->settings->get(My::id()); + $s = My::settings(); if (is_null($s)) { return false; } diff --git a/src/Manage.php b/src/Manage.php index 67e393e..85e1035 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -30,27 +33,21 @@ use Dotclear\Helper\Html\Form\{ }; use Exception; -class Manage extends dcNsProcess +class Manage extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) - && 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::MANAGE)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } // nullsafe check - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (is_null(dcCore::app()->blog)) { return false; } @@ -58,7 +55,7 @@ class Manage extends dcNsProcess return true; } - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $targets = Targets::instance(); try { @@ -85,8 +82,8 @@ class Manage extends dcNsProcess $targets->export(); dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice(__('Configuration successfully updated')); - dcCore::app()->adminurl->redirect('admin.plugin.noodles'); + Notices::addSuccessNotice(__('Configuration successfully updated')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -96,12 +93,12 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } // nullsafe check - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (is_null(dcCore::app()->blog)) { return; } @@ -113,16 +110,16 @@ class Manage extends dcNsProcess $note = '' . __('See local default avatar.') . ''; } - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugin') => '', My::name() => '', ]) . - dcPage::notices() . ' + Notices::getNotices() . ' -
'; - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/My.php b/src/My.php index f84b288..41f1c1c 100644 --- a/src/My.php +++ b/src/My.php @@ -14,39 +14,13 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string Default image name */ public const IMAGE = 'default-avatar.png'; - - /** - * 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/Prepend.php b/src/Prepend.php index de0b3c3..0c6e037 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; -class Prepend extends dcNsProcess +class Prepend extends Process { public static function init(): bool { - static::$init = defined('DC_RC_PATH'); - - return static::$init; + return self::status(My::checkContext(My::PREPEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/Targets.php b/src/Targets.php index 3586609..03d0b9e 100644 --- a/src/Targets.php +++ b/src/Targets.php @@ -44,12 +44,10 @@ final class Targets { // try to read main settings $active = $api = $local = null; - if (!is_null(dcCore::app()->blog)) { - $s = dcCore::app()->blog->settings->get(My::id()); - $active = $s->get('active'); - $api = $s->get('api'); - $local = $s->get('local'); - } + $s = My::settings(); + $active = $s->get('active'); + $api = $s->get('api'); + $local = $s->get('local'); // set main settings $this->active = is_bool($active) ? $active : false; @@ -95,7 +93,7 @@ final class Targets */ public function import(): void { - $s = dcCore::app()->blog?->settings->get(My::id())->get('settings'); + $s = My::settings()->get('settings'); if (!is_string($s)) { return; } @@ -122,7 +120,7 @@ final class Targets $targets[$target->id] = $target->exportSettings(); } - dcCore::app()->blog?->settings->get(My::id())->put('settings', json_encode($targets), 'string'); + My::settings()->put('settings', json_encode($targets), 'string'); } /** diff --git a/src/Uninstall.php b/src/Uninstall.php index fcd7c23..aed40d9 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\noodles; 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; }