Committer: ailyin
LJINT-362 (Comments for side projects): checkpoint commitU trunk/bin/upgrading/update-db-general.pl U trunk/cgi-bin/LJ/Comment.pm U trunk/cgi-bin/LJ/Identity.pm U trunk/cgi-bin/LJ/Talk.pm U trunk/cgi-bin/LJ/Widget/LoginMulti.pm U trunk/cgi-bin/weblib.pl U trunk/htdocs/gadgets/logcom.bml U trunk/htdocs/talkpost_do.bml U trunk/templates/CommentForm/FormEmbedable.tmpl
Modified: trunk/bin/upgrading/update-db-general.pl =================================================================== --- trunk/bin/upgrading/update-db-general.pl 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/bin/upgrading/update-db-general.pl 2010-12-30 12:25:26 UTC (rev 18005) @@ -3414,17 +3414,6 @@ ) Type=InnoDB EOC -register_tablecreate("exturl2entry_map", <<'EOC'); -CREATE TABLE exturl2entry_map ( - userid int(11) NOT NULL, - url_md5 varchar(22) default NULL, - jitemid int(11) NOT NULL, - - KEY userid (userid,url_md5) - - ) ENGINE=InnoDB -EOC - ### changes register_alter(sub { Modified: trunk/cgi-bin/LJ/Comment.pm =================================================================== --- trunk/cgi-bin/LJ/Comment.pm 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/cgi-bin/LJ/Comment.pm 2010-12-30 12:25:26 UTC (rev 18005) @@ -17,6 +17,7 @@ require "htmlcontrols.pl"; require "talklib.pl"; use LJ::TimeUtil; +use LJ::PartnerSite; use Encode(); @@ -1463,6 +1464,7 @@ my $parent = $self->parent || $self->entry; my $entry = $self->entry; + my $journal = $entry->journal; my $posteru = $self->poster; my $encoding = $targetu->mailencoding || 'UTF-8'; @@ -1511,6 +1513,20 @@ $t->param(parent_dtalkid => $self->parent->dtalkid); } + my $partner + = LJ::PartnerSite->find_by_journal_username($journal->username); + + if ( defined $partner ) { + my $docid = $partner->docid_from_entry($entry); + my $article_link = $partner->article_link($docid); + my $comment_link + = $partner->article_link( $docid, + { 'thread' => $self->dtalkid } ); + + $t->param( 'article_link' => $article_link, + 'comment_link' => $comment_link, ); + + } } # Processes template for HTML e-mail notifications @@ -1520,12 +1536,14 @@ my $targetu = shift; # target user, who should be notified about the comment my $t = shift; # LJ::HTML::Template object - template of the notification e-mail - my $parent = $self->parent || $self->entry; + my $entry = $self->entry; + my $parent = $self->parent; $self->_format_template_mail($targetu, $t); # add specific for HTML params - $t->param(parent_text => LJ::Talk::Post::blockquote($parent->body_html)); + $t->param(parent_text => LJ::Talk::Post::blockquote($parent ? $parent->body_html + : $entry->event_html )); $t->param(poster_text => LJ::Talk::Post::blockquote($self->body_html)); my $email_subject = $self->subject_html; Modified: trunk/cgi-bin/LJ/Identity.pm =================================================================== --- trunk/cgi-bin/LJ/Identity.pm 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/cgi-bin/LJ/Identity.pm 2010-12-30 12:25:26 UTC (rev 18005) @@ -209,18 +209,9 @@ "jid=$journalid&" . "pendcid=$pendcid"; $returl_fail = $returl . '&failed=1'; - } elsif ($forwhat =~ /^external-/) { - my (undef, $journalid, $ditemid, $dtalkid) = split /-/, $forwhat; - my $journal = LJ::load_userid($journalid); - my $entry = LJ::Entry->new($journal, 'ditemid' => $ditemid); - - my $uri = URI->new( $entry->prop('external_url') ); - if ($dtalkid) { - $uri->query_form( $uri->query_form, 'replyto' => $dtalkid ); - $uri->fragment( 't' . $dtalkid ); - } - - $returl = $returl_fail = $uri->as_string; + } elsif ($forwhat eq 'external') { + $returl = "$LJ::SITEROOT/gadgets/external-landing.bml?success"; + $returl_fail = "$LJ::SITEROOT/gadgets/external-landing.bml?fail"; } else { # the warning will sit in error logs, and the exception # will be handled Modified: trunk/cgi-bin/LJ/Talk.pm =================================================================== --- trunk/cgi-bin/LJ/Talk.pm 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/cgi-bin/LJ/Talk.pm 2010-12-30 12:25:26 UTC (rev 18005) @@ -1852,6 +1852,7 @@ }) || undef, 'logout_url' => $opts->{'logout_url'}, + 'js_check_domain' => $opts->{'js_check_domain'}, ); return $template->output; Modified: trunk/cgi-bin/LJ/Widget/LoginMulti.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/LoginMulti.pm 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/cgi-bin/LJ/Widget/LoginMulti.pm 2010-12-30 12:25:26 UTC (rev 18005) @@ -22,15 +22,17 @@ ## Handle auth params if (LJ::Request->did_post) { - do_login($thispage, $forwhat, \@errors); + do_login($thispage, $forwhat, \@errors, \%opts); ## where to go on success? return if LJ::Request->redirected; } + my $filename = $opts{'embedded'} ? 'ExternalLogin' : 'Login'; + ## Draw widget my $template = LJ::HTML::Template->new( { use_expr => 1 }, # force HTML::Template::Pro with Expr support - filename => "$ENV{'LJHOME'}/templates/Identity/Login.tmpl", + filename => "$ENV{'LJHOME'}/templates/Identity/$filename.tmpl", die_on_bad_params => 0, strict => 0, ) or die "Can't open template: $!"; @@ -50,10 +52,17 @@ my @types; if ($opts{'lj_auth'}) { - push @types, { - type => 'user', - ml_tab_heading => LJ::Lang::ml("/identity/login.bml.tab.user"), + my $type_display = { + 'type' => 'user', + 'ml_tab_heading' => LJ::Lang::ml("/identity/login.bml.tab.user"), + 'user_returnto' => $opts{'user_returnto'}, }; + + if ( $opts{'embedded'} ) { + $template->param( 'type_user' => [ $type_display ] ); + } + + push @types, $type_display; } ## external auth @@ -69,13 +78,21 @@ if ($type eq $current_type) { $type_display->{'errors'} = [ map { { 'error' => $_ } } @errors ]; } + + if ( $opts{'embedded'} ) { + $template->param( 'type_' . $type => [ $type_display ] ); + } push @types, $type_display; } + unless ( $opts{'embedded'} ) { + $template->param( 'types' => \@types ); + } + $template->param( - 'types' => \@types, - 'current_type' => $current_type, - 'returnto' => $thispage, + 'current_type' => $current_type, + 'returnto' => $thispage, + 'js_check_domain' => $opts{'js_check_domain'}, ); ## well cooked widget is here @@ -83,9 +100,7 @@ } sub do_login { - my $thispage = shift; - my $forwhat = shift; - my $errors = shift; + my ( $thispage, $forwhat, $errors, $opts ) = @_; my $idtype = LJ::Request->post_param('type'); ## Special case: perform LJ.com login. @@ -143,7 +158,9 @@ ## Where to go? my $returnto = LJ::Request->post_param("returnto") || $thispage; my $returl_fail = "$thispage?type=$idtype"; - unless ( $returnto =~ m!^https?://\Q$LJ::DOMAIN_WEB\E/! ) { + if ( $opts->{'embedded'} + || $returnto !~ m!^https?://\Q$LJ::DOMAIN_WEB\E/! ) + { ($returnto, $returl_fail) = LJ::Identity->unpack_forwhat($forwhat); } Modified: trunk/cgi-bin/weblib.pl =================================================================== --- trunk/cgi-bin/weblib.pl 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/cgi-bin/weblib.pl 2010-12-30 12:25:26 UTC (rev 18005) @@ -1278,7 +1278,10 @@ sub include_raw { my $type = shift; my $code = shift; - die "Bogus include type: $type" unless $type =~ m!^(js|css)$!; + + die "Bogus include type: $type" + unless $type =~ m!^(js|css|js_link|css_link)$!; + push @LJ::INCLUDE_RAW => [$type, $code]; } @@ -1478,11 +1481,17 @@ return $ret if $only_needed; # add raw js/css - foreach my $inc (@LJ::INCLUDE_RAW){ - if ($inc->[0] eq 'js'){ - $ret .= qq|<script type="text/javascript">\r\n| . $inc->[1] . "</script>\r\n"; - } elsif ($inc->[0] eq 'css'){ - $ret .= qq|<style>\r\n| . $inc->[1] . "</style>\n"; + foreach my $inc (@LJ::INCLUDE_RAW) { + my ( $type, $code ) = @$inc; + + if ($type eq 'js'){ + $ret .= qq|<script type="text/javascript">\r\n$code</script>\r\n|; + } elsif ($type eq 'css'){ + $ret .= qq|<style>\r\n$code</style>\n|; + } elsif ( $type eq 'js_link' ) { + $ret .= qq{<script type="text/javascript" src="$code"></script>\r\n}; + } elsif ( $type eq 'css_link' ) { + $ret .= qq{<link rel="stylesheet" type="text/css" href="$code" />}; } } Modified: trunk/htdocs/gadgets/logcom.bml =================================================================== --- trunk/htdocs/gadgets/logcom.bml 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/htdocs/gadgets/logcom.bml 2010-12-30 12:25:26 UTC (rev 18005) @@ -8,62 +8,29 @@ return 'This feature is disabled' unless LJ::is_enabled('external_comments'); - LJ::need_res(qw( js/partners/placeholder.js - js/jquery.js - stc/lj_base.css - stc/partners/login.css )); - my $thispage = "$LJ::SITEROOT/gadgets/logcom.bml"; $thispage .= "?" . LJ::Request->args; - my $url = $GET{url}; - my $rskey = $GET{rsk}; + my $docid = LJ::Request->get_param('docid'); + my $api_key = LJ::Request->get_param('rsk'); ## convert remote-site key to lj.com's community - my $username = LJ::ExternalComments->key_to_username($rskey); - return "unknown key" unless $username; + my $partner = LJ::PartnerSite->find_by_api_key($api_key); + return 'unknown key' + unless $partner; - my $journal = LJ::load_user($username); - return "unknown user" unless $journal; + $partner->request_logcom_resources; + my $journal = $partner->journal; + return 'rate limit exceeded' - unless LJ::RateLimit->check( $journal, - $LJ::PARTNER_RATE_LIMITS{$username} ); + unless LJ::RateLimit->check( $journal, $partner->rate_limits ); - my $domains = $LJ::PARTNER_DOMAINS{$username}; - my $domains_out = LJ::JSON->to_json($domains); - my $js_check_domain = qq[ - <script type="text/javascript"> - var trustedDomains = $domains_out; - - var domainMatch = checkDomain(window.location.href, trustedDomains); + my $js_check_domain = $partner->domain_check_js( { 'mode' => 'logcom' } ); - if (!domainMatch) { - window.location.href = 'about:blank'; - } + my $entry = $partner->find_entry_by_docid($docid); + my $jitemid = $entry->jitemid; - function checkDomain(href, trustedDomains) { - var currentDomain = href.match(] .q{/(http\:\/\/)(?:www\.)?([^\/]*)/} . qq[)[2]; - - for (var i = 0, l = trustedDomains.length; i < l; i++) { - if (trustedDomains[i] == currentDomain) { - return true; - } - } - - return false; - } - </script> - ]; - - ## convert article's uri on partners site to entryid on LJ.com - my $jitemid = LJ::ExternalComments->url_to_jitemid($journal, $url); - unless ($jitemid){ - ## create new empty entry for this url - $jitemid = LJ::ExternalComments->create_entry_for_url($journal, $url); - return "Can't create new entry" unless $jitemid; - } - my $replyto = LJ::Request->get_param('replyto'); if ($replyto) { @@ -72,9 +39,7 @@ unless $parent->valid; } - my $entry = LJ::Entry->new($journal, jitemid => $jitemid); - - if (my $remote = LJ::get_remote() and not $GET{viewform}){ + if (my $remote = LJ::get_remote() and not LJ::Request->get_param('viewform')) { ## show add comment form LJ::need_res(qw( stc/partners/login.css )); @@ -89,15 +54,15 @@ return LJ::Talk::talkform({ - remote => $remote, - journalu => $journal, - ditemid => $entry->ditemid, - embedable_form => 1, - replyto => int ($replyto / 256), - logout_url => $logout_url, - }); + 'embedable_form' => 1, + 'logout_url' => $logout_url, + 'js_check_domain' => $js_check_domain, - + 'remote' => $remote, + 'journalu' => $journal, + 'ditemid' => $entry->ditemid, + 'replyto' => int ($replyto / 256), + }); } else { ## display login widget LJ::need_res(qw( @@ -105,28 +70,17 @@ stc/partners/login.css )); - my $forwhat = 'external-' . - $journal->userid . '-' . - $entry->ditemid . '-' . - $replyto; + my $w = LJ::Widget::LoginMulti->new; + $w->{'no_container_div'} = 1; - my $uri = URI->new($url); - if ($replyto) { - $uri->query_form( $uri->query_form, 'replyto' => $replyto ); - $uri->fragment( 't' . $replyto ); - } + return $w->render( + 'embedded' => 1, + 'js_check_domain' => $js_check_domain, - my $ret = ""; - $ret .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> - <html> - <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> - <head> - <title>Log in</title> - " . LJ::res_includes() . " - <body>" - . LJ::Widget::LoginMulti->render(thispage => $uri->as_string, forwhat => $forwhat, lj_auth => 1,) - ."</body></html>"; - return $ret; + 'forwhat' => 'external', + 'thispage' => $thispage, + 'lj_auth' => 1, + ); } } Modified: trunk/htdocs/talkpost_do.bml =================================================================== --- trunk/htdocs/talkpost_do.bml 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/htdocs/talkpost_do.bml 2010-12-30 12:25:26 UTC (rev 18005) @@ -1,13 +1,20 @@ -<?page -body<= <?_code { +#line 3 use strict; - use vars qw(%POST %ML %GET $title); + our ( %ML, %GET, %POST, $title, $body ); + my @errors; my $skip_form_auth = 0; + my $external_site_case = $POST{'is_form_embedded'}; + my $site_scheme_wrap = ! $external_site_case; + + # indentation inside this subroutine is intentionally screwed + # to reduce the diff size ;-) + my $render_body = sub { + # stupid hack to allow hotmail people to post, since hotmail changes # POST forms to GET. this isn't a security problem (GET -> POST escalation) # since talklib.pl's LJ::Talk::Post::init checks for $POST{'ecphash'} @@ -114,6 +121,8 @@ $require_tos = 1; } + my $entry = LJ::Entry->new( $journalu, ditemid => $POST{'itemid'} ); + if (! $init || $require_tos) { my ($sth, $parpost); my $dbcr = LJ::get_cluster_def_reader($journalu); @@ -128,16 +137,55 @@ $POST{replyto} = $POST{parenttalkid}+0 unless exists $POST{replyto}; $POST{edit} = $POST{editid}; # talkform expects the editid to be in "edit" - return LJ::Talk::talkform({ 'remote' => $remote, - 'journalu' => $journalu, - 'parpost' => $parpost, - 'replyto' => $POST{replyto}, - 'ditemid' => $POST{itemid}, - 'require_tos' => $require_tos, - 'do_captcha' => $need_captcha, - 'stylemine' => $GET{'style'} eq "mine", - 'errors' => \@errors, - 'form' => \%POST }); + + my $talkform_opts = { + 'remote' => $remote, + 'journalu' => $journalu, + 'parpost' => $parpost, + 'replyto' => $POST{replyto}, + 'ditemid' => $POST{itemid}, + 'require_tos' => $require_tos, + 'do_captcha' => $need_captcha, + 'stylemine' => $GET{'style'} eq "mine", + 'errors' => \@errors, + 'form' => \%POST, + }; + + if ( $external_site_case ) { + $talkform_opts->{'embedable_form'} = 1; + + my $remote_sessid; + if ($remote) { + $remote_sessid = $remote->session->id; + } + + my $partner + = LJ::PartnerSite->find_by_journal_username( + $journalu->username ); + + my $docid = $partner->docid_from_entry($entry); + + my $replyto = $POST{'replyto'} + ? int ( $POST{'replyto'} ) * 256 + $entry->anum + : 0; + + my $logcom_page = "$LJ::SITEROOT/gadgets/logcom.bml?" . + 'docid=' . $docid . '&' . + 'rsk=' . $partner->api_key . '&' . + 'replyto=' . $replyto; + + my $logout_url = "$LJ::SITEROOT/gadgets/logout.bml?" . + 'returnto=' . LJ::eurl($logcom_page) . '&' . + 'sessid=' . $remote_sessid; + + $talkform_opts->{'logout_url'} = $logout_url; + $talkform_opts->{'js_check_domain'} + = $partner->domain_check_js( { 'mode' => 'logcom' } ); + + $partner->request_logcom_resources; + } + + return LJ::Talk::talkform($talkform_opts); } # checked $POST{agree_tos} was checked above if it was necessary, @@ -152,7 +200,6 @@ my $talkurl = $init->{talkurl}; my $entryu = $init->{entryu}; - my $journalu = $init->{journalu}; my $parent = $init->{parent}; my $comment = $init->{comment}; my $item = $init->{item}; @@ -168,7 +215,6 @@ if $parent->{state} eq 'F'; # no replying to suspended entries, even by entry poster - my $entry = LJ::Entry->new($journalu, jitemid => $item->{jitemid}); return LJ::bad_input($ML{'/talkpost.bml.error.noreply_suspended'}) if $entry && $entry->is_suspended; @@ -198,9 +244,21 @@ my $stylemine = $POST{'stylemine'} ? 'style=mine' : ''; my $commentlink; - if ($POST{'is_form_embedded'}) { - $commentlink = $entry->prop('external_url') - . '?view=' . $dtalkid . '#t' . $dtalkid; + if ($external_site_case) { + my $partner + = LJ::PartnerSite->find_by_journal_username($journalu->username); + + my $uri = URI->new( $partner->xdreceiver_url ); + + my $parentid = $parent->{'talkid'} + ? $parent->{'talkid'} * 256 + $entry->anum + : 0; + + $uri->query_form( $uri->query_form, + 'comment_id' => $dtalkid, + 'replyto' => $parentid, ); + + $commentlink = $uri->as_string; } elsif ($POST{'viewing_thread'} eq '') { $commentlink = LJ::Talk::talkargs($talkurl, "view=$dtalkid", $stylemine) . "#t$dtalkid"; } else { @@ -244,16 +302,27 @@ # Sucessful! $title = $ML{'.title'}; - return $ret; + + }; # end $render_body + + my $body = $render_body->(); + + my $head + = ! $LJ::REQ_HEAD_HAS{'chalresp_js'}++ + ? $LJ::COMMON_CODE{'chalresp_js'} + : ""; + + if ($site_scheme_wrap) { + return BML::render_page({ + 'body' => $body, + 'title' => $title, + 'head' => $head, + }); + } else { + return $body; + } } -_code?> - -<=body -title=><?_code return $title _code?> -head<= -<?_code return (! $LJ::REQ_HEAD_HAS{'chalresp_js'}++) ? $LJ::COMMON_CODE{'chalresp_js'} : ""; _code?> -<=head -page?><?_c <LJDEP> +_code?><?_c <LJDEP> lib: LJ::SpellCheck link: htdocs/lostinfo.bml, htdocs/userinfo.bml, htdocs/talkread.bml post: htdocs/talkpost_do.bml Modified: trunk/templates/CommentForm/FormEmbedable.tmpl =================================================================== --- trunk/templates/CommentForm/FormEmbedable.tmpl 2010-12-28 08:43:13 UTC (rev 18004) +++ trunk/templates/CommentForm/FormEmbedable.tmpl 2010-12-30 12:25:26 UTC (rev 18005) @@ -7,8 +7,14 @@ <TMPL_VAR lj_res_includes> </head> <body> - <div class="lj3-form-wrapper"> - <form class="lj3-form lj3-post-comment lj3-active" id="postform" method="post" action="/talkpost_do.bml" target="_top"> + <TMPL_IF errors> + <TMPL_LOOP errors> + <TMPL_VAR error><br> + </TMPL_LOOP> + </TMPL_IF> + + <div class="lj3-form-wrapper"> + <form class="lj3-form lj3-post-comment lj3-active" id="postform" method="post" action="/talkpost_do.bml" target=""> <TMPL_VAR form_intro> <input type="hidden" name="usertype" value="<TMPL_VAR usertype_default>"> <input type="hidden" name="is_form_embedded" value="1">