Skip to content

Commit

Permalink
Merge pull request #1083 from afuna/quicker-er-reply-bug-1078
Browse files Browse the repository at this point in the history
[#1078] Get quick reply working on the read page
  • Loading branch information
afuna committed Dec 6, 2014
2 parents 10a7289 + c280d71 commit 3fb1bc4
Show file tree
Hide file tree
Showing 15 changed files with 1,066 additions and 180 deletions.
2 changes: 2 additions & 0 deletions bin/upgrading/en.dat
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ collapsible.collapsed=Expand

collapsible.expanded=Collapse

comment.rpc.posted=Your comment has been posted.

contentflag.viewingconcepts.bycommunity=You are about to view content that a community administrator has advised should be viewed with discretion.

contentflag.viewingconcepts.byjournal=You're about to view content which the journal owner has advised should be viewed with discretion.
Expand Down
43 changes: 43 additions & 0 deletions cgi-bin/DW/Controller/RPC/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package DW::Controller::RPC::Misc;
use strict;
use LJ::JSON;
use DW::Routing;
use DW::Controller;

DW::Routing->register_rpc( "contentfilters", \&contentfilters_handler, format => 'json' );
DW::Routing->register_rpc( "extacct_auth", \&extacct_auth_handler, format => 'json' );
DW::Routing->register_rpc( "general", \&general_handler, format => 'json' );
DW::Routing->register_rpc( "addcomment", \&addcomment_handler, format => 'json', methods => { POST => 1 } );

sub contentfilters_handler {
my $r = DW::Request->get;
Expand Down Expand Up @@ -274,4 +276,45 @@ sub general_handler {
return DW::RPC->out( %ret );
}

sub addcomment_handler {
my $remote = LJ::get_remote();
my $r = DW::Request->get;
my $post = $r->post_args;

return DW::RPC->err( LJ::Lang::ml( 'error.invalidform' ) )
if $r->did_post && ! LJ::check_form_auth( $post->{lj_form_auth} );

# build the comment
my $req = {
ver => 1,

username => $remote->username,
journal => $post->{journal},
ditemid => $post->{itemid},
parent => $post->{parenttalkid},

body => $post->{body},
subject => $post->{subject},
prop_picture_keyword => $post->{prop_picture_keyword},

useragent => "rpc-addcomment",
};

# post!
my $post_error;
LJ::Protocol::do_request( "addcomment", $req, \$post_error, { noauth => 1, nocheckcap => 1 } );
return DW::RPC->err( LJ::Protocol::error_message( $post_error ) ) if $post_error;

# now get the comment count
my $entry;
my $uid = LJ::get_userid( $post->{journal} );
$entry = LJ::Entry->new( $uid, ditemid => $post->{itemid} ) if $uid;
$entry = undef unless $entry && $entry->valid;

my $count;
$count = $entry->reply_count( force_lookup => 1 ) if $entry;

return DW::RPC->out( message => LJ::Lang::ml( 'comment.rpc.posted' ), count => $count );
}

1;
10 changes: 7 additions & 3 deletions cgi-bin/LJ/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,13 @@ sub set_talkdata {
}

sub reply_count {
my $self = $_[0];
my $rc = $self->prop('replycount');
return $rc if defined $rc;
my ( $self, %opts ) = @_;

unless ( $opts{force_lookup} ) {
my $rc = $self->prop( 'replycount' );
return $rc if defined $rc;
}

return LJ::Talk::get_replycount($self->journal, $self->jitemid);
}

Expand Down
8 changes: 7 additions & 1 deletion cgi-bin/LJ/HTMLControls.pm
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ sub _html_option {
# is this individual option disabled?
my $dis = $item->{disabled} ? " disabled='disabled' style='color: #999;'" : '';

return "<option value=\"$value\"$id$sel$dis>" .
# are there additional data-attributes?
my $data_attribute = '';
if ( $item->{data} ) {
$data_attribute .= " data-$_='$item->{data}->{$_}'" foreach keys %{$item->{data} || {}};
}

return "<option value=\"$value\"$id$sel$dis$data_attribute>" .
( $ehtml ? ehtml( $text ) : $text ) . "</option>\n";
}

Expand Down
40 changes: 27 additions & 13 deletions cgi-bin/LJ/S2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ sub Entry
};
foreach ( qw( subject text journal poster new_day end_day
comments userpic permalink_url itemid tags timeformat24
admin_post ) ) {
admin_post dom_id ) ) {
$e->{$_} = $arg->{$_};
}

Expand Down Expand Up @@ -2227,6 +2227,7 @@ sub Entry_from_entryobj
moodthemeid => $moodthemeid,
timeformat24 => $remote && $remote->use_24hour_time,
admin_post => $entry_obj->admin_post,
dom_id => "entry-" . $journal->user . "-$ditemid",
} );

return $entry;
Expand Down Expand Up @@ -3584,6 +3585,8 @@ sub Comment__print_reply_link
_print_quickreply_link($ctx, $this, $opts);
}

