From aa7ec2d61d9a1fa8c14e8224a275b222e8088c7a Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 20 Oct 2023 18:04:17 +0200 Subject: [PATCH] upgrade to dotclear 2.28 --- CHANGELOG.md | 6 +++ README.md | 34 +++++++------ _define.php | 34 ++++++------- dcstore.xml | 6 +-- src/Backend.php | 25 ++++------ src/Frontend.php | 25 ++++------ src/My.php | 20 ++++---- src/Widgets.php | 121 ++++++++++++++++++++++------------------------- 8 files changed, 125 insertions(+), 146 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0299b6e..39064b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +postInfoWidget 1.2 - 2023.10.20 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + postInfoWidget 1.1 - 2023.08.13 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index e6f1c8c..d22eeb1 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,22 @@ # README -[![Release](https://img.shields.io/badge/release-1.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postInfoWidget/releases) -[![Date](https://img.shields.io/badge/date-2023.08.13-c44d58.svg)](https://git.dotclear.watch/JcDenis/postInfoWidget/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.2-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postInfoWidget/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/postInfoWidget) -[![License](https://img.shields.io/github/license/JcDenis/postInfoWidget)](https://git.dotclear.watch/JcDenis/postInfoWidget/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/postInfoWidget/src/branch/master/LICENSE) -## WHAT IS POSTINFOWIDGET ? +## ABOUT -_postInfoWidget_ "Entry information list" is a plugin for the open-source -web publishing software called Dotclear. +_postInfoWidget_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -Show entry details in a widget. +> Show entry details in a widget. ## REQUIREMENTS -_postInfoWidget_ requires: - -* permissions to manage widgets -* Dotclear 2.26 -* PHP 7.4 +* Dotclear 2.28 +* PHP 8.1 +* Dotclear permissions to manage widgets ## USAGE @@ -30,14 +27,15 @@ Add and configure "Entry information list" from widgets manager. ## 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/postInfoWidget) or [GitHub Page](https://github.com/JcDenis/postInfoWidget) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/postInfoWidget/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/postInfoWidget) -* Discuss and help : [Dotclear Forum](http://forum.dotclear.org/viewtopic.php?pid=332974#p332974) +* [License](https://git.dotclear.watch/JcDenis/postInfoWidget/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/postInfoWidget/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/postInfoWidget)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/postInfoWidget) (or on [GitHub](https://github.com/JcDenis/postInfoWidget)) +* [Issues & security](https://git.dotclear.watch/JcDenis/postInfoWidget/issues) (or on [GitHub](https://github.com/JcDenis/postInfoWidget/issues)) +* [Discuss & help](http://forum.dotclear.org/viewtopic.php?pid=332974#p332974) ## CONTRIBUTORS -* Jean-Christian Denis +* Jean-Christian Denis (author) * Pierre Van Glabeke You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 4d18d28..3e29703 100644 --- a/_define.php +++ b/_define.php @@ -1,33 +1,29 @@ registerModule( 'Entry information list', 'Show Entry informations on a widget', 'Jean-Christian Denis, Pierre Van Glabeke', - '1.1', + '1.2', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_USAGE, - 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']], + '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/dcstore.xml b/dcstore.xml index 9a229f2..d4b0aab 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Entry information list - 1.1 + 1.2 Jean-Christian Denis, Pierre Van Glabeke Show Entry informations on a widget - https://git.dotclear.watch/JcDenis/postInfoWidget/releases/download/v1.1/plugin-postInfoWidget.zip - 2.27 + https://git.dotclear.watch/JcDenis/postInfoWidget/releases/download/v1.2/plugin-postInfoWidget.zip + 2.28 https://git.dotclear.watch/JcDenis/postInfoWidget/src/branch/master/README.md https://git.dotclear.watch/JcDenis/postInfoWidget/issues diff --git a/src/Backend.php b/src/Backend.php index 1934edc..218599c 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,22 +1,19 @@ addBehaviors([ - 'initWidgets' => [Widgets::class, 'initWidgets'], - ]); + App::behavior()->addBehavior('initWidgets', Widgets::initWidgets(...)); return true; } diff --git a/src/Frontend.php b/src/Frontend.php index bf4bd24..56cfc4c 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,19 @@ addBehaviors([ - 'initWidgets' => [Widgets::class, 'initWidgets'], - ]); + App::behavior()->addBehavior('initWidgets', Widgets::initWidgets(...)); return true; } diff --git a/src/My.php b/src/My.php index cd98333..0e068cb 100644 --- a/src/My.php +++ b/src/My.php @@ -1,21 +1,19 @@ create( 'postinfowidget', - __('PostInfoWidget: entry information list'), - [self::class, 'publicWidget'], + __('Entry information list'), + self::publicWidget(...), null, __('Show Entry informations on a widget') ) @@ -76,7 +73,7 @@ class Widgets 'text' ); - if (dcCore::app()->plugins->moduleExists('tags')) { + if (App::plugins()->moduleExists('tags')) { $w->__get('postinfowidget')->setting( 'tag_str', __('Tags text (%T = tags list):'), @@ -173,7 +170,7 @@ class Widgets ); //*/ # --BEHAVIOR-- postInfoWidgetAdmin - dcCore::app()->callBehavior('postInfoWidgetAdmin', $w); + App::behavior()->callBehavior('postInfoWidgetAdmin', $w); $w->__get('postinfowidget') ->addContentOnly() @@ -183,14 +180,10 @@ class Widgets public static function publicWidget(WidgetsElement $w): string { - // nullsafe - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) { - return ''; - } - - if ($w->__get('offline') - || dcCore::app()->url->type != 'post' - || !dcCore::app()->ctx->__get('posts')->f('post_id') + if (!App::blog()->isDefined() + || $w->__get('offline') + || App::url()->type != 'post' + || !App::frontend()->context()->__get('posts')->f('post_id') ) { return ''; } @@ -204,8 +197,8 @@ class Widgets 'date', Date::str( $w->__get('dt_str'), - (int) strtotime(dcCore::app()->ctx->__get('posts')->f('post_dt')), - dcCore::app()->blog->settings->get('system')->get('blog_timezone') + (int) strtotime(App::frontend()->context()->__get('posts')->f('post_dt')), + App::blog()->settings()->get('system')->get('blog_timezone') ) ); } @@ -216,8 +209,8 @@ class Widgets 'create', Date::str( $w->__get('creadt_str'), - (int) strtotime(dcCore::app()->ctx->__get('posts')->post_creadt), - dcCore::app()->blog->settings->get('system')->get('blog_timezone') + (int) strtotime(App::frontend()->context()->__get('posts')->post_creadt), + App::blog()->settings()->get('system')->get('blog_timezone') ) ); } @@ -228,24 +221,24 @@ class Widgets 'update', Date::str( $w->__get('upddt_str'), - (int) strtotime(dcCore::app()->ctx->__get('posts')->f('post_upddt')), - dcCore::app()->blog->settings->get('system')->get('blog_timezone') + (int) strtotime(App::frontend()->context()->__get('posts')->f('post_upddt')), + App::blog()->settings()->get('system')->get('blog_timezone') ) ); } if ($w->__get('lang_str') != '') { $ln = L10n::getISOcodes(); - $lang_code = dcCore::app()->ctx->__get('posts')->f('post_lang') ? - dcCore::app()->ctx->__get('posts')->f('post_lang') : - dcCore::app()->blog->settings->get('system')->get('lang'); + $lang_code = App::frontend()->context()->__get('posts')->f('post_lang') ? + App::frontend()->context()->__get('posts')->f('post_lang') : + App::blog()->settings()->get('system')->get('lang'); $lang_name = $ln[$lang_code] ?? $lang_code; $lang_flag = file_exists( dirname(__DIR__) . '/img/flags/' . $lang_code . '.png' ) ? - 'getQmarkURL() . 'pf=postInfoWidget/img/flags/' . $lang_code . '.png" alt="' . $lang_name . '" />' : ''; @@ -267,13 +260,13 @@ class Widgets 'author', str_replace( '%T', - dcCore::app()->ctx->__get('posts')->getAuthorLink(), + App::frontend()->context()->__get('posts')->getAuthorLink(), Html::escapeHTML($w->__get('author_str')) ) ); } - if ($w->__get('category_str') != '' && dcCore::app()->ctx->__get('posts')->f('cat_id')) { + if ($w->__get('category_str') != '' && App::frontend()->context()->__get('posts')->f('cat_id')) { $content .= self::li( $w, 'category', @@ -281,25 +274,25 @@ class Widgets '%T', sprintf( $link, - dcCore::app()->ctx->__get('posts')->__call('getCategoryURL', []), - Html::escapeHTML(dcCore::app()->ctx->__get('posts')->f('cat_title')) + App::frontend()->context()->__get('posts')->__call('getCategoryURL', []), + Html::escapeHTML(App::frontend()->context()->__get('posts')->f('cat_title')) ), Html::escapeHTML($w->__get('category_str')) ) ); } - if ($w->__get('tag_str') != '' && dcCore::app()->plugins->moduleExists('tags')) { - $meta = dcCore::app()->meta->getMetadata([ + if ($w->__get('tag_str') != '' && App::plugins()->moduleExists('tags')) { + $meta = App::meta()->getMetadata([ 'meta_type' => 'tag', - 'post_id' => dcCore::app()->ctx->__get('posts')->f('post_id'), + 'post_id' => App::frontend()->context()->__get('posts')->f('post_id'), ]); $metas = []; while ($meta->fetch()) { $metas[$meta->f('meta_id')] = sprintf( $link, - dcCore::app()->blog->url . - dcCore::app()->url->getBase('tag') . '/' . + App::blog()->url() . + App::url()->getBase('tag') . '/' . rawurlencode($meta->f('meta_id')), $meta->f('meta_id') ); @@ -318,7 +311,7 @@ class Widgets } if ($w->__get('attachment_str') != '') { - $nb = dcCore::app()->ctx->__get('posts')->__call('countMedia', []); + $nb = App::frontend()->context()->__get('posts')->__call('countMedia', []); if ($nb == 0) { $attachment_numeric = 0; $attachment_textual = __('no attachment'); @@ -357,8 +350,8 @@ class Widgets ); } - if ($w->__get('comment_str') != '' && dcCore::app()->ctx->__get('posts')->__call('commentsActive', [])) { - $nb = (int) dcCore::app()->ctx->__get('posts')->f('nb_comment'); + if ($w->__get('comment_str') != '' && App::frontend()->context()->__get('posts')->__call('commentsActive', [])) { + $nb = (int) App::frontend()->context()->__get('posts')->f('nb_comment'); if ($nb == 0) { $comment_numeric = 0; $comment_textual = __('no comment'); @@ -397,8 +390,8 @@ class Widgets ); } - if ($w->__get('trackback_str') != '' && dcCore::app()->ctx->__get('posts')->__call('trackbacksActive', [])) { - $nb = (int) dcCore::app()->ctx->__get('posts')->f('nb_trackback'); + if ($w->__get('trackback_str') != '' && App::frontend()->context()->__get('posts')->__call('trackbacksActive', [])) { + $nb = (int) App::frontend()->context()->__get('posts')->f('nb_trackback'); if ($nb == 0) { $trackback_numeric = 0; $trackback_textual = __('no trackback'); @@ -446,26 +439,26 @@ class Widgets [ sprintf( $link, - dcCore::app()->ctx->__get('posts')->__call('getURL', []), + App::frontend()->context()->__get('posts')->__call('getURL', []), __('Permalink') ), - dcCore::app()->ctx->__get('posts')->__call('getURL', []), + App::frontend()->context()->__get('posts')->__call('getURL', []), ], Html::escapeHTML($w->__get('permalink_str')) ) ); } - if ($w->__get('feed') && dcCore::app()->ctx->__get('posts')->__call('commentsActive', [])) { + if ($w->__get('feed') && App::frontend()->context()->__get('posts')->__call('commentsActive', [])) { $content .= self::li( $w, 'feed', sprintf( $link, - dcCore::app()->blog->url . - dcCore::app()->url->getBase('feed') . + App::blog()->url() . + App::url()->getBase('feed') . '/atom/comments/' . - dcCore::app()->ctx->__get('posts')->f('post_id'), + App::frontend()->context()->__get('posts')->f('post_id'), __("This post's comments feed") ) ); @@ -473,7 +466,7 @@ class Widgets if ($w->__get('navprevpost')) { $npp = self::nav( - dcCore::app()->ctx->__get('posts'), + App::frontend()->context()->__get('posts'), -1, false, __('Previous entry'), @@ -489,7 +482,7 @@ class Widgets } if ($w->__get('navnextpost')) { $nnp = self::nav( - dcCore::app()->ctx->__get('posts'), + App::frontend()->context()->__get('posts'), 1, false, __('Next entry'), @@ -506,7 +499,7 @@ class Widgets if ($w->__get('navprevcat')) { $npc = self::nav( - dcCore::app()->ctx->__get('posts'), + App::frontend()->context()->__get('posts'), -1, true, __('Previous entry of this category'), @@ -523,7 +516,7 @@ class Widgets if ($w->__get('navnextcat')) { $nnc = self::nav( - dcCore::app()->ctx->__get('posts'), + App::frontend()->context()->__get('posts'), 1, true, __('Next entry of this category'), @@ -539,7 +532,7 @@ class Widgets } # --BEHAVIOR-- postInfoWidgetPublic - $content .= dcCore::app()->callBehavior('postInfoWidgetPublic', $w); + $content .= (string) App::behavior()->callBehavior('postInfoWidgetPublic', $w); if (empty($content)) { return ''; @@ -581,13 +574,12 @@ class Widgets public static function li(WidgetsElement $w, string $i, string $c): string { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return ''; } $s = ' style="padding-left:%spx;background: transparent url(\'' . - dcCore::app()->blog->getQmarkURL() . + App::blog()->getQmarkURL() . 'pf=postInfoWidget/img/%s%s.png\') no-repeat left center;"'; if ($w->__get('style') == 'small') { $s = sprintf($s, 16, $i, '-small'); @@ -603,12 +595,11 @@ class Widgets public static function nav(MetaRecord $p, int $d, bool $r, string $t, string $c): string { - // nullsafe - if (is_null(dcCore::app()->blog)) { + if (!App::blog()->isDefined()) { return ''; } - $rs = dcCore::app()->blog->getNextPost($p, $d, $r); + $rs = App::blog()->getNextPost($p, $d, $r); if (is_null($rs)) { return ''; }