1 # This is a module for handling URIs
8 # Takes an Apache a path to BML filename relative to htdocs
10 my ($class, $filename) = @_;
12 LJ
::Request
->handler("perl-script");
13 LJ
::Request
->notes("bml_filename" => "$LJ::HOME/htdocs/$filename");
14 LJ
::Request
->push_handlers(PerlHandler
=> \
&Apache
::BML
::handler
);
15 return LJ
::Request
::OK
;
20 Apache
::LiveJournal
::Interface
::Api
->load;
21 LJ
::Request
->handler("perl-script");
22 LJ
::Request
->push_handlers(PerlHandler
=> \
&Apache
::LiveJournal
::Interface
::Api
::handler
);
23 return LJ
::Request
::OK
;
26 # Handle a URI. Returns response if success, undef if not handled
27 # Takes URI and Apache $r
29 my ($class, $uri) = @_;
31 return undef unless $uri;
34 if (my ($rpc) = $uri =~ m!^.*/__rpc_(\w+)$!) {
35 my $bml_handler_path = $LJ::AJAX_URI_MAP
{$rpc};
37 return LJ
::URI
->bml_handler($bml_handler_path) if $bml_handler_path;
40 # handle "API" endpoint
41 if ($uri =~ /^\/__api_endpoint
.*$/) {
42 return LJ
::URI
->api_handler();
45 ## URI "/pics" can be handle only under user domains
46 return undef if $uri =~ /^\/pics/;
48 # handle normal URI mappings
49 if (my $bml_file = $LJ::URI_MAP
{$uri}) {
50 return LJ
::URI
->bml_handler($bml_file);
53 # handle URI redirects
54 if (my $url = $LJ::URI_REDIRECT
{$uri}) {
55 return Apache
::LiveJournal
::redir
($url, LJ
::Request
::HTTP_MOVED_TEMPORARILY
);
58 my $args = LJ
::Request
->args;
60 $full_uri .= "?$args" if $args;
64 # Now we handle verticals as subproject of community directory via LJ::Browse
68 # handle vertical URLs
69 if (my $v = LJ
::Vertical
->load_by_url($full_uri)) {
70 return LJ
::URI
->bml_handler("browse/index.bml");
73 if (my $c = LJ
::Browse
->load_by_url($full_uri)) {
74 return LJ
::URI
->bml_handler("browse/index.bml");
77 if ($uri =~ m!^/statistics(/.*|$)! or $uri =~ m!^/ratings(/.*|$)! and not $uri eq '/ratings/admin.bml') {
78 return LJ
::URI
->bml_handler("statistics/index.bml");
81 if ( $uri =~ m!^/singles(/.*|$)! ) {
82 return LJ
::URI
->bml_handler("singles/index.bml");