{-# LANGUAGE FlexibleContexts, TypeFamilies, QuasiQuotes #-} {-# OPTIONS_GHC -F -pgmFtrhsx #-} module Pages.Board where import ConfigT import Control.Applicative import Control.Applicative.Error import Control.Monad import Control.Monad.Trans import Data.Function import Data.Text (Text) import qualified Data.Text as Text import Data.Time import Data.Acid hiding (update, query) import Data.Maybe (fromMaybe, mapMaybe) import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy.Char8 as C import Data.List import Happstack.Data.IxSet ((@=)) import qualified Happstack.Data.IxSet as IxSet import Happstack.Server import Happstack.Server.HSP.HTML import HSP import qualified HSX.XMLGenerator as HSX import HSX.JMacro import Language.Javascript.JMacro import Pages.AppTemplate import Pages.FormPart import Server import State import System.Locale import Text.Digestive import Text.Digestive.HSP.Html4 import Types import URL import Web.Routes boardPage :: WebURL -> BoardName -> (Maybe Int) -> Server Response boardPage here boardName mPage = do res <- query (GetThreads (fromMaybe 0 mPage) boardName) env <- askRqEnv liftIO $ print env case res of (Left e) -> error (show e) (Right (threads, maxPageNum)) -> do let media = mapMaybe medium (concatMap posts threads) script <- genOnReady media toResponse <$> (unXMLGenT $ boardTemplate here mPage (Right (boardName, maxPageNum)) (Text.unpack (unBoardName boardName)) script <% mapM threadHTML threads %>) boardTemplate :: ( EmbedAsChild Server headers , EmbedAsChild Server body ) => WebURL -> Maybe Int -> (Either ThreadId (BoardName, Int)) -> String -- ^ title -> headers -- ^ extra tags to include in \
-> body -- ^ contents to put inside \ -> XMLGenT Server XML boardTemplate here mPage postType title headers body = do config <- askConfig login <- case role config of User -> do loginURL <- showURL (W_Login here) login Moderator -> do moderatorURL <- showURL W_Moderator moderator Admin -> do adminURL <- showURL W_Admin admin hereURL <- showURL here bds <- query AskBoards appTemplate title headersGoto page:
The thread you are trying to reply to does not exist.
(Right post) -> do seeOtherURL here validateNewThread :: Config -> Bool -> Transformer (XMLGenT Server) String (Text, Maybe Password, Text, Maybe (FilePath, FilePath), String) (Maybe Text, Maybe Password, Maybe Text, Maybe Medium, Text) validateNewThread config replyMode = transformEitherM $ \(name, tripCode, subject, mFile, msg) -> case (null msg, replyMode, mFile) of (True, True, _) -> return $ Left "You must supply a comment to respond to a thread." (True, False, _) -> return $ Left "You must supply and image and a comment to start a new thread." (False, False, Nothing) -> return $ Left "You must supply and image and a comment to start a new thread." (False, _, Just (origName, tmpFile)) | origName == "" && (not replyMode) -> return $ Left "You must supply and image and a comment to start a new thread." | origName == "" && replyMode -> do return $ Right $ (maybeText name, tripCode, maybeText subject, Nothing, Text.pack msg) | otherwise -> do medium <- saveImage (acid config) (storageDir config) origName tmpFile return $ Right $ (maybeText name, tripCode, maybeText subject, Just medium, Text.pack msg) where maybeText :: Text -> Maybe Text maybeText t = if Text.null t then Nothing else (Just t) threadHTML :: (XMLGenerator m, ShowURL m, URL m ~ WebURL, EmbedAsChild m ()) => Thread -> XMLGenT m (HSX.XML m) threadHTML thread = do replyURL <- showURL (W_Reply (threadId thread))Odd. This thread does not contain any posts.
(h:t) ->[ Reply ]
<% maybe "Anonymous" Text.unpack (poster post) %> <% maybe "" Text.unpack (subject post) %> <% formatTime defaultTimeLocale rfc822DateFormat (posted post) %> No.<% show $ unPostId $ postId post %>
<% case medium post of Nothing -> <% () %> (Just medium) -> <%<% Text.unpack (msg post) %>