diff --git a/ext/comment/main.php b/ext/comment/main.php index 44a8505f..70b54224 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -84,7 +84,7 @@ class CommentList extends Extension { } } else { - // FIXME: denied message + $this->theme->display_error($event->page, "Denied", "Only admins can delete comments"); } } else if($event->get_arg(0) == "list") { @@ -94,21 +94,18 @@ class CommentList extends Extension { if(is_a($event, 'PostListBuildingEvent')) { global $config; - if($config->get_int("comment_count") > 0) { - $event->page->add_block(new Block("Comments", $this->build_recent_comments(), "left")); + $cc = $config->get_int("comment_count"); + if($cc > 0) { + $this->theme->display_recent_comments($event->page, $this->get_recent_comments($cc)); } } if(is_a($event, 'DisplayingImageEvent')) { - if($this->can_comment()) { - $event->page->add_block(new Block("Comments", - $this->build_image_comments($event->image->id). - $this->theme->build_postbox($event->image->id), "main", 30)); - } - else { - $event->page->add_block(new Block("Comments", - $this->build_image_comments($event->image->id), "main", 30)); - } + $this->theme->display_comments( + $event->page, + $this->get_comments($event->image->id), + $this->can_comment(), + $event->image->id); } if(is_a($event, 'ImageDeletionEvent')) { @@ -180,34 +177,18 @@ class CommentList extends Extension { $n = 10; while(!$result->EOF) { $image = $database->get_image($result->fields["image_id"]); - $comments = $this->build_image_comments($image->id); + $comments = $this->get_comments($image->id); $this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment()); $n += 1; $result->MoveNext(); } } - - private function build_image_comments($image_id) { +// }}} +// get comments {{{ + private function get_recent_comments() { global $config; - $i_image_id = int_escape($image_id); - $html = "
Full List"; - return $html; - } - - private function query_to_html($query, $args, $trim=false) { - global $database; - global $config; - - $html = ""; - $result = $database->Execute($query, $args); - while(!$result->EOF) { - $comment = new Comment($result->fields); - $html .= $comment->to_html($trim); - $result->MoveNext(); + ", array($config->get_int('comment_count'))); + $comments = array(); + foreach($rows as $row) { + $comments[] = new Comment($row); } - return $html; + return $comments; + } + + private function get_comments($image_id) { + global $config; + global $database; + $i_image_id = int_escape($image_id); + $rows = $database->db->GetAll(" + SELECT + users.id as user_id, users.name as user_name, + comments.comment as comment, comments.id as comment_id, + comments.image_id as image_id, comments.owner_ip as poster_ip + FROM comments + LEFT JOIN users ON comments.owner_id=users.id + WHERE comments.image_id=? + ORDER BY comments.id ASC + ", array($i_image_id)); + $comments = array(); + foreach($rows as $row) { + $comments[] = new Comment($row); + } + return $comments; } // }}} // add / remove / edit comments {{{ @@ -294,22 +285,19 @@ class CommentList extends Extension { global $config; global $page; - $page->set_title("Error"); - $page->set_heading("Error"); - $page->add_block(new NavBlock()); if(!$config->get_bool('comment_anon') && $user->is_anonymous()) { - $page->add_main_block(new Block("Permission Denied", "Anonymous posting has been disabled")); + $this->theme->display_error($page, "Permission Denied", "Anonymous posting has been disabled"); } else if(trim($comment) == "") { - $page->add_main_block(new Block("Comment Empty", "Comments need text...")); + $this->theme->display_error($page, "Comment Empty", "Comments need text..."); } else if($this->is_comment_limit_hit()) { - $page->add_main_block(new Block("Comment Limit Hit", - "You've posted several comments recently; wait a minute and try again...")); + $this->theme->display_error($page, "Comment Limit Hit", + "You've posted several comments recently; wait a minute and try again..."); } else if($this->is_spam($comment)) { - $page->add_main_block(new Block("Spam Detected", - "Akismet thinks that your comment is spam. Try rewriting the comment?")); + $this->theme->display_error($page, "Spam Detected", + "Akismet thinks that your comment is spam. Try rewriting the comment?"); } else { $database->Execute( diff --git a/ext/comment/theme.php b/ext/comment/theme.php index cb99aaec..0f71a405 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -1,14 +1,7 @@ set_title("Comments"); - $page->set_heading("Comments"); - $page->add_block(new Block("Navigation", $this->build_navigation($current_page, $total_pages), "left")); - $page->add_block(new Paginator("comment/list", null, $current_page, $total_pages), 90); - } - - private function build_navigation($page_number, $total_pages) { + public function display_page_start($page, $page_number, $total_pages) { $prev = $page_number - 1; $next = $page_number + 1; @@ -18,7 +11,39 @@ class CommentListTheme extends Themelet { $h_next = ($page_number >= $total_pages) ? "Next" : "Next"; - return "$h_prev | $h_index | $h_next"; + $nav = "$h_prev | $h_index | $h_next"; + + $page->set_title("Comments"); + $page->set_heading("Comments"); + $page->add_block(new Block("Navigation", $nav, "left")); + $page->add_block(new Paginator("comment/list", null, $page_number, $total_pages), 90); + } + + public function display_recent_comments($page, $comments) { + $html = $this->comments_to_html($comments, true); + $html .= "
Full List"; + $page->add_block(new Block("Comments", $html, "left")); + } + + public function display_comments($page, $comments, $postbox, $image_id) { + if($postbox) { + $page->add_block(new Block("Comments", + $this->comments_to_html($comments). + $this->build_postbox($image_id), "main", 30)); + } + else { + $page->add_block(new Block("Comments", + $this->comments_to_html($comments), "main", 30)); + } + } + + + private function comments_to_html($comments, $trim=false) { + $html = ""; + foreach($comments as $comment) { + $html .= $comment->to_html($trim); + } + return $html; } // FIXME: privatise this @@ -37,7 +62,7 @@ class CommentListTheme extends Themelet { public function add_comment_list($page, $image, $comments, $position, $with_postbox) { $html = "