Blosxom plugin for Haloscan feedback system

Posted on September 16, 2006

This is a plugin that I concocted for enabling the usage of the Haloscan on a Blosxom site.

It is perfectly possible to add this functionality just by tweaking the flavour templates, of course, but this makes it easier to use and also makes it possible to port existing sites to Blosxom and easily maintain the comments that may already exist.

It also allows for the individual turning on or off of both comments and trackbacks on a per-story basis.

I’ll probably add a zipped file with the plugin somewhere on the site, but for now the code is displayed right here on this page.

# Blosxom Plugin: haloscan
# Author: Nuno Nunes ([email protected])
# Version: v0.02  2006-09-15
# Documentation: See the relevant sections of this file or type: perldoc haloscan

package haloscan;

# --- Configurable varables -------------------
#
# What is your account name on haloscan (the one that should appear
# on the javascript in the 'head' section of the HTML page)?
$haloscan_id = 'nunonunes' unless defined $haloscan_id;
#
# Message to display if comments are not allowed on a story.
$comments_closed_message = 'Comments are closed for this page'
  unless defined $comments_closed_message;
#
# Message to display if trackbacks are not allowed on a story.
$trackbacks_closed_message = 'Trackbacks are closed for this page'
  unless defined $trackbacks_closed_message;
#
# ---------------------------------------------

# Use $haloscan::head in your head template.
# Use $haloscan::comments and $haloscan::trackbakcs in your story template.

#use strict;
use vars qw{ $header $comments $trackbacks };

sub start {
  1;
}

sub head {
  my ($pkg, $dir, $head_ref) = @_;

  $header = qq{<script type="text/javascript" src="http://www.haloscan.com/load/$haloscan_id"> </script>};

  1;
}

sub story {
  my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;

  my $story_id = $permalink::story;
  $story_id =~ s/$blosxom::url//;

  $story_id = $meta::haloscanstoryid
    if defined $meta::haloscanstoryid;

  my $comments_allowed = 1;
  $comments_allowed = 0
    if (defined $meta::haloscancomments && $meta::haloscancomments =~ /^n/i);
  my $trackbacks_allowed = 1;
  $trackbacks_allowed = 0 
    if (defined $meta::haloscantrackbacks && $meta::haloscantrackbacks =~ /^n/i);

  if ($comments_allowed) {
    $comments = qq{<a href="javascript:HaloScan('$story_id');"><script type="text/javascript">postCount('$story_id');</script></a>};
  }
  else {
    $comments = $comments_closed_message;
  };

  if ($trackbacks_allowed) {
    $trackbacks = qq{<a href="javascript:HaloScanTB('$story_id');"><script type="text/javascript">postCountTB('$story_id');</script></a>};
  }
  else {
    $trackbacks = $trackbacks_closed_message;
  };



  1;
}

1;

=head1 NAME

Blosxom Plug-in: haloscan


=head1 SYNOPSIS

Integrates the comment and trackback service provided by Haloscan 
(http://haloscan.com/) into blosxom.

Requires the permalink plugin and knows how to work with the meta plugin
if it is installed.

=head1 INSTALLATION

Fill in the configurable variables according to the instructions and
put the file in your plugin directory (just like any other plugin).

If you whish to use the meta plugin together with this one make sure
that the it is run before this one (renaming meta to 00meta and this
one to 99haloscan does the trick --read the bloxsom plugin documentation
if you need further assistance).

You need to have the pemalink plugin installed for this one to work and
it must run before this one does. You can use the same scheme as defined
for the meta plugin to that effect.

=head1 CONFIGURATION

Fill in the variables in the Configurable varables section of this file
according with the descriptions (which should hopefully be self-explanatory)
and if you have any doubts check out the usage section bellow.

=head1 USAGE

After having set up an account on Haloscan and filled in all the variables to
be configured just put the $haloscan::header in your head flavour template
anywhere inside the HEAD HTML element.

Then, on your story flavour template, drop the $haloscan::comments and
$haloscan::trackbacks variables wherever you want them to appear and that's it!

Both comments and trackbacks are enabled by default for all stories.
Should you wish to control this behaviour, you can do so on a story-by-story
basis using the meta plugin and assigning the meta-variables
meta-haloscancomments and meta-haloscantrackbacks variables as exemplified
below:

----------
My great story's name
meta-haloscancomments: no
meta-haloscantrackbacks: yes
meta-haloscanstoryid: 1115

This is a really interesting story...
----------

For any one of the meta-haloscancomments and meta-haloscantrackbacks variables,
any value starting with the letter n turns it off and anything else (including
not setting the vriable at all) turns it on.

The meta-haloscanstoryid variable allows you to retain story IDs for specific 
stories in case you're porting from a different blogging system or if you want 
your Haloscan story IDs to be generated some other way.

These three variables (meta-haloscancomments, meta-haloscantrackbacks and 
meta-haloscanstoryid) are optional.

=head1 BUGS

Bug reports and comments may be sent to [email protected].

=head1 CHANGELOG

2006-09-16 - Added the ability to import storyIDs from a meta-variable.
2006-09-15 - First implementation.


=head1 LICENSE

This Blosxom Plug-in
Copyright 2006, Nuno Nunes

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.