qr/./); # $_[0] is a pre-request scratch area # put variables here so that we can access them later # outside of this _code block my $title = \$_[0]->{'title'}; my $head = \$_[0]->{'head'}; my $body = \$_[0]->{'body'}; my $bodyopts = \$_[0]->{'bodyopts'}; my $onload = \$_[0]->{'onload'}; my $update_type = $POST{'type'} || $GET{'type'}; $$title = ($update_type eq 'sticky') ? $ML{'.title2_sticky'} : $ML{'.title2'}; if ($GET{qotd} && !LJ::is_enabled('qotd')) { $$body = LJ::error_list( BML::ml('qotd.disabled', { sitename => $LJ::SITENAMESHORT } )); return; } # server down? if ($LJ::SERVER_DOWN) { $$body = LJ::server_down_html(); return; } LJ::set_active_crumb("postentry"); LJ::Controller::Post->rte_langmap(); # invalid text input? unless (LJ::text_in(\%POST)) { $$body = ""; return; } ## This header is to pass page content through IE8 XSS Filter. ## See also htdocs/preview/entry.bml. LJ::Request->header_out("X-XSS-Protection" => 0); ## And this header is to prevent Clickjacking attacks LJ::Request->header_out("X-Frame-Options" => 'deny'); my $usejournalu; if (my $usejournal = $GET{'usejournal'} || $POST{'usejournal'}) { $usejournalu = LJ::load_user($usejournal); unless ($usejournalu) { # invalid usejournal $$body = $ML{'.error.invalidusejournal'}; return; } } # get remote and see if they can post right now my $remote = LJ::get_remote(); # Should we show try and buy my $show_trynbuy = LJ::TryNBuy->can_enable($remote) || LJ::TryNBuy->active($remote); # Errors that are unlikely to change between starting # to compose an entry and submitting it. if ($remote) { if ($remote->underage) { return BML::redirect("$LJ::SITEROOT/agecheck/?s=1"); } return if LJ::bad_password_redirect(); my @posting_access = $remote->posting_access_list; if ( $remote->is_identity && scalar(@posting_access) == 0 && ! $usejournalu ) { $$title = $ML{'Sorry'}; $$body = BML::ml('.error.nonusercantpost', {'sitename' => $LJ::SITENAME}); return; } if (! LJ::get_cap($remote, "can_post")) { $$title = $ML{'.error.cantpost.title'}; $$body = $LJ::MSG_NO_POST || $ML{'.error.cantpost'}; return; } if (LJ::get_cap($remote, "disable_can_post")) { unless (LJ::run_hook("update.bml_disable_can_post", { title => $title, body => $body, })) { $$title = $ML{'.error.disabled.title'}; $$body = $ML{'.error.disabled'}; } return; } } my %res = (); # see if we need to do any transformations LJ::run_hooks("transform_update_$POST{transform}", \%GET, \%POST) if $POST{transform}; LJ::need_res(qw( stc/display_none.css stc/lj_base.css stc/entry.css stc/trava.css stc/widgets/selecttags.css js/lib/jquery-ui/jquery.ui.position.min.js js/lib/jquery-ui/jquery.ui.autocomplete.min.js js/jquery/jquery.bgiframe.js js/gears_init.js js/scanner.js js/photobucket_jw.js )); LJ::need_var(last_fm_user => $remote && $remote->{'last_fm_user'}); LJ::need_var(last_fm_api_key => $LJ::LAST_FM_API_KEY); ## 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; } if (LJ::is_enabled("delayed_entries")) { LJ::need_string(qw/ entryform.sticky_replace.edit entryform.sticky.edit entryform.choose_date/); } 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'} || $POST{'body'}; my $tags = $POST{'prop_taglist'} || $GET{'prop_taglist'}; my $url = $GET{'url'}; # Tags if ($remote) { my @tag_names; my $u = $usejournalu || $remote; my $utags = $u->tags; my $username = $u->user; if (keys %$utags) { @tag_names = sort { lc $a cmp lc $b } map { $_->{name} } values %$utags; } $$head .= "\n"; } # if a QotD id was passed in, fill in the fields with that QotD my $qid = $GET{qotd}+0; my $qotd = $qid ? LJ::QotD->get_single_question($qid) : ''; if ($qotd) { $subject = LJ::Widget::QotD->subject_text($qotd, user => $remote); my $lncode = ($remote && $remote->prop('browselang')) ? $remote->prop('browselang') : $LJ::DEFAULT_LANG; $event = LJ::Widget::QotD->embed_text($qotd, $lncode); $tags = LJ::Widget::QotD->tags_text($qotd); LJ::run_hooks('qotd_modify_tags', \$tags); my $text = LJ::Widget::QotD->qotd_display_embed( questions => [ $qotd ], form_disabled => 1 ); $$head .= ""; } if ($url) { ## currently, the URL is for YouTube only. ## in future support for other quick embeds will be added. ## TODO: use oEmbed for YouTube (http://apiblog.youtube.com/2009/10/oembed-support.html) if ($url =~ m!http://www.youtube.com/watch\?v=([\w\-]+)! || $url =~ m!http://www.youtube.com/v/([\w\-]+)!) { $event = <<"EMBED"; EMBED } } my $reposted_from = ''; my $repost_hidden = ''; # in case of repost other entry by its uri we should check its visibility # for remote user. if (my $repost = ($POST{repost} || $GET{repost})){ my $entry = LJ::Entry->new_from_url($repost); unless ($entry){ $$body = ""; return; } if ($entry->visible_to($remote)) { $subject ||= ( LJ::ehtm($entry->subject_orig) || LJ::Lang::ml("repost.default_subject")); unless ($event) { $event = $entry->event_raw; LJ::EmbedModule->add_user_to_embed($entry->journal->username, \$event); $event = LJ::Lang::ml( "repost.wrapper", { username => $entry->poster->username, url => $entry->url, subject => $subject, text => $event, }); } $reposted_from = $entry->url; $repost_hidden = LJ::repost_auth($POST{'repost_type'} || $GET{'repost_type'} || 'd', $entry->poster->username, $entry->url, $subject); } } # try to call a hook to fill in the fields my $override_fields = LJ::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 = ''; } else { $altlogin_display = ''; } # Check for errors, store in hash to render later my $errors = {}; my $showform = $POST{'showform'} || $auth_missing || exists $POST{'ljpost:off'}; # show entry form my $preview = $POST{'action:preview'}; if ( exists $POST{'ljpost:off'} ) { LJ::Request->set_cookie( ljpost => 0, expires => time + 86400 * 7, ); } # are we spellchecking before we post? my $did_spellcheck; my $spellcheck_html; if ($LJ::SPELLER && $POST{'action:spellcheck'}) { $did_spellcheck++; my $s = LJ::SpellCheck->new({ 'spellcommand' => $LJ::SPELLER, 'color' => '', 'lang' => $remote ? $remote->prop('browselang') : $LJ::DEFAULT_LANG, }); $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, $min) = split(/:/, $POST{'time'}); } my $print_entry_form = sub { my $opts = shift; # authentication box my $auth = ''; if ($altlogin_display eq 'none') { $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 # some other code at this bml-page can check this flag # with 'exists $BMLCodeBlock::POST{success}' $POST{success} = 1; if ($qotd) { LJ::MemCache::delete('qotd_count:'.$qotd->{qid}); } if ($usejournalu) { $ju = $usejournalu; # posting as community } elsif ($user) { $ju = LJ::load_user($user); # posting not as user from form } else { $ju = $remote; # posting as remote }; my $juser = $ju->{'user'}; my ($itemid, $anum) = ($res->{'itemid'}, $res->{'anum'}); my $delayedid = $res->{'delayedid'}; if ($res->{'itemid'}) { $itemlink = LJ::item_link($ju, $itemid, $anum); } else { $itemlink = LJ::DelayedEntry::item_link($ju, $res->{'delayedid'}); } if ($itemid) { $itemid = $itemid * 256 + $anum; $$body .= BML::ml('.update.success2', {'aopts' => "href='" . $ju->journal_base . "/'"}); } else { my $ext = $remote->equals($ju) ? '' : "?usejournal=" . $ju->username; $$body .= BML::ml('.update.success3', {'aopts' => "href=$LJ::SITEROOT/manage/scheduled_posts.bml$ext"}); } $$body .= $res->{extra_result_message}; $$body .= join(' ', @{$res->{warnings}} ) if $res->{warnings} and @{$res->{warnings}}; my $juser = $ju->{'user'}; my ($itemid, $anum) = ($res->{'itemid'}, $res->{'anum'}); my $delayedid = $res->{'delayedid'}; if ($res->{'itemid'}) { $itemlink = LJ::item_link($ju, $itemid, $anum); } else { $itemlink = LJ::DelayedEntry::item_link($ju, $res->{'delayedid'}); } $itemid = $itemid * 256 + $anum; my $writersblocklink = ''; if ($qid && LJ::run_hook('show_qotd_extra_text', $remote)) { $writersblocklink = "
' . LJ::Widget::Trynbuy->render(stage => 'simple') if ($show_trynbuy);
$$body .= LJ::Widget::GettingStarted->render;
$$body .= ' ' if ($show_trynbuy);
}
$$body .= " | "; { $$body .= LJ::get_ads({ location => 'bml.update/error', ljadwrapper => 1, below_ad => LJ::CProd->full_box_for($u, width => 300), interests_extra => $qid ? { qotd => $qotd } : {}, }); } $$body .= " |
| "; $print_entry_form->(); $$body .= " | "; { my $ad_details; my $ad = LJ::get_ads({ location => 'bml.update/main', get_slots_params => \$ad_details, interests_extra => $qid ? { qotd => $qotd } : {} }); my $trynbuy; $trynbuy = LJ::Widget::Trynbuy->render( 'stage' => 'simple' ) if $show_trynbuy; if ( $ad ) { my $width = $ad_details->[-1]->{width}; my $adunit = $ad_details->[-1]->{adunit}; $$body .= "$ad"; } else { $$body .= " | "; } } $$body .= " |