root/trunk/website/blog/addcomment.cfm @ 6

Revision 5, 9.5 kB (checked in by DanWilson, 17 years ago)

Initial Commit Of ModelGlue? Website (upgrade to blogcfc 511)

Line 
1<cfprocessingdirective pageencoding="utf-8">
2<!---
3        Name         : addcomment.cfm
4        Author       : Raymond Camden
5        Created      : February 11, 2003
6        Last Updated : October 8, 2007
7        History      : Reset history for version 5.0
8                                 : Lengths allowed for name/email were 100, needed to be 50
9                                 : Cancel confirmation (rkc 8/1/06)
10                                 : rb use (rkc 8/20/06)
11                                 : Scott updates the design a bit (ss 8/24/06)
12                                 : Default form.captchaText (rkc 10/21/06)
13                                 : Don't log the getentry (rkc 2/28/07)
14                                 : Don't mail if moderating (rkc 4/13/07)
15        Purpose          : Adds comments
16--->
17
18<cfif not isDefined("form.addcomment")>
19        <cfif isDefined("cookie.blog_name")>
20                <cfset form.name = cookie.blog_name>
21                <cfset form.rememberMe = true>
22        </cfif>
23        <cfif isDefined("cookie.blog_email")>
24                <cfset form.email = cookie.blog_email>
25                <cfset form.rememberMe = true>
26        </cfif>
27        <!--- RBB 11/02/2005: Added new website check --->
28        <cfif isDefined("cookie.blog_website")>
29                <cfset form.website = cookie.blog_website>
30                <cfset form.rememberMe = true>
31        </cfif>
32</cfif>
33
34<cfparam name="form.name" default="">
35<cfparam name="form.email" default="">
36<!--- RBB 11/02/2005: Added new website parameter --->
37<cfparam name="form.website" default="http://">
38<cfparam name="form.comments" default="">
39<cfparam name="form.rememberMe" default="false">
40<cfparam name="form.subscribe" default="false">
41<cfparam name="form.captchaText" default="">
42
43<!--- validate boolean --->
44<cfif not isBoolean(form.subscribe)>
45        <cfset form.subscribe = false />
46</cfif>
47<cfif not isBoolean(form.rememberme)>
48        <cfset form.rememberme = false />
49</cfif>
50               
51<cfset closeMe = false>
52<cfif not isDefined("url.id")>
53        <cfset closeMe = true>
54<cfelse>
55        <cftry>
56                <cfset entry = application.blog.getEntry(url.id,true)>
57                <cfcatch>
58                        <cfset closeMe = true>
59                </cfcatch>
60        </cftry>
61</cfif>
62<cfif closeMe>
63        <cfoutput>
64        <script>
65        window.close();
66        </script>
67        </cfoutput>
68        <cfabort>
69</cfif>
70
71<cfif isDefined("form.addcomment") and entry.allowcomments>
72        <cfset form.name = trim(form.name)>
73        <cfset form.email = trim(form.email)>
74        <!--- RBB 11/02/2005: Added new website option --->
75        <cfset form.website = trim(form.website)>
76        <cfset form.comments = trim(form.comments)>
77
78        <!-- if website is just http://, remove it --->
79        <cfif form.website is "http://">
80                <cfset form.website = "">
81        </cfif>
82        <!---// track the errors //--->
83        <cfset aErrors = arrayNew(1) />
84       
85        <cfif not len(form.name)>
86                <cfset arrayAppend(aErrors, rb("mustincludename")) />
87        </cfif>
88        <cfif not len(form.email) or not isEmail(form.email)>
89                <cfset arrayAppend(aErrors, rb("mustincludeemail")) />
90        </cfif>
91        <cfif len(form.website) and not isURL(form.website)>
92                <cfset arrayAppend(aErrors, rb("invalidurl")) />
93        </cfif>
94               
95        <cfif not len(form.comments)>
96                <cfset arrayAppend(aErrors, rb("mustincludecomments")) />
97        </cfif>
98               
99        <!--- captcha validation --->
100        <cfif application.useCaptcha>
101                <cfif not len(form.captchaText)>
102                        <cfset arrayAppend(aErrors, "Please enter the Captcha text.") />
103                <cfelseif NOT application.captcha.validateCaptcha(form.captchaHash,form.captchaText)>
104                        <cfset arrayAppend(aErrors, "The captcha text you have entered is incorrect.") />
105                </cfif>
106        </cfif>
107        <!--- cfformprotect --->
108        <cfif application.usecfp>
109                <cfset cffp = createObject("component","cfformprotect.cffpVerify").init() />
110                <!--- now we can test the form submission --->
111                <cfif not cffp.testSubmission(form)>
112                        <cfset arrayAppend(aErrors, "Your comment has been flagged as spam.") />
113                </cfif>
114        </cfif>
115                       
116        <cfif not arrayLen(aErrors)>
117          <!--- RBB 11/02/2005: added website to commentID --->
118                <cftry>
119                        <cfset commentID = application.blog.addComment(url.id,left(form.name,50), left(form.email,50), left(form.website,255), form.comments, form.subscribe)>
120                        <!--- Form a message about the comment --->
121                        <cfset subject = rb("commentaddedtoblog") & ": " & application.blog.getProperty("blogTitle") & " / " & rb("entry") & ": " & entry.title>
122                        <cfset commentTime = dateAdd("h", application.blog.getProperty("offset"), now())>
123                        <cfsavecontent variable="email">
124                        <cfoutput>
125#rb("commentaddedtoblogentry")#:        #application.utils.htmlToPlainText(entry.title)#
126#rb("commentadded")#:           #application.localeUtils.dateLocaleFormat(commentTime)# / #application.localeUtils.timeLocaleFormat(commentTime)#
127#rb("commentmadeby")#:          #form.name# <cfif len(form.website)>(#form.website#)</cfif>
128#rb("ipofposter")#:                     #cgi.REMOTE_ADDR#
129URL: #application.blog.makeLink(url.id)###c#commentID#
130
131
132#form.comments#
133
134------------------------------------------------------------
135#rb("unsubscribe")#: %unsubscribe%
136This blog powered by BlogCFC #application.blog.getVersion()#
137Created by Raymond Camden (http://www.coldfusionjedi.com)
138                        </cfoutput>
139                        </cfsavecontent>
140
141                        <cfinvoke component="#application.blog#" method="notifyEntry">
142                                <cfinvokeargument name="entryid" value="#entry.id#">
143                                <cfinvokeargument name="message" value="#trim(email)#">
144                                <cfinvokeargument name="subject" value="#subject#">
145                                <cfinvokeargument name="from" value="#form.email#">
146                                <cfif application.commentmoderation>
147                                        <cfinvokeargument name="adminonly" value="true">
148                                </cfif>                                                                         
149                                <cfinvokeargument name="commentid" value="#commentid#">
150                        </cfinvoke>
151                                                               
152                        <cfcatch>
153                                <cfif cfcatch.message is not "Comment blocked for spam.">
154                                        <cfrethrow>
155                                <cfelse>
156                                        <cfset arrayAppend(aErrors, "Your comment has been flagged as spam.") />               
157                                </cfif>
158                        </cfcatch>
159                               
160                        </cftry>
161                                       
162                <cfif not arrayLen(aErrors)>           
163                        <cfmodule template="tags/scopecache.cfm" scope="application" clearall="true">
164                        <cfset comments = application.blog.getComments(url.id)>
165                        <!--- clear form data --->
166                        <cfif form.rememberMe>
167                                <cfcookie name="blog_name" value="#trim(htmlEditFormat(form.name))#" expires="never">
168                                <cfcookie name="blog_email" value="#trim(htmlEditFormat(form.email))#" expires="never">
169                        <!--- RBB 11/02/2005: Added new website cookie --->
170                                <cfcookie name="blog_website" value="#trim(htmlEditFormat(form.website))#" expires="never">
171                        <cfelse>
172                                <cfcookie name="blog_name" expires="now">
173                                <cfcookie name="blog_email" expires="now">
174                                <!--- RBB 11/02/2005: Added new website form var --->
175                                <cfset form.name = "">
176                                <cfset form.email = "">
177                                <cfset form.website = "">
178                        </cfif>
179                        <cfset form.comments = "">
180                       
181                        <!--- reload page and close this up --->
182                        <cfoutput>
183                        <script>
184                        window.opener.location.reload();
185                        window.close();
186                        </script>
187                        </cfoutput>
188                        <cfabort>
189                </cfif>
190        </cfif>
191</cfif>
192
193<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" />
194
195<html>
196<head>
197        <cfoutput><title>#application.blog.getProperty("blogTitle")# : #rb("addcomments")#</title></cfoutput>
198        <link rel="stylesheet" href="includes/style.css" type="text/css"/>
199        <meta content="text/html; charset=UTF-8" http-equiv="content-type">
200</head>
201
202<body id="popUpFormBody">
203
204<cfoutput>
205<div class="date">#rb("comments")#: #entry.title#</div>
206<div class="body">
207</cfoutput>
208
209<cfif entry.allowcomments>
210       
211       
212                <cfif isDefined("aErrors") and arrayLen(aErrors)>
213                        <cfoutput>
214                                <div id="CommentError">
215                                        <b>#rb("correctissues")#:</b>
216                                        <ul class="error"><li>#arrayToList(aErrors, "</li><li>")#</li></ul>
217                                </div>
218                        </cfoutput>
219                </cfif>
220        <cfoutput>
221        <form action="#application.rootURL#/addcomment.cfm?#cgi.query_string#" method="post">
222        <cfif application.usecfp>
223                <cfinclude template="cfformprotect/cffp.cfm">
224        </cfif>
225  <fieldset id="commentForm">
226        <legend>#rb("postyourcomments")#</legend>
227  <div>
228                <label for="name">#rb("name")#:</label>
229                <input type="text" id="name" name="name" value="#form.name#">
230  </div>
231  <div>
232                <label for="email">#rb("emailaddress")#:</label>
233                <input type="text" id="email" name="email" value="#form.email#">
234  </div>
235  <div>
236                <label for="website">#rb("website")#:</label>
237                <input type="text" id="website" name="website" value="#form.website#">
238  </div>
239  <div>
240                <label for="comments">#rb("comments")#:</label>
241                <textarea name="comments" id="comments">#form.comments#</textarea>
242  </div>
243        <cfif application.useCaptcha>
244    <div>
245                <cfset variables.captcha = application.captcha.createHashReference() />
246                <input type="hidden" name="captchaHash" value="#variables.captcha.hash#" />
247                <label for="captchaText" class="longLabel">#rb("captchatext")#:</label>
248                <input type="text" name="captchaText" size="6" /><br>
249                <img src="#application.blog.getRootURL()#showCaptcha.cfm?hashReference=#variables.captcha.hash#" align="right" vspace="5"/>
250  </div>
251        </cfif>
252  <div>
253                <label for="rememberMe" class="longLabel">#rb("remembermyinfo")#:</label>
254                <input type="checkbox" class="checkBox" id="rememberMe" name="rememberMe" value="1" <cfif isBoolean(form.rememberMe) and form.rememberMe>checked</cfif>>
255  </div>
256  <div>
257                <label for="subscribe" class="longLabel">#rb("subscribe")#:</label>
258                <input type="checkbox" class="checkBox" id="subscribe" name="subscribe" value="1" <cfif isBoolean(form.subscribe) and form.subscribe>checked</cfif>>
259  </div>
260        <p style="clear:both">#rb("subscribetext")#</p>
261  <div style="text-align:center">
262                <input type="reset" id="reset" value="#rb("cancel")#" onClick="if(confirm('#rb("cancelconfirm")#')) { window.close(); } else { return false; }"> <input type="submit" id="submit" name="addcomment" value="#rb("post")#">
263    </div>
264</fieldset>
265        </form>
266        </cfoutput>
267       
268<cfelse>
269
270        <cfoutput>
271        <p>#rb("commentsnotallowed")#</p>
272        </cfoutput>
273       
274</cfif>
275</div>
276
277</body>
278</html>
Note: See TracBrowser for help on using the browser.