";
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 .= "