data Entry = Entry { author :: String
, text :: String
} deriving (Show, Read)
main :: IO ()
main = runCGI (handleErrors hbbs)
hbbs :: CGI CGIResult
hbbs = do
let out = output . showHtml
efile <- liftIO (openFile "entries.dat" ReadWriteMode)
name <- getInput "name"
text <- getInput "text"
entries <- liftM read (liftIO (hGetLine efile))
case text of
Nothing -> out $ hbbstitle +++
hbbscontent entries +++
hbbsform +++
hbbsend
Just txt ->
do let n = take 20 $ fromMaybe "Anonymous" name
t = take 200 $ filter isAscii txt
es = take 10 $ entries
liftIO $ do hSeek efile AbsoluteSeek 0
hPutStrLn efile (show ((Entry n t):es))
hClose efile
out $ hbbssubmitted entries (fromMaybe "Anonymous" name) txt
hbbssubmitted es n t =
p (toHtml ("Saved!")) +++
p (toHtml ((address (toHtml "Click here to reload")) ! [src "Main.cgi"]))
hbbstitle =
(thetitle (toHtml "HBBS")) +++
h1 (toHtml "HBBS!!") +++
h2 (toHtml "Do you dare to post?!")