From ba09e9a8651d3531786cf538773d9bbe25f342e9 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 18 Oct 2015 11:12:28 +0200 Subject: [PATCH] Show the recently commented pages --- admin/templates/comments.html.twig | 44 ++++++++++++++---------------- comments.php | 22 +++++++++++++++ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/admin/templates/comments.html.twig b/admin/templates/comments.html.twig index f5fcc04..6fea510 100644 --- a/admin/templates/comments.html.twig +++ b/admin/templates/comments.html.twig @@ -105,32 +105,28 @@

Showing {{grav.twig.comments.totalRetrieved}} comments of {{grav.twig.comments.totalAvailable}}

-

Recently commented pages

+ {% if grav.twig.pages %} +

Recently commented pages

-
- - - - - - - - {% for page in grav.twig.pages %} - - - - +
+
PageNumber of commentsLast commented on
{{page.title}}{{page.commentsCount}}Page: {{page.lastCommentDate}}
+ + + + + - {% endfor %} - -
PageNumber of commentsLast commented on
- - {% if grav.twig.comments.totalRetrieved < grav.twig.comments.totalAvailable %} - - {% endif %} -
+ {% for page in grav.twig.pages %} + + {{page.title}} + {{page.commentsCount}} + {{page.lastCommentDate}} + + {% endfor %} + + + + {% endif %} {% endblock %} diff --git a/comments.php b/comments.php index 2e64f53..80d32b2 100644 --- a/comments.php +++ b/comments.php @@ -129,6 +129,7 @@ class CommentsPlugin extends Plugin } $this->grav['twig']->comments = $comments; + $this->grav['twig']->pages = $this->fetchPages(); } } @@ -295,6 +296,27 @@ class CommentsPlugin extends Plugin return $this->getDataFromFilename($filename)['comments']; } + /** + * Return the latest commented pages + */ + private function fetchPages() { + $files = []; + $files = $this->getFilesOrderedByModifiedDate(); + + $pages = []; + + foreach($files as $file) { + $pages[] = [ + 'title' => $file->data['title'], + 'commentsCount' => count($file->data['comments']), + 'lastCommentDate' => gmdate('D, d M Y H:i:s', $file->modifiedDate) + ]; + } + + return $pages; + } + + /** * Given a data file route, return the YAML content already parsed */