From 7d7dbd16449147f3cba0d859021cb0dd828e1a8f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 16 Oct 2015 14:59:22 +0200 Subject: [PATCH] Order comments by timestamp in admin --- comments.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/comments.php b/comments.php index 6a7016a..2e64f53 100644 --- a/comments.php +++ b/comments.php @@ -245,21 +245,22 @@ class CommentsPlugin extends Plugin $files = []; $files = $this->getFilesOrderedByModifiedDate(); - $comments = []; foreach($files as $file) { $data = Yaml::parse(file_get_contents($file->filePath)); + for ($i = 0; $i < count($data['comments']); $i++) { - $commentDate = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp(); + $commentTimestamp = \DateTime::createFromFormat('D, d M Y H:i:s', $data['comments'][$i]['date'])->getTimestamp(); $sevenDaysAgo = time() - (7 * 24 * 60 * 60); - if ($commentDate < $sevenDaysAgo) { + if ($commentTimestamp < $sevenDaysAgo) { continue; } $data['comments'][$i]['pageTitle'] = $data['title']; $data['comments'][$i]['filePath'] = $file->filePath; + $data['comments'][$i]['timestamp'] = $commentTimestamp; } if (count($data['comments'])) { $comments = array_merge($comments, $data['comments']); @@ -268,7 +269,7 @@ class CommentsPlugin extends Plugin // Order comments by date usort($comments, function($a, $b) { - return !($a['date'] > $b['date']); + return !($a['timestamp'] > $b['timestamp']); }); $totalAvailable = count($comments);