X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FWeb%2FForum.pm;h=ca2195e352f3d7bd313af97f8b95dabd70ac5809;hb=c7030fde80686d05805d02f3586ec23224e4c6e5;hp=1c1ecedc9b15ec1a10b131e20c07762e07d6d0a4;hpb=b8985d0163efd6e9af29dcca7a7689183286c7e7;p=ndwebbie.git diff --git a/ND/Web/Forum.pm b/ND/Web/Forum.pm index 1c1eced..ca2195e 100644 --- a/ND/Web/Forum.pm +++ b/ND/Web/Forum.pm @@ -25,8 +25,7 @@ use HTML::Template; use ND::Web::Include; require Exporter; -our @ISA = qw/Exporter/; - +our @ISA = qw/Exporter/; our @EXPORT = qw/viewForumThread addForumPost addForumThread markThreadAsRead/; sub viewForumThread { @@ -37,8 +36,8 @@ sub viewForumThread { $template->param(Id => $thread->{id}); $template->param(Post => $thread->{post}); - my $posts = $ND::DBH->prepare(q{SELECT u.username,date_trunc('minute',fp.time::timestamp) AS time,fp.message,COALESCE(fp.time > ftv.time,TRUE) AS unread -FROM forum_threads ft JOIN forum_posts fp USING (ftid) JOIN users u USING (uid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid + my $posts = $ND::DBH->prepare(q{SELECT u.username,date_trunc('seconds',fp.time::timestamp) AS time,fp.message,COALESCE(fp.time > ftv.time,TRUE) AS unread +FROM forum_threads ft JOIN forum_posts fp USING (ftid) JOIN users u ON u.uid = fp.uid LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid WHERE ft.ftid = $1 ORDER BY fp.time ASC }); @@ -55,10 +54,16 @@ ORDER BY fp.time ASC } 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}; + my $text = parseMarkup(escapeHTML(param('message'))); + $text .= p b $@ if $@; + push @posts,{message => $text, unread => 1, username => 'PREVIEW', Time => 'Not submitted yet', NewPosts => $old ? 1 : 0}; + + $text = escapeHTML param('message'); + $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block + $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g; + $template->param(Message => $text); } $template->param(Posts => \@posts); - $template->param(Message => param('message')); markThreadAsRead($thread->{id}); @@ -78,9 +83,9 @@ sub addForumPost { sub addForumThread { my ($dbh,$board,$uid,$subject) = @_; - my $insert = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject) VALUES($1,$2)}); + my $insert = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject,uid) VALUES($1,$2,$3)}); - if ($insert->execute($board->{id},escapeHTML($subject))){ + if ($insert->execute($board->{id},escapeHTML($subject),$uid)){ 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})