diff options
author | morkt <> | 2015-01-02 10:22:25 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2015-01-02 10:22:25 +0100 |
commit | 228cb96969a33a60c40dd4991a394460652010af (patch) | |
tree | 9d69e00562ae545b79ca8a899d2439c4800133d7 /lib/VNDB/Func.pm | |
parent | 03585d77637a7052d0af2cdb1e4be66358412b6a (diff) |
staff: Fix deleting of staff + use JSON to pass data + minor fixes
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 54acfe4f..3b315c93 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -6,10 +6,12 @@ use warnings; use TUWF ':html'; use Exporter 'import'; use POSIX 'strftime', 'ceil', 'floor'; +use JSON::XS; use VNDBUtil; our @EXPORT = (@VNDBUtil::EXPORT, qw| clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags childtags charspoil imgpath imgurl fmtvote + jsonEncode jsonDecode script_json mtvoiced mtani mtvnlen mtrlstat mtvnlstat mtbloodt |); @@ -202,6 +204,28 @@ sub fmtvote { } +my $JSON; # cache + +# JSON::XS::encode_json converts input to utf8, whereas these functions +# operate on wide character strings. +sub jsonEncode ($) { + ($JSON ||= JSON::XS->new)->encode(@_); +} + +sub jsonDecode ($) { + ($JSON ||= JSON::XS->new)->decode(@_); +} + +# Insert JSON-encoded data as script, arguments: id, object +sub script_json { + script id => $_[0], type => 'application/json'; + my $js = jsonEncode $_[1]; + $js =~ s/</\\u003C/g; # escape HTML tags like </script> and <!-- + lit $js; + end; +} + + # mt() wrappers for data-dependent translation strings that have a special # value for 'unknown'. sub mtvoiced { !$_[0] ? mt '_unknown' : mt '_voiced_'.$_[0]; } |