%### -*-html-*- %### %### Main output for Trivial Gallery. %### %### (c) 2021 Mark Wooding %### % %###----- Licensing notice -------------------------------------------------- %### %### This file is part of Trivial Gallery. %### %### Trivial Gallery is free software: you can redistribute it and/or modify %### it under the terms of the GNU Affero General Public License as %### published by the Free Software Foundation; either version 3 of the %### License, or (at your option) any later version. %### %### Trivial Gallery is distributed in the hope that it will be useful, but %### WITHOUT ANY WARRANTY; without even the implied warranty of %### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %### Affero General Public License for more details. %### %### You should have received a copy of the GNU Affero General Public %### License along with Trivial Gallery. If not, see %### . % %###------------------------------------------------------------------------- <%def .html>\ % $r->content_type("text/html; charset=\"utf-8\""); "> <% $head %>\ <% $title %> <% $m->content %> \ % <%args> $title $head => "" % %###------------------------------------------------------------------------- <%def .not-found>\ <&| .html, title => "Not found" &>

Not found

Failed to find ‘<% $path |h %>’. % return 404; % <%args> $path % %###------------------------------------------------------------------------- <%def .contact>\ <%perl> 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; my $links = ""; my $uplink; if ($path eq "" || $path eq "/") { $uplink = undef; } else { ($uplink = $path) =~ s![^/]*/$!!; $links .= sprintf " \n", urlencode "$SCRIPTURL/$uplink"; } (my $nosl = $path) =~ s!/$!!; my $size = "medthumb"; my %tn; for my $f (@$ff) { $tn{$f} = TrivGal::Image->new($path . $f->name); } 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; } % <&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"), head => $links &> <& .breadcrumbs, what => "Folder", path => $path &> % % my $note = contents "$IMGROOT/$path/.tgal-note.html"; % if (defined $note) {
<% $note %>
% } % % if (@$dd) {

Subfolders

% } % % if (@$ff) {

Images

% } %
<& .footer, path => $path &> % <%args> $path % %###------------------------------------------------------------------------- <%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)); } 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 $fi = undef; FILE: for (my $i = 0; $i < @$ff; $i++) { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } } defined $fi or die "image not found in its folder?"; my $this = $ff->[$fi]; my %link; $link{up} = ""; if ($fi != 0) { $link{first} = $ff->[0]->name; $link{prev} = $ff->[$fi - 1]->name; } if ($fi != @$ff - 1) { $link{last} = $ff->[-1]->name; $link{next} = $ff->[$fi + 1]->name; } my $links = ""; 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}"; } % <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"), head => $links &> <& .breadcrumbs, what => "Image", path => $path &> % if ($this->comment) {

<% $this->comment %>

% } %
% if ($link{prev}) { % } % if ($link{next}) { % }
% % 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, caption => $m->interp->apply_escapes($f->name, "h"), focus => $f->name eq "$base$ext" &>\ % }
% } <& .footer, path => $dir &> % <%args> $path $scale => undef % %###------------------------------------------------------------------------- <%def .breadcrumbs>\ % $path =~ s!/$!!; % my @p = split m!/!, $path; % my $pp = ""; % my $prev = undef;

<% $what %> \ % if (!@p) { [top] % } else { [top] / \ % STEP: for my $p (@p) { % if (defined $prev) { % $pp .= "$prev/"; \ <% $prev %> / \ % } % $prev = $p; % } <% $prev %>\ % }

<%args> $what $path % %###------------------------------------------------------------------------- <%def .thumbnail>\ % my $tn; % if (defined $img) { $tn = $img->scale($size); } % else { $tn = "$STATICURL/folder.svg"; } % if ($focus) {
<% $caption %>
% } else {
<% $caption %> % if (defined $comment) { <% $comment %> % }
% }
% <%args> $target $img $size $caption $comment => undef $focus => 0 % %###------------------------------------------------------------------------- <%def .footer>\ <%perl> <%args> $path % %###------------------------------------------------------------------------- <%once> use autodie; use File::stat; use TrivGal; % <%init> TrivGal->init; my $path = $m->dhandler_arg; my $st = stat "$IMGROOT/$path"; my $comp; if (!$st) { $comp = ".not-found"; } elsif (-d $st) { $comp = ".contact"; } elsif (-f $st) { $comp = ".image"; } else { $comp = ".not-found"; } $r->header_out("X-AGPL-Source" => $SRCURL); $m->comp($comp, path => $path, %ARGS); % %###----- That's all, folks -------------------------------------------------