diff --git a/js/backend.js b/js/backend.js index 4af6ac0..d2a989f 100644 --- a/js/backend.js +++ b/js/backend.js @@ -1,7 +1,9 @@ -$(function(){ - /* toogle admin form sidebar */ - $('#fac h5').toggleWithLegend( - $('#fac').children().not('h5'), - {cookie:'dcx_fac_admin_form_sidebar',legend_click:true} - ); +/*global $, dotclear, datePicker */ +'use strict'; + +$(() => { + $('#fac h5').toggleWithLegend( + $('#fac').children().not('h5'), + {user_pref:'dcx_fac_admin_form_sidebar',legend_click:true} + ); }); \ No newline at end of file diff --git a/src/Backend.php b/src/Backend.php index 57bdc4d..436d291 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\fac; use dcCore; -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'); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 081877d..d9f78e0 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -16,9 +16,12 @@ namespace Dotclear\Plugin\fac; use ArrayObject; use dcCore; -use dcPage; -use dcPostsActions; use dcSettings; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Backend\Action\ActionsPosts; use Dotclear\Database\{ Cursor, MetaRecord @@ -61,7 +64,7 @@ class BackendBehaviors __('category pages') => 'category', __('entries feed') => 'feed', ]; - if (dcCore::app()->plugins->moduleExists('muppet') && class_exists('\muppet')) { + if (dcCore::app()->plugins->getDefine('muppet')->isDefined() && class_exists('\muppet')) { foreach (\muppet::getPostTypes() as $k => $v) { $types[sprintf( __('"%s" pages from extension muppet'), @@ -80,9 +83,6 @@ class BackendBehaviors */ public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void { - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { - return; - } $lines = ''; $fac_public_tpltypes = json_decode($blog_settings->get(My::id())->get('public_tpltypes'), true); if (!is_array($fac_public_tpltypes)) { @@ -96,15 +96,15 @@ class BackendBehaviors } echo - '
' . __('To add feed to an entry edit this entry and put in sidebar the url of the feed and select a format.') . '
'; if (dcCore::app()->auth->isSuperAdmin()) { - echo ''; } @@ -160,7 +160,7 @@ class BackendBehaviors */ public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(My::id() . '/js/backend.js'); + return My::jsLoad('backend'); } /** @@ -172,7 +172,7 @@ class BackendBehaviors */ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void { - if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get(My::id())->get('active')) { + if (is_null(dcCore::app()->blog) || !My::settings()->get('active')) { return; } @@ -231,11 +231,11 @@ class BackendBehaviors /** * Add actions to posts page combo * - * @param dcPostsActions $pa dcPostsActionsPage instance + * @param ActionsPosts $pa ActionsPostsPage instance */ - public static function adminPostsActions(dcPostsActions $pa): void + public static function adminPostsActions(ActionsPosts $pa): void { - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->auth) || !dcCore::app()->blog->settings->get(My::id())->get('active')) { + if (is_null(dcCore::app()->blog) || !My::settings()->get('active')) { return; } @@ -259,12 +259,12 @@ class BackendBehaviors /** * Posts actions callback to remove linked feed * - * @param dcPostsActions $pa dcPostsActions instance + * @param ActionsPosts $pa ActionsPosts instance * @param ArrayObject $post _POST actions */ - public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void + public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void { - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->auth)) { + if (is_null(dcCore::app()->blog)) { return; } # No entry @@ -286,17 +286,17 @@ class BackendBehaviors self::delFeed($post_id); } - dcPage::addSuccessNotice(__('Linked feed deleted.')); + Notices::addSuccessNotice(__('Linked feed deleted.')); $pa->redirect(true); } /** * Posts actions callback to add linked feed * - * @param dcPostsActions $pa dcPostsActions instance + * @param ActionsPosts $pa ActionsPosts instance * @param ArrayObject $post _POST actions */ - public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void + public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void { if (is_null(dcCore::app()->blog)) { return; @@ -315,13 +315,13 @@ class BackendBehaviors self::addFeed($post_id, $post); } - dcPage::addSuccessNotice(__('Linked feed added.')); + Notices::addSuccessNotice(__('Linked feed added.')); $pa->redirect(true); - # Display form + # Display form } else { $pa->beginPage( - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML(dcCore::app()->blog->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), __('Linked feed to this selection') => '', @@ -351,7 +351,7 @@ class BackendBehaviors */ protected static function formFeed(string $url = '', string $format = ''): string { - if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get(My::id())->get('active')) { + if (is_null(dcCore::app()->blog) || !My::settings()->get('active')) { return ''; } @@ -382,7 +382,7 @@ class BackendBehaviors if (is_null(dcCore::app()->blog)) { return []; } - $formats = json_decode(dcCore::app()->blog->settings->get(My::id())->get('formats'), true); + $formats = json_decode((string) My::settings()->get('formats'), true); if (!is_array($formats) || empty($formats)) { return []; } diff --git a/src/Config.php b/src/Config.php index 3f1e158..f809704 100644 --- a/src/Config.php +++ b/src/Config.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\fac; use dcCore; -use dcPage; -use dcNsProcess; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -30,25 +33,21 @@ use Dotclear\Helper\Html\Form\{ }; use Exception; -class Config extends dcNsProcess +class Config extends Process { public static function init(): bool { - static::$init == defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) - && 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; } //nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (is_null(dcCore::app()->blog)) { return false; } @@ -56,7 +55,7 @@ class Config extends dcNsProcess dcCore::app()->admin->__get('list')->getURL() . '#plugins' : $_REQUEST['redir']; # -- Get settings -- - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $fac_formats = json_decode($s->get('formats'), true); @@ -88,10 +87,10 @@ class Config extends dcNsProcess dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Configuration successfully updated.') ); - dcCore::app()->adminurl->redirect( + dcCore::app()->admin->url->redirect( 'admin.plugins', ['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] ); @@ -105,16 +104,11 @@ class Config extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } - //nullsafe - if (is_null(dcCore::app()->blog)) { - return; - } - - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $fac_formats = json_decode($s->get('formats'), true); @@ -148,7 +142,7 @@ class Config extends dcNsProcess echo '' . context::global_filters( $feed->description, diff --git a/src/Install.php b/src/Install.php index a240acd..7605e86 100644 --- a/src/Install.php +++ b/src/Install.php @@ -16,26 +16,19 @@ namespace Dotclear\Plugin\fac; use dcCore; use dcNamespace; -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') - && 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; - } - - if (is_null(dcCore::app()->blog)) { + if (!self::status()) { return false; } @@ -110,7 +103,7 @@ class Install extends dcNsProcess // Set module settings foreach ($mod_conf as $v) { - dcCore::app()->blog->settings->get(My::id())->put( + My::settings()->put( $v[0], $v[2], $v[3], diff --git a/src/My.php b/src/My.php index 7ee2866..fadc207 100644 --- a/src/My.php +++ b/src/My.php @@ -14,36 +14,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\fac; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +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__); - } } diff --git a/src/Uninstall.php b/src/Uninstall.php index f68949f..da0e35f 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\fac; 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; }