summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-01-19 18:54:40 +0100
committerYorhel <git@yorhel.nl>2016-01-19 18:58:22 +0100
commit0caed2e7674e8ee7419365e76f86d06c33b8c8aa (patch)
tree02d81be9cd5fa78897796e57b699963994c817d9 /lib
parentf7f096f2a07658381c4f98aef81c4991d997d19f (diff)
Move some VNDB::L10N stuff to VNDB::Func + intern VNDB::Func
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Func.pm65
-rw-r--r--lib/VNDB/Handler/Affiliates.pm2
-rw-r--r--lib/VNDB/Handler/Discussions.pm16
-rw-r--r--lib/VNDB/Handler/Misc.pm4
-rw-r--r--lib/VNDB/Handler/Producers.pm4
-rw-r--r--lib/VNDB/Handler/Releases.pm6
-rw-r--r--lib/VNDB/Handler/Staff.pm4
-rw-r--r--lib/VNDB/Handler/Tags.pm12
-rw-r--r--lib/VNDB/Handler/Traits.pm8
-rw-r--r--lib/VNDB/Handler/ULists.pm6
-rw-r--r--lib/VNDB/Handler/Users.pm8
-rw-r--r--lib/VNDB/Handler/VNPage.pm7
-rw-r--r--lib/VNDB/L10N.pm56
-rw-r--r--lib/VNDB/Util/BrowseHTML.pm6
-rw-r--r--lib/VNDB/Util/CommonHTML.pm2
15 files changed, 104 insertions, 102 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 64f087ae..42d1b7f2 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -3,14 +3,15 @@ package VNDB::Func;
use strict;
use warnings;
-use TUWF ':html', 'kv_validate';
+use TUWF ':html', 'kv_validate', 'xml_escape';
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 fmtmedia fmtvnlen
+ childtags charspoil imgpath imgurl
+ fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtuser
json_encode json_decode script_json
form_compare
|);
@@ -72,7 +73,7 @@ sub mt {
sub minage {
my($a, $ex) = @_;
- my $str = $a == -1 ? mt '_unknown' : !$a ? mt '_minage_all' : mt '_minage_age', $a;
+ my $str = $a == -1 ? 'Unknown' : !$a ? 'All ages' : sprintf '%d+', $a;
$ex = !defined($a) ? '' : {
0 => 'CERO A',
12 => 'CERO B',
@@ -81,7 +82,7 @@ sub minage {
18 => 'CERO Z',
}->{$a} if $ex;
return $str if !$ex;
- return $str.' '.mt('_minage_example', $ex);
+ return "$str (e.g. $ex)";
}
@@ -118,7 +119,7 @@ sub parenttags {
p;
my @p = _parenttags(@{$t->{parents}});
for my $p (@p ? @p : []) {
- a href => "/$type", $index; #mt '_tagp_indexlink';
+ a href => "/$type", $index;
for (reverse @$p) {
txt ' > ';
a href => "/$type$_->{id}", $_->{name};
@@ -165,9 +166,11 @@ sub childtags {
end;
}
if(@{$p->{'sub'}} > 6) {
+ my $c = @{$p->{'sub'}}-5;
li;
txt '> ';
- a href => "/$type$p->{id}", style => 'font-style: italic', mt $type eq 'g' ? '_tagp_moretags' : '_traitp_more', @{$p->{'sub'}}-5;
+ a href => "/$type$p->{id}", style => 'font-style: italic',
+ sprintf '%d more %s%s', $c, $type eq 'g' ? 'tag' : 'trait', $c==1 ? '' : 's';
end;
}
end;
@@ -221,6 +224,56 @@ sub fmtvnlen {
($xtra && $xtra == 2 && $len->[2] ? " ($len->[2])" : '');
}
+# Formats a UNIX timestamp as a '<number> <unit> ago' string
+sub fmtage {
+ my $a = time-shift;
+ my($t, $single, $plural) =
+ $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'year', 'years' ) :
+ $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'month', 'months' ) :
+ $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'week', 'weeks' ) :
+ $a > 60*60*24*2 ? ( $a/60/60/24, 'day', 'days' ) :
+ $a > 60*60*2 ? ( $a/60/60, 'hour', 'hours' ) :
+ $a > 60*2 ? ( $a/60, 'min', 'min' ) :
+ ( $a, 'sec', 'sec' );
+ $t = sprintf '%d', $t;
+ sprintf '%d %s ago', $t, $t == 1 ? $single : $plural;
+}
+
+# argument: database release date format (yyyymmdd)
+# y = 0000 -> unknown
+# y = 9999 -> TBA
+# m = 99 -> month+day unknown
+# d = 99 -> day unknown
+# return value: (unknown|TBA|yyyy|yyyy-mm|yyyy-mm-dd)
+# if date > now: <b class="future">str</b>
+sub fmtdatestr {
+ my $date = sprintf '%08d', shift||0;
+ my $future = $date > strftime '%Y%m%d', gmtime;
+ my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;
+
+ my $str = $y == 0 ? 'unknown' : $y == 9999 ? 'TBA' :
+ $m == 99 ? sprintf('%04d', $y) :
+ $d == 99 ? sprintf('%04d-%02d', $y, $m) :
+ sprintf('%04d-%02d-%02d', $y, $m, $d);
+
+ return $str if !$future;
+ return qq|<b class="future">$str</b>|;
+}
+
+# argument: unix timestamp and optional format (compact/full)
+sub fmtdate {
+ my($t, $f) = @_;
+ return strftime '%Y-%m-%d', gmtime $t if !$f || $f eq 'compact';
+ return strftime '%Y-%m-%d at %R', gmtime $t;
+}
+
+# Arguments: (uid, username), or a hashref containing that info
+sub fmtuser {
+ my($id,$n) = ref($_[0]) eq 'HASH' ? ($_[0]{uid}||$_[0]{requester}, $_[0]{username}) : @_;
+ return !$id ? '[deleted]' : sprintf '<a href="/u%d">%s</a>', $id, xml_escape $n;
+}
+
+
# JSON::XS::encode_json converts input to utf8, whereas the below functions
# operate on wide character strings. Canonicalization is enabled to allow for
diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm
index b180adeb..efba6b18 100644
--- a/lib/VNDB/Handler/Affiliates.pm
+++ b/lib/VNDB/Handler/Affiliates.pm
@@ -70,7 +70,7 @@ sub list {
td class => 'tc2', $l->{version} || '<default>';
td class => 'tc3', $l->{hidden} ? 'YES' : 'no';
td class => 'tc4', $l->{priority};
- td class => 'tc5', sprintf '%s / %s', $l->{price}, $l->{lastfetch} ? $self->{l10n}->age($l->{lastfetch}) : '-';
+ td class => 'tc5', sprintf '%s / %s', $l->{price}, $l->{lastfetch} ? fmtage($l->{lastfetch}) : '-';
td class => 'tc6';
a href => $l->{url}, 'link';
txt ' | ';
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index b95bab92..c2dea192 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -71,7 +71,7 @@ sub thread {
if(!$_->{hidden}) {
lit ' '.mt "_thread_byuser", $_;
br;
- lit $self->{l10n}->date($_->{date}, 'full');
+ txt fmtdate $_->{date}, 'full';
}
end;
td class => 'tc2';
@@ -300,7 +300,7 @@ sub edit {
'_postedit_edit';
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlForm({ frm => $frm, action => $url }, 'postedit' => [$title,
- [ static => label => mt('_postedit_form_username'), content => $self->{l10n}->userstr($p ? ($p->{uid}, $p->{username}) : ($self->authInfo->{id}, $self->authInfo->{username})) ],
+ [ static => label => mt('_postedit_form_username'), content => fmtuser($p ? ($p->{uid}, $p->{username}) : ($self->authInfo->{id}, $self->authInfo->{username})) ],
!$tid || $num == 1 ? (
[ input => short => 'title', name => mt('_postedit_form_title') ],
[ input => short => 'boards', name => mt('_postedit_form_boards') ],
@@ -559,8 +559,8 @@ sub search {
Tr;
td class => 'tc1_1'; a href => $link, 't'.$l->{tid}; end;
td class => 'tc1_2'; a href => $link, '.'.$l->{num}; end;
- td class => 'tc2', $self->{l10n}->date($l->{date});
- td class => 'tc3'; lit $self->{l10n}->userstr($l->{uid}, $l->{username}); end;
+ td class => 'tc2', fmtdate $l->{date};
+ td class => 'tc3'; lit fmtuser $l->{uid}, $l->{username}; end;
td class => 'tc4';
div class => 'title';
a href => $link, $l->{title};
@@ -618,14 +618,12 @@ sub _threadlist {
end;
td class => 'tc2', $o->{count}-1;
td class => 'tc3';
- lit $self->{l10n}->userstr($o->{fuid}, $o->{fusername});
+ lit fmtuser $o->{fuid}, $o->{fusername};
end;
td class => 'tc4';
- lit $self->{l10n}->userstr($o->{luid}, $o->{lusername});
+ lit fmtuser $o->{luid}, $o->{lusername};
lit ' @ ';
- a href => "/t$o->{id}.$o->{count}";
- lit $self->{l10n}->date($o->{ldate}, 'full');
- end;
+ a href => "/t$o->{id}.$o->{count}", fmtdate $o->{ldate}, 'full';
end;
end 'tr';
}
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 95bfe155..a6f6401b 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -147,7 +147,7 @@ sub homepage {
ul;
for (@$upcoming) {
li;
- lit $self->{l10n}->datestr($_->{released});
+ lit fmtdatestr $_->{released};
txt ' ';
cssicon $_, $self->{platforms}{$_} for (@{$_->{platforms}});
cssicon "lang $_", $self->{languages}{$_} for (@{$_->{languages}});
@@ -167,7 +167,7 @@ sub homepage {
ul;
for (@$justrel) {
li;
- lit $self->{l10n}->datestr($_->{released});
+ lit fmtdatestr $_->{released};
txt ' ';
cssicon $_, $self->{platforms}{$_} for (@{$_->{platforms}});
cssicon "lang $_", $self->{languages} for (@{$_->{languages}});
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 13dd40b0..a8bf371f 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -151,7 +151,7 @@ sub _releases {
for my $v (@vn) {
Tr class => 'vn';
td colspan => 6;
- i; lit $self->{l10n}->datestr($vn{$v->{vid}}[0]{released}); end;
+ i; lit fmtdatestr $vn{$v->{vid}}[0]{released}; end;
a href => "/v$v->{vid}", title => $v->{original}, $v->{title};
span '('.join(', ',
(grep($_->{developer}, @{$vn{$v->{vid}}}) ? mt '_prodpage_dev' : ()),
@@ -161,7 +161,7 @@ sub _releases {
end;
for my $rel (@{$vn{$v->{vid}}}) {
Tr class => 'rel';
- td class => 'tc1'; lit $self->{l10n}->datestr($rel->{released}); end;
+ td class => 'tc1'; lit fmtdatestr $rel->{released}; end;
td class => 'tc2', $rel->{minage} < 0 ? '' : minage $rel->{minage};
td class => 'tc3';
for (sort @{$rel->{platforms}}) {
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index fd05c069..531c878e 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -51,7 +51,7 @@ sub page {
[ catalog => serialize => sub { $_[0]||mt '_revision_empty' } ],
[ languages => join => ', ', split => sub { map $self->{languages}{$_}, @{$_[0]} } ],
[ 'website' ],
- [ released => htmlize => sub { $self->{l10n}->datestr($_[0]) } ],
+ [ released => htmlize => \&fmtdatestr ],
[ minage => serialize => \&minage ],
[ notes => diff => qr/[ ,\n\.]/ ],
[ platforms => join => ', ', split => sub { map $self->{platforms}{$_}, @{$_[0]} } ],
@@ -182,7 +182,7 @@ sub _infotable {
Tr;
td mt '_relinfo_released';
td;
- lit $self->{l10n}->datestr($r->{released});
+ lit fmtdatestr $r->{released};
end;
end;
@@ -520,7 +520,7 @@ sub browse {
my($s, $n, $l) = @_;
Tr;
td class => 'tc1';
- lit $self->{l10n}->datestr($l->{released});
+ lit fmtdatestr $l->{released};
end;
td class => 'tc2', $l->{minage} < 0 ? '' : minage $l->{minage};
td class => 'tc3';
diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm
index a6d59cbf..d4de2bf9 100644
--- a/lib/VNDB/Handler/Staff.pm
+++ b/lib/VNDB/Handler/Staff.pm
@@ -138,7 +138,7 @@ sub _roles {
my($r, $n, $l) = @_;
Tr;
td class => 'tc1'; a href => "/v$l->{vid}", title => $l->{t_original}||$l->{title}, shorten $l->{title}, 60; end;
- td class => 'tc2'; lit $self->{l10n}->datestr($l->{c_released}); end;
+ td class => 'tc2'; lit fmtdatestr $l->{c_released}; end;
td class => 'tc3', $self->{staff_roles}{$l->{role}};
td class => 'tc4', title => $l->{original}||$l->{name}, $l->{name};
td class => 'tc5', $l->{note};
@@ -167,7 +167,7 @@ sub _cast {
my($r, $n, $l) = @_;
Tr;
td class => 'tc1'; a href => "/v$l->{vid}", title => $l->{t_original}||$l->{title}, shorten $l->{title}, 60; end;
- td class => 'tc2'; lit $self->{l10n}->datestr($l->{c_released}); end;
+ td class => 'tc2'; lit fmtdatestr $l->{c_released}; end;
td class => 'tc3'; a href => "/c$l->{cid}", title => $l->{c_original}, $l->{c_name}; end;
td class => 'tc4', title => $l->{original}||$l->{name}, $l->{name};
td class => 'tc5', $l->{note};
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 3e6a37d1..bb6dd2d4 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -227,7 +227,7 @@ sub tagedit {
[ input => short => 'name', name => mt '_tagedit_frm_name' ],
$self->authCan('tagmod') ? (
$tag ?
- [ static => label => mt('_tagedit_frm_by'), content => $self->{l10n}->userstr($t->{addedby}, $t->{username}) ] : (),
+ [ static => label => mt('_tagedit_frm_by'), content => fmtuser($t->{addedby}, $t->{username}) ] : (),
[ select => short => 'state', name => mt('_tagedit_frm_state'), options => [
map [$_, mt '_tagedit_frm_state'.$_], 0..2 ] ],
[ checkbox => short => 'meta', name => mt '_tagedit_frm_meta' ],
@@ -328,7 +328,7 @@ sub taglist {
row => sub {
my($s, $n, $l) = @_;
Tr;
- td class => 'tc1', $self->{l10n}->age($l->{added});
+ td class => 'tc1', fmtage $l->{added};
td class => 'tc3';
a href => "/g$l->{id}", $l->{name};
if($f->{t} == -1) {
@@ -434,9 +434,7 @@ sub taglinks {
row => sub {
my($s, $n, $l) = @_;
Tr;
- td class => 'tc1';
- lit $self->{l10n}->date($l->{date});
- end;
+ td class => 'tc1', fmtdate $l->{date};
td class => 'tc2';
a href => $url->(u=>$l->{uid}), class => 'setfil', '> ' if !$f->{u};
a href => "/u$l->{uid}", $l->{username};
@@ -642,7 +640,7 @@ sub tagindex {
ul;
for (@$r) {
li;
- txt $self->{l10n}->age($_->{added});
+ txt fmtage $_->{added};
txt ' ';
a href => "/g$_->{id}", $_->{name};
end;
@@ -673,7 +671,7 @@ sub tagindex {
li mt '_tagidx_queue_empty' if !@$r;
for (@$r) {
li;
- txt $self->{l10n}->age($_->{added});
+ txt fmtage $_->{added};
txt ' ';
a href => "/g$_->{id}", $_->{name};
end;
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index 8d689581..4b106fa2 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -215,7 +215,7 @@ sub traitedit {
[ input => short => 'name', name => mt '_traite_frm_name' ],
$self->authCan('tagmod') ? (
$t ?
- [ static => label => mt('_traite_frm_by'), content => $self->{l10n}->userstr($t->{addedby}, $t->{username}) ] : (),
+ [ static => label => mt('_traite_frm_by'), content => fmtuser($t->{addedby}, $t->{username}) ] : (),
[ select => short => 'state', name => mt('_traite_frm_state'), options => [
map [$_, mt '_traite_frm_state'.$_], 0..2 ] ],
[ checkbox => short => 'meta', name => mt '_traite_frm_meta' ]
@@ -302,7 +302,7 @@ sub traitlist {
row => sub {
my($s, $n, $l) = @_;
Tr;
- td class => 'tc1', $self->{l10n}->age($l->{added});
+ td class => 'tc1', fmtage $l->{added};
td class => 'tc3';
if($l->{group}) {
b class => 'grayedout', $l->{groupname}.' / ';
@@ -347,7 +347,7 @@ sub traitindex {
ul;
for (@$r) {
li;
- txt $self->{l10n}->age($_->{added});
+ txt fmtage $_->{added};
txt ' ';
b class => 'grayedout', $_->{groupname}.' / ' if $_->{group};
a href => "/i$_->{id}", $_->{name};
@@ -379,7 +379,7 @@ sub traitindex {
li mt '_traiti_queue_empty' if !@$r;
for (@$r) {
li;
- txt $self->{l10n}->age($_->{added});
+ txt fmtage $_->{added};
txt ' ';
b class => 'grayedout', $_->{groupname}.' / ' if $_->{group};
a href => "/i$_->{id}", $_->{name};
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index 9a54e852..a19be8e9 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -190,7 +190,7 @@ sub votelist {
Tr;
td class => 'tc1';
input type => 'checkbox', name => 'vid', value => $l->{vid} if $own;
- txt ' '.$self->{l10n}->date($l->{date});
+ txt ' '.fmtdate $l->{date};
end;
td class => 'tc2', fmtvote $l->{vote};
td class => 'tc3';
@@ -299,7 +299,7 @@ sub wishlist {
a href => "/v$i->{vid}", title => $i->{original}||$i->{title}, ' '.shorten $i->{title}, 70;
end;
td class => 'tc2', $self->{wishlist_status}[$i->{wstat}];
- td class => 'tc3', $self->{l10n}->date($i->{added}, 'compact');
+ td class => 'tc3', fmtdate $i->{added}, 'compact';
end;
},
$own ? (footer => sub {
@@ -471,7 +471,7 @@ sub _vnlist_browse {
input type => 'checkbox', name => 'rid', value => $_->{rid} if $own;
end;
td class => 'tc3';
- lit $self->{l10n}->datestr($_->{released});
+ lit fmtdatestr $_->{released};
end;
td class => 'tc4';
cssicon "lang $_", $self->{languages}{$_} for @{$_->{languages}};
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index e7fd9a4f..8c72ba82 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -54,7 +54,7 @@ sub userpage {
Tr;
td mt '_userpage_registered';
- td $self->{l10n}->date($u->{registered});
+ td fmtdate $u->{registered};
end;
Tr;
@@ -504,7 +504,7 @@ sub posts {
Tr;
td class => 'tc1'; a href => "/t$l->{tid}.$l->{num}", 't'.$l->{tid}; end;
td class => 'tc2'; a href => "/t$l->{tid}.$l->{num}", '.'.$l->{num}; end;
- td class => 'tc3', $self->{l10n}->date($l->{date});
+ td class => 'tc3', fmtdate $l->{date};
td class => 'tc4';
a href => "/t$l->{tid}.$l->{num}", $l->{title};
b class => 'grayedout'; lit bb2html $l->{msg}, 150; end;
@@ -613,7 +613,7 @@ sub list {
td class => 'tc1';
a href => '/u'.$l->{id}, $l->{username};
end;
- td class => 'tc2', $self->{l10n}->date($l->{registered});
+ td class => 'tc2', fmtdate $l->{registered};
td class => 'tc3'.($l->{hide_list} && $self->authCan('usermod') ? ' linethrough' : '');
lit $l->{hide_list} && !$self->authCan('usermod') ? '-' : !$l->{c_votes} ? 0 :
qq|<a href="/u$l->{id}/votes">$l->{c_votes}</a>|;
@@ -714,7 +714,7 @@ sub notifies {
input type => 'checkbox', name => 'notifysel', value => "$l->{id}";
end;
td class => 'tc2', mt "_usern_type_$l->{ntype}";
- td class => 'tc3', $self->{l10n}->age($l->{date});
+ td class => 'tc3', fmtage $l->{date};
td class => 'tc4';
a href => "/u$uid/notify/$l->{id}", "$l->{ltype}$l->{iid}".($l->{subid}?".$l->{subid}":'');
end;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 055e2831..89cd9940 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -161,7 +161,7 @@ my @rel_cols = (
column_string => '_relinfo_released',
button_string => '_relinfo_released',
default => 1,
- draw => sub { lit $TUWF::OBJ->{l10n}->datestr($_[0]{released}) },
+ draw => sub { lit fmtdatestr $_[0]{released} },
}, { # Age rating
id => 'min',
sort_field => 'minage',
@@ -718,7 +718,6 @@ sub _affiliate_links {
return if !@$links;
$links = [ sort { $b->{priority}||$self->{affiliates}[$b->{affiliate}]{default_prio} <=> $a->{priority}||$self->{affiliates}[$a->{affiliate}]{default_prio} } @$links ];
- my $en = VNDB::L10N->get_handle('en');
Tr id => 'buynow';
td 'Available at';
@@ -736,7 +735,7 @@ sub _affiliate_links {
|| $version;
txt " at $f->{name}";
abbr class => 'pricenote', title =>
- $link->{lastfetch} ? sprintf('Last updated: %s.', $en->age($link->{lastfetch})) : '', " for $link->{price}"
+ $link->{lastfetch} ? sprintf('Last updated: %s.', fmtage($link->{lastfetch})) : '', " for $link->{price}"
if $link->{price};
txt ' ยป';
end;
@@ -779,7 +778,7 @@ sub _releases {
end;
for my $rel (grep grep($_ eq $l, @{$_->{languages}}), @$r) {
Tr;
- td class => 'tc1'; lit $self->{l10n}->datestr($rel->{released}); end;
+ td class => 'tc1'; lit fmtdatestr $rel->{released}; end;
td class => 'tc2', $rel->{minage} < 0 ? '' : minage $rel->{minage};
td class => 'tc3';
for (sort @{$rel->{platforms}}) {
diff --git a/lib/VNDB/L10N.pm b/lib/VNDB/L10N.pm
index 2e6a32bd..e03f1dcb 100644
--- a/lib/VNDB/L10N.pm
+++ b/lib/VNDB/L10N.pm
@@ -53,63 +53,17 @@ use warnings;
use base 'VNDB::L10N';
use POSIX 'strftime';
use TUWF::XML 'xml_escape';
+ require VNDB::Func;
our %Lexicon;
sub quant {
return $_[1]==1 ? $_[2] : $_[3];
}
- # Argument: unix timestamp
- # Returns: age
- sub age {
- my($self, $time) = @_;
- my $a = time-$time;
- my @f =
- $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'years' ) :
- $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'months' ) :
- $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'weeks' ) :
- $a > 60*60*24*2 ? ( $a/60/60/24, 'days' ) :
- $a > 60*60*2 ? ( $a/60/60, 'hours' ) :
- $a > 60*2 ? ( $a/60, 'min' ) :
- ( $a, 'sec' );
- return $self->maketext("_age_$f[1]", int $f[0]);
- }
-
- # argument: unix timestamp and optional format (compact/full)
- sub date {
- my($s, $t, $f) = @_;
- return strftime $s->maketext('_datetime_compact'), gmtime $t if !$f || $f eq 'compact';
- return strftime $s->maketext('_datetime_full'), gmtime $t;
- }
-
- # argument: database release date format (yyyymmdd)
- # y = 0000 -> unknown
- # y = 9999 -> TBA
- # m = 99 -> month+day unknown
- # d = 99 -> day unknown
- # return value: (unknown|TBA|yyyy|yyyy-mm|yyyy-mm-dd)
- # if date > now: <b class="future">str</b>
- sub datestr {
- my $self = shift;
- my $date = sprintf '%08d', shift||0;
- my $future = $date > strftime '%Y%m%d', gmtime;
- my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;
-
- my $str = $y == 0 ? 'unknown' : $y == 9999 ? 'TBA' :
- $m == 99 ? sprintf('%04d', $y) :
- $d == 99 ? sprintf('%04d-%02d', $y, $m) :
- sprintf('%04d-%02d-%02d', $y, $m, $d);
-
- return $str if !$future;
- return qq|<b class="future">$str</b>|;
- }
-
- # Arguments: (uid, username), or a hashref containing that info
- sub userstr {
- my $self = shift;
- my($id,$n) = ref($_[0])eq'HASH'?($_[0]{uid}||$_[0]{requester}, $_[0]{username}):@_;
- return !$id ? '[deleted]' : '<a href="/u'.$id.'">'.$n.'</a>';
- }
+ sub age { VNDB::Func::fmtage($_[1]) }
+ sub date { VNDB::Func::fmtdate($_[1], $_[2]) }
+ sub datestr { VNDB::Func::fmtdatestr($_[1]) }
+ sub userstr { VNDB::Func::fmtuser($_[1], $_[2]) }
# Arguments: index, @list. returns $list[index]
sub index {
diff --git a/lib/VNDB/Util/BrowseHTML.pm b/lib/VNDB/Util/BrowseHTML.pm
index 240cf20b..faa9ea3c 100644
--- a/lib/VNDB/Util/BrowseHTML.pm
+++ b/lib/VNDB/Util/BrowseHTML.pm
@@ -146,9 +146,9 @@ sub htmlBrowseHist {
td class => 'tc1_2';
a href => $revurl, ".$i->{rev}";
end;
- td class => 'tc2', $self->{l10n}->date($i->{added}, 'full');
+ td class => 'tc2', fmtdate $i->{added}, 'full';
td class => 'tc3';
- lit $self->{l10n}->userstr($i);
+ lit fmtuser $i;
end;
td class => 'tc4';
a href => $revurl, title => $i->{ioriginal}, shorten $i->{ititle}, 80;
@@ -206,7 +206,7 @@ sub htmlBrowseVN {
for (reverse sort @{$l->{c_languages}});
end;
td class => 'tc4';
- lit $self->{l10n}->datestr($l->{c_released});
+ lit fmtdatestr $l->{c_released};
end;
td class => 'tc5', sprintf '%.2f', ($l->{c_popularity}||0)*100;
td class => 'tc6';
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index b576e4ad..cacbae93 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -394,7 +394,7 @@ sub htmlVoteStats {
}
end;
td fmtvote $_->{vote};
- td $self->{l10n}->date($_->{date});
+ td fmtdate $_->{date};
end;
}
end 'table';