From a9b387ae81199968407bbccf20f42d8eae3379a2 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 5 Jan 2023 00:31:20 +0100 Subject: [PATCH] add dotclear style pagination --- _public.php | 92 +++++++++++++++++++++++++-- default-templates/dotty/comListe.html | 35 +++++++--- 2 files changed, 113 insertions(+), 14 deletions(-) diff --git a/_public.php b/_public.php index ecad548..4619e2f 100644 --- a/_public.php +++ b/_public.php @@ -28,6 +28,12 @@ dcCore::app()->tpl->addBlock('ComListeCommentsEntries', ['tplComListe','comListe dcCore::app()->tpl->addValue('ComListePaginationLinks', ['tplComListe','comListePaginationLinks']); dcCore::app()->tpl->addValue('ComListeOpenPostTitle', ['tplComListe','comListeOpenPostTitle']); +dcCore::app()->tpl->addBlock('ComListePagination', ['tplComListe','comListePagination']); +dcCore::app()->tpl->addValue('ComListePaginationCounter', ['tplComListe','comListePaginationCounter']); +dcCore::app()->tpl->addValue('ComListePaginationCurrent', ['tplComListe','comListePaginationCurrent']); +dcCore::app()->tpl->addBlock('ComListePaginationIf', ['tplComListe','comListePaginationIf']); +dcCore::app()->tpl->addValue('ComListePaginationURL', ['tplComListe','comListePaginationURL']); + dcCore::app()->addBehaviors([ 'publicBreadcrumb' => function ($context, $separator) { if ($context == 'comListe') { @@ -44,17 +50,13 @@ class tplComListe /* ComListeURL --------------------------------------- */ public static function comListeURL($attr) { - $f = dcCore::app()->tpl->getFilters($attr); - - return 'blog->url.dcCore::app()->url->getBase("comListe")') . '; ?>'; + return 'tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("comListe")') . '; ?>'; } /* ComListePageTitle --------------------------------------- */ public static function comListePageTitle($attr) { - $f = dcCore::app()->tpl->getFilters($attr); - - return 'blog->settings->get("' . basename(__DIR__) . '")->get("page_title")') . '; ?>'; + return 'tpl->getFilters($attr), 'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("page_title")') . '; ?>'; } /* ComListeNbCommentsPerPage --------------------------------------- */ @@ -125,6 +127,7 @@ class tplComListe $res = "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"; @@ -232,4 +235,81 @@ class tplComListe { return __('open post'); } + + public static function comListePagination(ArrayObject $attr, string $content): string + { + $params = "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 + "ctx->nb_entry_per_page; ' . "\n" . + 'dcCore::app()->ctx->nb_entry_per_page = abs((integer) dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("nb_comments_per_page"));' . "\n" . + "?>\n" . + $params . + 'ctx->pagination->f(0) > dcCore::app()->ctx->comments->count()) : ?>' . + $content . + "ctx->nb_entry_per_page = $bakcup_old_nbpp; ' . "\n" . + '?>'; + + } + + public static function comListePaginationCounter(ArrayObject $attr): string + { + return 'tpl->getFilters($attr), 'context::PaginationNbPages()') . '; ?>'; + } + + public static function comListePaginationCurrent(ArrayObject $attr): string + { + $offset = isset($attr['offset']) ? (int) $attr['offset'] : 0; + + return 'tpl->getFilters($attr), 'context::PaginationPosition(' . $offset . ')') . '; ?>'; + } + + public static function comListePaginationIf(ArrayObject $attr, string $content): string + { + $if = []; + + if (isset($attr['start'])) { + $sign = (bool) $attr['start'] ? '' : '!'; + $if[] = $sign . 'context::PaginationStart()'; + } + + if (isset($attr['end'])) { + $sign = (bool) $attr['end'] ? '' : '!'; + $if[] = $sign . 'context::PaginationEnd()'; + } + + if (count($if)) { + return '' . $content . ''; + } + + return $content; + } + + public static function comListePaginationURL(ArrayObject $attr): string + { + $offset = 0; + if (isset($attr['offset'])) { + $offset = (int) $attr['offset']; + } + + return 'tpl->getFilters($attr), 'context::PaginationURL(' . $offset . ')') . '; ?>'; + } } diff --git a/default-templates/dotty/comListe.html b/default-templates/dotty/comListe.html index b826a14..07b2af1 100644 --- a/default-templates/dotty/comListe.html +++ b/default-templates/dotty/comListe.html @@ -17,6 +17,12 @@

{{tpl:ComListePageTitle encode_html="1"}}

+ + +
@@ -42,17 +48,30 @@
+ + + + + + + -

- {{tpl:lang Pages:}} {{tpl:ComListePaginationLinks}} -

- -
\ No newline at end of file