From 23ad6f8f07e34fc33abd6d5c96694901e203eb5b Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 12 Aug 2023 23:31:55 +0200 Subject: [PATCH] upgrade to Dotclear 2.27 --- src/Backend.php | 43 +++++++---------------------- src/Frontend.php | 10 +++---- src/Install.php | 16 ++++------- src/Manage.php | 70 +++++++++++++++++++++-------------------------- src/My.php | 31 +++------------------ src/Prepend.php | 10 +++---- src/Uninstall.php | 10 +++---- 7 files changed, 62 insertions(+), 128 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index 2c478ee..314a13a 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,55 +14,32 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; -use dcAdmin; use dcCore; -use dcFavorites; -use dcMenu; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Backend\Favorites; +use Dotclear\Core\Process; -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; } - // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { - return false; - } - - // backend sidebar menu icon - if ((dcCore::app()->menu[dcAdmin::MENU_BLOG] instanceof dcMenu)) { - dcCore::app()->menu[dcAdmin::MENU_BLOG]->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(); // backend user dashboard icon - dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { - // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { - return; - } + dcCore::app()->addBehavior('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' => dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, diff --git a/src/Frontend.php b/src/Frontend.php index 59d8a0c..81e9812 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; use dcCore; -use dcNsProcess; +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 89a5a59..9ad8d2c 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,25 +15,20 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Database\Structure; use Exception; -class Install extends dcNsProcess +class Install extends Process { public static function init(): bool { - if (defined('DC_CONTEXT_ADMIN')) { - $version = dcCore::app()->plugins->moduleInfo(My::id(), 'version'); - static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true; - } - - return static::$init; + return self::status(My::checkContext(My::INSTALL)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -52,8 +47,7 @@ class Install extends dcNsProcess ->reference('fk_filesalias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade') ; - $si = new Structure(dcCore::app()->con, dcCore::app()->prefix); - $changes = $si->synchronize($s); + (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); return true; } catch (Exception $e) { diff --git a/src/Manage.php b/src/Manage.php index 28e24d1..79221a2 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -16,8 +16,11 @@ namespace Dotclear\Plugin\filesAlias; use dcCore; use dcMedia; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -32,30 +35,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) // nullsafe - && dcCore::app()->auth->check( - dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_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 - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (is_null(dcCore::app()->blog)) { return false; } @@ -67,8 +61,8 @@ class Manage extends dcNsProcess if (isset($_POST['a']) && is_array($_POST['a'])) { try { Utils::updateAliases($_POST['a']); - dcPage::addSuccessNotice(__('Aliases successfully updated.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Aliases successfully updated.')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -89,8 +83,8 @@ class Manage extends dcNsProcess if (!empty($found)) { try { Utils::createAlias($url, $target, $totrash, $password); - dcPage::addSuccessNotice(__('Alias for this media created.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Alias for this media created.')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -103,8 +97,8 @@ class Manage extends dcNsProcess if (!empty($found)) { try { Utils::createAlias($url, $target, $totrash, $password); - dcPage::addSuccessNotice(__('Alias for this media modified.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Alias for this media modified.')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -119,11 +113,11 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } - dcPage::openModule(My::name()); + Page::openModule(My::name()); if (($_REQUEST['part'] ?? '') == 'new') { self::displayAliasForm(); @@ -131,26 +125,26 @@ class Manage extends dcNsProcess self::displayAliasList(); } - dcPage::helpBlock('filesAlias'); + Page::helpBlock('filesAlias'); - dcPage::closeModule(); + Page::closeModule(); } private static function displayAliasForm(): void { // nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) { + if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { return; } echo - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML(dcCore::app()->blog->name) => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), __('New alias') => '', ]) . - dcPage::notices() . - (new Form('filesalias_new'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([ + Notices::getNotices() . + (new Form('filesalias_new'))->action(My::manageUrl())->method('post')->fields([ (new Text('h3', Html::escapeHTML(__('New alias')))), (new Note())->text(sprintf(__('Do not put blog media URL "%s" in fields or it will be removed.'), dcCore::app()->media->root_url))->class('form-note'), // destination @@ -178,8 +172,7 @@ class Manage extends dcNsProcess // submit (new Para())->items([ (new Submit(['save']))->value(__('Save')), - (new Hidden(['part'], 'new')), - dcCore::app()->formNonce(false), + ... My::hiddenFields(['part' => 'new']), ]), ])->render(); } @@ -187,20 +180,20 @@ class Manage extends dcNsProcess private static function displayAliasList(): void { // nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) { + if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) { return; } $aliases = Utils::getAliases(); echo - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML(dcCore::app()->blog->name) => '', My::name() => '', ]) . - dcPage::notices() . + Notices::getNotices() . '

' . __('New alias') . '

'; if ($aliases->isEmpty()) { @@ -233,7 +226,7 @@ class Manage extends dcNsProcess } echo - (new Form('filesalias_list'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([ + (new Form('filesalias_list'))->action(My::manageUrl())->method('post')->fields([ (new Text( '', '
' . @@ -250,8 +243,7 @@ class Manage extends dcNsProcess )), (new Para())->items([ (new Submit(['save']))->value(__('Update')), - (new Hidden(['part'], 'list')), - dcCore::app()->formNonce(false), + ... My::hiddenFields(['part' => 'list']), ]), (new Note())->text(__('To remove a link, empty its alias or destination.'))->class('form-note'), ])->render(); diff --git a/src/My.php b/src/My.php index 413f20b..172ed9d 100644 --- a/src/My.php +++ b/src/My.php @@ -14,36 +14,13 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My extends \initFilesAlias +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 This plugin table name */ + public const ALIAS_TABLE_NAME = 'filesalias'; } diff --git a/src/Prepend.php b/src/Prepend.php index 286f6e7..e8e263a 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; 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/Uninstall.php b/src/Uninstall.php index c4cfcb1..5754dcb 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\filesAlias; 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; }