summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-08-26 13:31:03 +0200
committerYorhel <git@yorhel.nl>2019-08-26 13:31:36 +0200
commit27ff73213928994e7e1117293c4a751fe99b215b (patch)
tree23ef55a51d44c91eae6d6da83410ff5bac6e80e0 /lib
parentf4cbd0c722a92ce249a2a4a74bc153868553847c (diff)
Display shop+price info on VN pages + delete old affiliate code
The current affiliate links format doesn't display as much information as before but it's also a lot less messy.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Affiliates.pm73
-rw-r--r--lib/VNDB/DB/Releases.pm4
-rw-r--r--lib/VNDB/Handler/Affiliates.pm152
-rw-r--r--lib/VNDB/Handler/VNPage.pm36
-rw-r--r--lib/VNDB/Util/Misc.pm19
5 files changed, 23 insertions, 261 deletions
diff --git a/lib/VNDB/DB/Affiliates.pm b/lib/VNDB/DB/Affiliates.pm
deleted file mode 100644
index 94dfd198..00000000
--- a/lib/VNDB/DB/Affiliates.pm
+++ /dev/null
@@ -1,73 +0,0 @@
-
-package VNDB::DB::Affiliates;
-
-use strict;
-use warnings;
-use POSIX 'strftime';
-use Exporter 'import';
-
-our @EXPORT = qw|dbAffiliateGet dbAffiliateEdit dbAffiliateDel dbAffiliateAdd|;
-
-
-# options: id rids affiliate hidden sort reverse
-# what: release
-sub dbAffiliateGet {
- my($self, %o) = @_;
- $o{sort} ||= 'id';
- $o{reverse} //= 0;
-
- my %where = (
- $o{id} ? ('id = ?' => $o{id}) : (),
- $o{rids} ? ('rid IN(!l)' => [$o{rids}]) : (),
- defined($o{affiliate}) ? ('affiliate = ?' => $o{affiliate}) : (),
- defined($o{hidden}) ? ('!s af.hidden' => $o{hidden} ? '' : 'NOT') : (),
- );
-
- my $join = $o{what} ? 'JOIN releases r ON r.id = af.rid' : '';
- my $select = $o{what} ? ', r.title' : '';
-
- my $order = sprintf {
- id => 'af.id %s',
- rel => 'r.title %s',
- prio => 'af.priority %s',
- url => 'af.url %s',
- lastfetch => 'af.lastfetch %s',
- }->{$o{sort}}, $o{reverse} ? 'DESC' : 'ASC';
-
- return $self->dbAll(qq|
- SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version,
- extract('epoch' from af.lastfetch) as lastfetch, af.price, af.data$select
- FROM affiliate_links af
- $join
- !W
- ORDER BY !s|, \%where, $order);
-}
-
-
-sub dbAffiliateDel {
- my($self, $id) = @_;
- $self->dbExec('DELETE FROM affiliate_links WHERE id = ?', $id);
-}
-
-
-sub dbAffiliateEdit {
- my($self, $id, %ops) = @_;
- my %set;
- exists($ops{$_}) && ($set{"$_ = ?"} = $ops{$_}) for(qw|rid priority hidden affiliate url version price data|);
- $set{"lastfetch = TIMESTAMP WITH TIME ZONE 'epoch' + ? * INTERVAL '1 second'"} = $ops{lastfetch} || $ops{lastfetch} eq '0' ? $ops{lastfetch} : undef if exists $ops{lastfetch};
- return if !keys %set;
- $self->dbExec('UPDATE affiliate_links !H WHERE id = ?', \%set, $id);
-}
-
-
-sub dbAffiliateAdd {
- my($self, %ops) = @_;
- $self->dbExec(q|INSERT INTO affiliate_links (rid, priority, hidden, affiliate, url, version, price, data, lastfetch)
- VALUES(!l, TIMESTAMP WITH TIME ZONE 'epoch' + ? * INTERVAL '1 second')|,
- [@ops{qw| rid priority hidden affiliate url version price data|}],
- $ops{lastfetch} || $ops{lastfetch} eq '0' ? $ops{lastfetch} : undef);
-}
-
-
-1;
-
diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm
index b95ef4c4..3e93fccf 100644
--- a/lib/VNDB/DB/Releases.pm
+++ b/lib/VNDB/DB/Releases.pm
@@ -50,7 +50,7 @@ sub dbReleaseFilters {
# Options: id vid pid released page results what med sort reverse date_before date_after
# plat prod_inc prod_exc lang olang type minage search resolution freeware doujin voiced uncensored ani_story ani_ero hidden_only
-# What: extended vn producers platforms media affiliates
+# What: extended vn producers platforms media
# Sort: title released minage
sub dbReleaseGet {
my($self, %o) = @_;
@@ -118,7 +118,7 @@ sub dbReleaseGet {
# options: id, rev, what
-# what: extended vn producers platforms media affiliates
+# what: extended vn producers platforms media
sub dbReleaseGetRev {
my $self = shift;
my %o = (what => '', @_);
diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm
deleted file mode 100644
index efba6b18..00000000
--- a/lib/VNDB/Handler/Affiliates.pm
+++ /dev/null
@@ -1,152 +0,0 @@
-
-package VNDB::Handler::Affiliates;
-
-use strict;
-use warnings;
-use TUWF ':html';
-use VNDB::Func;
-
-
-TUWF::register(
- qr{affiliates} => \&list,
- qr{affiliates/del/([1-9]\d*)} => \&linkdel,
- qr{affiliates/edit/([1-9]\d*)} => \&edit,
- qr{affiliates/new} => \&edit,
-);
-
-
-sub list {
- my $self = shift;
-
- return $self->htmlDenied if !$self->authCan('affiliate');
- my $f = $self->formValidate(
- { get => 'a', required => 0, enum => [ 0..$#{$self->{affiliates}} ] },
- { get => 'h', required => 0, default => 0, enum => [ -1..1 ] },
- { get => 'o', required => 0, default => 'a', enum => ['a', 'd'] },
- { get => 's', required => 0, default => 'rel', enum => [qw|rel prio url lastfetch|] },
- );
- return $self->resNotFound if $f->{_err};
-
- $self->htmlHeader(title => 'Affiliate administration interface');
- div class => 'mainbox';
- h1 'Affiliate administration interface';
- p class => 'browseopts';
- a defined($f->{a}) && $f->{a} == $_ ? (class => 'optselected') : (), href => "/affiliates?a=$_", $self->{affiliates}[$_]{name}
- for (grep $self->{affiliates}[$_], 0..$#{$self->{affiliates}});
- end;
- if(defined $f->{a}) {
- p class => 'browseopts';
- a $f->{h} == -1 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=-1",'all';
- a $f->{h} == 1 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=1", 'hidden';
- a $f->{h} == 0 ? (class => 'optselected') : (), href => "/affiliates?a=$f->{a};h=0", 'non-hidden';
- end;
- }
- end;
-
- if(defined $f->{a}) {
- my $list = $self->dbAffiliateGet(
- affiliate => $f->{a}, hidden => $f->{h}==-1?undef:$f->{h},
- what => 'release',
- sort => $f->{s}, reverse => $f->{o} eq 'd'
- );
- $self->htmlBrowse(
- items => $list,
- nextpage => 0,
- options => {p=>0, %$f},
- pageurl => '',
- sorturl => "/affiliates?a=$f->{a};h=$f->{h}",
- header => [
- ['Release', 'rel'],
- ['Version'],
- ['Hid'],
- ['Prio', 'prio'],
- ['Price / Lastfetch', 'lastfetch'],
- ['', 'url' ]
- ],
- row => sub {
- my($s, $n, $l) = @_;
- Tr;
- td class => 'tc1'; a href => "/r$l->{rid}", shorten $l->{title}, 50; end;
- 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} ? fmtage($l->{lastfetch}) : '-';
- td class => 'tc6';
- a href => $l->{url}, 'link';
- txt ' | ';
- a href => "/affiliates/edit/$l->{id}", 'edit';
- txt ' | ';
- a href => "/affiliates/del/$l->{id}?formcode=".$self->authGetCode("/affiliates/del/$l->{id}"), 'del';
- end;
- end;
- },
- );
- }
- $self->htmlFooter;
-}
-
-
-sub linkdel {
- my($self, $id) = @_;
- return $self->htmlDenied if !$self->authCan('affiliate');
- return if !$self->authCheckCode;
- my $l = $self->dbAffiliateGet(id => $id)->[0];
- return $self->resNotFound if !$l;
- $self->dbAffiliateDel($id);
- $self->resRedirect("/affiliates?a=$l->{affiliate}");
-}
-
-
-sub edit {
- my($self, $id) = @_;
- return $self->htmlDenied if !$self->authCan('affiliate');
-
- my $r = $id && $self->dbAffiliateGet(id => $id)->[0];
- return $self->resNotFound if $id && !$r;
-
- my $frm;
- if($self->reqMethod eq 'POST') {
- return if !$self->authCheckCode;
- $frm = $self->formValidate(
- { post => 'rid', required => 1, template => 'id' },
- { post => 'priority', required => 0, default => 0, template => 'int' },
- { post => 'hidden', required => 0, default => 0, enum => [0,1] },
- { post => 'affiliate',required => 1, enum => [0..$#{$self->{affiliates}}] },
- { post => 'url', required => 1 },
- { post => 'version', required => 0, default => '' },
- { post => 'price', required => 0, default => '' },
- { post => 'lastfetch',required => 0, template => 'uint' },
- { post => 'data', required => 0, default => '' },
- );
- if(!$frm->{_err}) {
- $self->dbAffiliateEdit($id, %$frm) if $id;
- $self->dbAffiliateAdd(%$frm) if !$id;
- return $self->resRedirect("/affiliates?a=$frm->{affiliate}", 'post');
- }
- }
-
- if($id) {
- $frm->{$_} = $r->{$_} for(qw|rid priority hidden affiliate url version price lastfetch data|);
- } else {
- $frm->{rid} = $self->reqGet('rid');
- }
-
- $self->htmlHeader(title => 'Edit affiliate link');
- $self->htmlForm({ frm => $frm, action => $id ? "/affiliates/edit/$id" : '/affiliates/new' }, 'blah' => [ 'Edit affiliate link',
- [ input => short => 'rid', name => 'Release ID', width => 100 ],
- [ input => short => 'priority', name => 'Priority', width => 50 ],
- [ check => short => 'hidden', name => 'Hidden' ],
- [ select => short => 'affiliate', name => 'Affiliate', options => [ map
- [ $_, $self->{affiliates}[$_]{name} ], grep $self->{affiliates}[$_], 0..$#{$self->{affiliates}} ] ],
- [ input => short => 'url', name => 'URL', width => 400 ],
- [ input => short => 'version', name => 'Version', width => 400 ],
- [ input => short => 'price', name => 'Price' ],
- [ input => short => 'lastfetch', name => 'Lastfetch', post => ' UNIX timestamp' ],
- [ input => short => 'data', name => 'Data', width => 400 ],
- ]);
- $self->htmlFooter;
-}
-
-
-1;
-
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index d611d909..fed9f5a1 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -338,7 +338,7 @@ sub page {
)->[0];
return $self->resNotFound if !$v->{id};
- my $r = $self->dbReleaseGet(vid => $vid, what => 'extended producers platforms media', results => 200);
+ my $r = $self->dbReleaseGet(vid => $vid, what => 'extended links producers platforms media', results => 200);
my $metadata = {
'og:title' => $v->{title},
@@ -753,32 +753,21 @@ sub _useroptions {
sub _affiliate_links {
my($self, $r) = @_;
- return if !keys @$r;
- my %r = map +($_->{id}, $_), @$r;
- my $links = $self->dbAffiliateGet(rids => [ keys %r ], hidden => 0);
- return if !@$links;
- $links = [ sort { $b->{priority}||$self->{affiliates}[$b->{affiliate}]{default_prio} <=> $a->{priority}||$self->{affiliates}[$a->{affiliate}]{default_prio} } @$links ];
+ # url => [$title, $url, $price]
+ my %links = map +($_->[1],$_), grep $_->[2], map @{$self->entryLinks(r => $_)}, @$r;
+ return if !keys %links;
+ use utf8;
Tr id => 'buynow';
- td 'Available at';
+ td 'Shops';
td;
- for my $link (@$links) {
- my $f = $self->{affiliates}[$link->{affiliate}];
- my $rel = $r{$link->{rid}};
- my $plat = join(' and ', map $self->{platforms}{$_}, @{$rel->{platforms}});
- my $version = join(' and ', map $self->{languages}{$_}, @{$rel->{languages}}).' '.$plat.' version';
-
- a rel => 'nofollow', href => $f->{link_format} ? $f->{link_format}->($link->{url}) : $link->{url};
- use utf8;
- txt $link->{version}
- || ($f->{default_version} && $f->{default_version}->($self, $link, $rel))
- || $version;
- txt " at $f->{name}";
- abbr class => 'pricenote', title =>
- $link->{lastfetch} ? sprintf('Last updated: %s.', fmtage($link->{lastfetch})) : '', " for $link->{price}"
- if $link->{price};
- txt ' »';
+ for my $l (sort { $a->[0] cmp $b->[0] || $a->[2] cmp $b->[2] } values %links) {
+ b class => 'standout', '» ';
+ a href => $l->[1];
+ txt $l->[2];
+ b class => 'grayedout', " @ ";
+ txt $l->[0];
end;
br;
}
@@ -846,7 +835,6 @@ sub _releases {
}
end;
td class => 'tc6';
- a href => "/affiliates/new?rid=$rel->{id}", 'a' if $self->authCan('affiliate');
if($rel->{website}) {
a href => $rel->{website}, rel => 'nofollow';
cssicon 'external', 'External link';
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm
index c980ea7d..9c745024 100644
--- a/lib/VNDB/Util/Misc.pm
+++ b/lib/VNDB/Util/Misc.pm
@@ -161,15 +161,15 @@ sub bbSubstLinks {
}
-# Returns an arrayref of links, each link being [$title, $url]
+# Returns an arrayref of links, each link being [$title, $url, $price]
sub entryLinks {
my($self, $type, $obj) = @_;
my $w = $obj->{l_wikidata} ? $self->dbWikidata($obj->{l_wikidata}) : {};
my @links;
my $lnk = sub {
- my($v, $title, $url, $xform) = @_;
- push @links, map [ $title, sprintf $url, $xform ? $xform->($_) : $_ ], ref $v ? @$v : $v ? ($v) : ();
+ my($v, $title, $url, $xform, $price) = @_;
+ push @links, map [ $title, sprintf($url, $xform ? $xform->($_) : $_), $price ], ref $v ? @$v : $v ? ($v) : ();
};
$lnk->($obj->{l_site}, 'Official website', '%s'); # (staff) Homepage always comes first
@@ -197,22 +197,21 @@ sub entryLinks {
if($type eq 'r') {
$lnk->($obj->{l_steam}, 'Steam', 'https://store.steampowered.com/app/%d/');
$lnk->($obj->{l_steam}, 'SteamDB', 'https://steamdb.info/app/%d/info');
- $lnk->($obj->{l_dlsite}, 'DLsite (jpn)',sprintf $self->{dlsite_url}, $obj->{l_dlsite_shop}||'home');
- $lnk->($obj->{l_dlsiteen}, 'DLsite (eng)',sprintf $self->{dlsite_url}, $obj->{l_dlsiteen_shop}||'eng');
+ $lnk->($obj->{l_dlsite}, 'DLsite (jpn)',sprintf($self->{dlsite_url}, $obj->{l_dlsite_shop}||'home'), undef, $obj->{l_dlsite_price});
+ $lnk->($obj->{l_dlsiteen}, 'DLsite (eng)',sprintf($self->{dlsite_url}, $obj->{l_dlsiteen_shop}||'eng'), undef, $obj->{l_dlsiteen_price});
$lnk->($obj->{l_gog}, 'GOG', 'https://www.gog.com/game/%s');
$lnk->($obj->{l_itch}, 'Itch.io', 'https://%s');
- $lnk->($obj->{l_denpa}, 'Denpasoft', $self->{denpa_url});
- $lnk->($obj->{l_jlist}, 'J-List', $self->{jlist_url}) if !$obj->{l_jlist_jbox};
- $lnk->($obj->{l_jlist}, 'JBOX', $self->{jbox_url}) if $obj->{l_jlist_jbox};
+ $lnk->($obj->{l_denpa}, 'Denpasoft', $self->{denpa_url}, undef, $obj->{l_denpa_price});
+ $lnk->($obj->{l_jlist}, $obj->{l_jlist_jbox} ? 'JBOX' : 'J-List', $self->{ $obj->{l_jlist_jbox} ? 'jbox_url' : 'jlist_url' }, undef, $obj->{l_jlist_price});
$lnk->($obj->{l_jastusa}, 'JAST USA', 'https://jastusa.com/%s');
$lnk->($obj->{l_gyutto}, 'Gyutto', 'https://gyutto.com/i/item%d');
$lnk->($obj->{l_digiket}, 'Digiket', 'https://www.digiket.com/work/show/_data/ID=ITM%07d/');
$lnk->($obj->{l_melon}, 'Melonbooks', 'https://www.melonbooks.com/index.php?main_page=product_info&products_id=IT%010d');
- $lnk->($obj->{l_mg}, 'MangaGamer', !defined($obj->{l_mg_r18}) || $obj->{l_mg_r18} ? $self->{mg_r18_url} : $self->{mg_main_url});
+ $lnk->($obj->{l_mg}, 'MangaGamer', !defined($obj->{l_mg_r18}) || $obj->{l_mg_r18} ? $self->{mg_r18_url} : $self->{mg_main_url}, undef, $obj->{l_mg_price});
$lnk->($obj->{l_getchu}, 'Getchu', 'http://www.getchu.com/soft.phtml?id=%d');
$lnk->($obj->{l_getchudl}, 'DL.Getchu', 'http://dl.getchu.com/i/item%d');
$lnk->($obj->{l_dmm}, 'DMM', 'https://%s');
- push @links, map [ 'PlayAsia', $_->{url} ], @{$obj->{l_playasia}} if $obj->{l_playasia};
+ push @links, map [ 'PlayAsia', $_->{url}, $_->{price} ], @{$obj->{l_playasia}} if $obj->{l_playasia};
}
# Staff links