Fix for issue 346 - "Only first page of comments is shown"
This commit is contained in:
		
							parent
							
								
									6dc345085f
								
							
						
					
					
						commit
						a7ab12abdd
					
				| @ -292,11 +292,18 @@ class CommentList extends Extension { | |||||||
| 		if(class_exists("Ratings")) { | 		if(class_exists("Ratings")) { | ||||||
| 			$user_ratings = Ratings::get_user_privs($user); | 			$user_ratings = Ratings::get_user_privs($user); | ||||||
| 		} | 		} | ||||||
|  | 		 | ||||||
| 		$total_pages = $database->cache->get("comment_pages"); | 		$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) { | 		if(is_null($current_page) || $current_page <= 0) { | ||||||
| 			$current_page = 1; | 			$current_page = 1; | ||||||
| 		} | 		} | ||||||
| 		$current_page = $this->sanity_check_pagenumber($current_page, $total_pages); | 		$current_page = $this->sanity_check_pagenumber($current_page, $total_pages); | ||||||
|  | 		 | ||||||
| 		$threads_per_page = 10; | 		$threads_per_page = 10; | ||||||
| 		$start = $threads_per_page * ($current_page - 1); | 		$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)); | 		$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(); | 		$images = array(); | ||||||
| 		while($row = $result->fetch()) { | 		while($row = $result->fetch()) { | ||||||
| 			$image = Image::by_id($row["image_id"]); | 			$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")); | 		$this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment")); | ||||||
| 	} | 	} | ||||||
| // }}}
 | // }}}
 | ||||||
|  | 
 | ||||||
| // get comments {{{
 | // get comments {{{
 | ||||||
| 	private function get_recent_comments($count) { | 	private function get_recent_comments($count) { | ||||||
| 		global $config; | 		global $config; | ||||||
| @ -396,6 +399,7 @@ class CommentList extends Extension { | |||||||
| 		return $comments; | 		return $comments; | ||||||
| 	} | 	} | ||||||
| // }}}
 | // }}}
 | ||||||
|  | 
 | ||||||
| // add / remove / edit comments {{{
 | // add / remove / edit comments {{{
 | ||||||
| 	private function is_comment_limit_hit() { | 	private function is_comment_limit_hit() { | ||||||
| 		global $user; | 		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))); | 		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
 | // do some checks
 | ||||||
| 	private function sanity_check_pagenumber($pagenum, $maxpage){ | 	private function sanity_check_pagenumber(/*int*/ $pagenum, /*int*/ $maxpage){ | ||||||
| 		if (!is_numeric($pagenum)){ | 		if (!is_numeric($pagenum)){ | ||||||
| 			$pagenum=1; | 			$pagenum=1; | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user