diff options
-rw-r--r-- | data/script.js | 15 | ||||
-rw-r--r-- | data/style.css | 9 | ||||
-rw-r--r-- | lib/VNDB/DB/Releases.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 30 | ||||
-rw-r--r-- | util/sql/schema.sql | 15 | ||||
-rw-r--r-- | util/updates/update_2.20.sql | 19 |
6 files changed, 89 insertions, 1 deletions
diff --git a/data/script.js b/data/script.js index c2ede03c..a9e79aa1 100644 --- a/data/script.js +++ b/data/script.js @@ -2763,6 +2763,21 @@ if(byId('charspoil_sel')) { } +// mouse-over price information / disclaimer +if(byId('buynow')) { + var l = byClass(byId('buynow'), 'acronym', 'pricenote'); + for(var i=0; i<l.length; i++) { + l[i].buynow_last = l[i].title; + l[i].title = null; + ddInit(l[i], 'bottom', function(acr) { + return tag('p', {onmouseover:ddHide, style:'padding: 3px'}, + acr.buynow_last, tag('br', null), '* The displayed price only serves as an indication, actual price may differ.' + ); + }); + } +} + + // set note input box (/u+/list) if(byId('not') && byId('vns')) byId('vns').onchange = function () { diff --git a/data/style.css b/data/style.css index bc99fbcc..c9af8eb7 100644 --- a/data/style.css +++ b/data/style.css @@ -338,6 +338,15 @@ div.vndetails table dd { margin-left: 90px; } div.vndetails td.relations dt { float: none; font-style: normal; } div.vndetails td.relations dd { margin-left: 15px; } div.vndetails td.anime b { font-size: 8px; font-weight: normal; padding-right: 4px; } + +td#buynow h1 { display: block; width: 100px; background: #bf9228; font-size: 13px; text-align: center; margin: -3px 0 0 0 } +td#buynow h1 a { display: block; width: 100%; color: #fff; border: none; padding: 2px; font-weight: bold } +td#buynow ul { background: #ffe095; width: 100%; margin: 0; border: 1px solid #bf9228 } +td#buynow li { list-style-type: none; margin: 0 } +td#buynow li a { display: block; width: 100%; color: #000; border: none } +td#buynow li a:hover { background: #ffebba } +td#buynow .pricenote { border: 0 } + div#vntags { margin: 15px 30px 0 30px; border-top: 1px solid $border$; padding: 1px 5% 0 5%; text-align: center; } #vntags span { white-space: nowrap; margin-left: 15px; } #vntags b { color: $grayedout$; font-weight: normal; font-size: 8px } diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm index bd2d5bd3..6f9465f8 100644 --- a/lib/VNDB/DB/Releases.pm +++ b/lib/VNDB/DB/Releases.pm @@ -12,7 +12,7 @@ our @EXPORT = qw|dbReleaseGet dbReleaseRevisionInsert|; # Options: id vid pid rev released page results what med sort reverse date_before date_after # plat lang olang type minage search resolution freeware doujin voiced ani_story ani_ero -# What: extended changes vn producers platforms media +# What: extended changes vn producers platforms media affiliates # Sort: title released minage sub dbReleaseGet { my($self, %o) = @_; diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 37efb04a..ff079675 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -141,6 +141,7 @@ sub page { _relations($self, \$i, $v) if @{$v->{relations}}; _anime($self, \$i, $v) if @{$v->{anime}}; _useroptions($self, \$i, $v) if $self->authInfo->{id}; + _affiliate_links($self, $r); Tr; td class => 'vndesc', colspan => 2; @@ -404,6 +405,35 @@ sub _useroptions { } +sub _affiliate_links { + my($self, $r) = @_; + return if !keys @$r; + my %r = map +($_->{id}, $_), @$r; + my $links = $self->dbAffiliateGet(rids => [ keys %r ]); + return if !@$links; + + $links = [ sort { $b->{priority} <=> $a->{priority} } @$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 >_> + h1; a href => $links->[0]{url}, 'Buy now!'; end; + ul; + for my $link (@$links) { + li; a href => $link->{url}; + use utf8; + txt '→ '; + txt $link->{version} || join(', ', map $en->maketext("_lang_$_"), @{$r{$link->{rid}}{languages}}).' version'; + txt ' '; + acronym class => 'pricenote', title => sprintf('Last updated: %s.', $en->age($link->{lastfetch})), "for $link->{price}*" + if $link->{price}; + txt " at $self->{affiliates}[$link->{affiliate}]{name}."; + end; end; + } + end; + end; end; +} + + sub _releases { my($self, $v, $r) = @_; diff --git a/util/sql/schema.sql b/util/sql/schema.sql index 39e9351a..d780bec8 100644 --- a/util/sql/schema.sql +++ b/util/sql/schema.sql @@ -1,5 +1,18 @@ +-- affiliate_links +CREATE TABLE affiliate_links ( + id SERIAL PRIMARY KEY, + rid integer NOT NULL, + hidden boolean NOT NULL DEFAULT false, + priority smallint NOT NULL DEFAULT 0, + affiliate smallint NOT NULL DEFAULT 0, + url varchar NOT NULL, + version varchar NOT NULL DEFAULT '', + lastfetch timestamptz, + price varchar NOT NULL DEFAULT '' +); + -- anime CREATE TABLE anime ( id integer NOT NULL PRIMARY KEY, @@ -452,6 +465,7 @@ CREATE TABLE wlists ( +ALTER TABLE affiliate_links ADD FOREIGN KEY (rid) REFERENCES releases (id); ALTER TABLE changes ADD FOREIGN KEY (requester) REFERENCES users (id) ON DELETE SET DEFAULT; ALTER TABLE chars ADD FOREIGN KEY (latest) REFERENCES chars_rev (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE chars_rev ADD FOREIGN KEY (id) REFERENCES changes (id); @@ -521,6 +535,7 @@ ALTER TABLE wlists ADD FOREIGN KEY (uid) REFERENCES users ALTER TABLE wlists ADD FOREIGN KEY (vid) REFERENCES vn (id); +CREATE INDEX affiliate_links_rid ON affiliate_links (rid) WHERE NOT hidden; CREATE INDEX releases_vn_vid ON releases_vn (vid); CREATE INDEX tags_vn_date ON tags_vn (date); CREATE UNIQUE INDEX chars_vns_pkey ON chars_vns (cid, vid, COALESCE(rid, 0)); diff --git a/util/updates/update_2.20.sql b/util/updates/update_2.20.sql index 28efd713..9ee38b07 100644 --- a/util/updates/update_2.20.sql +++ b/util/updates/update_2.20.sql @@ -22,3 +22,22 @@ CREATE TRIGGER stats_cache_edit AFTER UPDATE ON tags CREATE TRIGGER stats_cache_new AFTER INSERT ON traits FOR EACH ROW WHEN (NEW.state = 2) EXECUTE PROCEDURE update_stats_cache(); CREATE TRIGGER stats_cache_edit AFTER UPDATE ON traits FOR EACH ROW WHEN (OLD.state IS DISTINCT FROM NEW.state) EXECUTE PROCEDURE update_stats_cache(); + + +CREATE TABLE affiliate_links ( + id SERIAL PRIMARY KEY, + rid integer NOT NULL REFERENCES releases (id), + hidden boolean NOT NULL DEFAULT false, -- to hide a link for some reason + priority smallint NOT NULL DEFAULT 0, -- manual ordering when competing on a VN page, usually not necessary + affiliate smallint NOT NULL DEFAULT 0, -- index to a semi-static array in data/config.pl + url varchar NOT NULL, + version varchar NOT NULL DEFAULT '', -- "x edition" or "x version", default used is "<language> version" + lastfetch timestamptz, -- last update of price + price varchar NOT NULL DEFAULT '' -- formatted, including currency, e.g. "$50" or "€34.95 / $50.46" +); + +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'); |