summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--data/global.pl14
-rw-r--r--lib/VNDB/DB/Affiliates.pm54
-rw-r--r--lib/VNDB/Handler/Affiliates.pm123
-rw-r--r--lib/VNDB/Handler/VNPage.pm3
-rw-r--r--util/updates/update_2.20.sql1
6 files changed, 188 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index c099205d..734689ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
2.20 - ?
+ - Added support for sponsored links on VN pages
- Order the VNs listed on char browser by release date
- Order the traits groups on /i by their 'order' column
- Use same browsing-table on trait pages and char browser
diff --git a/data/global.pl b/data/global.pl
index 5fd2bf85..c985b8ea 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -32,13 +32,13 @@ our %S = (%S,
ch_size => [ 256, 300 ], # max. w*h of char images
cv_size => [ 256, 400 ], # max. w*h of cover images
user_ranks => [
- # allowed actions # DB number
- [qw| hist |], # 0
- [qw| hist |], # 1
- [qw| hist board |], # 2
- [qw| hist board edit tag |], # 3
- [qw| hist board boardmod edit charedit tag mod lock del tagmod |], # 4
- [qw| hist board boardmod edit charedit tag mod lock del tagmod usermod |], # 5
+ # allowed actions # DB number
+ [qw| hist |], # 0
+ [qw| hist |], # 1
+ [qw| hist board |], # 2
+ [qw| hist board edit tag |], # 3
+ [qw| hist board boardmod edit charedit tag mod lock del tagmod |], # 4
+ [qw| hist board boardmod edit charedit tag mod lock del tagmod usermod affiliate |], # 5
],
languages => [qw|cs da de en es fi fr hu it ja ko nl no pl pt-br pt-pt ru sk sv tr vi zh|],
producer_types => [qw|co in ng|],
diff --git a/lib/VNDB/DB/Affiliates.pm b/lib/VNDB/DB/Affiliates.pm
new file mode 100644
index 00000000..2aa891ce
--- /dev/null
+++ b/lib/VNDB/DB/Affiliates.pm
@@ -0,0 +1,54 @@
+
+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 hide_hidden
+# what: release
+sub dbAffiliateGet {
+ my($self, %o) = @_;
+
+ my %where = (
+ $o{id} ? ('id = ?' => $o{id}) : (),
+ $o{rids} ? ('rid IN(!l)' => [$o{rids}]) : (),
+ defined($o{affiliate}) ? ('affiliate = ?' => $o{affiliate}) : (),
+ $o{hide_hidden} ? ('NOT hidden' => 1) : (),
+ );
+
+ my $join = $o{what} ? 'JOIN releases r ON r.id = af.rid JOIN releases_rev rr ON rr.id = r.latest' : '';
+ my $select = $o{what} ? ', rr.title' : '';
+
+ return $self->dbAll("SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version, extract('epoch' from af.lastfetch) as lastfetch, af.price$select
+ FROM affiliate_links af $join !W", \%where);
+}
+
+
+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|);
+ return if !keys %set;
+ $self->dbExec('UPDATE affiliate_links !H WHERE id = ?', \%set, $id);
+}
+
+sub dbAffiliateAdd {
+ my($self, %ops) = @_;
+ $self->dbExec('INSERT INTO affiliate_links (rid, priority, hidden, affiliate, url, version) VALUES(!l)',
+ [@ops{qw| rid priority hidden affiliate url version|}]);
+}
+
+
+1;
+
diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm
new file mode 100644
index 00000000..36435ade
--- /dev/null
+++ b/lib/VNDB/Handler/Affiliates.pm
@@ -0,0 +1,123 @@
+
+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*)} => \&del,
+ 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}} ] }
+ );
+ 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 (0..$#{$self->{affiliates}});
+ end;
+ end;
+
+ if(defined $f->{a}) {
+ my $list = $self->dbAffiliateGet(affiliate => $f->{a}, what => 'release');
+ $self->htmlBrowse(
+ items => $list,
+ nextpage => 0,
+ options => {p=>0},
+ pageurl => '',
+ header => [ ['Release'], ['Version'], ['Hid'], ['Prio'], ['URL'], ['Price'], [''] ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ 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'; a href => $l->{url}, $l->{url}; end;
+ td class => 'tc6', sprintf '%s / %s', $l->{price}, $l->{lastfetch} ? $self->{l10n}->age($l->{lastfetch}) : '-';
+ td class => 'tc7';
+ 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 del {
+ 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 => 'int' },
+ { 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 => '' },
+ );
+ 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|);
+ } 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} ], 0..$#{$self->{affiliates}} ] ],
+ [ input => short => 'url', name => 'URL', width => 400 ],
+ [ input => short => 'version', name => 'Version', width => 400 ],
+ ]);
+ $self->htmlFooter;
+}
+
+
+1;
+
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index ff079675..0c9a6754 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -412,7 +412,7 @@ sub _affiliate_links {
my $links = $self->dbAffiliateGet(rids => [ keys %r ]);
return if !@$links;
- $links = [ sort { $b->{priority} <=> $a->{priority} } @$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; td colspan => 2, id => 'buynow'; # don't call it "affiliate", most adblock filters have that included >_>
@@ -489,6 +489,7 @@ 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 'ext', mt '_vnpage_rel_extlink';
diff --git a/util/updates/update_2.20.sql b/util/updates/update_2.20.sql
index 9ee38b07..51b9252b 100644
--- a/util/updates/update_2.20.sql
+++ b/util/updates/update_2.20.sql
@@ -41,3 +41,4 @@ CREATE INDEX affiliate_links_rid ON affiliate_links (rid) WHERE NOT hidden;
--INSERT INTO affiliate_links (rid, priority, affiliate, url, version, lastfetch, price) VALUES
-- (175, 1, 0, 'http://www.jbox.com/product/PCG4776', 'Original all-ages edition (Japanese)', NOW(), '$110.00'),
-- (8124, 0, 0, 'http://www.jbox.com/product/PSPLB001', 'Converted edition (PSP, Japanese)', NOW(), '$78.00');
+