X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/e5db8f3f72b6ca721f7045529791c2214fbb40f9..86ef170717e1837a99bf7b80c26173219601180e:/word.plp
diff --git a/word.plp b/word.plp
index 2c16a24..64a093f 100644
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,16 @@
<(common.inc.plp)><:
-my $wordlist = "data/wordlist.en.inc.pl";
+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 $lang = $get{lang} || 'en';
+my $wordlist = "data/wordlist.$lang.inc.pl";
my $limit = $get{v} // (exists $get{v} ? 4 : 3);
Html({
@@ -79,6 +89,7 @@ sub printimgs {
say '
';
for my $row (@_) {
my ($id, $level, $title) = split /:/, $row, 3;
+ $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$//;
@@ -93,7 +104,18 @@ sub printimgs {
say '';
if (exists $get{q}) {
- my @rows = map {@$_} values %{$table}; # flatten categories
+ my @rows;
+ if ($Request) {
+ my @query = $Request;
+ while (@query) {
+ push @rows, grep { (split /:/)[1] <= $limit } @query;
+ s/:.*// for @query;
+ @query = map {$_ ? @{$_} : ()} @{$table}{@query};
+ }
+ }
+ else {
+ @rows = map {ref ? @$_ : $_} values %{$table}; # flatten categories
+ }
@rows = sort { rand <=> .5 } @rows;
$table = {};
printimgs(@rows);