commit
acbbad2f80
2 changed files with 34 additions and 15 deletions
|
@ -178,13 +178,16 @@ class CommentList extends Extension {
|
|||
$this->build_page($page_num);
|
||||
}
|
||||
else if($event->get_arg(0) === "beta-search") {
|
||||
$i_comment_count = Comment::count_comments_by_user($user);
|
||||
$com_per_page = 50;
|
||||
$total_pages = ceil($i_comment_count/$com_per_page);
|
||||
$search = $event->get_arg(1);
|
||||
$page_num = int_escape($event->get_arg(2));
|
||||
|
||||
$page_num = $this->sanity_check_pagenumber($page_num, $total_pages);
|
||||
$duser = User::by_name($search);
|
||||
|
||||
$comments = $this->get_user_comments($duser->id, 50, ($page_num-1) * 50);
|
||||
$this->theme->display_all_user_comments($comments, $page_num, 10);
|
||||
$comments = $this->get_user_comments($duser->id, $com_per_page, ($page_num-1) * $com_per_page);
|
||||
$this->theme->display_all_user_comments($comments, $page_num, $total_pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,11 +292,11 @@ class CommentList extends Extension {
|
|||
if(class_exists("Ratings")) {
|
||||
$user_ratings = Ratings::get_user_privs($user);
|
||||
}
|
||||
|
||||
$total_pages = $database->cache->get("comment_pages");
|
||||
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);
|
||||
|
||||
|
@ -307,7 +310,6 @@ class CommentList extends Extension {
|
|||
";
|
||||
$result = $database->Execute($get_threads, array("limit"=>$threads_per_page, "offset"=>$start));
|
||||
|
||||
$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);
|
||||
|
@ -474,7 +476,19 @@ class CommentList extends Extension {
|
|||
global $database;
|
||||
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){
|
||||
if (!is_numeric($pagenum)){
|
||||
$pagenum=1;
|
||||
}
|
||||
if ($pagenum>$maxpage){
|
||||
$pagenum=$maxpage;
|
||||
}
|
||||
if ($pagenum<=0){
|
||||
$pagenum=1;
|
||||
}
|
||||
return $pagenum;
|
||||
}
|
||||
private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) {
|
||||
global $database;
|
||||
global $config;
|
||||
|
|
|
@ -36,7 +36,7 @@ class CommentListTheme extends Themelet {
|
|||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" :
|
||||
'<a href="'.make_link('comment/list/'.$prev).'">Prev</a>';
|
||||
$h_index = "<a href='".make_link("comment/list")."'>Index</a>";
|
||||
$h_index = "<a href='".make_link("post/list")."'>Index</a>";
|
||||
$h_next = ($page_number >= $total_pages) ? "Next" :
|
||||
'<a href="'.make_link('comment/list/'.$next).'">Next</a>';
|
||||
|
||||
|
@ -171,7 +171,11 @@ class CommentListTheme extends Themelet {
|
|||
}
|
||||
|
||||
public function display_all_user_comments($comments, $page_number, $total_pages) {
|
||||
global $page;
|
||||
global $page, $user;
|
||||
|
||||
assert(is_numeric($page_number));
|
||||
assert(is_numeric($total_pages));
|
||||
|
||||
$html = "";
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment, true);
|
||||
|
@ -184,19 +188,20 @@ class CommentListTheme extends Themelet {
|
|||
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
$u_tags = url_escape(implode(" ", $search_terms));
|
||||
$query = empty($u_tags) ? "" : '/'.$u_tags;
|
||||
|
||||
//$search_terms = array('I','have','no','idea','what','this','does!');
|
||||
//$u_tags = url_escape(implode(" ", $search_terms));
|
||||
//$query = empty($u_tags) ? "" : '/'.$u_tags;
|
||||
|
||||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" : "<a href='$prev'>Prev</a>";
|
||||
$h_index = "<a href='".make_link("post/list")."'>Index</a>";
|
||||
$h_next = ($page_number >= $total_pages) ? "Next" : "<a href='$next'>Next</a>";
|
||||
|
||||
$page->add_block(new Block("Navigation", $h_prev.' | '.$h_next, "left", 0));
|
||||
$page->add_block(new Block("Navigation", $h_prev.' | '.$h_index.' | '.$h_next, "left", 0));
|
||||
$this->display_paginator($page, 'comment/beta-search/'.$user->name, null, $page_number, $total_pages);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
global $config, $user;
|
||||
|
||||
|
|
Reference in a new issue