| 1 | package Vee::Controller::Index; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'Catalyst::Controller'; |
|---|
| 6 | |
|---|
| 7 | use DateTime; |
|---|
| 8 | |
|---|
| 9 | __PACKAGE__->config->{namespace} = ''; |
|---|
| 10 | |
|---|
| 11 | =head1 NAME |
|---|
| 12 | |
|---|
| 13 | Vee::Controller::Index - Index Controller |
|---|
| 14 | |
|---|
| 15 | =head1 SYNOPSIS |
|---|
| 16 | |
|---|
| 17 | See L<Vee>. |
|---|
| 18 | |
|---|
| 19 | =head1 DESCRIPTION |
|---|
| 20 | |
|---|
| 21 | Catalyst Controller for the index page. |
|---|
| 22 | |
|---|
| 23 | =head1 METHODS |
|---|
| 24 | |
|---|
| 25 | =cut |
|---|
| 26 | |
|---|
| 27 | =head2 root |
|---|
| 28 | |
|---|
| 29 | =cut |
|---|
| 30 | |
|---|
| 31 | my $shoutbox_fields = { |
|---|
| 32 | content => { type => 'textarea', rows => 3, cols => 20 }, |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | sub index : Path { |
|---|
| 36 | my ($self, $c) = @_; |
|---|
| 37 | |
|---|
| 38 | my $s = $c->stash; |
|---|
| 39 | $s->{page_title} = 'Home/News'; |
|---|
| 40 | $s->{link_name} = 'main'; |
|---|
| 41 | $s->{extra_css} = [ 'index', 'bbcode' ]; |
|---|
| 42 | |
|---|
| 43 | my $news_forum = $c->model('DBIC::Forums')->find( $c->site_opts->{special_forums}{news} ); |
|---|
| 44 | my $page_sizes = $c->site_opts->{page_sizes}{index}; |
|---|
| 45 | |
|---|
| 46 | $s->{recent_news} = $news_forum->threads( undef, { prefetch => 'first_post', order_by => 'me.id DESC', rows => $page_sizes->{news} } ); |
|---|
| 47 | $s->{recent_news} = $s->{recent_news}->search(\ 'NOT FIND_IN_SET("deleted", me.flags)') unless $c->can_i(override_thread_deleted => $news_forum->id); |
|---|
| 48 | |
|---|
| 49 | $s->{recent_shouts} = $c->model('DBIC::Shoutbox')->search( undef, { order_by => 'me.time DESC', rows => $page_sizes->{shoutbox} } ); |
|---|
| 50 | $s->{recent_art} = $c->model('DBIC::Gallery')->search( undef, { order_by => 'me.time DESC', rows => $page_sizes->{gallery} } ); |
|---|
| 51 | |
|---|
| 52 | # TODO: break this off into a "new posts" sort of page, and just put NEW THREADS here |
|---|
| 53 | my $threads_rs = $c->model('DBIC::Threads')->search; |
|---|
| 54 | $threads_rs = $threads_rs->search({ 'me.flags' => { '!=', 'deleted' } }) unless $c->can_i('override_thread_deleted'); |
|---|
| 55 | $s->{recent_posts} = $threads_rs->search( undef, { |
|---|
| 56 | order_by => 'last_post.time DESC', |
|---|
| 57 | rows => $page_sizes->{forum}, |
|---|
| 58 | prefetch => { last_post => 'user' }, |
|---|
| 59 | } ); |
|---|
| 60 | |
|---|
| 61 | # NOT FIND_IN_SET breaks here; why? |
|---|
| 62 | $s->{recent_posts} = $s->{recent_posts}->search({ 'last_post.flags' => { '!=', 'deleted' } }) unless $c->can_i('override_thread_deleted'); |
|---|
| 63 | |
|---|
| 64 | # Grab a list of unread threads |
|---|
| 65 | if ($c->user) { |
|---|
| 66 | my @unread_ids = $threads_rs->unread_ids($c->user->obj); |
|---|
| 67 | my %unread_hash = map { $_ => 1 } @unread_ids; |
|---|
| 68 | |
|---|
| 69 | $s->{is_unread} = sub { $unread_hash{$_[0]->id} }; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | $s->{recent_users} = $c->model('DBIC::Users')->search( |
|---|
| 73 | { time_active => { '>', time - $c->site_opts->{user_activity_timeout} } }, |
|---|
| 74 | { order_by => 'me.time_active DESC' } |
|---|
| 75 | ); |
|---|
| 76 | |
|---|
| 77 | my $shoutbox_form = Vee::Form->new( |
|---|
| 78 | id => 'shoutbox', |
|---|
| 79 | fields => $shoutbox_fields, |
|---|
| 80 | params => $c->req->params, |
|---|
| 81 | ); |
|---|
| 82 | $s->{shoutbox_form} = $shoutbox_form; |
|---|
| 83 | |
|---|
| 84 | $s->{template} = 'index.tt'; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | =head1 AUTHOR |
|---|
| 88 | |
|---|
| 89 | Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>) |
|---|
| 90 | |
|---|
| 91 | See the included F<AUTHORS> file for a full list of contributers. |
|---|
| 92 | |
|---|
| 93 | =head1 LICENSE |
|---|
| 94 | |
|---|
| 95 | See the included F<LICENSE> file. |
|---|
| 96 | |
|---|
| 97 | =cut |
|---|
| 98 | |
|---|
| 99 | 1; |
|---|