comment themed
git-svn-id: file:///home/shish/svn/shimmie2/trunk@332 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
43ff2c2569
commit
1008c36180
2 changed files with 82 additions and 69 deletions
|
@ -84,7 +84,7 @@ class CommentList extends Extension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// FIXME: denied message
|
$this->theme->display_error($event->page, "Denied", "Only admins can delete comments");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if($event->get_arg(0) == "list") {
|
else if($event->get_arg(0) == "list") {
|
||||||
|
@ -94,21 +94,18 @@ class CommentList extends Extension {
|
||||||
|
|
||||||
if(is_a($event, 'PostListBuildingEvent')) {
|
if(is_a($event, 'PostListBuildingEvent')) {
|
||||||
global $config;
|
global $config;
|
||||||
if($config->get_int("comment_count") > 0) {
|
$cc = $config->get_int("comment_count");
|
||||||
$event->page->add_block(new Block("Comments", $this->build_recent_comments(), "left"));
|
if($cc > 0) {
|
||||||
|
$this->theme->display_recent_comments($event->page, $this->get_recent_comments($cc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'DisplayingImageEvent')) {
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
if($this->can_comment()) {
|
$this->theme->display_comments(
|
||||||
$event->page->add_block(new Block("Comments",
|
$event->page,
|
||||||
$this->build_image_comments($event->image->id).
|
$this->get_comments($event->image->id),
|
||||||
$this->theme->build_postbox($event->image->id), "main", 30));
|
$this->can_comment(),
|
||||||
}
|
$event->image->id);
|
||||||
else {
|
|
||||||
$event->page->add_block(new Block("Comments",
|
|
||||||
$this->build_image_comments($event->image->id), "main", 30));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'ImageDeletionEvent')) {
|
if(is_a($event, 'ImageDeletionEvent')) {
|
||||||
|
@ -180,34 +177,18 @@ class CommentList extends Extension {
|
||||||
$n = 10;
|
$n = 10;
|
||||||
while(!$result->EOF) {
|
while(!$result->EOF) {
|
||||||
$image = $database->get_image($result->fields["image_id"]);
|
$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());
|
$this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment());
|
||||||
$n += 1;
|
$n += 1;
|
||||||
$result->MoveNext();
|
$result->MoveNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
private function build_image_comments($image_id) {
|
// get comments {{{
|
||||||
|
private function get_recent_comments() {
|
||||||
global $config;
|
global $config;
|
||||||
$i_image_id = int_escape($image_id);
|
global $database;
|
||||||
$html = "<div id='image_comments'>";
|
$rows = $database->db->GetAll("
|
||||||
$html .= $this->query_to_html("
|
|
||||||
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), false);
|
|
||||||
$html .= "</div>";
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function build_recent_comments() {
|
|
||||||
global $config;
|
|
||||||
$html = $this->query_to_html("
|
|
||||||
SELECT
|
SELECT
|
||||||
users.id as user_id, users.name as user_name,
|
users.id as user_id, users.name as user_name,
|
||||||
comments.comment as comment, comments.id as comment_id,
|
comments.comment as comment, comments.id as comment_id,
|
||||||
|
@ -216,23 +197,33 @@ class CommentList extends Extension {
|
||||||
LEFT JOIN users ON comments.owner_id=users.id
|
LEFT JOIN users ON comments.owner_id=users.id
|
||||||
ORDER BY comments.id DESC
|
ORDER BY comments.id DESC
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
", array($config->get_int('comment_count')), true);
|
", array($config->get_int('comment_count')));
|
||||||
$html .= "<p><a class='more' href='".make_link("comment/list")."'>Full List</a>";
|
$comments = array();
|
||||||
return $html;
|
foreach($rows as $row) {
|
||||||
|
$comments[] = new Comment($row);
|
||||||
|
}
|
||||||
|
return $comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function query_to_html($query, $args, $trim=false) {
|
private function get_comments($image_id) {
|
||||||
global $database;
|
|
||||||
global $config;
|
global $config;
|
||||||
|
global $database;
|
||||||
$html = "";
|
$i_image_id = int_escape($image_id);
|
||||||
$result = $database->Execute($query, $args);
|
$rows = $database->db->GetAll("
|
||||||
while(!$result->EOF) {
|
SELECT
|
||||||
$comment = new Comment($result->fields);
|
users.id as user_id, users.name as user_name,
|
||||||
$html .= $comment->to_html($trim);
|
comments.comment as comment, comments.id as comment_id,
|
||||||
$result->MoveNext();
|
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 $html;
|
return $comments;
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// add / remove / edit comments {{{
|
// add / remove / edit comments {{{
|
||||||
|
@ -294,22 +285,19 @@ class CommentList extends Extension {
|
||||||
global $config;
|
global $config;
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
$page->set_title("Error");
|
|
||||||
$page->set_heading("Error");
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
if(!$config->get_bool('comment_anon') && $user->is_anonymous()) {
|
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) == "") {
|
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()) {
|
else if($this->is_comment_limit_hit()) {
|
||||||
$page->add_main_block(new Block("Comment Limit Hit",
|
$this->theme->display_error($page, "Comment Limit Hit",
|
||||||
"You've posted several comments recently; wait a minute and try again..."));
|
"You've posted several comments recently; wait a minute and try again...");
|
||||||
}
|
}
|
||||||
else if($this->is_spam($comment)) {
|
else if($this->is_spam($comment)) {
|
||||||
$page->add_main_block(new Block("Spam Detected",
|
$this->theme->display_error($page, "Spam Detected",
|
||||||
"Akismet thinks that your comment is spam. Try rewriting the comment?"));
|
"Akismet thinks that your comment is spam. Try rewriting the comment?");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$database->Execute(
|
$database->Execute(
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class CommentListTheme extends Themelet {
|
class CommentListTheme extends Themelet {
|
||||||
public function display_page_start($page, $current_page, $total_pages) {
|
public function display_page_start($page, $page_number, $total_pages) {
|
||||||
$page->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) {
|
|
||||||
$prev = $page_number - 1;
|
$prev = $page_number - 1;
|
||||||
$next = $page_number + 1;
|
$next = $page_number + 1;
|
||||||
|
|
||||||
|
@ -18,7 +11,39 @@ class CommentListTheme extends Themelet {
|
||||||
$h_next = ($page_number >= $total_pages) ? "Next" :
|
$h_next = ($page_number >= $total_pages) ? "Next" :
|
||||||
"<a href='".make_link("comment/list/$next")."'>Next</a>";
|
"<a href='".make_link("comment/list/$next")."'>Next</a>";
|
||||||
|
|
||||||
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 .= "<p><a class='more' href='".make_link("comment/list")."'>Full List</a>";
|
||||||
|
$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
|
// FIXME: privatise this
|
||||||
|
@ -37,7 +62,7 @@ class CommentListTheme extends Themelet {
|
||||||
public function add_comment_list($page, $image, $comments, $position, $with_postbox) {
|
public function add_comment_list($page, $image, $comments, $position, $with_postbox) {
|
||||||
$html = "<div style='text-align: left'>";
|
$html = "<div style='text-align: left'>";
|
||||||
$html .= "<div style='float: left; margin-right: 16px;'>" . build_thumb_html($image) . "</div>";
|
$html .= "<div style='float: left; margin-right: 16px;'>" . build_thumb_html($image) . "</div>";
|
||||||
$html .= $comments;
|
$html .= $this->comments_to_html($comments);
|
||||||
$html .= "</div>";
|
$html .= "</div>";
|
||||||
if($with_postbox) {
|
if($with_postbox) {
|
||||||
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
||||||
|
|
Reference in a new issue