X-Git-Url: https://git.distorted.org.uk/~mdw/tgal/blobdiff_plain/6e749fabbf4a2758454db148bd366367069142c5..784bdf8f1aab63a19724cb60026e78f8f7550ab8:/mason/dhandler diff --git a/mason/dhandler b/mason/dhandler index 011c561..de50cd8 100755 --- a/mason/dhandler +++ b/mason/dhandler @@ -67,9 +67,9 @@ Failed to find ‘<% $path |h %>’. %###------------------------------------------------------------------------- <%def .contact>\ <%perl> - unless ($r->path_info =~ m!/$!) { - $m->redirect(join_paths($SCRIPTURL, $path) . "/"); - } + unless ($r->path_info =~ m!/$!) + { $m->redirect(join_paths($SCRIPTURL, $path) . "/"); } + my $real = join_paths $IMGROOT, $path; my $url = join_paths $SCRIPTURL, $path; my ($dd, $ff, $ii) = listdir $real; @@ -83,18 +83,27 @@ Failed to find ‘<% $path |h %>’. } (my $nosl = $path) =~ s!/$!!; + my $size = "medthumb"; my %tn; for my $f (@$ff) - { $tn{$f} = TrivGal::Image->new($path . $f->name); } + { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); } for my $d (@$dd) { - my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name; - $tn{$d} = $iii ? - TrivGal::Image->new(join_paths $path, $d->name, $iii->name) : - undef; + my $p = join_paths $path, $d->name; + DIR: for (;;) { + my ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p; + if (defined $iii) { + my $index = join_paths $p, $iii->name; + $tn{$d} = TrivGal::Image->new($index)->scale($size); + last DIR; + } + if (!@$ddd) { $tn{$d} = undef; last DIR; } + $p = join_paths $p, $ddd->[0]->name; + } } % -<&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"), +<&| .html, title => + "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"), head => $links &> <& .breadcrumbs, what => "Folder", path => $path &> % @@ -107,28 +116,24 @@ Failed to find ‘<% $path |h %>’. % % if (@$dd) {

Subfolders

-% for my $size (qw{bigthumb}) { % } + % } % % if (@$ff) {

Images

-% for my $size (qw{bigthumb}) { % } + % } %
@@ -144,16 +149,29 @@ Failed to find ‘<% $path |h %>’. <%def .image>\ <%perl> my ($dir, $base, $ext) = split_path $path; + + if (defined $scale) { + my $img = TrivGal::Image->new($path); + $m->redirect($img->scale($scale, 1)); + } + my $real = join_paths $IMGROOT, $path; my $url = join_paths $IMGURL, $path; my $realdir = join_paths $IMGROOT, $dir; my $urldir = join_paths $SCRIPTURL, $dir; my ($dd, $ff, $ii) = listdir $realdir; - my $vw = TrivGal::Image->new($path)->scale("view"); + my @thumbsz = qw{smallthumb medthumb bigthumb}; + my %tn; + my $vw; my $fi = undef; - FILE: for (my $i = 0; $i < @$ff; $i++) - { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } } + FILE: for (my $i = 0; $i < @$ff; $i++) { + my $f = $ff->[$i]; + my $img = TrivGal::Image->new(join_paths $dir, $f->name); + for my $sz (@thumbsz) { $tn{$f->name}{$sz} = $img->scale($sz); } + if ($ff->[$i]->name eq "$base$ext") + { $fi = $i; $vw = $img->scale("view"); } + } defined $fi or die "image not found in its folder?"; my $this = $ff->[$fi]; @@ -199,13 +217,13 @@ Failed to find ‘<% $path |h %>’. % } % -% my %img = map { $_ => TrivGal::Image->new($dir . "/" . $_->name) } @$ff; -% for my $size (qw{bigthumb}) { +% for my $size (qw{smallthumb medthumb bigthumb}) {
% for my $f (@$ff) { - <& .thumbnail, target => $f->name, img => $img{$f}, size => $size, + <& .thumbnail, target => $f->name, + tn => $tn{$f->name}{$size}, size => $size, caption => $m->interp->apply_escapes($f->name, "h"), - focus => $f->name eq "$base$ext" &>\ + focus => $f eq $this &>\ % }
% } @@ -214,6 +232,7 @@ Failed to find ‘<% $path |h %>’. % <%args> $path + $scale => undef % @@ -247,17 +266,15 @@ Failed to find ‘<% $path |h %>’. % %###------------------------------------------------------------------------- <%def .thumbnail>\ -% my $tn; -% if (defined $img) { $tn = $img->scale($size); } -% else { $tn = "$STATICURL/folder.svg"; } +% $tn //= "$STATICURL/folder.svg"; % if ($focus) { -
- +
+
<% $caption %>
% } else {
- +
<% $caption %> % if (defined $comment) { @@ -270,7 +287,7 @@ Failed to find ‘<% $path |h %>’. % <%args> $target - $img + $tn $size $caption $comment => undef @@ -288,10 +305,9 @@ Failed to find ‘<% $path |h %>’. Trivial Gallery, copyright © 2021 Mark Wooding. Free software: you can modify it and/or redistribute it under the terms of the - GNU Affero + GNU Affero General Public License version 3. - Browse or download - the source code. + Browse or download the source code. % my $user = % find_covering_file $IMGROOT, $path, ".tgal-footer.html"; @@ -309,7 +325,6 @@ Failed to find ‘<% $path |h %>’. %###------------------------------------------------------------------------- <%once> use autodie; -use Data::Dumper; use File::stat; use TrivGal; @@ -325,7 +340,8 @@ use Data::Dumper; elsif (-d $st) { $comp = ".contact"; } elsif (-f $st) { $comp = ".image"; } else { $comp = ".not-found"; } - $m->comp($comp, path => $path); + $r->header_out("X-AGPL-Source" => $SRCURL); + $m->comp($comp, path => $path, %ARGS); % %###----- That's all, folks -------------------------------------------------