summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-04-11 10:51:44 +0200
committerYorhel <git@yorhel.nl>2020-04-11 10:51:47 +0200
commitc71afbf134c173d5c36871135e969b93c652be0c (patch)
treea08b9ff7eee33b9896045a2b3bb4675d3d217488 /lib/VNDB
parent6fd9ceb051538f11829b7d9b2919665dbeca70ed (diff)
v2rw: Convert VN char pages (/v+/chars)
This also reimplements the VN infobox part of the page - a good first step into converting the main VN pages to v2rw. The new '?view=' parameter is used for spoiler and sexual hiding. Also fixes a bug on character pages where release-specific roles weren't displayed correctly.
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/ExtLinks.pm13
-rw-r--r--lib/VNDB/Handler/Chars.pm168
-rw-r--r--lib/VNDB/Handler/VNPage.pm26
3 files changed, 14 insertions, 193 deletions
diff --git a/lib/VNDB/ExtLinks.pm b/lib/VNDB/ExtLinks.pm
index 722bf10b..2d057847 100644
--- a/lib/VNDB/ExtLinks.pm
+++ b/lib/VNDB/ExtLinks.pm
@@ -6,7 +6,7 @@ use VNDB::Config;
use VNDB::Schema;
use Exporter 'import';
-our @EXPORT = ('enrich_extlinks', 'revision_extlinks', 'validate_extlinks');
+our @EXPORT = ('sql_extlinks', 'enrich_extlinks', 'revision_extlinks', 'validate_extlinks');
# column name in wikidata table => \%info
@@ -162,6 +162,15 @@ our %LINKS = (
);
+# Return a list of columns to fetch all external links for a database entry.
+sub sql_extlinks {
+ my($type, $prefix) = @_;
+ $prefix ||= '';
+ my $l = $LINKS{$type} || die "DB entry type $type has no links";
+ VNWeb::DB::sql_comma(map $prefix.$_, sort keys %$l)
+}
+
+
# Fetch a list of links to display at the given database entries, adds the
# following field to each object:
#
@@ -213,7 +222,7 @@ sub enrich_extlinks {
}
my sub l {
my($f, $price) = @_;
- my($v, $fmt, $fmt2, $label) = ($obj->{$f}, @{$l->{$f}}{'fmt', 'fmt2', 'label'});
+ my($v, $fmt, $fmt2, $label) = ($obj->{$f}, $l->{$f} ? @{$l->{$f}}{'fmt', 'fmt2', 'label'} : ());
push @links, map [ $label, sprintf(ref $fmt2 ? $fmt2->($obj) : $fmt2 || $fmt, $_), $price ], ref $v ? @$v : $v ? $v : ()
}
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index d1544981..95430108 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -9,7 +9,7 @@ use VNDB::Func;
use VNDB::Types;
use List::Util 'min';
-our @EXPORT = ('charOps', 'charTable', 'charBrowseTable');
+our @EXPORT = ('charOps', 'charBrowseTable');
TUWF::register(
qr{c(?:([1-9]\d*)(?:\.([1-9]\d*))?/(edit|copy)|/new)}
@@ -43,172 +43,6 @@ sub charOps {
}
-# Also used from Handler::VNPage
-sub charTable {
- my($self, $r, $link, $sep, $vn, $spoil) = @_;
- $spoil ||= 0;
-
- div class => 'chardetails '.charspoil($spoil).($sep ? ' charsep' : '');
-
- # image
- div class => 'charimg';
- if(!$r->{image}) {
- p 'No image uploaded yet';
- } else {
- img src => imgurl(ch => $r->{image}), alt => $r->{name};
- }
- end 'div';
-
- # info table
- table class => 'stripe';
- thead;
- Tr;
- td colspan => 2;
- if($link) {
- a href => "/c$r->{id}", style => 'margin-right: 10px; font-weight: bold', $r->{name};
- } else {
- b style => 'margin-right: 10px', $r->{name};
- }
- b class => 'grayedout', style => 'margin-right: 10px', $r->{original} if $r->{original};
- cssicon "gen $r->{gender}", $GENDER{$r->{gender}} if $r->{gender} ne 'unknown';
- span $BLOOD_TYPE{$r->{bloodt}} if $r->{bloodt} ne 'unknown';
- end;
- end;
- end;
-
- if($r->{alias}) {
- $r->{alias} =~ s/\n/, /g;
- Tr;
- td class => 'key', 'Aliases';
- td $r->{alias};
- end;
- }
- if(defined($r->{weight}) || $r->{height} || $r->{s_bust} || $r->{s_waist} || $r->{s_hip} || $r->{cup_size}) {
- Tr;
- td class => 'key', 'Measurements';
- td join ', ',
- $r->{height} ? "Height: $r->{height}cm" : (),
- defined($r->{weight}) ? "Weight: $r->{weight}kg" : (),
- $r->{s_bust} || $r->{s_waist} || $r->{s_hip} ?
- sprintf 'Bust-Waist-Hips: %s-%s-%scm', $r->{s_bust}||'??', $r->{s_waist}||'??', $r->{s_hip}||'??' : (),
- $r->{cup_size} ? "$CUP_SIZE{$r->{cup_size}} cup" : ();
- end;
- }
- if($r->{b_month} && $r->{b_day}) {
- Tr;
- td class => 'key', 'Birthday';
- td $r->{b_day}.' '.[qw{January February March April May June July August September October November December}]->[$r->{b_month}-1];
- end;
- }
- if(defined $r->{age}) {
- Tr;
- td class => 'key', 'Age';
- td $r->{age};
- end;
- }
-
- # traits
- my %groups;
- my @groups;
- for (@{$r->{traits}}) {
- my $g = $_->{group}||$_->{tid};
- push @groups, $g if !$groups{$g};
- push @{$groups{ $g }}, $_
- }
- for my $g (@groups) {
- Tr class => 'traitrow';
- td class => 'key'; a href => '/i'.($groups{$g}[0]{group}||$groups{$g}[0]{tid}), $groups{$g}[0]{groupname} || $groups{$g}[0]{name}; end;
- td;
- for (0..$#{$groups{$g}}) {
- my $t = $groups{$g}[$_];
- span class => charspoil($t->{spoil}).($t->{sexual} ? ' sexual' : '');
- txt ', ';
- a href => "/i$t->{tid}", $t->{name};
- end;
- }
- end;
- end;
- }
-
- # vns
- if(@{$r->{vns}} && (!$vn || $vn && (@{$r->{vns}} > 1 || $r->{vns}[0]{rid}))) {
- my %vns;
- push @{$vns{$_->{vid}}}, $_ for(sort { !defined($a->{rid})?1:!defined($b->{rid})?-1:$a->{rtitle} cmp $b->{rtitle} } @{$r->{vns}});
- Tr;
- td class => 'key', $vn ? 'Releases' : 'Visual novels';
- td;
- my $first = 0;
- for my $g (sort { $vns{$a}[0]{vntitle} cmp $vns{$b}[0]{vntitle} } keys %vns) {
- my @r = @{$vns{$g}};
- # special case: all releases, no exceptions
- if(!$vn && @r == 1 && !$r[0]{rid}) {
- span class => charspoil $r[0]{spoil};
- txt $CHAR_ROLE{$r[0]{role}}{txt}.' - ';
- a href => "/v$r[0]{vid}/chars", $r[0]{vntitle};
- br;
- end;
- next;
- }
- # otherwise, print VN title and list releases separately
- my $minspoil = 5;
- $minspoil = $minspoil > $_->{spoil} ? $_->{spoil} : $minspoil for (@r);
- span class => charspoil $minspoil;
- a href => "/v$r[0]{vid}/chars", $r[0]{vntitle} if !$vn;
- for(@r) {
- span class => charspoil $_->{spoil};
- br if !$vn || $_ != $r[0];
- b class => 'grayedout', '> ';
- txt $CHAR_ROLE{$_->{role}}{txt}.' - ';
- if($_->{rid}) {
- b class => 'grayedout', "r$_->{rid}:";
- a href => "/r$_->{rid}", $_->{rtitle};
- } else {
- txt 'All other releases';
- }
- end;
- }
- br;
- end;
- }
- end;
- end;
- }
-
- if(@{$r->{seiyuu}}) {
- Tr;
- td class => 'key', 'Voiced by';
- td;
- my $last_name = '';
- for my $s (sort { $a->{name} cmp $b->{name} } @{$r->{seiyuu}}) {
- next if $s->{name} eq $last_name;
- a href => "/s$s->{sid}", title => $s->{original}||$s->{name}, $s->{name};
- txt ' ('.$s->{note}.')' if $s->{note};
- br;
- $last_name = $s->{name};
- }
- end;
- end;
- }
-
- # description
- if($r->{desc}) {
- Tr class => 'nostripe';
- td class => 'chardesc', colspan => 2;
- h2 'Description';
- p;
- lit bb2html $r->{desc}, 0, 1;
- end;
- end;
- end;
- }
-
- end 'table';
- end;
- clearfloat;
-}
-
-
-
sub edit {
my($self, $id, $rev, $copy) = @_;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 2f35744f..3170fd30 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -14,7 +14,6 @@ use POSIX 'strftime';
TUWF::register(
qr{v/rand} => \&rand,
qr{v([1-9]\d*)/releases} => \&releases,
- qr{v([1-9]\d*)/(chars)} => \&page,
qr{v([1-9]\d*)/staff} => sub { $_[0]->resRedirect("/v$_[1]#staff") },
qr{v([1-9]\d*)(?:\.([1-9]\d*))?} => \&page,
);
@@ -306,7 +305,7 @@ sub _releases_table {
sub page {
my($self, $vid, $rev) = @_;
- my $char = $rev && $rev eq 'chars';
+ my $char = $rev && $rev eq 'chars'; # XXX: Not used anymore; implemented in VNWeb::VN::Page.
$rev = undef if $char;
my $method = $rev ? 'dbVNGetRev' : 'dbVNGet';
@@ -500,7 +499,7 @@ sub page {
}
if($char) {
- _chars($self, $chars, $v);
+ #_chars($self, $chars, $v);
} else {
_releases($self, $v, $r);
_staff($self, $v);
@@ -948,27 +947,6 @@ sub _charspoillvl {
}
-sub _chars {
- my($self, $l, $v) = @_;
- return if !@$l;
- my %done;
- my %rol;
- for my $r (keys %CHAR_ROLE) {
- $rol{$r} = [ grep grep($_->{role} eq $r, @{$_->{vns}}) && !$done{$_->{id}}++, @$l ];
- }
- div class => 'charops', id => 'charops';
- $self->charOps(1, 'chars');
- for my $r (keys %CHAR_ROLE) {
- next if !@{$rol{$r}};
- div class => 'mainbox';
- h1 $CHAR_ROLE{$r}{ @{$rol{$r}} > 1 ? 'plural' : 'txt' };
- $self->charTable($_, 1, $_ != $rol{$r}[0], 1, _charspoillvl $v->{id}, $_) for (@{$rol{$r}});
- end;
- }
- end;
-}
-
-
sub _charsum {
my($self, $l, $v) = @_;
return if !@$l;