From 112130b8ad191c12d41dc02c43211f6f9697007e Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 15 Oct 2012 21:48:55 +0100 Subject: [PATCH] the start of full per-user comment history --- ext/comment/main.php | 19 ++++++++++++++----- ext/comment/theme.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index f9cdac35..d287e5c9 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -177,6 +177,15 @@ class CommentList extends Extension { $page_num = int_escape($event->get_arg(1)); $this->build_page($page_num); } + else if($event->get_arg(0) === "beta-search") { + $search = $event->get_arg(1); + $page_num = int_escape($event->get_arg(2)); + + $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); + } } } @@ -205,8 +214,8 @@ class CommentList extends Extension { $h_comment_rate = sprintf("%.1f", ($i_comment_count / $i_days_old)); $event->add_stats("Comments made: $i_comment_count, $h_comment_rate per day"); - $recent = $this->get_user_recent_comments($event->display_user->id, 10); - $this->theme->display_user_comments($recent); + $recent = $this->get_user_comments($event->display_user->id, 10); + $this->theme->display_recent_user_comments($recent, $event->display_user); } public function onDisplayingImage(DisplayingImageEvent $event) { @@ -341,7 +350,7 @@ class CommentList extends Extension { return $comments; } - private function get_user_recent_comments(/*int*/ $user_id, /*int*/ $count) { + private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { global $config; global $database; $rows = $database->get_all(" @@ -354,8 +363,8 @@ class CommentList extends Extension { LEFT JOIN users ON comments.owner_id=users.id WHERE users.id = :user_id ORDER BY comments.id DESC - LIMIT :limit - ", array("user_id"=>$user_id, "limit"=>$count)); + OFFSET :offset LIMIT :limit + ", array("user_id"=>$user_id, "offset"=>$offset, "limit"=>$count)); $comments = array(); foreach($rows as $row) { $comments[] = new Comment($row); diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 4fa676c9..7a4173da 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -155,7 +155,7 @@ class CommentListTheme extends Themelet { /** * Show comments made by a user */ - public function display_user_comments($comments) { + public function display_recent_user_comments($comments, $user) { global $page; $html = ""; foreach($comments as $comment) { @@ -164,9 +164,38 @@ class CommentListTheme extends Themelet { if(empty($html)) { $html = '

No comments by this user.

'; } + else { + $html .= "

More

"; + } $page->add_block(new Block("Comments", $html, "left", 70, "comment-list-user")); } + public function display_all_user_comments($comments, $page_number, $total_pages) { + global $page; + $html = ""; + foreach($comments as $comment) { + $html .= $this->comment_to_html($comment, true); + } + if(empty($html)) { + $html = '

No comments by this user.

'; + } + $page->add_block(new Block("Comments", $html, "main", 70, "comment-list-user")); + + + $prev = $page_number - 1; + $next = $page_number + 1; + + $u_tags = url_escape(implode(" ", $search_terms)); + $query = empty($u_tags) ? "" : '/'.$u_tags; + + + $h_prev = ($page_number <= 1) ? "Prev" : "Prev"; + $h_next = ($page_number >= $total_pages) ? "Next" : "Next"; + + $page->add_block(new Block("Navigation", $h_prev.' | '.$h_next, "left", 0)); + } + + protected function comment_to_html($comment, $trim=false) { global $config, $user;