From 4dbab7441a03f0bf74045853bebd0074d086f3ca Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 16 Aug 2023 22:03:40 +0200 Subject: [PATCH] upgrade to Dotclear 2.27 --- src/ActivityReportActions.php | 6 +-- src/Backend.php | 46 ++++------------ src/BackendBehaviors.php | 29 ++++------- src/Config.php | 28 +++++----- src/FeedsActions.php | 14 ++--- src/FeedsDefaultActions.php | 23 ++++---- src/FeedsList.php | 18 ++++--- src/Frontend.php | 10 ++-- src/Install.php | 18 ++----- src/Manage.php | 86 +++++++++++++++--------------- src/ManageFeed.php | 98 +++++++++++++++-------------------- src/ManageFeedVars.php | 2 +- src/My.php | 31 ++--------- src/PostsFilter.php | 36 +++++++------ src/PostsList.php | 12 +++-- src/Prepend.php | 10 ++-- src/Settings.php | 11 +--- src/Uninstall.php | 10 ++-- src/UrlHandler.php | 6 +-- src/ZoneclearFeedServer.php | 6 +-- 20 files changed, 207 insertions(+), 293 deletions(-) diff --git a/src/ActivityReportActions.php b/src/ActivityReportActions.php index 6567e92..d305d0e 100644 --- a/src/ActivityReportActions.php +++ b/src/ActivityReportActions.php @@ -37,7 +37,7 @@ class ActivityReportActions __('Feed named "%s" point to "%s" has been updated by "%s"'), 'zoneclearFeedServerAfterUpdateFeed', function (Cursor $cur, int $id): void { - $user = dcCore::app()->auth?->getInfo('user_cn'); + $user = dcCore::app()->auth->getInfo('user_cn'); if (!is_string($user)) { return; } @@ -64,7 +64,7 @@ class ActivityReportActions __('A new feed named "%s" point to "%s" was added by "%s"'), 'zoneclearFeedServerAfterAddFeed', function (Cursor $cur, int $id): void { - $user = dcCore::app()->auth?->getInfo('user_cn'); + $user = dcCore::app()->auth->getInfo('user_cn'); if (!is_string($user) || !is_string($cur->getField('feed_name')) || !is_string($cur->getField('feed_feed')) @@ -115,7 +115,7 @@ class ActivityReportActions } $row = new FeedRow($rs); - $user = dcCore::app()->auth?->getInfo('user_cn'); + $user = dcCore::app()->auth->getInfo('user_cn'); if (!is_string($user)) { return; } diff --git a/src/Backend.php b/src/Backend.php index 2bffedd..c54b6e5 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,27 +14,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; -use dcAdmin; use dcCore; -use dcPage; -use dcMenu; -use dcNsProcess; +use Dotclear\Core\Process; /** * Backend prepend. */ -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; } @@ -54,42 +49,19 @@ class Backend extends dcNsProcess 'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'], ]); - // nullsafe - if (is_null(dcCore::app()->blog)) { - return false; - } - // not active - if (!dcCore::app()->blog->settings->get(My::id())->get('active') - || '' == dcCore::app()->blog->settings->get(My::id())->get('user') - ) { + if (!My::settings()->get('active') || '' == My::settings()->get('user')) { return false; } - // get user perm - $has_perm = dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - - // add 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()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', - $_SERVER['REQUEST_URI'] - ), - $has_perm - ); - } - // no perm - if (!$has_perm) { + if (!My::checkContext(My::MENU)) { return true; } + // sidebar menu + My::addBackendMenuItem(); + // behaviors that require user perm dcCore::app()->addBehaviors([ 'adminDashboardFavoritesV2' => [BackendBehaviors::class, 'adminDashboardFavoritesV2'], diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index b7951a9..8d3949f 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -16,9 +16,8 @@ namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; use dcCore; -use dcPage; -use dcFavorites; use dcSettings; +use Dotclear\Core\Backend\Favorites; use Dotclear\Database\MetaRecord; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -218,7 +217,7 @@ class BackendBehaviors [(new Para()) ->items([ (new Link()) - ->href(dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) + ->href(My::managerUrl()) ->text(__('Configure feeds')), ])] : [], @@ -231,13 +230,13 @@ class BackendBehaviors /** * User dashboard favorites icon. */ - public static function adminDashboardFavoritesV2(dcFavorites $favs): void + public static function adminDashboardFavoritesV2(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, @@ -250,11 +249,8 @@ class BackendBehaviors } $fav['title'] .= '
' . sprintf(__('%s feed disabled', '%s feeds disabled', (int) $count), (int) $count); - $fav['large-icon'] = dcPage::getPF(My::id() . '/icon-update.svg'); - $fav['url'] = dcCore::app()->adminurl->get( - 'admin.plugin.' . My::id(), - ['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc'] - ); + $fav['large-icon'] = My::fileURL('icon-update.svg'); + $fav['url'] = My::manageUrl(['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']); }, ]); } @@ -329,7 +325,7 @@ class BackendBehaviors } else { $row = new FeedRow(ZoneclearFeedServer::instance()->getFeeds(['feed_id' => $rs_meta->f('meta_id')])); $item = (new Link()) - ->href(dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => 'feed', 'feed_id' => $row->id]) . '#feed') + ->href(My::manageUrl(['part' => 'feed', 'feed_id' => $row->id]) . '#feed') ->title(__('edit feed')) ->text(Html::escapeHTML($row->name)); } @@ -341,7 +337,7 @@ class BackendBehaviors */ public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(My::id() . '/js/post.js'); + return My::jsLoad('post'); } /** @@ -402,10 +398,7 @@ class BackendBehaviors ]); if (!$fid->isEmpty()) { $edit = (new Link()) - ->href(dcCore::app()->adminurl->get( - 'admin.plugin.' . My::id(), - ['part' => 'feed', 'feed_id' => $fid->f('meta_id')] - )) + ->href(My::manageUrl(['part' => 'feed', 'feed_id' => $fid->f('meta_id')])) ->text(__('Edit this feed')); } } diff --git a/src/Config.php b/src/Config.php index 1f42d55..ec6e239 100644 --- a/src/Config.php +++ b/src/Config.php @@ -14,28 +14,28 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; -use adminModulesList; use dcCore; -use dcPage; -use dcNsProcess; +use Dotclear\Core\Backend\{ + Notices, + ModulesList, + Page +}; +use Dotclear\Core\Process; use Exception; /** * Backend module configuration. */ -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; } @@ -47,13 +47,13 @@ class Config extends dcNsProcess try { BackendBehaviors::adminBeforeBlogSettingsUpdate(null); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Configuration has been successfully updated.') ); - dcCore::app()->adminurl?->redirect('admin.plugins', [ + dcCore::app()->admin->url->redirect('admin.plugins', [ 'module' => My::id(), 'conf' => '1', - 'redir' => !(dcCore::app()->admin->__get('list') instanceof adminModulesList) ? '' : dcCore::app()->admin->__get('list')->getRedir(), + 'redir' => !(dcCore::app()->admin->__get('list') instanceof ModulesList) ? '' : dcCore::app()->admin->__get('list')->getRedir(), ]); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -64,12 +64,12 @@ class Config extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } BackendBehaviors::adminBlogPreferencesFormV2(null); - dcPage::helpBlock('zoneclearFeedServer'); + Page::helpBlock('zoneclearFeedServer'); } } diff --git a/src/FeedsActions.php b/src/FeedsActions.php index 462da9c..987bf7b 100644 --- a/src/FeedsActions.php +++ b/src/FeedsActions.php @@ -15,9 +15,9 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; -use dcActions; use dcCore; -use dcPage; +use Dotclear\Core\Backend\Action\Actions; +use Dotclear\Core\Backend\Page; use Dotclear\Database\MetaRecord; use Dotclear\Helper\Html\Form\{ Link, @@ -29,7 +29,7 @@ use Exception; /** * Backend feeds list actions handler. */ -class FeedsActions extends dcActions +class FeedsActions extends Actions { public ZoneclearFeedServer $zcfs; @@ -61,9 +61,9 @@ class FeedsActions extends dcActions public function beginPage(string $breadcrumb = '', string $head = ''): void { - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsLoad('js/_posts_actions.js') . + Page::jsLoad('js/_posts_actions.js') . $head ); echo @@ -78,14 +78,14 @@ class FeedsActions extends dcActions public function endPage(): void { - dcPage::closeModule(); + Page::closeModule(); } public function error(Exception $e): void { dcCore::app()->error->add($e->getMessage()); $this->beginPage( - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML((string) dcCore::app()->blog?->name) => '', $this->getCallerTitle() => $this->getRedirection(true), __('Feeds actions') => '', diff --git a/src/FeedsDefaultActions.php b/src/FeedsDefaultActions.php index 13d2bec..d67e4b0 100644 --- a/src/FeedsDefaultActions.php +++ b/src/FeedsDefaultActions.php @@ -17,7 +17,10 @@ namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; use dcCore; use dcMeta; -use dcPage; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Database\Statement\DeleteStatement; use Dotclear\Helper\Html\Form\{ Form, @@ -93,7 +96,7 @@ class FeedsDefaultActions $ap->zcfs->enableFeed($id, $enable); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( $enable ? __( '%d feed has been successfully enabled.', @@ -150,7 +153,7 @@ class FeedsDefaultActions } } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Entries have been successfully deleted.') ); $ap->redirect(true); @@ -173,7 +176,7 @@ class FeedsDefaultActions $ap->zcfs->deleteFeed($id); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( __( '%d feed has been successfully deleted.', '%d feeds have been successfully deleted.', @@ -201,7 +204,7 @@ class FeedsDefaultActions $ap->zcfs->checkFeedsUpdate($id, true); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( __('%d feed has been successfully updated.', '%d feeds have been successfully updated.', count($ids)), count($ids) )); @@ -229,7 +232,7 @@ class FeedsDefaultActions //$ap->zcfs->checkFeedsUpdate($id, true); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( __('Last update of %s feed successfully reseted.', 'Last update of %s feeds successfully reseted.', count($ids)), count($ids) )); @@ -259,14 +262,14 @@ class FeedsDefaultActions $ap->zcfs->updateFeed($id, $cur); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( __('Category of %s feed successfully changed.', 'Category of %s feeds successfully changed.', count($ids)), count($ids) )); $ap->redirect(true); } else { $ap->beginPage( - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML((string) dcCore::app()->blog?->name) => '', __('Feeds server') => '', $ap->getCallerTitle() => $ap->getRedirection(true), @@ -325,14 +328,14 @@ class FeedsDefaultActions $ap->zcfs->updateFeed($id, $cur); } - dcPage::addSuccessNotice(sprintf( + Notices::addSuccessNotice(sprintf( __('Update frequency of %s feed successfully changed.', 'Update frequency of %s feeds successfully changed.', count($ids)), count($ids) )); $ap->redirect(true); } else { $ap->beginPage( - dcPage::breadcrumb( + Page::breadcrumb( [ Html::escapeHTML((string) dcCore::app()->blog?->name) => '', __('Feeds server') => '', diff --git a/src/FeedsList.php b/src/FeedsList.php index ff99440..50b8dc5 100644 --- a/src/FeedsList.php +++ b/src/FeedsList.php @@ -15,10 +15,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; -use adminGenericFilterV2; -use adminGenericListV2; 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, @@ -32,9 +34,9 @@ use Dotclear\Helper\Html\Html; /** * Backend feeds list. */ -class FeedsList extends adminGenericListV2 +class FeedsList extends Listing { - public function display(adminGenericFilterV2 $filter, string $enclose_block = ''): void + public function display(Filters $filter, string $enclose_block = ''): void { if ($this->rs->isEmpty()) { echo @@ -53,7 +55,7 @@ class FeedsList extends adminGenericListV2 $page = is_numeric($filter->value('page')) ? (int) $filter->value('page') : 1; $nbpp = is_numeric($filter->value('nb')) ? (int) $filter->value('nb') : 10; $count = (int) $this->rs_count; - $pager = new dcPager($page, $count, $nbpp, 10); + $pager = new Pager($page, $count, $nbpp, 10); $cols = new ArrayObject([ 'title' => (new Text('th', __('Name'))) @@ -120,11 +122,11 @@ class FeedsList extends adminGenericListV2 $shunk_feed = substr($shunk_feed, 0, 50) . '...' . substr($shunk_feed, -20); } - $url = dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => 'feed', 'feed_id' => $row->id]); + $url = My::manageUrl(['part' => 'feed', 'feed_id' => $row->id]); if (!is_string($url)) { $url = ''; } - $tz = dcCore::app()->auth?->getInfo('user_tz'); + $tz = dcCore::app()->auth->getInfo('user_tz'); if (!is_string($tz)) { $tz = 'UTC'; } diff --git a/src/Frontend.php b/src/Frontend.php index 340e6dd..9ceb688 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,8 +15,8 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use dcCore; -use dcNsProcess; use dcUtils; +use Dotclear\Core\Process; use Dotclear\Database\MetaRecord; use Dotclear\Helper\Html\Html; use Exception; @@ -24,18 +24,16 @@ use Exception; /** * 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/Install.php b/src/Install.php index 10a4cad..c6d0363 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,28 +15,23 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Database\Structure; use Exception; /** * Module installation. */ -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; } @@ -75,10 +70,7 @@ class Install extends dcNsProcess (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); // Settings - $s = dcCore::app()->blog?->settings->get(My::id()); - if (is_null($s)) { - return false; - } + $s = My::settings(); $s->put('active', false, 'boolean', 'Enable zoneclearBlogServer', false, true); $s->put('pub_active', false, 'boolean', 'Enable public page of list of feeds', false, true); $s->put('post_status_new', true, 'boolean', 'Enable auto publish new posts', false, true); diff --git a/src/Manage.php b/src/Manage.php index ed85e84..5f39cf0 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -14,11 +14,16 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; -use adminGenericFilterV2; -use dcAdminFilters; 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\Html\Form\{ Div, Form, @@ -34,27 +39,23 @@ use Exception; /** * Backend feeds list manage page. */ -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, - ]), dcCore::app()->blog->id); + self::status(My::checkContext(My::MANAGE)); // call period manage page if (($_REQUEST['part'] ?? 'feeds') === 'feed') { - static::$init = ManageFeed::init(); + self::status(ManageFeed::init()); } - return static::$init; + return self::status(); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -78,7 +79,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } @@ -87,16 +88,16 @@ class Manage extends dcNsProcess // not configured if (!$s->active || !$s->user) { - dcPage::openModule(My::id()); + Page::openModule(My::id()); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', ]) . - dcPage::notices(); + Notices::getNotices(); - dcPage::closeModule(); + Page::closeModule(); return; } @@ -118,10 +119,10 @@ class Manage extends dcNsProcess } // feeds filters - $feeds_filter = new adminGenericFilterV2(My::id() . 'feeds'); + $feeds_filter = new Filters(My::id() . 'feeds'); $feeds_filter->add('part', 'feeds'); - $feeds_filter->add(dcAdminFilters::getPageFilter()); - $feeds_filter->add(dcAdminFilters::getSearchFilter()); + $feeds_filter->add(FiltersLibrary::getPageFilter()); + $feeds_filter->add(FiltersLibrary::getSearchFilter()); $params = $feeds_filter->params(); // feeds list @@ -133,24 +134,24 @@ class Manage extends dcNsProcess dcCore::app()->error->add($e->getMessage()); } - dcPage::openModule( + Page::openModule( My::id(), ( isset($feeds_list) && !dcCore::app()->error->flag() ? - $feeds_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'feeds'], '&')) . - dcPage::jsModuleLoad(My::id() . '/js/feeds.js') + $feeds_filter->js(My::manageUrl(['part' => 'feeds'], '&')) . + My::jsLoad('feeds') : '' ) . - dcPage::jsPageTabs() + Page::jsPageTabs() ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), __('Feeds list') => '', ]) . - dcPage::notices(); + Notices::getNotices(); echo (new Para()) @@ -159,21 +160,21 @@ class Manage extends dcNsProcess (new Link()) ->class('button add') ->text(__('New feed')) - ->href((string) dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'feed'])), + ->href((string) My::manageUrl(['part' => 'feed'])), ]) ->render(); if (isset($feeds_list)) { $feeds_filter->display( 'admin.plugin.' . My::id(), - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), ['part' => 'feeds']) + My::parsedHiddenFields(['part' => 'feeds']) ); $feeds_list->display( $feeds_filter, (new Form('form-feeds')) ->method('post') - ->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'feeds'])) + ->action(My::manageUrl(['part' => 'feeds'])) ->fields([ (new Text('', '%s')), (new Div()) @@ -183,25 +184,22 @@ class Manage extends dcNsProcess ->class('col checkboxes-helpers'), (new Para()) ->class('col right') - ->items(array_merge( - dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), $feeds_filter->values(true)), - [ - (new Label(__('Selected feeds action:'), Label::OUTSIDE_LABEL_BEFORE)) - ->for('action'), - (new Select('action')) - ->items($feeds_actions_page->getCombo()), - (new Submit('feeds-action')) - ->value(__('ok')), - dcCore::app()->formNonce(false), + ->items([ + (new Label(__('Selected feeds action:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('action'), + (new Select('action')) + ->items($feeds_actions_page->getCombo()), + (new Submit('feeds-action')) + ->value(__('ok')), + ... My::hiddenFields($feeds_filter->values(true)), - ] - )), + ]), ]), ]) ->render() ); } - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/ManageFeed.php b/src/ManageFeed.php index c3c2db5..e8d272c 100644 --- a/src/ManageFeed.php +++ b/src/ManageFeed.php @@ -15,9 +15,12 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use dcCore; -use dcNsProcess; -use dcPage; -use dcPostsActions; +use Dotclear\Core\Backend\Action\ActionsPosts; +use Dotclear\Core\Backend\{ + Notices, + Page +}; +use Dotclear\Core\Process; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -37,23 +40,16 @@ use Exception; /** * Backend feed and feed posts manage page. */ -class ManageFeed extends dcNsProcess +class ManageFeed 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, - ]), dcCore::app()->blog->id) - && ($_REQUEST['part'] ?? 'feeds') === 'feed'; - - return static::$init; + return self::status(My::checkContext(My::MANAGE) && ($_REQUEST['part'] ?? 'feeds') === 'feed'); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -104,13 +100,8 @@ class ManageFeed extends dcNsProcess throw new Exception(__('Failed to save feed.')); } - dcPage::addSuccessNotice( - __('Feed successfully created.') - ); - dcCore::app()->adminurl?->redirect( - 'admin.plugin.' . My::id(), - ['part' => 'feed', 'feed_id' => $id] - ); + Notices::addSuccessNotice(__('Feed successfully created.')); + My::redirect(['part' => 'feed', 'feed_id' => $id]); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -125,7 +116,7 @@ class ManageFeed extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } @@ -136,7 +127,7 @@ class ManageFeed extends dcNsProcess // Prepared entries list if ($v->id && $v->can_view_page) { // posts actions - $posts_actions_page = new dcPostsActions( + $posts_actions_page = new ActionsPosts( 'plugin.php', [ 'p' => My::id(), @@ -188,25 +179,25 @@ class ManageFeed extends dcNsProcess } // display - dcPage::openModule( + Page::openModule( My::id(), ( $v->id && isset($post_filter) && !dcCore::app()->error->flag() ? - $post_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'feed', 'feed_id' => $v->id], '&') . '#entries') . - dcPage::jsModuleLoad(My::id() . '/js/feed.js') + $post_filter->js(My::manageUrl(['part' => 'feed', 'feed_id' => $v->id], '&') . '#entries') . + My::jsLoad('feed') : '' ) . - dcPage::jsPageTabs() . + Page::jsPageTabs() . $v->next_headlink . "\n" . $v->prev_headlink ); echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), ($v->id ? __('Edit feed') : __('New feed')) => '', ]) . - dcPage::notices() . + Notices::getNotices() . (new Text('h3', ($v->id ? sprintf(__('Edit feed "%s"'), Html::escapeHTML($v->name)) : __('New feed'))))->render(); if ($v->can_view_page) { @@ -232,7 +223,7 @@ class ManageFeed extends dcNsProcess ->items([ (new Form('edit-entry-form')) ->method('post') - ->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) + ->action(My::manageUrl()) ->fields([ (new Div()) ->class('two-cols') @@ -379,19 +370,16 @@ class ManageFeed extends dcNsProcess ]), (new Para()) ->class('clear') - ->items(array_merge( - dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), [ + ->items([ + (new Submit(['save'])) + ->value(__('Save') . ' (s)') + ->accesskey('s'), + ... My::hiddenFields([ 'part' => 'feed', 'feed_id' => (string) $v->id, 'action' => 'savefeed', ]), - [ - (new Submit(['save'])) - ->value(__('Save') . ' (s)') - ->accesskey('s'), - dcCore::app()->formNonce(false), - ] - )), + ]), ]), ]) ->render(); @@ -403,7 +391,7 @@ class ManageFeed extends dcNsProcess # show posts filters $post_filter->display( ['admin.plugin.' . My::id(),'#entries'], - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), [ + My::manageUrl([ 'part' => 'feed', 'feed_id' => $v->id, ]) @@ -417,10 +405,10 @@ class ManageFeed extends dcNsProcess # show posts $post_list->display( $post_filter, - dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $args, '&') . '#entries', + My::manageUrl($args, '&') . '#entries', (new Form('form-entries')) ->method('post') - ->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'feed']) . '#entries') + ->action(My::manageUrl(['part' => 'feed']) . '#entries') ->fields([ (new Text('', '%s')), (new Div()) @@ -430,21 +418,17 @@ class ManageFeed extends dcNsProcess ->class('col checkboxes-helpers'), (new Para()) ->class('col right') - ->items(array_merge( - dcCore::app()->adminurl->hiddenFormFields('admin.plugin.' . My::id(), $post_filter->values()), - [ - (new Hidden('redir', dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $post_filter->values()))), - (new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE)) - ->for('action'), - (new Select('action')) - ->items($posts_actions_page->getCombo()), - (new Submit('feed-action')) - ->value(__('ok')), - dcCore::app()->formNonce(false), - - ] - )), + ->items([ + (new Hidden('redir', My::manageUrl($post_filter->values()))), + (new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE)) + ->for('action'), + (new Select('action')) + ->items($posts_actions_page->getCombo()), + (new Submit('feed-action')) + ->value(__('ok')), + ... My::hiddenFields($post_filter->values()), + ]), ]), ]) ->render() @@ -453,6 +437,6 @@ class ManageFeed extends dcNsProcess echo ''; } - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/ManageFeedVars.php b/src/ManageFeedVars.php index 2b2a2be..230ef8b 100644 --- a/src/ManageFeedVars.php +++ b/src/ManageFeedVars.php @@ -54,7 +54,7 @@ class ManageFeedVars $feed_headlink = ''; $feed_link = '%s'; - $lang = dcCore::app()->auth?->getInfo('user_lang'); + $lang = dcCore::app()->auth->getInfo('user_lang'); // default values $feed_id = 0; diff --git a/src/My.php b/src/My.php index 8f3d876..ee8ee25 100644 --- a/src/My.php +++ b/src/My.php @@ -14,15 +14,15 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; -use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string This module database table name */ - public const TABLE_NAME = 'zc_feed'; + public const TABLE_NAME = \initZoneclearFeedServer::TABLE_NAME; /** @var string This module meta prefix */ public const META_PREFIX = 'zoneclearfeed_'; @@ -55,29 +55,8 @@ class My 'FeedFeedURL', ]; - /** - * This module id. - */ - public static function id(): string + public static function checkCustomContext(int $context): ?bool { - 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__); + return $context == My::BACKEND ? defined('DC_CONTEXT_ADMIN') : null; } } diff --git a/src/PostsFilter.php b/src/PostsFilter.php index 3392d26..3d32cc0 100644 --- a/src/PostsFilter.php +++ b/src/PostsFilter.php @@ -15,19 +15,21 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; -use adminGenericFilterV2; -use dcAdminCombos; -use dcAdminFilter; -use dcAdminFilters; use dcCore; use dcUtils; +use Dotclear\Core\Backend\Combos; +use Dotclear\Core\Backend\Filter\{ + Filter, + Filters, + FiltersLibrary +}; use Dotclear\Helper\Html\Html; use Exception; /** * Backend feed posts list filters. */ -class PostsFilter extends adminGenericFilterV2 +class PostsFilter extends Filters { public function __construct() { @@ -35,7 +37,7 @@ class PostsFilter extends adminGenericFilterV2 parent::__construct('posts'); $filters = new ArrayObject([ - dcAdminFilters::getPageFilter(), + FiltersLibrary::getPageFilter(), $this->getPostUserFilter(), $this->getPostCategoriesFilter(), $this->getPostStatusFilter(), @@ -53,7 +55,7 @@ class PostsFilter extends adminGenericFilterV2 /** * Posts users select * - * @return null|dcAdminFilter + * @return null|Filter */ public function getPostUserFilter() { @@ -70,10 +72,10 @@ class PostsFilter extends adminGenericFilterV2 return null; } - $combo = dcAdminCombos::getUsersCombo($users); + $combo = Combos::getUsersCombo($users); dcUtils::lexicalKeySort($combo); - return (new dcAdminFilter('user_id')) + return (new Filter('user_id')) ->param() ->title(__('Author:')) ->options(array_merge( @@ -86,7 +88,7 @@ class PostsFilter extends adminGenericFilterV2 /** * Posts categories select * - * @return null|dcAdminFilter + * @return null|Filter */ public function getPostCategoriesFilter() { @@ -116,7 +118,7 @@ class PostsFilter extends adminGenericFilterV2 } } - return (new dcAdminFilter('cat_id')) + return (new Filter('cat_id')) ->param() ->title(__('Category:')) ->options($combo) @@ -126,21 +128,21 @@ class PostsFilter extends adminGenericFilterV2 /** * Posts status select */ - public function getPostStatusFilter(): dcAdminFilter + public function getPostStatusFilter(): Filter { - return (new dcAdminFilter('status')) + return (new Filter('status')) ->param('post_status') ->title(__('Status:')) ->options(array_merge( ['-' => ''], - dcAdminCombos::getPostStatusesCombo() + Combos::getPostStatusesCombo() )); } /** * Posts by month select * - * @return null|dcAdminFilter + * @return null|Filter */ public function getPostMonthFilter() { @@ -157,13 +159,13 @@ class PostsFilter extends adminGenericFilterV2 return null; } - return (new dcAdminFilter('month')) + return (new Filter('month')) ->param('post_month', function ($f) { return substr($f[0], 4, 2); }) ->param('post_year', function ($f) { return substr($f[0], 0, 4); }) ->title(__('Month:')) ->options(array_merge( ['-' => ''], - dcAdminCombos::getDatesCombo($dates) + Combos::getDatesCombo($dates) )); } } diff --git a/src/PostsList.php b/src/PostsList.php index 4b67912..cf29ea0 100644 --- a/src/PostsList.php +++ b/src/PostsList.php @@ -15,9 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use ArrayObject; -use adminGenericListV2; use dcCore; -use dcPager; +use Dotclear\Core\Backend\Listing\{ + Listing, + Pager +}; use Dotclear\Helper\Date; use Dotclear\Helper\Html\Form\{ Checkbox, @@ -31,7 +33,7 @@ use Dotclear\Helper\Html\Html; /** * Backend feed posts lists. */ -class PostsList extends adminGenericListV2 +class PostsList extends Listing { public function display(PostsFilter $filter, string $base_url, string $enclose_block = ''): void { @@ -52,7 +54,7 @@ class PostsList extends adminGenericListV2 $page = is_numeric($filter->value('page')) ? (int) $filter->value('page') : 1; $nbpp = is_numeric($filter->value('nb')) ? (int) $filter->value('nb') : 10; $count = (int) $this->rs_count; - $pager = new dcPager($page, $count, $nbpp, 10); + $pager = new Pager($page, $count, $nbpp, 10); $pager->base_url = $base_url; $cols = new ArrayObject([ @@ -106,7 +108,7 @@ class PostsList extends adminGenericListV2 { $cat_title = (new Text('', __('None'))); if ($this->rs->cat_title - && dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CATEGORIES]), dcCore::app()->blog?->id) + && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CATEGORIES]), dcCore::app()->blog?->id) ) { $cat_title = (new Link()) ->href('category.php?id=' . $this->rs->cat_id) diff --git a/src/Prepend.php b/src/Prepend.php index db1bd9e..c45aaa7 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -15,23 +15,21 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; /** * Module prepend. */ -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/Settings.php b/src/Settings.php index fa4fa4f..d493287 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -14,9 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; -use dcCore; -use Exception; - /** * Module settings (type hinting). */ @@ -52,11 +49,7 @@ class Settings */ protected function __construct() { - if (is_null(dcCore::app()->blog)) { - throw new Exception(__('Blog is not defined')); - } - - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $update_limit = is_numeric($s->get('update_limit')) ? (int) $s->get('update_limit') : 1; @@ -101,7 +94,7 @@ class Settings */ public function set(string $key, mixed $value): bool { - $s = dcCore::app()->blog?->settings->get(My::id()); + $s = My::settings(); if (!is_null($s) && property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { $s->drop($key); diff --git a/src/Uninstall.php b/src/Uninstall.php index cd2247a..3183c87 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,24 +15,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\zoneclearFeedServer; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Plugin\Uninstaller\Uninstaller; /** * Plugin Uninstaller actions. */ -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/UrlHandler.php b/src/UrlHandler.php index e5d216e..f45b782 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -74,7 +74,7 @@ class UrlHandler extends dcUrlHandlers exit(1); - # Server js + # Server js } elseif ($args == '/zcfsupd.js' && 3 == $s->bhv_pub_upd) { dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::path() . '/default-templates'); self::serveDocument( @@ -84,13 +84,13 @@ class UrlHandler extends dcUrlHandlers false ); - # Server feeds description page + # Server feeds description page } elseif (in_array($args, ['', '/']) && $s->pub_active) { $theme = dcCore::app()->blog->settings->get('system')->get('theme'); if (!is_string($theme)) { self::p404(); } - $tplset = dcCore::app()->themes->moduleInfo($theme, 'tplset'); + $tplset = dcCore::app()->themes->getDefine($theme)->get('tplset'); $path = My::path() . '/default-templates/'; if (!empty($tplset) && is_dir($path . $tplset)) { dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $path . $tplset); diff --git a/src/ZoneclearFeedServer.php b/src/ZoneclearFeedServer.php index 209c902..5da3571 100644 --- a/src/ZoneclearFeedServer.php +++ b/src/ZoneclearFeedServer.php @@ -528,7 +528,7 @@ class ZoneclearFeedServer } $i++; - # Not updated since last visit + # Not updated since last visit } elseif (!$id && '' != $feed->pubdate && strtotime($feed->pubdate) < $row->upd_last @@ -625,7 +625,7 @@ class ZoneclearFeedServer $is_new_published_entry = true; } - # Update entry + # Update entry } else { $post_id = is_numeric($old_post->f('post_id')) ? (int) $old_post->f('post_id') : 0; @@ -764,7 +764,7 @@ class ZoneclearFeedServer if (!dcCore::app()->auth->checkUser($this->settings->user)) { throw new Exception('Unable to set user'); } - # Disable + # Disable } else { // auth on branch My goes readonly //dcCore::app()->auth = null;