Adding report abusive comments to blogCFC
You may notice i;ve been making a few changes to blogCFC over the past couple of days - here's another.
Have ever have people adding bad comments to you blog entries? Do you have nice readers who are willing to let you know about them?
If you've answered yes to the above questions you may wish to do the following to enable your uses to report bad comments - hell you may just want to do it for the fun of it!
Add the 'report this' link to index.cfm @ line 178 - 196 (depending on version)
Create the page reportAbuse.cfm and play it in the root folder of you blog – the code for this page is mainly taken from send.cfm
<cfprocessingdirective pageencoding="utf-8">
<!---
Name : Report Abuse
Author : Nick Tong - taken from Ray Camdens send.cfm page
Created : Oct 11, 2006
History : Created from send.cfm
Purpose : Sends a report to the admin reporting on comments
--->
<cfif not structKeyExists(url,"cid") OR not structKeyExists(url,"id")>
<cflocation url="#application.rooturl#/" addToken="false" />
<cfelse>
<cftry>
<cfset request.entry = application.blog.getEntry(url.id) />
<cfset request.comment = application.blog.getComment(url.cid) />
<cfcatch>
<cflocation url="#application.rooturl#/" addToken="false" />
</cfcatch>
</cftry>
</cfif>
<cfset showForm = true>
<cfparam name="form.email" default="">>
<cfparam name="form.notes" default="">
<cfparam name="form.captchaText" default="">
<cfif structKeyExists(form, "send")>
<cfset errorStr = "">
<cfif not len(trim(form.email)) or not isEmail(form.email)>
<cfset errorStr = errorStr & rb("mustincludeemail") & "<br />">
</cfif>
<!--- captcha validation --->
<cfif application.useCaptcha>
<cfif not len(form.captchaText)>
<cfset errorStr = errorStr & "Please enter the Captcha text.<br>">
<cfelseif NOT application.captcha.validateCaptcha(form.captchaHash,form.captchaText)>
<cfset errorStr = errorStr & "The captcha text you have entered is incorrect.<br>">
</cfif>
</cfif>
<cfif not len(errorStr)>
<cfsavecontent variable="body">
<cfoutput>
<p>
The following comment entry was sent to you from: <b>#form.email#</b><br />
It came from the blog: <b>#application.blog.getProperty("blogtitle")#</b><br />
The entry is titled: <b>#request.entry.title#</b><br />
The comment is: #request.comment.comment#<br>
The comment can be edited here: <b><a href="#application.rooturl#/admin/comment.cfm?id=#url.cid#">#application.rooturl#/admin/comment.cfm?id=#url.cid#</a></b>
The comment can be found here: <b><a href="#application.blog.makeLink(request.entry.id)###comments">#application.blog.makeLink(request.entry.id)#</a></b>
</p>
<cfif len(form.notes)>
<p>
The following notes were included:<br />
<b>#form.notes#</b>
</p>
<p>
<hr>
</p>
</cfif>
#application.blog.renderEntry(request.entry.body)#
<cfif len(request.entry.morebody)>#application.blog.renderEntry(request.entry.morebody)#</cfif>
</cfoutput>
</cfsavecontent>
<cfset application.utils.mail(
to=application.blog.getProperty("owneremail"),
from=form.email,
subject="#rb("commentreportfrom")#: #application.blog.getProperty("blogtitle")#",
type="html",
body=body,
mailserver=application.blog.getProperty("mailserver"),
mailusername=application.blog.getProperty("mailusername"),
mailpassword=application.blog.getProperty("mailpassword")
)>
<cfset showForm = false>
</cfif>
</cfif>
<cfmodule template="tags/layout.cfm" title="#rb("send")#">
<cfoutput>
<div class="date"><b>#rb("sendcommentabuse")#: #request.entry.title#</b></div>
<div class="body">
<cfif showForm>
<p>
#rb("sendcommentform")#
</p>
<cfif isDefined("errorStr") and len(errorStr)>
<cfoutput><b style="">#rb("correctissues")#:</b><ul>#errorStr#</ul></cfoutput>
</cfif>
<form action="#cgi.script_name#?#cgi.query_string#" method="post">
<fieldset id="sendForm">
<div>
<label for="email">#rb("youremailaddress")#:</label>
<input type="text" id="email" name="email" value="#form.email#" style="width:300px;">
</div>
<div>
<label for="notes">#rb("optionalnotes")#:</label>
<textarea name="notes" id="notes">#form.notes#</textarea>
</div>
<cfif application.useCaptcha>
<cfset variables.captcha = application.captcha.createHashReference() />
<div>
<input type="hidden" name="captchaHash" value="#variables.captcha.hash#" />
<label for="captchaText" class="longLabel">#rb("captchatext")#:</label>
<input type="text" name="captchaText" size="6" /><br>
<img src="#application.blog.getRootURL()#showCaptcha.cfm?hashReference=#variables.captcha.hash#" vspace="5"/>
</div>
</cfif>
<div>
<input type="submit" id="submit" name="send" value="#rb("sendcommentabuse")#">
</div>
</fieldset>
</form>
<cfelse>
<p>
#rb("commentabusesent")#
</p>
</cfif>
</div>
</cfoutput>
</cfmodule>
<cfsetting enablecfoutputonly=false>
Add the following lines to locale file in the org folder (main.properties)
sendcommentform=The form below can be used to report comment abuse. Please fill out the form below.
commentabusesent=Your comment abuse report has been sent.
commentreportfrom=Comment report for post
Reinit the app (?reinit=1) and away you go.
When a user clicks on the new link they will be asked to enter their email address and any comments. Once they click send this will then send you an email (to the blog admin email) with links to the comment, aricle and admin edit area.





Outside of that - way cool!
locals:
commentreportfrom=comment report from
and updated the report page to use this.
Ben - it's a very Bad state indeed. I know here in the UK both Mark Drew and Andy Jarret have had big problems with spammer in comments, newletters etc!! CURSE them all! - oh the spammer that is ;)