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