diff --git a/js/admin.js b/js/admin.js index beec66e..df1f767 100644 --- a/js/admin.js +++ b/js/admin.js @@ -2,6 +2,6 @@ $(function(){ /* toogle admin form sidebar */ $('#templator h5').toggleWithLegend( $('#templator').children().not('h5'), - {cookie:'dcx_templator_admin_form_sidebar',legend_click:true} + {user_pref:'dcx_templator_admin_form_sidebar',legend_click:true} ); }); \ No newline at end of file diff --git a/src/Backend.php b/src/Backend.php index 245a9b4..11a1966 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,50 +14,23 @@ declare(strict_types=1); namespace Dotclear\Plugin\templator; -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()->blog) - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - My::PERMISSION_TEMPLATOR, - 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; } - // nullsafe - if (is_null(dcCore::app()->blog)) { - return false; - } - - //backend sidebar menu icon - if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) { - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - urldecode(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, - My::PERMISSION_TEMPLATOR, - ]), dcCore::app()->blog->id) - ); - } + My::addBackendMenuItem(); dcCore::app()->addBehaviors([ 'adminPostHeaders' => [BackendBehaviors::class,'adminPostHeaders'], diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index fe603a3..7e0b907 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -16,10 +16,15 @@ namespace Dotclear\Plugin\templator; use ArrayObject; use dcCore; -use dcPage; -use dcPostsActions; -use Dotclear\Database\Cursor; -use Dotclear\Database\MetaRecord; +use Dotclear\Core\Backend\Action\ActionsPosts; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Database\{ + Cursor, + MetaRecord +}; use Dotclear\Helper\Html\Html; use Exception; @@ -29,7 +34,7 @@ class BackendBehaviors { public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(My::id() . '/js/admin.js'); + return My::jsLoad('admin'); } public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void @@ -60,7 +65,7 @@ class BackendBehaviors } } - public static function adminPostsActions(dcPostsActions $pa): void + public static function adminPostsActions(ActionsPosts $pa): void { $pa->addAction( [ @@ -72,7 +77,7 @@ class BackendBehaviors ); } - public static function adminPostsActionsCallback(dcPostsActions $pa, ArrayObject $post): void + public static function adminPostsActionsCallback(ActionsPosts $pa, ArrayObject $post): void { # No entry $posts_ids = $pa->getIDs(); @@ -91,7 +96,7 @@ class BackendBehaviors } } - dcPage::addSuccessNotice(__('Entries template updated.')); + Notices::addSuccessNotice(__('Entries template updated.')); $pa->redirect(true); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -99,7 +104,7 @@ class BackendBehaviors } $pa->beginPage( - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML((string) dcCore::app()->blog?->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), __('Entry template') => '', diff --git a/src/Frontend.php b/src/Frontend.php index 23e64dc..a75ce8e 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,24 +15,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\templator; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Database\MetaRecord; /** * Frontend prepend. */ -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/Manage.php b/src/Manage.php index 8daaf27..77e0208 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,41 +14,34 @@ declare(strict_types=1); namespace Dotclear\Plugin\templator; -use adminGenericFilterV2; -use adminPostList; -use dcAdminFilters; use dcCore; -use dcNsProcess; -use dcPage; -use dcPager; +use Dotclear\Core\Backend\Filter\{ + Filters, + FiltersLibrary +}; +use Dotclear\Core\Backend\Listing\ListingPosts; +use Dotclear\Core\Backend\Listing\Pager as corePager; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\File\Files; use Dotclear\Helper\Html\Html; 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()->blog) - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - My::PERMISSION_TEMPLATOR, - ]), 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 - if (is_null(dcCore::app()->blog)) { + if (!self::status()) { return false; } @@ -71,8 +64,8 @@ class Manage extends dcNsProcess $t->initializeTpl($name, $_POST['filesource']); if (!dcCore::app()->error->flag()) { - dcPage::addSuccessNotice(__('The new template has been successfully created.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('The new template has been successfully created.')); + My::redirect(); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -90,8 +83,8 @@ class Manage extends dcNsProcess ); if (!dcCore::app()->error->flag()) { - dcPage::addSuccessNotice(__('The template has been successfully copied.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']); + Notices::addSuccessNotice(__('The template has been successfully copied.')); + My::redirect(['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -109,8 +102,8 @@ class Manage extends dcNsProcess ); if (!dcCore::app()->error->flag()) { - dcPage::addSuccessNotice(__('The template has been successfully copied.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']); + Notices::addSuccessNotice(__('The template has been successfully copied.')); + My::redirect(['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -127,8 +120,8 @@ class Manage extends dcNsProcess dcCore::app()->meta->delMeta($file, 'template'); if (!dcCore::app()->error->flag()) { - dcPage::addSuccessNotice(__('The template has been successfully removed.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']); + Notices::addSuccessNotice(__('The template has been successfully removed.')); + My::redirect(['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -140,7 +133,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } @@ -159,28 +152,28 @@ class Manage extends dcNsProcess if (!$t->canUseRessources(true)) { dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.')); - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), ]) . - dcPage::notices(); + Notices::getNotices(); /* * Duplicate dotclear template */ } elseif ('new' == $v->part) { - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), $v->name => '', ]) . - dcPage::notices() . + Notices::getNotices() . - '
'; @@ -205,16 +198,16 @@ class Manage extends dcNsProcess * Copy templator template */ } elseif ('copy' == $v->part && !empty($_REQUEST['file'])) { - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), $v->name => '', ]) . - dcPage::notices() . + Notices::getNotices() . - ''; /* @@ -241,16 +233,16 @@ class Manage extends dcNsProcess }; $name = $full_name . dcCore::app()->blog->getCategory($category_id)->f('cat_title'); - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), $v->name => '', ]) . - dcPage::notices() . + Notices::getNotices() . - ''; /* * Delete templator template */ } elseif ('delete' == $v->part && !empty($_REQUEST['file'])) { - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), $v->name => '', ]) . - dcPage::notices() . + Notices::getNotices() . - ''; /* * List templator templates */ } elseif ('files' == $v->part) { - dcPage::openModule(My::name()); + Page::openModule(My::name()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), $v->name => '', ]) . - dcPage::notices() . + Notices::getNotices() . '' . __('No template.') . '
'; } else { // reuse "used templatro template" filter settings - $filter = new adminGenericFilterV2(My::id()); - $filter->add(dcAdminFilters::getPageFilter()); + $filter = new Filters(My::id()); + $filter->add(FiltersLibrary::getPageFilter()); $page = is_numeric($filter->value('page')) ? (int) $filter->value('page') : 1; $nb = is_numeric($filter->value('nb')) ? (int) $filter->value('nb') : 1; - $pager = new dcPager($page, count($v->items), $nb, 10); + $pager = new corePager($page, count($v->items), $nb, 10); echo '