| 1 | %### -*-html-*- |
| 2 | %### |
| 3 | %### Main output for Trivial Gallery. |
| 4 | %### |
| 5 | %### (c) 2021 Mark Wooding |
| 6 | %### |
| 7 | % |
| 8 | %###----- Licensing notice -------------------------------------------------- |
| 9 | %### |
| 10 | %### This file is part of Trivial Gallery. |
| 11 | %### |
| 12 | %### Trivial Gallery is free software: you can redistribute it and/or modify |
| 13 | %### it under the terms of the GNU Affero General Public License as |
| 14 | %### published by the Free Software Foundation; either version 3 of the |
| 15 | %### License, or (at your option) any later version. |
| 16 | %### |
| 17 | %### Trivial Gallery is distributed in the hope that it will be useful, but |
| 18 | %### WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | %### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | %### Affero General Public License for more details. |
| 21 | %### |
| 22 | %### You should have received a copy of the GNU Affero General Public |
| 23 | %### License along with Trivial Gallery. If not, see |
| 24 | %### <https://www.gnu.org/licenses/>. |
| 25 | % |
| 26 | %###------------------------------------------------------------------------- |
| 27 | <%def .html>\ |
| 28 | % $r->content_type("text/html; charset=\"utf-8\""); |
| 29 | <!DOCTYPE html> |
| 30 | <!-- |
| 31 | Trivial Gallery, copyright © 2021 Mark Wooding. |
| 32 | Free software: you can redistribute it and/or modify it under the terms |
| 33 | of the GNU Affero General Public License. |
| 34 | --> |
| 35 | <html> |
| 36 | <head> |
| 37 | <meta name=viewport content="width=device-width initial-scale=1.0"> |
| 38 | <script type="text/javascript" src="<% "$STATICURL/tgal.js" |u %>" defer></script> |
| 39 | <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |u %>"> |
| 40 | <% $head %>\ |
| 41 | <title><% $title %></title> |
| 42 | </head> |
| 43 | <body> |
| 44 | <% $m->content %> |
| 45 | </body> |
| 46 | </html>\ |
| 47 | % |
| 48 | <%args> |
| 49 | $title |
| 50 | $head => "" |
| 51 | </%args> |
| 52 | </%def> |
| 53 | % |
| 54 | %###------------------------------------------------------------------------- |
| 55 | <%def .not-found>\ |
| 56 | <&| .html, title => "Not found" &> |
| 57 | <h1>Not found</h1> |
| 58 | Failed to find ‘<% $path |h %>’. |
| 59 | </&> |
| 60 | % return 404; |
| 61 | % |
| 62 | <%args> |
| 63 | $path |
| 64 | </%args> |
| 65 | </%def> |
| 66 | % |
| 67 | %###------------------------------------------------------------------------- |
| 68 | <%def .contact>\ |
| 69 | <%perl> |
| 70 | unless ($r->path_info =~ m!/$!) |
| 71 | { $m->redirect(join_paths($SCRIPTURL, $path) . "/"); } |
| 72 | |
| 73 | my $real = join_paths $IMGROOT, $path; |
| 74 | my $url = join_paths $SCRIPTURL, $path; |
| 75 | my ($dd, $ff, $ii) = listdir $real; |
| 76 | my $links = ""; |
| 77 | my $uplink; |
| 78 | if ($path eq "" || $path eq "/") { $uplink = undef; } |
| 79 | else { |
| 80 | ($uplink = $path) =~ s![^/]*/$!!; |
| 81 | $links .= sprintf " <link rel=up href=\"%s\">\n", |
| 82 | urlencode "$SCRIPTURL/$uplink"; |
| 83 | } |
| 84 | (my $nosl = $path) =~ s!/$!!; |
| 85 | |
| 86 | my $size = "medthumb"; |
| 87 | my %tn; |
| 88 | for my $f (@$ff) |
| 89 | { $tn{$f} = TrivGal::Image->new($path . $f->name); } |
| 90 | for my $d (@$dd) { |
| 91 | my $p = join_paths $path, $d->name; |
| 92 | DIR: for (;;) { |
| 93 | my ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p; |
| 94 | if (defined $iii) { |
| 95 | my $index = join_paths $p, $iii->name; |
| 96 | $tn{$d} = TrivGal::Image->new($index); |
| 97 | last DIR; |
| 98 | } |
| 99 | if (!@$ddd) { $tn{$d} = undef; last DIR; } |
| 100 | $p = join_paths $p, $ddd->[0]->name; |
| 101 | } |
| 102 | } |
| 103 | </%perl> |
| 104 | % |
| 105 | <&| .html, title => |
| 106 | "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"), |
| 107 | head => $links &> |
| 108 | <& .breadcrumbs, what => "Folder", path => $path &> |
| 109 | % |
| 110 | % my $note = contents "$IMGROOT/$path/.tgal-note.html"; |
| 111 | % if (defined $note) { |
| 112 | <div class=note> |
| 113 | <% $note %> |
| 114 | </div> |
| 115 | % } |
| 116 | % |
| 117 | % if (@$dd) { |
| 118 | <h2>Subfolders</h2> |
| 119 | <div class="gallery <% $size %>"> |
| 120 | % for my $d (@$dd) { |
| 121 | <& .thumbnail, target => $d->name, comment => $d->comment, |
| 122 | img => $tn{$d}, size => $size, |
| 123 | caption => $m->interp->apply_escapes($d->name, "h") &>\ |
| 124 | % } |
| 125 | </div> |
| 126 | % } |
| 127 | % |
| 128 | % if (@$ff) { |
| 129 | <h2>Images</h2> |
| 130 | <div class="gallery <% $size %>"> |
| 131 | % for my $f (@$ff) { |
| 132 | <& .thumbnail, target => $f->name, comment => $f->comment, |
| 133 | img => $tn{$f}, size => $size, |
| 134 | caption => $m->interp->apply_escapes($f->name, "h") &>\ |
| 135 | % } |
| 136 | </div> |
| 137 | % } |
| 138 | % |
| 139 | <div class=fill></div> |
| 140 | <& .footer, path => $path &> |
| 141 | </&> |
| 142 | % |
| 143 | <%args> |
| 144 | $path |
| 145 | </%args> |
| 146 | </%def> |
| 147 | % |
| 148 | %###------------------------------------------------------------------------- |
| 149 | <%def .image>\ |
| 150 | <%perl> |
| 151 | my ($dir, $base, $ext) = split_path $path; |
| 152 | my $real = join_paths $IMGROOT, $path; |
| 153 | my $img = TrivGal::Image->new($path); |
| 154 | |
| 155 | if (defined $scale) { $m->redirect($img->scale($scale)); } |
| 156 | |
| 157 | my $url = join_paths $IMGURL, $path; |
| 158 | my $realdir = join_paths $IMGROOT, $dir; |
| 159 | my $urldir = join_paths $SCRIPTURL, $dir; |
| 160 | my ($dd, $ff, $ii) = listdir $realdir; |
| 161 | my $vw = $img->scale("view"); |
| 162 | |
| 163 | my $fi = undef; |
| 164 | FILE: for (my $i = 0; $i < @$ff; $i++) |
| 165 | { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } } |
| 166 | defined $fi or die "image not found in its folder?"; |
| 167 | my $this = $ff->[$fi]; |
| 168 | |
| 169 | my %link; |
| 170 | $link{up} = ""; |
| 171 | if ($fi != 0) { |
| 172 | $link{first} = $ff->[0]->name; |
| 173 | $link{prev} = $ff->[$fi - 1]->name; |
| 174 | } |
| 175 | if ($fi != @$ff - 1) { |
| 176 | $link{last} = $ff->[-1]->name; |
| 177 | $link{next} = $ff->[$fi + 1]->name; |
| 178 | } |
| 179 | |
| 180 | my $links = ""; |
| 181 | my $pre = |
| 182 | urlencode join_paths $SCRIPTURL, $dir; |
| 183 | for my $rel (qw{up first prev next last}) { |
| 184 | exists $link{$rel} and |
| 185 | $links .= sprintf " <link rel=%s href=\"%s\">\n", |
| 186 | $rel, urlencode "$pre/$link{$rel}"; |
| 187 | } |
| 188 | </%perl> |
| 189 | % |
| 190 | <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"), |
| 191 | head => $links &> |
| 192 | <& .breadcrumbs, what => "Image", path => $path &> |
| 193 | % if ($this->comment) { |
| 194 | <div class=comment> |
| 195 | <p><% $this->comment %> |
| 196 | </div> |
| 197 | % } |
| 198 | % |
| 199 | <div class=viewnav> |
| 200 | % if ($link{prev}) { |
| 201 | <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div> |
| 202 | % } |
| 203 | <a class=view href="<% $url |h %>"> |
| 204 | <img src="<% $vw |h %>"> |
| 205 | </a> |
| 206 | % if ($link{next}) { |
| 207 | <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div> |
| 208 | % } |
| 209 | </div> |
| 210 | % |
| 211 | % my %img = map { $_ => TrivGal::Image->new($dir . "/" . $_->name) } @$ff; |
| 212 | % for my $size (qw{smallthumb medthumb bigthumb}) { |
| 213 | <div class="thumbstrip <% $size %>"> |
| 214 | % for my $f (@$ff) { |
| 215 | <& .thumbnail, target => $f->name, img => $img{$f}, size => $size, |
| 216 | caption => $m->interp->apply_escapes($f->name, "h"), |
| 217 | focus => $f eq $this &>\ |
| 218 | % } |
| 219 | </div> |
| 220 | % } |
| 221 | <& .footer, path => $dir &> |
| 222 | </&> |
| 223 | % |
| 224 | <%args> |
| 225 | $path |
| 226 | $scale => undef |
| 227 | </%args> |
| 228 | </%def> |
| 229 | % |
| 230 | %###------------------------------------------------------------------------- |
| 231 | <%def .breadcrumbs>\ |
| 232 | % $path =~ s!/$!!; |
| 233 | % my @p = split m!/!, $path; |
| 234 | % my $pp = ""; |
| 235 | % my $prev = undef; |
| 236 | <h1><% $what %> \ |
| 237 | % if (!@p) { |
| 238 | [top] |
| 239 | % } else { |
| 240 | <a href="<% $SCRIPTURL |u %>/">[top]</a> / \ |
| 241 | % STEP: for my $p (@p) { |
| 242 | % if (defined $prev) { |
| 243 | % $pp .= "$prev/"; |
| 244 | <a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\ |
| 245 | <% $prev %></a> / \ |
| 246 | % } |
| 247 | % $prev = $p; |
| 248 | % } |
| 249 | <% $prev %>\ |
| 250 | % } |
| 251 | </h1> |
| 252 | <%args> |
| 253 | $what |
| 254 | $path |
| 255 | </%args> |
| 256 | </%def> |
| 257 | % |
| 258 | %###------------------------------------------------------------------------- |
| 259 | <%def .thumbnail>\ |
| 260 | % my $tn; |
| 261 | % if (defined $img) { $tn = $img->scale($size); } |
| 262 | % else { $tn = "$STATICURL/folder.svg"; } |
| 263 | % if ($focus) { |
| 264 | <figure class="thumb focusthumb <% $size %>"> |
| 265 | <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>"> |
| 266 | <figcaption><span class=name><% $caption %></span></figcaption> |
| 267 | % } else { |
| 268 | <figure class="thumb <% $size %>"> |
| 269 | <a class=thumb href="<% $target |u %>"> |
| 270 | <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>"> |
| 271 | <figcaption> |
| 272 | <span class=name><% $caption %></span> |
| 273 | % if (defined $comment) { |
| 274 | <span class=comment><% $comment %></span> |
| 275 | % } |
| 276 | </figcaption> |
| 277 | </a> |
| 278 | % } |
| 279 | </figure> |
| 280 | % |
| 281 | <%args> |
| 282 | $target |
| 283 | $img |
| 284 | $size |
| 285 | $caption |
| 286 | $comment => undef |
| 287 | $focus => 0 |
| 288 | </%args> |
| 289 | </%def> |
| 290 | % |
| 291 | %###------------------------------------------------------------------------- |
| 292 | <%def .footer>\ |
| 293 | <%perl> |
| 294 | </%perl> |
| 295 | <div class=footer> |
| 296 | <div class=footitem> |
| 297 | <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a> |
| 298 | Trivial Gallery, copyright © 2021 Mark Wooding. |
| 299 | Free software: you can modify it and/or redistribute it under the |
| 300 | terms of the |
| 301 | <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero |
| 302 | General Public License version 3</a>. |
| 303 | Browse or download the <a href="<% $SRCURL %>">source code</a>. |
| 304 | </div> |
| 305 | % my $user = |
| 306 | % find_covering_file $IMGROOT, $path, ".tgal-footer.html"; |
| 307 | % if (defined $user) { |
| 308 | <div class=footitem> |
| 309 | <% $user %> |
| 310 | </div> |
| 311 | % } |
| 312 | </div> |
| 313 | <%args> |
| 314 | $path |
| 315 | </%args> |
| 316 | </%def> |
| 317 | % |
| 318 | %###------------------------------------------------------------------------- |
| 319 | <%once> |
| 320 | use autodie; |
| 321 | use File::stat; |
| 322 | |
| 323 | use TrivGal; |
| 324 | </%once> |
| 325 | % |
| 326 | <%init> |
| 327 | TrivGal->init; |
| 328 | |
| 329 | my $path = $m->dhandler_arg; |
| 330 | my $st = stat "$IMGROOT/$path"; |
| 331 | my $comp; |
| 332 | if (!$st) { $comp = ".not-found"; } |
| 333 | elsif (-d $st) { $comp = ".contact"; } |
| 334 | elsif (-f $st) { $comp = ".image"; } |
| 335 | else { $comp = ".not-found"; } |
| 336 | $r->header_out("X-AGPL-Source" => $SRCURL); |
| 337 | $m->comp($comp, path => $path, %ARGS); |
| 338 | </%init> |
| 339 | % |
| 340 | %###----- That's all, folks ------------------------------------------------- |