Weblog weblog = null;
WeblogEntry entry = null;
RollerMessages messages = new RollerMessages();
WeblogTrackbackRequest trackbackRequest = null;
if (!WebloggerRuntimeConfig.getBooleanProperty("users.trackbacks.enabled")) {
// TODO: i18n
error = "Trackbacks are disabled for this site";
} else {
try {
trackbackRequest = new WeblogTrackbackRequest(request);
if ((trackbackRequest.getTitle() == null) ||
"".equals(trackbackRequest.getTitle())) {
trackbackRequest.setTitle(trackbackRequest.getUrl());
}
if (trackbackRequest.getExcerpt() == null) {
trackbackRequest.setExcerpt("");
} else if (trackbackRequest.getExcerpt().length() >= 255) {
trackbackRequest.setExcerpt(trackbackRequest.getExcerpt().substring(0, 252)+"...");
}
// lookup weblog specified by comment request
UserManager uMgr = WebloggerFactory.getWeblogger().getUserManager();
weblog = uMgr.getWebsiteByHandle(trackbackRequest.getWeblogHandle());
if (weblog == null) {
throw new WebloggerException("unable to lookup weblog: "+
trackbackRequest.getWeblogHandle());
}
// lookup entry specified by comment request
WeblogManager weblogMgr = WebloggerFactory.getWeblogger().getWeblogManager();
entry = weblogMgr.getWeblogEntryByAnchor(weblog, trackbackRequest.getWeblogAnchor());
if (entry == null) {
throw new WebloggerException("unable to lookup entry: "+
trackbackRequest.getWeblogAnchor());
}
} catch (Exception e) {
// some kind of error parsing the request or looking up weblog
logger.debug("error creating trackback request", e);
error = e.getMessage();
}
}
if (error != null) {
pw.println(this.getErrorResponse(error));
return;
}
try {
// 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
WeblogEntryComment comment = new WeblogEntryComment();
comment.setContent("[Trackback] "+trackbackRequest.getExcerpt());
comment.setName(trackbackRequest.getBlogName());
comment.setUrl(trackbackRequest.getUrl());
comment.setWeblogEntry(entry);
comment.setRemoteHost(request.getRemoteHost());
comment.setNotify(Boolean.FALSE);
comment.setPostTime(new Timestamp(new Date().getTime()));
// run new trackback through validators
int validationScore = commentValidationManager.validateComment(comment, messages);
logger.debug("Comment Validation score: " + validationScore);
if (validationScore == 100 && weblog.getCommentModerationRequired()) {
// Valid comments go into moderation if required
comment.setStatus(WeblogEntryComment.PENDING);
} else if (validationScore == 100) {
// else they're approved
comment.setStatus(WeblogEntryComment.APPROVED);
} else {
// Invalid comments are marked as spam
comment.setStatus(WeblogEntryComment.SPAM);
}
// save, commit, send response
if(!WeblogEntryComment.SPAM.equals(comment.getStatus()) ||
!WebloggerRuntimeConfig.getBooleanProperty("trackbacks.ignoreSpam.enabled")) {
WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
mgr.saveComment(comment);
WebloggerFactory.getWeblogger().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
MailUtil.sendEmailNotification(comment, messages,
I18nMessages.getMessages(trackbackRequest.getLocaleInstance()),
validationScore == 100);
if(WeblogEntryComment.PENDING.equals(comment.getStatus())) {
pw.println(this.getSuccessResponse("Trackback submitted to moderator"));
} else {