Drop an unneeded $r->subprocess_env.
[pr0n] / perl / Sesse / pr0n / Listing.pm
1 package Sesse::pr0n::Listing;
2 use strict;
3 use warnings;
4
5 use Sesse::pr0n::Common qw(error dberror);
6
7 sub handler {
8         my $r = shift;
9         my $dbh = Sesse::pr0n::Common::get_dbh();
10
11         # Internal? (Ugly?)
12         if ($r->get_server_name =~ /internal/ || $r->get_server_name =~ /skoyen\.bilder\.knatten\.com/) {
13                 my $user = Sesse::pr0n::Common::check_access($r);
14                 if (!defined($user)) {
15                         return Apache2::Const::OK;
16                 }
17         }
18
19 #       my $q = $dbh->prepare('SELECT t1.id,t1.date,t1.name FROM events t1 LEFT JOIN images t2 ON t1.id=t2.event WHERE t1.vhost=? GROUP BY t1.id,t1.date,t1.name ORDER BY COALESCE(MAX(t2.date),\'1970-01-01 00:00:00\'),t1.id') or
20 #               dberror($r, "Couldn't list events");
21         my $q = $dbh->prepare('SELECT id,date,name FROM events e JOIN last_picture_cache c ON e.id=c.event WHERE vhost=? ORDER BY last_picture DESC')
22                 or dberror($r, "Couldn't list events");
23         $q->execute($r->get_server_name)
24                 or dberror($r, "Couldn't get events");
25
26         $r->content_type('text/html; charset=utf-8');
27
28         Sesse::pr0n::Common::header($r, Sesse::pr0n::Templates::fetch_template($r, 'event-listing'));
29         $r->print("    <ul>\n");
30
31         while (my $ref = $q->fetchrow_hashref()) {
32                 my $id = $ref->{'id'};
33                 my $date = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'date'}));
34                 my $name = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'name'}));
35                 
36                 $r->print("      <li><a href=\"$id/\">$name</a> ($date)</li>\n");
37         }
38
39         $r->print("    </ul>\n");
40         Sesse::pr0n::Common::footer($r);
41
42         $q->finish();
43         return Apache2::Const::OK;
44 }
45
46 1;
47
48