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