X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=NDWeb%2FPages%2FForum.pm;h=0e1e2cb7c3327875a2064f590b6fe659fe74d4bc;hb=ffcc68db8809345dbf6104b04560d724280f226c;hp=55cbe9615481a4ca5ffe35c84ba6fb47e80bd5c7;hpb=d6c9085e748c4d61901aaea72f0e1546dcc7cdda;p=ndwebbie.git diff --git a/NDWeb/Pages/Forum.pm b/NDWeb/Pages/Forum.pm index 55cbe96..0e1e2cb 100644 --- a/NDWeb/Pages/Forum.pm +++ b/NDWeb/Pages/Forum.pm @@ -17,22 +17,25 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * #**************************************************************************/ -package ND::Web::Pages::Forum; +package NDWeb::Pages::Forum; use strict; use warnings; -use ND::Web::Forum; +use NDWeb::Forum; use CGI qw/:standard/; -use ND::Web::Include; +use NDWeb::Include; use ND::Include; -use base qw/ND::Web::XMLPage/; +use base qw/NDWeb::XMLPage/; -$ND::Web::Page::PAGES{forum} = __PACKAGE__; +$NDWeb::Page::PAGES{forum} = __PACKAGE__; sub parse { my $self = shift; if ($self->{URI} =~ m{^/.*/allUnread}){ - param('allUnread',1); + $self->{allUnread} = 1; + }elsif ($self->{URI} =~ m{^/.*/search(?:/(.*))?}){ + bless $self, 'NDWeb::Pages::Forum::Search'; + $self->{PAGE} = 'forum/search'; } } @@ -155,34 +158,50 @@ sub render_body { ,undef,$thread->{fcid}) or $ND::ERROR .= p($DBH->errstr); $BODY->param(Category => $category); - }elsif(defined param('allUnread')){ #List threads in this board + }elsif(defined $self->{allUnread}){ #List threads in this board $BODY->param(AllUnread => 1); - $BODY->param(Id => $board->{id}); + + my $threads = $DBH->prepare(q{SELECT fcid,category,fbid,board,ft.ftid AS id,u.username,ft.subject, + count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, + date_trunc('seconds',max(fp.time)::timestamp) as last_post, + min(fp.time)::date as posting_date, ft.sticky + FROM forum_categories fc + JOIN forum_boards fb USING (fcid) + JOIN forum_threads ft USING (fbid) + JOIN forum_posts fp USING (ftid) + JOIN users u ON u.uid = ft.uid + LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid + WHERE fbid > 0 AND + fb.fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1))) + GROUP BY fcid,category,fbid,board,ft.ftid, ft.subject,ft.sticky,u.username + HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= 1 + ORDER BY fcid,fbid,sticky DESC,last_post DESC}); + my ($time) = $DBH->selectrow_array('SELECT now()::timestamp',undef); $BODY->param(Date => $time); - $categories->execute or $ND::ERROR .= p($DBH->errstr); + $threads->execute($ND::UID) or $ND::ERROR .= p($DBH->errstr); my @categories; - while (my $category = $categories->fetchrow_hashref){ - $boards->execute($category->{id},$ND::UID) or $ND::ERROR .= p($DBH->errstr); - my @boards; - while (my $board = $boards->fetchrow_hashref){ - next if $board->{id} < 0; - $threads->execute($board->{id},$ND::UID,1) or $ND::ERROR .= p($DBH->errstr); - my $i = 0; - my @threads; - while (my $thread = $threads->fetchrow_hashref){ - $i++; - $thread->{Odd} = $i % 2; - push @threads,$thread; - } - $board->{Threads} = \@threads; - delete $board->{post}; - push @boards,$board if $i > 0; + my $category = {fcid => 0}; + my $board = {fbid => 0}; + while (my $thread = $threads->fetchrow_hashref){ + if ($category->{fcid} != $thread->{fcid}){ + delete $category->{fcid}; + $category = {fcid => $thread->{fcid}, category => $thread->{category}}; + push @categories,$category; } - $category->{Boards} = \@boards; - delete $category->{id}; - push @categories,$category if @boards; + if ($board->{fbid} != $thread->{fbid}){ + delete $board->{fbid}; + $board = {fbid => $thread->{fbid}, board => $thread->{board}}; + push @{$category->{Boards}},$board; + } + delete $thread->{fcid}; + delete $thread->{fbid}; + delete $thread->{category}; + delete $thread->{board}; + push @{$board->{Threads}},$thread; } + delete $category->{fcid}; + delete $board->{fbid}; $BODY->param(Categories => \@categories); }elsif($board){ #List threads in this board @@ -196,11 +215,8 @@ sub render_body { my ($time) = $DBH->selectrow_array('SELECT now()::timestamp',undef); $BODY->param(Date => $time); $threads->execute($board->{id},$ND::UID,0) or $ND::ERROR .= p($DBH->errstr); - my $i = 0; my @threads; while (my $thread = $threads->fetchrow_hashref){ - $i++; - $thread->{Odd} = $i % 2; push @threads,$thread; } $BODY->param(Threads => \@threads); @@ -226,31 +242,34 @@ sub render_body { my ($category) = $DBH->selectrow_array(q{SELECT category FROM forum_categories WHERE fcid = $1} ,undef,$board->{fcid}) or $ND::ERROR .= p($DBH->errstr); $BODY->param(Category => $category); - - }elsif($self->{URI} =~ m{^/.*/search/(.*)}){ #List threads in this board }else{ #List boards $BODY->param(Overview => 1); - $categories->execute or $ND::ERROR .= p($DBH->errstr); - my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board,count(NULLIF(COALESCE(fp.fpid::boolean,FALSE) AND COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,date_trunc('seconds',max(fp.time)::timestamp) as last_post - FROM forum_boards fb LEFT OUTER JOIN (forum_threads ft JOIN forum_posts fp USING (ftid)) ON fb.fbid = ft.fbid LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid - WHERE fb.fcid = $1 AND - fb.fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($2))) - GROUP BY fb.fbid, fb.board - ORDER BY fb.fbid }); + my $boards = $DBH->prepare(q{SELECT fcid,category,fb.fbid AS id,fb.board + ,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread + ,date_trunc('seconds',max(fp.time)::timestamp) as last_post + FROM forum_categories + JOIN forum_boards fb USING (fcid) + JOIN forum_threads ft USING (fbid) + JOIN forum_posts fp USING (ftid) + LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv USING (ftid) + WHERE EXISTS (SELECT fbid FROM forum_access WHERE fbid = fb.fbid AND gid IN (SELECT groups($1))) + GROUP BY fcid,category,fb.fbid, fb.board + ORDER BY fcid,fb.fbid + }); + $boards->execute($ND::UID) or warn $DBH->errstr; my @categories; - while (my $category = $categories->fetchrow_hashref){ - $boards->execute($category->{id},$ND::UID) or $ND::ERROR .= p($DBH->errstr); - my @boards; - my $i = 0; - while (my $board = $boards->fetchrow_hashref){ - $i++; - $board->{Odd} = $i % 2; - push @boards,$board; + my $category = {fcid => 0}; + while (my $board = $boards->fetchrow_hashref){ + if ($category->{fcid} != $board->{fcid}){ + delete $category->{fcid}; + $category = {fcid => $board->{fcid}, category => $board->{category}}; + push @categories,$category; } - $category->{Boards} = \@boards; - delete $category->{id}; - push @categories,$category if $i > 0; + delete $board->{fcid}; + delete $board->{category}; + push @{$category->{Boards}},$board; } + delete $category->{fcid}; $BODY->param(Categories => \@categories); }