PapaScott I like big blogs and I cannot lie! 🐘

15 Minutes of Concentration

Whenever I try to get any work done at home while watching Christopher, I have to think of an article by Joel Sponsky where he writes that it takes (at least) 15 minutes for a programmer to start concentrating on solving a problem, and that with every interruption, you have to start that concentration time over from zero. How often does a 4-year-old leave a parent alone for 15 minutes? Yes, my point exactly.

With that in mind, below is the Movable Type 3.x plugin for which I've been trying to write a front-end. It emulates the WordPress function in which you can automatically moderate a comment with several hyperlinks. Save this as MT_DIR/plugins/modhref.pl, and set $maxhref to the maximum number of links you want to allow.

Once I was half-way done, I saw that it would pretty much be a knock-off of Chad Everett's Moderate plugin, just using a different critereon for moderation (Moderate checks the age of the posting and the lastest comment for the post, and moderates if either is too old). The criteria could probably be combined into a single plugin to perform simple tests on comments not explicitly banned by MT-Blacklist.

# Modhref: Moderate comments with too many links.
# A Plugin for Movable Type
package MT::Plugin::Modhref;
use vars qw($VERSION);
$VERSION = '0.01';
use strict;
use MT;
use MT::Comment;
use MT::Plugin;
# configuration variables (TODO put into CGI interface)
my $maxhref = 4; # maximum number of links before a comment is moderated
my $reg_ok = 1;  # pre-approve registered commenters?

my $plugin = new MT::Plugin({
  name => 'Modhref',
  description => 'Moderate comments with too many links.',
  doc_link => 'https://www.papascott.de/'
});
MT->add_plugin($plugin);
MT::Comment->add_callback('pre_save', 10, $plugin, &modhref);
sub modhref {
  my ($eh, $obj) = @_;
  my $count = 0;
  unless ($obj->id) { # only check new comments
    # don't check registered comments unless we say so
    return if ($obj->commenter_id && $reg_ok); 
    my $text = $obj->text;
    $count++ while $text =~ /<a [^>]*href[^>]*>/gi;  # count links
    $obj->visible(0) if ($count > $maxhref); # moderate if we find to many
  }
}
1;
comments powered by Disqus