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