diff --git a/src/Backend.php b/src/Backend.php index eff22b3..99bc63f 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,47 +14,25 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; -use dcAdmin; use dcCore; -use dcPage; -use dcNsProcess; +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_USAGE, - 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) { - return false; - } - - // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return false; } // backend sidebar menu icon if (Utils::isActive()) { - 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((string) 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) - ); - // backend user dashboard favorites icon - dcCore::app()->addBehavior('adminDashboardFavoritesV2', [BackendBehaviors::class, 'adminDashboardFavoritesV2']); + My::addBackendMenuItem(); } // backend pwt management @@ -82,7 +60,7 @@ class Backend extends dcNsProcess ]); // add plugin "importExport" features - if (!is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get(My::id())->get('importexport_active')) { + if (!My::settings()->get('importexport_active')) { dcCore::app()->addBehaviors([ 'exportFullV2' => [ImportExport::class, 'exportFullV2'], 'exportSingleV2' => [ImportExport::class, 'exportSingleV2'], diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 55ecb73..9d048e3 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -15,10 +15,8 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; use ArrayObject; -use dcCore; -use dcFavorites; -use dcPage; use dcSettings; +use Dotclear\Core\Backend\Favorites; use Dotclear\Database\{ Cursor, MetaRecord @@ -122,24 +120,20 @@ class BackendBehaviors /** * Add user dashboard icon. * - * @param dcFavorites $favs The user favorites + * @param Favorites $favs The user favorites */ - public static function adminDashboardFavoritesV2(dcFavorites $favs): void + public static function adminDashboardFavoritesV2(Favorites $favs): void { - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { - return; - } - - $favs->register(My::id(), [ - 'title' => __('Post widget text'), - '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'), - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_USAGE, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), - ]); + $favs->register( + My::id(), + [ + 'title' => My::name(), + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), + //'permissions' => null, + ] + ); } /** @@ -149,7 +143,7 @@ class BackendBehaviors */ public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(My::id() . '/js/backend.js'); + return My::jsLoad('backend'); } /** @@ -253,7 +247,7 @@ class BackendBehaviors } # Upddate widget else { - Utils::updWidget($w->f('option_id'), $wcur); + Utils::updWidget((int) $w->f('option_id'), $wcur); } } } diff --git a/src/Frontend.php b/src/Frontend.php index 4ededd7..1f8c5a1 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; 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 dc20b05..f460019 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,28 +15,20 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; 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 { - 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 - if (is_null(dcCore::app()->blog)) { + if (!self::status()) { return false; } @@ -62,7 +54,7 @@ class Install extends dcNsProcess (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); // Settings - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $s->put( 'active', true, diff --git a/src/Manage.php b/src/Manage.php index be40beb..8dd0def 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,38 +14,29 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; -use dcAdminFilters; -use adminGenericFilterV2; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Backend\Filter\{ + Filters, + FiltersLibrary +}; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\Network\Http; use Exception; -use form; - -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_USAGE, - 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) { - return false; - } - - // nullsafe check - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return false; } @@ -56,13 +47,13 @@ class Manage extends dcNsProcess Utils::delWidget((int) $id); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Posts widgets successfully delete.') ); if (!empty($_POST['redir'])) { Http::redirect($_POST['redir']); } else { - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + My::redirect(); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -74,21 +65,21 @@ 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; } # filters - $filter = new adminGenericFilterV2('pwt'); - $filter->add(dcAdminFilters::getPageFilter()); - $filter->add(dcAdminFilters::getInputFilter('search_post_title', __('Entry:'))); - $filter->add(dcAdminFilters::getInputFilter('search_widget_title', __('Widget:'))); - $filter->add(dcAdminFilters::getInputFilter('user_id', __('User:'))); + $filter = new Filters('pwt'); + $filter->add(FiltersLibrary::getPageFilter()); + $filter->add(FiltersLibrary::getInputFilter('search_post_title', __('Entry:'))); + $filter->add(FiltersLibrary::getInputFilter('search_widget_title', __('Widget:'))); + $filter->add(FiltersLibrary::getInputFilter('user_id', __('User:'))); $params = $filter->params(); # Get posts with text widget @@ -102,38 +93,37 @@ class Manage extends dcNsProcess } // display - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsPageTabs() . - dcPage::jsModuleLoad(My::id() . '/js/manage.js') . - $filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record') + Page::jsPageTabs() . + My::jsLoad('manage') . + $filter->js(My::manageUrl() . '#record') ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', ]) . - dcPage::notices(); + Notices::getNotices(); if ($posts_list) { - $filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id())); + $filter->display('admin.plugin.' . My::id()); $posts_list->display( $filter, - '
' ); } - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/ManageList.php b/src/ManageList.php index 1d9acab..d96f679 100644 --- a/src/ManageList.php +++ b/src/ManageList.php @@ -15,11 +15,13 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; use ArrayObject; -use adminGenericFilterV2; -use adminGenericListV2; use context; use dcCore; -use dcPager; +use Dotclear\Core\Backend\Filter\Filters; +use Dotclear\Core\Backend\Listing\{ + Listing, + Pager +}; use Dotclear\Helper\Date; use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Html; @@ -29,18 +31,18 @@ use Dotclear\Helper\Html\Html; * @brief postWidgetText - admin list methods. * @since 2.6 */ -class ManageList extends adminGenericListV2 +class ManageList extends Listing { - public function display(adminGenericFilterV2 $filter, string $enclose = '%s'): void + public function display(Filters $filter, string $enclose = '%s'): void { // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { + if (is_null(dcCore::app()->blog)) { return; } // prepare page $blocks = explode('%s', $enclose); - $pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); + $pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); $tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC'); // no record diff --git a/src/My.php b/src/My.php index 6967a01..2dc54d3 100644 --- a/src/My.php +++ b/src/My.php @@ -14,39 +14,13 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string Plugin table name */ - public const TABLE_NAME = 'post_option'; - - /** - * 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__); - } + public const TABLE_NAME = \initPostWidgetText::PWT_TABLE_NAME; } diff --git a/src/Uninstall.php b/src/Uninstall.php index f64c0d5..5b4ac67 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\postWidgetText; 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/Utils.php b/src/Utils.php index 40c5242..357b1a2 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -41,7 +41,7 @@ class Utils */ public static function isActive(): bool { - return !is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get(My::id())->get('active'); + return My::settings()->get('active'); } /** @@ -145,7 +145,7 @@ class Utils public static function addWidget(Cursor $cur): int { // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { + if (is_null(dcCore::app()->blog)) { throw new Exception(__('Blog is not set')); } @@ -206,7 +206,7 @@ class Utils public static function updWidget(int $id, Cursor $cur): void { // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { + if (is_null(dcCore::app()->blog)) { throw new Exception(__('Blog is not set')); } @@ -257,7 +257,7 @@ class Utils public static function delWidget(int $id, ?string $type = null): void { // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { + if (is_null(dcCore::app()->blog)) { throw new Exception(__('Blog is not set')); }