summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-12-02 10:40:27 +0100
committerYorhel <git@yorhel.nl>2008-12-02 10:40:27 +0100
commit2e086e8f474ad1bb8840ff64a2f2590e9dae3212 (patch)
treeba205c033dd1ff96bf18e4ac7643d356523eb5d8 /lib
parent531db3e8ddc8523df730a3412fe6ccee21a71259 (diff)
Started on the release pages
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Func.pm30
-rw-r--r--lib/VNDB/Handler/Releases.pm147
2 files changed, 176 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index ac555d1d..8971c6a8 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
use POSIX 'strftime';
-our @EXPORT = qw| shorten date datestr monthstr userstr bb2html |;
+our @EXPORT = qw| shorten date datestr monthstr userstr bb2html gtintype |;
# I would've done this as a #define if this was C...
@@ -143,5 +143,33 @@ sub bb2html {
}
+# GTIN code as argument,
+# Returns 'JAN', 'EAN', 'UPC' or undef,
+# Also 'normalizes' the first argument in place
+sub gtintype {
+ $_[0] =~ s/[^\d]+//g;
+ $_[0] =~ s/^0+//;
+ my $c = shift;
+ return undef if $c !~ /^[0-9]{12,13}$/; # only gtin-12 and 13
+ $c = ('0'x(13-length $c)) . $c; # pad with zeros
+
+ # calculate check digit according to
+ # http://www.gs1.org/productssolutions/barcodes/support/check_digit_calculator.html#how
+ my @n = reverse split //, $c;
+ my $n = shift @n;
+ $n += $n[$_] * ($_ % 2 != 0 ? 1 : 3) for (0..$#n);
+ return undef if $n % 10 != 0;
+
+ # Do some rough guesses based on:
+ # http://www.gs1.org/productssolutions/barcodes/support/prefix_list.html
+ # and http://en.wikipedia.org/wiki/List_of_GS1_country_codes
+ local $_ = $c;
+ return 'JAN' if /^4[59]/; # prefix code 450-459 & 490-499
+ return 'UPC' if /^(?:0[01]|0[6-9]|13|75[45])/; # prefix code 000-019 & 060-139 & 754-755
+ return undef if /(?:0[2-5]|2|97[789]|9[6-9])/; # some codes we don't want: 020–059 & 200-299 & 977-999
+ return 'EAN'; # let's just call everything else EAN :)
+}
+
+
1;
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
new file mode 100644
index 00000000..6c033d5c
--- /dev/null
+++ b/lib/VNDB/Handler/Releases.pm
@@ -0,0 +1,147 @@
+
+package VNDB::Handler::Releases;
+
+use strict;
+use warnings;
+use YAWF ':html';
+use VNDB::Func;
+
+
+YAWF::register(
+ qr{r([1-9]\d*)}, \&page,
+);
+
+
+sub page {
+ my($self, $rid) = @_;
+
+ my $r = $self->dbReleaseGet(id => $rid, what => 'vn producers platforms media')->[0];
+ return 404 if !$r->{id};
+
+ $self->htmlHeader(title => $r->{title});
+ $self->htmlMainTabs('r', $r);
+ div class => 'mainbox release';
+ h1 $r->{title};
+ h2 class => 'alttitle', $r->{original} if $r->{original};
+
+ _infotable($self, $r);
+
+ if($r->{notes}) {
+ p class => 'description';
+ lit bb2html $r->{notes};
+ end;
+ }
+
+ end;
+ $self->htmlFooter;
+}
+
+
+sub _infotable {
+ my($self, $r) = @_;
+ table;
+ Tr;
+ td class => 'key', ' ';
+ td ' ';
+ end;
+ my $i = 0;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Relation';
+ td;
+ for (@{$r->{vn}}) {
+ a href => "/v$_->{vid}", title => $_->{original}||$_->{title}, shorten $_->{title}, 60;
+ br if $_ != $r->{vn}[$#{$r->{vn}}];
+ }
+ end;
+ end;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Type';
+ td;
+ my $type = $self->{release_types}[$r->{type}];
+ acronym class => 'icons '.lc(substr $type, 0, 3), title => $type, ' ';
+ txt ' '.$type;
+ end;
+ end;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Language';
+ td;
+ acronym class => "icons lang $r->{language}", title => $self->{languages}{$r->{language}}, ' ';
+ txt ' '.$self->{languages}{$r->{language}};
+ end;
+ end;
+
+ if(@{$r->{platforms}}) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Platform'.($#{$r->{platforms}} ? 's' : '');
+ td;
+ for(@{$r->{platforms}}) {
+ acronym class => "icons $_", title => $self->{platforms}{$_}, ' ';
+ txt ' '.$self->{platforms}{$_};
+ br if $_ ne $r->{platforms}[$#{$r->{platforms}}];
+ }
+ end;
+ end;
+ }
+
+ if(@{$r->{media}}) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Medi'.($#{$r->{media}} ? 'a' : 'um');
+ td join ', ', map {
+ my $med = $self->{media}{$_->{medium}};
+ $med->[1] ? sprintf('%d %s%s', $_->{qty}, $med->[0], $_->{qty}>1?'s':'') : $med->[0]
+ } @{$r->{media}};
+ end;
+ }
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Released';
+ td;
+ lit datestr $r->{released};
+ end;
+ end;
+
+ if($r->{minage} >= 0) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Age rating';
+ td $self->{age_ratings}{$r->{minage}};
+ end;
+ }
+
+ if(@{$r->{producers}}) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Producer'.($#{$r->{producers}} ? 's' : '');
+ td;
+ for (@{$r->{producers}}) {
+ a href => "/p$_->{id}", title => $_->{original}||$_->{name}, shorten $_->{name}, 60;
+ br if $_ != $r->{producers}[$#{$r->{producers}}];
+ }
+ end;
+ end;
+ }
+
+ if($r->{gtin}) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td gtintype $r->{gtin};
+ td $r->{gtin};
+ end;
+ }
+
+ if($r->{website}) {
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Links';
+ td;
+ a href => $r->{website}, rel => 'nofollow', 'Official website';
+ end;
+ end;
+ }
+
+ end;
+}
+
+
+
+1;
+