code review
This commit is contained in:
parent
48400b5b82
commit
ca14b5036e
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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',
|
||||
|
@ -2,10 +2,10 @@
|
||||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="comListe">
|
||||
<name>Comments list</name>
|
||||
<version>0.9</version>
|
||||
<version>0.9.1</version>
|
||||
<author>Benoit de Marne, Pierre Van Glabeke and contributors</author>
|
||||
<desc>Display a list of all comments and trackbacks of a blog in a public page</desc>
|
||||
<file>https://git.dotclear.watch/JcDenis/comListe/releases/download/v0.9/plugin-comListe.zip</file>
|
||||
<file>https://git.dotclear.watch/JcDenis/comListe/releases/download/v0.9.1/plugin-comListe.zip</file>
|
||||
<da:dcmin>2.28</da:dcmin>
|
||||
<da:details>https://git.dotclear.watch/JcDenis/comListe/src/branch/master/README.md</da:details>
|
||||
<da:support>https://git.dotclear.watch/JcDenis/comListe/issues</da:support>
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeURL(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($attr), 'App::blog()->url.App::url()->getBase("comListe")') . '; ?>';
|
||||
}
|
||||
|
||||
/* ComListePageTitle --------------------------------------- */
|
||||
/**
|
||||
* comListePageTitle.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePageTitle(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($attr), 'App::blog()->settings()->get("' . My::id() . '")->get("page_title")') . '; ?>';
|
||||
}
|
||||
|
||||
/* ComListeNbCommentsPerPage --------------------------------------- */
|
||||
/**
|
||||
* comListeNbCommentsPerPage.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $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<string, mixed> $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<string, mixed> $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<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePaginationLinks(ArrayObject $attr): string
|
||||
{
|
||||
$p = '<?php
|
||||
@ -210,12 +235,21 @@ class Template
|
||||
return $p;
|
||||
}
|
||||
|
||||
/* ComListeOpenPostTitle --------------------------------------- */
|
||||
/**
|
||||
* comListeOpenPostTitle.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeOpenPostTitle(ArrayObject $attr): string
|
||||
{
|
||||
return __('open post');
|
||||
}
|
||||
|
||||
/**
|
||||
* comListeCommentOrderNumber.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeCommentOrderNumber(ArrayObject $attr): string
|
||||
{
|
||||
return
|
||||
@ -226,6 +260,11 @@ class Template
|
||||
'?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePagination.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePagination(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$params = "<?php\n" .
|
||||
@ -259,11 +298,21 @@ class Template
|
||||
'?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePaginationCounter.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePaginationCounter(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($attr), 'App::frontend()->context()::PaginationNbPages()') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePaginationCurrent.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $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 '<?php echo ' . sprintf(App::frontend()->template()->getFilters($attr), 'App::frontend()->context()::PaginationPosition(' . $offset . ')') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePaginationIf.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePaginationIf(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$if = [];
|
||||
@ -292,6 +346,11 @@ class Template
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePaginationURL.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePaginationURL(ArrayObject $attr): string
|
||||
{
|
||||
$offset = 0;
|
@ -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;
|
@ -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'),
|
||||
|
@ -29,10 +29,10 @@ class Prepend extends Process
|
||||
}
|
||||
|
||||
App::url()->register(
|
||||
'comListe',
|
||||
My::id(),
|
||||
'comListe',
|
||||
'^comListe(?:/(.+))?$',
|
||||
UrlHandler::comListe(...)
|
||||
FrontendUrl::comListe(...)
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -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',
|
||||
|
@ -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(
|
||||
'<p><a href="%s">%s</a></p>',
|
||||
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())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user