From 3ffacaeb98384d9fc743d0fef9277ab9fd9847c7 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 15 Oct 2023 20:49:39 +0200 Subject: [PATCH] upgrade to Dotclear 2.28 --- CHANGELOG.md | 6 ++ README.md | 2 +- _define.php | 44 ++++----- _init.php | 21 ---- dcstore.xml | 6 +- src/Backend.php | 41 ++++---- src/BackendActionsLinks.php | 27 +++--- src/BackendActionsLinksDefault.php | 35 ++++--- src/BackendListingLinks.php | 25 +++-- src/Combo.php | 35 +++---- src/Frontend.php | 33 +++---- src/FrontendContext.php | 41 ++++---- src/FrontendTemplate.php | 149 ++++++++++++++--------------- src/FrontendUrl.php | 45 ++++----- src/Install.php | 32 +++---- src/Manage.php | 19 ++-- src/ManageCat.php | 27 +++--- src/ManageCats.php | 27 +++--- src/ManageLink.php | 35 ++++--- src/ManageLinks.php | 23 ++--- src/My.php | 57 ++++++----- src/PluginActivityReport.php | 33 +++---- src/PluginSitemaps.php | 33 +++---- src/Prepend.php | 31 +++--- src/Uninstall.php | 22 ++--- src/Utils.php | 79 ++++++++------- src/Widgets.php | 46 ++++----- 27 files changed, 451 insertions(+), 523 deletions(-) delete mode 100644 _init.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0446ab1..3349750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +cinecturlink2 2.1 - 2023.10.15 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1+ +* Upgrade to Dotclear 2.28 + cinecturlink2 2.0 - 2023.08.24 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index 06b4b56..ea51627 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ It is hightly based on cinecturlink for Dotclear 1 by Tigroux and maintain by br ## REQUIREMENTS -* Dotclear 2.27 +* Dotclear 2.28 * PHP 8.1+ * Dotclear admin permission for configuration * Dotclear contentadmin permission for management diff --git a/_define.php b/_define.php index 3ce6a66..9ef57ab 100644 --- a/_define.php +++ b/_define.php @@ -1,44 +1,34 @@ registerModule( 'Cinecturlink 2', 'Widgets and pages about books, musics, films, blogs you are interested in', 'Jean-Christian Denis and Contributors', - '2.0', + '2.1', [ - 'requires' => [ - ['php', '8.1'], - ['core', '2.27'], - ], - 'settings' => [ - 'blog' => '#params.' . basename(__DIR__) . '_params', - ], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_CONTENT_ADMIN, - ]), - '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']], + 'settings' => ['blog' => '#params.' . basename(__DIR__) . '_params'], + '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 55ac9c6..0000000 --- a/_init.php +++ /dev/null @@ -1,21 +0,0 @@ - Cinecturlink 2 - 2.0 + 2.1 Jean-Christian Denis and Contributors Widgets and pages about books, musics, films, blogs you are interested in - https://git.dotclear.watch/JcDenis/cinecturlink2/releases/download/v2.0/plugin-cinecturlink2.zip - 2.27 + https://git.dotclear.watch/JcDenis/cinecturlink2/releases/download/v2.1/plugin-cinecturlink2.zip + 2.28 https://git.dotclear.watch/JcDenis/cinecturlink2/src/branch/master/README.md https://git.dotclear.watch/JcDenis/cinecturlink2/issues diff --git a/src/Backend.php b/src/Backend.php index d869910..db1002e 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,22 +1,12 @@ addBehavior('initWidgets', [Widgets::class, 'initLinks']); - dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initCats']); - - dcCore::app()->addBehaviors([ + App::behavior()->addBehaviors([ + 'initWidgets' => Widgets::init(...), 'adminColumnsListsV2' => function (ArrayObject $cols) { $cols[My::id()] = [ My::name(), @@ -89,13 +84,13 @@ class Backend extends Process 'url' => My::manageUrl() . '#links', 'small-icon' => My::icons(), 'large-icon' => My::icons(), - 'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), + 'permissions' => App::auth()->makePermissions([App::auth()::PERMISSION_CONTENT_ADMIN]), ]); }, - 'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void { + 'adminBlogPreferencesFormV2' => function (BlogSettings $blog_settings): void { $s = $blog_settings->get(My::id()); - $url = (string) dcCore::app()->blog?->url . dcCore::app()->url->getBase(My::id()); + $url = App::blog()->url() . App::url()->getBase(My::id()); $public_nbrpp = (int) $s->get('public_nbrpp'); if ($public_nbrpp < 1) { $public_nbrpp = 10; @@ -202,7 +197,7 @@ class Backend extends Process ->render(); }, - 'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void { + 'adminBeforeBlogSettingsUpdate' => function (BlogSettings $blog_settings): void { $s = $blog_settings->get(My::id()); $active = !empty($_POST[My::id() . 'active']); $widthmax = abs((int) $_POST[My::id() . 'widthmax']); @@ -218,12 +213,12 @@ class Backend extends Process $public_nbrpp = 10; } if (empty($folder)) { - dcCore::app()->error->add(__('You must provide a specific folder for images.')); + App::error()->add(__('You must provide a specific folder for images.')); return; } Utils::makePublicDir( - DC_ROOT . '/' . dcCore::app()->blog?->settings->get('system')->get('public_path'), + App::config()->dotclearRoot() . '/' . App::blog()->settings()->get('system')->get('public_path'), $folder, true ); diff --git a/src/BackendActionsLinks.php b/src/BackendActionsLinks.php index cf1be46..62760c6 100644 --- a/src/BackendActionsLinks.php +++ b/src/BackendActionsLinks.php @@ -1,21 +1,11 @@ callBehavior('cinecturlink2AddDefaultLinksActions', $this); + App::behavior()->callBehavior('cinecturlink2AddDefaultLinksActions', $this); } public function beginPage(string $breadcrumb = '', string $head = ''): void @@ -75,7 +72,7 @@ class BackendActionsLinks extends Actions public function error(Exception $e): void { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); $this->beginPage( Page::breadcrumb([ __('Plugins') => '', diff --git a/src/BackendActionsLinksDefault.php b/src/BackendActionsLinksDefault.php index 0daddf6..9be92fd 100644 --- a/src/BackendActionsLinksDefault.php +++ b/src/BackendActionsLinksDefault.php @@ -1,21 +1,11 @@ addAction( [__('Delete') => 'dellinks'], - [self::class, 'doDeleteLinks'] + self::doDeleteLinks(...) ); $ap->addAction( [__('Change rating') => 'updlinksnote'], - [self::class, 'doChangeNote'] + self::doChangeNote(...) ); $ap->addAction( [__('Change category') => 'updlinkscat'], - [self::class, 'doChangeCategory'] + self::doChangeCategory(...) ); } @@ -87,7 +84,7 @@ class BackendActionsLinksDefault $cat_id = is_numeric($post['upd_cat_id']) ? abs((int) $post['upd_cat_id']) : null; - $cur = dcCore::app()->con->openCursor($ap->utils->table); + $cur = App::con()->openCursor($ap->utils->table); foreach ($ids as $id) { $cur->clean(); $cur->setField('cat_id', $cat_id == 0 ? null : $cat_id); @@ -125,7 +122,7 @@ class BackendActionsLinksDefault (new Submit('do-action')) ->value(__('Save')), (new Hidden(['action'], 'updlinkscat')), - dcCore::app()->formNonce(false), + App::nonce()->formNonce(), ] )), @@ -152,7 +149,7 @@ class BackendActionsLinksDefault $link_note = 10; } - $cur = dcCore::app()->con->openCursor($ap->utils->table); + $cur = App::con()->openCursor($ap->utils->table); foreach ($ids as $id) { $cur->clean(); $cur->setField('link_note', $link_note); @@ -190,7 +187,7 @@ class BackendActionsLinksDefault (new Submit('do-action')) ->value(__('Save')), (new Hidden(['action'], 'updlinksnote')), - dcCore::app()->formNonce(false), + App::nonce()->formNonce(), ] )), diff --git a/src/BackendListingLinks.php b/src/BackendListingLinks.php index aab70c0..0afbae4 100644 --- a/src/BackendListingLinks.php +++ b/src/BackendListingLinks.php @@ -1,21 +1,11 @@ value('page'), $this->rs_count, (int) $filter->value('nb'), 10); + $pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); $cols = new ArrayObject([ 'title' => (new Th()) @@ -161,7 +158,7 @@ class BackendListingLinks extends Listing ->text(Html::escapeHTML($this->rs->link_note)) ->class('number'), 'date' => (new Td()) - ->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->link_upddt, (string) dcCore::app()->auth->getInfo('user_tz')))) + ->text(Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->link_upddt, (string) App::auth()->getInfo('user_tz')))) ->class('nowrap'), ]); diff --git a/src/Combo.php b/src/Combo.php index caacd1b..7c72e8c 100644 --- a/src/Combo.php +++ b/src/Combo.php @@ -1,29 +1,25 @@ + * @return array */ public static function categoriesCombo(): array { @@ -41,7 +37,7 @@ class Combo } /** - * @return array + * @return array */ public static function langsCombo(): array { @@ -49,7 +45,7 @@ class Combo } /** - * @return array + * @return array */ public static function notesCombo(): array { @@ -65,10 +61,9 @@ class Combo $dir = null; try { - dcCore::app()->media = new dcMedia(); - dcCore::app()->media->chdir(My::settings()->folder); - dcCore::app()->media->getDir(); - $dir = & dcCore::app()->media->dir; + App::media()->chdir((string) My::settings()->get('folder')); + App::media()->getDir(); + $dir = & App::media()->dir; foreach ($dir['files'] as $file) { if (!in_array($file->extension, My::ALLOWED_MEDIA_EXTENSION)) { diff --git a/src/Frontend.php b/src/Frontend.php index 66eceb1..e782a40 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,19 @@ addBehavior('initWidgets', [Widgets::class, 'initLinks']); - dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initCats']); + App::behavior()->addBehavior('initWidgets', Widgets::init(...)); $values = [ 'c2PageFeedID', @@ -91,16 +87,17 @@ class Frontend extends Process 'c2CategoryIf', ]; - if (My::settings()?->active) { + if (My::settings()->active) { foreach ($blocks as $v) { - dcCore::app()->tpl->addBlock($v, [FrontendTemplate::class, $v]); + App::frontend()->template()->addBlock($v, [FrontendTemplate::class, $v]); } foreach ($values as $v) { - dcCore::app()->tpl->addValue($v, [FrontendTemplate::class, $v]); + App::frontend()->template()->addValue($v, [FrontendTemplate::class, $v]); } } else { foreach (array_merge($blocks, $values) as $v) { - dcCore::app()->tpl->addBlock($v, [FrontendTemplate::class, 'disable']); + pdump($v); + App::frontend()->template()->addBlock($v, FrontendTemplate::disable(...)); } } diff --git a/src/FrontendContext.php b/src/FrontendContext.php index 401cb0f..615e2d2 100644 --- a/src/FrontendContext.php +++ b/src/FrontendContext.php @@ -1,30 +1,27 @@ ctx->c2_pagination === null) { + if (App::frontend()->context()->c2_pagination === null) { return false; } - $nb_posts = dcCore::app()->ctx->c2_pagination->f(0); - $nb_per_page = dcCore::app()->ctx->c2_params['limit'][1]; + $nb_posts = App::frontend()->context()->c2_pagination->f(0); + $nb_per_page = App::frontend()->context()->c2_params['limit'][1]; $nb_pages = ceil($nb_posts / $nb_per_page); return $nb_pages; @@ -72,7 +69,7 @@ class FrontendContext $args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args); - $url = dcCore::app()->blog->url . $args; + $url = App::blog()->url() . $args; if ($n > 1) { $url = preg_replace('#/$#', '', $url); @@ -89,18 +86,18 @@ class FrontendContext public static function categoryCurrent() { - if (!isset(dcCore::app()->ctx->c2_page_params['cat_id']) - && !isset(dcCore::app()->ctx->c2_page_params['cat_title']) + if (!isset(App::frontend()->context()->c2_page_params['cat_id']) + && !isset(App::frontend()->context()->c2_page_params['cat_title']) ) { return false; } - if (isset(dcCore::app()->ctx->c2_page_params['cat_id']) - && dcCore::app()->ctx->c2_page_params['cat_id'] == dcCore::app()->ctx->c2_categories->cat_id + if (isset(App::frontend()->context()->c2_page_params['cat_id']) + && App::frontend()->context()->c2_page_params['cat_id'] == App::frontend()->context()->c2_categories->cat_id ) { return true; } - if (isset(dcCore::app()->ctx->c2_page_params['cat_title']) - && dcCore::app()->ctx->c2_page_params['cat_title'] == dcCore::app()->ctx->c2_categories->cat_title + if (isset(App::frontend()->context()->c2_page_params['cat_title']) + && App::frontend()->context()->c2_page_params['cat_title'] == App::frontend()->context()->c2_categories->cat_title ) { return true; } diff --git a/src/FrontendTemplate.php b/src/FrontendTemplate.php index 5d6ec79..5318288 100644 --- a/src/FrontendTemplate.php +++ b/src/FrontendTemplate.php @@ -1,24 +1,21 @@ tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase(\'cinecturlink2\')') . '; ?>'; + return 'template()->getFilters($a), 'App::blog()->url().App::url()->getBase(\'cinecturlink2\')') . '; ?>'; } public static function c2PageTitle(ArrayObject $a): string { - return "blog->settings->cinecturlink2->public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf(dcCore::app()->tpl->getFilters($a), '$title') . '; ?>'; + return "settings()->cinecturlink2->public_title; if (empty(\$title)) { \$title = __('My cinecturlink'); } echo " . sprintf(App::frontend()->template()->getFilters($a), '$title') . '; ?>'; } public static function c2PageFeedURL(ArrayObject $a): string { - return 'tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("' . My::id() . '")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>'; + return 'template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/feed/' . (!empty($a['type']) && preg_match('#^(rss2|atom)$#', $a['type']) ? $a['type'] : 'atom') . '"') . '; ?>'; } public static function c2PageFeedID(ArrayObject $a): string { - return 'urn:md5:blog->id."' . My::id() . '"); ?>'; + return 'urn:md5:id()."' . My::id() . '"); ?>'; } public static function c2PageDescription(ArrayObject $a): string { - return 'blog->settings->cinecturlink2->public_description; echo ' . sprintf(dcCore::app()->tpl->getFilters($a), '$description') . '; ?>'; + return 'settings()->cinecturlink2->public_description; echo ' . sprintf(App::frontend()->template()->getFilters($a), '$description') . '; ?>'; } public static function c2If(ArrayObject $a, string $c): string { $if = []; - $operator = isset($a['operator']) ? dcTemplate::getOperator($a['operator']) : '&&'; + $operator = isset($a['operator']) ? Tpl::getOperator($a['operator']) : '&&'; if (isset($a['request_link'])) { $sign = (bool) $a['request_link'] ? '' : '!'; - $if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["link_id"]) || isset(dcCore::app()->ctx->c2_page_params["link_title"]))'; + $if[] = $sign . '(isset(App::frontend()->context()->c2_page_params["link_id"]) || isset(App::frontend()->context()->c2_page_params["link_title"]))'; } if (isset($a['request_cat'])) { $sign = (bool) $a['request_cat'] ? '' : '!'; - $if[] = $sign . '(isset(dcCore::app()->ctx->c2_page_params["cat_id"]) || isset(dcCore::app()->ctx->c2_page_params["cat_title"]))'; + $if[] = $sign . '(isset(App::frontend()->context()->c2_page_params["cat_id"]) || isset(App::frontend()->context()->c2_page_params["cat_title"]))'; } return empty($if) ? $c : '\n" . $c . "\n"; @@ -106,35 +103,35 @@ class FrontendTemplate return "ctx->c2_page_params) ? dcCore::app()->ctx->c2_page_params : array(); \n" . + "\$params = is_array(App::frontend()->context()->c2_page_params) ? App::frontend()->context()->c2_page_params : array(); \n" . $res . - "dcCore::app()->ctx->c2_params = \$params; unset(\$params);\n" . - "if (!dcCore::app()->ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new " . Utils::class . "(); } \n" . - "dcCore::app()->ctx->c2_entries = dcCore::app()->ctx->cinecturlink->getLinks(dcCore::app()->ctx->c2_params); \n" . - 'while (dcCore::app()->ctx->c2_entries->fetch()) : ?>' . $c . 'ctx->pop('c2_entries'); dcCore::app()->ctx->pop('c2_params'); \n" . + "App::frontend()->context()->c2_params = \$params; unset(\$params);\n" . + "if (!App::frontend()->context()->exists('cinecturlink')) { App::frontend()->context()->cinecturlink = new " . Utils::class . "(); } \n" . + "App::frontend()->context()->c2_entries = App::frontend()->context()->cinecturlink->getLinks(App::frontend()->context()->c2_params); \n" . + 'while (App::frontend()->context()->c2_entries->fetch()) : ?>' . $c . 'context()->pop('c2_entries'); App::frontend()->context()->pop('c2_params'); \n" . "?>\n"; } public static function c2EntriesHeader(ArrayObject $a, string $c): string { - return 'ctx->c2_entries->isStart()) : ?>' . $c . ''; + return 'context()->c2_entries->isStart()) : ?>' . $c . ''; } public static function c2EntriesFooter(ArrayObject $a, string $c): string { - return 'ctx->c2_entries->isEnd()) : ?>' . $c . ''; + return 'context()->c2_entries->isEnd()) : ?>' . $c . ''; } public static function c2EntryIf(ArrayObject $a, string $c): string { $if = []; - $operator = isset($a['operator']) ? dcTemplate::getOperator($a['operator']) : '&&'; + $operator = isset($a['operator']) ? Tpl::getOperator($a['operator']) : '&&'; if (isset($a['has_category'])) { $sign = (bool) $a['has_category'] ? '!' : '='; - $if[] = '(dcCore::app()->ctx->exists("c2_entries") && "" ' . $sign . '= dcCore::app()->ctx->c2_entries->cat_title)'; + $if[] = '(App::frontend()->context()->exists("c2_entries") && "" ' . $sign . '= App::frontend()->context()->c2_entries->cat_title)'; } return empty($if) ? $c : '\n" . $c . "\n"; @@ -142,105 +139,105 @@ class FrontendTemplate public static function c2EntryIfFirst(ArrayObject $a): string { - return 'ctx->c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'first') . '"; } ?>'; + return 'context()->c2_entries->index() == 0) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'first') . '"; } ?>'; } public static function c2EntryIfOdd(ArrayObject $a): string { - return 'ctx->c2_entries->index()+1)%2 == 1) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'odd') . '"; } ?>'; + return 'context()->c2_entries->index()+1)%2 == 1) { echo "' . (isset($a['return']) ? addslashes(Html::escapeHTML($a['return'])) : 'odd') . '"; } ?>'; } public static function c2EntryFeedID(ArrayObject $a): string { - return 'urn:md5:ctx->c2_entries->blog_id.dcCore::app()->ctx->c2_entries->link_id.dcCore::app()->ctx->c2_entries->link_creadt); ?>'; + return 'urn:md5:context()->c2_entries->blog_id.App::frontend()->context()->c2_entries->link_id.App::frontend()->context()->c2_entries->link_creadt); ?>'; } public static function c2EntryID(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_id', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_id', $a); } public static function c2EntryTitle(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_title', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_title', $a); } public static function c2EntryDescription(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_desc', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_desc', $a); } public static function c2EntryAuthorCommonName(ArrayObject $a): string { - return self::getGenericValue('dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)', $a); + return self::getGenericValue('App::users()->getUserCN(App::frontend()->context()->c2_entries->user_id,App::frontend()->context()->c2_entries->user_name,App::frontend()->context()->c2_entries->user_firstname,App::frontend()->context()->c2_entries->user_displayname)', $a); } public static function c2EntryAuthorDisplayName(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_displayname', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->user_displayname', $a); } public static function c2EntryAuthorID(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_id', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->user_id', $a); } public static function c2EntryAuthorEmail(ArrayObject $a): string { - return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? 'dcCore::app()->ctx->c2_entries->user_email' : "strtr(dcCore::app()->ctx->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a); + return self::getGenericValue((isset($a['spam_protected']) && !$a['spam_protected'] ? 'App::frontend()->context()->c2_entries->user_email' : "strtr(App::frontend()->context()->c2_entries->user_email,array('@'=>'%40','.'=>'%2e'))"), $a); } public static function c2EntryAuthorLink(ArrayObject $a): string { - return self::getGenericValue('sprintf((dcCore::app()->ctx->c2_entries->user_url ? \'%1$s\' : \'%1$s\'),html::escapeHTML(dcUtils::getUserCN(dcCore::app()->ctx->c2_entries->user_id,dcCore::app()->ctx->c2_entries->user_name,dcCore::app()->ctx->c2_entries->user_firstname,dcCore::app()->ctx->c2_entries->user_displayname)),html::escapeHTML(dcCore::app()->ctx->c2_entries->user_url))', $a); + return self::getGenericValue('sprintf((App::frontend()->context()->c2_entries->user_url ? \'%1$s\' : \'%1$s\'),html::escapeHTML(App::users()->getUserCN(App::frontend()->context()->c2_entries->user_id,App::frontend()->context()->c2_entries->user_name,App::frontend()->context()->c2_entries->user_firstname,App::frontend()->context()->c2_entries->user_displayname)),html::escapeHTML(App::frontend()->context()->c2_entries->user_url))', $a); } public static function c2EntryAuthorURL(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->user_url', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->user_url', $a); } public static function c2EntryFromAuthor(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_author', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_author', $a); } public static function c2EntryLang(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_lang', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_lang', $a); } public static function c2EntryURL(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->link_url', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->link_url', $a); } public static function c2EntryCategory(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->cat_title', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->cat_title', $a); } public static function c2EntryCategoryID(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->ctx->c2_entries->cat_id', $a); + return self::getGenericValue('App::frontend()->context()->c2_entries->cat_id', $a); } public static function c2EntryCategoryURL(ArrayObject $a): string { - return self::getGenericValue('dcCore::app()->blog->url.dcCore::app()->url->getBase("' . My::id() . '")."/".dcCore::app()->blog->settings->cinecturlink2->public_caturl."/".urlencode(dcCore::app()->ctx->c2_entries->cat_title)', $a); + return self::getGenericValue('App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_entries->cat_title)', $a); } public static function c2EntryImg(ArrayObject $a): string { - $f = dcCore::app()->tpl->getFilters($a); + $f = App::frontend()->template()->getFilters($a); $style = isset($a['style']) ? Html::escapeHTML($a['style']) : ''; return - "ctx->exists('c2_entries')) { " . - '$widthmax = (integer) dcCore::app()->blog->settings->cinecturlink2->widthmax; ' . + "context()->exists('c2_entries')) { " . + '$widthmax = (integer) App::blog()->settings()->cinecturlink2->widthmax; ' . "\$img = sprintf('\"%s\"'," . - 'dcCore::app()->ctx->c2_entries->link_img, ' . - "html::escapeHTML(dcCore::app()->ctx->c2_entries->link_title.' - '.dcCore::app()->ctx->c2_entries->link_author), " . + 'App::frontend()->context()->c2_entries->link_img, ' . + "html::escapeHTML(App::frontend()->context()->c2_entries->link_title.' - '.App::frontend()->context()->c2_entries->link_author), " . "(\$widthmax ? ' style=\"width:'.\$widthmax.'px;$style\"' : '') " . '); ' . 'echo ' . sprintf($f, '$img') . "; unset(\$img); } ?> \n"; @@ -251,13 +248,13 @@ class FrontendTemplate $format = !empty($a['format']) ? addslashes($a['format']) : ''; if (!empty($a['rfc822'])) { - $p = 'dt::rfc822(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)'; + $p = 'dt::rfc822(strtotime(App::frontend()->context()->c2_entries->link_creadt), App::blog()->settings()->system->blog_timezone)'; } elseif (!empty($a['iso8601'])) { - $p = 'dt::iso8601(strtotime(dcCore::app()->ctx->c2_entries->link_creadt), dcCore::app()->blog->settings->system->blog_timezone)'; + $p = 'dt::iso8601(strtotime(App::frontend()->context()->c2_entries->link_creadt), App::blog()->settings()->system->blog_timezone)'; } elseif ($format) { - $p = "dt::dt2str('" . $format . "', dcCore::app()->ctx->c2_entries->link_creadt)"; + $p = "dt::dt2str('" . $format . "', App::frontend()->context()->c2_entries->link_creadt)"; } else { - $p = 'dt::dt2str(dcCore::app()->blog->settings->system->date_format, dcCore::app()->ctx->c2_entries->link_creadt)'; + $p = 'dt::dt2str(App::blog()->settings()->system->date_format, App::frontend()->context()->c2_entries->link_creadt)'; } return self::getGenericValue($p, $a); @@ -265,17 +262,17 @@ class FrontendTemplate public static function c2EntryTime(ArrayObject $a): string { - return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format') . ', dcCore::app()->ctx->c2_entries->link_creadt)', $a); + return self::getGenericValue('dt::dt2str(' . (!empty($a['format']) ? "'" . addslashes($a['format']) . "'" : 'App::blog()->settings()->system->time_format') . ', App::frontend()->context()->c2_entries->link_creadt)', $a); } public static function c2Pagination(ArrayObject $a, string $c): string { $p = "ctx->c2_params;\n" . - "dcCore::app()->ctx->c2_pagination = dcCore::app()->ctx->cinecturlink->getLinks(\$params,true); unset(\$params);\n" . + "\$params = App::frontend()->context()->c2_params;\n" . + "App::frontend()->context()->c2_pagination = App::frontend()->context()->cinecturlink->getLinks(\$params,true); unset(\$params);\n" . "?>\n"; - return isset($a['no_context']) ? $p . $c : $p . 'ctx->c2_pagination->f(0) > dcCore::app()->ctx->c2_entries->count()) : ?>' . $c . ''; + return isset($a['no_context']) ? $p . $c : $p . 'context()->c2_pagination->f(0) > App::frontend()->context()->c2_entries->count()) : ?>' . $c . ''; } public static function c2PaginationCounter(ArrayObject $a): string @@ -313,21 +310,21 @@ class FrontendTemplate { return "ctx->exists('cinecturlink')) { dcCore::app()->ctx->cinecturlink = new " . Utils::class . "(); } \n" . - "dcCore::app()->ctx->c2_categories = dcCore::app()->ctx->cinecturlink->getCategories(); \n" . - 'while (dcCore::app()->ctx->c2_categories->fetch()) : ?>' . $c . 'ctx->c2_categories = null; \n" . + "if (!App::frontend()->context()->exists('cinecturlink')) { App::frontend()->context()->cinecturlink = new " . Utils::class . "(); } \n" . + "App::frontend()->context()->c2_categories = App::frontend()->context()->cinecturlink->getCategories(); \n" . + 'while (App::frontend()->context()->c2_categories->fetch()) : ?>' . $c . 'context()->c2_categories = null; \n" . "?>\n"; } public static function c2CategoriesHeader(ArrayObject $a, string $c): string { - return 'ctx->c2_categories->isStart()) : ?>' . $c . ''; + return 'context()->c2_categories->isStart()) : ?>' . $c . ''; } public static function c2CategoriesFooter(ArrayObject $a, string $c): string { - return 'ctx->c2_categories->isEnd()) : ?>' . $c . ''; + return 'context()->c2_categories->isEnd()) : ?>' . $c . ''; } public static function c2CategoryIf(ArrayObject $a, string $c): string @@ -340,7 +337,7 @@ class FrontendTemplate } if (isset($a['first'])) { $sign = (bool) $a['first'] ? '' : '!'; - $if[] = $sign . 'dcCore::app()->ctx->c2_categories->isStart()'; + $if[] = $sign . 'App::frontend()->context()->c2_categories->isStart()'; } return empty($if) ? $c : '' . $c . ''; @@ -354,36 +351,36 @@ class FrontendTemplate $p = 'atom'; } - return 'tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("' . My::id() . '")."/".dcCore::app()->blog->settings->cinecturlink2->public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>'; + return 'template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_categories->cat_title)."/feed/' . $p . '"') . '; ?>'; } public static function c2CategoryFeedID(ArrayObject $a): string { - return 'urn:md5:blog->id."' . My::id() . '".dcCore::app()->ctx->c2_categories->cat_id); ?>'; + return 'urn:md5:id()."' . My::id() . '".App::frontend()->context()->c2_categories->cat_id); ?>'; } public static function c2CategoryID(ArrayObject $a): string { - return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_id') . '; } ?>'; + return "context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_id') . '; } ?>'; } public static function c2CategoryTitle(ArrayObject $a): string { - return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_title') . '; } ?>'; + return "context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_title') . '; } ?>'; } public static function c2CategoryDescription(ArrayObject $a): string { - return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->ctx->c2_categories->cat_desc') . '; } ?>'; + return "context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::frontend()->context()->c2_categories->cat_desc') . '; } ?>'; } public static function c2CategoryURL(ArrayObject $a): string { - return "ctx->exists('c2_categories')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("' . My::id() . '")."/".dcCore::app()->blog->settings->cinecturlink2->public_caturl."/".urlencode(dcCore::app()->ctx->c2_categories->cat_title)') . '; } ?>'; + return "context()->exists('c2_categories')) { echo " . sprintf(App::frontend()->template()->getFilters($a), 'App::blog()->url().App::url()->getBase("' . My::id() . '")."/".App::blog()->settings()->cinecturlink2->public_caturl."/".urlencode(App::frontend()->context()->c2_categories->cat_title)') . '; } ?>'; } protected static function getGenericValue(string $p, ArrayObject $a): string { - return "ctx->exists('c2_entries')) { echo " . sprintf(dcCore::app()->tpl->getFilters($a), "$p") . '; } ?>'; + return "context()->exists('c2_entries')) { echo " . sprintf(App::frontend()->template()->getFilters($a), "$p") . '; } ?>'; } } diff --git a/src/FrontendUrl.php b/src/FrontendUrl.php index 17428a2..4d142b4 100644 --- a/src/FrontendUrl.php +++ b/src/FrontendUrl.php @@ -1,26 +1,21 @@ themes->getDefine(dcCore::app()->blog->settings->system->theme)->get('tplset'); - $tpldir = Path::real(dcCore::app()->plugins->getDefine(My::id())->get('root')) . DIRECTORY_SEPARATOR . Utility::TPL_ROOT . DIRECTORY_SEPARATOR; - dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $tpldir . (!empty($tplset) && is_dir($tpldir . $tplset) ? $tplset : DC_DEFAULT_TPLSET)); + $tplset = App::themes()->getDefine(App::blog()->settings()->get('system')->get('theme'))->get('tplset'); + $tpldir = Path::real(App::plugins()->getDefine(My::id())->get('root')) . DIRECTORY_SEPARATOR . App::frontend()::TPL_ROOT . DIRECTORY_SEPARATOR; + App::frontend()->template()->setPath(App::frontend()->template()->getPath(), $tpldir . (!empty($tplset) && is_dir($tpldir . $tplset) ? $tplset : App::config()->defaultTplset())); $params = []; @@ -60,12 +55,12 @@ class FrontendUrl extends dcUrlHandlers if (!empty($f) && in_array($f, ['atom', 'rss2'])) { $mime = $f == 'atom' ? 'application/atom+xml' : 'application/xml'; - //dcCore::app()->ctx->short_feed_items = dcCore::app()->blog->settings->system->short_feed_items; + //App::frontend()->context()->short_feed_items = App::blog()->settings()->system->short_feed_items; - $params['limit'] = dcCore::app()->blog->settings->system->nb_post_per_feed; - dcCore::app()->ctx->c2_page_params = $params; + $params['limit'] = App::blog()->settings()->get('system')->get('nb_post_per_feed'); + App::frontend()->context()->c2_page_params = $params; - header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog->settings->system->robots_policy, '')); + header('X-Robots-Tag: ' . App::frontend()->context()::robotsPolicy(App::blog()->settings()->get('system')->get('robots_policy'), '')); self::serveDocument('cinecturlink2-' . $f . '.xml', $mime); } else { $d = self::getPageArgs($args, 'c2detail'); @@ -77,8 +72,8 @@ class FrontendUrl extends dcUrlHandlers } } - $params['limit'] = (int) My::settings()->public_nbrpp; - dcCore::app()->ctx->c2_page_params = $params; + $params['limit'] = (int) My::settings()->public_nbrpp; + App::frontend()->context()->c2_page_params = $params; self::serveDocument('cinecturlink2.html', 'text/html'); } diff --git a/src/Install.php b/src/Install.php index 833ee7f..a6e26f9 100644 --- a/src/Install.php +++ b/src/Install.php @@ -1,26 +1,22 @@ con, dcCore::app()->prefix); + $s = new Structure(App::con(), App::con()->prefix()); $s->{My::CINECTURLINK_TABLE_NAME} ->link_id('bigint', 0, false) ->blog_id('varchar', 32, false) @@ -77,7 +73,7 @@ class Install extends Process ->index('idx_cinecturlink2_cat_blog_id', 'btree', 'blog_id') ->unique('uk_cinecturlink2_cat_title', 'cat_title', 'blog_id'); - (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); + (new Structure(App::con(), App::con()->prefix()))->synchronize($s); $s = My::settings(); $s->put('avtive', true, 'boolean', 'Enable cinecturlink2', false, true); @@ -92,7 +88,7 @@ class Install extends Process return true; } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); return false; } @@ -100,7 +96,7 @@ class Install extends Process private static function upgradeSettings(): void { - if (version_compare((string) dcCore::app()->getVersion(My::id()), '2.0', '<')) { + if (version_compare(App::version()->getVersion(My::id()), '2.0', '<')) { $ids = [ 'active', 'widthmax', @@ -116,7 +112,7 @@ class Install extends Process foreach ($ids as $id) { $sql = new UpdateStatement(); $sql - ->ref(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME) + ->ref(App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME) ->column('setting_id') ->value($id) ->where('setting_id = ' . $sql->quote('cinecturlink2_' . $id)) diff --git a/src/Manage.php b/src/Manage.php index 85aa9b3..d93384a 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -1,21 +1,18 @@ con->openCursor($utils->cat_table); + $cur = App::con()->openCursor($utils->cat_table); $cur->setField('cat_title', self::$cattitle); $cur->setField('cat_desc', self::$catdesc); @@ -81,7 +78,7 @@ class ManageCat extends Process if ($exists) { throw new Exception(__('Category with same name already exists.')); } - $cur = dcCore::app()->con->openCursor($C2->cat_table); + $cur = App::con()->openCursor($C2->cat_table); $cur->setField('cat_title', self::$cattitle); $cur->setField('cat_desc', self::$catdesc); @@ -102,7 +99,7 @@ class ManageCat extends Process My::redirect(['part' => 'cats']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } return true; diff --git a/src/ManageCats.php b/src/ManageCats.php index dcb2d1a..4e1d17c 100644 --- a/src/ManageCats.php +++ b/src/ManageCats.php @@ -1,20 +1,10 @@ con->openCursor($utils->cat_table); + $cur = App::con()->openCursor($utils->cat_table); $cur->setField('cat_pos', $i); $utils->updCategory((int) $id, $cur); } @@ -93,7 +90,7 @@ class ManageCats extends Process My::redirect(['part' => 'cats']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } return true; @@ -157,7 +154,7 @@ class ManageCats extends Process Page::openModule( My::name(), - (!dcCore::app()->auth->user_prefs?->get('accessibility')->get('nodragdrop') ? + (!App::auth()->prefs()->get('accessibility')->get('nodragdrop') ? Page::jsLoad('js/jquery/jquery-ui.custom.js') . Page::jsLoad('js/jquery/jquery.ui.touch-punch.js') . My::jsLoad('c2cats') diff --git a/src/ManageLink.php b/src/ManageLink.php index 5d5fcf7..886d18c 100644 --- a/src/ManageLink.php +++ b/src/ManageLink.php @@ -1,20 +1,10 @@ auth->getInfo('user_lang'); + self::$linklang = $_POST['linklang'] ?? App::auth()->getInfo('user_lang'); self::$linkimage = $_POST['linkimage'] ?? ''; self::$linknote = $_POST['linknote'] ?? ''; if (!empty($_POST['save'])) { try { Utils::makePublicDir( - DC_ROOT . '/' . dcCore::app()->blog->settings->system->get('public_path'), + App::config()->dotclearRoot() . '/' . App::blog()->settings()->system->get('public_path'), My::settings()->folder ); if (empty(self::$linktitle)) { @@ -89,7 +86,7 @@ class ManageLink extends Process //throw new Exception(__('You must provide a link to an image.')); } - $cur = dcCore::app()->con->openCursor($utils->table); + $cur = App::con()->openCursor($utils->table); $cur->setField('link_title', self::$linktitle); $cur->setField('link_desc', self::$linkdesc); $cur->setField('link_author', self::$linkauthor); @@ -130,7 +127,7 @@ class ManageLink extends Process ] ); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -147,7 +144,7 @@ class ManageLink extends Process My::redirect(['part' => 'links']); } } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } } @@ -178,7 +175,7 @@ class ManageLink extends Process Page::openModule( My::name(), - Page::jsVars(['dotclear.c2_lang' => dcCore::app()->auth->getInfo('user_lang')]) . + Page::jsVars(['dotclear.c2_lang' => App::auth()->getInfo('user_lang')]) . My::jsLoad('c2link') ); @@ -286,7 +283,7 @@ class ManageLink extends Process ->items([ (new Link()) ->class('modal hidden-if-no-js') - ->href(dcCore::app()->adminurl->get('admin.media', ['d' => (string) My::settings()->folder])) + ->href(App::backend()->url()->get('admin.media', ['d' => (string) My::settings()->folder])) ->title(__('Media manager')) ->text(__('Go to media manager to add image to cinecturlink path.')), ]), diff --git a/src/ManageLinks.php b/src/ManageLinks.php index b6f0208..7755634 100644 --- a/src/ManageLinks.php +++ b/src/ManageLinks.php @@ -1,20 +1,10 @@ getLinks($params, true)->f(0); self::$module_listing = new BackendListingLinks($links, self::$module_counter); } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); + App::error()->add($e->getMessage()); } return true; diff --git a/src/My.php b/src/My.php index d1a7665..a3b8713 100644 --- a/src/My.php +++ b/src/My.php @@ -1,39 +1,52 @@ ALLOWED_MEDIA_EXTENSION + */ public const ALLOWED_MEDIA_EXTENSION = ['png', 'jpg', 'gif', 'bmp', 'jpeg']; public static function checkCustomContext(int $context): ?bool { - if (in_array($context, [My::MENU, My::BACKEND])) { - return 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); - } + return match ($context) { + self::MENU, self::MANAGE, self::BACKEND => App::task()->checkContext('BACKEND') + && App::blog()->isDefined() + && App::auth()->check(App::auth()->makePermissions([ + App::auth()::PERMISSION_CONTENT_ADMIN, + ]), App::blog()->id()), - return null; + default => null, + }; } } diff --git a/src/PluginActivityReport.php b/src/PluginActivityReport.php index c15a8b5..9cb3718 100644 --- a/src/PluginActivityReport.php +++ b/src/PluginActivityReport.php @@ -1,22 +1,19 @@ addAction( @@ -39,7 +36,7 @@ class PluginActivityReport __('updating link'), __('Cinecturlink named "%s" has been updated by "%s"'), 'cinecturlink2AfterUpdLink', - [self::class, 'updLink'] + self::updLink(...) ); // from BEHAVIOR cinecturlink2BeforeDelLink in cinecturlink2/inc/class.cinecturlink2.php ActivityReport::instance()->addAction( @@ -48,7 +45,7 @@ class PluginActivityReport __('link deletion'), __('Cinecturlink named "%s" has been deleted by "%s"'), 'cinecturlink2BeforeDelLink', - [self::class, 'delLink'] + self::delLink(...) ); } @@ -56,7 +53,7 @@ class PluginActivityReport { $logs = [ $cur->link_title, - dcCore::app()->auth->getInfo('user_cn'), + App::auth()->getInfo('user_cn'), ]; ActivityReport::instance()->addLog('cinecturlink2', 'create', $logs); } @@ -68,7 +65,7 @@ class PluginActivityReport $logs = [ $rs->link_title, - dcCore::app()->auth->getInfo('user_cn'), + App::auth()->getInfo('user_cn'), ]; ActivityReport::instance()->addLog('cinecturlink2', 'update', $logs); } @@ -80,7 +77,7 @@ class PluginActivityReport $logs = [ $rs->link_title, - dcCore::app()->auth->getInfo('user_cn'), + App::auth()->getInfo('user_cn'), ]; ActivityReport::instance()->addLog('cinecturlink2', 'delete', $logs); } diff --git a/src/PluginSitemaps.php b/src/PluginSitemaps.php index c59901f..fb6ac4f 100644 --- a/src/PluginSitemaps.php +++ b/src/PluginSitemaps.php @@ -1,21 +1,18 @@ plugins->moduleExists('cinecturlink2') - && dcCore::app()->blog->settings->sitemaps->sitemaps_cinecturlink2_url + if (App::plugins()->moduleExists('cinecturlink2') + && App::blog()->settings()->get('sitemaps')->get('sitemaps_cinecturlink2_url') ) { - $freq = $sitemaps->getFrequency(dcCore::app()->blog->settings->sitemaps->sitemaps_cinecturlink2_fq); - $prio = $sitemaps->getPriority(dcCore::app()->blog->settings->sitemaps->sitemaps_cinecturlink2_pr); - $base = dcCore::app()->blog->url . dcCore::app()->url->getBase('cinecturlink2'); + $freq = $sitemaps->getFrequency(App::blog()->settings()->get('sitemaps')->get('sitemaps_cinecturlink2_fq')); + $prio = $sitemaps->getPriority(App::blog()->settings()->get('sitemaps')->get('sitemaps_cinecturlink2_pr')); + $base = App::blog()->url() . App::url()->getBase('cinecturlink2'); $sitemaps->addEntry($base, $prio, $freq); $C2 = new Utils(); $cats = $C2->getCategories(); while ($cats->fetch()) { - $sitemaps->addEntry($base . '/' . dcCore::app()->blog->settings->cinecturlink2->public_caturl . '/' . urlencode($cats->cat_title), $prio, $freq); + $sitemaps->addEntry($base . '/' . My::settings()->get('public_caturl') . '/' . urlencode($cats->cat_title), $prio, $freq); } } } diff --git a/src/Prepend.php b/src/Prepend.php index aa26e00..74b86db 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -1,22 +1,19 @@ url->register( + App::url()->register( My::id(), 'cinecturlink', '^cinecturlink(?:/(.+))?$', - [FrontendUrl::class, 'c2Page'] + FrontendUrl::c2Page(...) ); - dcCore::app()->addBehaviors([ - 'sitemapsDefineParts' => [PluginSitemaps::class, 'sitemapsDefineParts'], - 'sitemapsURLsCollect' => [PluginSitemaps::class, 'sitemapsURLsCollect'], + App::behavior()->addBehaviors([ + 'sitemapsDefineParts' => PluginSitemaps::sitemapsDefineParts(...), + 'sitemapsURLsCollect' => PluginSitemaps::sitemapsURLsCollect(...), ]); if (defined('ACTIVITY_REPORT_V2')) { diff --git a/src/Uninstall.php b/src/Uninstall.php index 48a9385..d53eee3 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,19 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/Utils.php b/src/Utils.php index 305682d..36eb769 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,21 +1,10 @@ con = dcCore::app()->con; - $this->table = dcCore::app()->prefix . My::CINECTURLINK_TABLE_NAME; - $this->cat_table = dcCore::app()->prefix . My::CATEGORY_TABLE_NAME; - $this->blog = (string) dcCore::app()->blog?->id; + $this->con = App::con(); + $this->table = App::con()->prefix() . My::CINECTURLINK_TABLE_NAME; + $this->cat_table = App::con()->prefix() . My::CATEGORY_TABLE_NAME; + $this->blog = App::blog()->id(); } /** @@ -106,7 +117,7 @@ class Utils ->join( (new JoinStatement()) ->inner() - ->from($sql->as(dcCore::app()->prefix . dcAuth::USER_TABLE_NAME, 'U')) + ->from($sql->as(App::con()->prefix() . App::auth()::USER_TABLE_NAME, 'U')) ->on('U.user_id = L.user_id') ->statement() ) @@ -126,7 +137,7 @@ class Utils $sql->from($params['from']); } - $sql->where('L.blog_id = ' . $sql->quote(dcCore::app()->blog->id)); + $sql->where('L.blog_id = ' . $sql->quote($this->blog)); if (isset($params['link_type'])) { if (is_array($params['link_type']) && !empty($params['link_type'])) { @@ -227,7 +238,7 @@ class Utils $cur->link_id = $this->getNextLinkId(); $cur->blog_id = $this->blog; - $cur->user_id = dcCore::app()->auth->userID(); + $cur->user_id = App::auth()->userID(); $cur->link_creadt = date('Y-m-d H:i:s'); $cur->link_upddt = date('Y-m-d H:i:s'); $cur->link_pos = 0; @@ -242,7 +253,7 @@ class Utils $this->trigger(); # --BEHAVIOR-- cinecturlink2AfterAddLink - dcCore::app()->callBehavior('cinecturlink2AfterAddLink', $cur); + App::behavior()->callBehavior('cinecturlink2AfterAddLink', $cur); return (int) $cur->link_id; } @@ -270,7 +281,7 @@ class Utils if ($behavior) { # --BEHAVIOR-- cinecturlink2AfterUpdLink - dcCore::app()->callBehavior('cinecturlink2AfterUpdLink', $cur, $id); + App::behavior()->callBehavior('cinecturlink2AfterUpdLink', $cur, $id); } } @@ -286,7 +297,7 @@ class Utils } # --BEHAVIOR-- cinecturlink2BeforeDelLink - dcCore::app()->callBehavior('cinecturlink2BeforeDelLink', $id); + App::behavior()->callBehavior('cinecturlink2BeforeDelLink', $id); $sql = new DeleteStatement(); $sql @@ -348,7 +359,7 @@ class Utils $sql->from($params['from']); } - $sql->where('C.blog_id = ' . $sql->quote(dcCore::app()->blog->id)); + $sql->where('C.blog_id = ' . $sql->quote($this->blog)); if (!empty($params['cat_id'])) { if (is_array($params['cat_id'])) { @@ -528,7 +539,7 @@ class Utils */ private function trigger(): void { - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); } /** @@ -563,9 +574,9 @@ class Utils public static function getPublicDirs(): array { $dirs = []; - $all = Files::getDirList(dcCore::app()->blog->public_path); + $all = Files::getDirList(App::blog()->publicPath()); foreach ($all['dirs'] as $dir) { - $dir = substr($dir, strlen(dcCore::app()->blog->public_path) + 1); + $dir = substr($dir, strlen(App::blog()->publicPath()) + 1); $dirs[$dir] = $dir; } diff --git a/src/Widgets.php b/src/Widgets.php index fc766e8..215dbdd 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -1,27 +1,24 @@ create( 'cinecturlink2links', __('My cinecturlink'), - [self::class, 'parseLinks'], + self::parseLinks(...), null, __('Show selection of cinecturlinks') ) @@ -112,15 +109,12 @@ class Widgets ->addContentOnly() ->addClass() ->addOffline(); - } - public static function initCats(WidgetsStack $w): void - { $w ->create( 'cinecturlink2cats', __('List of categories of cinecturlink'), - [self::class, 'parseCats'], + self::parseCats(...), null, __('List of categories of cinecturlink') ) @@ -148,7 +142,7 @@ class Widgets public static function parseLinks(WidgetsElement $w): string { if (!My::settings()->avtive - || !$w->checkHomeOnly(dcCore::app()->url->type) + || !$w->checkHomeOnly(App::url()->type) ) { return ''; } @@ -216,7 +210,7 @@ class Widgets $count = abs((int) $rs->link_count); # --BEHAVIOR-- cinecturlink2WidgetLinks - $bhv = dcCore::app()->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); + $bhv = App::behavior()->callBehavior('cinecturlink2WidgetLinks', $rs->link_id); $entries[] = '

