3 %### Main output for Trivial Gallery.
5 %### (c) 2021 Mark Wooding
8 %###----- Licensing notice --------------------------------------------------
10 %### This file is part of Trivial Gallery.
12 %### Trivial Gallery is free software: you can redistribute it and/or modify
13 %### it under the terms of the GNU Affero General Public License as
14 %### published by the Free Software Foundation; either version 3 of the
15 %### License, or (at your option) any later version.
17 %### Trivial Gallery is distributed in the hope that it will be useful, but
18 %### WITHOUT ANY WARRANTY; without even the implied warranty of
19 %### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 %### Affero General Public License for more details.
22 %### You should have received a copy of the GNU Affero General Public
23 %### License along with Trivial Gallery. If not, see
24 %### <https://www.gnu.org/licenses/>.
26 %###-------------------------------------------------------------------------
28 % $r->content_type("text/html; charset=\"utf-8\"");
31 Trivial Gallery, copyright © 2021 Mark Wooding.
32 Free software: you can redistribute it and/or modify it under the terms
33 of the GNU Affero General Public License.
37 <meta name=viewport content="width=device-width initial-scale=1.0">
38 <script type="text/javascript" src="<% "$STATICURL/tgal.js" |hu %>" defer></script>
39 <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |hu %>">
41 <title><% $title %></title>
54 %###-------------------------------------------------------------------------
56 <&| .html, title => "Not found" &>
58 Failed to find ‘<% $path |h %>’.
67 %###-------------------------------------------------------------------------
70 unless ($r->path_info =~ m!/$!)
71 { $m->redirect(join_paths($SCRIPTURL, $path) . "/"); }
73 my $real = join_paths $IMGROOT, $path;
74 my $url = join_paths $SCRIPTURL, $path;
75 my ($dd, $ff, $ii) = listdir $real;
78 if ($path eq "" || $path eq "/") { $uplink = undef; }
80 ($uplink = $path) =~ s![^/]*/$!!;
81 $links .= sprintf " <link rel=up href=\"%s\">\n",
82 urlencode "$SCRIPTURL/$uplink";
84 (my $nosl = $path) =~ s!/$!!;
86 my $size = "medthumb";
90 { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
92 my $p = join_paths $path, $d->name;
93 my ($ddd, $fff, $iii);
94 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
97 $count .= scalar(@$ddd) . "/" if @$ddd;
98 $count .= scalar(@$fff) if @$fff;
103 my $index = join_paths $p, $iii->name;
104 $tn{$d} = TrivGal::Image->new($index)->scale($size);
107 if (!@$ddd) { $tn{$d} = undef; last DIR; }
108 $p = join_paths $p, $ddd->[0]->name;
109 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
115 "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
117 <&| .breadcrumbs, what => "Folder", path => $path &>
119 <a href="<% "$SCRIPTURL/" . substr($path, 0, -1) . ".zip" |hu %>">[zip]</a>
123 % my $note = contents "$IMGROOT/$path/.tgal-note.html";
124 % if (defined $note) {
132 <div class="gallery <% $size %>">
133 <& .thumbnail, target => $d->name, comment => $d->comment,
134 tn => $tn{$d}, size => $size,
136 $m->interp->apply_escapes($d->name, "h") .
144 <div class="gallery <% $size %>">
146 <& .thumbnail, target => $f->name, comment => $f->comment,
147 tn => $tn{$f}, size => $size,
148 caption => $m->interp->apply_escapes($f->name, "h") &>\
153 <div class=fill></div>
154 <& .footer, path => $path &>
162 %###-------------------------------------------------------------------------
165 my $st = stat "$IMGROOT/$path";
166 if (!$st) { $m->comp(".not-found", path => $path); return; }
167 my $zip = "$TMP/t$$-download.zip";
168 my $err = "$TMP/t$$-download.stderr";
171 untie *STDIN; open STDIN, "</dev/null";
172 untie *STDOUT; open STDOUT, ">/dev/null";
173 untie *STDERR; open STDERR, ">", $err;
174 chdir "$IMGROOT/$path";
175 exec "zip", "-qr", $zip, ".";
182 <&| .html, title => "Zip failed (rc = $?)" &>
185 open my $f, "<", $err;
187 while (read $f, $buf, 16384) { $m->print($buf); }
193 $r->content_type("application/zip");
194 open my $f, "<", $zip; binmode $f;
196 while (read $f, $buf, 16384) { $m->print($buf); }
201 eval { unlink $zip; };
202 eval { unlink $err; };
211 %###-------------------------------------------------------------------------
214 my ($dir, $base, $ext) = split_path $path;
216 if (defined $scale) {
217 my $img = TrivGal::Image->new($path);
218 $m->redirect($img->scale($scale, 1));
221 my $real = join_paths $IMGROOT, $path;
222 my $url = join_paths $IMGURL, $path;
223 my $realdir = join_paths $IMGROOT, $dir;
224 my $urldir = join_paths $SCRIPTURL, $dir;
225 my ($dd, $ff, $ii) = listdir $realdir;
226 my @thumbsz = qw{smallthumb medthumb bigthumb};
227 my @imgsz = sort { $SIZE{$a} <=> $SIZE{$b} } keys %SIZE;
233 FILE: for (my $i = 0; $i < @$ff; $i++) {
235 my $img = TrivGal::Image->new(join_paths $dir, $f->name);
236 for my $sz (@thumbsz) { $tn{$f->name}{$sz} = $img->scale($sz); }
237 if ($ff->[$i]->name eq "$base$ext") {
239 ($wd, $ht) = ($img->wd, $img->ht);
241 SIZE: for my $sc (@imgsz) {
243 last SIZE if $max < $sz;
244 $vw{$sc} = $img->scale($sc);
248 defined $fi or die "image not found in its folder?";
249 my $this = $ff->[$fi];
254 $link{first} = $ff->[0]->name;
255 $link{prev} = $ff->[$fi - 1]->name;
257 if ($fi != @$ff - 1) {
258 $link{last} = $ff->[-1]->name;
259 $link{next} = $ff->[$fi + 1]->name;
263 my $pre = urlencode join_paths $SCRIPTURL, $dir;
264 for my $rel (qw{up first prev next last}) {
265 $links .= sprintf " <link rel=%s href=\"%s\">\n", $rel,
266 urlencode "$pre/$link{$rel}"
267 if exists $link{$rel};
271 <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
273 <& .breadcrumbs, what => "Image", path => $path &>
274 % if ($this->comment) {
276 <p><% $this->comment %>
282 <div class=prev><a class=prev href="<% "$pre/$link{prev}" |hu %>">‹</a></div>
284 <a class=view href="<% $url |h %>">
286 % my ($hoff, $voff) = (60, 480);
287 % SIZE: for (my $i = 0; $i < @imgsz; $i++) {
288 % my $scale = $imgsz[$i];
289 % last SIZE unless exists $vw{$scale};
290 % my $scsz = $SIZE{$scale};
291 % my $f = $scsz/$max;
292 % my ($thiswd, $thisht) = map int, ($f*$wd + $hoff, $f*$ht + $voff);
293 <source srcset="<% $vw{$scale} |h %>"
294 media="(max-width: <% $thiswd %>px) or (max-height: <% $thisht %>px)">
296 <img src="<% "$IMGURL/$path" |hu %>">
300 <div class=next><a class=next href="<% "$pre/$link{next}" |hu %>">›</a></div>
304 % for my $size (qw{smallthumb medthumb bigthumb}) {
305 <div class="thumbstrip <% $size %>">
307 <& .thumbnail, target => $f->name,
308 tn => $tn{$f->name}{$size}, size => $size,
309 caption => $m->interp->apply_escapes($f->name, "h"),
310 focus => $f eq $this &>\
314 <& .footer, path => $dir &>
323 %###-------------------------------------------------------------------------
326 % my @p = split m!/!, $path;
333 <a href="<% $SCRIPTURL |hu %>/">[top]</a> / \
334 % STEP: for my $p (@p) {
335 % if (defined $prev) {
337 <a href="<% join_paths($SCRIPTURL, $pp) |hu %>/">\
338 <% $prev %></a> / \
344 % if ($m->has_content) {
355 %###-------------------------------------------------------------------------
357 % $tn //= "$STATICURL/folder.svg";
359 <figure class="thumb focusthumb <% $size %>">
360 <img class="thumb <% $size %>" loading=lazy src="<% $tn |h %>">
361 <figcaption><span class=name><% $caption %></span></figcaption>
363 <figure class="thumb <% $size %>">
364 <a class=thumb href="<% $target |hu %>">
365 <img class="thumb <% $size %>" loading=lazy src="<% $tn |h %>">
367 <span class=name><% $caption %></span>
368 % if (defined $comment) {
369 <span class=comment><% $comment %></span>
386 %###-------------------------------------------------------------------------
392 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |hu %>"></a>
393 Trivial Gallery, copyright © 2021 Mark Wooding.
394 Free software: you can modify it and/or redistribute it under the
396 <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
397 General Public License version 3</a>.
398 Browse or download the <a href="<% $SRCURL %>">source code</a>.
401 % find_covering_file $IMGROOT, $path, ".tgal-footer.html";
402 % if (defined $user) {
413 %###-------------------------------------------------------------------------
424 my $path = $m->dhandler_arg;
425 my $st = stat "$IMGROOT/$path";
428 $comp = ".not-found";
429 if ($path =~ /^ (.*) (\.(?: zip)) $/x) {
430 $st = stat "$IMGROOT/$1";
431 if ($st) { $path = $1; $comp = $2; }
434 elsif (-d $st) { $comp = ".contact"; }
435 elsif (-f $st) { $comp = ".image"; }
436 else { $comp = ".not-found"; }
437 $r->header_out("X-AGPL-Source" => $SRCURL);
438 $m->comp($comp, path => $path, %ARGS);
441 %###----- That's all, folks -------------------------------------------------