From a7ab12abddd9fc86f6c789d8f01931f741b6fdb0 Mon Sep 17 00:00:00 2001 From: jgen Date: Tue, 3 Dec 2013 14:39:12 -0500 Subject: [PATCH] Fix for issue 346 - "Only first page of comments is shown" --- ext/comment/main.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 1cc05c2a..22bf4551 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -292,11 +292,18 @@ class CommentList extends Extension { if(class_exists("Ratings")) { $user_ratings = Ratings::get_user_privs($user); } + $total_pages = $database->cache->get("comment_pages"); + if(empty($total_pages)) { + $total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments $where GROUP BY image_id) AS s1") / 10); + $database->cache->set("comment_pages", $total_pages, 600); + } + if(is_null($current_page) || $current_page <= 0) { $current_page = 1; } $current_page = $this->sanity_check_pagenumber($current_page, $total_pages); + $threads_per_page = 10; $start = $threads_per_page * ($current_page - 1); @@ -310,11 +317,6 @@ class CommentList extends Extension { "; $result = $database->Execute($get_threads, array("limit"=>$threads_per_page, "offset"=>$start)); - if(empty($total_pages)) { - $total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments $where GROUP BY image_id) AS s1") / 10); - $database->cache->set("comment_pages", $total_pages, 600); - } - $images = array(); while($row = $result->fetch()) { $image = Image::by_id($row["image_id"]); @@ -330,6 +332,7 @@ class CommentList extends Extension { $this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment")); } // }}} + // get comments {{{ private function get_recent_comments($count) { global $config; @@ -396,6 +399,7 @@ class CommentList extends Extension { return $comments; } // }}} + // add / remove / edit comments {{{ private function is_comment_limit_hit() { global $user; @@ -477,7 +481,7 @@ class CommentList extends Extension { return ($database->get_row("SELECT * FROM comments WHERE image_id=:image_id AND comment=:comment", array("image_id"=>$image_id, "comment"=>$comment))); } // do some checks - private function sanity_check_pagenumber($pagenum, $maxpage){ + private function sanity_check_pagenumber(/*int*/ $pagenum, /*int*/ $maxpage){ if (!is_numeric($pagenum)){ $pagenum=1; }