pyblosxom-disqus/disqus.py
author cavorite@cavorite.dactilofono
Thu Dec 25 14:02:43 2008 -0500 (19 months ago)
changeset 1 57126d5cb8a6
permissions -rw-r--r--
Updated description
     1 """
     2 This module enables support fot the Disqus comment system.
     3 
     4 This module requires the following configuration parameters:
     5 
     6     disqus_short_name - The short name of the website account 
     7                         in Disqus.
     8 
     9 The following parameters are optional:
    10 
    11     disqus_developer - A boolean value for allowing testing on a private 
    12                        server. See http://disqus.com/help/#faq-14
    13 
    14 The comments are enabled for the flavours that contain a template file named:
    15     disqus-enabled.
    16 
    17 For example, for enabling the comments for the flavour 'html', an empty file
    18 named 'disqus-enabled.html' must be created under the directory 'html.flav'.
    19 
    20 This program is distributed under the BSD license.
    21 
    22 """
    23 __author__ = "Juan Manuel Caicedo"
    24 __version__ = "0.1"
    25 __url__ = "http://cavorite.com/labs/pyblosxom-disqus/"
    26 __description__ = "Allows to use the service Disqus for comments on each blog entry."
    27 
    28 def cb_start(args):
    29     """
    30     Sets the defaults values for the optional configuration properties.
    31     """
    32     request = args["request"]
    33     config = request.getConfiguration()
    34 
    35     if not config.has_key('disqus_developer'):
    36         config['disqus_developer'] = False
    37 
    38 def verify_installation(request):
    39     """
    40     Verifies the plugin installation checking for the required configuration properties.
    41     """
    42     config = request.getConfiguration()
    43     retval = 1
    44     if not config.has_key('disqus_short_name'):
    45         print 'The "short name" of the Disqus account dmust be specified in the config file'
    46         retval = 0
    47 
    48     return retval
    49 
    50 
    51 def cb_story(args):
    52     """
    53     Adds the Disqus code for embedding the comments.
    54     """
    55     renderer = args['renderer']
    56     entry = args['entry']
    57     template = args['template']
    58     request = args["request"]
    59     data = request.getData()
    60     config = request.getConfiguration()
    61 
    62     if len(renderer.getContent()) == 1 \
    63             and renderer.flavour.has_key('disqus-enabled') \
    64             and not entry.has_key("nocomments"):
    65  
    66         short_name = config['disqus_short_name']
    67         template = '<div id="disqus_thread"></div>'
    68         if config.get('disqus_developer'):
    69             template = template + '''
    70             <script type="text/javascript" >
    71             var disqus_developer = 1;
    72             </script>
    73             '''
    74 
    75         template = template + '''<script type="text/javascript" src="http://disqus.com/forums/%(short_name)s/embed.js"></script><noscript><a href="http://%(short_name)s.disqus.com/?url=ref">View the discussion thread.</a></noscript><a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>''' % {'short_name': short_name}
    76 
    77         args['template'] = args['template'] + template
    78 
    79     return template
    80