"; return; } my %ierr; my $email = $POST{invite_email} || ''; my $create_link = $LJ::SITEROOT . "/create?from=$u->{user}"; my @invitecodes; my $code; if ( $LJ::USE_ACCT_CODES ) { @invitecodes = DW::InviteCodes->by_owner_unused( userid => $u->id ); if ( $u->is_identity ) { $body = BML::ml( '.error.openid', { sitename => $LJ::SITENAMESHORT } ); return; } unless ( @invitecodes ) { $body = $ML{'.msg.noinvitecodes'}; $body .= " " . BML::ml( '.msg.noinvitecodes.requestmore', { aopts => "href='$LJ::SITEROOT/invite'" } ) if DW::BusinessRules::InviteCodeRequests::can_request( user => $u ); return; } $code = $POST{code} || $invitecodes[0]->code; $create_link .= "&code=".$code; # sort so that those which have been sent are last on the list @invitecodes = sort { ( $a->timesent || 0 ) <=> ( $b->timesent || 0 ) } @invitecodes; } my $email_checkbox; my $validate_form = sub { my $rv = 1; my $bogus = sub { my $key = shift; my $msg = shift; $ierr{$key} = $msg; $rv = 0; }; $bogus->('form_auth', $ML{'error.invalidform'}) unless LJ::check_form_auth(); if ($email) { my @errs; LJ::check_email( $email, \@errs, \%POST, \$email_checkbox ); $bogus->( "email", @errs ) if @errs; if ($LJ::USER_EMAIL && $email =~ /$LJ::USER_DOMAIN$/) { $bogus->("email", $ML{'.error.useralreadyhasaccount'}); } unless ( $LJ::USE_ACCT_CODES ) { my $dbh = LJ::get_db_reader(); my $ct = $dbh->selectrow_array("SELECT COUNT(*) FROM email WHERE email = ?", undef, $email); if ($ct > 0) { my $findfriends_userhasaccount = LJ::Hooks::run_hook("findfriends_invite_user_has_account"); if ($findfriends_userhasaccount) { $bogus->("email", $findfriends_userhasaccount); } else { $bogus->("email", $ML{'.error.useralreadyhasaccount'}); } } } } else { $bogus->("email", $ML{'.error.noemail'}); } if ($POST{'msg'} =~ /<(img|image)\s+src/i) { $bogus->("msg", $ML{'.error.noimagesallowed'}); } foreach ( LJ::get_urls( $POST{'msg'} ) ) { if ( $_ !~ m!^https?://([\w-]+\.)?$LJ::DOMAIN(/.*)?$!i ) { $bogus->( "msg", "$_
" . BML::ml( '.error.nooffsitelinksallowed', { sitename => $LJ::SITENAMESHORT } ) ); last; } } return $rv; }; # inline error my $inerr = sub { my $key = shift; my $post = shift || ""; return "" unless $ierr{$key}; return "$ierr{$key}$post"; }; my $msg_subject = BML::ml('.msg_subject', { username => $u->display_username, sitenameshort => $LJ::SITENAMESHORT }); my $msg_body_top = BML::ml('.msg_body_top', { displayname => $u->name_html, username => $u->display_username, sitename => $LJ::SITENAMESHORT }); my $msg_body_bottom = BML::ml('.msg_body_bottom', { createlink => $create_link, username => $u->display_username }); my $msg_sig = BML::ml('.msg_sig', { sitename => $LJ::SITENAMESHORT, siteroot => "$LJ::SITEROOT/" }); my $msg_custom = $ML{'.msg_custom'}; my $msg_subject_display = $msg_subject; $msg_subject_display =~ s/\n/
/g; my $msg_body_top_display = $msg_body_top; $msg_body_top_display =~ s/\n/
/g; my $msg_body_bottom_display = $msg_body_bottom; $msg_body_bottom_display =~ s/\n/
/g; # the code shown will be the code last posted, not the code that will be sent # so just wipe it out, to prevent any confusion $msg_body_bottom_display =~ s/(&code=).{20}/$1xxxxxxxxxxxxx/; my $msg_sig_display = $msg_sig; $msg_sig_display =~ s/\n/
/g; my $msg_custom_display = $msg_custom; $msg_custom_display =~ s/\n/
/g; my $msg_footer = BML::ml('.msg_footer2', { sitename => $LJ::SITENAMESHORT, siteroot => "$LJ::SITEROOT/", username => $u->display_username, name => $u->name_html, adminemail => $LJ::ADMIN_EMAIL, }); my $code_sent; if (LJ::did_post() && $validate_form->()) { if ( $u->rate_log( 'invitefriend', 1 ) ) { my $given_msg_custom = $POST{msg} ? "$POST{msg}\n\n" : ""; $u->log_event('friend_invite_sent', { remote => $u, extra => $email, }); if ( $LJ::USE_ACCT_CODES ) { # mark an invite code as sent my $invite_obj = DW::InviteCodes->new( code => $code ); $invite_obj->send_code( email => $email ); $body .= "
" . BML::ml( '.success.code', { email => $email, invitecode => $code } ); $body .= " " . BML::ml( '.success.invitemore' ) if DW::InviteCodes->unused_count( userid => $u->id ) > 1; $body .= "
"; $code_sent = 1; } else { $body .= "
" . BML::ml('.success', { email => $email }) . "
"; } # Blank email so the form is redisplayed for a new # recipient, but with the same message $email = ''; # Over rate limit } else { $body = BML::ml('.error.overratelimit', {'sitename' => $LJ::SITENAMESHORT, 'aopts' => "href='$LJ::SITEROOT/manage/circle/invite'"}); return; } } my $findfriends_intro = LJ::Hooks::run_hook("findfriends_invite_intro"); if ($findfriends_intro) { $body .= $findfriends_intro; } elsif ( $LJ::USE_ACCT_CODES ) { my $unusedinvites = DW::InviteCodes->unused_count( userid => $u->id ); $body .= " "href='$LJ::SITEROOT/invite'" , num => $unusedinvites, notif => "href='$LJ::SITEROOT/manage/settings/?cat=notifications'" } ) . " p?>"; } else { $body .= " "href='$create_link'", createlink => $create_link} ) . " p?>"; } $body .= "
"; $body .= LJ::form_auth(); $body .= "
"; $body .= " "; $body .= LJ::html_text({ name => "invite_email", id => "email", class => 'text', value => $email }) . " "; $body .= LJ::html_submit($ML{'.btn.invite2'}); if ($inerr->("email")) { $body .= "
" . $inerr->("email"); } if ( $email_checkbox ) { $body .= "
" . $email_checkbox; } if ( $LJ::USE_ACCT_CODES ) { $body .= "
" . LJ::labelfy("code-".$invitecodes[0]->code, $ML{'.form.input.code'}); my $is_first = 1; foreach my $invitecode ( splice( @invitecodes, 0, 5 ) ) { my $label = $invitecode->code; if ( $invitecode->code eq $POST{code} && $code_sent ) { $label .= " - " . $ML{'.form.codelist.justsent'}; } elsif ( $invitecode->timesent ) { $label .= " - " . BML::ml( '.form.codelist.alreadysent', { date => LJ::time_to_http( $invitecode->timesent ) }) } $body .= "

"; $body .= LJ::html_check( { selected => $is_first, name => "code", id => "code-".$invitecode->code, type=> "radio", value => $invitecode->code, label => $label, } ); $body .= "

"; $is_first = 0 if $invitecode->code ne $POST{code}; } } $body .= "
"; $body .= $inerr->('form_auth'); $body .= "

$ML{'.form.input.message'}

" . $inerr->("msg", "
"); $body .= "
"; $body .= "

$ML{'.msg_subject.header'} $msg_subject_display

"; $body .= "

$ML{'.msg.header'}

"; $body .= "
"; $body .= "

$msg_body_top_display

"; $body .= LJ::html_textarea({ name => "msg", value => LJ::did_post() ? $POST{msg} : $msg_custom_display, class => "text", rows => 5, cols => 70, }); $body .= "

$msg_body_bottom_display

"; $body .= "
"; $body .= $msg_sig_display; $body .= "
"; $body .= LJ::html_submit($ML{'.btn.invite2'}); $body .= "
"; return; } _code?> body=> page?>