#!/usr/bin/perl -Tw ############################################################ ## Written and copyright 2002 by ## Jacqueline D. Hamilton (kira@cgi101.com) ## ## This code is excerpted from "CGI Programming 201" ## (http://www.cgi101.com/advanced) ## ## You may use this code on your own website, however ## you may not publish or sell any copy or derivative work ## without permission of the author. ############################################################# use strict; use lib '.'; use MyBoard; my ($msgid, $sth, $rv, $count, $msg, $resp); # untaint the query string if ($ENV{QUERY_STRING} =~ /^(\d+)$/) { $msgid = $1; } else { &dienice("$ENV{QUERY_STRING} isn't a valid message number."); } $sth = $dbh->prepare("select *, date_format(date, '%W, %M %e, %Y') as nicedate, date_format(date, '%l:%i %p') as nicetime from messages where (messages.id=? or thread_id=?) order by thread_id, date") or &dbdie; $rv = $sth->execute($msgid, $msgid); if ($rv < 1) { &dienice("Message $msgid does not exist."); } $msg = $sth->fetchrow_hashref; # if the FIRST message is a follow-up, redirect them to the entire # page for that message thread. if ($msg->{thread_id} != 0) { print $cgi->redirect("$url/message.cgi?$msg->{thread_id}#$msg->{id}"); exit; } &do_header("$btitle: $msg->{nicedate}: $msg->{subject}"); print qq(

$btitle: $msg->{nicedate}: $msg->{subject}

\n); &showpost($msg); $resp = 0; while ($msg = $sth->fetchrow_hashref) { if ($resp == 0) { print qq(

Comments

\n); $resp = 1; } &showpost($msg); } &do_footer; sub showpost { my($hdr); my($msg) = @_; # smiliefy is optional... print &smiliefy($msg->{message}), qq(

\n); my($author) = &linkify($msg->{author}, $msg->{email}); print qq(Msg #$msg->{id} | Posted by $author on $msg->{nicedate} $msg->{nicetime}

\n); # only allow follow-ups to the original message if ($msg->{thread_id} == 0) { print qq(Post a Comment

\n); } print qq(


\n); }