// check if trackbacks are allowed for this entry
// this checks site-wide settings, weblog settings, and entry settings
if (entry != null && entry.getCommentsStillAllowed() && entry.isPublished()) {
// Track trackbacks as comments
CommentData comment = new CommentData();
comment.setContent("[Trackback] "+trackbackRequest.getExcerpt());
comment.setName(trackbackRequest.getBlogName());
comment.setUrl(trackbackRequest.getUrl());
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
LinkbackExtractor linkback = new LinkbackExtractor(
comment.getUrl(), URLUtilities.getWeblogEntryURL(weblog, null, entry.getAnchor(), true));
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 && weblog.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();
// only invalidate the cache if comment isn't moderated
if(!weblog.getCommentModerationRequired()) {
// Clear all caches associated with comment
CacheManager.invalidate(comment);
}
// Send email notifications
String rootURL = RollerRuntimeConfig.getAbsoluteContextURL();
if (rootURL == null || rootURL.trim().length()==0) {
rootURL = RequestUtils.serverURL(request) + request.getContextPath();
}
CommentServlet.sendEmailNotification(comment, rootURL);
if(comment.getPending().booleanValue()) {
pw.println(this.getSuccessResponse("Trackback submitted to moderator"));
} else {
pw.println(this.getSuccessResponse("Trackback accepted"));
}
}