]> ruin.nu Git - ndwebbie.git/blobdiff - ND/Web/Pages/Forum.pm
forum class
[ndwebbie.git] / ND / Web / Pages / Forum.pm
index 17ef00b5ce20fe76c7edd30e0edbe0d9ce3ea1bd..76a7e62438611ff9990735d4d304f79e0eaaf8f5 100644 (file)
@@ -25,23 +25,22 @@ use CGI qw/:standard/;
 use ND::Web::Include;
 use ND::Include;
 
-$ND::PAGES{forum} = {parse => \&parse, process => \&process, render=> \&render};
+use base qw/ND::Web::XMLPage/;
+
+$ND::Web::Page::PAGES{forum} = __PACKAGE__;
 
 sub parse {
-       my ($uri) = @_;
-       if ($uri =~ m{^/.*/allUnread}){
+       my $self = shift;
+       if ($self->{URI} =~ m{^/.*/allUnread}){
                param('allUnread',1);
        }
 }
 
-sub process {
-
-}
-
-sub render {
-       my ($DBH,$BODY) = @_;
-
-       $ND::TEMPLATE->param(TITLE => 'Forum');
+sub render_body {
+       my $self = shift;
+       my ($BODY) = @_;
+       $self->{TITLE} = 'Forum';
+       my $DBH = $self->{DBH};
 
        $DBH->do(q{UPDATE users SET last_forum_visit = NOW() WHERE uid = $1},undef,$ND::UID) or $ND::ERROR .= p($DBH->errstr);
 
@@ -82,12 +81,12 @@ sub render {
        }
 
        if (defined param('cmd')){
-               if(param('cmd') eq 'Submit'){
+               if(param('cmd') eq 'Submit' or param('cmd') eq 'Preview'){
                        $DBH->begin_work;
                        if ($board && $board->{post}){
                                $thread = addForumThread $DBH,$board,$ND::UID,param('subject');
                        }
-                       if ($thread && $thread->{post}){
+                       if (param('cmd') eq 'Submit' and $thread && $thread->{post}){
                                addForumPost($DBH,$thread,$ND::UID,param('message'));
                        }
                        $DBH->commit or $ND::ERROR .= p($DBH->errstr);
@@ -129,7 +128,10 @@ sub render {
                GROUP BY fb.fbid,fb.board
                ORDER BY fb.fbid
                        });
-       my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,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, ft.sticky
+       my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,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_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
                WHERE ft.fbid = $1
                GROUP BY ft.ftid, ft.subject,ft.sticky