Fix some Perl deprecation warnings. Patches from xim.
[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 Apache2::Request;
7 use POSIX;
8
9 sub handler {
10         my $r = shift;
11         my $apr = Apache2::Request->new($r);
12         my $dbh = Sesse::pr0n::Common::get_dbh();
13
14         my ($event, $abspath, $datesort, $tag);
15         if ($r->uri =~ /^\/\+all\/?/) {
16                 $event = '+all';
17                 $abspath = 1;
18                 $tag = undef; 
19
20                 $datesort = 'DESC NULLS LAST';
21         } elsif ($r->uri =~ /^\/\+tags\/([a-zA-Z0-9-]+)\/?$/) {
22                 $tag = $1;
23                 $event = "+tags/$tag";
24                 $abspath = 1;
25                 
26                 $datesort = 'DESC NULLS LAST';
27         } else {
28                 # Find the event
29                 $r->uri =~ /^\/([a-zA-Z0-9-]+)\/?$/
30                         or error($r, "Could not extract event");
31                 $event = $1;
32                 $abspath = 0;
33                 $tag = undef;
34                 $datesort = 'ASC NULLS LAST';
35         }
36
37         # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/
38         if ($r->uri !~ /\/$/) {
39                 $r->headers_out->{'location'} = $r->uri . "/";
40                 return Apache2::Const::REDIRECT;
41         }
42
43         # Internal? (Ugly?) 
44         if ($r->get_server_name =~ /internal/ || $r->get_server_name =~ /skoyen\.bilder\.knatten\.com/ || $r->get_server_name =~ /lia\.heimdal\.org/) {
45                 my $user = Sesse::pr0n::Common::check_access($r);
46                 if (!defined($user)) {
47                         return Apache2::Const::OK;
48                 }
49         }
50
51         # Read the appropriate settings from the query string into the settings hash
52         my %defsettings = (
53                 thumbxres => 80,
54                 thumbyres => 64,
55                 xres => -1,
56                 yres => -1,
57                 start => 1,
58                 num => 250,
59                 all => 1,
60                 infobox => 1,
61                 rot => 0,
62                 sel => 0,
63                 fullscreen => 0,
64                 model => undef,
65                 lens => undef,
66                 author => undef
67         );
68         
69         my $where;
70         if (defined($tag)) {
71                 my $tq = $dbh->quote($tag);
72                 $where = " AND id IN ( SELECT image FROM tags WHERE tag=$tq )";
73         } elsif ($event eq '+all') {
74                 $where = '';
75         } else {
76                 $where = ' AND event=' . $dbh->quote($event);
77         }
78         
79         # Any NEF files => default to processing
80         my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND ( LOWER(filename) LIKE '%.nef' OR LOWER(filename) LIKE '%.cr2' ) LIMIT 1",
81                 undef, $r->get_server_name)
82                 and $defsettings{'xres'} = $defsettings{'yres'} = undef;
83         
84         # Reduce the front page load when in overload mode.
85         if (Sesse::pr0n::Overload::is_in_overload($r)) {
86                 $defsettings{'num'} = 100;
87         }
88                 
89         my %settings = %defsettings;
90
91         for my $s (qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens author)) {
92                 my $val = $apr->param($s);
93                 if (defined($val) && $val =~ /^(\d+)$/) {
94                         $settings{$s} = $val;
95                 }
96                 if ($s eq "num" && defined($val) && $val == -1) {
97                         $settings{$s} = $val;
98                 }
99                 if (($s eq "xres" || $s eq "yres") && defined($val) && ($val == -1 || $val == -2)) {
100                         $settings{$s} = $val;
101                 }
102                 if (($s eq "model" || $s eq "lens" || $s eq "author") && defined($val)) {
103                         $settings{$s} = Sesse::pr0n::Common::pretty_unescape($val);
104                 }
105         }
106
107         my $thumbxres = $settings{'thumbxres'};
108         my $thumbyres = $settings{'thumbyres'};
109         my $xres = $settings{'xres'};
110         my $yres = $settings{'yres'};
111         my $start = $settings{'start'};
112         my $num = $settings{'num'};
113         my $all = $settings{'all'};
114         my $infobox = $settings{'infobox'} ? '' : 'nobox/';
115         my $rot = $settings{'rot'};
116         my $sel = $settings{'sel'};
117         my $model = $settings{'model'};
118         my $lens = $settings{'lens'};
119         my $author = $settings{'author'};
120
121         # Construct SQL for this filter
122         if ($all == 0) {
123                 $where .= ' AND selected=\'t\'';        
124         }
125         if (defined($model) && defined($lens)) {
126                 my $mq = $dbh->quote($model);
127                 my $lq = $dbh->quote($lens);
128
129                 if ($model eq '') {
130                         # no defined model
131                         $where .= " AND model IS NULL";
132                 } else {
133                         $where .= " AND model=$mq";
134                 }
135         
136                 if ($lens eq '') {
137                         # no defined lens
138                         $where .= " AND lens IS NULL";
139                 } else {
140                         $where .= " AND lens=$lq";
141                 }
142         }
143         if (defined($author)) {
144                 my $aq = $dbh->quote($author);
145
146                 $where .= " AND takenby=$aq";
147         }
148
149         if (defined($num) && $num == -1) {
150                 $num = undef;
151         }
152
153         my ($date, $name);
154
155         if ($event eq '+all' || defined($tag)) {
156                 $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM last_picture_cache WHERE vhost=?",
157                         undef, $r->get_server_name)
158                         or error($r, "Could not list events", 404, "File not found");
159                 $date = undef;
160                 $name = Sesse::pr0n::Templates::fetch_template($r, 'all-event-title');
161                 $r->set_last_modified($ref->{'last_update'});
162         } else {
163                 $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=?",
164                         undef, $r->get_server_name, $event)
165                         or error($r, "Could not find event $event", 404, "File not found");
166
167                 $date = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'date'}));
168                 $name = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'name'}));
169                 $r->set_last_modified($ref->{'last_update'});
170         }
171                                 
172         # If the client can use cache, do so
173         if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
174                 return $rc;
175         }
176         
177         # Count the number of selected images.
178         $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS num_selected FROM images WHERE vhost=? $where AND selected=\'t\'", undef, $r->get_server_name);
179         my $num_selected = $ref->{'num_selected'};
180
181         # Find all images related to this event.
182         my $limit = (defined($start) && defined($num) && !$settings{'fullscreen'}) ? (" LIMIT $num OFFSET " . ($start-1)) : "";
183
184         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")
185                 or dberror($r, "prepare()");
186         $q->execute($r->get_server_name)
187                 or dberror($r, "image enumeration");
188
189         # Print the page itself
190         if ($settings{'fullscreen'}) {
191                 $r->content_type("text/html; charset=utf-8");
192
193                 if (defined($tag)) {
194                         my $title = Sesse::pr0n::Templates::process_template($r, "tag-title", { tag => $tag });
195                         Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => $title });
196                 } else {
197                         Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => "$name [$event]" });
198                 }
199
200                 my @files = ();
201                 while (my $ref = $q->fetchrow_hashref()) {
202                         my $width = defined($ref->{'width'}) ? $ref->{'width'} : -1;
203                         my $height = defined($ref->{'height'}) ? $ref->{'height'} : -1;
204                         push @files, [ $ref->{'event'}, $ref->{'filename'}, $width, $height ];
205                 }
206                 
207                 for my $i (0..$#files) {
208                         my $line = sprintf "        [ \"%s\", \"%s\", %d, %d ]", @{$files[$i]};
209                         $line .= "," unless ($i == $#files);
210                         $r->print($line . "\n");
211                 }
212
213                 my %settings_no_fullscreen = %settings;
214                 $settings_no_fullscreen{'fullscreen'} = 0;
215
216                 my $returnurl = "http://" . $r->get_server_name . "/" . $event . "/" .
217                         Sesse::pr0n::Common::get_query_string(\%settings_no_fullscreen, \%defsettings);
218                 
219                 # *whistle*
220                 $returnurl =~ s/&/&/g;
221
222                 Sesse::pr0n::Templates::print_template($r, "fullscreen-footer", {
223                         vhost => $r->get_server_name,
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, "tag-title", { tag => $tag });
232                         Sesse::pr0n::Common::header($r, $title);
233                 } else {
234                         Sesse::pr0n::Common::header($r, "$name [$event]");
235                 }
236                 if (defined($date)) {
237                         Sesse::pr0n::Templates::print_template($r, "date", { date => $date });
238                 }
239
240                 if (Sesse::pr0n::Overload::is_in_overload($r)) {
241                         Sesse::pr0n::Templates::print_template($r, "overloadmode");
242                 }
243
244                 print_thumbsize($r, $event, \%settings, \%defsettings);
245                 print_viewres($r, $event, \%settings, \%defsettings);
246                 print_pagelimit($r, $event, \%settings, \%defsettings);
247                 print_infobox($r, $event, \%settings, \%defsettings);
248                 print_selected($r, $event, \%settings, \%defsettings) if ($num_selected > 0);
249                 print_fullscreen($r, $event, \%settings, \%defsettings);
250                 print_nextprev($r, $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($r->get_server_name)
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, "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, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url, action => $action });
311                                         } else {
312                                                 Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url, action => $action });
313                                         }
314                                 }
315                                 Sesse::pr0n::Templates::print_template($r, "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                         $r->print("    <form method=\"post\" action=\"/rotate\">\n");
326                         $r->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                                 $r->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                                 $r->print("    <h2>");
359                                 Sesse::pr0n::Templates::print_template($r, "submittedby", { author => $takenby, action => $action, filterurl => $url, date => $day });
360                                 print_fullscreen_fromhere($r, $event, \%settings, \%defsettings, $img_num);
361                                 $r->print("</h2>\n");
362
363                                 if ($rot != 1) {
364                                         $r->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                                 $r->print("    <p>");
391                         } else {
392                                 $r->print("     ");
393                         }
394                         $r->print("<a href=\"$prefix$uri\"><img src=\"$prefix${thumbxres}x${thumbyres}/$filename\" alt=\"\"$imgsz /></a>\n");
395                 
396                         if ($rot == 1) {
397                                 $r->print("      90 <input type=\"checkbox\" name=\"rot-" .
398                                         $ref->{'id'} . "-90\" />\n");
399                                 $r->print("      180 <input type=\"checkbox\" name=\"rot-" .
400                                         $ref->{'id'} . "-180\" />\n");
401                                 $r->print("      270 <input type=\"checkbox\" name=\"rot-" .
402                                         $ref->{'id'} . "-270\" />\n");
403                                 $r->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                         $r->print("      <input type=\"submit\" value=\"Rotate\" />\n");
412                         $r->print("    </form>\n");
413                 } else {
414                         $r->print("    </p>\n");
415                 }
416
417                 print_nextprev($r, $event, $where, \%settings, \%defsettings);
418                 Sesse::pr0n::Common::footer($r);
419         }
420
421         return Apache2::Const::OK;
422 }
423
424 sub eq_with_undef {
425         my ($a, $b) = @_;
426         
427         return 1 if (!defined($a) && !defined($b));
428         return 0 unless (defined($a) && defined($b));
429         return ($a eq $b);
430 }
431
432 sub print_changes {
433         my ($r, $event, $template, $settings, $defsettings, $var1, $var2, $alternatives) = @_;
434
435         my $title = Sesse::pr0n::Templates::fetch_template($r, $template);
436         chomp $title;
437         $r->print("    <p>$title:\n");
438
439         for my $a (@$alternatives) {
440                 my $text;
441                 my %newsettings = %$settings;
442
443                 if (ref $a) {
444                         my ($v1, $v2);
445                         ($text, $v1, $v2) = @$a;
446                         
447                         $newsettings{$var1} = $v1;
448                         $newsettings{$var2} = $v2;
449                 } else {
450                         $text = $a;
451
452                         # Parse the current alternative
453                         my ($v1, $v2) = split /x/, $a;
454
455                         $newsettings{$var1} = $v1;
456                         $newsettings{$var2} = $v2;
457                 }
458
459                 $r->print("      ");
460
461                 # Check if these settings are current (print only label)
462                 if (eq_with_undef($settings->{$var1}, $newsettings{$var1}) &&
463                     eq_with_undef($settings->{$var2}, $newsettings{$var2})) {
464                         $r->print($text);
465                 } else {
466                         Sesse::pr0n::Common::print_link($r, $text, "/$event/", \%newsettings, $defsettings);
467                 }
468                 $r->print("\n");
469         }
470         $r->print("    </p>\n");
471 }
472
473 sub print_thumbsize {
474         my ($r, $event, $settings, $defsettings) = @_;
475         my @alternatives = qw(80x64 120x96 160x128 240x192 320x256);
476
477         print_changes($r, $event, 'thumbsize', $settings, $defsettings,
478                       'thumbxres', 'thumbyres', \@alternatives);
479 }
480 sub print_viewres {
481         my ($r, $event, $settings, $defsettings) = @_;
482         my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1152x864 1280x960 1400x1050 1600x1200 1920x1440 2048x1536);
483         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited'));
484         chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original'));
485         push @alternatives, [ $unlimited, -2, -2 ];
486         push @alternatives, [ $original, -1, -1 ];
487
488         print_changes($r, $event, 'viewres', $settings, $defsettings,
489                       'xres', 'yres', \@alternatives);
490 }
491
492 sub print_pagelimit {
493         my ($r, $event, $settings, $defsettings) = @_;
494         
495         my $title = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage');
496         chomp $title;
497         $r->print("    <p>$title:\n");
498         
499         # Get choices
500         chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'imgsperpage-unlimited'));
501         my @alternatives = qw(10 50 100 250 500);
502         push @alternatives, $unlimited;
503         
504         for my $num (@alternatives) {
505                 my %newsettings = %$settings;
506
507                 if ($num !~ /^\d+$/) { # unlimited
508                         $newsettings{'num'} = -1;
509                 } else {
510                         $newsettings{'num'} = $num;
511                 }
512
513                 $r->print("      ");
514                 if (eq_with_undef($settings->{'num'}, $newsettings{'num'})) {
515                         $r->print($num);
516                 } else {
517                         Sesse::pr0n::Common::print_link($r, $num, "/$event/", \%newsettings, $defsettings);
518                 }
519                 $r->print("\n");
520         }
521         $r->print("    </p>\n");
522 }
523
524 sub print_infobox {
525         my ($r, $event, $settings, $defsettings) = @_;
526
527         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'infobox'));
528         chomp (my $on = Sesse::pr0n::Templates::fetch_template($r, 'infobox-on'));
529         chomp (my $off = Sesse::pr0n::Templates::fetch_template($r, 'infobox-off'));
530
531         $r->print("    <p>$title:\n");
532
533         my %newsettings = %$settings;
534
535         if ($settings->{'infobox'} == 1) {
536                 $r->print($on);
537         } else {
538                 $newsettings{'infobox'} = 1;
539                 Sesse::pr0n::Common::print_link($r, $on, "/$event/", \%newsettings, $defsettings);
540         }
541
542         $r->print(' ');
543
544         if ($settings->{'infobox'} == 0) {
545                 $r->print($off);
546         } else {
547                 $newsettings{'infobox'} = 0;
548                 Sesse::pr0n::Common::print_link($r, $off, "/$event/", \%newsettings, $defsettings);
549         }
550         
551         $r->print('</p>');
552 }
553
554 sub print_nextprev {
555         my ($r, $event, $where, $settings, $defsettings) = @_;
556         my $start = $settings->{'start'};
557         my $num = $settings->{'num'};
558         my $dbh = Sesse::pr0n::Common::get_dbh();
559
560         $num = undef if (defined($num) && $num == -1);
561         return unless (defined($start) && defined($num));
562
563         # determine total number
564         my $ref = $dbh->selectrow_hashref("SELECT count(*) AS num_images FROM images WHERE vhost=? $where",
565                 undef, $r->get_server_name)
566                 or dberror($r, "image enumeration");
567         my $num_images = $ref->{'num_images'};
568
569         return if ($start == 1 && $start + $num >= $num_images);
570
571         my $end = $start + $num - 1;
572         if ($end > $num_images) {
573                 $end = $num_images;
574         }
575
576         $r->print("    <p class=\"nextprev\">\n");
577
578         # Previous
579         if ($start > 1) {
580                 my $newstart = $start - $num;
581                 if ($newstart < 1) {
582                         $newstart = 1;
583                 }
584                 my $newend = $newstart + $num - 1;
585                 if ($newend > $num_images) {
586                         $newend = $num_images;
587                 }
588
589                 my %newsettings = %$settings;
590                 $newsettings{'start'} = $newstart;
591                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'prevpage'));
592                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'prevaccesskey'));
593                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)\n", "/$event/", \%newsettings, $defsettings, $accesskey);
594         }
595
596         # This
597         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'thispage'));
598         $r->print("    $title ($start-$end)\n");
599
600         # Next
601         if ($end < $num_images) {
602                 my $newstart = $start + $num;
603                 my $newend = $newstart + $num - 1;
604                 if ($newend > $num_images) {
605                         $newend = $num_images;
606                 }
607                 
608                 my %newsettings = %$settings;
609                 $newsettings{'start'} = $newstart;
610                 chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'nextpage'));
611                 chomp (my $accesskey = Sesse::pr0n::Templates::fetch_template($r, 'nextaccesskey'));
612                 Sesse::pr0n::Common::print_link($r, "$title ($newstart-$newend)", "/$event/", \%newsettings, $defsettings, $accesskey);
613         }
614
615         $r->print("    </p>\n");
616 }
617
618 sub print_selected {
619         my ($r, $event, $settings, $defsettings) = @_;
620
621         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'show'));
622         chomp (my $all = Sesse::pr0n::Templates::fetch_template($r, 'show-all'));
623         chomp (my $sel = Sesse::pr0n::Templates::fetch_template($r, 'show-selected'));
624
625         $r->print("    <p>$title:\n");
626
627         my %newsettings = %$settings;
628
629         if ($settings->{'all'} == 0) {
630                 $r->print($sel);
631         } else {
632                 $newsettings{'all'} = 0;
633                 Sesse::pr0n::Common::print_link($r, $sel, "/$event/", \%newsettings, $defsettings);
634         }
635
636         $r->print(' ');
637
638         if ($settings->{'all'} == 1) {
639                 $r->print($all);
640         } else {
641                 $newsettings{'all'} = 1;
642                 Sesse::pr0n::Common::print_link($r, $all, "/$event/", \%newsettings, $defsettings);
643         }
644         
645         $r->print('</p>');
646 }
647
648 sub print_fullscreen {
649         my ($r, $event, $settings, $defsettings) = @_;
650
651         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen'));
652
653         my %newsettings = %$settings;
654         $newsettings{'fullscreen'} = 1;
655
656         $r->print("    <p>");
657         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
658         $r->print("</p>\n");
659 }
660
661 sub print_fullscreen_fromhere {
662         my ($r, $event, $settings, $defsettings, $start) = @_;
663
664         chomp (my $title = Sesse::pr0n::Templates::fetch_template($r, 'fullscreen-fromhere'));
665
666         my %newsettings = %$settings;
667         $newsettings{'fullscreen'} = 1;
668         $newsettings{'start'} = $start;
669
670         $r->print("    <span class=\"fsfromhere\">");
671         Sesse::pr0n::Common::print_link($r, $title, "/$event/", \%newsettings, $defsettings);
672         $r->print("</span>\n");
673 }
674         
675 1;
676
677