From ce5309fcde2bd29b042efc5868e7721a951dd846 Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 20 Sep 2004 17:18:25 +0000 Subject: [PATCH] Feedback form. You need to set the hosts.feedback_email field in the database to activate it for a particular site. --- MANIFEST | 4 ++ scripts/.depend | 12 +++-- scripts/Makefile | 4 +- scripts/page.ml | 16 ++++--- scripts/send_feedback.ml | 92 +++++++++++++++++++++++++++++++++++++++ scripts/send_feedback_form.ml | 40 +++++++++++++++++ templates/page.html | 3 ++ templates/send_feedback.txt | 20 +++++++++ templates/send_feedback_form.html | 72 ++++++++++++++++++++++++++++++ 9 files changed, 252 insertions(+), 11 deletions(-) create mode 100644 scripts/send_feedback.ml create mode 100644 scripts/send_feedback_form.ml create mode 100644 templates/send_feedback.txt create mode 100644 templates/send_feedback_form.html diff --git a/MANIFEST b/MANIFEST index 0ec51e2..f0371c8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -96,6 +96,8 @@ scripts/restore.ml scripts/restore_form.ml scripts/rss.ml scripts/search.ml +scripts/send_feedback.ml +scripts/send_feedback_form.ml scripts/signup.ml scripts/sitemap.ml scripts/undelete_file.ml @@ -139,6 +141,8 @@ templates/page_404.html templates/recent.html templates/restore_form.html templates/rss.xml +templates/send_feedback.txt +templates/send_feedback_form.html templates/sitemap.html templates/undelete_file_form.html templates/undelete_image_form.html diff --git a/scripts/.depend b/scripts/.depend index cf4a8c2..b29a791 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -2,8 +2,8 @@ 00-TEMPLATE.cmx: cocanwiki.cmx cocanwiki_template.cmx cgi_expires.cmo: cocanwiki_date.cmo cgi_expires.cmx: cocanwiki_date.cmx -cocanwiki.cmo: cocanwiki_ok.cmo -cocanwiki.cmx: cocanwiki_ok.cmx +cocanwiki.cmo: cocanwiki_ok.cmo cocanwiki_strings.cmo +cocanwiki.cmx: cocanwiki_ok.cmx cocanwiki_strings.cmx cocanwiki_diff.cmo: cocanwiki_files.cmo cocanwiki_diff.cmx: cocanwiki_files.cmx cocanwiki_images.cmo: cocanwiki_files.cmo cocanwiki_strings.cmo \ @@ -81,9 +81,9 @@ login_form.cmx: cocanwiki.cmx cocanwiki_strings.cmx cocanwiki_template.cmx logout.cmo: cocanwiki.cmo cocanwiki_ok.cmo logout.cmx: cocanwiki.cmx cocanwiki_ok.cmx page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \ - cocanwiki_strings.cmo cocanwiki_template.cmi wikilib.cmi + cocanwiki_template.cmi wikilib.cmi page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \ - cocanwiki_strings.cmx cocanwiki_template.cmx wikilib.cmx + cocanwiki_template.cmx wikilib.cmx pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx preview.cmo: cocanwiki.cmo wikilib.cmi @@ -102,6 +102,10 @@ rss.cmo: cocanwiki.cmo cocanwiki_template.cmi wikilib.cmi rss.cmx: cocanwiki.cmx cocanwiki_template.cmx wikilib.cmx search.cmo: cocanwiki.cmo search.cmx: cocanwiki.cmx +send_feedback.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi +send_feedback.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx +send_feedback_form.cmo: cocanwiki.cmo cocanwiki_template.cmi +send_feedback_form.cmx: cocanwiki.cmx cocanwiki_template.cmx signup.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo signup.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx sitemap.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_strings.cmo \ diff --git a/scripts/Makefile b/scripts/Makefile index 6cf7991..a5ca44a 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.13 2004/09/20 15:34:36 rich Exp $ +# $Id: Makefile,v 1.14 2004/09/20 17:18:26 rich Exp $ include ../Makefile.config @@ -57,6 +57,8 @@ OBJS := 00-TEMPLATE.cmo \ restore_form.cmo \ rss.cmo \ search.cmo \ + send_feedback.cmo \ + send_feedback_form.cmo \ signup.cmo \ sitemap.cmo \ undelete_file.cmo \ diff --git a/scripts/page.ml b/scripts/page.ml index 9378107..3ff3e01 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.15 2004/09/20 15:34:36 rich Exp $ + * $Id: page.ml,v 1.16 2004/09/20 17:18:26 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,13 +45,15 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = let page = q#param "page" in let page = if page = "" then "index" else page in - (* Host-specific CSS? *) - let sth = dbh#prepare_cached "select css is not null from hosts - where id = ?" in + (* Host-specific fields. *) + let sth = dbh#prepare_cached "select css is not null, + feedback_email is not null + from hosts where id = ?" in sth#execute [`Int hostid]; - let has_host_css = + let has_host_css, has_feedback_email = match sth#fetch1 () with - | [ `Bool has_host_css ] -> has_host_css + | [ `Bool has_host_css; `Bool has_feedback_email ] -> + has_host_css, has_feedback_email | _ -> assert false in (* Can the user edit? Manage users? etc. *) @@ -80,6 +82,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = t#conditional "has_host_css" has_host_css; t#conditional "has_page_css" has_page_css; + t#conditional "has_feedback_email" has_feedback_email; + t#conditional "can_edit" can_edit; t#conditional "can_manage_users" can_manage_users; t#conditional "can_manage_contacts" can_manage_contacts; diff --git a/scripts/send_feedback.ml b/scripts/send_feedback.ml new file mode 100644 index 0000000..3dc1a1e --- /dev/null +++ b/scripts/send_feedback.ml @@ -0,0 +1,92 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: send_feedback.ml,v 1.1 2004/09/20 17:18:26 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open ExtString + +open Cocanwiki +open Cocanwiki_template +open Cocanwiki_ok + +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user = + let template = get_template dbh hostid "send_feedback.txt" in + + if q#param_true "cancel" then ( + (* Request cancelled. *) + q#redirect ("http://" ^ hostname); + raise CgiExit + ); + + (* Get the feedback email for this host. *) + let sth = + dbh#prepare_cached "select feedback_email from hosts where id = ?" in + sth#execute [`Int hostid]; + + let to_addr = sth#fetch1string () in + + (* Get the fields. *) + let page = q#param "page" in + let name = q#param "name" in + let email = q#param "email" in + let feedback = q#param "feedback" in + + template#set "page" page; + template#set "name" name; + template#set "email" email; + template#set "feedback" feedback; + + (* Get the IP address for logging purposes. *) + let ip = + try Connection.remote_ip (Request.connection r) with Not_found -> "" in + + (* Get the User-Agent string. Consider in future rejecting spammers + * who don't set User-Agent. + *) + let ua = + try Table.get (Request.headers_in r) "User-Agent" with Not_found -> "" in + + (* Get the user details, if any. *) + let username = + match user with + Anonymous -> "anonymous" + | User (userid, username, _) -> + sprintf "%s (%d)" username userid in + + template#set "ip" ip; + template#set "ua" ua; + template#set "username" username; + template#set "hostname" hostname; + + (* Send the feedback email. *) + let subject = "Wiki feedback: Feedback about " ^ page ^ " page" in + let body = template#to_string in + Sendmail.send_mail ~subject ~to_addr:[to_addr] ~body (); + + (* Confirm. *) + ok ~title:"Thank you for your feedback" ~buttons:[ok_button "/"] + q "An email has been sent to the site administrators." + +let () = + register_script run diff --git a/scripts/send_feedback_form.ml b/scripts/send_feedback_form.ml new file mode 100644 index 0000000..7fef87e --- /dev/null +++ b/scripts/send_feedback_form.ml @@ -0,0 +1,40 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: send_feedback_form.ml,v 1.1 2004/09/20 17:18:26 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "send_feedback_form.html" in + + let page = q#param "page" in + + template#set "page" page; + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/templates/page.html b/templates/page.html index 1a5fb71..6d7e0ec 100644 --- a/templates/page.html +++ b/templates/page.html @@ -84,6 +84,9 @@ diff --git a/templates/send_feedback.txt b/templates/send_feedback.txt new file mode 100644 index 0000000..ab59d85 --- /dev/null +++ b/templates/send_feedback.txt @@ -0,0 +1,20 @@ +This is an automatically generated message from the feedback form at +::hostname::. Someone has filled out this form and sent it to you +below. + +---------------------------------------------------------------------- +Feedback about page http://::hostname::/::page::: + +Name: ::name:: +Email: ::email:: + +Feedback: + +::feedback:: +---------------------------------------------------------------------- + +LOGGING INFORMATION: + +IP address: ::ip:: +Username: ::username:: +User-Agent: ::ua:: diff --git a/templates/send_feedback_form.html b/templates/send_feedback_form.html new file mode 100644 index 0000000..8e8989a --- /dev/null +++ b/templates/send_feedback_form.html @@ -0,0 +1,72 @@ + + + +Send feedback about this page + + + + + +

Send feedback about this page

+ +
+ + + + + + + + + + + + + + + + + + + + + + +
Name:
Email:
Feedback:
All fields are optional, but please give us your +email address if you'd like us to get back to you.
+
+
+ +

Contents of the page

+ + + +<a href="/::page_html_tag::" target="_blank">Go here to see the page on which you are sending feedback.</a> + + + + + + + + + + \ No newline at end of file -- 1.8.3.1