X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FWeb%2FForum.pm;h=1c1ecedc9b15ec1a10b131e20c07762e07d6d0a4;hb=9298f8363ced9fbe9cba01386629281150b96945;hp=8e194199413b726c261636baaaec04394c12d457;hpb=98378b594064426cdbc06b30a58553195d8cf8ec;p=ndwebbie.git diff --git a/ND/Web/Forum.pm b/ND/Web/Forum.pm index 8e19419..1c1eced 100644 --- a/ND/Web/Forum.pm +++ b/ND/Web/Forum.pm @@ -27,14 +27,13 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/viewForumThread addForumPost markThreadAsRead/; +our @EXPORT = qw/viewForumThread addForumPost addForumThread markThreadAsRead/; sub viewForumThread { my ($thread) = @_; my $template = HTML::Template->new(filename => "templates/viewthread.tmpl", global_vars => 1, cache => 1); - $template->param(Subject => $thread->{subject}); $template->param(Id => $thread->{id}); $template->param(Post => $thread->{post}); @@ -54,7 +53,12 @@ ORDER BY fp.time ASC $post->{message} = parseMarkup($post->{message}); push @posts,$post; } + + if (defined param('cmd') && param('cmd') eq 'Preview'){ + push @posts,{message => parseMarkup(escapeHTML(param('message'))), unread => 1, username => 'PREVIEW', Time => 'Not submitted yet', NewPosts => $old ? 1 : 0}; + } $template->param(Posts => \@posts); + $template->param(Message => param('message')); markThreadAsRead($thread->{id}); @@ -71,6 +75,21 @@ sub addForumPost { return 1; } +sub addForumThread { + my ($dbh,$board,$uid,$subject) = @_; + + my $insert = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject) VALUES($1,$2)}); + + if ($insert->execute($board->{id},escapeHTML($subject))){ + my $id = $dbh->last_insert_id(undef,undef,undef,undef,"forum_threads_ftid_seq"); + return $dbh->selectrow_hashref(q{SELECT ftid AS id, subject, $2::boolean AS post FROM forum_threads WHERE ftid = $1} + ,undef,$id,$board->{post}) + or $ND::ERROR .= p($dbh->errstr); + }else{ + $ND::ERROR .= p($dbh->errstr); + } +} + sub markThreadAsRead { my ($thread) = @_; my $rows = $ND::DBH->do(q{UPDATE forum_thread_visits SET time = now()