Private comments

It was recently pointed out to me that my old blogging software allowed for private comments (i.e., those that are just mailed to me and not displayed on the site) and this one doesn’t. I looked around, and afaics MT doesn’t allow them. So I’ve sort of hacked them into place. The rest of this article is a techie description of how I did it which you do not have to read, but bear this one thing in mind: do not preview a comment which is going to be private, because it forgets the “private” flag. I haven’t finished this yet. But I thought people might like it anyway. There are only a couple of changes that need to be made to allow private comments; one to your comment template (to give commenters a “private” box to tick) and a couple to lib/MT/App/Comments.pm (to pay attention to said checkbox). Note that you should be fairly comfortable hacking around in your MT installation before attempting this. In your Comment Listing template (from the MT admin interface, click Templates) add the line: <input type="checkbox" name="privatecomment" />Private comment (email only?)<br /> after the main comment \<textarea> tag. (Or, you know, add it wherever you want.) That gives your users a checkbox to tick. Now, in lib/MT/App/Comments.pm, in your mt/ directory, change the lines: $comment->save; $app->rebuild_indexes( Blog => $blog ) or return $app->error("Index rebuild failed: " . $app->errstr); $app->rebuild_entry( Entry => $entry ) or return $app->error("Rebuild failed: " . $app->errstr); to read: if ($q->param('privatecomment')) { $comment->privatecomment('yes'); } else { $comment->save; $comment->privatecomment('no'); $app->rebuild_indexes( Blog => $blog ) or return $app->error("Index rebuild failed: " . $app->errstr); $app->rebuild_entry( Entry => $entry ) or return $app->error("Rebuild failed: " . $app->errstr); } This checks the setting of the private comment flag and only saves the comment and rebuilds the site if it’s turned off. You must also make sure that “Email new comments?” in your Blog Config is turned on, otherwise private comments will just disappear into the ether. For an extra piece of niceness, after the lines: Name: @{[ $comment->author ]} Email Address: @{[ $comment->email ]} URL: @{[ $comment->url ]} add the line Private comment: @{[ $comment->privatecomment ]} This indicates, when a comment is sent to you, whether it was a private comment or not. And that should be it. Note that, as said above, if the comment gets previewed it will forget your “private” setting. This is because to remember it I’d have to create an MTCommentPreviewPrivate tag, and I haven’t had time to do this yet. Moreover, I think I’m coming around to deciding that this whole magic-tags feature of MT’s templates is broken. I mean, it’s just Cold Fusion all over again, isn’t it? I can understand a simple tag which is substituted with text, no problem, but doing programming stuff (if statements, loops) with tags was broken when Cold Fusion did it and is still broken now. I personally think that MT should allow you, if you know what you’re doing, to embed some kind of programming language into pages; whether Perl or some kind of tiny custom scripting language, it would give so much more power to template writers. I feel some kind of essay coming on…

More in the discussion (powered by webmentions)

  • (no mentions, yet.)