# Load the blog config.
$root->{blogcfg} = &readConfig('blog.conf') unless exists $root->{blogcfg};
my $action = $query->{action} || 'index';
my $id = $query->{id} || '';
my $entry = {};
if (length $id > 0) {
if (&entryExists($id)) {
# Good. Read this entry.
$entry = &readEntry($id);
}
else {
$root->{content} = "Missing Entry
";
return 1;
}
}
if ($action eq 'index') {
$root->{content} = "Comments
\n\n";
# Get the comments on this.
my @comments = &getComments($id);
if (scalar(@comments)) {
my $ln = 0;
foreach my $line (@comments) {
my ($ip,$time,$name,$msg) = split(/<>/, $line, 4);
my $stamp = &timeFormat($root->{blogcfg}->{blog}->{timestamp}, $time);
# Get an avatar.
my $avatar = "{conf}->{site}->{public}/avatars/user_guest.png\" "
. "width=\"100\" height=\"100\" alt=\"Guest\">
\n"
. "guest\n";
my $intro = "Posted by somebody\n\n";
if ($name =~ /^guest:/i) {
$name =~ s/^guest://i;
$intro = "Posted by $name (Guest)
\n\n";
}
else {
&readUser($name) unless exists $root->{users}->{$name};
my $nick = $name;
my $pos = $root->{conf}->{powers}->{$root->{users}->{$name}->{power}};
if (&userExists($name)) {
$nick = &getNickname($name);
}
$intro = "Posted by "
. "$nick ($pos)
\n\n";
# Do they have an avatar?
if (length $root->{users}->{$name}->{avatar} > 0) {
$avatar = ""
. "{users}->{$name}->{avatar}\" width=\"100\" "
. "height=\"100\" alt=\"$nick\">
\n"
. "$name\n";
}
else {
$avatar = ""
. "{conf}->{site}->{public}/avatars/"
. "user_guest.png\" width=\"100\" "
. "height=\"100\" alt=\"$nick\">
\n"
. "$name\n";
}
}
$root->{content} .= "
\n"
. "
\n"
. "$avatar"
. "
\n"
. "
$stamp\n"
. "$intro"
. "$msg\n";
if ($root->{auth}) {
my $perm = &getBlogPermissions();
if ($perm eq 'authors') {
$root->{content} .= "
\n"
. "
["
. "delete]\n";
}
}
$root->{content} .= "
\n
\n";
$ln++;
}
}
else {
$root->{content} .= "Nobody has commented on this entry yet. Why not "
. "be the first?\n\n";
}
# Are we allowed to comment?
my $canComment = 1;
if (not $root->{auth}) {
if ($root->{blogcfg}->{comments}->{allowguests} == 0) {
$canComment = 0;
}
}
if ($canComment) {
$root->{content} .= "Leave a Comment
\n\n"
. "\n";
}
else {
$root->{content} .= "Leave a Comment
\n\n"
. "You must be logged in to comment "
. "on this entry.";
}
}
elsif ($action eq 'save') {
my $name = $query->{name} || 'Anonymous';
my $msg = $query->{message} || '';
my $trap1 = $query->{email} || '';
my $trap2 = $query->{url} || '';
my $trap3 = $query->{comment} || '';
my $denied = 0;
if ($trap1 ne '') {
$denied++;
}
if ($trap2 ne 'http://') {
$denied++;
}
if ($trap3 ne '') {
$denied++;
}
if (length $msg == 0) {
$denied++;
}
if ($denied) {
$root->{content} = "Comment Denied
\n\n"
. "Your comment wasn't acceptible. Please try again.";
return 1;
}
# Filter the message.
$msg =~ s~&~&~ig;
$msg =~ s~<~<~ig;
$msg =~ s~>~>~ig;
$name =~ s~&~&~ig;
$name =~ s~<~<~ig;
$name =~ s~>~>~ig;
# Handle newlines.
$msg =~ s~\x0a~
~ig;
$msg =~ s~\x0d~~ig;
$name =~ s~[\x0d\x0a]~~ig;
# Logged in?
if ($root->{auth} == 1) {
$name = $root->{me};
}
else {
$name = "guest:$name";
}
# Add the comment.
&blogComment($id,
name => $name,
message => $msg,
);
$root->{content} = "Comment Posted
\n\n"
. "Your comment has been posted. "
. "Return to the entry.";
# Send an e-mail to the site administrator.
$msg =~ s/
/\n/g;
my %smtp = (
Smtp => $root->{conf}->{mail}->{server},
From => "Starburst Blog <$root->{conf}->{mail}->{from}>",
To => $root->{conf}->{site}->{webmaster},
Subject => "New Blog Comment: $entry->{subject}",
Message => "Dear $root->{conf}->{site}->{title} Administrator:\n\n"
. "A new blog comment, written by $name, has been posted to your "
. "blog entry titled \"$entry->{subject}\"\n\n"
. "---\n"
. "$msg\n"
. "---\n\n"
. "Click the link below to view this entry and the new comment:\n"
. "http://$ENV{SERVER_NAME}/?p=blog;id=$id\n\n"
. "Note: this message was automatically generated. Do not reply "
. "to this e-mail.",
);
sendEmail(%smtp);
}
elsif ($action eq 'delete') {
$root->{content} = "Delete Comments
\n\n";
my $line = (defined $query->{line} ? $query->{line} : '');
# Make sure we have permission.
my $perm = &getBlogPermissions();
if ($perm eq 'authors') {
if (length $line > 0) {
# Request this line to be deleted.
&deleteComment($id,$line);
$root->{content} = "Comment Deleted
\n\n"
. "DO NOT REFRESH THIS PAGE. The comment on line $line "
. "has been deleted. "
. "Back to Entry.";
}
else {
$root->{content} = "Unknown Line
\n\n"
. "No valid comment entry was given.";
}
}
else {
$root->{content} = "Access Denied
\n\n"
. "You do not have permission to delete this comment.";
}
}