summaryrefslogtreecommitdiff
path: root/cgi-bin/comment
blob: 01a763b0625857debaaa96d3a630be0ee36f1930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/perl
#########################################
# comment
# redundant w/ post: add a comment/files to a thread
#########################################

use localbucky;

my $pid;

$dbh = DBI->connect ($dsn);

our ($USER, $lastlog) = checkin();
logout() unless ($USER != -1);

$input->{id} ||= $input->{object_from_uri} if defined($input->{object_from_uri});
$input->{id} =~ s/\D*//g;
if ($input->{c} eq "edit")
	{
	my $header_args;
	my $comment = get_comment($input->{id});
	error("No such comment!") if ($comment == -1);
	my $thread  = get_thread($comment->{thread});
	my $keyword = get_keyword($thread->{keyword});
	error("Cannot edit comment!") unless ($USER->{username} eq $BUCKY_ADMINISTRATOR || $USER->{username} eq $comment->{username} || (check_key($thread->{display}, "editable") && check_privacy($thread, $keyword)));

	$header_args->{title}	 = qq(editing comment . . .); 
	$header_args->{subtitle} = qq(<span class="lite"><a href="$BUCKY/).details_link($thread).qq(/$comment->{thread}">back to post</a> &middot; $thread->{title}</span>),
	$header_args->{color}	 = "ivory";

	header ($header_args);
	menu();
	print <<duh;
<table width=100% border=0 cellpadding=0 cellspacing=5>
<tr><td align=center valign=top width=100%><div style="width: 399px;">
duh
	curt_post_form($comment);
	print qq!</td></tr></table>\n!;
	footer();
	}
elsif ($input->{c} eq "delete")
	{
	my $header_args;
	my $comment = get_comment($input->{id});
	error("No such comment!") if ($comment == -1);
	my $thread  = get_thread($comment->{thread});
	my $keyword = get_keyword($thread->{keyword});
	error("Cannot delete comment!") unless ($USER->{username} eq $BUCKY_ADMINISTRATOR || $USER->{username} eq $comment->{username} || (check_key($thread->{display}, "editable") && check_privacy($thread, $keyword)));

	if ($input->{ok} eq "yes")
		{
		delete_comment($comment->{id});
		redirect("$BUCKY/".details_link($thread)."/$comment->{thread}".get_revision($thread));
		}
	else
		{
		$header_args->{title}	 = qq(delete comment?); 
		$header_args->{subtitle} = qq(<span class="lite"><a href="$BUCKY/).details_link($thread).qq(/$comment->{thread}">back to post</a> ($thread->{title})</span>);
		$header_args->{color}	 = "ivory";

		header ($header_args);
		menu();
		print qq!<center><p><div class="bluebox" style="width: 320px; padding: 10px;"><big><b>Are you sure you want to !;
		print qq!delete this comment?</b></big><hr noshade color="$BUCKY_COLOR_HR"><p>\n!;
		my $subcomment = substr($comment->{comment}, 0, 64);
		$subcomment =~ s/</&lt;/g;
		$subcomment =~ s/>/&gt;/g;
		$subcomment =~ s/"/&quot;/g;
		print "<p>".$subcomment."</p>";
		print qq!<form action="$BUCKY/comment" method="post" enctype="multipart/form-data">!;
		print qq(<input type=hidden name="c" value="delete">\n);
		print qq(<input type=hidden name="id" value="$comment->{id}">\n);
		print qq(<input type=hidden name="debug" value="1">\n) if ($DEBUG);
		print qq(<input type=hidden name="ok" value="yes">\n);

		print qq(<br><input type="submit" value="DELETE" class="clicky"></form></div></center>);
		print qq(</td></tr></table>\n);
		footer();
		}
	}
elsif ($input->{c} eq "reply")
	{
	my $header_args;
	my $comment = -1;
	my $thread = -1;
	my $keyword = -1;
	if (exists($input->{id}))
		{
		$comment = get_comment($input->{id});
		error("No such comment!") if ($comment == -1);
		$thread  = get_thread($comment->{thread});
		}
	elsif (exists($input->{thread}))
		{
		$thread  = get_thread($input->{thread});
		}
	my $keyword = get_keyword($thread->{keyword});
	error("Cannot see comment!") unless (check_privacy($thread) || check_op($keyword));

	$header_args->{title}	 = qq(reply to comment . . .); 
	$header_args->{subtitle} = qq(<span class="lite"><a href="$BUCKY/).details_link($thread).qq(/$comment->{thread}">back to post</a> &middot; $thread->{title}</span>);
	$header_args->{color}	 = "ivory";

	header ($header_args);
	menu();
	print <<duh;
<table width=100% border=0 cellpadding=0 cellspacing=5>
<tr><td align=center valign=top width=100%><div style="width: 399px;">
duh
	curt_reply_form($comment, $thread, $keyword);
	print qq!</td></tr></table>\n!;
	footer();
	}
elsif ($input->{c} eq "update")
	{
	my $comment = get_comment($input->{id});
	error("No such comment!") if ($comment == -1);
	my $thread  = get_thread($comment->{thread});
	my $keyword = get_keyword($thread->{keyword});
	error("Cannot edit comment!") unless ($USER->{username} eq $BUCKY_ADMINISTRATOR || $USER->{username} eq $comment->{username} || (check_key($thread->{display}, "editable") && check_privacy($thread, $keyword)));
	update_comment($input->{id}, $input->{comment}) if ($input->{comment});
	touch_thread($thread);

	if ($comment->{thread} == 1)
		{
 		redirect("$BUCKY/index");
		}
	else
		{
		redirect("$BUCKY/".details_link($thread)."/$comment->{thread}".get_revision($thread));
		}
	}
elsif ($input->{id} == 1)
	{
	add_comment($input->{id}, -1, $USER->{username}, $input->{comment}) if ($input->{comment});
 	redirect("$BUCKY/index");
	}
else
	{
	my $pid;
	my $t;
	my $keyword;
	if ($DEBUG)
		{
		header ("adding message to $input->{id}");
		print "adding message to $input->{id}:<p><tt>";
		}

	$t = get_thread($input->{id});
	if ($t == -1)
		{
		flush_files();
		redirect("$BUCKY/".details_link($t)."/$comment->{thread}".get_revision($t));
		}
	$keyword = get_keyword($thread->{keyword});
#	error("No such thread!") unless ($t != -1 && check_privacy($t, $keyword));

	if (exists($input->{parent_id}))
		{
		my $headc = get_comment($input->{parent_id});
		error("No such comment!") if ($headc == -1);
		if ($headc->{parent_id} != -1)
			{ $pid = $headc->{parent_id}; }
		else
			{ $pid = $headc->{id}; }
		}
	else
		{
		$pid = -1;
		}

	add_comment($t->{id}, $pid, $USER->{username}, $input->{comment}) if ($input->{comment});
	situate_files($t->{id}, $USER->{username});
	touch_thread($t);
	redirect("$BUCKY/".details_link($t)."/$t->{id}".get_revision($t));
	switch_file_privacy($t->{id}, $t->{private});
	}

if ($DEBUG)
	{
	footer ();
	}

$dbh->disconnect ();

print "Comment: " . &report_time() . "\n" if $timer;