LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / lj-bml-init.pl
blob1a0bb2249adea4157b294bcb1f0edfdaddf9ac77
1 package LJ;
2 use strict;
4 use lib "$ENV{LJHOME}/cgi-bin";
5 use POSIX qw(ENOENT);
6 use LJ::Config;
7 LJ::Config->load;
8 use LJ::Request;
10 foreach (@LJ::LANGS, @LJ::LANGS_IN_PROGRESS) {
11 BML::register_isocode(substr($_, 0, 2), $_);
12 BML::register_language($_);
15 # set default path/domain for cookies
16 BML::set_config("CookieDomain" => $LJ::COOKIE_DOMAIN);
17 BML::set_config("CookiePath" => $LJ::COOKIE_PATH);
19 BML::register_hook("startup", sub {
20 my $uri = "bml" . LJ::Request->uri;
21 unless ($uri =~ s/\.bml$//) {
22 $uri .= ".index";
24 $uri =~ s!/!.!g;
25 LJ::Request->notes("codepath" => $uri);
26 });
28 BML::register_hook("codeerror", sub {
29 my $msg = shift;
31 my $err = LJ::errobj($msg) or return;
32 $err->log;
33 $msg = $err->as_html;
35 chomp $msg;
36 $msg .= " \@ $LJ::SERVER_NAME" if $LJ::SERVER_NAME;
37 warn "$msg\n";
39 my $remote = LJ::get_remote();
40 if (($remote && $remote->show_raw_errors) || $LJ::IS_DEV_SERVER) {
41 return "<pre>" . LJ::ehtml("[Error: $msg]") . "</pre>";
42 } else {
43 return $LJ::MSG_ERROR || "Sorry, there was a problem.";
45 });
47 if ($LJ::UNICODE) {
48 BML::set_config("DefaultContentType", "text/html; charset=utf-8");
51 # register BML multi-language hook
52 BML::register_hook("ml_getter", \&LJ::Lang::get_text);
54 # include file handling
55 BML::register_hook('include_getter', sub {
56 # simply call LJ::load_include, as it does all the work of hitting up
57 # memcache/db for us and falling back to disk if necessary...
58 my ($file, $source) = @_;
59 $$source = LJ::load_include($file);
60 return 1;
61 });
63 # Allow scheme override to be defined as a code ref or an explicit string value
64 BML::register_hook('default_scheme_override', sub {
65 my $current_scheme = shift;
67 my $override = $LJ::BML_SCHEME_OVERRIDE{$current_scheme};
68 return LJ::conf_test($override) if defined $override;
70 return LJ::conf_test($LJ::SCHEME_OVERRIDE);
71 });
73 # extra perl to insert at the beginning of a code block
74 # compilation
75 BML::register_hook("codeblock_init_perl", sub {
76 return q{
77 *errors = *BMLCodeBlock::errors;
78 *warnings = *BMLCodeBlock::warnings;
80 });
82 # now apply any local behaviors which may be defined
83 eval { require "lj-bml-init-local.pl" };
84 die $@ if $@ && $! != ENOENT;