NunoNunes.org

Loading
Entries by year
2010
Months
Jan
Entries by month
January
Sun Mon Tue Wed Thu Fri Sat
         
5
           
Powered by Blosxom
Creative Commons License

Blosxom plugin for Disqus feedback system

This is a plugin that I concocted for enabling the usage of the Disqus 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 feedback 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: disqus
# Author: Nuno Nunes <http://nunonunes.org/>
# Version: v0.01  2010-01-05
# Documentation: See the relevant sections of this file or type: perldoc disqus

package disqus;

# --- Configurable variables -------------------
#
# What is your username on Disqus (the one that should appear
# on the javascript section of the HTML pages)?
$disqus_username = 'nunonunes' unless defined $disqus_username;
# 
# Message to display if feedback (comments and trackbacks) is not allowed 
# on a story.
$feedback_not_allowed_message = 'Feedback has been disabled for this page'
   unless defined $feedback_not_allowed_message;
#
# ---------------------------------------------

# Use $disqus::comments and $disqus::comment_count in your story template.
# Use $disqus::footer in your footer template.

use vars qw{ $footer $comments $comment_count };

sub start {
  1;
}

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

  my $feedback_allowed = 1;
  $feedback_allowed = 0
    if (defined $meta::allowfeedback && $meta::allowfeedback =~ /^n/i);

  if ($pagetype::pagetype eq 'story') {
    $comment_count ="";
    if ($feedback_allowed) {
      $comments = <<COMMENTS_THREAD;
<div id="disqus_thread"></div>
<script type="text/javascript" src="http://disqus.com/forums/$disqus_username/embed.js"></script>
<noscript><a href="http://disqus.com/forums/$disqus_username/?url=ref">View the discussion thread.</a></noscript>
COMMENTS_THREAD
    }
    else {
      $comments = $feedback_not_allowed_message;
    }
  }
  else {
    $comments = "";
    $comment_count = "";
    if ($feedback_allowed) {
      $comment_count = "$permalink::story#disqus_thread";
    }
  };

  1;
}

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

  $footer = <<FOOTER_END;
<script type="text/javascript">
//<![CDATA[
(function() {
    var links = document.getElementsByTagName('a');
    var query = '?';
    for(var i = 0; i < links.length; i++) {
    if(links[i].href.indexOf('#disqus_thread') >= 0) {
        query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
    }
    }
    document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/$disqus_username/get_num_replies.js' + query + '"></' + 'script>');
})();
//]]>
</script>
FOOTER_END

  if ($pagetype::pagetype eq 'story') {
    $footer = "";
  }

  1;
}


1;

=head1 NAME

Blosxom Plug-in: disqus


=head1 SYNOPSIS

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

Requires the permalink and pagetype plugins 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 99disqus does the trick --read the bloxsom plugin documentation
if you require further assistance).

You need to have the permalink 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.

    You also need to have the pagetype plugin installed and have it run before
    this one, just like the permalink plugin above.

=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 Disqus and filled in all the variables to 
be configured at the top of this plugin, just put the $disqus::footer in your 
foot flavour template, near the end.

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

Feedback (both comments and trackbacks) is 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-variable
meta-allowfeedback as exemplified below:

----------
My great story's name
meta-allowfeedback: no

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

Any value you assign to this variable starting with the letter n turns it off 
and anything else (including not setting the variable at all) turns it on.

=head1 BUGS

Bug reports and comments may be sent to nuno@nunonunes.org.

=head1 CHANGELOG

2011-03-21 - Fixed some typos and bugs that were helpfully pointed out by 
             Christian G. Warden.

2010-01-05 - First implementation.

=head1 AUTHOR

Nuno Nunes <http://nunonunes.org/>

=head1 LICENSE

This Disqus Plug-in
Copyright 2010, 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.

About this entry

Originally written on Jan 05, 2010 @ 22:33
Read article on it's own page (permalink)

The content of this site is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.