#!/usr/bin/perl # # Translate certain scheme decisions into others BML::register_hook('scheme_translation', sub { my $scheme = shift; my $remote = LJ::get_remote(); if (my $season = LJ::conf_test($LJ::SEASON)) { return "$scheme-$season" if $scheme eq "vertigo" || $scheme eq "horizon"; } return undef if $LJ::DISABLED{'sup_scheme'}; if ($remote) { # 1) remote + sup bit == sup return 'sup' if $remote->in_class('sup_user'); # 2) remote + no sup == no translation return undef; } my $ip = LJ::get_remote_ip(); my $class = LJ::LJcom::ip_class($ip); # 3) no remote + russia ip if ($class eq 'sup' || $class eq 'russia') { # 3.1) sup unless 'nosup cookie' return "sup" unless $BML::COOKIE{'nosup'}; # 3.2) nosup cookie logged-out from russia ip == no translation return undef; } # 4) no remote + non-russia ip == no translation return undef; }); BML::register_hook('rewrite_filename', sub { my %opts = @_; my $req = $opts{req}; my $env = $opts{env}; ## If remote is SUP and alternate file exists use the alternate file return (LJ::SUP->is_remote_sup() and -e "$req->{file}.sup") ? "$req->{file}.sup" : # process bml-file with .sup extension undef; }); BML::register_hook('alt_default_scheme', sub { my $env = shift; return $env->{DefaultSUPScheme} if LJ::SUP->is_remote_sup(); return; }); BML::register_hook('force_redirect', sub { my $uri = shift; ## If user directly specified .bml.sup page - redirect him/her onto corresponding regular page. if ($uri =~ /^(.*)\.sup$/) { return $1; } return undef; }); 1;