*EntryLite__print_reply_link = \&_print_quickreply_link;
*Entry__print_reply_link = \&_print_quickreply_link;
*Page__print_reply_link = \&_print_quickreply_link;
*EntryPage__print_reply_link = \&_print_quickreply_link;

Expand All @@ -3594,13 +3597,15 @@ sub _print_quickreply_link
$opts ||= {};

# one of these had better work
my $replyurl = $opts->{'reply_url'} || $this->{'reply_url'} || $this->{'entry'}->{'comments'}->{'post_url'};
my $replyurl = $opts->{'reply_url'} || $this->{'reply_url'} # entrypage comments
|| $this->{'entry'}->{'comments'}->{'post_url'} # entrypage entry
|| $this->{comments}->{post_url}; # readpage entry

# clean up input:
my $linktext = LJ::ehtml($opts->{'linktext'}) || "";

my $target = $opts->{target} || '';
return unless $target =~ /^\w+$/; # if no target specified bail out
return unless $target =~ /^[\w-]+$/; # if no target specified bail out

my $opt_class = $opts->{class}|| '';
undef $opt_class unless $opt_class =~ /^[\w\s-]+$/;
Expand Down Expand Up @@ -3647,7 +3652,7 @@ sub _print_quickreply_link
$onclick = "onclick='$onclick'";
}

$onclick = "" unless $page->{'_type'} eq 'EntryPage';
$onclick = "" unless $page->{view} eq 'entry' || $page->{view} eq 'read';
$onclick = "" unless LJ::is_enabled('s2quickreply');
$onclick = "" if $page->{'_u'}->does_not_allow_comments_from( $remote );

Expand All @@ -3659,10 +3664,10 @@ sub _print_reply_container
my ($ctx, $this, $opts) = @_;

my $page = get_page();
return unless $page->{'_type'} eq 'EntryPage';
return unless $page->{view} eq 'entry' || $page->{view} eq 'read';

my $target = $opts->{target} || '';
undef $target unless $target =~ /^\w+$/;
undef $target unless $target =~ /^[\w-]+$/;

my $class = $opts->{class} || '';

Expand All @@ -3675,19 +3680,28 @@ sub _print_reply_container

$class = $class ? "class=\"$class\"" : "";

$S2::pout->("<div $class id=\"ljqrt$target\" style=\"display: none;\"></div>");
$S2::pout->("<div $class id=\"ljqrt$target\" data-quickreply-container=\"$target\" style=\"display: none;\"></div>");

# unless we've already inserted the big qrdiv ugliness, do it.
unless ($ctx->[S2::SCRATCH]->{'quickreply_printed_div'}++) {
my $u = $page->{'_u'};
my $ditemid = $page->{'entry'}{'itemid'} || 0;

my $userpic = LJ::ehtml($page->{'_picture_keyword'}) || "";
my $thread = $page->{_viewing_thread_id} + 0 || "";
$S2::pout->( LJ::create_qr_div( $u, $ditemid, $page->{_styleopts}, $userpic, $thread ) );
if ( $page->{view} eq "entry" || $page->{view} eq "read" ) {
my $u = $page->{'_u'};
my $ditemid = $page->{'entry'}{'itemid'} || $this->{itemid} || 0;

my $userpic = LJ::ehtml($page->{'_picture_keyword'}) || "";
my $thread = $page->{_viewing_thread_id} + 0 || "";
$S2::pout->( LJ::create_qr_div( $u, $ditemid,
style_opts => $page->{_styleopts},
userpic => $userpic,
thread => $thread,
minimal => $page->{view} eq "read",
) );
}
}
}

*EntryLite__print_reply_container = \&_print_reply_container;
*Entry__print_reply_container = \&_print_reply_container;
*Comment__print_reply_container = \&_print_reply_container;
*EntryPage__print_reply_container = \&_print_reply_container;
*Page__print_reply_container = \&_print_reply_container;
Expand Down
16 changes: 16 additions & 0 deletions cgi-bin/LJ/S2/FriendsPage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ sub FriendsPage

LJ::need_res( LJ::S2::tracking_popup_js() );

# load for icon browser
my @iconbrowser_extra_stylesheet;
@iconbrowser_extra_stylesheet = ( 'stc/jquery/jquery.ui.theme.smoothness.css' );
LJ::need_res( LJ::Talk::init_iconbrowser_js( 1, @iconbrowser_extra_stylesheet ) )
if $remote && $remote->can_use_userpic_select;

# load for quick reply
LJ::need_res( { group => "jquery" }, qw(
js/jquery/jquery.ui.core.js
stc/jquery/jquery.ui.core.css
js/jquery/jquery.ui.widget.js
js/jquery.quickreply.js
stc/css/components/quick-reply.css
js/jquery.threadexpander.js
) );

# load for ajax cuttag
LJ::need_res( 'js/cuttag-ajax.js' );
LJ::need_res( { group => "jquery" }, qw(
Expand Down
Loading

0 comments on commit 3fb1bc4

Please sign in to comment.