[1] | 1 | package Sophie::Controller::Root; |
---|
| 2 | use Moose; |
---|
| 3 | use namespace::autoclean; |
---|
| 4 | |
---|
| 5 | BEGIN { 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 | |
---|
| 15 | Sophie::Controller::Root - Root Controller for Sophie |
---|
| 16 | |
---|
| 17 | =head1 DESCRIPTION |
---|
| 18 | |
---|
| 19 | [enter your description here] |
---|
| 20 | |
---|
| 21 | =head1 METHODS |
---|
| 22 | |
---|
[3] | 23 | =cut |
---|
| 24 | |
---|
| 25 | sub begin : Private { |
---|
| 26 | my ( $self, $c ) = @_; |
---|
| 27 | |
---|
[54] | 28 | if ($c->req->path =~ m:[^/]+\/+$:) { |
---|
[17] | 29 | my $path = $c->req->path; |
---|
| 30 | $path =~ s:/*$::; |
---|
| 31 | $c->res->redirect($c->uri_for("/$path")); |
---|
| 32 | return; |
---|
| 33 | } |
---|
| 34 | |
---|
[54] | 35 | if (!$c->stash->{sitepath}) { |
---|
[50] | 36 | my @path; |
---|
[54] | 37 | my @reqpath = split('/', $c->req->path); |
---|
[50] | 38 | foreach (@reqpath) { |
---|
| 39 | push(@path, $_); |
---|
[54] | 40 | push(@{ $c->stash->{sitepath} }, { path => $c->uri_for('/', @path), |
---|
| 41 | name => $_ || '*' }); |
---|
[50] | 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
[16] | 45 | if (($c->req->query_keywords || '') =~ /([^\w]|^)json([^\w]|$)/ || |
---|
| 46 | exists($c->req->params ->{json})) { |
---|
[3] | 47 | $c->stash->{current_view} = 'Json'; |
---|
| 48 | } |
---|
[16] | 49 | if (($c->req->query_keywords || '') =~ /([^\w]|^)ajax([^\w]|$)/ || |
---|
| 50 | exists($c->req->params ->{ajax})) { |
---|
| 51 | $c->stash->{current_view} = 'Ajax'; |
---|
| 52 | } |
---|
[4] | 53 | |
---|
| 54 | if ($c->action =~ m/^admin\//) { |
---|
[65] | 55 | if (!($c->user_exists && $c->check_user_roles($c->user, 'Admin'))) { |
---|
[247] | 56 | $c->go('/login/index'); |
---|
[4] | 57 | } |
---|
| 58 | } |
---|
[124] | 59 | |
---|
| 60 | $c->delete_expired_sessions; |
---|
[3] | 61 | } |
---|
| 62 | |
---|
[1] | 63 | =head2 index |
---|
| 64 | |
---|
| 65 | The root page (/) |
---|
| 66 | |
---|
| 67 | =cut |
---|
| 68 | |
---|
| 69 | sub index :Path :Args(0) { |
---|
| 70 | my ( $self, $c ) = @_; |
---|
| 71 | |
---|
[196] | 72 | $c->stash->{metarevisite} = 1; |
---|
[92] | 73 | $c->stash->{xmlrpc} = $c->forward( |
---|
[148] | 74 | '/search/rpms/bydate', |
---|
[92] | 75 | [ |
---|
| 76 | { |
---|
| 77 | src => 1, |
---|
| 78 | rows => 20, |
---|
| 79 | }, |
---|
| 80 | 1 |
---|
| 81 | ] |
---|
| 82 | ); |
---|
[1] | 83 | } |
---|
| 84 | |
---|
[150] | 85 | sub robots :Path('/robots.txt') { |
---|
| 86 | my ($self, $c) = @_; |
---|
| 87 | |
---|
| 88 | $c->serve_static_file($c->path_to('root', 'static', 'robots.txt')); |
---|
| 89 | } |
---|
| 90 | |
---|
[1] | 91 | =head2 default |
---|
| 92 | |
---|
| 93 | Standard 404 error page |
---|
| 94 | |
---|
| 95 | =cut |
---|
| 96 | |
---|
| 97 | sub default :Path { |
---|
| 98 | my ( $self, $c ) = @_; |
---|
[196] | 99 | $c->go('/404/index'); |
---|
[1] | 100 | } |
---|
| 101 | |
---|
| 102 | =head2 end |
---|
| 103 | |
---|
| 104 | Attempt to render a view, if needed. |
---|
| 105 | |
---|
| 106 | =cut |
---|
| 107 | |
---|
[2] | 108 | sub _end : ActionClass('RenderView') {} |
---|
[1] | 109 | |
---|
[2] | 110 | sub end : Private { |
---|
| 111 | my ( $self, $c ) = @_; |
---|
[265] | 112 | if (!$c->stash->{current_view}) { |
---|
| 113 | if (ref($c->stash->{xmlrpc}) eq 'HASH' && |
---|
| 114 | $c->stash->{xmlrpc}{graph}) { |
---|
| 115 | $c->stash->{current_view} = 'GD'; |
---|
| 116 | } |
---|
| 117 | } |
---|
[3] | 118 | if (!$c->req->xmlrpc->method) { |
---|
[2] | 119 | $c->forward('_end'); |
---|
| 120 | } |
---|
[17] | 121 | $c->stash->{data} = $c->stash->{xmlrpc}; |
---|
[42] | 122 | $c->model('Base')->storage->dbh->rollback; |
---|
[2] | 123 | } |
---|
| 124 | |
---|
[1] | 125 | =head1 AUTHOR |
---|
| 126 | |
---|
| 127 | Olivier Thauvin |
---|
| 128 | |
---|
| 129 | =head1 LICENSE |
---|
| 130 | |
---|
| 131 | This library is free software. You can redistribute it and/or modify |
---|
| 132 | it under the same terms as Perl itself. |
---|
| 133 | |
---|
| 134 | =cut |
---|
| 135 | |
---|
| 136 | __PACKAGE__->meta->make_immutable; |
---|
| 137 | |
---|
| 138 | 1; |
---|