forked from dreamwidth/dreamwidth
/
talkscreen.bml
249 lines (217 loc) · 9.41 KB
/
talkscreen.bml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?_c
# This code was forked from the LiveJournal project owned and operated
# by Live Journal, Inc. The code has been modified and expanded by
# Dreamwidth Studios, LLC. These files were originally licensed under
# the terms of the license supplied by Live Journal, Inc, which can
# currently be found at:
#
# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
#
# In accordance with the original license, this code and all its
# modifications are provided under the GNU General Public License.
# A copy of that license can be found in the LICENSE file included as
# part of this distribution.
_c?>
<?_info
nocache=>1
_info?><?_code
{
use strict;
use vars qw(%GET %POST);
use vars qw($body);
use LJ::JSON;
my $jsmode = !!$GET{jsmode};
$body = "";
# explicitly set language scope for use when called as an
# endpoint from users' journals:
BML::set_language_scope('/talkscreen.bml');
my $error = sub {
if ($jsmode) {
BML::finish();
# FIXME: remove once we've switched over completely to jquery
if ( !!$GET{json} ) {
return to_json( { error => $_[0] } );
} else {
return "alert('" . LJ::ejs($_[0]) . "'); 0;";
}
}
$body = "<?h1 $ML{'Error'} h1?><?p $_[0] p?>";
return;
};
my $bad_input = sub {
return $error->("Bad input: $_[0]") if $jsmode;
$body = LJ::bad_input($_[0]);
return;
};
my $mode = $POST{'mode'} || $GET{'mode'};
my $talkid = $POST{'talkid'} || $GET{'talkid'};
my $journal = $POST{'journal'} || $GET{'journal'};
my $qtalkid = $talkid+0;
my $dtalkid = $qtalkid; # display talkid, for use in URL later
my $jsres = sub {
my ( $mode, $message ) = @_;
# flip case of 'un'
my $newmode = "un$mode";
$newmode =~ s/^unun//;
my $alttext = $newmode;
$alttext =~ s/(\w+)/\u\L$1/g;
my $stockimg = {
'screen' => "silk/comments/screen.png",
'unscreen' => "silk/comments/unscreen.png",
'freeze' => "silk/comments/freeze.png",
'unfreeze' => "silk/comments/unfreeze.png",
};
my %ret = (
id => $dtalkid,
mode => $mode,
newalt => $alttext,
oldimage => "$LJ::IMGPREFIX/$stockimg->{$mode}",
newimage => "$LJ::IMGPREFIX/$stockimg->{$newmode}",
newurl => "$LJ::SITEROOT/talkscreen?mode=$newmode&journal=$journal&talkid=$dtalkid",
msg => $message,
);
sleep 1 if $LJ::IS_DEV_SERVER;
BML::finish();
return to_json( \%ret );
};
my $remote = LJ::get_remote();
return $error->($ML{'.error.login'}) unless $remote;
# we need to find out: $u, $up (poster of the entry this is a comment to),
# userpost (username of this comment's author). Then we can check permissions.
my $u = LJ::load_user($journal);
return $error->($ML{'talk.error.bogusargs'}) unless $u;
# if we're on a user vhost, our remote was authed using that vhost,
# so let's let them only modify the journal that their session
# was authed against. if they're on www., then their javascript is
# off/old, and they get a confirmation page, and we're using their
# mastersesion cookie anyway.
my $domain_owner = LJ::Session->url_owner;
if ($LJ::ONLY_USER_VHOSTS && $domain_owner) {
return $bad_input->("URL doesn't match journal owner") unless $domain_owner eq $u->{user};
}
my $dbcr = LJ::get_cluster_def_reader($u);
return $error->($ML{'error.nodb'}) unless $dbcr;
my $post;
$qtalkid = int($qtalkid / 256); # get rid of anum
$post = $dbcr->selectrow_hashref("SELECT jtalkid AS 'talkid', nodetype, state, nodeid AS 'itemid', ".
"parenttalkid, journalid, posterid FROM talk2 ".
"WHERE journalid=$u->{'userid'} AND jtalkid=$qtalkid");
return $error->($ML{'talk.error.nocomment'}) unless $post;
return $error->($ML{'talk.error.comm_deleted'}) if $post->{'state'} eq "D";
my $state = $post->{'state'};
$u ||= LJ::load_userid($post->{'journalid'});
return $error->($LJ::MSG_READONLY_USER) if $u->is_readonly;
if ($post->{'posterid'}) {
$post->{'userpost'} = LJ::get_username($post->{'posterid'});
}
my $qitemid = $post->{'itemid'}+0;
my $e = LJ::Entry->new( $u, jitemid => $qitemid );
my $up = $e->poster;
my $itemlink = $e->url;
my $linktext = BML::ml( '.link', { aopts => "href='$itemlink'" } );
if ($mode eq 'screen') {
my $can_screen = LJ::Talk::can_screen($remote, $u, $up, $post->{'userpost'});
return $error->($ML{'.error.privs.screen'}) unless $can_screen;
if ($POST{'confirm'} eq 'Y') {
return $error->( $ML{'error.invalidform'} ) unless LJ::check_form_auth();
} else {
$body .= "<?h1 $ML{'.screen.sure.title'} h1?><?p $ML{'.screen.sure.body'} p?>";
$body .= "<p><form method='POST' action='talkscreen'><center>\n";
$body .= LJ::form_auth();
$body .= LJ::html_hidden(mode => 'screen', 'talkid' => $talkid,
journal => $u->{user}, confirm => 'Y');
$body .= LJ::html_submit(undef, $ML{'.screen.doit'});
$body .= "</center>";
$body .= "</form>\n";
return;
}
if ($state ne 'S') {
LJ::Talk::screen_comment($u, $qitemid, $qtalkid);
}
# FIXME: no error checking?
return $jsres->($mode, $ML{'.screened.body'}) if $jsmode;
$body = "<?h1 $ML{'.screened.title'} h1?><?p $ML{'.screened.body'} $linktext p?>";
return;
}
if ($mode eq 'unscreen') {
my $can_unscreen = LJ::Talk::can_unscreen($remote, $u, $up, $post->{'userpost'});
return $error->($ML{'.error.privs.unscreen'}) unless $can_unscreen;
if ($POST{'confirm'} eq 'Y') {
return $error->( $ML{'error.invalidform'} ) unless LJ::check_form_auth();
} else {
$body .= "<?h1 $ML{'.unscreen.sure.title'} h1?><?p $ML{'.unscreen.sure.body'} p?>";
$body .= "<p><form method='POST' action='talkscreen'><center>\n";
$body .= LJ::form_auth();
$body .= LJ::html_hidden(mode => 'unscreen', 'talkid' => $talkid,
journal => $u->{user}, confirm => 'Y');
$body .= LJ::html_submit(undef, $ML{'.unscreen.doit'});
$body .= "</center>";
$body .= "</form>\n";
return;
}
if ($state ne 'A') {
LJ::Talk::unscreen_comment($u, $qitemid, $qtalkid);
}
# FIXME: no error checking?
return $jsres->($mode, $ML{'.unscreened.body'}) if $jsmode;
$body = "<?h1 $ML{'.unscreened.title'} h1?><?p $ML{'.unscreened.body'} $linktext p?>";
return;
}
if ($mode eq 'freeze') {
my $can_freeze = LJ::Talk::can_freeze($remote, $u, $up, $post->{userpost});
unless ($can_freeze) {
$body = "<?h1 $ML{'Error'} h1?><?p $ML{'.error.privs.freeze'} p?>";
return;
}
if ($POST{confirm} eq 'Y') {
return $error->( $ML{'error.invalidform'} ) unless LJ::check_form_auth();
} else {
$body .= "<?h1 $ML{'.freeze.sure.title'} h1?><?p $ML{'.freeze.sure.body'} p?>";
$body .= "<p><form method='post' action='talkscreen'><center>\n";
$body .= LJ::form_auth();
$body .= LJ::html_hidden(mode => 'freeze', 'talkid' => $talkid,
journal => $u->{user}, confirm => 'Y');
$body .= LJ::html_submit(undef, $ML{'.freeze.doit'});
$body .= "</center>";
$body .= "</form>\n";
return;
}
if ($state ne 'F') {
LJ::Talk::freeze_thread($u, $qitemid, $qtalkid);
}
return $jsres->($mode, $ML{'.frozen.body'}) if $jsmode;
$body = "<?h1 $ML{'.frozen.title'} h1?><?p $ML{'.frozen.body'} $linktext p?>";
return;
}
if ($mode eq 'unfreeze') {
my $can_unfreeze = LJ::Talk::can_unfreeze($remote, $u, $up, $post->{userpost});
unless ($can_unfreeze) {
$body = "<?h1 $ML{'Error'} h1?><?p You are not allowed to unfreeze this thread p?>";
return;
}
if ($POST{confirm} eq 'Y') {
return $error->( $ML{'error.invalidform'} ) unless LJ::check_form_auth();
} else {
$body .= "<?h1 $ML{'.unfreeze.sure.title'} h1?><?p $ML{'.unfreeze.sure.body'} p?>";
$body .= "<p><form method='post' action='talkscreen'><center>\n";
$body .= LJ::form_auth();
$body .= LJ::html_hidden(mode => 'unfreeze', 'talkid' => $talkid,
journal => $u->{user}, confirm => 'Y');
$body .= LJ::html_submit(undef, $ML{'.unfreeze.doit'});
$body .= "</center></form>\n";
return;
}
if ($state eq 'F') {
LJ::Talk::unfreeze_thread($u, $qitemid, $qtalkid);
}
return $jsres->($mode, $ML{'.unfrozen.body'}) if $jsmode;
$body = "<?h1 $ML{'.unfrozen.title'} h1?><?p $ML{'.unfrozen.body'} $linktext p?>";
return;
}
$body = "<?h1 $ML{'Error'} h1?><?p $ML{'error.unknownmode'} p?>";
return;
}
_code?><?page
title=><?_ml .title2 _ml?>
body=><?_code return $body; _code?>
page?>