diff --git a/src/Backend.php b/src/Backend.php index 496029a..9678d7e 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,30 +14,25 @@ declare(strict_types=1); namespace Dotclear\Plugin\improve; -use dcAdmin; use dcCore; -use dcPage; -use dcFavorites; -use dcNsProcess; +use Dotclear\Core\Backend\Favorites; +use Dotclear\Core\Process; /** * Improve admin class * * Add menu and dashboard icons, load Improve tasks. */ -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -45,23 +40,17 @@ class Backend extends dcNsProcess 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->isSuperAdmin() - ); + My::addBackendMenuItem(); dcCore::app()->addBehaviors([ - 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { + 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register( My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), - 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), //'permissions' => null, ] ); diff --git a/src/Config.php b/src/Config.php index 709264b..7147911 100644 --- a/src/Config.php +++ b/src/Config.php @@ -15,8 +15,8 @@ declare(strict_types=1); namespace Dotclear\Plugin\improve; use dcCore; -use dcPage; -use dcNsProcess; +use Dotclear\Core\Backend\Notices; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -34,19 +34,16 @@ use Exception; * * Set preference for this plugin. */ -class Config extends dcNsProcess +class Config extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::CONFIG)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -54,7 +51,7 @@ class Config extends dcNsProcess return true; } - if (is_null(dcCore::app()->blog)) { + if (is_null(dcCore::app()->blog) || !My::settings()) { return false; } @@ -63,14 +60,14 @@ class Config extends dcNsProcess if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) { $pdisabled = implode(';', $_POST['disabled']); } - dcCore::app()->blog->settings->get(My::id())->put('disabled', $pdisabled); - dcCore::app()->blog->settings->get(My::id())->put('nodetails', !empty($_POST['nodetails'])); - dcCore::app()->blog->settings->get(My::id())->put('allow_distrib', !empty($_POST['allow_distrib'])); - dcCore::app()->blog->settings->get(My::id())->put('combosortby', $_POST['combosortby'] ?: 'name'); + My::settings()->put('disabled', $pdisabled); + My::settings()->put('nodetails', !empty($_POST['nodetails'])); + My::settings()->put('allow_distrib', !empty($_POST['allow_distrib'])); + My::settings()->put('combosortby', $_POST['combosortby'] ?: 'name'); - dcPage::addSuccessNotice(__('Configuration successfully updated')); + Notices::addSuccessNotice(__('Configuration successfully updated')); - dcCore::app()->adminurl->redirect( + dcCore::app()->admin->url->redirect( 'admin.plugins', ['module' => My::id(), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] ); @@ -83,7 +80,7 @@ class Config extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } @@ -91,8 +88,7 @@ class Config extends dcNsProcess return; } - $items = []; - $settings = dcCore::app()->blog->settings->get(My::id()); + $items = []; foreach (Improve::instance()->tasks->dump() as $task) { $items[] = (new Para())->items([ @@ -106,16 +102,16 @@ class Config extends dcNsProcess (new Fieldset())->class('fieldset')->legend(new Legend(__('List of disabled tasks')))->fields($items), (new Fieldset())->class('fieldset')->legend(new Legend(__('Options')))->fields([ (new Para())->items([ - (new Checkbox('nodetails', (bool) $settings->get('nodetails')))->value('1'), + (new Checkbox('nodetails', (bool) My::settings()?->get('nodetails')))->value('1'), (new Label(__('Hide details of rendered tasks'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'), ]), (new Para())->items([ - (new Checkbox('allow_distrib', (bool) $settings->get('allow_distrib')))->value('1'), + (new Checkbox('allow_distrib', (bool) My::settings()?->get('allow_distrib')))->value('1'), (new Label(__('Show dotclear distributed modules'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('allow_distrib'), ]), (new Para())->items([ (new Label(__('Sort modules seletion by:'), Label::OUTSIDE_LABEL_BEFORE))->for('combosortby'), - (new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default($settings->get('combosortby')), + (new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default(My::settings()?->get('combosortby')), ]), ]), ])->render(); diff --git a/src/Improve.php b/src/Improve.php index 85ecf18..8b8a330 100644 --- a/src/Improve.php +++ b/src/Improve.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\improve; -use dcCore; use dcModuleDefine; use Dotclear\Helper\File\{ Files, @@ -50,7 +49,7 @@ class Improve $this->tasks = new Tasks(); // mark some tasks as disabled (by settings) - $disable = explode(';', (string) dcCore::app()->blog?->settings->get(My::id())->get('disabled')); + $disable = explode(';', (string) My::settings()?->get('disabled')); foreach ($disable as $id) { $this->tasks->get($id)?->disable(); } diff --git a/src/Install.php b/src/Install.php index 9411ea3..e3b8276 100644 --- a/src/Install.php +++ b/src/Install.php @@ -16,7 +16,7 @@ namespace Dotclear\Plugin\improve; use dcCore; use dcNamespace; -use dcNsProcess; +use Dotclear\Core\Process; use Exception; /** @@ -25,7 +25,7 @@ use Exception; * Set default settings and version * and manage changes on updates. */ -class Install extends dcNsProcess +class Install extends Process { /** @var array Improve default settings */ private static $default_settings = [[ @@ -37,15 +37,12 @@ class Install extends dcNsProcess 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) { + if (!self::status()) { return false; } @@ -65,7 +62,7 @@ class Install extends dcNsProcess private static function putSettings(): void { foreach (self::$default_settings as $v) { - dcCore::app()->blog?->settings->get(My::id())->put( + My::settings()?->put( $v[0], $v[2], $v[3], @@ -79,11 +76,11 @@ class Install extends dcNsProcess /** Update improve < 0.8 : action modules settings name */ private static function update_0_8_0(): void { - if (!is_null(dcCore::app()->blog) && version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) { - foreach (dcCore::app()->blog->settings->get(My::id())->dumpGlobalSettings() as $id => $values) { + if (!is_null(dcCore::app()->blog) && My::settings() && version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) { + foreach (My::settings()->dumpGlobalSettings() as $id => $values) { $newId = str_replace('ImproveAction', '', $id); if ($id != $newId) { - dcCore::app()->blog->settings->get(My::id())->rename($id, strtolower($newId)); + My::settings()->rename($id, strtolower($newId)); } } } diff --git a/src/Manage.php b/src/Manage.php index 0c4d57c..ee94d43 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,11 +15,10 @@ declare(strict_types=1); namespace Dotclear\Plugin\improve; use dcCore; -use dcPage; -use dcAdminNotices; use dcThemes; -use dcUtils; -use dcNsProcess; +use Dotclear\Core\Backend\Notices; +use Dotclear\Core\Backend\Page; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -32,6 +31,7 @@ use Dotclear\Helper\Html\Form\{ Submit, Text }; +use Dotclear\Helper\Text as TText; use Exception; /** @@ -40,7 +40,7 @@ use Exception; * Display page and configure modules * and execute tasks. */ -class Manage extends dcNsProcess +class Manage extends Process { /** @var string $type Current module(s) type */ private static string $type = 'plugin'; @@ -53,15 +53,12 @@ class Manage extends dcNsProcess public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::MANAGE)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -74,9 +71,9 @@ class Manage extends dcNsProcess if (!empty($_POST['fix'])) { if (empty($_POST['actions'])) { - dcAdminNotices::addWarningNotice(__('No tasks selected')); + Notices::addWarningNotice(__('No tasks selected')); } elseif (self::$module == '-') { - dcAdminNotices::addWarningNotice(__('No module selected')); + Notices::addWarningNotice(__('No module selected')); } else { try { $time = Improve::instance()->fix( @@ -87,15 +84,15 @@ class Manage extends dcNsProcess dcCore::app()->blog?->triggerBlog(); if (Improve::instance()->logs->has('error')) { - $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; + $notice = ['type' => Notices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; } elseif (Improve::instance()->logs->has('warning')) { - $notice = ['type' => dcAdminNotices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; + $notice = ['type' => Notices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; } elseif (Improve::instance()->logs->has('success')) { - $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes')]; + $notice = ['type' => Notices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes')]; } else { - $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; + $notice = ['type' => Notices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; } - dcAdminNotices::addNotice($notice['type'], sprintf($notice['msg'], self::$module, $time)); + Notices::addNotice($notice['type'], sprintf($notice['msg'], self::$module, $time)); $done = true; } catch (Exception $e) { @@ -106,7 +103,7 @@ class Manage extends dcNsProcess } if ($done) { - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); + My::redirect(['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); } return true; @@ -114,23 +111,23 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsModuleLoad(My::id() . '/js/index.js') . + My::jsLoad('index') . (self::$task === null ? '' : self::$task->header()) ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', empty($_REQUEST['config']) ? (self::$type == 'theme' ? __('Themes tasks') : __('Plugins tasks')) : __('Configure module') => '', ]) . - dcPage::notices(); + Notices::getNotices(); if (empty($_REQUEST['config'])) { self::displayActions(); @@ -138,19 +135,19 @@ class Manage extends dcNsProcess self::displayConfigurator(); } - dcPage::closeModule(); + Page::closeModule(); } private static function displayConfigurator(): void { - $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type]); + $back_url = $_REQUEST['redir'] ?? My::manageURL(['type' => self::$type]); if (null === self::$task) { echo '
' . __('Unknow task') . '
'; } else { - $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$task->properties->id]); + $redir = $_REQUEST['redir'] ?? My::manageUrl(['type' => self::$type, 'config' => self::$task->properties->id]); $res = self::$task->configure($redir); echo ' @@ -158,7 +155,7 @@ class Manage extends dcNsProcess