X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tgal/blobdiff_plain/458a80b28430759f20b5b724a1e59392608e0db7..7cd805d11b686c973574dd5cab7b1cb8f907f26d:/mason/dhandler
diff --git a/mason/dhandler b/mason/dhandler
index dded49c..0c834b9 100755
--- a/mason/dhandler
+++ b/mason/dhandler
@@ -35,8 +35,8 @@ of the GNU Affero General Public License.
-
- ">
+
+ ">
<% $head %>\
<% $title %>
@@ -83,20 +83,37 @@ Failed to find ‘<% $path |h %>’.
}
(my $nosl = $path) =~ s!/$!!;
+ my $size = "medthumb";
my %tn;
+ my (%nd, %nf);
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;
+ my ($ddd, $fff, $iii);
+ ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+ $nd{$d} = @$ddd; $nf{$d} = @$fff;
+ DIR: for (;;) {
+ 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;
+ ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+ }
}
%perl>
%
-<&| .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 &>
+<&| .breadcrumbs, what => "Folder", path => $path &>
+
+&>
%
% my $note = contents "$IMGROOT/$path/.tgal-note.html";
% if (defined $note) {
@@ -107,33 +124,82 @@ Failed to find ‘<% $path |h %>’.
%
% if (@$dd) {
Subfolders
-% for my $size (qw{medthumb}) {
-% for my $d (@$dd) {
+% for my $d (@$dd) {
+% my $count = "";
+% $count .= "$nd{$d}/" if $nd{$d};
+% $count .= "$nf{$d}" if $nf{$d};
<& .thumbnail, target => $d->name, comment => $d->comment,
- img => $tn{$d}, size => $size,
- caption => $m->interp->apply_escapes($d->name, "h") &>\
-% }
-
+ tn => $tn{$d}, size => $size,
+ caption =>
+ $m->interp->apply_escapes($d->name, "h") . " [$count]" &>\
% }
+
% }
%
% if (@$ff) {
Images
-% for my $size (qw{medthumb}) {
-% for my $f (@$ff) {
+% for my $f (@$ff) {
<& .thumbnail, target => $f->name, comment => $f->comment,
- img => $tn{$f}, size => "bigthumb",
+ tn => $tn{$f}, size => $size,
caption => $m->interp->apply_escapes($f->name, "h") &>\
-% }
-
% }
+
% }
%
<& .footer, path => $path &>
&>
+%
+<%args>
+ $path
+%args>
+%def>
+%
+%###-------------------------------------------------------------------------
+<%def .zip>\
+<%perl>
+ my $st = stat "$IMGROOT/$path";
+ if (!$st) { $m->comp(".not-found", path => $path); return; }
+ my $zip = "$TMP/t$$-download.zip";
+ my $err = "$TMP/t$$-download.stderr";
+ my $kid = fork;
+ if (!$kid) {
+ untie *STDIN; open STDIN, "/dev/null";
+ untie *STDERR; open STDERR, ">", $err;
+ chdir "$IMGROOT/$path";
+ exec "zip", "-qr", $zip, ".";
+ exit 127;
+ }
+ waitpid $kid, 0;
+%perl>
+%
+% if ($?) {
+<&| .html, title => "Zip failed (rc = $?)" &>
+
+<%perl>
+ open my $f, "<", $err;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+%perl>
+
+&>
+% } else {
+<%perl>
+ $r->content_type("application/zip");
+ open my $f, "<", $zip; binmode $f;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+%perl>
+% }
+%
+<%perl>
+ eval { unlink $zip; };
+ eval { unlink $err; };
+%perl>
+
%
<%args>
$path
@@ -144,20 +210,39 @@ Failed to find ‘<% $path |h %>’.
<%def .image>\
<%perl>
my ($dir, $base, $ext) = split_path $path;
- my $real = join_paths $IMGROOT, $path;
- my $img = TrivGal::Image->new($path);
- if (defined $scale) { $m->redirect($img->scale($scale)); }
+ 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 = $img->scale("view");
+ my @thumbsz = qw{smallthumb medthumb bigthumb};
+ my @imgsz = sort { $SIZE{$a} <=> $SIZE{$b} } keys %SIZE;
+ my ($wd, $ht, $max);
+ 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;
+ ($wd, $ht) = ($img->wd, $img->ht);
+ $max = $img->sz;
+ SIZE: for my $sc (@imgsz) {
+ my $sz = $SIZE{$sc};
+ last SIZE if $max < $sz;
+ $vw{$sc} = $img->scale($sc);
+ }
+ }
+ }
defined $fi or die "image not found in its folder?";
my $this = $ff->[$fi];
@@ -173,12 +258,11 @@ Failed to find ‘<% $path |h %>’.
}
my $links = "";
- my $pre =
- urlencode join_paths $SCRIPTURL, $dir;
+ my $pre = urlencode join_paths $SCRIPTURL, $dir;
for my $rel (qw{up first prev next last}) {
- exists $link{$rel} and
- $links .= sprintf " \n",
- $rel, urlencode "$pre/$link{$rel}";
+ $links .= sprintf " \n", $rel,
+ urlencode "$pre/$link{$rel}"
+ if exists $link{$rel};
}
%perl>
%
@@ -193,23 +277,35 @@ Failed to find ‘<% $path |h %>’.
%
%
-% my %img = map { $_ => TrivGal::Image->new($dir . "/" . $_->name) } @$ff;
% 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 &>\
% }
% }
@@ -232,17 +328,21 @@ Failed to find ‘<% $path |h %>’.
% if (!@p) {
[top]
% } else {
-[top] / \
+[top] / \
% STEP: for my $p (@p) {
% if (defined $prev) {
% $pp .= "$prev/";
-\
+ \
<% $prev %> / \
% }
% $prev = $p;
% }
<% $prev %>\
% }
+% if ($m->has_content) {
+
+<% $m->content %>\
+% }
<%args>
$what
@@ -252,17 +352,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) {
@@ -275,7 +373,7 @@ Failed to find ‘<% $path |h %>’.
%
<%args>
$target
- $img
+ $tn
$size
$caption
$comment => undef
@@ -289,7 +387,7 @@ Failed to find ‘<% $path |h %>’.
%perl>