summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-07 14:54:46 +0200
committerYorhel <git@yorhel.nl>2009-07-07 15:25:26 +0200
commit5d6f09f838392f1e2c072f44f904b5f9eab95f45 (patch)
treecb95e3d444dc47b01d6c66d9501d6f7b6ac3284d
parentc281835ad2b538c6e1afbd3a4bffe440c011b51c (diff)
Posts browser on user pages (/u+/posts)
-rw-r--r--ChangeLog1
-rw-r--r--data/style.css17
-rw-r--r--lib/VNDB/DB/Discussions.pm32
-rw-r--r--lib/VNDB/Handler/Discussions.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm61
-rw-r--r--lib/VNDB/Util/CommonHTML.pm6
6 files changed, 111 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index c4ef01fb..4ccddca8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
- Automatically fill out title & original title when adding a release
- Separated VN search filters from search box
- Tag filers on VN search
+ - Posts browser on user pages
2.4 - 2009-06-07
- Release search + browser + filters
diff --git a/data/style.css b/data/style.css
index 755f8c01..dec6462b 100644
--- a/data/style.css
+++ b/data/style.css
@@ -472,7 +472,7 @@ div.mainbox.history td.tc1_2 {
}
div.mainbox.history td.tc2 { width: 65px; }
div.mainbox.history td.tc3 { width: 90px }
-div.mainbox.history tr.editsum td {
+tr.editsum td {
color: $grayedout$;
padding-top: 0;
text-align: right;
@@ -998,6 +998,21 @@ ul#catselect li li.exc { background-position: 0px -33px; color: $statnok$; }
}
+/***** User posts browser ****/
+div.browse.uposts td.tc1 {
+ padding-left: 0!important;
+ padding-right: 0;
+ text-align: right;
+ width: 60px;
+ *width: auto; /* IE7 sucks */
+}
+.uposts td.tc2 {
+ padding-left: 0;
+ width: 25px;
+}
+.uposts td.tc3 { width: 65px; }
+
+
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 78a462df..58cc5f61 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -153,25 +153,45 @@ sub dbThreadCount {
}
-# Options: tid, num, what, page, results
+# Options: tid, num, what, order, uid, hide, page, results
+# what: user thread
sub dbPostGet {
my($self, %o) = @_;
$o{results} ||= 50;
$o{page} ||= 1;
+ $o{what} ||= '';
+ $o{order} ||= 'tp.num ASC';
my %where = (
- 'tp.tid = ?' => $o{tid},
+ $o{tid} ? (
+ 'tp.tid = ?' => $o{tid} ) : (),
$o{num} ? (
'tp.num = ?' => $o{num} ) : (),
+ $o{uid} ? (
+ 'tp.uid = ?' => $o{uid} ) : (),
+ $o{hide} ? (
+ 'tp.hidden = FALSE' => 1 ) : (),
+ $o{hide} && $o{what} =~ /thread/ ? (
+ 't.hidden = FALSE' => 1 ) : (),
+ );
+
+ my @select = (
+ qw|tp.num tp.date tp.edited tp.msg tp.hidden|,
+ $o{what} =~ /user/ ? qw|tp.uid u.username| : (),
+ $o{what} =~ /thread/ ? (qw|tp.tid t.title|, 't.hidden AS thread_hidden') : (),
+ );
+ my @join = (
+ $o{what} =~ /user/ ? 'JOIN users u ON u.id = tp.uid' : (),
+ $o{what} =~ /thread/ ? 'JOIN threads t ON t.id = tp.tid' : (),
);
my($r, $np) = $self->dbPage(\%o, q|
- SELECT tp.num, tp.date, tp.edited, tp.msg, tp.hidden, tp.uid, u.username
+ SELECT !s
FROM threads_posts tp
- JOIN users u ON u.id = tp.uid
+ !s
!W
- ORDER BY tp.num ASC|,
- \%where,
+ ORDER BY !s|,
+ join(', ', @select), join(' ', @join), \%where, $o{order}
);
return wantarray ? ($r, $np) : $r;
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 45a2e24e..eff8212e 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -26,7 +26,7 @@ sub thread {
my $t = $self->dbThreadGet(id => $tid, what => 'boardtitles')->[0];
return 404 if !$t->{id} || $t->{hidden} && !$self->authCan('boardmod');
- my $p = $self->dbPostGet(tid => $tid, results => 25, page => $page);
+ my $p = $self->dbPostGet(tid => $tid, results => 25, page => $page, what => 'user');
return 404 if !$p->[0];
$self->htmlHeader(title => $t->{title});
@@ -142,7 +142,7 @@ sub edit {
my $t = $tid && $self->dbThreadGet(id => $tid, what => 'boards')->[0];
return 404 if $tid && !$t->{id};
- my $p = $num && $self->dbPostGet(tid => $tid, num => $num)->[0];
+ my $p = $num && $self->dbPostGet(tid => $tid, num => $num, what => 'user')->[0];
return 404 if $num && !$p->{num};
# are we allowed to perform this action?
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 895a6fbe..deaf19e1 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -16,6 +16,7 @@ YAWF::register(
qr{u/newpass/sent} => \&newpass_sent,
qr{u/register} => \&register,
qr{u([1-9]\d*)/edit} => \&edit,
+ qr{u([1-9]\d*)/posts} => \&posts,
qr{u([1-9]\d*)/del(/[od])?} => \&delete,
qr{u/(all|[0a-z])} => \&list,
);
@@ -101,9 +102,14 @@ sub userpage {
Tr ++$i % 2 ? (class => 'odd') : ();
td 'Forum stats';
- td sprintf '%d post%s, %d new thread%s',
+ td;
+ txt sprintf '%d post%s, %d new thread%s. ',
$u->{postcount}, $u->{postcount} != 1 ? 's' : '',
$u->{threadcount}, $u->{threadcount} != 1 ? 's' : '';
+ if($u->{postcount}) {
+ a href => "/u$uid/posts"; lit 'Browse posts &raquo;'; end;
+ }
+ end;
end;
end;
end;
@@ -380,6 +386,59 @@ sub edit {
}
+sub posts {
+ my($self, $uid) = @_;
+
+ # fetch user info (cached if uid == loggedin uid)
+ my $u = $self->authInfo->{id} && $self->authInfo->{id} == $uid ? $self->authInfo : $self->dbUserGet(uid => $uid)->[0];
+ return 404 if !$u->{id};
+
+ my $f = $self->formValidate(
+ { name => 'p', required => 0, default => 1, template => 'int' }
+ );
+
+ my($posts, $np) = $self->dbPostGet(uid => $uid, hide => 1, what => 'thread', page => $f->{p}, order => 'tp.date DESC');
+
+ $self->htmlHeader(title => "Posts made by $u->{username}");
+ $self->htmlMainTabs(u => $u, 'posts');
+ div class => 'mainbox';
+ h1 "Posts made by $u->{username}";
+ if(!@$posts) {
+ p "\u$u->{username} hasn't made any posts yet.";
+ }
+ end;
+
+ $self->htmlBrowse(
+ items => $posts,
+ class => 'uposts',
+ options => $f,
+ nextpage => $np,
+ pageurl => "/u$uid/posts",
+ header => [
+ [ '' ],
+ [ '' ],
+ [ 'Date' ],
+ sub { td; a href => '#', id => 'history_comments', 'expand'; txt 'Title'; end; }
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ 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', date $l->{date};
+ td class => 'tc4'; a href => "/t$l->{tid}.$l->{num}", $l->{title}; end;
+ end;
+ Tr class => $n % 2 ? 'editsum odd hidden' : 'editsum hidden';
+ td colspan => 4;
+ lit bb2html $l->{msg}, 150;
+ end;
+ end;
+ },
+ ) if @$posts;
+ $self->htmlFooter;
+}
+
+
sub delete {
my($self, $uid, $act) = @_;
return $self->htmlDenied if !$self->authCan('usermod');
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 646c052a..a6aa1dd3 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -48,10 +48,16 @@ sub htmlMainTabs {
li $sel eq 'list' ? (class => 'tabselected') : ();
a href => "/$id/list", 'list';
end;
+ }
+ if($type eq 'u') {
li $sel eq 'tags' ? (class => 'tabselected') : ();
a href => "/$id/tags", 'tags';
end;
+
+ li $sel eq 'posts' ? (class => 'tabselected') : ();
+ a href => "/$id/posts", 'posts';
+ end;
}
if($type eq 'v' && $self->authCan('tag') && !$obj->{hidden}) {