diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a69e19..9727000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +templator 1.7 - 2023.10.20 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + templator 1.6 - 2023.08.15 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index e83a7be..48e716e 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,25 @@ # README -[![Release](https://img.shields.io/badge/release-1.6-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases) -[![Date](https://img.shields.io/badge/date-2023.08.15-c44d58.svg)](https://git.dotclear.watch/JcDenis/templator/releases) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![Release](https://img.shields.io/badge/release-1.7-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases) +![Date](https://img.shields.io/badge/date-2023.10.20-c44d58.svg) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/templator) -[![License](https://img.shields.io/github/license/JcDenis/templator)](https://git.dotclear.watch/JcDenis/templator/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE) -## WHAT IS TEMPLATOR ? +## ABOUT -_templator_ is a plugin for the open-source -web publishing software called Dotclear. +_templator_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -It help you to manage additonnal tempaltes for your blog. +> Help you to manage additonnal tempaltes for your blog. You can copy existing templates, then edit them. You can attribute a template to a post or a category. ## REQUIREMENTS -_templator_ requires: - -* content admin or templator -* Dotclear 2.27 +* Dotclear 2.28 * PHP 8.1+ -* A writable directory on public path to store tempaltes +* System writable directory on public path to store tempaltes +* Dotclear content admin or templator ## USAGE @@ -34,14 +31,15 @@ You can manage your additional templates from menu ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/templator) or [GitHub Page](https://github.com/JcDenis/templator) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/templator/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/templator) -* Discuss and help : [Dotclear Forum](http://forum.dotclear.net/viewtopic.php?id=42059) +* [License](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/templator/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/templator)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/templator) (or on [GitHub](https://github.com/JcDenis/templator)) +* [Issues & security](https://git.dotclear.watch/JcDenis/templator/issues) (or on [GitHub](https://github.com/JcDenis/templator/issues)) +* [Discuss & help](http://forum.dotclear.net/viewtopic.php?id=42059) ## CONTRIBUTORS * Osku (author) -* Jean-Christian Denis +* Jean-Christian Denis (latest) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index d402849..d8720ce 100644 --- a/_define.php +++ b/_define.php @@ -1,36 +1,30 @@ registerModule( 'Templates engine', 'Create and select more templates for your posts', 'Osku and contributors', - '1.6', + '1.7', [ - 'requires' => [ - ['php', '8.1'], - ['core', '2.27'], - ], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - initTemplator::PERMISSION_TEMPLATOR, - ]), - 'type' => 'plugin', - 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', - 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', - 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'type' => 'plugin', + 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', + 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', + 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', ] ); diff --git a/_init.php b/_init.php deleted file mode 100644 index ad94697..0000000 --- a/_init.php +++ /dev/null @@ -1,20 +0,0 @@ - Templates engine - 1.6 + 1.7 Osku and contributors Create and select more templates for your posts - https://git.dotclear.watch/JcDenis/templator/releases/download/v1.6/plugin-templator.zip - 2.27 + https://git.dotclear.watch/JcDenis/templator/releases/download/v1.7/plugin-templator.zip + 2.28 https://git.dotclear.watch/JcDenis/templator/src/branch/master/README.md https://git.dotclear.watch/JcDenis/templator/issues diff --git a/src/Backend.php b/src/Backend.php index 11a1966..7467bb0 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,22 +1,20 @@ addBehaviors([ - 'adminPostHeaders' => [BackendBehaviors::class,'adminPostHeaders'], - 'adminPostFormItems' => [BackendBehaviors::class,'adminPostFormItems'], - 'adminPageHeaders' => [BackendBehaviors::class,'adminPostHeaders'], - 'adminPageFormItems' => [BackendBehaviors::class,'adminPostFormItems'], - 'adminAfterPostCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'], - 'adminBeforePostUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'], - 'adminAfterPageCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'], - 'adminBeforePageUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'], - 'adminPostsActions' => [BackendBehaviors::class,'adminPostsActions'], - 'adminPagesActions' => [BackendBehaviors::class,'adminPostsActions'], - 'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'], - 'initWidgets' => [Widgets::class, 'initWidgets'], + App::behavior()->addBehaviors([ + 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...), + 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...), + 'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...), + 'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...), + 'adminAfterPostCreate' => BackendBehaviors::adminBeforePostUpdate(...), + 'adminBeforePostUpdate' => BackendBehaviors::adminBeforePostUpdate(...), + 'adminAfterPageCreate' => BackendBehaviors::adminBeforePostUpdate(...), + 'adminBeforePageUpdate' => BackendBehaviors::adminBeforePostUpdate(...), + 'adminPostsActions' => BackendBehaviors::adminPostsActions(...), + 'adminPagesActions' => BackendBehaviors::adminPostsActions(...), + 'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...), + 'initWidgets' => Widgets::initWidgets(...), ]); return true; diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 7e0b907..df76dd4 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -1,21 +1,11 @@ meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->f('post_id')]); + $post_meta = App::meta()->getMetadata(['meta_type' => 'template', 'post_id' => $post->f('post_id')]); $selected = $post_meta->isEmpty() ? '' : $post_meta->f('meta_id'); } @@ -58,9 +56,9 @@ class BackendBehaviors $post_id = (int) $post_id; if (isset($_POST['post_tpl'])) { - dcCore::app()->meta->delPostMeta($post_id, 'template'); + App::meta()->delPostMeta($post_id, 'template'); if (!empty($_POST['post_tpl'])) { - dcCore::app()->meta->setPostMeta($post_id, 'template', $_POST['post_tpl']); + App::meta()->setPostMeta($post_id, 'template', $_POST['post_tpl']); } } } @@ -73,7 +71,7 @@ class BackendBehaviors __('Select the template') => 'tpl', ], ], - [self::class, 'adminPostsActionsCallback'] + self::adminPostsActionsCallback(...) ); } @@ -90,24 +88,24 @@ class BackendBehaviors if (isset($post['post_tpl']) && is_string($post['post_tpl'])) { try { foreach ($posts_ids as $post_id) { - dcCore::app()->meta->delPostMeta($post_id, 'template'); + App::meta()->delPostMeta($post_id, 'template'); if (!empty($post['post_tpl'])) { - dcCore::app()->meta->setPostMeta($post_id, 'template', $post['post_tpl']); + App::meta()->setPostMeta($post_id, 'template', $post['post_tpl']); } } Notices::addSuccessNotice(__('Entries template updated.')); $pa->redirect(true); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } $pa->beginPage( Page::breadcrumb([ - Html::escapeHTML((string) dcCore::app()->blog?->name) => '', - $pa->getCallerTitle() => $pa->getRedirection(true), - __('Entry template') => '', + Html::escapeHTML(App::blog()->name()) => '', + $pa->getCallerTitle() => $pa->getRedirection(true), + __('Entry template') => '', ]) ); @@ -120,7 +118,7 @@ class BackendBehaviors '

