cd1338631b08e7ce48dc7658416db768a888ded6
[pr0n] / perl / Sesse / pr0n / Index.pm
1 package Sesse::pr0n::Index;
2 use strict;
3 use warnings;
4
5 use Sesse::pr0n::Common qw(error dberror);
6 use POSIX;
7
8 sub handler {
9         my $r = shift;
10         my $dbh = Sesse::pr0n::Common::get_dbh();
11
12         my ($event, $abspath, $datesort);
13         if ($r->path_info =~ /^\/\+all\/?/) {
14                 $event = '+all';
15                 $abspath = 1;
16
17                 $datesort = 'DESC NULLS LAST';
18         } else {
19                 # Find the event
20                 $r->path_info =~ /^\/([a-zA-Z0-9-]+)\/?$/
21                         or return error($r, "Could not extract event");
22                 $event = $1;
23                 $abspath = 0;
24                 $datesort = 'ASC NULLS LAST';
25         }
26
27         # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/
28         if ($r->path_info !~ /\/$/) {
29                 my $res = Plack::Response->new(301);
30                 $res->header('Location' => $r->path_info . "/");
31                 return $res;
32         }
33
34         # Internal? (Ugly?) 
35         if (Sesse::pr0n::Common::get_server_name($r) =~ /internal/ ||
36             Sesse::pr0n::Common::get_server_name($r) =~ /skoyen\.bilder\.knatten\.com/ ||
37             Sesse::pr0n::Common::get_server_name($r) =~ /lia\.heimdal\.org/) {
38                 my $user = Sesse::pr0n::Common::check_access($r);
39                 return Sesse::pr0n::Common::generate_401($r) if (!defined($user));
40         }
41
42         # Read the appropriate settings from the query string into the settings hash
43         my %defsettings = (
44                 thumbxres => 320,
45                 thumbyres => 256,
46                 xres => -1,
47                 yres => -1,
48                 start => 1,
49                 num => 250,
50                 all => 1,
51                 infobox => 1,
52                 rot => 0,
53                 sel => 0,
54                 fullscreen => 0,
55                 model => undef,
56                 lens => undef,
57                 author => undef
58         );
59         
60         my $where;
61         if ($event eq '+all') {
62                 $where = '';
63         } else {
64                 $where = ' AND event=' . $dbh->quote($event);
65         }
66         
67         # Any NEF files => default to processing
68         my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND ( LOWER(filename) LIKE '%.nef' OR LOWER(filename) LIKE '%.cr2' ) LIMIT 1",
69                 undef, Sesse::pr0n::Common::get_server_name($r))
70                 and $defsettings{'xres'} = $defsettings{'yres'} = undef;
71         
72         # Reduce the front page load when in overload mode.
73         if (Sesse::pr0n::Overload::is_in_overload($r)) {
74                 $defsettings{'num'} = 100;
75         }
76                 
77         my %settings = %defsettings;
78
79         for my $s (qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens author)) {
80                 my $val = $r->param($s);
81                 if (defined($val) && $val =~ /^(\d+)$/) {
82                         $settings{$s} = $val;
83                 }
84                 if ($s eq "num" && defined($val) && $val == -1) {
85                         $settings{$s} = $val;
86                 }
87                 if (($s eq "xres" || $s eq "yres") && defined($val) && ($val == -1 || $val == -2)) {
88                         $settings{$s} = $val;
89                 }
90                 if (($s eq "model" || $s eq "lens" || $s eq "author") && defined($val)) {
91                         $settings{$s} = Sesse::pr0n::Common::pretty_unescape($val);
92                 }
93         }
94
95         my $thumbxres = $settings{'thumbxres'};
96         my $thumbyres = $settings{'thumbyres'};
97         my $xres = $settings{'xres'};
98         my $yres = $settings{'yres'};
99         my $start = $settings{'start'};
100         my $num = $settings{'num'};
101         my $all = $settings{'all'};
102         my $infobox = $settings{'infobox'} ? '' : 'nobox/';
103         my $rot = $settings{'rot'};
104         my $sel = $settings{'sel'};
105         my $model = $settings{'model'};
106         my $lens = $settings{'lens'};
107         my $author = $settings{'author'};
108
109         # Construct SQL for this filter
110         if ($all == 0) {
111                 $where .= ' AND selected=\'t\'';        
112         }
113         if (defined($model) && defined($lens)) {
114                 my $mq = $dbh->quote($model);
115                 my $lq = $dbh->quote($lens);
116
117                 if ($model eq '') {
118                         # no defined model
119                         $where .= " AND model IS NULL";
120                 } else {
121                         $where .= " AND model=$mq";
122                 }
123         
124                 if ($lens eq '') {
125                         # no defined lens
126                         $where .= " AND lens IS NULL";
127                 } else {
128                         $where .= " AND lens=$lq";
129                 }
130         }
131         if (defined($author)) {
132                 my $aq = $dbh->quote($author);
133
134                 $where .= " AND takenby=$aq";
135         }
136
137         if (defined($num) && $num == -1) {
138                 $num = undef;
139         }
140
141         my ($date, $name);
142
143         if ($event eq '+all') {
144                 $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM last_picture_cache WHERE vhost=?",
145                         undef, Sesse::pr0n::Common::get_server_name($r))
146                         or return error($r, "Could not list events", 404, "File not found");
147                 $date = undef;
148                 $name = Sesse::pr0n::Templates::fetch_template($r, 'all-event-title');
149                 Sesse::pr0n::Common::set_last_modified($r, $ref->{'last_update'});
150         } else {
151                 $ref = $dbh->selectrow_hashref("SELECT name,date,EXTRACT(EPOCH FROM last_update) AS last_update FROM events NATURAL JOIN last_picture_cache WHERE vhost=? AND event=?",
152                         undef, Sesse::pr0n::Common::get_server_name($r), $event)
153                         or return error($r, "Could not find event $event", 404, "File not found");
154
155                 $date = HTML::Entities::encode_entities($ref->{'date'});
156                 $name = HTML::Entities::encode_entities($ref->{'name'});
157                 Sesse::pr0n::Common::set_last_modified($r, $ref->{'last_update'});
158         }
159                                 
160         # # If the client can use cache, do so
161         # if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
162         #       return $rc;
163         # }
164         
165         # Count the number of selected images.
166         $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS num_selected FROM images WHERE vhost=? $where AND selected=\'t\'", undef, Sesse::pr0n::Common::get_server_name($r));
167         my $num_selected = $ref->{'num_selected'};
168
169         # Find all images related to this event.
170         my $limit = (defined($start) && defined($num) && !$settings{'fullscreen'}) ? (" LIMIT $num OFFSET " . ($start-1)) : "";
171
172         my $q = $dbh->prepare("SELECT *, (date - INTERVAL '6 hours')::date AS day FROM images WHERE vhost=? $where ORDER BY (date - INTERVAL '6 hours')::date $datesort,takenby,date,filename $limit")
173                 or return dberror($r, "prepare()");
174         $q->execute(Sesse::pr0n::Common::get_server_name($r))
175                 or return dberror($r, "image enumeration");
176
177         # Print the page itself
178         my $res = Plack::Response->new(200);
179         my $io = IO::String->new;
180         if ($settings{'fullscreen'}) {
181                 $res->content_type("text/html; charset=utf-8");
182
183                 Sesse::pr0n::Templates::print_template($r, $io, "fullscreen-header", { title => "$name [$event]" });
184
185                 my @files = ();
186                 while (my $ref = $q->fetchrow_hashref()) {
187                         my $width = defined($ref->{'width'}) ? $ref->{'width'} : -1;
188                         my $height = defined($ref->{'height'}) ? $ref->{'height'} : -1;
189                         push @files, [ $ref->{'event'}, $ref->{'filename'}, $width, $height ];
190                 }
191                 
192                 for my $i (0..$#files) {
193                         my $line = sprintf "        [ \"%s\", \"%s\", %d, %d ]", @{$files[$i]};
194                         $line .= "," unless ($i == $#files);
195                         $io->print($line . "\n");
196                 }
197
198                 my %settings_no_fullscreen = %settings;
199                 $settings_no_fullscreen{'fullscreen'} = 0;
200
201                 my $returnurl = "http://" . Sesse::pr0n::Common::get_server_name($r) . "/" . $event . "/" .
202                         Sesse::pr0n::Common::get_query_string(\%settings_no_fullscreen, \%defsettings);
203                 
204                 # *whistle*
205                 $returnurl =~ s/&/&/g;
206
207                 Sesse::pr0n::Templates::print_template($r, $io, "fullscreen-footer", {
208                         returnurl => $returnurl,
209                         start => $settings{'start'} - 1,
210                         sel => $settings{'sel'},
211                         infobox => $infobox
212                 });
213         } else {
214                 Sesse::pr0n::Common::header($r, $io, "$name [$event]");
215                 if (defined($date)) {
216                         Sesse::pr0n::Templates::print_template($r, $io, "date", { date => $date });
217                 }
218
219                 if (Sesse::pr0n::Overload::is_in_overload($r)) {
220                         Sesse::pr0n::Templates::print_template($r, $io, "overloadmode");
221                 }
222
223                 print_viewres($r, $io, $event, \%settings, \%defsettings);
224                 print_pagelimit($r, $io, $event, \%settings, \%defsettings);
225                 print_infobox($r, $io, $event, \%settings, \%defsettings);
226                 print_selected($r, $io, $event, \%settings, \%defsettings) if ($num_selected > 0);
227                 print_fullscreen($r, $io, $event, \%settings, \%defsettings);
228                 print_nextprev($r, $io, $event, $where, \%settings, \%defsettings);
229         
230                 if (1 || $event ne '+all') {
231                         # Find the equipment used
232                         my $eq = $dbh->prepare("
233                                 SELECT
234                                         model,
235                                         lens,
236                                         COUNT(*) AS num
237                                 FROM images
238                                 WHERE vhost=? $where
239                                 GROUP BY 1,2
240                                 ORDER BY 1,2")
241                                 or die "Couldn't prepare to find equipment: $!";
242                         $eq->execute(Sesse::pr0n::Common::get_server_name($r))
243                                 or die "Couldn't find equipment: $!";
244
245                         my @equipment = ();
246                         my %cameras_seen = ();
247                         while (my $ref = $eq->fetchrow_hashref) {
248                                 if (!defined($ref->{'lens'}) && exists($cameras_seen{$ref->{'model'}})) {
249                                         #
250                                         # Some compact cameras seem to add lens info sometimes and not at other
251                                         # times; if we have seen a camera with at least one specific lens earlier,
252                                         # just combine entries without a lens with the previous one.
253                                         #
254                                         $equipment[$#equipment]->{'num'} += $ref->{'num'};
255                                         next;
256                                 }
257                                 push @equipment, $ref;
258                                 $cameras_seen{$ref->{'model'}} = 1;
259                         }
260                         $eq->finish;
261
262                         if (scalar @equipment > 0) {
263                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-start");
264                                 for my $e (@equipment) {
265                                         my $eqspec = $e->{'model'};
266                                         $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'}));
267                                         $eqspec = HTML::Entities::encode_entities($eqspec);
268
269                                         my %newsettings = %settings;
270
271                                         my $action;
272                                         if (defined($model) && defined($lens)) {
273                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter"));
274                                                 $newsettings{'model'} = undef;
275                                                 $newsettings{'lens'} = undef;
276                                                 $newsettings{'start'} = 1;
277                                         } else {
278                                                 chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter"));
279                                                 $newsettings{'model'} = $e->{'model'};
280                                                 $newsettings{'lens'} = defined($e->{'lens'}) ? $e->{'lens'} : '';
281                                                 $newsettings{'start'} = 1;
282                                         }
283                                         
284                                         my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
285
286                                         # This isn't correct for all languages. Fix if we ever need to care. :-)
287                                         if ($e->{'num'} == 1) {
288                                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url, action => $action });
289                                         } else {
290                                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url, action => $action });
291                                         }
292                                 }
293                                 Sesse::pr0n::Templates::print_template($r, $io, "equipment-end");
294                         }
295                 }
296
297                 my $toclose = 0;
298                 my $lastupl = "";
299                 my $img_num = (defined($start) && defined($num)) ? $start : 1;
300                 
301                 # Print out all thumbnails
302                 if ($rot == 1) {
303                         $io->print("    <form method=\"post\" action=\"/rotate\">\n");
304                         $io->print("      <input type=\"hidden\" name=\"event\" value=\"$event\" />\n");
305                 }
306
307                 while (my $ref = $q->fetchrow_hashref()) {
308                         my $imgsz = "";
309                         my $takenby = $ref->{'takenby'};
310                         my $day = '';
311                         if (defined($ref->{'day'})) {
312                                 $day = ", " . $ref->{'day'};
313                         }
314
315                         my $groupkey = $takenby . $day;
316
317                         if ($groupkey ne $lastupl) {
318                                 $io->print("    </p>\n\n") if ($lastupl ne "" && $rot != 1);
319                                 $lastupl = $groupkey;
320
321                                 my %newsettings = %settings;
322
323                                 my $action;
324                                 if (defined($author)) {
325                                         chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter"));
326                                         $newsettings{'author'} = undef;
327                                         $newsettings{'start'} = 1;
328                                 } else {
329                                         chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter"));
330                                         $newsettings{'author'} = $ref->{'takenby'};
331                                         $newsettings{'start'} = 1;
332                                 }
333
334                                 my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings);
335                                 
336                                 $io->print("    <h2>");
337                                 Sesse::pr0n::Templates::print_template($r, $io, "submittedby", { author => $takenby, action => $action, filterurl => $url, date => $day });
338                                 print_fullscreen_fromhere($r, $io, $event, \%settings, \%defsettings, $img_num);
339                                 $io->print("</h2>\n");
340
341                                 if ($rot != 1) {
342                                         $io->print("    <p class=\"photos\">\n");
343                                 }
344                         }
345
346                         if (defined($ref->{'width'}) && defined($ref->{'height'})) {
347                                 my $width = $ref->{'width'};
348                                 my $height = $ref->{'height'};
349                                         
350                                 ($width, $height) = Sesse::pr0n::Common::scale_aspect($width, $height, $thumbxres, $thumbyres);
351                                 $imgsz = " width=\"$width\" height=\"$height\"";
352                         }
353
354                         my $filename = $ref->{'filename'};
355                         my $uri = $infobox . $filename;
356                         if (defined($xres) && defined($yres) && $xres != -1 && $xres != -2) {
357                                 $uri = "${xres}x$yres/$infobox$filename";
358                         } elsif (defined($xres) && $xres == -1) {
359                                 $uri = "original/$infobox$filename";
360                         }
361                         
362                         my $prefix = "";
363                         if ($abspath) {
364                                 $prefix = "/" . $ref->{'event'} . "/";
365                         }
366                 
367                         if ($rot == 1) {        
368                                 $io->print("    <p>");
369                         } else {
370                                 $io->print("     ");
371                         }
372                         $io->print("<a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
373                 
374                         if ($rot == 1) {
375                                 $io->print("      90 <input type=\"checkbox\" name=\"rot-" .
376                                         $ref->{'id'} . "-90\" />\n");
377                                 $io->print("      180 <input type=\"checkbox\" name=\"rot-" .
378                                         $ref->{'id'} . "-180\" />\n");
379                                 $io->print("      270 <input type=\"checkbox\" name=\"rot-" .
380                                         $ref->{'id'} . "-270\" />\n");
381                                 $io->print("      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
382                                         "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Del <input type=\"checkbox\" name=\"del-" . $ref->{'id'} . "\" /></p>\n");
383                         }
384                         
385                         ++$img_num;
386                 }
387
388                 if ($rot == 1) {
389                         $io->print("      <input type=\"submit\" value=\"Rotate\" />\n");
390                         $io->print("    </form>\n");
391                 } else {
392                         $io->print("    </p>\n");
393                 }
394
395                 print_nextprev($r, $io, $event, $where, \%settings, \%defsettings);
396                 Sesse::pr0n::Common::footer($r, $io);
397         }
398
399         $io->setpos(0);
400         $res->body($io);
401         return $res;
402 }
403
404 sub eq_with_undef {
405         my ($a, $b) = @_;
406         
407         return 1 if (!defined($a) && !defined($b));
408         return 0 unless (defined($a) && defined($b));
409         return ($a eq $b);
410 }
411
412 sub print_changes {
413         my ($r, $io, $event, $template, $settings, $defsettings, $var1, $var2, $alternatives) = @_;
414
415         my $title = Sesse::pr0n::Templates::fetch_template($r, $template);
416         chomp $title;
417         $io->print("    <p>$title:\n");
418
419         for my $a (@$alternatives) {
420                 my $text;
421                 my %newsettings = %$settings;
422
423                 if (ref $a) {
424                         my ($v1, $v2);
425                         ($text, $v1, $v2) = @$a;
426                         
427                         $newsettings{$var1} = $v1;
428                         $newsettings{$var2} = $v2;
429                 } else {
430                         $text = $a;
431
432                         # Parse the current alternative
433                         my ($v1, $v2) = split /x/, $a;
434
435                         $newsettings{$var1} = $v1;
436                         $newsettings{$var2} = $v2;
437                 }
438
439                 $io->print("      ");
440
441                 # Check if these settings are current (print only label)
442                 if (eq_with_undef($settings->{$var1}, $newsettings{$var1}) &&
443                     eq_with_undef($settings->{$var2}, $newsettings{$var2})) {
444                         $io->print($text);
445                 } else {
446                         Sesse::pr0n::Common::print_link($io, $text, "/$event/", \%newsettings, $defsettings);
447                 }
448                 $io->print("\n");
449         }
450         $io->print("    </p>\n");
451 }
452
453 sub print_viewres {
454         my ($r, $io, $event, $settings, $defsettings) = @_;
455         my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1152x864 1280x960 1400x1050 1600x1200 1920x1440 2048x1536 2304x1728);
456         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited'));
457         chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original'));
458         push @alternatives, [ $unlimited, -2, -2 ];
459         push @alternatives, [ $original, -1, -1 ];
460
461         print_changes($r, $io, $event, 'viewres', $settings, $defsettings,
462                       'xres', 'yres', \@alternatives);
463 }
464
465 sub print_pagelimit {
466         my ($r, $io, $event, $settings, $defsettings) = @_;
467         
468         my $title = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage');
469         chomp $title;
470         $io->print("    <p>$title:\n");
471         
472         # Get choices
473         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage-unlimited'));
474         my @alternatives = qw(10 50 100 250 500);
475         push @alternatives, $unlimited;
476         
477         for my $num (@alternatives) {
478                 my %newsettings = %$settings;
479
480                 if ($num !~ /^\d+$/) { # unlimited
481                         $newsettings{'num'} = -1;
482                 } else {
483                         $newsettings{'num'} = $num;
484                 }
485
486                 $io->print("      ");
487                 if (eq_with_undef($settings->{'num'}, $newsettings{'num'})) {
488                         $io->print($num);
489                 } else {
490                         Sesse::pr0n::Common::print_link($io, $num, "/$event/", \%newsettings, $defsettings);
491                 }
492                 $io->print("\n");
493         }
494         $io->print("    </p>\n");
495 }
496
497 sub print_infobox {
498         my ($r, $io, $event, $settings, $defsettings) = @_;
499
500         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'infobox'));
501         chomp (my $on = Sesse::pr0n::Templates::fetch_template($r, 'infobox-on'));
502         chomp (my $off = Sesse::pr0n::Templates::fetch_template($r, 'infobox-off'));
503
504         $io->print("    <p>$title:\n");
505
506         my %newsettings = %$settings;
507
508         if ($settings->{'infobox'} == 1) {
509                 $io->print($on);
510         } else {
511                 $newsettings{'infobox'} = 1;
512                 Sesse::pr0n::Common::print_link($io, $on, "/$event/", \%newsettings, $defsettings);
513         }
514
515         $io->print(' ');
516
517         if ($settings->{'infobox'} == 0) {
518                 $io->print($off);
519         } else {
520                 $newsettings{'infobox'} = 0;
521                 Sesse::pr0n::Common::print_link($io, $off, "/$event/", \%newsettings, $defsettings);
522         }
523         
524         $io->print('</p>');
525 }
526
527 sub print_nextprev {
528         my ($r, $io, $event, $where, $settings, $defsettings) = @_;
529         my $start = $settings->{'start'};
530         my $num = $settings->{'num'};
531         my $dbh = Sesse::pr0n::Common::get_dbh();
532
533         $num = undef if (defined($num) && $num == -1);
534         return unless (defined($start) && defined($num));
535
536         # determine total number
537         my $ref = $dbh->selectrow_hashref("SELECT count(*) AS num_images FROM images WHERE vhost=? $where",
538                 undef, Sesse::pr0n::Common::get_server_name($r))
539                 or return dberror($r, "image enumeration");
540         my $num_images = $ref->{'num_images'};
541
542         return if ($start == 1 && $start + $num >= $num_images);
543
544         my $end = $start + $num - 1;
545         if ($end > $num_images) {
546                 $end = $num_images;
547         }
548
549         $io->print("    <p class=\"nextprev\">\n");
550
551         # Previous
552         if ($start > 1) {
553                 my $newstart = $start - $num;
554                 if ($newstart < 1) {
555                         $newstart = 1;
556                 }
557                 my $newend = $newstart + $num - 1;
558                 if ($newend > $num_images) {
559                         $newend = $num_images;
560                 }
561
562                 my %newsettings = %$settings;
563                 $newsettings{'start'} = $newstart;
564                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'prevpage'));
565                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'prevaccesskey'));
566                 Sesse::pr0n::Common::print_link($io, "$title ($newstart-$newend)\n", "/$event/", \%newsettings, $defsettings, $accesskey);
567         }
568
569         # This
570         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'thispage'));
571         $io->print("    $title ($start-$end)\n");
572
573         # Next
574         if ($end < $num_images) {
575                 my $newstart = $start + $num;
576                 my $newend = $newstart + $num - 1;
577                 if ($newend > $num_images) {
578                         $newend = $num_images;
579                 }
580                 
581                 my %newsettings = %$settings;
582                 $newsettings{'start'} = $newstart;
583                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'nextpage'));
584                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'nextaccesskey'));
585                 Sesse::pr0n::Common::print_link($io, "$title ($newstart-$newend)", "/$event/", \%newsettings, $defsettings, $accesskey);
586         }
587
588         $io->print("    </p>\n");
589 }
590
591 sub print_selected {
592         my ($r, $io, $event, $settings, $defsettings) = @_;
593
594         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'show'));
595         chomp (my $all = Sesse::pr0n::Templates::fetch_template($r, 'show-all'));
596         chomp (my $sel = Sesse::pr0n::Templates::fetch_template($r, 'show-selected'));
597
598         $io->print("    <p>$title:\n");
599
600         my %newsettings = %$settings;
601
602         if ($settings->{'all'} == 0) {
603                 $io->print($sel);
604         } else {
605                 $newsettings{'all'} = 0;
606                 Sesse::pr0n::Common::print_link($io, $sel, "/$event/", \%newsettings, $defsettings);
607         }
608
609         $io->print(' ');
610
611         if ($settings->{'all'} == 1) {
612                 $io->print($all);
613         } else {
614                 $newsettings{'all'} = 1;
615                 Sesse::pr0n::Common::print_link($io, $all, "/$event/", \%newsettings, $defsettings);
616         }
617         
618         $io->print('</p>');
619 }
620
621 sub print_fullscreen {
622         my ($r, $io, $event, $settings, $defsettings) = @_;
623
624         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen'));
625
626         my %newsettings = %$settings;
627         $newsettings{'fullscreen'} = 1;
628
629         $io->print("    <p>");
630         Sesse::pr0n::Common::print_link($io, $title, "/$event/", \%newsettings, $defsettings);
631         $io->print("</p>\n");
632 }
633
634 sub print_fullscreen_fromhere {
635         my ($r, $io, $event, $settings, $defsettings, $start) = @_;
636
637         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen-fromhere'));
638
639         my %newsettings = %$settings;
640         $newsettings{'fullscreen'} = 1;
641         $newsettings{'start'} = $start;
642
643         $io->print("    <span class=\"fsfromhere\">");
644         Sesse::pr0n::Common::print_link($io, $title, "/$event/", \%newsettings, $defsettings);
645         $io->print("</span>\n");
646 }
647         
648 1;
649
650