diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b6df4..1c122eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +comListe 0.9.1 - 2023.10.24 +=========================================================== +* Require dotclear 2.28 +* Require PHP 8.1 +* Code review + comListe 0.9 - 2023.10.15 =========================================================== * Require dotclear 2.28 diff --git a/README.md b/README.md index 1e92b0d..cb1e2a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # README -[![Release](https://img.shields.io/badge/release-0.9-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/comListe/releases) -![Date](https://img.shields.io/badge/date-2023.10.15-c44d58.svg) +[![Release](https://img.shields.io/badge/release-0.9.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/comListe/releases) +![Date](https://img.shields.io/badge/date-2023.10.24-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/comListe) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/comListe/src/branch/master/LICENSE) @@ -36,7 +36,7 @@ to your theme tpl path and adapt them. * [Packages & details](https://git.dotclear.watch/JcDenis/comListe/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/comListe)) * [Sources & contributions](https://git.dotclear.watch/JcDenis/comListe) (or on [GitHub](https://github.com/JcDenis/comListe)) * [Issues & security](https://git.dotclear.watch/JcDenis/comListe/issues) (or on [GitHub](https://github.com/JcDenis/comListe/issues)) -* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=333985) +* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=48531) ## CONTRIBUTORS diff --git a/_define.php b/_define.php index 44f0471..9f3de8d 100644 --- a/_define.php +++ b/_define.php @@ -18,7 +18,7 @@ $this->registerModule( 'Comments list', 'Display a list of all comments and trackbacks of a blog in a public page', 'Benoit de Marne, Pierre Van Glabeke and contributors', - '0.9', + '0.9.1', [ 'requires' => [['core', '2.28']], 'permissions' => 'My', diff --git a/dcstore.xml b/dcstore.xml index 41dec6b..a3898b0 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,10 +2,10 @@ Comments list - 0.9 + 0.9.1 Benoit de Marne, Pierre Van Glabeke and contributors Display a list of all comments and trackbacks of a blog in a public page - https://git.dotclear.watch/JcDenis/comListe/releases/download/v0.9/plugin-comListe.zip + https://git.dotclear.watch/JcDenis/comListe/releases/download/v0.9.1/plugin-comListe.zip 2.28 https://git.dotclear.watch/JcDenis/comListe/src/branch/master/README.md https://git.dotclear.watch/JcDenis/comListe/issues diff --git a/locales/fr/resources.php b/locales/fr/resources.php index a9c47bb..c220e7f 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -2,9 +2,10 @@ /** * @file * @brief The plugin locales resources + * @ingroup comListe * - * @author Tomtom (author) + * @author Benoit de Marne (author) * @author Jean-Christian Denis (latest) * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -dcCore::app()->resources['help']['comListe'] = __DIR__ . '/help/comListe.html'; +\Dotclear\App::backend()->resources()->set('help', 'comListe', __DIR__ . '/help/comListe.html'); diff --git a/src/Backend.php b/src/Backend.php index cca7c48..5122981 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -8,6 +8,7 @@ use ArrayObject; use Dotclear\App; use Dotclear\Core\Backend\Favorites; use Dotclear\Core\Process; +use Dotclear\Helper\Html\Html; /** * @brief comListe backend class. @@ -51,9 +52,10 @@ class Backend extends Process if (My::id() == $type) { $item[0] = My::name(); $item[1] = My::settings()->get('page_title') ?? My::name(); - $item[2] = App::backend()->__get('blog_url') . App::url()->getURLFor(My::id()); + $item[2] = Html::stripHostURL(App::blog()->url()) . App::url()->getURLFor(My::id()); } }, + 'initWidgets' => Widgets::initWidgets(...), ]); return true; diff --git a/src/Frontend.php b/src/Frontend.php index f414400..426edc5 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -24,39 +24,31 @@ class Frontend extends Process public static function process(): bool { - if (!self::status()) { + if (!self::status() || !My::settings()->get('enable')) { return false; } - if (!My::settings()->get('enable')) { - return false; - } + $tpl = App::frontend()->template(); - App::frontend()->template()->addValue('ComListeURL', Template::comListeURL(...)); - App::frontend()->template()->addValue('ComListePageTitle', Template::comListePageTitle(...)); - App::frontend()->template()->addValue('ComListeNbComments', Template::comListeNbComments(...)); - App::frontend()->template()->addValue('ComListeNbCommentsPerPage', Template::comListeNbCommentsPerPage(...)); - App::frontend()->template()->addBlock('ComListeCommentsEntries', Template::comListeCommentsEntries(...)); - App::frontend()->template()->addValue('ComListePaginationLinks', Template::comListePaginationLinks(...)); - App::frontend()->template()->addValue('ComListeOpenPostTitle', Template::comListeOpenPostTitle(...)); - App::frontend()->template()->addValue('ComListeCommentOrderNumber', Template::comListeCommentOrderNumber(...)); + $tpl->addValue('ComListeURL', FrontendTemplate::comListeURL(...)); + $tpl->addValue('ComListePageTitle', FrontendTemplate::comListePageTitle(...)); + $tpl->addValue('ComListeNbComments', FrontendTemplate::comListeNbComments(...)); + $tpl->addValue('ComListeNbCommentsPerPage', FrontendTemplate::comListeNbCommentsPerPage(...)); + $tpl->addBlock('ComListeCommentsEntries', FrontendTemplate::comListeCommentsEntries(...)); + $tpl->addValue('ComListePaginationLinks', FrontendTemplate::comListePaginationLinks(...)); + $tpl->addValue('ComListeOpenPostTitle', FrontendTemplate::comListeOpenPostTitle(...)); + $tpl->addValue('ComListeCommentOrderNumber', FrontendTemplate::comListeCommentOrderNumber(...)); - App::frontend()->template()->addBlock('ComListePagination', Template::comListePagination(...)); - App::frontend()->template()->addValue('ComListePaginationCounter', Template::comListePaginationCounter(...)); - App::frontend()->template()->addValue('ComListePaginationCurrent', Template::comListePaginationCurrent(...)); - App::frontend()->template()->addBlock('ComListePaginationIf', Template::comListePaginationIf(...)); - App::frontend()->template()->addValue('ComListePaginationURL', Template::comListePaginationURL(...)); + $tpl->addBlock('ComListePagination', FrontendTemplate::comListePagination(...)); + $tpl->addValue('ComListePaginationCounter', FrontendTemplate::comListePaginationCounter(...)); + $tpl->addValue('ComListePaginationCurrent', FrontendTemplate::comListePaginationCurrent(...)); + $tpl->addBlock('ComListePaginationIf', FrontendTemplate::comListePaginationIf(...)); + $tpl->addValue('ComListePaginationURL', FrontendTemplate::comListePaginationURL(...)); - App::behavior()->addBehavior( - 'publicBreadcrumb', - function (string $context, string $separator): ?string { - if ($context == 'comListe') { - return __('Comments list'); - } - - return null; - }, - ); + App::behavior()->addBehaviors([ + 'publicBreadcrumb' => fn (string $context, string $separator) => $context == 'comListe' ? __('Comments list') : null, + 'initWidgets' => Widgets::initWidgets(...), + ]); return true; } diff --git a/src/Template.php b/src/FrontendTemplate.php similarity index 86% rename from src/Template.php rename to src/FrontendTemplate.php index 16e559d..24f2751 100644 --- a/src/Template.php +++ b/src/FrontendTemplate.php @@ -16,24 +16,36 @@ use Dotclear\Helper\Html\Html; * @author Jean-Christian Denis (latest) * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -class Template +class FrontendTemplate { public string $html_prev = '«prev.'; public string $html_next = 'next»'; - /* ComListeURL --------------------------------------- */ + /** + * comListeURL. + * + * @param ArrayObject $attr The attributes + */ public static function comListeURL(ArrayObject $attr): string { return 'template()->getFilters($attr), 'App::blog()->url.App::url()->getBase("comListe")') . '; ?>'; } - /* ComListePageTitle --------------------------------------- */ + /** + * comListePageTitle. + * + * @param ArrayObject $attr The attributes + */ public static function comListePageTitle(ArrayObject $attr): string { return 'template()->getFilters($attr), 'App::blog()->settings()->get("' . My::id() . '")->get("page_title")') . '; ?>'; } - /* ComListeNbCommentsPerPage --------------------------------------- */ + /** + * comListeNbCommentsPerPage. + * + * @param ArrayObject $attr The attributes + */ public static function comListeNbCommentsPerPage(ArrayObject $attr): string { if (!App::blog()->isDefined()) { @@ -44,7 +56,11 @@ class Template return Html::escapeHTML((string) App::frontend()->context()->__get('nb_comment_per_page')); } - /* comListeNbComments --------------------------------------- */ + /** + * comListeNbComments. + * + * @param ArrayObject $attr The attributes + */ public static function comListeNbComments(ArrayObject$attr): string { if (!App::blog()->isDefined()) { @@ -58,7 +74,11 @@ class Template return Html::escapeHTML((string) $nb_comments); } - /* ComListeCommentsEntries --------------------------------------- */ + /** + * comListeCommentsEntries. + * + * @param ArrayObject $attr The attributes + */ public static function comListeCommentsEntries(ArrayObject $attr, string $content): string { $p = 'if (App::frontend()->context()->posts !== null) { ' . @@ -122,8 +142,13 @@ class Template return $res; } - /* ComListePaginationLinks --------------------------------------- */ - /* Reprise et adaptation de la fonction PaginationLinks du plugin advancedPagination-1.9 */ + /** + * comListePaginationLinks. + * + * Reprise et adaptation de la fonction PaginationLinks du plugin advancedPagination-1.9 + * + * @param ArrayObject $attr The attributes + */ public static function comListePaginationLinks(ArrayObject $attr): string { $p = ' $attr The attributes + */ public static function comListeOpenPostTitle(ArrayObject $attr): string { return __('open post'); } + /** + * comListeCommentOrderNumber. + * + * @param ArrayObject $attr The attributes + */ public static function comListeCommentOrderNumber(ArrayObject $attr): string { return @@ -226,6 +260,11 @@ class Template '?>'; } + /** + * comListePagination. + * + * @param ArrayObject $attr The attributes + */ public static function comListePagination(ArrayObject $attr, string $content): string { $params = "'; } + /** + * comListePaginationCounter. + * + * @param ArrayObject $attr The attributes + */ public static function comListePaginationCounter(ArrayObject $attr): string { return 'template()->getFilters($attr), 'App::frontend()->context()::PaginationNbPages()') . '; ?>'; } + /** + * comListePaginationCurrent. + * + * @param ArrayObject $attr The attributes + */ public static function comListePaginationCurrent(ArrayObject $attr): string { $offset = isset($attr['offset']) ? (int) $attr['offset'] : 0; @@ -271,6 +320,11 @@ class Template return 'template()->getFilters($attr), 'App::frontend()->context()::PaginationPosition(' . $offset . ')') . '; ?>'; } + /** + * comListePaginationIf. + * + * @param ArrayObject $attr The attributes + */ public static function comListePaginationIf(ArrayObject $attr, string $content): string { $if = []; @@ -292,6 +346,11 @@ class Template return $content; } + /** + * comListePaginationURL. + * + * @param ArrayObject $attr The attributes + */ public static function comListePaginationURL(ArrayObject $attr): string { $offset = 0; diff --git a/src/UrlHandler.php b/src/FrontendUrl.php similarity index 62% rename from src/UrlHandler.php rename to src/FrontendUrl.php index a4b02ba..8fd6d63 100644 --- a/src/UrlHandler.php +++ b/src/FrontendUrl.php @@ -15,15 +15,13 @@ use Dotclear\Core\Frontend\Url; * @author Jean-Christian Denis (latest) * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -class UrlHandler extends Url +class FrontendUrl extends Url { public static function comListe(?string $args): void { $args = (string) $args; - if (!App::blog()->isDefined() - || !My::settings()->get('enable') - ) { + if (!My::settings()->get('enable')) { self::p404(); } @@ -31,11 +29,10 @@ class UrlHandler extends Url App::frontend()->context()->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page')); $tplset = App::themes()->moduleInfo(App::blog()->settings()->get('system')->get('theme'), 'tplset'); - if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) { - App::frontend()->template()->setPath(App::frontend()->template()->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset])); - } else { - App::frontend()->template()->setPath(App::frontend()->template()->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', App::config()->defaultTplset()])); + if (empty($tplset) || !is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) { + $tplset = App::config()->defaultTplset(); } + App::frontend()->template()->appendPath(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset])); self::serveDocument('comListe.html'); exit; diff --git a/src/Manage.php b/src/Manage.php index 51b8df9..a909882 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -107,7 +107,7 @@ class Manage extends Process (new Text('h4', __('General options'))), (new Para())->items([ (new Label(__('Public page title:'), Label::OUTSIDE_LABEL_BEFORE))->for('comliste_page_title'), - (new Input('comliste_page_title'))->size(30)->maxlenght(255)->value((string) $s->get('page_title')), + (new Input('comliste_page_title'))->size(30)->maxlength(255)->value((string) $s->get('page_title')), ]), (new Para())->items([ (new Label(__('Number of comments per page:'), Label::OUTSIDE_LABEL_BEFORE))->for('comliste_nb_comments_per_page'), diff --git a/src/Prepend.php b/src/Prepend.php index 8dc0fba..8a776c5 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -29,10 +29,10 @@ class Prepend extends Process } App::url()->register( - 'comListe', + My::id(), 'comListe', '^comListe(?:/(.+))?$', - UrlHandler::comListe(...) + FrontendUrl::comListe(...) ); return true; diff --git a/src/Uninstall.php b/src/Uninstall.php index cd94f02..9399a83 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -29,11 +29,6 @@ class Uninstall extends Process } Uninstaller::instance() - ->addUserAction( - 'settings', - 'delete_all', - My::id() - ) ->addUserAction( 'plugins', 'delete', @@ -44,11 +39,6 @@ class Uninstall extends Process 'delete', My::id() ) - ->addDirectAction( - 'settings', - 'delete_all', - My::id() - ) ->addDirectAction( 'plugins', 'delete', diff --git a/src/Widgets.php b/src/Widgets.php index 7207b34..ed3380f 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -42,8 +42,7 @@ class Widgets public static function parseWidget(WidgetsElement $w): string { - if (!App::blog()->isDefined() - || $w->__get('offline') + if ($w->get('offline') || !$w->checkHomeOnly(App::url()->type) || !My::settings()->get('enable') ) { @@ -51,14 +50,14 @@ class Widgets } return $w->renderDiv( - (bool) $w->__get('content_only'), - My::id() . ' ' . $w->__get('class'), + (bool) $w->get('content_only'), + My::id() . ' ' . $w->get('class'), '', - ($w->__get('title') ? $w->renderTitle(Html::escapeHTML($w->__get('title'))) : '') . + ($w->get('title') ? $w->renderTitle(Html::escapeHTML($w->get('title'))) : '') . sprintf( '

%s

', App::blog()->url() . App::url()->getBase('comListe'), - $w->__get('link_title') ? Html::escapeHTML($w->__get('link_title')) : (My::settings()->get('page_title') ?? My::name()) + $w->get('link_title') ? Html::escapeHTML($w->get('link_title')) : (My::settings()->get('page_title') ?? My::name()) ) ); }