2007-06-30 01:19:11 +00:00
|
|
|
<?php
|
|
|
|
class CommentListTheme extends Themelet {
|
2009-08-24 02:43:10 +00:00
|
|
|
var $comments_shown = 0;
|
2010-02-02 18:12:54 +00:00
|
|
|
var $anon_id = 1;
|
2009-08-24 02:43:10 +00:00
|
|
|
|
2009-08-04 16:45:09 +00:00
|
|
|
/**
|
2009-08-18 23:33:18 +00:00
|
|
|
* Display a page with a list of images, and for each image,
|
|
|
|
* the image's comments
|
2007-07-28 20:30:01 +00:00
|
|
|
*/
|
2009-08-04 16:45:09 +00:00
|
|
|
public function display_comment_list($images, $page_number, $total_pages, $can_post) {
|
2010-01-03 08:15:52 +00:00
|
|
|
global $config, $page, $user;
|
2009-08-18 23:33:18 +00:00
|
|
|
|
|
|
|
// aaaaaaargh php
|
|
|
|
assert(is_array($images));
|
2009-08-19 04:53:27 +00:00
|
|
|
assert(is_numeric($page_number));
|
|
|
|
assert(is_numeric($total_pages));
|
2009-08-18 23:33:18 +00:00
|
|
|
assert(is_bool($can_post));
|
2009-08-04 16:45:09 +00:00
|
|
|
|
|
|
|
// parts for the whole page
|
2007-06-30 01:19:11 +00:00
|
|
|
$prev = $page_number - 1;
|
|
|
|
$next = $page_number + 1;
|
|
|
|
|
|
|
|
$h_prev = ($page_number <= 1) ? "Prev" :
|
|
|
|
"<a href='".make_link("comment/list/$prev")."'>Prev</a>";
|
2007-07-26 13:19:39 +00:00
|
|
|
$h_index = "<a href='".make_link()."'>Index</a>";
|
2007-06-30 01:19:11 +00:00
|
|
|
$h_next = ($page_number >= $total_pages) ? "Next" :
|
|
|
|
"<a href='".make_link("comment/list/$next")."'>Next</a>";
|
|
|
|
|
2007-07-19 14:02:18 +00:00
|
|
|
$nav = "$h_prev | $h_index | $h_next";
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-07-19 14:02:18 +00:00
|
|
|
$page->set_title("Comments");
|
|
|
|
$page->set_heading("Comments");
|
|
|
|
$page->add_block(new Block("Navigation", $nav, "left"));
|
2007-07-21 15:02:14 +00:00
|
|
|
$this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
|
2009-08-04 16:45:09 +00:00
|
|
|
|
|
|
|
// parts for each image
|
|
|
|
$position = 10;
|
|
|
|
foreach($images as $pair) {
|
|
|
|
$image = $pair[0];
|
|
|
|
$comments = $pair[1];
|
|
|
|
|
|
|
|
$thumb_html = $this->build_thumb_html($image);
|
|
|
|
|
|
|
|
$comment_html = "";
|
2009-08-18 23:33:18 +00:00
|
|
|
$comment_limit = $config->get_int("comment_list_count", 10);
|
|
|
|
$comment_count = count($comments);
|
|
|
|
if($comment_limit > 0 && $comment_count > $comment_limit) {
|
|
|
|
$hidden = $comment_count - $comment_limit;
|
|
|
|
$comment_html .= "<p>showing $comment_limit of $comment_count comments</p>";
|
|
|
|
$comments = array_slice($comments, -$comment_limit);
|
|
|
|
}
|
2010-02-03 15:22:54 +00:00
|
|
|
$this->anon_id = 1;
|
2009-08-04 16:45:09 +00:00
|
|
|
foreach($comments as $comment) {
|
|
|
|
$comment_html .= $this->comment_to_html($comment);
|
|
|
|
}
|
2010-01-03 08:15:52 +00:00
|
|
|
if(!$user->is_anonymous()) {
|
|
|
|
if($can_post) {
|
|
|
|
$comment_html .= $this->build_postbox($image->id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($can_post) {
|
|
|
|
if(!$config->get_bool('comment_captcha')) {
|
|
|
|
$comment_html .= $this->build_postbox($image->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$comment_html .= "<a href='".make_link("post/view/".$image->id)."'>Add Comment</a>";
|
|
|
|
}
|
|
|
|
}
|
2009-08-04 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$html = "
|
|
|
|
<table class='comment_list_table'><tr>
|
|
|
|
<td>$thumb_html</td>
|
|
|
|
<td>$comment_html</td>
|
|
|
|
</tr></table>
|
|
|
|
";
|
|
|
|
|
|
|
|
$page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position++));
|
|
|
|
}
|
2007-07-19 14:02:18 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 16:45:09 +00:00
|
|
|
|
|
|
|
/**
|
2007-07-28 20:30:01 +00:00
|
|
|
* Add some comments to the page, probably in a sidebar
|
|
|
|
*
|
|
|
|
* $comments = an array of Comment objects to be shown
|
|
|
|
*/
|
2009-08-04 16:45:09 +00:00
|
|
|
public function display_recent_comments($comments) {
|
|
|
|
global $page;
|
2010-02-02 18:12:54 +00:00
|
|
|
$this->anon_id = -1;
|
2009-08-04 16:45:09 +00:00
|
|
|
$html = "";
|
|
|
|
foreach($comments as $comment) {
|
|
|
|
$html .= $this->comment_to_html($comment, true);
|
|
|
|
}
|
2007-07-19 14:02:18 +00:00
|
|
|
$html .= "<p><a class='more' href='".make_link("comment/list")."'>Full List</a>";
|
|
|
|
$page->add_block(new Block("Comments", $html, "left"));
|
|
|
|
}
|
|
|
|
|
2009-08-04 16:45:09 +00:00
|
|
|
|
|
|
|
/**
|
2007-10-27 23:32:39 +00:00
|
|
|
* Show comments for an image
|
2007-07-28 20:30:01 +00:00
|
|
|
*/
|
2009-08-04 16:45:09 +00:00
|
|
|
public function display_image_comments(Image $image, $comments, $postbox) {
|
|
|
|
global $page;
|
2010-02-02 18:12:54 +00:00
|
|
|
$this->anon_id = 1;
|
2009-08-04 16:45:09 +00:00
|
|
|
$html = "";
|
|
|
|
foreach($comments as $comment) {
|
|
|
|
$html .= $this->comment_to_html($comment);
|
2007-07-19 14:02:18 +00:00
|
|
|
}
|
2009-08-04 16:45:09 +00:00
|
|
|
if($postbox) {
|
|
|
|
$html .= $this->build_postbox($image->id);
|
2007-07-19 14:02:18 +00:00
|
|
|
}
|
2009-07-28 00:09:00 +00:00
|
|
|
$page->add_block(new Block("Comments", $html, "main", 30));
|
2007-07-19 14:02:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2007-08-23 11:14:03 +00:00
|
|
|
protected function comment_to_html($comment, $trim=false) {
|
2007-07-19 17:57:35 +00:00
|
|
|
global $user;
|
|
|
|
|
|
|
|
$tfe = new TextFormattingEvent($comment->comment);
|
|
|
|
send_event($tfe);
|
|
|
|
|
|
|
|
$i_uid = int_escape($comment->owner_id);
|
|
|
|
$h_name = html_escape($comment->owner_name);
|
|
|
|
$h_poster_ip = html_escape($comment->poster_ip);
|
2010-04-07 12:25:46 +00:00
|
|
|
$h_timestamp = autodate($comment->posted);
|
2007-07-19 17:57:35 +00:00
|
|
|
$h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted);
|
|
|
|
$i_comment_id = int_escape($comment->comment_id);
|
|
|
|
$i_image_id = int_escape($comment->image_id);
|
|
|
|
|
2010-02-02 18:12:54 +00:00
|
|
|
$anoncode = "";
|
|
|
|
if($h_name == "Anonymous" && $this->anon_id >= 0) {
|
|
|
|
$anoncode = "<sup>{$this->anon_id}</sup>";
|
|
|
|
$this->anon_id++;
|
|
|
|
}
|
|
|
|
$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>$anoncode";
|
2009-08-04 16:45:09 +00:00
|
|
|
$stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50));
|
2008-12-27 10:56:51 +00:00
|
|
|
$stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
|
2009-01-04 19:18:37 +00:00
|
|
|
$h_dellink = $user->is_admin() ?
|
2010-04-07 12:25:46 +00:00
|
|
|
"<br>($h_poster_ip, $h_timestamp, <a ".
|
2008-12-27 10:56:51 +00:00
|
|
|
"onclick=\"return confirm('Delete comment by $h_name:\\n$stripped_nonl');\" ".
|
2007-07-19 17:57:35 +00:00
|
|
|
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
2009-08-04 16:45:09 +00:00
|
|
|
|
|
|
|
if($trim) {
|
|
|
|
return "
|
|
|
|
$h_userlink: $h_comment
|
|
|
|
<a href='".make_link("post/view/$i_image_id")."'>>>></a>
|
|
|
|
$h_dellink
|
|
|
|
";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//$avatar = "";
|
|
|
|
//if(!empty($comment->owner->email)) {
|
|
|
|
// $hash = md5(strtolower($comment->owner->email));
|
|
|
|
// $avatar = "<img src=\"http://www.gravatar.com/avatar/$hash.jpg\"><br>";
|
|
|
|
//}
|
2009-08-24 02:43:10 +00:00
|
|
|
$oe = ($this->comments_shown++ % 2 == 0) ? "even" : "odd";
|
2009-08-04 16:45:09 +00:00
|
|
|
return "
|
2010-02-03 16:01:00 +00:00
|
|
|
<a name='$i_comment_id'></a>
|
2009-08-24 02:43:10 +00:00
|
|
|
<div class='$oe comment'>
|
2009-08-04 16:45:09 +00:00
|
|
|
$h_userlink: $h_comment
|
|
|
|
$h_dellink
|
|
|
|
</div>
|
|
|
|
";
|
|
|
|
}
|
2007-07-19 17:57:35 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 11:14:03 +00:00
|
|
|
protected function build_postbox($image_id) {
|
2010-01-03 08:15:52 +00:00
|
|
|
global $config;
|
2009-11-10 03:01:20 +00:00
|
|
|
|
2007-06-30 01:19:11 +00:00
|
|
|
$i_image_id = int_escape($image_id);
|
2008-12-30 22:20:42 +00:00
|
|
|
$hash = CommentList::get_hash();
|
2010-01-03 08:15:52 +00:00
|
|
|
$captcha = $config->get_bool("comment_captcha") ? captcha_get_html() : "";
|
2009-11-10 03:55:17 +00:00
|
|
|
|
2007-06-30 01:19:11 +00:00
|
|
|
return "
|
2010-09-22 11:56:19 +00:00
|
|
|
".make_form(make_link("comment/add"))."
|
2009-08-04 16:45:09 +00:00
|
|
|
<input type='hidden' name='image_id' value='$i_image_id' />
|
|
|
|
<input type='hidden' name='hash' value='$hash' />
|
|
|
|
<textarea name='comment' rows='5' cols='50'></textarea>
|
2010-01-03 08:15:52 +00:00
|
|
|
$captcha
|
2009-08-04 16:45:09 +00:00
|
|
|
<br><input type='submit' value='Post Comment' />
|
2007-06-30 01:19:11 +00:00
|
|
|
</form>
|
2009-08-04 16:45:09 +00:00
|
|
|
";
|
2007-06-30 01:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|