Compare commits
No commits in common. "master" and "v0.8" have entirely different histories.
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,21 +1,3 @@
|
||||
comListe 0.9.2 - 2023.11.04
|
||||
===========================================================
|
||||
* Require dotclear 2.28
|
||||
* Require PHP 8.1
|
||||
* Cosmetic fix
|
||||
|
||||
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
|
||||
* Require PHP 8.1
|
||||
* Upgrade to Dotclear 2.28
|
||||
|
||||
comListe 0.8 - 2023.08.06
|
||||
===========================================================
|
||||
* Require dotclear 2.27
|
||||
|
41
README.md
41
README.md
@ -1,22 +1,25 @@
|
||||
# README
|
||||
|
||||
[![Release](https://img.shields.io/badge/release-0.9.2-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/comListe/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.11.04-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)
|
||||
[![Release](https://img.shields.io/github/v/release/JcDenis/comListe)](https://git.dotclear.watch/JcDenis/comListe/releases)
|
||||
[![Date](https://img.shields.io/github/release-date/JcDenis/comListe)](https://git.dotclear.watch/JcDenis/comListe/releases)
|
||||
[![Issues](https://img.shields.io/github/issues/JcDenis/comListe)](https://git.dotclear.watch/JcDenis/comListe/issues)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/comListe)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/comListe)](https://git.dotclear.watch/JcDenis/comListe/blob/master/LICENSE)
|
||||
|
||||
## ABOUT
|
||||
## WHAT IS COMLISTE ?
|
||||
|
||||
_comListe_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
|
||||
_comListe_ is a plugin for the open-source
|
||||
web publishing software called Dotclear.
|
||||
|
||||
> Add public page of all comments and trackbacks.
|
||||
It adds public page of all comments and trackbacks.
|
||||
|
||||
## REQUIREMENTS
|
||||
|
||||
* Dotclear 2.28
|
||||
* PHP 8.1
|
||||
* Dotclear admin permissons for configuration
|
||||
_comListe_ requires:
|
||||
|
||||
* admin perms for configuration
|
||||
* Dotclear 2.27
|
||||
|
||||
## USAGE
|
||||
|
||||
@ -33,15 +36,15 @@ to your theme tpl path and adapt them.
|
||||
|
||||
## LINKS
|
||||
|
||||
* [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=48531)
|
||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
||||
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/comListe) or [GitHub Page](https://github.com/JcDenis/comListe)
|
||||
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/comListe/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/comListe)
|
||||
* Discuss and help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=333985)
|
||||
|
||||
## CONTRIBUTORS
|
||||
|
||||
* Benoit de Marne (author)
|
||||
* Pierre Van Glabeke
|
||||
* Jean-Christian Denis (latest)
|
||||
* Benoit de Marne (author)
|
||||
* Pierre Van Glabeke
|
||||
* Jean-Christian Denis
|
||||
|
||||
You are welcome to contribute to this code.
|
||||
You are welcome to contribute to this code.
|
38
_define.php
38
_define.php
@ -1,31 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* @brief The plugin comListe definition
|
||||
* @ingroup comListe
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @defgroup comListe Plugin comListe.
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* Display a list of all comments and trackbacks of a blog in a public page.
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$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.2',
|
||||
'0.8',
|
||||
[
|
||||
'requires' => [['core', '2.28']],
|
||||
'permissions' => 'My',
|
||||
'type' => 'plugin',
|
||||
'settings' => ['self' => ''],
|
||||
'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.26']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_ADMIN,
|
||||
]),
|
||||
'type' => 'plugin',
|
||||
'settings' => [
|
||||
'self' => '',
|
||||
],
|
||||
'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',
|
||||
]
|
||||
);
|
||||
|
@ -2,11 +2,11 @@
|
||||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="comListe">
|
||||
<name>Comments list</name>
|
||||
<version>0.9.2</version>
|
||||
<version>0.8</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.2/plugin-comListe.zip</file>
|
||||
<da:dcmin>2.28</da:dcmin>
|
||||
<file>https://gitea.dotclear.watch/JcDenis/comListe/releases/download/v0.8/plugin-comListe.zip</file>
|
||||
<da:dcmin>2.26</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>
|
||||
</module>
|
||||
|
@ -1,10 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* @brief The plugin locales resources
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @author Tomtom (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
dcCore::app()->resources['help']['comListe'] = __DIR__ . '/help/comListe.html';
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* @brief The plugin locales resources
|
||||
* @ingroup comListe
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
\Dotclear\App::backend()->resources()->set('help', 'comListe', __DIR__ . '/help/comListe.html');
|
||||
dcCore::app()->resources['help']['comListe'] = __DIR__ . '/help/comListe.html';
|
||||
|
@ -1,23 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Backend\Favorites;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
/**
|
||||
* @brief comListe backend class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -34,7 +35,7 @@ class Backend extends Process
|
||||
// Admin menu
|
||||
My::addBackendMenuItem();
|
||||
|
||||
App::behavior()->addBehaviors([
|
||||
dcCore::app()->addBehaviors([
|
||||
// Dashboard favorites
|
||||
'adminDashboardFavoritesV2' => function (Favorites $favs): void {
|
||||
$favs->register(My::id(), [
|
||||
@ -42,7 +43,7 @@ class Backend extends Process
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]),
|
||||
]);
|
||||
},
|
||||
'adminSimpleMenuAddType' => function (ArrayObject $items): void {
|
||||
@ -52,10 +53,9 @@ class Backend extends Process
|
||||
if (My::id() == $type) {
|
||||
$item[0] = My::name();
|
||||
$item[1] = My::settings()->get('page_title') ?? My::name();
|
||||
$item[2] = Html::stripHostURL(App::blog()->url()) . App::url()->getURLFor(My::id());
|
||||
$item[2] = dcCore::app()->admin->__get('blog_url') . dcCore::app()->url->getURLFor(My::id());
|
||||
}
|
||||
},
|
||||
'initWidgets' => Widgets::initWidgets(...),
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
/**
|
||||
* @brief comListe frontend class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Frontend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -24,31 +26,39 @@ class Frontend extends Process
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status() || !My::settings()->get('enable')) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tpl = App::frontend()->template();
|
||||
if (!My::settings()->get('enable')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$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(...));
|
||||
dcCore::app()->tpl->addValue('ComListeURL', [Template::class,'comListeURL']);
|
||||
dcCore::app()->tpl->addValue('ComListePageTitle', [Template::class,'comListePageTitle']);
|
||||
dcCore::app()->tpl->addValue('ComListeNbComments', [Template::class,'comListeNbComments']);
|
||||
dcCore::app()->tpl->addValue('ComListeNbCommentsPerPage', [Template::class,'comListeNbCommentsPerPage']);
|
||||
dcCore::app()->tpl->addBlock('ComListeCommentsEntries', [Template::class,'comListeCommentsEntries']);
|
||||
dcCore::app()->tpl->addValue('ComListePaginationLinks', [Template::class,'comListePaginationLinks']);
|
||||
dcCore::app()->tpl->addValue('ComListeOpenPostTitle', [Template::class,'comListeOpenPostTitle']);
|
||||
dcCore::app()->tpl->addValue('ComListeCommentOrderNumber', [Template::class,'comListeCommentOrderNumber']);
|
||||
|
||||
$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(...));
|
||||
dcCore::app()->tpl->addBlock('ComListePagination', [Template::class,'comListePagination']);
|
||||
dcCore::app()->tpl->addValue('ComListePaginationCounter', [Template::class,'comListePaginationCounter']);
|
||||
dcCore::app()->tpl->addValue('ComListePaginationCurrent', [Template::class,'comListePaginationCurrent']);
|
||||
dcCore::app()->tpl->addBlock('ComListePaginationIf', [Template::class,'comListePaginationIf']);
|
||||
dcCore::app()->tpl->addValue('ComListePaginationURL', [Template::class,'comListePaginationURL']);
|
||||
|
||||
App::behavior()->addBehaviors([
|
||||
'publicBreadcrumb' => fn (string $context, string $separator) => $context == 'comListe' ? __('Comments list') : null,
|
||||
'initWidgets' => Widgets::initWidgets(...),
|
||||
]);
|
||||
dcCore::app()->addBehavior(
|
||||
'publicBreadcrumb',
|
||||
function (string $context, string $separator): ?string {
|
||||
if ($context == 'comListe') {
|
||||
return __('Comments list');
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,363 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
/**
|
||||
* @brief comListe frontend template class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class FrontendTemplate
|
||||
{
|
||||
public string $html_prev = '«prev.';
|
||||
public string $html_next = 'next»';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeNbCommentsPerPage(ArrayObject $attr): string
|
||||
{
|
||||
if (!App::blog()->isDefined()) {
|
||||
return '10';
|
||||
}
|
||||
App::frontend()->context()->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
return Html::escapeHTML((string) App::frontend()->context()->__get('nb_comment_per_page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* comListeNbComments.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeNbComments(ArrayObject$attr): string
|
||||
{
|
||||
if (!App::blog()->isDefined()) {
|
||||
return '0';
|
||||
}
|
||||
if (!App::frontend()->context()->exists('pagination')) {
|
||||
App::frontend()->context()->__set('pagination', App::blog()->getComments([], true));
|
||||
}
|
||||
$nb_comments = App::frontend()->context()->__get('pagination')->f(0);
|
||||
|
||||
return Html::escapeHTML((string) $nb_comments);
|
||||
}
|
||||
|
||||
/**
|
||||
* comListeCommentsEntries.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListeCommentsEntries(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$p = 'if (App::frontend()->context()->posts !== null) { ' .
|
||||
"\$params['post_id'] = App::frontend()->context()->posts->post_id; " .
|
||||
"App::blog()->withoutPassword(false);\n" .
|
||||
"}\n";
|
||||
|
||||
if (empty($attr['with_pings'])) {
|
||||
$p .= "\$params['comment_trackback'] = false;\n";
|
||||
}
|
||||
|
||||
$lastn = 0;
|
||||
if (isset($attr['lastn'])) {
|
||||
$lastn = abs((int) $attr['lastn']) + 0;
|
||||
}
|
||||
|
||||
if ($lastn > 0) {
|
||||
$p .= "\$params['limit'] = " . $lastn . ";\n";
|
||||
} else {
|
||||
$p .= "if (App::frontend()->context()->nb_comment_per_page !== null) { \$params['limit'] = App::frontend()->context()->nb_comment_per_page; }\n";
|
||||
}
|
||||
|
||||
$p .= "\$params['limit'] = array(((App::frontend()->getPageNumber()-1)*\$params['limit']),\$params['limit']);\n";
|
||||
|
||||
if (empty($attr['no_context'])) {
|
||||
$p .= 'if (App::frontend()->context()->exists("categories")) { ' .
|
||||
"\$params['cat_id'] = App::frontend()->context()->categories->cat_id; " .
|
||||
"}\n";
|
||||
|
||||
$p .= 'if (App::frontend()->context()->exists("langs")) { ' .
|
||||
"\$params['sql'] = \"AND P.post_lang = '\".App::con()->escapeStr((string) App::frontend()->context()->langs->post_lang).\"' \"; " .
|
||||
"}\n";
|
||||
}
|
||||
|
||||
// Sens de tri issu des paramètres du plugin
|
||||
$order = !App::blog()->isDefined() ? 'desc' : My::settings()->get('comments_order');
|
||||
if (isset($attr['order']) && preg_match('/^(desc|asc)$/i', $attr['order'])) {
|
||||
$order = $attr['order'];
|
||||
}
|
||||
|
||||
$p .= "\$params['order'] = 'comment_dt " . ($order ?? 'desc') . "';\n";
|
||||
|
||||
if (isset($attr['no_content']) && $attr['no_content']) {
|
||||
$p .= "\$params['no_content'] = true;\n";
|
||||
}
|
||||
|
||||
$res = "<?php\n";
|
||||
$res .= $p;
|
||||
$res .= 'App::frontend()->context()->comments_params = $params; ';
|
||||
$res .= 'App::frontend()->context()->comments = App::blog()->getComments($params); unset($params);' . "\n";
|
||||
$res .= "if (App::frontend()->context()->posts !== null) { App::blog()->withoutPassword(true);}\n";
|
||||
|
||||
if (!empty($attr['with_pings'])) {
|
||||
$res .= 'App::frontend()->context()->pings = App::frontend()->context()->comments;' . "\n";
|
||||
}
|
||||
|
||||
$res .= "?>\n";
|
||||
|
||||
$res .= '<?php while (App::frontend()->context()->comments->fetch()) : ?>' . $content . '<?php endwhile; App::frontend()->context()->pop("comments"); ?>';
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
function comListeMakePageLink($pageNumber, $linkText) {
|
||||
if ($pageNumber != App::frontend()->getPageNumber()) {
|
||||
$args = $_SERVER["URL_REQUEST_PART"];
|
||||
$args = preg_replace("#(^|/)page/([0-9]+)$#","",$args);
|
||||
$url = App::blog()->url().$args;
|
||||
|
||||
if ($pageNumber > 1) {
|
||||
$url = preg_replace("#/$#","",$url);
|
||||
$url .= "/page/".$pageNumber;
|
||||
}
|
||||
|
||||
if (!empty($_GET["q"])) {
|
||||
$s = strpos($url,"?") !== false ? "&" : "?";
|
||||
$url .= $s."q=".rawurlencode($_GET["q"]);
|
||||
}
|
||||
|
||||
return "<a href=\"".$url."\">".$linkText."</a> ";
|
||||
} else {
|
||||
return $linkText." ";
|
||||
}
|
||||
}
|
||||
|
||||
$current = App::frontend()->getPageNumber();
|
||||
|
||||
if(empty($params)) {
|
||||
App::frontend()->context()->pagination = App::blog()->getComments(null,true);
|
||||
} else {
|
||||
App::frontend()->context()->pagination = App::blog()->getComments($params,true);
|
||||
unset($params);
|
||||
}
|
||||
|
||||
if (App::frontend()->context()->exists("pagination")) {
|
||||
$nb_comments = App::frontend()->context()->pagination->f(0);
|
||||
}
|
||||
|
||||
$nb_per_page = abs((integer) App::blog()->settings->get("' . My::id() . '")->get("nb_comments_per_page"));
|
||||
$nb_pages = ceil($nb_comments/$nb_per_page);
|
||||
$nb_max_pages = 10;
|
||||
$nb_sequence = 2*3+1;
|
||||
$quick_distance = 10;
|
||||
|
||||
if($nb_pages <= $nb_max_pages) {
|
||||
/* less or equal than 10 pages, simple links */
|
||||
for ($i = 1; $i <= $nb_pages; $i++) {
|
||||
echo comListeMakePageLink($i,$i);
|
||||
}
|
||||
} else {
|
||||
/* more than 10 pages, smart links */
|
||||
echo comListeMakePageLink(1,1);
|
||||
$min_page = max($current - ($nb_sequence - 1) / 2, 2);
|
||||
$max_page = min($current + ($nb_sequence - 1) / 2, $nb_pages - 1);
|
||||
if ($min_page > 2) {
|
||||
echo "...";
|
||||
echo " ";
|
||||
}
|
||||
|
||||
for ($i = $min_page; $i <= $max_page ; $i++) {
|
||||
echo comListeMakePageLink($i,$i);
|
||||
}
|
||||
|
||||
if ($max_page < $nb_pages - 1) {
|
||||
echo "...";
|
||||
echo " ";
|
||||
}
|
||||
echo comListeMakePageLink($nb_pages,$nb_pages);
|
||||
|
||||
/* quick navigation links */
|
||||
if($current >= 1 + $quick_distance) {
|
||||
echo " ";
|
||||
echo comListeMakePageLink($current - $quick_distance, "<<");
|
||||
}
|
||||
|
||||
if($current <= $nb_pages - $quick_distance) {
|
||||
echo " ";
|
||||
echo comListeMakePageLink($current + $quick_distance, ">> ");
|
||||
}
|
||||
}
|
||||
?>';
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
'<?php echo ' .
|
||||
'App::frontend()->context()->comments->index() + 1 +' .
|
||||
'(App::frontend()->getPageNumber() - 1) * ' .
|
||||
'abs((integer) App::blog()->settings()->get("' . My::id() . '")->get("nb_comments_per_page"));' .
|
||||
'?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePagination.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePagination(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$params = "<?php\n" .
|
||||
'$params = App::frontend()->context()->comments_params;' . "\n" .
|
||||
App::behavior()->callBehavior(
|
||||
'templatePrepareParams',
|
||||
[
|
||||
'tag' => 'Pagination',
|
||||
'method' => 'comListe::getComments',
|
||||
],
|
||||
$attr,
|
||||
$content
|
||||
) .
|
||||
'App::frontend()->context()->pagination = App::blog()->getComments($params,true); unset($params);' . "\n" .
|
||||
"?>\n";
|
||||
|
||||
if (isset($attr['no_context']) && $attr['no_context']) {
|
||||
return $params . $content;
|
||||
}
|
||||
|
||||
return
|
||||
"<?php\n" .
|
||||
'$bakcup_old_nbpp = App::frontend()->context()->nb_entry_per_page; ' . "\n" .
|
||||
'App::frontend()->context()->nb_entry_per_page = abs((integer) App::blog()->settings()->get("' . My::id() . '")->get("nb_comments_per_page"));' . "\n" .
|
||||
"?>\n" .
|
||||
$params .
|
||||
'<?php if (App::frontend()->context()->pagination->f(0) > App::frontend()->context()->comments->count()) : ?>' .
|
||||
$content .
|
||||
"<?php endif;\n" .
|
||||
'App::frontend()->context()->nb_entry_per_page = $bakcup_old_nbpp; ' . "\n" .
|
||||
'?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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 = [];
|
||||
|
||||
if (isset($attr['start'])) {
|
||||
$sign = (bool) $attr['start'] ? '' : '!';
|
||||
$if[] = $sign . 'App::frontend()->context()::PaginationStart()';
|
||||
}
|
||||
|
||||
if (isset($attr['end'])) {
|
||||
$sign = (bool) $attr['end'] ? '' : '!';
|
||||
$if[] = $sign . 'App::frontend()->context()::PaginationEnd()';
|
||||
}
|
||||
|
||||
if (count($if)) {
|
||||
return '<?php if(' . implode(' && ', $if) . ') : ?>' . $content . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* comListePaginationURL.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*/
|
||||
public static function comListePaginationURL(ArrayObject $attr): string
|
||||
{
|
||||
$offset = 0;
|
||||
if (isset($attr['offset'])) {
|
||||
$offset = (int) $attr['offset'];
|
||||
}
|
||||
|
||||
return '<?php echo ' . sprintf(App::frontend()->template()->getFilters($attr), 'App::frontend()->context()::PaginationURL(' . $offset . ')') . '; ?>';
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Frontend\Url;
|
||||
|
||||
/**
|
||||
* @brief comListe frontend URL class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class FrontendUrl extends Url
|
||||
{
|
||||
public static function comListe(?string $args): void
|
||||
{
|
||||
$args = (string) $args;
|
||||
|
||||
if (!My::settings()->get('enable')) {
|
||||
self::p404();
|
||||
}
|
||||
|
||||
App::frontend()->setPageNumber(self::getPageNumber($args) ?: 1);
|
||||
App::frontend()->context()->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
$tplset = App::themes()->getDefine(App::blog()->settings()->get('system')->get('theme'))->get('tplset');
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @brief comListe install class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -29,6 +31,10 @@ class Install extends Process
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$s = My::settings();
|
||||
$s->put('enable', false, 'boolean', 'Enable comListe', false, true);
|
||||
@ -38,7 +44,7 @@ class Install extends Process
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
App::error()->add($e->getMessage());
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1,10 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
@ -26,14 +36,6 @@ use Dotclear\Helper\Html\Form\{
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @brief comListe manage class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Manage extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -47,7 +49,7 @@ class Manage extends Process
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!App::blog()->isDefined()) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -65,11 +67,11 @@ class Manage extends Process
|
||||
$s->put('nb_comments_per_page', $_POST['comliste_nb_comments_per_page'] ?? 10);
|
||||
$s->put('comments_order', $_POST['comliste_comments_order'] == 'asc' ? 'asc' : 'desc');
|
||||
|
||||
App::blog()->triggerBlog();
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
Notices::addSuccessNotice(__('Configuration successfully updated.'));
|
||||
My::redirect();
|
||||
} catch (Exception $e) {
|
||||
App::error()->add($e->getMessage());
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -81,7 +83,7 @@ class Manage extends Process
|
||||
return;
|
||||
}
|
||||
|
||||
if (!App::blog()->isDefined()) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -90,8 +92,8 @@ class Manage extends Process
|
||||
Page::openModule(My::name());
|
||||
|
||||
echo Page::breadcrumb([
|
||||
Html::escapeHTML(App::blog()->name()) => '',
|
||||
My::name() => '',
|
||||
Html::escapeHTML(dcCore::app()->blog->name) => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
Notices::getNotices() .
|
||||
|
||||
@ -107,7 +109,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)->maxlength(255)->value((string) $s->get('page_title')),
|
||||
(new Input('comliste_page_title'))->size(30)->maxlenght(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'),
|
||||
|
20
src/My.php
20
src/My.php
@ -1,5 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
@ -7,14 +17,8 @@ namespace Dotclear\Plugin\comListe;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* @brief comListe My helper.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* This module definitions.
|
||||
*/
|
||||
class My extends MyPlugin
|
||||
{
|
||||
// Use default permissions
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
/**
|
||||
* @brief comListe prepend class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Prepend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -28,11 +30,11 @@ class Prepend extends Process
|
||||
return false;
|
||||
}
|
||||
|
||||
App::url()->register(
|
||||
My::id(),
|
||||
dcCore::app()->url->register(
|
||||
'comListe',
|
||||
'comListe',
|
||||
'^comListe(?:/(.+))?$',
|
||||
FrontendUrl::comListe(...)
|
||||
[UrlHandler::class, 'comListe']
|
||||
);
|
||||
|
||||
return true;
|
||||
|
306
src/Template.php
Normal file
306
src/Template.php
Normal file
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use ArrayObject;
|
||||
use dcCore;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
class Template
|
||||
{
|
||||
public string $html_prev = '«prev.';
|
||||
public string $html_next = 'next»';
|
||||
|
||||
/* ComListeURL --------------------------------------- */
|
||||
public static function comListeURL(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("comListe")') . '; ?>';
|
||||
}
|
||||
|
||||
/* ComListePageTitle --------------------------------------- */
|
||||
public static function comListePageTitle(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->blog->settings->get("' . My::id() . '")->get("page_title")') . '; ?>';
|
||||
}
|
||||
|
||||
/* ComListeNbCommentsPerPage --------------------------------------- */
|
||||
public static function comListeNbCommentsPerPage(ArrayObject $attr): string
|
||||
{
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) {
|
||||
return '10';
|
||||
}
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
return Html::escapeHTML((string) dcCore::app()->ctx->__get('nb_comment_per_page'));
|
||||
}
|
||||
|
||||
/* comListeNbComments --------------------------------------- */
|
||||
public static function comListeNbComments(ArrayObject$attr): string
|
||||
{
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) {
|
||||
return '0';
|
||||
}
|
||||
if (!dcCore::app()->ctx->exists('pagination')) {
|
||||
dcCore::app()->ctx->__set('pagination', dcCore::app()->blog->getComments([], true));
|
||||
}
|
||||
$nb_comments = dcCore::app()->ctx->__get('pagination')->f(0);
|
||||
|
||||
return Html::escapeHTML((string) $nb_comments);
|
||||
}
|
||||
|
||||
/* ComListeCommentsEntries --------------------------------------- */
|
||||
public static function comListeCommentsEntries(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$p = 'if (dcCore::app()->ctx->posts !== null) { ' .
|
||||
"\$params['post_id'] = dcCore::app()->ctx->posts->post_id; " .
|
||||
"dcCore::app()->blog->withoutPassword(false);\n" .
|
||||
"}\n";
|
||||
|
||||
if (empty($attr['with_pings'])) {
|
||||
$p .= "\$params['comment_trackback'] = false;\n";
|
||||
}
|
||||
|
||||
$lastn = 0;
|
||||
if (isset($attr['lastn'])) {
|
||||
$lastn = abs((int) $attr['lastn']) + 0;
|
||||
}
|
||||
|
||||
if ($lastn > 0) {
|
||||
$p .= "\$params['limit'] = " . $lastn . ";\n";
|
||||
} else {
|
||||
$p .= "if (dcCore::app()->ctx->nb_comment_per_page !== null) { \$params['limit'] = dcCore::app()->ctx->nb_comment_per_page; }\n";
|
||||
}
|
||||
|
||||
$p .= "\$params['limit'] = array(((dcCore::app()->public->getPageNumber()-1)*\$params['limit']),\$params['limit']);\n";
|
||||
|
||||
if (empty($attr['no_context'])) {
|
||||
$p .= 'if (dcCore::app()->ctx->exists("categories")) { ' .
|
||||
"\$params['cat_id'] = dcCore::app()->ctx->categories->cat_id; " .
|
||||
"}\n";
|
||||
|
||||
$p .= 'if (dcCore::app()->ctx->exists("langs")) { ' .
|
||||
"\$params['sql'] = \"AND P.post_lang = '\".dcCore::app()->blog->con->escapeStr((string) dcCore::app()->langs->post_lang).\"' \"; " .
|
||||
"}\n";
|
||||
}
|
||||
|
||||
// Sens de tri issu des paramètres du plugin
|
||||
$order = is_null(dcCore::app()->blog) ? 'desc' : My::settings()->get('comments_order');
|
||||
if (isset($attr['order']) && preg_match('/^(desc|asc)$/i', $attr['order'])) {
|
||||
$order = $attr['order'];
|
||||
}
|
||||
|
||||
$p .= "\$params['order'] = 'comment_dt " . ($order ?? 'desc') . "';\n";
|
||||
|
||||
if (isset($attr['no_content']) && $attr['no_content']) {
|
||||
$p .= "\$params['no_content'] = true;\n";
|
||||
}
|
||||
|
||||
$res = "<?php\n";
|
||||
$res .= $p;
|
||||
$res .= 'dcCore::app()->ctx->comments_params = $params; ';
|
||||
$res .= 'dcCore::app()->ctx->comments = dcCore::app()->blog->getComments($params); unset($params);' . "\n";
|
||||
$res .= "if (dcCore::app()->ctx->posts !== null) { dcCore::app()->blog->withoutPassword(true);}\n";
|
||||
|
||||
if (!empty($attr['with_pings'])) {
|
||||
$res .= 'dcCore::app()->ctx->pings = dcCore::app()->ctx->comments;' . "\n";
|
||||
}
|
||||
|
||||
$res .= "?>\n";
|
||||
|
||||
$res .= '<?php while (dcCore::app()->ctx->comments->fetch()) : ?>' . $content . '<?php endwhile; dcCore::app()->ctx->pop("comments"); ?>';
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/* ComListePaginationLinks --------------------------------------- */
|
||||
/* Reprise et adaptation de la fonction PaginationLinks du plugin advancedPagination-1.9 */
|
||||
public static function comListePaginationLinks(ArrayObject $attr): string
|
||||
{
|
||||
$p = '<?php
|
||||
|
||||
function comListeMakePageLink($pageNumber, $linkText) {
|
||||
if ($pageNumber != dcCore::app()->public->getPageNumber()) {
|
||||
$args = $_SERVER["URL_REQUEST_PART"];
|
||||
$args = preg_replace("#(^|/)page/([0-9]+)$#","",$args);
|
||||
$url = dcCore::app()->blog->url.$args;
|
||||
|
||||
if ($pageNumber > 1) {
|
||||
$url = preg_replace("#/$#","",$url);
|
||||
$url .= "/page/".$pageNumber;
|
||||
}
|
||||
|
||||
if (!empty($_GET["q"])) {
|
||||
$s = strpos($url,"?") !== false ? "&" : "?";
|
||||
$url .= $s."q=".rawurlencode($_GET["q"]);
|
||||
}
|
||||
|
||||
return "<a href=\"".$url."\">".$linkText."</a> ";
|
||||
} else {
|
||||
return $linkText." ";
|
||||
}
|
||||
}
|
||||
|
||||
$current = dcCore::app()->public->getPageNumber();
|
||||
|
||||
if(empty($params)) {
|
||||
dcCore::app()->ctx->pagination = dcCore::app()->blog->getComments(null,true);
|
||||
} else {
|
||||
dcCore::app()->ctx->pagination = dcCore::app()->blog->getComments($params,true);
|
||||
unset($params);
|
||||
}
|
||||
|
||||
if (dcCore::app()->ctx->exists("pagination")) {
|
||||
$nb_comments = dcCore::app()->ctx->pagination->f(0);
|
||||
}
|
||||
|
||||
$nb_per_page = abs((integer) dcCore::app()->blog->settings->get("' . My::id() . '")->get("nb_comments_per_page"));
|
||||
$nb_pages = ceil($nb_comments/$nb_per_page);
|
||||
$nb_max_pages = 10;
|
||||
$nb_sequence = 2*3+1;
|
||||
$quick_distance = 10;
|
||||
|
||||
if($nb_pages <= $nb_max_pages) {
|
||||
/* less or equal than 10 pages, simple links */
|
||||
for ($i = 1; $i <= $nb_pages; $i++) {
|
||||
echo comListeMakePageLink($i,$i);
|
||||
}
|
||||
} else {
|
||||
/* more than 10 pages, smart links */
|
||||
echo comListeMakePageLink(1,1);
|
||||
$min_page = max($current - ($nb_sequence - 1) / 2, 2);
|
||||
$max_page = min($current + ($nb_sequence - 1) / 2, $nb_pages - 1);
|
||||
if ($min_page > 2) {
|
||||
echo "...";
|
||||
echo " ";
|
||||
}
|
||||
|
||||
for ($i = $min_page; $i <= $max_page ; $i++) {
|
||||
echo comListeMakePageLink($i,$i);
|
||||
}
|
||||
|
||||
if ($max_page < $nb_pages - 1) {
|
||||
echo "...";
|
||||
echo " ";
|
||||
}
|
||||
echo comListeMakePageLink($nb_pages,$nb_pages);
|
||||
|
||||
/* quick navigation links */
|
||||
if($current >= 1 + $quick_distance) {
|
||||
echo " ";
|
||||
echo comListeMakePageLink($current - $quick_distance, "<<");
|
||||
}
|
||||
|
||||
if($current <= $nb_pages - $quick_distance) {
|
||||
echo " ";
|
||||
echo comListeMakePageLink($current + $quick_distance, ">> ");
|
||||
}
|
||||
}
|
||||
?>';
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
/* ComListeOpenPostTitle --------------------------------------- */
|
||||
public static function comListeOpenPostTitle(ArrayObject $attr): string
|
||||
{
|
||||
return __('open post');
|
||||
}
|
||||
|
||||
public static function comListeCommentOrderNumber(ArrayObject $attr): string
|
||||
{
|
||||
return
|
||||
'<?php echo ' .
|
||||
'dcCore::app()->ctx->comments->index() + 1 +' .
|
||||
'(dcCore::app()->public->getPageNumber() - 1) * ' .
|
||||
'abs((integer) dcCore::app()->blog->settings->get("' . My::id() . '")->get("nb_comments_per_page"));' .
|
||||
'?>';
|
||||
}
|
||||
|
||||
public static function comListePagination(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$params = "<?php\n" .
|
||||
'$params = dcCore::app()->ctx->comments_params;' . "\n" .
|
||||
dcCore::app()->callBehavior(
|
||||
'templatePrepareParams',
|
||||
[
|
||||
'tag' => 'Pagination',
|
||||
'method' => 'comListe::getComments',
|
||||
],
|
||||
$attr,
|
||||
$content
|
||||
) .
|
||||
'dcCore::app()->ctx->pagination = dcCore::app()->blog->getComments($params,true); unset($params);' . "\n" .
|
||||
"?>\n";
|
||||
|
||||
if (isset($attr['no_context']) && $attr['no_context']) {
|
||||
return $params . $content;
|
||||
}
|
||||
|
||||
return
|
||||
"<?php\n" .
|
||||
'$bakcup_old_nbpp = dcCore::app()->ctx->nb_entry_per_page; ' . "\n" .
|
||||
'dcCore::app()->ctx->nb_entry_per_page = abs((integer) dcCore::app()->blog->settings->get("' . My::id() . '")->get("nb_comments_per_page"));' . "\n" .
|
||||
"?>\n" .
|
||||
$params .
|
||||
'<?php if (dcCore::app()->ctx->pagination->f(0) > dcCore::app()->ctx->comments->count()) : ?>' .
|
||||
$content .
|
||||
"<?php endif;\n" .
|
||||
'dcCore::app()->ctx->nb_entry_per_page = $bakcup_old_nbpp; ' . "\n" .
|
||||
'?>';
|
||||
}
|
||||
|
||||
public static function comListePaginationCounter(ArrayObject $attr): string
|
||||
{
|
||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx::PaginationNbPages()') . '; ?>';
|
||||
}
|
||||
|
||||
public static function comListePaginationCurrent(ArrayObject $attr): string
|
||||
{
|
||||
$offset = isset($attr['offset']) ? (int) $attr['offset'] : 0;
|
||||
|
||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx::PaginationPosition(' . $offset . ')') . '; ?>';
|
||||
}
|
||||
|
||||
public static function comListePaginationIf(ArrayObject $attr, string $content): string
|
||||
{
|
||||
$if = [];
|
||||
|
||||
if (isset($attr['start'])) {
|
||||
$sign = (bool) $attr['start'] ? '' : '!';
|
||||
$if[] = $sign . 'dcCore::app()->ctx::PaginationStart()';
|
||||
}
|
||||
|
||||
if (isset($attr['end'])) {
|
||||
$sign = (bool) $attr['end'] ? '' : '!';
|
||||
$if[] = $sign . 'dcCore::app()->ctx::PaginationEnd()';
|
||||
}
|
||||
|
||||
if (count($if)) {
|
||||
return '<?php if(' . implode(' && ', $if) . ') : ?>' . $content . '<?php endif; ?>';
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public static function comListePaginationURL(ArrayObject $attr): string
|
||||
{
|
||||
$offset = 0;
|
||||
if (isset($attr['offset'])) {
|
||||
$offset = (int) $attr['offset'];
|
||||
}
|
||||
|
||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx::PaginationURL(' . $offset . ')') . '; ?>';
|
||||
}
|
||||
}
|
@ -1,20 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
/**
|
||||
* @brief comListe uninstall class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -24,11 +27,16 @@ class Uninstall extends Process
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Uninstaller::instance()
|
||||
->addUserAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
@ -39,6 +47,11 @@ class Uninstall extends Process
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
|
46
src/UrlHandler.php
Normal file
46
src/UrlHandler.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcUrlHandlers;
|
||||
|
||||
class UrlHandler extends dcUrlHandlers
|
||||
{
|
||||
public static function comListe(?string $args): void
|
||||
{
|
||||
$args = (string) $args;
|
||||
|
||||
if (is_null(dcCore::app()->blog)
|
||||
|| is_null(dcCore::app()->ctx)
|
||||
|| !My::settings()->get('enable')
|
||||
) {
|
||||
self::p404();
|
||||
}
|
||||
|
||||
dcCore::app()->public->setPageNumber(self::getPageNumber($args) ?: 1);
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset');
|
||||
if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) {
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]));
|
||||
} else {
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', DC_DEFAULT_TPLSET]));
|
||||
}
|
||||
|
||||
self::serveDocument('comListe.html');
|
||||
exit;
|
||||
}
|
||||
}
|
@ -1,22 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief comListe, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Benoit de Marne, Pierre Van Glabeke and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use Dotclear\App;
|
||||
use dcCore;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
|
||||
/**
|
||||
* @brief comListe widgets class.
|
||||
* @ingroup comListe
|
||||
*
|
||||
* @author Benoit de Marne (author)
|
||||
* @author Jean-Christian Denis (latest)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Widgets
|
||||
{
|
||||
public static function initWidgets(WidgetsStack $w): void
|
||||
@ -24,7 +26,7 @@ class Widgets
|
||||
$w->create(
|
||||
My::id(),
|
||||
My::name(),
|
||||
self::parseWidget(...),
|
||||
[self::class, 'parseWidget'],
|
||||
null,
|
||||
__('Link to comments list public page')
|
||||
)
|
||||
@ -42,22 +44,23 @@ class Widgets
|
||||
|
||||
public static function parseWidget(WidgetsElement $w): string
|
||||
{
|
||||
if ($w->get('offline')
|
||||
|| !$w->checkHomeOnly(App::url()->type)
|
||||
if (is_null(dcCore::app()->blog)
|
||||
|| $w->__get('offline')
|
||||
|| !$w->checkHomeOnly(dcCore::app()->url->type)
|
||||
|| !My::settings()->get('enable')
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
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())
|
||||
dcCore::app()->blog->url . dcCore::app()->url->getBase('comListe'),
|
||||
$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