word: store data entries as prepared subarrays
[sheet.git] / word.plp
index 050ad90f626ddb79390343a57ba4b29a9bcc3096..9ea54e89f7d002937e0c21dc12caf12ce5d2ff88 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,18 @@
 <(common.inc.plp)><:
 
-my $wordlist = "data/wordlist.en.inc.pl";
+our $lang = $get{lang} || 'en';
+our $wordlistbase = "data/wordlist.$lang";
+
+if ($Request and $Request =~ m{\A([^/]+)}) {
+       my $page = "word/$1.plp";
+       utf8::downgrade($page); # unicode filename breaks contents encoding
+       if (-e $page) {
+               Include $page;
+               exit;
+       }
+}
+
+my $wordlist = "$wordlistbase.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
 
 Html({
@@ -78,7 +90,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$//;
@@ -97,8 +110,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};
                }
        }