source: server/trunk/web/lib/Sophie/Controller/Root.pm @ 422

Last change on this file since 422 was 316, checked in by nanardon, 13 years ago
  • add cron job to clean obsoleted data
File size: 2.5 KB
Line 
1package Sophie::Controller::Root;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller' }
6
7#
8# Sets the actions in this controller to be registered with no prefix
9# so they function identically to actions created in MyApp.pm
10#
11__PACKAGE__->config(namespace => '');
12
13=head1 NAME
14
15Sophie::Controller::Root - Root Controller for Sophie
16
17=head1 DESCRIPTION
18
19[enter your description here]
20
21=head1 METHODS
22
23=cut
24
25sub begin : Private {
26    my ( $self, $c ) = @_;
27
28    if ($c->req->path =~ m:[^/]+\/+$:) {
29        my $path = $c->req->path;
30        $path =~ s:/*$::;
31        $c->res->redirect($c->uri_for("/$path"));
32        return;
33    }
34
35    if (!$c->stash->{sitepath}) {
36        my @path;
37        my @reqpath = split('/', $c->req->path);
38        foreach (@reqpath) {
39            push(@path, $_);
40            push(@{ $c->stash->{sitepath} }, { path => $c->uri_for('/', @path),
41                    name => $_ || '*' });
42        }
43    }
44
45    if (($c->req->query_keywords || '') =~ /([^\w]|^)json([^\w]|$)/ ||
46        exists($c->req->params ->{json})) {
47        $c->stash->{current_view} = 'Json';
48    }
49    if (($c->req->query_keywords || '') =~ /([^\w]|^)ajax([^\w]|$)/ ||
50        exists($c->req->params ->{ajax})) {
51        $c->stash->{current_view} = 'Ajax';
52    }
53
54    #$c->delete_expired_sessions;
55}
56
57=head2 index
58
59The root page (/)
60
61=cut
62
63sub index :Path :Args(0) {
64    my ( $self, $c ) = @_;
65
66    $c->stash->{metarevisite} = 1;
67    $c->stash->{xmlrpc} = $c->forward(
68        '/search/rpms/bydate',
69        [
70            {
71                src => 1,
72                rows => 20,
73            },
74            1
75        ]
76    ); 
77}
78
79sub robots :Path('/robots.txt') {
80    my ($self, $c) = @_;
81
82    $c->serve_static_file($c->path_to('root', 'static', 'robots.txt'));
83}
84
85=head2 default
86
87Standard 404 error page
88
89=cut
90
91sub default :Path {
92    my ( $self, $c ) = @_;
93    $c->go('/404/index');
94}
95
96=head2 end
97
98Attempt to render a view, if needed.
99
100=cut
101
102sub _end : ActionClass('RenderView') {}
103
104sub  end : Private {
105    my ( $self, $c ) = @_;
106    if (!$c->stash->{current_view}) {
107        if (ref($c->stash->{xmlrpc}) eq 'HASH' &&
108            $c->stash->{xmlrpc}{graph}) {
109            $c->stash->{current_view} = 'GD';
110        }
111    }
112    if (!$c->req->xmlrpc->method) {
113        $c->forward('_end');
114    }
115    $c->stash->{data} = $c->stash->{xmlrpc};
116    $c->model('Base')->storage->dbh->rollback;
117}
118
119=head1 AUTHOR
120
121Olivier Thauvin
122
123=head1 LICENSE
124
125This library is free software. You can redistribute it and/or modify
126it under the same terms as Perl itself.
127
128=cut
129
130__PACKAGE__->meta->make_immutable;
131
1321;
Note: See TracBrowser for help on using the repository browser.