summaryrefslogtreecommitdiff
path: root/lib/VNWeb
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-11-15 17:04:41 +0100
committerYorhel <git@yorhel.nl>2019-11-15 17:06:23 +0100
commit34a2d37a7bac141aab6b0c815a17ed75d4ef858e (patch)
tree87ec011c9281811019c441e92b66c7b009e70681 /lib/VNWeb
parent4580ee0776e4e8a32ec99dc0506625a6e061c854 (diff)
Move pubskin fetching responsibility to VNWeb::HTML::framework_
Requiring callers to fetch the right fields and pass it along to framework_() just seems brittle. This implementation requires an extra query but does make an effort to avoid fetching the skin and css when it's not needed.
Diffstat (limited to 'lib/VNWeb')
-rw-r--r--lib/VNWeb/Discussions/UPosts.pm4
-rw-r--r--lib/VNWeb/HTML.pm9
-rw-r--r--lib/VNWeb/Misc/History.pm4
-rw-r--r--lib/VNWeb/User/Page.pm4
4 files changed, 11 insertions, 10 deletions
diff --git a/lib/VNWeb/Discussions/UPosts.pm b/lib/VNWeb/Discussions/UPosts.pm
index 3d678505..733346ce 100644
--- a/lib/VNWeb/Discussions/UPosts.pm
+++ b/lib/VNWeb/Discussions/UPosts.pm
@@ -35,7 +35,7 @@ sub listing_ {
TUWF::get qr{/$RE{uid}/posts}, sub {
- my $u = tuwf->dbRowi('SELECT id, ', sql_user(), ', pubskin_can, pubskin_enabled, customcss, skin FROM users u WHERE id =', \tuwf->capture('id'));
+ my $u = tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \tuwf->capture('id'));
return tuwf->resNotFound if !$u->{id};
my $page = eval { tuwf->validate(get => p => { upage => 1 })->data } || 1;
@@ -55,7 +55,7 @@ TUWF::get qr{/$RE{uid}/posts}, sub {
my $own = auth && $u->{id} == auth->uid;
my $title = $own ? 'My posts' : 'Posts by '.user_displayname $u;
- framework_ title => $title, type => 'u', dbobj => $u, tab => 'posts', pubskin => $u,
+ framework_ title => $title, type => 'u', dbobj => $u, tab => 'posts',
sub {
div_ class => 'mainbox', sub {
h1_ $title;
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 2947041e..24989851 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -144,10 +144,12 @@ sub _head_ {
my $o = shift;
my $fancy = !(auth->pref('nodistract_can') && auth->pref('nodistract_nofancy'));
- my $pubskin = $fancy && $o->{pubskin}{pubskin_can} && $o->{pubskin}{pubskin_enabled};
- my $skin = tuwf->reqGet('skin') || ($pubskin ? $o->{pubskin}{skin} : auth->pref('skin')) || '';
+ my $pubskin = $fancy && $o->{type} && $o->{type} eq 'u' && $o->{dbobj} ? tuwf->dbRowi(
+ 'SELECT customcss, skin FROM users WHERE pubskin_can AND pubskin_enabled AND id =', \$o->{dbobj}{id}
+ ) : {};
+ my $skin = tuwf->reqGet('skin') || $pubskin->{skin} || auth->pref('skin') || '';
$skin = config->{skin_default} if !tuwf->{skins}{$skin};
- my $customcss = $pubskin ? $o->{pubskin}{customcss} : auth->pref('customcss');
+ my $customcss = $pubskin->{customcss} || auth->pref('customcss');
meta_ charset => 'utf-8';
title_ $o->{title}.' | vndb';
@@ -405,7 +407,6 @@ sub _hidden_msg_ {
# feeds => 1/0
# search => $query
# og => { opengraph metadata }
-# pubskin => { object with: pubskin_can, customcss, skin }
# type => Database entry type (used for the main tabs & hidden message)
# dbobj => Database entry object (used for the main tabs & hidden message)
# Recognized object fields: id, entry_hidden, entry_locked
diff --git a/lib/VNWeb/Misc/History.pm b/lib/VNWeb/Misc/History.pm
index 6c63e73d..d3caf4a9 100644
--- a/lib/VNWeb/Misc/History.pm
+++ b/lib/VNWeb/Misc/History.pm
@@ -176,7 +176,7 @@ TUWF::get qr{/(?:([upvrcsd])([1-9]\d*)/)?hist} => sub {
};
my $obj = !$type ? undef :
- $type eq 'u' ? tuwf->dbRowi('SELECT id, ', sql_user(), ', pubskin_can, pubskin_enabled, customcss, skin FROM users u WHERE id =', \$id) :
+ $type eq 'u' ? tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \$id) :
$type eq 'p' ? dbitem producers => 'name' :
$type eq 'v' ? dbitem vn => 'title' :
$type eq 'r' ? dbitem releases => 'title' :
@@ -188,7 +188,7 @@ TUWF::get qr{/(?:([upvrcsd])([1-9]\d*)/)?hist} => sub {
$obj->{title} = user_displayname $obj if $type eq 'u';
my $title = $type ? "Edit history of $obj->{title}" : 'Recent changes';
- framework_ title => $title, type => $type, dbobj => $obj, tab => 'hist', $type eq 'u' ? (pubskin => $obj) : (),
+ framework_ title => $title, type => $type, dbobj => $obj, tab => 'hist',
sub {
my $filt;
div_ class => 'mainbox', sub {
diff --git a/lib/VNWeb/User/Page.pm b/lib/VNWeb/User/Page.pm
index dbb4a086..654e3d90 100644
--- a/lib/VNWeb/User/Page.pm
+++ b/lib/VNWeb/User/Page.pm
@@ -125,7 +125,7 @@ sub _votestats_ {
TUWF::get qr{/$RE{uid}}, sub {
my $u = tuwf->dbRowi(q{
- SELECT id, hide_list, c_changes, c_votes, c_tags, pubskin_can, pubskin_enabled, skin, customcss
+ SELECT id, hide_list, c_changes, c_votes, c_tags
,}, sql_totime('registered'), q{ AS registered
,}, sql_user(), q{
FROM users u
@@ -143,7 +143,7 @@ TUWF::get qr{/$RE{uid}}, sub {
});
my $title = user_displayname($u)."'s profile";
- framework_ title => $title, type => 'u', pubskin => $u, dbobj => $u,
+ framework_ title => $title, type => 'u', dbobj => $u,
sub {
div_ class => 'mainbox userpage', sub {
h1_ $title;