mason/dhandler: Apply both URL and HTML escaping to links.
[tgal] / mason / dhandler
index 94c39cc..f3a8cfc 100755 (executable)
@@ -35,8 +35,8 @@ of the GNU Affero General Public License.
 <html>
 <head>
   <meta name=viewport content="width=device-width initial-scale=1.0">
-  <script type="text/javascript" src="<% "$STATICURL/tgal.js" |u %>" defer></script>
-  <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |u %>">
+  <script type="text/javascript" src="<% "$STATICURL/tgal.js" |hu %>" defer></script>
+  <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |hu %>">
 <% $head %>\
   <title><% $title %></title>
 </head>
@@ -85,12 +85,14 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 
        my $size = "medthumb";
        my %tn;
+       my (%nd, %nf);
        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;
+         $nd{$d} = @$ddd; $nf{$d} = @$fff;
          DIR: for (;;) {
            if (defined $iii) {
              my $index = join_paths $p, $iii->name;
@@ -120,9 +122,13 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <h2>Subfolders</h2>
 <div class="gallery <% $size %>">
 %   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,
                 tn => $tn{$d}, size => $size,
-                caption => $m->interp->apply_escapes($d->name, "h") &>\
+                caption =>
+                  $m->interp->apply_escapes($d->name, "h") . " [$count]" &>\
 %   }
 </div>
 % }
@@ -209,13 +215,13 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %
 <div class=viewnav>
 % if ($link{prev}) {
-  <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">&lsaquo;</a></div>
+  <div class=prev><a class=prev href="<% "$pre/$link{prev}" |hu %>">&lsaquo;</a></div>
 % }
   <a class=view href="<% $url |h %>">
     <img src="<% $vw |h %>">
   </a>
 % if ($link{next}) {
-  <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">&rsaquo;</a></div>
+  <div class=next><a class=next href="<% "$pre/$link{next}" |hu %>">&rsaquo;</a></div>
 % }
 </div>
 %
@@ -248,11 +254,11 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 % if (!@p) {
 [top]
 % } else {
-<a href="<% $SCRIPTURL |u %>/">[top]</a>&thinsp;/&thinsp;\
+<a href="<% $SCRIPTURL |hu %>/">[top]</a>&thinsp;/&thinsp;\
 %   STEP: for my $p (@p) {
 %     if (defined $prev) {
 %       $pp .= "$prev/";
-<a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
+<a href="<% join_paths($SCRIPTURL, $pp) |hu %>/">\
 <% $prev %></a>&thinsp;/&thinsp;\
 %     }
 %     $prev = $p;
@@ -303,7 +309,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 </%perl>
 <div class=footer>
   <div class=footitem>
-    <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
+    <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |hu %>"></a>
     Trivial Gallery, copyright &copy; 2021 Mark Wooding.
     Free software: you can modify it and/or redistribute it under the
     terms of the