comment theme API changes
This commit is contained in:
parent
c506030acd
commit
7555ada953
14 changed files with 337 additions and 422 deletions
|
@ -1,14 +1,6 @@
|
|||
<?php
|
||||
require_once "lib/akismet.class.php";
|
||||
|
||||
/* CommentPostingEvent {{{
|
||||
* CommentPostingEvent:
|
||||
* $comment_id
|
||||
*
|
||||
* A comment is being deleted. Maybe used by spam
|
||||
* detectors to get a feel for what should be delted
|
||||
* and what should be kept?
|
||||
*/
|
||||
class CommentPostingEvent extends Event {
|
||||
var $image_id, $user, $comment;
|
||||
|
||||
|
@ -18,11 +10,8 @@ class CommentPostingEvent extends Event {
|
|||
$this->comment = $comment;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
/* CommentDeletionEvent {{{
|
||||
* CommentDeletionEvent:
|
||||
* $comment_id
|
||||
*
|
||||
|
||||
/**
|
||||
* A comment is being deleted. Maybe used by spam
|
||||
* detectors to get a feel for what should be delted
|
||||
* and what should be kept?
|
||||
|
@ -34,10 +23,10 @@ class CommentDeletionEvent extends Event {
|
|||
$this->comment_id = $comment_id;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
class CommentPostingException extends SCoreException {}
|
||||
|
||||
class Comment { // {{{
|
||||
class Comment {
|
||||
public function Comment($row) {
|
||||
$this->owner_id = $row['user_id'];
|
||||
$this->owner_name = $row['user_name'];
|
||||
|
@ -52,29 +41,59 @@ class Comment { // {{{
|
|||
global $database;
|
||||
return $database->db->GetOne("SELECT COUNT(*) AS count FROM comments WHERE owner_id=?", array($user->id));
|
||||
}
|
||||
} // }}}
|
||||
}
|
||||
|
||||
class CommentList implements Extension {
|
||||
var $theme;
|
||||
// event handler {{{
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
class CommentList extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config, $database;
|
||||
$config->set_default_bool('comment_anon', true);
|
||||
$config->set_default_int('comment_window', 5);
|
||||
$config->set_default_int('comment_limit', 10);
|
||||
$config->set_default_int('comment_count', 5);
|
||||
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
if($config->get_int("ext_comments_version") < 2) {
|
||||
// shortcut to latest
|
||||
if($config->get_int("ext_comments_version") < 1) {
|
||||
$database->create_table("comments", "
|
||||
id SCORE_AIPK,
|
||||
image_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL,
|
||||
owner_ip SCORE_INET NOT NULL,
|
||||
posted DATETIME DEFAULT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
INDEX (image_id),
|
||||
INDEX (owner_ip),
|
||||
INDEX (posted),
|
||||
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
");
|
||||
$config->set_int("ext_comments_version", 2);
|
||||
}
|
||||
|
||||
if($event instanceof InitExtEvent) {
|
||||
global $config;
|
||||
$config->set_default_bool('comment_anon', true);
|
||||
$config->set_default_int('comment_window', 5);
|
||||
$config->set_default_int('comment_limit', 10);
|
||||
$config->set_default_int('comment_count', 5);
|
||||
// ===
|
||||
if($config->get_int("ext_comments_version") < 1) {
|
||||
$database->Execute("CREATE TABLE comments (
|
||||
id {$database->engine->auto_increment},
|
||||
image_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL,
|
||||
owner_ip CHAR(16) NOT NULL,
|
||||
posted DATETIME DEFAULT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
INDEX (image_id)
|
||||
) {$database->engine->create_table_extras}");
|
||||
$config->set_int("ext_comments_version", 1);
|
||||
}
|
||||
|
||||
if($config->get_int("ext_comments_version") < 2) {
|
||||
$this->install();
|
||||
if($config->get_int("ext_comments_version") == 1) {
|
||||
$database->Execute("CREATE INDEX comments_owner_ip ON comments(owner_ip)");
|
||||
$database->Execute("CREATE INDEX comments_posted ON comments(posted)");
|
||||
$config->set_int("ext_comments_version", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("comment")) {
|
||||
public function onPageRequest($event) {
|
||||
if($event->page_matches("comment")) {
|
||||
if($event->get_arg(0) == "add") {
|
||||
if(isset($_POST['image_id']) && isset($_POST['comment'])) {
|
||||
try {
|
||||
|
@ -110,121 +129,84 @@ class CommentList implements Extension {
|
|||
$this->build_page($event->get_arg(1));
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof PostListBuildingEvent) {
|
||||
$cc = $config->get_int("comment_count");
|
||||
if($cc > 0) {
|
||||
$recent = $this->get_recent_comments($cc);
|
||||
if(count($recent) > 0) {
|
||||
$this->theme->display_recent_comments($page, $recent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof DisplayingImageEvent) {
|
||||
$this->theme->display_comments(
|
||||
$page,
|
||||
$this->get_comments($event->image->id),
|
||||
$this->can_comment(),
|
||||
$event->image);
|
||||
}
|
||||
|
||||
if($event instanceof ImageDeletionEvent) {
|
||||
$this->delete_comments($event->image->id);
|
||||
}
|
||||
// TODO: split akismet into a separate class, which can veto the event
|
||||
if($event instanceof CommentPostingEvent) {
|
||||
$this->add_comment_wrapper($event->image_id, $event->user, $event->comment, $event);
|
||||
}
|
||||
if($event instanceof CommentDeletionEvent) {
|
||||
$this->delete_comment($event->comment_id);
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("Comment Options");
|
||||
$sb->add_bool_option("comment_anon", "Allow anonymous comments: ");
|
||||
$sb->add_label("<br>Limit to ");
|
||||
$sb->add_int_option("comment_limit");
|
||||
$sb->add_label(" comments per ");
|
||||
$sb->add_int_option("comment_window");
|
||||
$sb->add_label(" minutes");
|
||||
$sb->add_label("<br>Show ");
|
||||
$sb->add_int_option("comment_count");
|
||||
$sb->add_label(" recent comments on the index");
|
||||
$sb->add_text_option("comment_wordpress_key", "<br>Akismet Key ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if(is_a($event, 'SearchTermParseEvent')) {
|
||||
$matches = array();
|
||||
if(preg_match("/comments(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$comments = $matches[2];
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)"));
|
||||
}
|
||||
else if(preg_match("/commented_by=(.*)/i", $event->term, $matches)) {
|
||||
global $database;
|
||||
$user = User::by_name($matches[1]);
|
||||
if(!is_null($user)) {
|
||||
$user_id = $user->id;
|
||||
}
|
||||
else {
|
||||
$user_id = -1;
|
||||
}
|
||||
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
|
||||
}
|
||||
else if(preg_match("/commented_by_userid=([0-9]+)/i", $event->term, $matches)) {
|
||||
$user_id = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
// installer {{{
|
||||
protected function install() {
|
||||
global $database;
|
||||
|
||||
public function onPostListBuilding($event) {
|
||||
global $config;
|
||||
|
||||
// shortcut to latest
|
||||
if($config->get_int("ext_comments_version") < 1) {
|
||||
$database->create_table("comments", "
|
||||
id SCORE_AIPK,
|
||||
image_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL,
|
||||
owner_ip SCORE_INET NOT NULL,
|
||||
posted DATETIME DEFAULT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
INDEX (image_id),
|
||||
INDEX (owner_ip),
|
||||
INDEX (posted),
|
||||
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
");
|
||||
$config->set_int("ext_comments_version", 2);
|
||||
}
|
||||
|
||||
// ===
|
||||
if($config->get_int("ext_comments_version") < 1) {
|
||||
$database->Execute("CREATE TABLE comments (
|
||||
id {$database->engine->auto_increment},
|
||||
image_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL,
|
||||
owner_ip CHAR(16) NOT NULL,
|
||||
posted DATETIME DEFAULT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
INDEX (image_id)
|
||||
) {$database->engine->create_table_extras}");
|
||||
$config->set_int("ext_comments_version", 1);
|
||||
}
|
||||
|
||||
if($config->get_int("ext_comments_version") == 1) {
|
||||
$database->Execute("CREATE INDEX comments_owner_ip ON comments(owner_ip)");
|
||||
$database->Execute("CREATE INDEX comments_posted ON comments(posted)");
|
||||
$config->set_int("ext_comments_version", 2);
|
||||
$cc = $config->get_int("comment_count");
|
||||
if($cc > 0) {
|
||||
$recent = $this->get_recent_comments($cc);
|
||||
if(count($recent) > 0) {
|
||||
$this->theme->display_recent_comments($recent);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
public function onDisplayingImage($event) {
|
||||
$this->theme->display_image_comments(
|
||||
$event->image,
|
||||
$this->get_comments($event->image->id),
|
||||
$this->can_comment()
|
||||
);
|
||||
}
|
||||
|
||||
public function onImageDeletion($event) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM comments WHERE image_id=?", array($image_id));
|
||||
log_info("comment", "Deleting all comments for Image #$image_id");
|
||||
}
|
||||
|
||||
// TODO: split akismet into a separate class, which can veto the event
|
||||
public function onCommentPosting($event) {
|
||||
$this->add_comment_wrapper($event->image_id, $event->user, $event->comment, $event);
|
||||
}
|
||||
|
||||
public function onCommentDeletion($event) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM comments WHERE id=?", array($comment_id));
|
||||
log_info("comment", "Deleting Comment #$comment_id");
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Comment Options");
|
||||
$sb->add_bool_option("comment_anon", "Allow anonymous comments: ");
|
||||
$sb->add_label("<br>Limit to ");
|
||||
$sb->add_int_option("comment_limit");
|
||||
$sb->add_label(" comments per ");
|
||||
$sb->add_int_option("comment_window");
|
||||
$sb->add_label(" minutes");
|
||||
$sb->add_label("<br>Show ");
|
||||
$sb->add_int_option("comment_count");
|
||||
$sb->add_label(" recent comments on the index");
|
||||
$sb->add_text_option("comment_wordpress_key", "<br>Akismet Key ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onSearchTermParse($event) {
|
||||
$matches = array();
|
||||
if(preg_match("/comments(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$comments = $matches[2];
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)"));
|
||||
}
|
||||
else if(preg_match("/commented_by=(.*)/i", $event->term, $matches)) {
|
||||
global $database;
|
||||
$user = User::by_name($matches[1]);
|
||||
if(!is_null($user)) {
|
||||
$user_id = $user->id;
|
||||
}
|
||||
else {
|
||||
$user_id = -1;
|
||||
}
|
||||
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
|
||||
}
|
||||
else if(preg_match("/commented_by_userid=([0-9]+)/i", $event->term, $matches)) {
|
||||
$user_id = int_escape($matches[1]);
|
||||
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
|
||||
}
|
||||
}
|
||||
|
||||
// page building {{{
|
||||
private function build_page($current_page) {
|
||||
global $page;
|
||||
|
@ -250,16 +232,15 @@ class CommentList implements Extension {
|
|||
$total_pages = (int)($database->db->GetOne("SELECT COUNT(image_id) AS count FROM comments GROUP BY image_id") / 10);
|
||||
|
||||
|
||||
$this->theme->display_page_start($page, $current_page, $total_pages);
|
||||
|
||||
$n = 10;
|
||||
$images = array();
|
||||
while(!$result->EOF) {
|
||||
$image = Image::by_id($result->fields["image_id"]);
|
||||
$comments = $this->get_comments($image->id);
|
||||
$this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment());
|
||||
$n += 1;
|
||||
$images[] = array($image, $comments);
|
||||
$result->MoveNext();
|
||||
}
|
||||
|
||||
$this->theme->display_comment_list($images, $current_page, $total_pages, $this->can_comment());
|
||||
}
|
||||
// }}}
|
||||
// get comments {{{
|
||||
|
@ -433,19 +414,6 @@ class CommentList implements Extension {
|
|||
log_info("comment", "Comment #$cid added");
|
||||
}
|
||||
}
|
||||
|
||||
private function delete_comments($image_id) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM comments WHERE image_id=?", array($image_id));
|
||||
log_info("comment", "Deleting all comments for Image #$image_id");
|
||||
}
|
||||
|
||||
private function delete_comment($comment_id) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM comments WHERE id=?", array($comment_id));
|
||||
log_info("comment", "Deleting Comment #$comment_id");
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new CommentList());
|
||||
?>
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
<?php
|
||||
|
||||
class CommentListTheme extends Themelet {
|
||||
/*
|
||||
/**
|
||||
* Do the basics of the comments page
|
||||
*
|
||||
* $page_number = the current page number
|
||||
* $total_pages = the total number of comment pages
|
||||
*/
|
||||
public function display_page_start(Page $page, $page_number, $total_pages) {
|
||||
public function display_comment_list($images, $page_number, $total_pages, $can_post) {
|
||||
global $page;
|
||||
|
||||
// parts for the whole page
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
|
@ -23,66 +26,66 @@ class CommentListTheme extends Themelet {
|
|||
$page->set_heading("Comments");
|
||||
$page->add_block(new Block("Navigation", $nav, "left"));
|
||||
$this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
|
||||
|
||||
// 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 = "";
|
||||
foreach($comments as $comment) {
|
||||
$comment_html .= $this->comment_to_html($comment);
|
||||
}
|
||||
if($can_post) {
|
||||
$comment_html .= $this->build_postbox($image->id);
|
||||
}
|
||||
|
||||
$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++));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Add some comments to the page, probably in a sidebar
|
||||
*
|
||||
* $comments = an array of Comment objects to be shown
|
||||
*/
|
||||
public function display_recent_comments(Page $page, $comments) {
|
||||
$html = $this->comments_to_html($comments, true);
|
||||
public function display_recent_comments($comments) {
|
||||
global $page;
|
||||
$html = "";
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment, true);
|
||||
}
|
||||
$html .= "<p><a class='more' href='".make_link("comment/list")."'>Full List</a>";
|
||||
$page->add_block(new Block("Comments", $html, "left"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Show comments for an image
|
||||
*/
|
||||
public function display_comments(Page $page, $comments, $postbox, Image $image) {
|
||||
if($postbox) {
|
||||
$html = $this->comments_to_html($comments) . $this->build_postbox($image->id);
|
||||
public function display_image_comments(Image $image, $comments, $postbox) {
|
||||
global $page;
|
||||
$html = "";
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment);
|
||||
}
|
||||
else {
|
||||
$html = $this->comments_to_html($comments);
|
||||
if($postbox) {
|
||||
$html .= $this->build_postbox($image->id);
|
||||
}
|
||||
$page->add_block(new Block("Comments", $html, "main", 30));
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a block with thumbnail and comments, as part of the comment
|
||||
* list page
|
||||
*/
|
||||
public function add_comment_list(Page $page, Image $image, $comments, $position, $with_postbox) {
|
||||
$html = "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left; margin-right: 16px;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div style='margin-left: 230px;'>" . $this->comments_to_html($comments) . "</div>";
|
||||
$html .= "</div>";
|
||||
if($with_postbox) {
|
||||
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
||||
}
|
||||
else {
|
||||
// $html .= "<div style='clear:both;'><p><small>You need to create an account before you can comment</small></p></div>";
|
||||
$html .= "<div style='clear:both;'><p> </p></div>";
|
||||
}
|
||||
|
||||
$page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Various functions which are only used by this theme
|
||||
*/
|
||||
|
||||
|
||||
protected function comments_to_html($comments, $trim=false) {
|
||||
$html = "<div class='commentblock'>";
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment, $trim);
|
||||
}
|
||||
$html .= "</div>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
global $user;
|
||||
|
@ -98,14 +101,33 @@ class CommentListTheme extends Themelet {
|
|||
$i_image_id = int_escape($comment->image_id);
|
||||
|
||||
$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||
$stripped_nonl = str_replace("\n", "\\n", $tfe->stripped);
|
||||
$stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50));
|
||||
$stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
|
||||
$h_dellink = $user->is_admin() ?
|
||||
"<br>($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n$stripped_nonl');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
return "<div class='comment'><p>$h_userlink: $h_comment $h_imagelink $h_dellink</p></div>";
|
||||
|
||||
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>";
|
||||
//}
|
||||
return "
|
||||
<div class='comment'>
|
||||
$h_userlink: $h_comment
|
||||
$h_dellink
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
protected function build_postbox($image_id) {
|
||||
|
@ -113,12 +135,12 @@ class CommentListTheme extends Themelet {
|
|||
$hash = CommentList::get_hash();
|
||||
return "
|
||||
<form action='".make_link("comment/add")."' method='POST'>
|
||||
<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>
|
||||
<br><input type='submit' value='Post Comment' />
|
||||
<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>
|
||||
<br><input type='submit' value='Post Comment' />
|
||||
</form>
|
||||
";
|
||||
";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
<?php
|
||||
|
||||
class CustomCommentListTheme extends CommentListTheme {
|
||||
public function display_page_start($page, $page_number, $total_pages) {
|
||||
public function display_comment_list($images, $page_number, $total_pages, $can_post) {
|
||||
global $page;
|
||||
|
||||
$page->disable_left();
|
||||
|
||||
// parts for the whole page
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
|
@ -12,30 +17,51 @@ class CustomCommentListTheme extends CommentListTheme {
|
|||
"<a href='".make_link("comment/list/$next")."'>Next</a>";
|
||||
|
||||
$nav = "$h_prev | $h_index | $h_next";
|
||||
|
||||
|
||||
$page->set_title("Comments");
|
||||
$page->set_heading("Comments");
|
||||
$page->add_block(new Block("Navigation", $nav, "left"));
|
||||
$this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
|
||||
$page->disable_left();
|
||||
|
||||
// parts for each image
|
||||
$position = 10;
|
||||
foreach($images as $pair) {
|
||||
$image = $pair[0];
|
||||
$comments = $pair[1];
|
||||
|
||||
$thumb_html = $this->build_thumb_html($image);
|
||||
|
||||
$s = " ";
|
||||
$un = $image->get_owner()->name;
|
||||
$t = "";
|
||||
foreach($image->get_tag_array() as $tag) {
|
||||
$u_tag = url_escape($tag);
|
||||
$t .= "<a href='".make_link("post/list/$u_tag/1")."'>".html_escape($tag)."</a> ";
|
||||
}
|
||||
$p = autodate($image->posted);
|
||||
|
||||
$comment_html = "<b>Date</b> $p $s <b>User</b> $un<br><b>Tags</b> $t<p> ";
|
||||
foreach($comments as $comment) {
|
||||
$comment_html .= $this->comment_to_html($comment);
|
||||
}
|
||||
if($can_post) {
|
||||
$comment_html .= $this->build_postbox($image->id);
|
||||
}
|
||||
|
||||
$html = "
|
||||
<table><tr>
|
||||
<td style='width: 220px;'>$thumb_html</td>
|
||||
<td style='text-align: left;'>$comment_html</td>
|
||||
</tr></table>
|
||||
";
|
||||
|
||||
|
||||
$page->add_block(new Block(" ", $html, "main", $position++));
|
||||
}
|
||||
}
|
||||
|
||||
public function display_recent_comments($page, $comments) {
|
||||
public function display_recent_comments($comments) {
|
||||
// no recent comments in this theme
|
||||
//$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 $page, $comments, $postbox, Image $image) {
|
||||
$count = count($comments);
|
||||
$cs = $count == 1 ? "Comment" : "Comments";
|
||||
if($postbox) {
|
||||
$html = $this->comments_to_html($comments) . $this->build_postbox($image->id);
|
||||
}
|
||||
else {
|
||||
$html = $this->comments_to_html($comments);
|
||||
}
|
||||
$page->add_block(new Block("$count $cs", $html, "main", 30));
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,33 +81,21 @@ class CustomCommentListTheme extends CommentListTheme {
|
|||
|
||||
$h_userlink = "<a class='username' href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||
$h_dellink = $user->is_admin() ?
|
||||
" ($h_poster_ip, <a ".
|
||||
"<br>($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n".$tfe->stripped."');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
return "<p class='comment'>$h_userlink $h_dellink<br/><b>Posted on $h_posted</b><br/>$h_comment</p>";
|
||||
}
|
||||
|
||||
public function add_comment_list(Page $page, Image $image, $comments, $position, $with_postbox) {
|
||||
$s = " ";
|
||||
$un = $image->get_owner()->name;
|
||||
$t = "";
|
||||
foreach($image->get_tag_array() as $tag) {
|
||||
$u_tag = url_escape($tag);
|
||||
$t .= "<a href='".make_link("post/list/$u_tag/1")."'>".html_escape($tag)."</a> ";
|
||||
if($trim) {
|
||||
return "<p class='comment'>$h_userlink $h_dellink<br/><b>Posted $h_posted</b><br/>$h_comment</p>";
|
||||
}
|
||||
else {
|
||||
return "
|
||||
<table class='comment'><tr>
|
||||
<td style='width: 150px;'>$h_userlink<br/><b>Posted $h_posted</b>$h_dellink</td>
|
||||
<td>$h_comment</td>
|
||||
</tr></table>
|
||||
";
|
||||
}
|
||||
$p = autodate($image->posted);
|
||||
|
||||
$html = "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left; margin-right: 16px;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div style='margin-left: 250px;'>";
|
||||
$html .= "<b>Date</b> $p $s <b>User</b> $un<br><b>Tags</b> $t<p> ";
|
||||
$html .= $this->comments_to_html($comments);
|
||||
$html .= "</div>";
|
||||
$html .= "</div>";
|
||||
$html .= "<div style='clear: both; display: block; height: 64px;'> </div>";
|
||||
|
||||
$page->add_block(new Block(" ", $html, "main", $position));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -39,7 +39,6 @@ THEAD {
|
|||
}
|
||||
TD {
|
||||
vertical-align: top;
|
||||
text-align: center;
|
||||
}
|
||||
/* bzchan: subtitle black border removed */
|
||||
#subtitle {
|
||||
|
@ -50,7 +49,9 @@ TD {
|
|||
border-top: none;
|
||||
}
|
||||
#body SELECT {width: 150px;}
|
||||
TD>INPUT {width: 100%;}
|
||||
TD>INPUT[type="submit"] {width: 100%;}
|
||||
TD>INPUT[type="text"] {width: 100%;}
|
||||
TD>INPUT[type="password"] {width: 100%;}
|
||||
TD>SELECT {width: 100%;}
|
||||
|
||||
#footer {
|
||||
|
|
|
@ -1,51 +1,12 @@
|
|||
<?php
|
||||
|
||||
class CustomCommentListTheme extends CommentListTheme {
|
||||
public function add_comment_list(Page $page, Image $image, $comments, $position, $with_postbox) {
|
||||
$html = "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left; margin-right: 16px;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div style='margin-left: 228px;'>" . $this->comments_to_html($comments) . "</div>";
|
||||
$html .= "</div>";
|
||||
if($with_postbox) {
|
||||
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
||||
}
|
||||
else {
|
||||
// $html .= "<div style='clear:both;'><p><small>You need to create an account before you can comment</small></p></div>";
|
||||
$html .= "<div style='clear:both;'><p> </p></div>";
|
||||
}
|
||||
|
||||
$page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position));
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
return $this->rr(parent::comment_to_html($comment, $trim));
|
||||
}
|
||||
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
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);
|
||||
$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);
|
||||
|
||||
$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||
$stripped_nonl = str_replace("\n", "\\n", $tfe->stripped);
|
||||
$stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
|
||||
$h_dellink = $user->is_admin() ?
|
||||
"<br>($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n$stripped_nonl');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
return "
|
||||
<div class='rr'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'>
|
||||
<div class='comment'>$h_userlink: $h_comment $h_imagelink $h_dellink</div>
|
||||
</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>";
|
||||
protected function build_postbox($image_id) {
|
||||
return $this->rr(parent::build_postbox($image_id));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,17 +3,8 @@
|
|||
* A customised version of the Setup theme
|
||||
*/
|
||||
class CustomSetupTheme extends SetupTheme {
|
||||
/**
|
||||
* Turn a SetupBlock into HTML... with rounded corners.
|
||||
*/
|
||||
protected function sb_to_html(SetupBlock $block) {
|
||||
return "
|
||||
<div class='rr setupblock'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'><b>{$block->header}</b><br>{$block->body}</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>
|
||||
";
|
||||
return $this->rr(parent::sb_to_html($block));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -120,6 +120,7 @@ UL {
|
|||
overflow: hidden;
|
||||
}
|
||||
.comment {
|
||||
margin-bottom: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
|
@ -187,7 +188,6 @@ UL {
|
|||
|
||||
.setupblock {
|
||||
text-align: center;
|
||||
margin: 16px;
|
||||
width: 350px;
|
||||
}
|
||||
.setupblock TEXTAREA {
|
||||
|
|
|
@ -50,6 +50,20 @@ class Themelet {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put something in a rounded rectangle box; specific to the default theme
|
||||
*/
|
||||
public function rr($html) {
|
||||
return "
|
||||
<div class='rr'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'>$html</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a generic paginator
|
||||
*/
|
||||
|
|
|
@ -1,29 +1,50 @@
|
|||
<?php
|
||||
|
||||
class CustomCommentListTheme extends CommentListTheme {
|
||||
/*
|
||||
* Do the basics of the comments page
|
||||
*
|
||||
* $page_number = the current page number
|
||||
* $total_pages = the total number of comment pages
|
||||
*/
|
||||
public function display_page_start(Page $page, $page_number, $total_pages) {
|
||||
public function display_comment_list($images, $page_number, $total_pages, $can_post) {
|
||||
global $config, $page;
|
||||
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
global $config;
|
||||
$page_title = $config->get_string('title');
|
||||
$page->set_title($page_title);
|
||||
$page->set_heading($page_title);
|
||||
$page->disable_left();
|
||||
$page->add_block(new Block(null, $this->build_upload_box(), "main", 0));
|
||||
// $page->add_block(new Block(null, "<hr>", "main", 2));
|
||||
// $this->display_paginator($page, "comment/list", null, $page_number, $total_pages, 5);
|
||||
$page->add_block(new Block(null, "<hr>", "main", 80));
|
||||
$this->display_paginator($page, "comment/list", null, $page_number, $total_pages, 90);
|
||||
|
||||
// parts for each image
|
||||
$position = 10;
|
||||
foreach($images as $pair) {
|
||||
$image = $pair[0];
|
||||
$comments = $pair[1];
|
||||
|
||||
$h_filename = html_escape($image->filename);
|
||||
$h_filesize = to_shorthand_int($image->filesize);
|
||||
$w = $image->width;
|
||||
$h = $image->height;
|
||||
|
||||
$comment_html = "";
|
||||
$comment_id = 0;
|
||||
foreach($comments as $comment) {
|
||||
$comment_html .= $this->comment_to_html($comment, false, $comment_id++);
|
||||
}
|
||||
|
||||
$html = "<p style='clear:both'> </p><hr height='1'>";
|
||||
$html .= "File: <a href=\"".make_link("post/view/{$image->id}")."\">$h_filename</a> - ($h_filesize, {$w}x{$h}) - ";
|
||||
$html .= html_escape($image->get_tag_list());
|
||||
$html .= "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div class='commentset'>$comment_html</div>";
|
||||
$html .= "</div>";
|
||||
|
||||
$page->add_block(new Block(null, $html, "main", $position++));
|
||||
}
|
||||
}
|
||||
|
||||
public function display_recent_comments(Page $page, $comments) {
|
||||
public function display_recent_comments($comments) {
|
||||
// sidebar fails in this theme
|
||||
}
|
||||
|
||||
|
@ -31,35 +52,6 @@ class CustomCommentListTheme extends CommentListTheme {
|
|||
return "[[ insert upload-and-comment extension here ]]";
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a block with thumbnail and comments, as part of the comment
|
||||
* list page
|
||||
*/
|
||||
public function add_comment_list(Page $page, Image $image, $comments, $position, $with_postbox) {
|
||||
$h_filename = html_escape($image->filename);
|
||||
$h_filesize = to_shorthand_int($image->filesize);
|
||||
$w = $image->width;
|
||||
$h = $image->height;
|
||||
|
||||
$html = "<hr height='1'>";
|
||||
$html .= "File: <a href=\"".make_link("post/view/{$image->id}")."\">$h_filename</a> - ($h_filesize, {$w}x{$h}) - ";
|
||||
$html .= html_escape($image->get_tag_list());
|
||||
$html .= "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left; margin-left: 16px; margin-right: 16px;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div class='commentset'>" . $this->comments_to_html($comments) . "</div>";
|
||||
$html .= "</div>";
|
||||
|
||||
$page->add_block(new Block(null, $html, "main", $position));
|
||||
}
|
||||
|
||||
protected function comments_to_html($comments, $trim=false) {
|
||||
$html = "";
|
||||
$inner_id = 0;
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment, $trim, $inner_id++);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function comment_to_html(Comment $comment, $trim=false, $inner_id=0) {
|
||||
global $user;
|
||||
|
@ -80,27 +72,16 @@ class CustomCommentListTheme extends CommentListTheme {
|
|||
" ($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n".$tfe->stripped."');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
$h_reply = "[<a href='".make_link("post/view/$i_image_id")."'>Reply</a>]";
|
||||
|
||||
if($inner_id == 0) {
|
||||
return "<div class='comment'>$h_userlink$h_dellink $h_date No.$i_comment_id [Reply]<p>$h_comment</p></div>";
|
||||
return "<div class='comment' style='margin-top: 8px;'>$h_userlink$h_dellink $h_date No.$i_comment_id $h_reply<p>$h_comment</p></div>";
|
||||
}
|
||||
else {
|
||||
return "<table><tr><td nowrap class='doubledash'>>></td><td>".
|
||||
"<div class='reply'>$h_userlink$h_dellink $h_date No.$i_comment_id [Reply]<p>$h_comment</p></div>" .
|
||||
"<div class='reply'>$h_userlink$h_dellink $h_date No.$i_comment_id $h_reply<p>$h_comment</p></div>" .
|
||||
"</td></tr></table>";
|
||||
}
|
||||
}
|
||||
|
||||
protected function build_postbox($image_id) {
|
||||
$i_image_id = int_escape($image_id);
|
||||
return "
|
||||
<form action='".make_link("comment/add")."' method='POST'>
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<textarea name='comment' rows='5' cols='50'></textarea>
|
||||
<br><input type='submit' value='Post' />
|
||||
</form>
|
||||
";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -106,7 +106,5 @@ TD {
|
|||
padding: 5px;
|
||||
}
|
||||
.thumb {
|
||||
width: 220px;
|
||||
display: inline-block;
|
||||
margin-bottom: 16px;
|
||||
margin: 16px;
|
||||
}
|
||||
|
|
|
@ -1,51 +1,12 @@
|
|||
<?php
|
||||
|
||||
class CustomCommentListTheme extends CommentListTheme {
|
||||
public function add_comment_list(Page $page, Image $image, $comments, $position, $with_postbox) {
|
||||
$html = "<div style='text-align: left'>";
|
||||
$html .= "<div style='float: left; margin-right: 16px;'>" . $this->build_thumb_html($image) . "</div>";
|
||||
$html .= "<div style='margin-left: 228px;'>" . $this->comments_to_html($comments) . "</div>";
|
||||
$html .= "</div>";
|
||||
if($with_postbox) {
|
||||
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
||||
}
|
||||
else {
|
||||
// $html .= "<div style='clear:both;'><p><small>You need to create an account before you can comment</small></p></div>";
|
||||
$html .= "<div style='clear:both;'><p> </p></div>";
|
||||
}
|
||||
|
||||
$page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position));
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
return $this->box(parent::comment_to_html($comment, $trim));
|
||||
}
|
||||
|
||||
protected function comment_to_html(Comment $comment, $trim=false) {
|
||||
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);
|
||||
$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);
|
||||
|
||||
$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||
$stripped_nonl = str_replace("\n", "\\n", $tfe->stripped);
|
||||
$stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
|
||||
$h_dellink = $user->is_admin() ?
|
||||
"<br>($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n$stripped_nonl');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
return "
|
||||
<div class='rr'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'>
|
||||
<div class='comment'>$h_userlink: $h_comment $h_imagelink $h_dellink</div>
|
||||
</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>";
|
||||
protected function build_postbox($image_id) {
|
||||
return $this->box(parent::build_postbox($image_id));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,17 +3,8 @@
|
|||
* A customised version of the Setup theme
|
||||
*/
|
||||
class CustomSetupTheme extends SetupTheme {
|
||||
/**
|
||||
* Turn a SetupBlock into HTML... with rounded corners.
|
||||
*/
|
||||
protected function sb_to_html(SetupBlock $block) {
|
||||
return "
|
||||
<div class='rr setupblock'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'><b>{$block->header}</b><br>{$block->body}</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>
|
||||
";
|
||||
return $this->box(parent::sb_to_html($block));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -186,7 +186,6 @@ UL {
|
|||
|
||||
.setupblock {
|
||||
text-align: center;
|
||||
margin: 16px;
|
||||
width: 350px;
|
||||
}
|
||||
.setupblock TEXTAREA {
|
||||
|
|
|
@ -51,6 +51,20 @@ class Themelet {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put something in a box; specific to the default theme
|
||||
*/
|
||||
public function box($html) {
|
||||
return "
|
||||
<div class='rr'>
|
||||
<div class='rrtop'><div></div></div>
|
||||
<div class='rrcontent'>$html</div>
|
||||
<div class='rrbot'><div></div></div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a generic paginator
|
||||
*/
|
||||
|
|
Reference in a new issue