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