word/memory: mirrored duplication of unpaired images
[sheet.git] / word.plp
index 9fa1aaaf87c7b7987c5d0e5c6cf39b45a64d2193..f47c4f48ed167d63d4608d2d71c5e80e96dbae13 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,15 +1,19 @@
 <(common.inc.plp)><:
 
+our $lang = $get{lang} || 'en';
+our $wordlistbase = "data/wordlist";
+
 if ($Request and $Request =~ m{\A([^/]+)}) {
        my $page = "word/$1.plp";
+       utf8::downgrade($page); # unicode filename breaks contents encoding
        if (-e $page) {
+               $wordlistbase .= ".$lang";
                Include $page;
                exit;
        }
 }
 
-my $lang = $get{lang} || 'en';
-my $wordlist = "data/wordlist.$lang.inc.pl";
+my $wordlist = "$wordlistbase.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
 
 Html({
@@ -87,7 +91,8 @@ sub showimg {
 sub printimgs {
        say '<ul>';
        for my $row (@_) {
-               my ($id, $level, $title) = split /:/, $row, 3;
+               my ($id, $level, $title) = @{$row};
+               $id or die "empty reference"; # assertion to prevent loops
                my @type;
                push @type, 'parent' if defined $table->{$id};
                push @type, 'large'  if $level =~ s/c$//;
@@ -106,8 +111,8 @@ if (exists $get{q}) {
        if ($Request) {
                my @query = $Request;
                while (@query) {
-                       push @rows, grep { (split /:/)[1] <= $limit } @query;
-                       s/:.*// for @query;
+                       push @rows, grep { $_->[1] <= $limit } @query;
+                       $_ = $_->[0] for @query;
                        @query = map {$_ ? @{$_} : ()} @{$table}{@query};
                }
        }
@@ -118,7 +123,10 @@ if (exists $get{q}) {
        $table = {};
        printimgs(@rows);
 }
+elsif ($Request and $Request =~ /^\d+$/) {
+       printimgs([$Request]);
+}
 else {
-       printimgs($Request || $table->{''}->[0]);
+       printimgs($table->{''}->[0]);
 }
 say '</section>';