]> git.sesse.net Git - wloh/blobdiff - www/index.pl
Fix double-HTML-encoding.
[wloh] / www / index.pl
index 0bf35594f8e385c7878badb0b6678c4b012e1124..2b7dcaf31c03080d745526cd1cbc843cfb5a8f4b 100755 (executable)
@@ -31,10 +31,6 @@ my %ratings = ();
 my %ratings_stddev = ();
 my @matches = ();
 
-sub sanitize {
-       return HTML::Entities::encode_entities(shift);
-}
-
 sub color {
        my $x = shift;
        return int(255.0 * ($x ** (1.80)));
@@ -93,7 +89,7 @@ sub get_players_and_ratings {
 
        while (my $ref = $q->fetchrow_hashref) {
                my $id = $ref->{'id'};
-               $players{$id} = sanitize(Encode::decode_utf8($ref->{'navn'}));
+               $players{$id} = Encode::decode_utf8($ref->{'navn'});
                $ratings{$id} = $ref->{'rating'};
                $ratings_stddev{$id} = $ref->{'rating_stddev'};
        }
@@ -243,7 +239,7 @@ sub make_table {
                                push @player_ranks, {
                                        'td/style' => "background-color: rgb($r, $g, $b)",
                                        'a' => sprintf("%.1f%%", $pn * 100.0),
-                                       'a/href' => "javascript:showScenario('$table_id', '/$locale/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i"
+                                       'a/href' => "javascript:showScenario('$table_id', '/$locale/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i')"
                                };
                        }
                }
@@ -356,7 +352,6 @@ get_players_and_ratings($dbh, $locale, $season, $division, $subdivision);
 my $cov = get_covariance_matrix($dbh, keys %players);
 
 if (defined($match_player) && defined($match_position)) {
-       print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning');
        my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, \%ratings, $cov);
 
        --$match_player;
@@ -368,7 +363,11 @@ if (defined($match_player) && defined($match_position)) {
        while (<MCCALC>) {
                /(\d+) (\d+) (-?\d+)/ or next;
                chomp;
-               push @scenario, [ $1, $2, $3 ];
+               push @scenario, {
+                       'player-1' => $players{$1},
+                       'player-2' => $players{$2},
+                       'result' => sprintf("%+d", $3),
+               };
        }
        close MCCALC;
        unlink $tmpnam;
@@ -377,18 +376,19 @@ if (defined($match_player) && defined($match_position)) {
        my $player_name = $players{$sorted_players[$match_player]};
 
        if (scalar @scenario == 0) {
-               printf "    <p>Fant ingen m&aring;te <strong>%s</strong> kan ende p&aring; <strong>%d.</strong> plass p&aring;.</p>\n",
-                       $player_name, ($match_position + 1);
+               print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+               wloh_common::process_template('scenario-not-found.xml', {
+                       '#nick' => $player_name,
+                       '#rank' => sprintf("%d.", $match_position + 1)
+               });
        } else {
-               printf "    <p>Scenario der <strong>%s</strong> ender p&aring; <strong>%d.</strong> plass:</p>\n",
-                       $player_name, ($match_position + 1);
-               print "    <ul>\n";
-               for my $m (@scenario) {
-                       printf "    <li>%s &ndash; %s: %+d</li>\n", $players{$m->[0]}, $players{$m->[1]}, $m->[2];
-               }
-               print "    </ul>\n";
+               print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+               wloh_common::process_template('scenario.xml', {
+                       '#nick' => $player_name,
+                       '#rank' => sprintf("%d.", $match_position + 1),
+                       '#results' => \@scenario
+               });
        }
-       print_footer();
 } else {
        POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8');