2 package POE::Component::IRC::Plugin::NoPaste::Httpd::Pasted;
6 use POE::Component::IRC::Plugin::NoPaste::Httpd;
7 use POE::Component::IRC::Plugin::NoPaste::StaticFile;
8 use Locale::TextDomain qw(pci-nopaste);
11 use Time::Format qw(%time);
12 use Encode qw(from_to);
15 my ($this, $req, $resp) = @_;
17 if ($req->uri->path =~ m!^/pasted/(\d+)$!) {
18 return pasted_handler(
19 $this, $req, $resp, $1);
22 return notfound_handler(@_);
27 my ($this, $req, $resp, $post_id) = @_;
29 # check for the existence of line in db
30 my $post = $this->{nopaste}{db}->dbh->selectrow_hashref(q{
37 return notfound_handler(@_);
40 # is the channel_id still defined?
41 my $ch = $this->{nopaste}{id_to_channel}{$post->{channel_id}};
43 # no. probably there should be some way to change channel_id.
44 return notfound_handler(@_);
55 local $ENV{LANGUAGE} = $ch->{locale};
57 my $t = POE::Component::IRC::Plugin::NoPaste::Template->new(
58 -data => static_file('tmpl/pasted.html'));
61 lang => $ch->{locale},
62 title => $escape->("NoPaste :: $ch->{name}"),
65 my ($ptr) = gethostbyaddr(
66 inet_aton($req->{connection}->remote_ip), AF_INET);
67 my @readable = $this->{nopaste}->pickup_readable($ch->{id}, $ptr);
69 if (@readable or $ch->{restriction}{read} eq 'any') {
70 # we want to know which are the next and the previous posts.
71 my $prev = $this->{nopaste}{db}->dbh->selectrow_hashref(q{
74 WHERE channel_id = ? AND posted_time > ?
76 }, undef, $ch->{id}, $post->{posted_time});
77 my $next = $this->{nopaste}{db}->dbh->selectrow_hashref(q{
80 WHERE channel_id = ? AND posted_time < ?
82 }, undef, $ch->{id}, $post->{posted_time});
85 $t->readable->prev->add(
86 id => $prev->{post_id},
88 "Pasted by {name}", name => $escape->($prev->{nick})),
89 title => $escape->($prev->{title}),
93 channel_id => $ch->{id},
94 l18n_index => __"Index",
97 $t->readable->next->add(
98 id => $next->{post_id},
100 "Pasted by {name}", name => $escape->($next->{nick})),
101 title => $escape->($next->{title}),
106 l18n_name => __"Name",
107 name => $escape->($post->{nick}),
108 l18n_title => __"Title",
109 title => $escape->($post->{title}),
110 l18n_body => __"Body",
111 body => $escape->($post->{body}),
115 my $msg = $this->{nopaste}->gen_unreadable_error($ch);
116 $msg =~ s!\n!<br />!g;
118 $t->not_readable->add(
123 $resp->content($t->str);