' . ($w->withlink && !empty($url) ? '' : '') . @@ -228,7 +222,7 @@ class Widgets '

' . $bhv; try { - $cur = dcCore::app()->con->openCursor($C2->table); + $cur = App::con()->openCursor($C2->table); $cur->link_count = ($count + 1); $C2->updLink((int) $rs->link_id, $cur, false); } catch (Exception $e) { @@ -240,7 +234,7 @@ class Widgets ) { shuffle($entries); if (My::settings()->triggeronrandom) { - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); } } @@ -251,7 +245,7 @@ class Widgets ($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . implode(' ', $entries) . ( $w->showpagelink && My::settings()->public_active ? - '

' . __('More links') . '

' : '' + '

' . __('More links') . '

' : '' ) ); } @@ -260,7 +254,7 @@ class Widgets { if (!My::settings()->avtive || !My::settings()->public_active - || !$w->checkHomeOnly(dcCore::app()->url->type) + || !$w->checkHomeOnly(App::url()->type) ) { return ''; } @@ -273,14 +267,14 @@ class Widgets $res = []; $res[] = '
  • ' . __('all links') . '' . ($w->shownumlink ? ' (' . ($C2->getLinks([], true)->f(0)) . ')' : '') . '
  • '; while ($rs->fetch()) { $res[] = '
  • ' .