10 |
# Static::Simple: will serve static files from the applications root directory |
# Static::Simple: will serve static files from the applications root directory |
11 |
# |
# |
12 |
use Catalyst qw/-Debug |
use Catalyst qw/-Debug |
|
Static::Simple |
|
13 |
Prototype |
Prototype |
14 |
Config::YAML |
Config::YAML |
15 |
FillInForm |
FillInForm |
16 |
SubRequest |
SubRequest |
17 |
|
Static::Simple |
18 |
|
StackTrace |
19 |
|
Dumper |
20 |
/; |
/; |
21 |
# FormValidator |
# FormValidator |
22 |
|
|
23 |
our $VERSION = '0.16-dev'; |
use Encode qw/is_utf8 decode/; |
24 |
|
|
25 |
|
our $VERSION = '0.37-dev'; |
26 |
|
|
27 |
# |
# |
28 |
# Configure the application |
# Configure the application |
60 |
sub default : Private { |
sub default : Private { |
61 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
62 |
$c->stash->{template} = 'index.tt'; |
$c->stash->{template} = 'index.tt'; |
63 |
|
|
64 |
|
my $site_name = shift @{ $c->req->args } || ''; |
65 |
|
|
66 |
|
$c->log->debug("trying site name: $site_name"); |
67 |
|
|
68 |
|
if (my $sites_root = $c->config->{sites_root}) { |
69 |
|
my $site_path = $c->path_to('root', $sites_root, $site_name); |
70 |
|
|
71 |
|
if (-e $site_path) { |
72 |
|
$c->stash->{site} = $site_name; |
73 |
|
if (my $action = join('/', @{ $c->req->args })) { |
74 |
|
$c->log->debug( "site: $site_name, action: $action" ); |
75 |
|
# do a subrequest |
76 |
|
$c->res->body( $c->subreq( $action, $c->stash, @{ $c->req->args } ) ); |
77 |
|
} else { |
78 |
|
$c->log->debug( "site: $site_name" ); |
79 |
|
} |
80 |
|
} else { |
81 |
|
$c->log->debug( "can't find site $site_name in $site_path"); |
82 |
|
} |
83 |
|
} else { |
84 |
|
$c->log->warn("sites_root not defined in config"); |
85 |
|
} |
86 |
} |
} |
87 |
|
|
88 |
=item end |
=item end |
94 |
|
|
95 |
$c->stash->{webpacus_version} = $VERSION; |
$c->stash->{webpacus_version} = $VERSION; |
96 |
|
|
97 |
# Forward to View unless response body is already defined |
if ($c->response->body) { |
98 |
$c->forward('View::TT') unless $c->response->body; |
$c->log->debug("at end body exists, we won't touch it!"); |
99 |
|
} else { |
100 |
|
if (my $site_name = $c->stash->{site}) { |
101 |
|
my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template}); |
102 |
|
if (-e $template_path) { |
103 |
|
$c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template}; |
104 |
|
} else { |
105 |
|
$c->log->warn("can't find $template_path, fallback to default"); |
106 |
|
} |
107 |
|
$c->log->debug("using template " . $c->stash->{template}); |
108 |
|
|
109 |
|
$c->stash->{site_url} = "/$site_name/"; |
110 |
|
|
111 |
|
#$c->log->dumper( $c->stash, 'stash' ); |
112 |
|
|
113 |
|
} |
114 |
|
|
115 |
|
# Forward to View unless response body is already defined |
116 |
|
$c->forward('View::TT'); |
117 |
|
|
118 |
|
# oh, turn utf8 flag for all parametars (why do I need to do this?) |
119 |
|
my $utf8_params; |
120 |
|
map { |
121 |
|
$utf8_params->{$_} = decode('UTF-8', $c->request->params->{$_}); |
122 |
|
} keys %{ $c->request->params }; |
123 |
|
|
124 |
|
# and fill-in form with new UTF-8 encoded params (to prevent double-escape of UTF-8) |
125 |
|
$c->fillform( $utf8_params ); |
126 |
|
|
127 |
$c->fillform; # defaults to $c->req->parameters |
$c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new WebPAC.Suggest(#gs; |
128 |
|
$c->response->{body} =~ s#\Qnew Ajax.Updater(\E#new WebPAC.Updater(#gs; |
129 |
|
|
130 |
$c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new Ajax.Suggest(#gs; |
# $c->log->debug( $c->response->body ); |
131 |
# $c->log->debug( $c->response->body ); |
} |
132 |
|
|
133 |
} |
} |
134 |
|
|