diff options
Diffstat (limited to 'haunt/jakob/dynamic/capabilities/comment-form.scm')
| -rw-r--r-- | haunt/jakob/dynamic/capabilities/comment-form.scm | 95 |
1 files changed, 61 insertions, 34 deletions
diff --git a/haunt/jakob/dynamic/capabilities/comment-form.scm b/haunt/jakob/dynamic/capabilities/comment-form.scm index 29e00ec..23d669d 100644 --- a/haunt/jakob/dynamic/capabilities/comment-form.scm +++ b/haunt/jakob/dynamic/capabilities/comment-form.scm @@ -29,47 +29,76 @@ #:use-module (web request) #:use-module (web response) #:use-module (web uri) - #:export (render-comment-form + #:export (render-static-comment-form + render-dynamic-comment-form render-comment-form-success render-comment-form-failure get-comment-form)) -(define* (render-comment-form slug #:key (header-level 'h1) (captcha-id "") captcha-image) +(define (render-commenter-info-field) + `(fieldset (@ (id "commenter-info")) + (legend "Commenter Info") + (label (@ (for "name")) "Name:") + (input (@ (type "text") (id "name") (name "name") (required #t) (size 24))) + (label (@ (for "email")) "Email (optional, used for Gravatar):") + (input (@ (type "text") (id "email") (name "email") (size 24))) + (label (@ (for "url")) "Webpage URL (optional):") + (input (@ (type "text") (id "url") (name "url") (size 24))))) + +(define (render-comment-content-field) + `(fieldset (@ (id "comment-content")) + (legend "Comment") + (label (@ (for "subject")) "Subject (optional):") + (input (@ (type "text") (id "subject") (name "subject") (size 24))) + (label (@ (for "comment")) "Comment :") + (textarea (@ (id "coment") (name "comment") (rows 4) (cols 50))))) + +(define* (render-comment-captcha-field #:optional (captcha-id "") captcha-image + #:key hidden) + `(fieldset ,(if hidden + '(@ (id "comment-captcha") (hidden "#t")) + '(@ (id "comment-captcha"))) + (legend "Captcha") + (div (@ (id "captcha-challenge-primary")) + (label (@ (for "captcha")) "Please evaluate the following definite integral:") + (img (@ (id "captcha-image") + (src ,(if captcha-image + (format #f "data:image/jpeg;charset=utf-8;base64,~a" + (base64-encode captcha-image)) + "")))) + (input (@ (type "text") (id "captcha") (name "captcha") (size 24)))) + (button (@ (id "pow-trigger") (hidden #t)) + "Too hard? (Or unable to see the challenge?) Click here.") + (input (@ (autocomplete "off") (type "text") (id "captcha-id") (name "captcha-id") (hidden #t) (value ,captcha-id))) + (input (@ (autocomplete "off") (type "text") (id "captcha-alt") (name "captcha-alt") (hidden #t))) + (input (@ (autocomplete "off") (type "text") (id "captcha-alt-id") (name "captcha-alt-id") (hidden #t))) + (input (@ (type "submit") (id "submit-form") (value "Submit"))))) + +(define (render-static-comment-form slug captcha-id captcha-image) + `(div (@ (id "comment-form")) + (h1 "Comment form") + (form (@ (id "comment-input") (action "/api/comment") (method "post")) + (input (@ (type "text") (name "slug") (hidden #t) (value ,slug))) + ,(render-commenter-info-field) + ,(render-comment-content-field) + ,(render-comment-captcha-field captcha-id captcha-image)) + ,(script "proof-of-work.js"))) + +(define* (render-dynamic-comment-form slug) `(div (@ (id "comment-form")) - (,header-level "Comment form") + (h3 "Comment form") (form (@ (id "comment-input") (action "/api/comment") (method "post")) (input (@ (type "text") (name "slug") (hidden #t) (value ,slug))) - (input (@ (type "text") (id "captcha-id") (name "captcha-id") (hidden #t) (autocomplete "off") (value ,captcha-id))) - (fieldset (@ (id "commenter-info")) - (legend "Commenter Info") - (label (@ (for "name")) "Name:") - (input (@ (type "text") (id "name") (name "name") (required #t) (size 24))) - (label (@ (for "email")) "Email (optional, used for Gravatar):") - (input (@ (type "text") (id "email") (name "email") (size 24))) - (label (@ (for "url")) "Webpage URL (optional):") - (input (@ (type "text") (id "url") (name "url") (size 24)))) - (fieldset (@ (id "comment-content")) - (legend "Comment") - (label (@ (for "subject")) "Subject (optional):") - (input (@ (type "text") (id "subject") (name "subject") (size 24))) - (label (@ (for "comment")) "Comment :") - (textarea (@ (id "coment") (name "comment") (rows 4) (cols 50)))) - (fieldset (@ (id "comment-captcha")) + ,(render-commenter-info-field) + ,(render-comment-content-field) + (fieldset (@ (id "captcha-trigger-block")) (legend "Captcha") - (label (@ (for "captcha")) "Please evaluate the following definite integral:") - (img (@ (id "captcha-image") - (src ,(if captcha-image - (format #f "data:image/jpeg;charset=utf-8;base64,~a" - (base64-encode captcha-image)) - "")))) - (input (@ (type "text") (id "captcha") (name "captcha") (size 24))) - (button (@ (id "pow-trigger") (hidden #t)) - "Too hard? (Or unable to see the challenge?) Click here.") - (input (@ (type "text") (id "captcha-alt") (name "captcha-alt") (hidden #t))) - (input (@ (type "text") (id "captcha-alt-id") (name "captcha-alt-id") (hidden #t))) - (input (@ (type "submit") (id "submit-form") (value "Submit"))))) + (label "You need to complete a captcha to write a comment.") + (button (@ (id "captcha-challenge-trigger")) + "Click here to generate a captcha challenge")) + ,(render-comment-captcha-field #:hidden #t)) ,(script "dynamic-comment-form.js") ,(script "proof-of-work.js"))) @@ -86,9 +115,7 @@ This is a wrapper around `get-comments-by-slug'." (let* ((path-encoded (uri-path (request-uri request))) (path (split-and-decode-uri-path path-encoded)) (slug (last path)) - (form (render-comment-form slug - #:captcha-id captcha-id - #:captcha-image captcha-image))) + (form (render-staticcomment-form slug #f captcha-id captcha-image))) (values '((content-type . (text/html))) (sxml->html-string (theme #:content form #:title "Comment prompt")))))) |