%### -*-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 => ""
%args>
%def>
%
%###-------------------------------------------------------------------------
<%def .not-found>\
<&| .html, title => "Not found" &>
Not found
Failed to find ‘<% $path |h %>’.
&>
% return 404;
%
<%args>
$path
%args>
%def>
%
%###-------------------------------------------------------------------------
<%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!/$!!;
%perl>
%
<&| .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
% for my $d (@$dd) {
% my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
% my $tn = $iii ?
% TrivGal::Image->new(join_paths $path, $d->name, $iii->name) :
% undef;
<& .thumbnail, target => $d->name . "/", comment => $d->comment,
img => $tn, size => "bigthumb",
caption => $m->interp->apply_escapes($d->name, "h") &>\
% }
% }
%
% if (@$ff) {
Images
% for my $f (@$ff) {
<& .thumbnail, target => $f->name, comment => $f->comment,
img => TrivGal::Image->new($path . $f->name),
size => "bigthumb",
caption => $m->interp->apply_escapes($f->name, "h") &>\
% }
% }
%
<& .footer, path => $path &>
&>
%
<%args>
$path
%args>
%def>
%
%###-------------------------------------------------------------------------
<%def .image>\
<%perl>
my ($dir, $base, $ext) = split_path $path;
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 $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}";
}
%perl>
%
<&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
head => $links &>
<& .breadcrumbs, what => "Image", path => $path &>
% if ($this->comment) {
% }
%
% if ($link{prev}) {
% }
% if ($link{next}) {
% }
%
% for my $f (@$ff) {
% my $img = TrivGal::Image->new($dir . "/" . $f->name);
<& .thumbnail, target => $f->name, img => $img, size => "bigthumb",
caption => $m->interp->apply_escapes($f->name, "h"),
focus => $f->name eq "$base$ext" &>\
% }
<& .footer, path => $dir &>
&>
%
<%args>
$path
%args>
%def>
%
%###-------------------------------------------------------------------------
<%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
%args>
%def>
%
%###-------------------------------------------------------------------------
<%def .thumbnail>\
% my $tn;
% if (defined $img) { $tn = $img->scale($size); }
% else { $tn = "$STATICURL/folder.svg"; }
% if ($focus) {
<% $caption %>
% } else {
<% $caption %>
% if (defined $comment) {
% }
% }
%
<%args>
$target
$img
$size
$caption
$comment => undef
$focus => 0
%args>
%def>
%
%###-------------------------------------------------------------------------
<%def .footer>\
<%perl>
%perl>
<%args>
$path
%args>
%def>
%
%###-------------------------------------------------------------------------
<%once>
use autodie;
use Data::Dumper;
use File::stat;
use TrivGal;
%once>
%
<%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"; }
$m->comp($comp, path => $path);
%init>
%
%###----- That's all, folks -------------------------------------------------
<% $this->comment %>