boolean siteAllows = website.getAllowComments().booleanValue();
if (entry!=null && siteAllows && entry.getCommentsStillAllowed()) {
// Track trackbacks as comments
CommentData comment = new CommentData();
comment.setContent("[Trackback] "+excerpt);
comment.setName(blogName);
comment.setUrl(url);
comment.setWeblogEntry(entry);
comment.setNotify(Boolean.FALSE);
comment.setPostTime(new Timestamp(new Date().getTime()));
// If comment contains blacklisted text, mark as spam
SpamChecker checker = new SpamChecker();
if (checker.checkTrackback(comment)) {
comment.setSpam(Boolean.TRUE);
logger.debug("Trackback blacklisted: "+comment.getUrl());
error = "REJECTED: trackback contains spam words";
}
// Else, if trackback verification is on...
else if (RollerRuntimeConfig.getBooleanProperty(
"site.trackbackVerification.enabled")) {
// ...ensure trackbacker actually links to us
RollerContext rctx= RollerContext.getRollerContext();
String absurl = rctx.getAbsoluteContextUrl(req);
LinkbackExtractor linkback = new LinkbackExtractor(
comment.getUrl(), absurl + entry.getPermaLink());
if (linkback.getExcerpt() == null) {
comment.setPending(Boolean.TRUE);
comment.setApproved(Boolean.FALSE);
verified = false;
// if we can't verify trackback, then reject it
error = "REJECTED: trackback failed verification";
logger.debug("Trackback failed verification: "+comment.getUrl());
}
}
if (error == null) {
// If comment moderation is on, set comment as pending
if (verified && website.getCommentModerationRequired()) {
comment.setPending(Boolean.TRUE);
comment.setApproved(Boolean.FALSE);
} else if (verified) {
comment.setPending(Boolean.FALSE);
comment.setApproved(Boolean.TRUE);
}
// save, commit, send response
WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
mgr.saveComment(comment);
RollerFactory.getRoller().flush();
// Clear all caches associated with comment
CacheManager.invalidate(comment);
// Send email notifications
RollerContext rc = RollerContext.getRollerContext();
String rootURL = rc.getAbsoluteContextUrl(req);
if (rootURL == null || rootURL.trim().length()==0) {
rootURL = RequestUtils.serverURL(req) + req.getContextPath();
}
CommentServlet.sendEmailNotification(comment, rootURL);
pw.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
pw.println("<response>");
pw.println("<error>0</error>");
if (comment.getPending().booleanValue()) {
pw.println("<message>Trackback sumitted to moderation</message>");
} else {
pw.println("<message>Trackback accepted</message>");
}
pw.println("</response>");