X-Git-Url: https://git.distorted.org.uk/~mdw/tgal/blobdiff_plain/b0e94d8a6a8cfc0cb5f19f7bdfa110af15c8ca6e..f6ac176798628842d70f993c03b4f4978bccbef1:/mason/dhandler
diff --git a/mason/dhandler b/mason/dhandler
index 94c39cc..78f0f95 100755
--- a/mason/dhandler
+++ b/mason/dhandler
@@ -35,8 +35,8 @@ of the GNU Affero General Public License.
-
- ">
+
+ ">
<% $head %>\
<% $title %>
@@ -85,12 +85,19 @@ Failed to find ‘<% $path |h %>’.
my $size = "medthumb";
my %tn;
+ my %count;
for my $f (@$ff)
{ $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
for my $d (@$dd) {
my $p = join_paths $path, $d->name;
my ($ddd, $fff, $iii);
($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+
+ my $count = "";
+ $count .= scalar(@$ddd) . "/" if @$ddd;
+ $count .= scalar(@$fff) if @$fff;
+ $count{$d} = $count;
+
DIR: for (;;) {
if (defined $iii) {
my $index = join_paths $p, $iii->name;
@@ -107,7 +114,11 @@ Failed to find ‘<% $path |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) {
@@ -119,10 +130,11 @@ Failed to find ‘<% $path |h %>’.
% if (@$dd) {
Subfolders
-% for my $d (@$dd) {
<& .thumbnail, target => $d->name, comment => $d->comment,
tn => $tn{$d}, size => $size,
- caption => $m->interp->apply_escapes($d->name, "h") &>\
+ caption =>
+ $m->interp->apply_escapes($d->name, "h") .
+ " [$count{$d}]" &>\
% }
% }
@@ -148,6 +160,55 @@ Failed to find ‘<% $path |h %>’.
%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
+%args>
+%def>
+%
+%###-------------------------------------------------------------------------
<%def .image>\
<%perl>
my ($dir, $base, $ext) = split_path $path;
@@ -163,16 +224,26 @@ Failed to find ‘<% $path |h %>’.
my $urldir = join_paths $SCRIPTURL, $dir;
my ($dd, $ff, $ii) = listdir $realdir;
my @thumbsz = qw{smallthumb medthumb bigthumb};
+ my @imgsz = sort { $SIZE{$a} <=> $SIZE{$b} } keys %SIZE;
+ my ($wd, $ht, $max);
my %tn;
- my $vw;
+ my %vw;
my $fi = undef;
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"); }
+ 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];
@@ -189,12 +260,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>
%
@@ -209,13 +279,25 @@ Failed to find ‘<% $path |h %>’.
%
%
@@ -248,17 +330,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
@@ -271,12 +357,12 @@ Failed to find ‘<% $path |h %>’.
% $tn //= "$STATICURL/folder.svg";
% if ($focus) {
-
+
<% $caption %>
% } else {
-
-
+
+
<% $caption %>
% if (defined $comment) {
@@ -303,7 +389,7 @@ Failed to find ‘<% $path |h %>’.
%perl>