summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-12 10:58:45 +0200
committerYorhel <git@yorhel.nl>2019-09-12 10:58:45 +0200
commitf6851137f4a6f1f9feba51ec5473e743d64a58b2 (patch)
treef9cddfc402ebdcf0befa5777fec5d276f590f7ed
parent08aab1b868280b295150734cdf3841d60b815f96 (diff)
VNDB::Types: Convert discussion_boards to %BOARD_TYPE
-rw-r--r--data/global.pl12
-rw-r--r--lib/VNDB/Handler/Discussions.pm48
-rw-r--r--lib/VNDB/Handler/Misc.pm2
-rw-r--r--lib/VNDB/Types.pm10
4 files changed, 35 insertions, 37 deletions
diff --git a/data/global.pl b/data/global.pl
index 2083c5a1..311789d0 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -48,18 +48,6 @@ our %S;
permissions => {qw| board 1 boardmod 2 edit 4 tag 16 dbmod 32 tagmod 64 usermod 128 |},
default_perm => 1+4+16, # Keep synchronised with the default value of users.perm
default_tags_cat=> 'cont,tech',
- # Some discussion board properties are hardcoded, e.g.:
- # - number of rows to show on /t
- # - whether it needs mod access
- # - whether it needs to be linked to a DB item.
- discussion_boards => ordhash(
- an => 'Announcements',
- db => 'VNDB discussions',
- ge => 'General discussions',
- v => 'Visual novels',
- p => 'Producers',
- u => 'Users',
- ),
board_edit_time => 7*24*3600,
age_ratings => [-1, 0, 6..18],
release_types => [qw|complete partial trial|],
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 48676bfc..93ef7f59 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -6,6 +6,7 @@ use warnings;
use TUWF ':html', 'xml_escape', 'uri_escape';
use POSIX 'ceil';
use VNDB::Func;
+use VNDB::Types;
use List::Util qw(first max);
@@ -51,7 +52,7 @@ sub thread {
ul;
for (sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$t->{boards}}) {
li;
- a href => "/t/$_->{type}", $self->{discussion_boards}{$_->{type}};
+ a href => "/t/$_->{type}", $BOARD_TYPE{$_->{type}}{txt};
if($_->{iid}) {
txt ' > ';
a style => 'font-weight: bold', href => "/t/$_->{type}$_->{iid}", "$_->{type}$_->{iid}";
@@ -215,14 +216,14 @@ sub edit {
for (split /[ ,]/, $frm->{boards}) {
my($ty, $id) = ($1, $2) if /^([a-z]{1,2})([0-9]*)$/;
push @boards, [ $ty, $id ] if !grep $_->[0].$_->[1] eq $ty.$id, @boards;
+ my $bt = $BOARD_TYPE{$ty};
push @{$frm->{_err}}, "Wrong board: $_" if
- !$ty || !$self->{discussion_boards}{$ty}
- || $ty eq 'an' && ($id || !$self->authCan('boardmod'))
- || $ty eq 'db' && $id
- || $ty eq 'ge' && $id
- || $ty eq 'v' && (!$id || !$self->dbVNGet(id => $id)->[0]{id})
- || $ty eq 'p' && (!$id || !$self->dbProducerGet(id => $id)->[0]{id})
- || $ty eq 'u' && (!$id || !$self->dbUserGet(uid => $id)->[0]{id});
+ !$ty || !$bt
+ || !$self->authCan($bt->{post_perm})
+ || !$bt->{dbitem} && $id || $bt->{dbitem} && !$id
+ || $ty eq 'v' && !$self->dbVNGet(id => $id)->[0]{id}
+ || $ty eq 'p' && !$self->dbProducerGet(id => $id)->[0]{id}
+ || $ty eq 'u' && !$self->dbUserGet(uid => $id)->[0]{id};
}
}
@@ -380,7 +381,7 @@ sub vote {
sub board {
my($self, $type, $iid) = @_;
$iid ||= '';
- return $self->resNotFound if $type =~ /(db|an|ge|all)/ && $iid;
+ return $self->resNotFound if ($type eq 'all' || !$BOARD_TYPE{$type}{dbitem}) && $iid;
my $f = $self->formValidate(
{ get => 'p', required => 0, default => 1, template => 'page' },
@@ -393,7 +394,7 @@ sub board {
$self->dbVNGet(id => $iid)->[0];
return $self->resNotFound if $iid && !$obj;
my $ititle = $obj && ($obj->{title}||$obj->{name}||$obj->{username});
- my $title = !$obj ? $self->{discussion_boards}{$type} || 'All boards' : "Related discussions for $ititle";
+ my $title = $obj ? "Related discussions for $ititle" : $type eq 'all' ? 'All boards' : $BOARD_TYPE{$type}{txt};
my($list, $np) = $self->dbThreadGet(
$type ne 'all' ? (type => $type) : (),
@@ -414,7 +415,7 @@ sub board {
p;
a href => '/t', 'Discussion board';
txt ' > ';
- a href => "/t/$type", $self->{discussion_boards}{$type}||'All boards';
+ a href => "/t/$type", $type eq 'all' ? 'All boards' : $BOARD_TYPE{$type}{txt};
if($iid) {
txt ' > ';
a style => 'font-weight: bold', href => "/t/$type$iid", "$type$iid";
@@ -434,8 +435,8 @@ sub board {
b 'No related threads found';
br; br;
a href => "/t/$type$iid/new", 'Why not create one yourself?';
- } else {
- a href => '/t/'.($iid ? $type.$iid : $type ne 'ge' ? 'db' : $type).'/new', 'Start a new thread' if $type ne 'all';
+ } elsif($type ne 'all' && $self->authCan($BOARD_TYPE{$type}{post_perm})) {
+ a href => '/t/'.($iid ? $type.$iid : $type).'/new', 'Start a new thread';
}
end;
end 'div';
@@ -460,23 +461,22 @@ sub index {
end 'fieldset';
p class => 'browseopts';
a href => '/t/all', 'All boards';
- a href => '/t/'.$_, $self->{discussion_boards}{$_}
- for (keys %{$self->{discussion_boards}});
+ a href => '/t/'.$_, $BOARD_TYPE{$_}{txt} for (keys %BOARD_TYPE);
end;
end;
end;
- for (keys %{$self->{discussion_boards}}) {
+ for (keys %BOARD_TYPE) {
my $list = $self->dbThreadGet(
type => $_,
- results => /^(db|v|ge)$/ ? 10 : 5,
+ results => $BOARD_TYPE{$_}{index_rows},
page => 1,
what => 'firstpost lastpost boardtitles',
sort => 'lastpost', reverse => 1,
asuser => $self->authInfo()->{id},
);
h1 class => 'boxtitle';
- a href => "/t/$_", $self->{discussion_boards}{$_};
+ a href => "/t/$_", $BOARD_TYPE{$_}{txt};
end;
_threadlist($self, $list, {p=>1}, 0, "/t", $_);
}
@@ -490,7 +490,7 @@ sub search {
my $frm = $self->formValidate(
{ get => 'bq', required => 0, maxlength => 100 },
- { get => 'b', required => 0, multi => 1, enum => [ keys %{$self->{discussion_boards}} ] },
+ { get => 'b', required => 0, multi => 1, enum => [ keys %BOARD_TYPE ] },
{ get => 't', required => 0 },
{ get => 'p', required => 0, default => 1, template => 'page' },
);
@@ -500,8 +500,8 @@ sub search {
$self->htmlForm({ frm => $frm, action => '/t/search', method => 'get', nosubmit => 1, noformcode => 1 }, 'boardsearch' => ['Search the discussion board',
[ input => short => 'bq', name => 'Query' ],
[ check => short => 't', name => 'Only search thread titles' ],
- [ select => short => 'b', name => 'Boards', multi => 1, size => scalar keys %{$self->{discussion_boards}},
- options => [ map [$_,$self->{discussion_boards}{$_}], keys %{$self->{discussion_boards}} ] ],
+ [ select => short => 'b', name => 'Boards', multi => 1, size => scalar keys %BOARD_TYPE,
+ options => [ map [$_,$BOARD_TYPE{$_}{txt}], keys %BOARD_TYPE ] ],
[ static => content => sub {
input type => 'submit', class => 'submit', tabindex => 10, value => 'Search!';
} ],
@@ -509,7 +509,7 @@ sub search {
return $self->htmlFooter if !$frm->{bq};
my %boards = map +($_,1), @{$frm->{b}};
- %boards = () if keys %boards == keys %{$self->{discussion_boards}};
+ %boards = () if keys %boards == keys %BOARD_TYPE;
my($l, $np);
if($frm->{t}) {
@@ -625,8 +625,8 @@ sub _threadlist {
last if $i++ > 4;
txt ', ' if $i > 2;
a href => "/t/$_->{type}".($_->{iid}||''),
- title => $_->{original}||$self->{discussion_boards}{$_->{type}},
- shorten $_->{title}||$self->{discussion_boards}{$_->{type}}, 30;
+ title => $_->{original}||$BOARD_TYPE{$_->{type}}{txt},
+ shorten $_->{title}||$BOARD_TYPE{$_->{type}}{txt}, 30;
}
txt ', ...' if @boards > 4;
end;
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 0e77408d..d1cba2a4 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -119,7 +119,7 @@ sub homepage {
my $posts = $self->dbThreadGet(what => 'lastpost boardtitles', results => 10, sort => 'lastpost', reverse => 1, notusers => 1);
ul;
for (@$posts) {
- my $boards = join ', ', map $self->{discussion_boards}{$_->{type}}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
+ my $boards = join ', ', map $BOARD_TYPE{$_->{type}}{txt}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
li;
txt fmtage($_->{ldate}).' ';
a href => "/t$_->{id}.$_->{count}", title => "Posted in $boards", shorten $_->{title}, 25;
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 981991e6..f101e68d 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -210,6 +210,16 @@ hash VNLIST_STATUS =>
4 => 'Dropped';
+# SQL: ENUM board_type
+hash BOARD_TYPE =>
+ an => { txt => 'Announcements', post_perm => 'boardmod', index_rows => 5, dbitem => 0 },
+ db => { txt => 'VNDB discussions', post_perm => 'board', index_rows => 10, dbitem => 0 },
+ ge => { txt => 'General discussions', post_perm => 'board', index_rows => 10, dbitem => 0 },
+ v => { txt => 'Visual novels', post_perm => 'board', index_rows => 10, dbitem => 1 },
+ p => { txt => 'Producers', post_perm => 'board', index_rows => 5, dbitem => 1 },
+ u => { txt => 'Users', post_perm => 'board', index_rows => 5, dbitem => 1 };
+
+
# SQL: ENUM blood_type
hash BLOOD_TYPE =>