diff options
author | Yorhel <git@yorhel.nl> | 2019-11-14 13:26:03 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-11-14 13:31:15 +0100 |
commit | 389fe32c24adce3277548892b5d636c40ac35bc4 (patch) | |
tree | b739ac49edbe9670b64d310676a32310a6f69440 /lib/VNDB/Handler/Staff.pm | |
parent | 06bacb61526f3945520dd344821d2aa7b85a5f43 (diff) |
v2rw: Convert staff pages
This is where the ExtLink module comes in handy: generating the revision
comparison thing is much easier now. Did find and fix a bunch of issues
with the new revision box generator code, but that was to be expected, I
hadn't tested that code well yet and this is its first more demanding
use.
Rest of this is a pretty direct rewrite, nothing too special.
Diffstat (limited to 'lib/VNDB/Handler/Staff.pm')
-rw-r--r-- | lib/VNDB/Handler/Staff.pm | 165 |
1 files changed, 1 insertions, 164 deletions
diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm index 7da42e8d..adab2be8 100644 --- a/lib/VNDB/Handler/Staff.pm +++ b/lib/VNDB/Handler/Staff.pm @@ -3,180 +3,17 @@ package VNDB::Handler::Staff; use strict; use warnings; -use TUWF qw(:html :xml uri_escape xml_escape); +use TUWF qw(:html :xml uri_escape); use VNDB::Func; use VNDB::Types; -use VNDB::ExtLinks; use List::Util qw(first); TUWF::register( - qr{s([1-9]\d*)(?:\.([1-9]\d*))?} => \&page, qr{s/([a-z0]|all)} => \&list, qr{xml/staff\.xml} => \&staffxml, ); -sub page { - my($self, $id, $rev) = @_; - - my $method = $rev ? 'dbStaffGetRev' : 'dbStaffGet'; - my $s = $self->$method( - id => $id, - what => 'extended aliases roles', - $rev ? ( rev => $rev ) : () - )->[0]; - return $self->resNotFound if !$s->{id}; - enrich_extlinks s => $s; - - my $metadata = { - 'og:title' => $s->{name}, - 'og:description' => bb2text $s->{desc}, - }; - - $self->htmlHeader(title => $s->{name}, noindex => $rev, metadata => $metadata); - $self->htmlMainTabs('s', $s) if $id; - return if $self->htmlHiddenMessage('s', $s); - - if($rev) { - my $prev = $rev && $rev > 1 && $self->dbStaffGetRev(id => $id, rev => $rev-1, what => 'extended aliases')->[0]; - $self->htmlRevision('s', $prev, $s, - [ name => 'Name (romaji)', diff => 1 ], - [ original => 'Original name', diff => 1 ], - [ gender => 'Gender', serialize => sub { $GENDER{$_[0]} } ], - [ lang => 'Language', serialize => sub { "$_[0] ($LANGUAGE{$_[0]})" } ], - [ l_site => 'Official page', diff => 1 ], - [ l_wp => 'Wikipedia link', htmlize => sub { $_[0] ? sprintf '<a href="http://en.wikipedia.org/wiki/%s">%1$s</a>', xml_escape $_[0] : '[empty]' }], - [ l_wikidata=> 'Wikidata ID', htmlize => sub { $_[0] ? sprintf '<a href="https://www.wikidata.org/wiki/Q%d">Q%1$d</a>', $_[0] : '[empty]' } ], - [ l_twitter => 'Twitter account', diff => 1 ], - [ l_anidb => 'AniDB creator ID', serialize => sub { $_[0] // '' } ], - [ l_pixiv => 'Pixiv', htmlize => sub { $_[0] ? sprintf '<a href="https://www.pixiv.net/member.php?id=%d">%1$d</a>', $_[0] : '[empty]' } ], - [ desc => 'Description', diff => qr/[ ,\n\.]/ ], - [ aliases => 'Aliases', join => '<br />', split => sub { - map xml_escape(sprintf('%s%s', $_->{name}, $_->{original} ? ' ('.$_->{original}.')' : '')), @{$_[0]}; - }], - ); - } - - div class => 'mainbox staffpage'; - $self->htmlItemMessage('s', $s); - h1 $s->{name}; - h2 class => 'alttitle', lang => $s->{lang}, $s->{original} if $s->{original}; - - # info table - table class => 'stripe'; - thead; - Tr; - td colspan => 2; - b style => 'margin-right: 10px', $s->{name}; - b class => 'grayedout', style => 'margin-right: 10px', lang => $s->{lang}, $s->{original} if $s->{original}; - cssicon "gen $s->{gender}", $GENDER{$s->{gender}} if $s->{gender} ne 'unknown'; - end; - end; - end; - Tr; - td class => 'key', 'Language'; - td $LANGUAGE{$s->{lang}}; - end; - if(@{$s->{aliases}}) { - Tr; - td class => 'key', @{$s->{aliases}} == 1 ? 'Alias' : 'Aliases'; - td; - table class => 'aliases'; - for my $alias (@{$s->{aliases}}) { - Tr class => 'nostripe'; - td $alias->{original} ? () : (colspan => 2), class => 'key'; - txt $alias->{name}; - end; - td lang => $s->{lang}, $alias->{original} if $alias->{original}; - end; - } - end; - end; - end; - } - if($s->{extlinks}->@*) { - Tr; - td class => 'key', 'Links'; - td; - for($s->{extlinks}->@*) { - a href => $_->[1], $_->[0]; - br if $_ != $s->{extlinks}[$#{$s->{extlinks}}]; - } - end; - end; - } - end 'table'; - - # description - p class => 'description'; - lit bb2html $s->{desc}, 0, 1; - end; - end; - - _roles($self, $s); - _cast($self, $s); - $self->htmlFooter; -} - - -sub _roles { - my($self, $s) = @_; - return if !@{$s->{roles}}; - - h1 class => 'boxtitle', 'Credits'; - $self->htmlBrowse( - items => $s->{roles}, - class => 'staffroles', - header => [ - [ 'Title' ], - [ 'Released' ], - [ 'Role' ], - [ 'As' ], - [ 'Note' ], - ], - row => sub { - 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 fmtdatestr $l->{c_released}; end; - td class => 'tc3', $CREDIT_TYPE{$l->{role}}; - td class => 'tc4', title => $l->{original}||$l->{name}, $l->{name}; - td class => 'tc5', $l->{note}; - end; - }, - ); -} - - -sub _cast { - my($self, $s) = @_; - return if !@{$s->{cast}}; - - h1 class => 'boxtitle', sprintf 'Voiced characters (%d)', scalar @{$s->{cast}}; - $self->htmlBrowse( - items => $s->{cast}, - class => 'staffroles', - header => [ - [ 'Title' ], - [ 'Released' ], - [ 'Cast' ], - [ 'As' ], - [ 'Note' ], - ], - row => sub { - 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 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}; - end; - }, - ); -} - - sub list { my ($self, $char) = @_; |