' . $pa->getHiddenFields() . - dcCore::app()->formNonce() . + App::nonce()->getFormNonce() . form::hidden(['action'], 'tpl') . '

' . ''; diff --git a/src/Frontend.php b/src/Frontend.php index a75ce8e..545c584 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,25 +1,20 @@ tpl->setPath( - dcCore::app()->tpl->getPath(), + App::frontend()->template()->setPath( + App::frontend()->template()->getPath(), Templator::instance()->getPath() ); - dcCore::app()->addBehaviors([ + App::behavior()->addBehaviors([ 'urlHandlerBeforeGetData' => function ($_): void { - if (is_null(dcCore::app()->ctx)) { - return; - } - - if ((dcCore::app()->ctx->__get('posts') instanceof MetaRecord) - && (array_key_exists(dcCore::app()->url->type, dcCore::app()->getPostTypes()) || dcCore::app()->url->type == 'pages')) { + if ((App::frontend()->context()->__get('posts') instanceof MetaRecord) + && (array_key_exists(App::url()->type, App::postTypes()->getPostTypes()) || App::url()->type == 'pages')) { $params = []; $params['meta_type'] = 'template'; - $params['post_id'] = dcCore::app()->ctx->__get('posts')->f('post_id'); - $post_meta = dcCore::app()->meta->getMetadata($params); + $params['post_id'] = App::frontend()->context()->__get('posts')->f('post_id'); + $post_meta = App::meta()->getMetadata($params); - if (!$post_meta->isEmpty() && is_string($post_meta->f('meta_id')) && dcCore::app()->tpl->getFilePath($post_meta->f('meta_id'))) { - dcCore::app()->ctx->__set('current_tpl', $post_meta->f('meta_id')); + if (!$post_meta->isEmpty() && is_string($post_meta->f('meta_id')) && App::frontend()->template()->getFilePath($post_meta->f('meta_id'))) { + App::frontend()->context()->__set('current_tpl', $post_meta->f('meta_id')); } } - if (dcCore::app()->ctx->__get('current_tpl') == 'category.html' - && (dcCore::app()->ctx->__get('categories') instanceof MetaRecord) - && is_string(dcCore::app()->ctx->__get('categories')->f('cat_id')) - && preg_match('/^[0-9]{1,}/', dcCore::app()->ctx->__get('categories')->f('cat_id'), $cat_id) + if (App::frontend()->context()->__get('current_tpl') == 'category.html' + && (App::frontend()->context()->__get('categories') instanceof MetaRecord) + && is_string(App::frontend()->context()->__get('categories')->f('cat_id')) + && preg_match('/^[0-9]{1,}/', App::frontend()->context()->__get('categories')->f('cat_id'), $cat_id) ) { $tpl = 'category-' . $cat_id[0] . '.html'; - if (dcCore::app()->tpl->getFilePath($tpl)) { - dcCore::app()->ctx->__set('current_tpl', $tpl); + if (App::frontend()->template()->getFilePath($tpl)) { + App::frontend()->context()->__set('current_tpl', $tpl); } } }, - 'initWidgets' => [Widgets::class, 'initWidgets'], + 'initWidgets' => Widgets::initWidgets(...), ]); return true; diff --git a/src/Manage.php b/src/Manage.php index 77e0208..f95b9a0 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -1,20 +1,10 @@ initializeTpl($name, $_POST['filesource']); - if (!dcCore::app()->error->flag()) { + if (!App::error()->flag()) { Notices::addSuccessNotice(__('The new template has been successfully created.')); My::redirect(); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -82,12 +80,12 @@ class Manage extends Process rawurldecode($_POST['file']) ); - if (!dcCore::app()->error->flag()) { + if (!App::error()->flag()) { Notices::addSuccessNotice(__('The template has been successfully copied.')); My::redirect(['part' => 'files']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -101,12 +99,12 @@ class Manage extends Process rawurldecode($_POST['file']) ); - if (!dcCore::app()->error->flag()) { + if (!App::error()->flag()) { Notices::addSuccessNotice(__('The template has been successfully copied.')); My::redirect(['part' => 'files']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -117,14 +115,14 @@ class Manage extends Process try { $file = rawurldecode($_POST['file']); $v->media->removeItem($file); - dcCore::app()->meta->delMeta($file, 'template'); + App::meta()->delMeta($file, 'template'); if (!dcCore::app()->error->flag()) { Notices::addSuccessNotice(__('The template has been successfully removed.')); My::redirect(['part' => 'files']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -133,12 +131,9 @@ class Manage extends Process public static function render(): void { - if (!self::status()) { - return; - } - - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!self::status() + || !App::blog()->isDefined() + ) { return; } @@ -151,7 +146,7 @@ class Manage extends Process */ if (!$t->canUseRessources(true)) { - dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.')); + App::error()->add(__('The plugin is unusable with your configuration. You have to change file permissions.')); Page::openModule(My::name()); echo Page::breadcrumb([ @@ -226,12 +221,12 @@ class Manage extends Process */ } elseif ('copycat' == $v->part && !empty($_REQUEST['file'])) { $category_id = (int) str_replace(['category-','.html'], '', $_REQUEST['file']); - $cat_parents = dcCore::app()->blog->getCategoryParents($category_id); + $cat_parents = App::blog()->getCategoryParents($category_id); $full_name = ''; while ($cat_parents->fetch()) { $full_name = $cat_parents->f('cat_title') . ' › '; }; - $name = $full_name . dcCore::app()->blog->getCategory($category_id)->f('cat_title'); + $name = $full_name . App::blog()->getCategory($category_id)->f('cat_title'); Page::openModule(My::name()); echo @@ -322,8 +317,8 @@ class Manage extends Process * List Used templator template */ } elseif ('used' == $v->part) { - $tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']); - $tags = dcCore::app()->meta->computeMetaStats($tags); + $tags = App::meta()->getMetadata(['meta_type' => 'template']); + $tags = App::meta()->computeMetaStats($tags); $tags->sort('meta_id_lower', 'asc'); $last_letter = null; @@ -403,9 +398,9 @@ class Manage extends Process $name = $file['f']; if (preg_match('/^category-(.+).html$/', $name, $cat_id)) { - $category = dcCore::app()->blog->getCategory((int) $cat_id[1]); + $category = App::blog()->getCategory((int) $cat_id[1]); $full_name = ''; - $cat_parents = dcCore::app()->blog->getCategoryParents((int) $cat_id[1]); + $cat_parents = App::blog()->getCategoryParents((int) $cat_id[1]); while ($cat_parents->fetch()) { $full_name = $cat_parents->f('cat_title') . ' › '; }; @@ -422,16 +417,16 @@ class Manage extends Process $t->writeTpl($file['f'], $file['c']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } - $ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + $ict = App::auth()->prefs()->get('interface')->get('colorsyntax_theme'); Page::openModule( My::name(), ( - dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? - Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) : '' + App::auth()->prefs()->get('interface')->get('colorsyntax') ? + Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => App::auth()->prefs()->get('interface')->get('colorsyntax')]) : '' ) . Page::jsJson('theme_editor_msg', [ 'saving_document' => __('Saving document...'), @@ -442,7 +437,7 @@ class Manage extends Process Page::jsModuleLoad('themeEditor/js/script.js') . Page::jsConfirmClose('file-form') . ( - dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ? + App::auth()->prefs()->get('interface')->get('colorsyntax') ? Page::jsLoadCodeMirror(is_string($ict) ? $ict : '') : '' ) . Page::cssModuleLoad('themeEditor/style.css') @@ -478,8 +473,8 @@ class Manage extends Process echo ''; - if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) { - $ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + if (App::auth()->prefs()->get('interface')->get('colorsyntax')) { + $ict = App::auth()->prefs()->get('interface')->get('colorsyntax_theme'); echo Page::jsJson('theme_editor_mode', ['mode' => 'html']) . Page::jsModuleLoad('themeEditor/js/mode.js') . @@ -495,15 +490,15 @@ class Manage extends Process $redir = $_REQUEST['redir'] ?? My::manageUrl(['part' => 'used']); # Unselect the template - if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_PUBLISH, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id)) { + if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && App::auth()->check(App::auth()->makePermissions([ + App::auth()::PERMISSION_PUBLISH, + App::auth()::PERMISSION_CONTENT_ADMIN, + ]), App::blog()->id())) { try { - dcCore::app()->meta->delMeta($file, 'template'); + App::meta()->delMeta($file, 'template'); My::redirect(['part' => 'posts', 'file' => $file]); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -520,15 +515,15 @@ class Manage extends Process # Get posts try { - $posts = dcCore::app()->meta->getPostsByMeta($params); + $posts = App::meta()->getPostsByMeta($params); if (is_null($posts)) { throw new Exception(__('Failed to get posts meta')); } - $counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0); + $counter = App::meta()->getPostsByMeta($params, true)?->f(0); $counter = is_numeric($counter) ? (int) $counter : 0; $post_list = new ListingPosts($posts, $counter); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } Page::openModule( @@ -549,7 +544,7 @@ class Manage extends Process '

' . sprintf(__('Unselect template "%s"'), '' . $file . '') . '

' . '

' . __('Back') . '

'; - if (!dcCore::app()->error->flag() && isset($posts)) { + if (!App::error()->flag() && isset($posts)) { if ($posts->isEmpty() && !$filter->show()) { echo '

' . __('There is no entries') . '

'; } else { @@ -573,9 +568,9 @@ class Manage extends Process '

' . '

' . form::hidden('action', 'unselecttpl') . - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), $filter->values()) . + App::backend()->url()->getHiddenFormFields('admin.plugin.' . My::id(), $filter->values()) . form::hidden('redir', $redir) . - dcCore::app()->formNonce() . + App::nonce()->getFormNonce() . '' . '', $filter->show() diff --git a/src/ManageVars.php b/src/ManageVars.php index ea66467..d2121cb 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -1,25 +1,24 @@ $items The media items */ public readonly array $items; @@ -57,10 +56,11 @@ class ManageVars $this->part = empty($name) ? '' : $_REQUEST['part']; // Extend dcMedia to change settings to allow .html vs media_exclusion - $this->media = new Media(); + $this->media = clone App::media(); + $this->media->setExcludePattern('/^(.html)$/i'); $this->media->chdir(Templator::MY_TPL_DIR); // For users with only templator permission, we use sudo. - dcCore::app()->auth?->sudo([$this->media,'getDir']); + App::auth()->sudo($this->media->getDir(...)); $dir = $this->media->dir; $this->items = array_values($dir['files']); @@ -69,7 +69,7 @@ class ManageVars $has_categories = false; try { - $categories = dcCore::app()->blog?->getCategories(['post_type' => 'post']); + $categories = App::blog()->getCategories(['post_type' => 'post']); if (!is_null($categories)) { $l = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1; $full_name = [is_string($categories->f('cat_title')) ? $categories->f('cat_title') : '']; @@ -103,8 +103,8 @@ class ManageVars 'post.html' => 'post', ]; - if (dcCore::app()->plugins->moduleExists('pages') - && dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([initPages::PERMISSION_PAGES]), dcCore::app()->blog?->id) + if (App::plugins()->moduleExists('pages') + && App::auth()->check(App::auth()->makePermissions([Pages::PERMISSION_PAGES]), App::blog()->id()) ) { $sources_combo['page.html'] = 'page'; } diff --git a/src/Media.php b/src/Media.php deleted file mode 100644 index 49ec97f..0000000 --- a/src/Media.php +++ /dev/null @@ -1,26 +0,0 @@ -blog) - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - My::PERMISSION_TEMPLATOR, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - } + return match ($context) { + self::BACKEND, self::MENU, self::MANAGE => App::task()->checkContext('BACKEND') + && App::auth()->check(App::auth()->makePermissions([ + self::PERMISSION_TEMPLATOR, + App::auth()::PERMISSION_CONTENT_ADMIN, + ]), App::blog()->id()), - return null; + default => null, + }; } } diff --git a/src/Pager.php b/src/Pager.php index 7f988c0..e8ff585 100644 --- a/src/Pager.php +++ b/src/Pager.php @@ -1,33 +1,31 @@ blog)) { + if (!App::blog()->isDefined()) { return ''; } - $p_url = dcCore::app()->admin->getPageURL(); + $p_url = App::backend()->getPageURL(); $fname = $f->basename; $count = ''; $params = []; @@ -41,9 +39,9 @@ class Pager if (preg_match('/^category-(.+).html$/', $f->basename, $cat_id)) { $cat_id = (int) $cat_id[1]; - $category = dcCore::app()->blog->getCategory($cat_id); + $category = App::blog()->getCategory($cat_id); $full_name = ''; - $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id); + $cat_parents = App::blog()->getCategoryParents($cat_id); while ($cat_parents->fetch()) { $full_name = $cat_parents->f('cat_title') . ' › '; }; @@ -54,7 +52,7 @@ class Pager $part = 'copycat'; try { - $counter = dcCore::app()->blog->getPosts($params, true); + $counter = App::blog()->getPosts($params, true); if ($counter->f(0) == 0) { $count = __('No entry'); } elseif ($counter->f(0) == 1) { @@ -63,7 +61,7 @@ class Pager $count = '' . $counter->f(0) . ' ' . __('entries') . ''; } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } elseif (preg_match('/^widget-(.+)$/', $f->basename)) { $count = ' '; @@ -75,7 +73,7 @@ class Pager $params['post_type'] = ''; try { - $counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0); + $counter = App::meta()->getPostsByMeta($params, true)?->f(0); $counter = is_numeric($counter) ? (int) $counter : 0; $url = My::manageUrl([ 'part' => 'posts', @@ -90,7 +88,7 @@ class Pager $count = '' . $counter . ' ' . __('entries') . ''; } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -99,10 +97,10 @@ class Pager '