qr/./); # $_[1] is a pre-request scratch area # put variables here so that we can access them later # outside of this _code block my $title = \$_[1]->{'title'}; my $head = \$_[1]->{'head'}; my $body = \$_[1]->{'body'}; my $bodyopts = \$_[1]->{'bodyopts'}; my $onload = \$_[1]->{'onload'}; $$title = $ML{'.title2'}; # invalid text input? unless (LJ::text_in(\%POST)) { $$body = ""; return; } # invalid usejournal if ($GET{usejournal} && !LJ::load_user($GET{usejournal})) { $$body = $ML{'.error.invalidusejournal'}; return; } # get remote and see if they can post right now my $remote = LJ::get_remote(); # Errors that are unlikely to change between starting # to compose an entry and submitting it. if ($remote) { return BML::redirect( LJ::create_url( "/entry/new", cur_args => \%GET, keep_args => 1 ) ) if ! LJ::did_post() && LJ::BetaFeatures->user_in_beta( $remote => "updatepage" ); if ($remote->identity) { $$title = $ML{'Sorry'}; $$body = BML::ml('.error.nonusercantpost', {'sitename' => $LJ::SITENAME}); return; } if (! $remote->can_post ) { $$title = $ML{'.error.cantpost.title'}; $$body = $LJ::MSG_NO_POST || $ML{'.error.cantpost'}; return; } } my %res = (); # see if we need to do any transformations LJ::Hooks::run_hooks("transform_update_$POST{transform}", \%GET, \%POST) if $POST{transform}; LJ::need_res( { priority => $LJ::OLD_RES_PRIORITY }, 'stc/entry.css' ); LJ::need_res('stc/display_none.css', 'stc/lj_base.css', 'js/6alib/inputcomplete.js'); ## figure out times my $now = DateTime->now; # if user has timezone, use it! if ($remote && $remote->prop("timezone")) { my $tz = $remote->prop("timezone"); $tz = $tz ? eval { DateTime::TimeZone->new(name => $tz); } : undef; $now = eval { DateTime->from_epoch(epoch => time(), time_zone => $tz); } if $tz; } my ($year, $mon, $mday, $hour, $min) = ($now->year, sprintf("%02d", $now->month), sprintf("%02d", $now->day), $now->hour, sprintf("%02d", $now->minute)); my $subject = $POST{'subject'} || $GET{'subject'}; my $event = $POST{'event'} || $GET{'event'}; my $tags = $POST{'prop_taglist'} || $GET{'prop_taglist'}; # if a share url was passed in, fill in the fields with the appropriate text if ( $GET{share} && ( my $page = DW::External::Page->new( url => $GET{share} ) ) ) { $subject = LJ::ehtml( $page->title ); $event = '' . ( LJ::ehtml( $page->description ) || $subject || $page->url ) . "\n\n"; } # try to call a hook to fill in the fields my $override_fields = LJ::Hooks::run_hook('update_fields', \%GET); my $opt_preformatted = 0; if ($override_fields) { $event = $override_fields->{'event'} if exists($override_fields->{'event'}); $subject = $override_fields->{'subject'} if exists($override_fields->{'subject'}); $tags = $override_fields->{'tags'} if exists($override_fields->{'tags'}); $opt_preformatted = $override_fields->{'prop_opt_preformatted'} if exists($override_fields->{'prop_opt_preformatted'}); } ### define some bools with common logic ### my $did_post = LJ::did_post() && !$POST{transform}; # transforms aren't posts my $user_is_remote = $remote && $remote->{'user'} eq $POST{'user'}; # user is remote my $auth_as_remote = $remote && (! $GET{'altlogin'} || $user_is_remote); # auth as remote my $auth_missing = $POST{'user'} && ! $POST{'password'} && ! $user_is_remote && ! $POST{'response'}; # user w/o password # which authentication option do we display by default? my $altlogin_display = 'none'; my $remotelogin_display = 'none'; if ($auth_as_remote) { $remotelogin_display = 'block'; } else { $altlogin_display = 'block'; } # Check for errors, store in hash to render later my $errors; my $showform = $POST{'showform'} || $auth_missing; # show entry form my $preview = $POST{'action:preview'}; # are we spellchecking before we post? my $did_spellcheck; my $spellcheck_html; if ($LJ::SPELLER && $POST{'action:spellcheck'}) { $did_spellcheck++; my $s = new LJ::SpellCheck { 'spellcommand' => $LJ::SPELLER, 'color' => '', }; $spellcheck_html = $s->check_html(\$event); $spellcheck_html = "" unless $spellcheck_html ne ""; my $date = LJ::html_datetime_decode({ 'name' => "date_ymd", }, \%POST); ($year, $mon, $mday) = split( /\D/, $date); $hour = $POST{'hour'}; $min = $POST{'min'}; } my $print_entry_form = sub { my $opts = shift; # authentication box my $auth = ''; if ($altlogin_display eq 'none') { $auth.= "
\n"; $auth .= "\n"; $auth .= "" . $remote->{user} . " $ML{'entryform.switchuser'}\n"; $auth .= "
\n\n"; } # table with username/password fields $auth .= "\n"; $auth .= "\n"; $auth .= LJ::html_text({ 'name' => 'user', 'id' => 'altlogin_username', 'class' => 'text', 'size' => '15', 'maxlength' => '25', 'tabindex' => '5', 'value' => $POST{'user'} || $GET{'user'} }) . "\n"; $auth .= "
\n"; $auth .= "\n";
$auth .= "\n";
$auth .= LJ::html_text({ 'type' => 'password', 'id' => 'altlogin_password', 'class' => 'text',
'name' => 'password', 'tabindex' => '6', 'size' => '15', 'maxlength' => $LJ::PASSWORD_MAXLENGTH }) . "\n";
# posted with a user, but no password
if ($did_post && $auth_missing) {
$auth .= "
";
}
$auth .= "
| \n\n";
my ($ju, $itemlink);
# short bail if this was posted moderated or some other special case (no itemid but a message)
if (!defined $res{itemid} && $res{message}) {
$$body .= " $res{message} p?>"; } else { # update success my $updatemessage = '.update.success2'; if ($POST{'usejournal'}) { $ju = LJ::load_user($POST{'usejournal'}); # posting as community } elsif ($user) { $ju = LJ::load_user($user); # posting not as user from form } else { $ju = $remote; # posting as remote }; if ( $ju->is_community ) { # changes the update message if journal is from a community $updatemessage = '.update.success2.community'; } $$body .= BML::ml( $updatemessage, {'aopts' => "href='" . $ju->journal_base . "/'"} ); $$body .= " $protocol_message" if $protocol_message; my $juser = $ju->{'user'}; my ($itemid, $anum) = ($res{'itemid'}, $res{'anum'}); $itemlink = LJ::item_link($ju, $itemid, $anum); my $orig_itemid = $itemid; $itemid = $itemid * 256 + $anum; my $edititemlink = "/editjournal?journal=$juser&itemid=$itemid"; # crosspost if we're posting to our own journal and have # selected crosspost. if ($ju == $remote && ($POST{prop_xpost_check} || $GET{prop_xpost_check})) { my ($xpost_successes, $xpost_errors) = LJ::Protocol::schedule_xposts($remote, $itemid, 0, sub { my $acctid = (shift)->acctid; ($POST{"prop_xpost_$acctid"} || $GET{"prop_xpost_$acctid"}, {password => $POST{"prop_xpost_password_$acctid"} || $GET{"prop_xpost_password_$acctid"}, auth_challenge => $POST{"prop_xpost_chal_$acctid"} || $GET{"prop_xpost_chal_$acctid"}, auth_response => $POST{"prop_xpost_resp_$acctid"} || $GET{"prop_xpost_resp_$acctid"}}) }); $$body .= "
"; } my @after_entry_post_extra_options = LJ::Hooks::run_hooks('after_entry_post_extra_options', user => $ju, itemlink => $itemlink); my $after_entry_post_extra_options = join('', map {$_->[0]} @after_entry_post_extra_options) || ''; my $security_ml; my $filternames = ''; my $c_or_p = $ju->is_community ? 'c' : 'p'; if ( $req{"security"} eq "private" ) { $security_ml = "post.security.private.$c_or_p"; } elsif ( $req{"security"} eq "usemask" ) { if ( $req{"allowmask"} == 0 ) { # custom security with no group -- essentially private $security_ml = "post.security.private.$c_or_p"; } elsif ( $req{"allowmask"} > 1 ) { # custom group $filternames = $ju->security_group_display( $req{"allowmask"} ); $security_ml = "post.security.custom"; } else { # access list $security_ml = "post.security.access.$c_or_p"; } } else { # public $security_ml = "post.security.public"; } $$body .= " p?> $filternames } ); my $subject = $req{subject}; if ( length $subject > 0 ) { # use the HTML cleaner on the entry subject, # then display it without escaping LJ::CleanHTML::clean_subject( \$subject ); } else { $subject = $ML{'.extradata.subject.no_subject'}; } $$body .= sprintf( " p?>
| "; $$body .= " |
| "; $print_entry_form->(); $$body .= " | "; $$body .= ""; $$body .= " |