summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-30 15:43:05 +0100
committerYorhel <git@yorhel.nl>2019-10-30 15:43:08 +0100
commit60452526c1c68d55dbde2ded27235dce7649b03a (patch)
treec827a59c4a87484b99e932669caecf23a9b50c8d
parent8a1a72e7a5edd08a69cc7743b228fa402a7c66c7 (diff)
v2rw: Convert /u+/posts
Simple conversion, no real changes other than that the new version has full pagination.
-rw-r--r--lib/VNDB/Handler/Users.pm69
-rw-r--r--lib/VNWeb/Discussions/UPosts.pm72
2 files changed, 72 insertions, 69 deletions
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
deleted file mode 100644
index a9c53206..00000000
--- a/lib/VNDB/Handler/Users.pm
+++ /dev/null
@@ -1,69 +0,0 @@
-
-package VNDB::Handler::Users;
-
-use strict;
-use warnings;
-use TUWF ':html';
-use VNDB::Func;
-
-
-TUWF::register(
- qr{u([1-9]\d*)/posts} => \&posts,
-);
-
-
-sub posts {
- my($self, $uid) = @_;
-
- # fetch user info
- my $u = $self->dbUserGet(uid => $uid, what => 'hide_list pubskin')->[0];
- return $self->resNotFound if !$u->{id};
-
- my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'page' }
- );
- return $self->resNotFound if $f->{_err};
-
- my($posts, $np) = $self->dbPostGet(uid => $uid, hide => 1, what => 'thread', page => $f->{p}, sort => 'date', reverse => 1);
-
- my $title = 'Posts made by '.VNWeb::HTML::user_displayname($u);
- $self->htmlHeader(title => $title, noindex => 1, pubskin => $u);
- $self->htmlMainTabs(u => $u, 'posts');
- div class => 'mainbox';
- h1 $title;
- if(!@$posts) {
- p VNWeb::HTML::user_displayname($u)." hasn't made any posts yet.";
- }
- end;
-
- $self->htmlBrowse(
- items => $posts,
- class => 'uposts',
- options => $f,
- nextpage => $np,
- pageurl => "/u$uid/posts",
- header => [
- [ '' ],
- [ '' ],
- [ 'Date' ],
- [ 'Title' ],
- ],
- row => sub {
- my($s, $n, $l) = @_;
- Tr;
- td class => 'tc1'; a href => "/t$l->{tid}.$l->{num}", 't'.$l->{tid}; end;
- td class => 'tc2'; a href => "/t$l->{tid}.$l->{num}", '.'.$l->{num}; end;
- td class => 'tc3', fmtdate $l->{date};
- td class => 'tc4';
- a href => "/t$l->{tid}.$l->{num}", $l->{title};
- b class => 'grayedout'; lit bb2html $l->{msg}, 150; end;
- end;
- end;
- },
- ) if @$posts;
- $self->htmlFooter;
-}
-
-
-1;
-
diff --git a/lib/VNWeb/Discussions/UPosts.pm b/lib/VNWeb/Discussions/UPosts.pm
new file mode 100644
index 00000000..3d678505
--- /dev/null
+++ b/lib/VNWeb/Discussions/UPosts.pm
@@ -0,0 +1,72 @@
+package VNWeb::Discussions::UPosts;
+
+use VNWeb::Prelude;
+
+
+sub listing_ {
+ my($count, $list, $page) = @_;
+
+ my sub url { '?'.query_encode @_ }
+
+ paginate_ \&url, $page, [ $count, 50 ], 't';
+ div_ class => 'mainbox browse uposts', sub {
+ table_ class => 'stripe', sub {
+ thead_ sub { tr_ sub {
+ td_ class => 'tc1', sub { debug_ $list };
+ td_ class => 'tc2', '';
+ td_ class => 'tc3', 'Date';
+ td_ class => 'tc4', 'Title';
+ }};
+ tr_ sub {
+ my $url = "/t$_->{tid}.$_->{num}";
+ td_ class => 'tc1', sub { a_ href => $url, 't'.$_->{tid} };
+ td_ class => 'tc2', sub { a_ href => $url, '.'.$_->{num} };
+ td_ class => 'tc3', fmtdate $_->{date};
+ td_ class => 'tc4', sub {
+ a_ href => $url, $_->{title};
+ b_ class => 'grayedout', sub { lit_ bb2html $_->{msg}, 150 };
+ };
+ } for @$list;
+ }
+ };
+
+ paginate_ \&url, $page, [ $count, 50 ], 'b';
+}
+
+
+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'));
+ return tuwf->resNotFound if !$u->{id};
+
+ my $page = eval { tuwf->validate(get => p => { upage => 1 })->data } || 1;
+
+ my $from_and_where = sql
+ 'FROM threads_posts tp
+ JOIN threads t ON t.id = tp.tid
+ WHERE NOT t.private AND NOT t.hidden AND NOT tp.hidden AND tp.uid =', \$u->{id};
+
+ my $count = tuwf->dbVali('SELECT count(*)', $from_and_where);
+ my($list) = $count ? tuwf->dbPagei(
+ { results => 50, page => $page },
+ 'SELECT tp.tid, tp.num, substring(tp.msg from 1 for 1000) as msg, t.title
+ , ', sql_totime('tp.date'), 'as date',
+ $from_and_where, 'ORDER BY tp.date DESC'
+ ) : ();
+
+ 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,
+ sub {
+ div_ class => 'mainbox', sub {
+ h1_ $title;
+ if(!$count) {
+ p_ +($own ? 'You have' : user_displayname($u).' has').' not posted anything on the forums yet.';
+ }
+ };
+
+ listing_ $count, $list, $page if $count;
+ };
+};
+
+
+1;