summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-11-19 11:28:00 +0100
committerYorhel <git@yorhel.nl>2019-11-19 11:28:25 +0100
commitbd2ff24a35ec70aad52ae5352ce349da53ee5248 (patch)
tree227250da094256c5e18345cd0ed2a449d17136d3 /lib
parent3328d1e39868e14bd42cc341c05fdd8bd2868288 (diff)
v2rw: Convert discussion board listings + change link structure a bit
A board-wide "tab"-like structure rather than breadcrumbs, has a more consistent feeling.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/Discussions.pm121
-rw-r--r--lib/VNWeb/Discussions/Board.pm52
-rw-r--r--lib/VNWeb/Discussions/Index.pm10
-rw-r--r--lib/VNWeb/Discussions/Lib.pm32
-rw-r--r--lib/VNWeb/Discussions/Search.pm1
5 files changed, 84 insertions, 132 deletions
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index ac4bd190..8e9baeb0 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -14,7 +14,6 @@ TUWF::register(
qr{t([1-9]\d*)(?:/([1-9]\d*))?} => \&thread,
qr{t([1-9]\d*)(/[1-9]\d*)?/vote} => \&vote,
qr{t([1-9]\d*)\.([1-9]\d*)} => \&redirect,
- qr{t/(all|db|an|ge|[vpu])([1-9]\d*)?} => \&board,
qr{t([1-9]\d*)/reply} => \&edit,
qr{t([1-9]\d*)\.([1-9]\d*)/edit} => \&edit,
qr{t/(db|an|ge|[vpu])([1-9]\d*)?/new} => \&edit,
@@ -378,126 +377,6 @@ sub vote {
}
-sub board {
- my($self, $type, $iid) = @_;
- $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' },
- );
- return $self->resNotFound if $f->{_err};
-
- my $obj = !$iid ? undef :
- $type eq 'u' ? $self->dbUserGet(uid => $iid, what => 'hide_list')->[0] :
- $type eq 'p' ? $self->dbProducerGet(id => $iid)->[0] :
- $self->dbVNGet(id => $iid)->[0];
- return $self->resNotFound if $iid && !$obj;
- my $ititle = $obj && ($obj->{title}||$obj->{name}||VNWeb::HTML::user_displayname($obj));
- 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) : (),
- $iid ? (iid => $iid) : (),
- results => 50,
- page => $f->{p},
- what => 'firstpost lastpost boardtitles',
- sort => $type eq 'an' ? 'id' : 'lastpost', reverse => 1,
- asuser => $self->authInfo()->{id},
- );
-
- $self->htmlHeader(title => $title, noindex => 1, feeds => [ $type eq 'an' ? 'announcements' : 'posts' ], type => $type, dbobj => $obj);
-
- $self->htmlMainTabs($type, $obj, 'disc') if $iid;
- form action => '/t/search', method => 'get';
- div class => 'mainbox';
- h1 $title;
- p;
- a href => '/t', 'Discussion board';
- txt ' > ';
- 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";
- txt ':';
- a href => "/$type$iid", $ititle;
- }
- end;
- if(!$iid) {
- fieldset class => 'search';
- input type => 'text', name => 'bq', id => 'bq', class => 'text';
- input type => 'hidden', name => 'b', value => $type if $type ne 'all';
- input type => 'submit', class => 'submit', value => 'Search!';
- end 'fieldset';
- }
- p class => 'center';
- if(!@$list) {
- b 'No related threads found';
- br; br;
- a href => "/t/$type$iid/new", 'Why not create one yourself?';
- } 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';
- end 'form';
-
- _threadlist($self, $list, $f, $np, "/t/$type$iid", $type.$iid) if @$list;
-
- $self->htmlFooter;
-}
-
-
-sub _threadlist {
- my($self, $list, $f, $np, $url, $board) = @_;
- $self->htmlBrowse(
- items => $list,
- options => $f,
- nextpage => $np,
- pageurl => $url,
- class => 'discussions',
- header => [
- [ 'Topic' ],
- [ 'Replies' ],
- [ 'Starter' ],
- [ 'Last post' ],
- ],
- row => sub {
- my($self, $n, $o) = @_;
- Tr;
- td class => 'tc1';
- a $o->{locked} ? ( class => 'locked' ) : (), href => "/t$o->{id}";
- span class => 'pollflag', '[poll]' if $o->{haspoll};
- txt shorten $o->{title}, 50;
- end;
- b class => 'boards';
- my $i = 1;
- my @boards = sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } grep $_->{type}.($_->{iid}||'') ne $board, @{$o->{boards}};
- for(@boards) {
- last if $i++ > 4;
- txt ', ' if $i > 2;
- a href => "/t/$_->{type}".($_->{iid}||''),
- title => $_->{original}||$BOARD_TYPE{$_->{type}}{txt},
- shorten $_->{title}||$BOARD_TYPE{$_->{type}}{txt}, 30;
- }
- txt ', ...' if @boards > 4;
- end;
- end;
- td class => 'tc2', $o->{count}-1;
- td class => 'tc3';
- VNWeb::HTML::user_($o, 'firstpost_');
- end;
- td class => 'tc4';
- VNWeb::HTML::user_($o, 'lastpost_');
- lit ' @ ';
- a href => "/t$o->{id}.$o->{count}", fmtdate $o->{lastpost_date}, 'full';
- end;
- end 'tr';
- }
- );
-}
-
-
sub _poll {
my($self, $t, $url) = @_;
my($num_votes, $stats, $own_votes) = $self->dbPollStats($t->{id});
diff --git a/lib/VNWeb/Discussions/Board.pm b/lib/VNWeb/Discussions/Board.pm
new file mode 100644
index 00000000..80207ed7
--- /dev/null
+++ b/lib/VNWeb/Discussions/Board.pm
@@ -0,0 +1,52 @@
+package VNWeb::Discussions::Board;
+
+use VNWeb::Prelude;
+use VNWeb::Discussions::Lib;
+
+my $board_regex = join '|', map $_.($BOARD_TYPE{$_}{dbitem}?'(?:[1-9][0-9]{0,5})?':''), keys %BOARD_TYPE;
+
+TUWF::get qr{/t/(all|$board_regex)}, sub {
+ my($type, $id) = tuwf->capture(1) =~ /^([^0-9]+)([0-9]*)$/;
+
+ my $page = eval { tuwf->validate(get => p => { upage => 1 })->data } || 1;
+
+ my $obj = !$id ? undef :
+ $type eq 'v' ? tuwf->dbRowi('SELECT id, title, original, hidden AS entry_hidden, locked AS entry_locked FROM vn WHERE id =', \$id) :
+ $type eq 'p' ? tuwf->dbRowi('SELECT id, name, original, hidden AS entry_hidden, locked AS entry_locked FROM producers WHERE id =', \$id) :
+ $type eq 'u' ? tuwf->dbRowi('SELECT id,', sql_user(), 'FROM users u WHERE id =', \$id) : undef;
+ return tuwf->resNotFound if $id && !$obj->{id};
+
+ my $ititle = $obj && ($obj->{title} || $obj->{name} || user_displayname $obj);
+ my $title = $obj ? "Related discussions for $ititle" : $type eq 'all' ? 'All boards' : $BOARD_TYPE{$type}{txt};
+ my $createurl = '/t/'.($id ? $type.$id : $type eq 'db' ? 'db' : 'ge').'/new';
+
+ framework_ title => $title, type => $type, dbobj => $obj, tab => 'disc',
+ sub {
+ div_ class => 'mainbox', sub {
+ h1_ $title;
+ boardtypes_ $type;
+ boardsearch_ $type if !$id;
+ p_ class => 'center', sub {
+ a_ href => $createurl, 'Start a new thread';
+ } if auth->permBoard;
+ };
+
+ threadlist_
+ where => $type ne 'all' && sql('t.id IN(SELECT tid FROM threads_boards WHERE type =', \$type, $id ? ('AND iid =', \$id) : (), ')'),
+ boards => $type ne 'all' && sql('NOT (tb.type =', \$type, 'AND tb.iid =', \($id||0), ')'),
+ results => 50,
+ sort => $type eq 'an' ? 't.id DESC' : undef,
+ page => $page,
+ paginate => sub { "?p=$_" }
+ or div_ class => 'mainbox', sub {
+ h1_ 'An empty board';
+ p_ class => 'center', sub {
+ txt_ "Nobody's started a discussion on this board yet. Why not ";
+ a_ href => $createurl, 'create a new thread';
+ txt_ ' yourself?';
+ }
+ }
+ };
+};
+
+1;
diff --git a/lib/VNWeb/Discussions/Index.pm b/lib/VNWeb/Discussions/Index.pm
index d178c579..565cbc49 100644
--- a/lib/VNWeb/Discussions/Index.pm
+++ b/lib/VNWeb/Discussions/Index.pm
@@ -9,14 +9,8 @@ TUWF::get qr{/t}, sub {
form_ method => 'get', action => '/t/search', sub {
div_ class => 'mainbox', sub {
h1_ 'Discussion board index';
- fieldset_ class => 'search', sub {
- input_ type => 'text', name => 'bq', id => 'bq', class => 'text';
- input_ type => 'submit', class => 'submit', value => 'Search!';
- };
- p_ class => 'browseopts', sub {
- a_ href => '/t/all', 'All boards';
- a_ href => '/t/'.$_, $BOARD_TYPE{$_}{txt} for (keys %BOARD_TYPE);
- };
+ boardtypes_ 'index';
+ boardsearch_;
}
};
diff --git a/lib/VNWeb/Discussions/Lib.pm b/lib/VNWeb/Discussions/Lib.pm
index 63fb80d8..f2439f97 100644
--- a/lib/VNWeb/Discussions/Lib.pm
+++ b/lib/VNWeb/Discussions/Lib.pm
@@ -3,7 +3,7 @@ package VNWeb::Discussions::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/threadlist_/;
+our @EXPORT = qw/threadlist_ boardsearch_ boardtypes_/;
# Generate a thread list table, options:
@@ -12,6 +12,7 @@ our @EXPORT = qw/threadlist_/;
# results => Number of threads to display.
# page => Current page number.
# paginate => sub {} reference that generates a url for paginate_(); pagination is disabled when not set.
+# sort => SQL (default: tl.date DESC)
#
# Returns 1 if something was displayed, 0 if no threads matched the where clause.
sub threadlist_ {
@@ -36,8 +37,8 @@ sub threadlist_ {
JOIN users tfu ON tfu.id = tf.uid
JOIN users tlu ON tlu.id = tl.uid
WHERE }, $where, q{
- ORDER BY tl.date DESC
- });
+ ORDER BY}, $opt{sort}||'tl.date DESC'
+ );
return 0 if !@$lst;
enrich boards => id => tid => sub { sql q{
@@ -92,4 +93,29 @@ sub threadlist_ {
1;
}
+
+sub boardsearch_ {
+ my($type) = @_;
+ form_ action => '/t/search', sub {
+ fieldset_ class => 'search', sub {
+ input_ type => 'text', name => 'bq', id => 'bq', class => 'text';
+ input_ type => 'hidden', name => 'b', value => $type if $type && $type ne 'all';
+ input_ type => 'submit', class => 'submit', value => 'Search!';
+ }
+ }
+}
+
+
+sub boardtypes_ {
+ my($type) = @_;
+ p_ class => 'browseopts', sub {
+ a_ href => '/t/'.$_->[0], mkclass(optselected => $type && $type eq $_->[0]), $_->[1] for (
+ [ index => 'Index' ],
+ [ all => 'All boards' ],
+ map [ $_, $BOARD_TYPE{$_}{txt} ], keys %BOARD_TYPE
+ );
+ };
+}
+
+
1;
diff --git a/lib/VNWeb/Discussions/Search.pm b/lib/VNWeb/Discussions/Search.pm
index 6d21380a..511267b0 100644
--- a/lib/VNWeb/Discussions/Search.pm
+++ b/lib/VNWeb/Discussions/Search.pm
@@ -15,6 +15,7 @@ sub filters_ {
my %boards = map +($_,1), $filt->{b}->@*;
form_ method => 'get', action => tuwf->reqPath(), sub {
+ boardtypes_;
table_ style => 'margin: 0 auto', sub { tr_ sub {
td_ style => 'padding: 10px', sub {
p_ class => 'linkradio', sub {