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