| 1 | package Vee::Controller::Shoutbox; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'Catalyst::Controller'; |
|---|
| 6 | |
|---|
| 7 | use Vee::Authorization; |
|---|
| 8 | |
|---|
| 9 | =head1 NAME |
|---|
| 10 | |
|---|
| 11 | Vee::Controller::Shoutbox - Shoutbox Controller |
|---|
| 12 | |
|---|
| 13 | =head1 SYNOPSIS |
|---|
| 14 | |
|---|
| 15 | See L<Vee> |
|---|
| 16 | |
|---|
| 17 | =head1 DESCRIPTION |
|---|
| 18 | |
|---|
| 19 | Catalyst Controller for viewing the shoutbox. |
|---|
| 20 | |
|---|
| 21 | =head1 METHODS |
|---|
| 22 | |
|---|
| 23 | =cut |
|---|
| 24 | |
|---|
| 25 | =head2 list |
|---|
| 26 | |
|---|
| 27 | Show a list of all shoutbox entries ever. |
|---|
| 28 | |
|---|
| 29 | =cut |
|---|
| 30 | |
|---|
| 31 | sub history : Path : Args(0) { |
|---|
| 32 | my ($self, $c) = @_; |
|---|
| 33 | my $s = $c->stash; |
|---|
| 34 | my $skip = $s->{skip} = $c->req->params->{skip} || 0; |
|---|
| 35 | |
|---|
| 36 | $s->{page_title} = 'Shoutbox'; |
|---|
| 37 | $s->{extra_css} = 'index'; |
|---|
| 38 | |
|---|
| 39 | $s->{shouts_rs} = $c->model('DBIC::Shoutbox')->search(undef, { |
|---|
| 40 | order_by => 'time DESC', |
|---|
| 41 | prefetch => ['user'], |
|---|
| 42 | rows => $c->site_opts->{page_sizes}{shoutbox}, |
|---|
| 43 | offset => $skip, |
|---|
| 44 | }); |
|---|
| 45 | |
|---|
| 46 | $s->{shout_total} = $c->model('DBIC::Shoutbox')->count; |
|---|
| 47 | |
|---|
| 48 | $s->{template} = 'shoutbox.tt'; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | =head2 post |
|---|
| 52 | |
|---|
| 53 | Posts some stupid spam :( |
|---|
| 54 | |
|---|
| 55 | =cut |
|---|
| 56 | |
|---|
| 57 | sub post : Local : Args(0) { |
|---|
| 58 | my ($self, $c) = @_; |
|---|
| 59 | my $s = $c->stash; |
|---|
| 60 | |
|---|
| 61 | my $content = Vee::Utils::fix_newlines( $c->req->params->{content} ); |
|---|
| 62 | my $name = $c->req->params->{name} |
|---|
| 63 | || ($c->user ? $c->user->name : 'Anonymous'); |
|---|
| 64 | |
|---|
| 65 | if (!$content) { |
|---|
| 66 | $c->vee_abort("Sorry, no mimes allowed."); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | (my $linect = $content) =~ tr/\x0a//cd; |
|---|
| 70 | if (length($linect) >= 10) { # TODO: make me a pref! |
|---|
| 71 | $c->vee_abort("Your shoutbox entry has too many lines, sorry."); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | # TODO: better spamproofing of some sort later, maybe? |
|---|
| 75 | if ($content =~ m!<a |</a>|\[url=|\[/url\]!) { |
|---|
| 76 | $c->vee_abort("Your shoutbox entry contains links. This usually means you are a spambot, in which case you can shove your online poker ads where the sun don't shine. If you are not, simply go back and try again without the code; HTML and bbcode don't work in the shoutbox anyway."); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | $c->model('DBIC::Shoutbox')->create({ |
|---|
| 80 | name => $name, |
|---|
| 81 | user_id => ($c->user ? $c->user->obj->id : undef), |
|---|
| 82 | ip => Vee::Utils::inet_aton($c->req->address), |
|---|
| 83 | time => time, |
|---|
| 84 | content => $content, |
|---|
| 85 | }); |
|---|
| 86 | |
|---|
| 87 | $c->res->redirect( $c->uri_for('/') ); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | =head1 AUTHOR |
|---|
| 91 | |
|---|
| 92 | Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>) |
|---|
| 93 | |
|---|
| 94 | See the included F<AUTHORS> file for a full list of contributers. |
|---|
| 95 | |
|---|
| 96 | =head1 LICENSE |
|---|
| 97 | |
|---|
| 98 | See the included F<LICENSE> file. |
|---|
| 99 | |
|---|
| 100 | =cut |
|---|
| 101 | |
|---|
| 102 | 1; |
|---|