spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / perl / simple comments

Simple Comments

A basic, Perl-based comment system for static Web pages

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

By Dan Ragle

Current release: v.962
Release date: July 29, 2008
Download

On this page is a collection of information pertaining to WebRef's Simple Comments Perl script that allows you to implement a basic comment posting system on the static pages of your Web site. Here you'll find the latest Simple Comments zipped distribution file, a link to the latest changelog (included in the distribution), basic features and requirements of the system, links to the individual release notes, and whatever else I can think of. To get started with Simple Comments, I recommend that you read this page in its entirety. While not mandatory, the release notes for the versions also provide some potentially helpful bits of information--especially from a developer's perspective--and may be beneficial both from an implementation and an educational perspective, i.e., even if you aren't interested in using the Simple Comments script, you may be interested in reading some of the developmental issues I've encountered while developing it; points that are elaborated upon in the release notes.

Contents:

Features
Requirements
Test Page
Downloads
Setup
Release Notes

Features

The key features and capabilities of the most recent version of Simple Comments include:

Requirements

To set up and use this system, you'll need Perl 5.6 or later installed on your server, the Apache Web Server with executable includes enabled (the ability to execute a Perl script when called in the HTML file as an include, see the setup instructions) access rights to create a directory outside the Web server's document root on your server, and access to place scripts into your cgi-bin. Basic Perl savvy and comfort in tossing files around on your Web server (as well as setting their access rights) will also be needed.

Though optional (beginning with .910), access to a password protected area (via Apache access controls) within your cgi-bin is also recommended; preferably reachable via an SSL server.

You will also need the following Perl modules installed on your system:

All but the HTML::Template module are typically installed with your Perl distribution; HTML::Template (and any others that may be missing) you can pick up from CPAN. XML::Simple is sometimes missing; if so, you may need to install both XML::Simple and XML::Parser (which XML::Simple relies on).

The following modules are recommended for use with OpenIDs (i.e., if openid_enabled is set to 1), and may in fact be required for use with some OpenID providers:

To use CAPTCHAs in your comment submission form, you need to decide whether you prefer to use the captchas.net system (see http://captchas.net) or the recaptcha system from Carnegie Mellon University (see http://recaptcha.net). If you select the captchas.net system, then you must first register with and receive a user-id and shared secret from http://captchas.net. If you select the recpatcha system, then register on the http://recaptcha.net site. Registration for both systems is free as of this writing; though both request that you warn them if your usage will be somewhat high (50k+ hits a day for captchas.net, or 100k+ hits a day for recaptcha.net). Once you've registered, you can then enable CAPTCHAS by including the appropriate _captcha and/or recaptcha_ parameter settings in the config.xml file.

To enable administrator notifications (the notify_admin_on_submit and notify_admin_on_visitor_confirm options) the Web user account (the account used by the Web server to perform system operations) must have access to sendmail. Additionally, sendmail access is required to enable the visitor registration system, since non-OpenID visitors are required to confirm their E-mail addresses as part of the registration process.

The comments script will work in both a standard and mod_perl enabled Web server.

Test Page

Want to submit a test comment? On most pages of our site (including this one) we'll only publish comments that actually pertain to the article, so you can't enter stuff like test comment or hello world. On our Test Page, however, we'll let you get away with those types of comments.

The test page also shows you what the comment display templates look like "out-of-the-box," i.e., the comments are displayed on the test page with the same templates in the Simple Comments distribution file (for the comments that appear on other pages of our site, we've modified the templates to match the WebRef look and feel). You can access the test page by clicking on the following link:

Simple Comments Test Page

Downloads

You can download the latest version of Simple Comments by clicking this link: comments.zip. The download is provided as a zipped file; use your favorite extractor to unzip it.

To view a list of changes from version to version, read the CHANGES.txt file.

Setting Up Simple Comments

Refer to the Readme.txt, included in the Zip distribution, for setup instructions.

Release Notes

These articles contain notes pertaining to each individual release of Simple Comments. Developers who are learning Perl may find these release notes of interest. The first release article (v.902) includes much of the information on this page, and also discusses the basic architecture of the scripts. Later release articles focus on new features, documentation of fixed bugs, and/or technical points of interest within the new release itself.

User Comments Submit | Register | Login Comment Feed RSS 2.0
89. Dan Ragle
Admin
08/29/2008 02:35PM

39 total posts | view profile

Great, Thomas, glad it's working for you!

Yeah, the executable directory thing is definitely worth mentioning in the access rights section of the docs. I'll see about making that adjustment for the next release.
85. Thomas
08/29/2008 02:04AM
your knee jerk guess seems close..

Hi Again Dan,

error log entry:

Cannot create user submission data log.

[Note: I edited the above to remove server-specific information - Dan]

The users direcctory is RW for the webservers UID.

the file submit.log was not present, so I created it, making it RW as well for the web servers UID.

but no joy.

I set the submit_threshold to 0, and got an error indication on teh web (no error entry in the error.log file)

The error page was :

"Error in Comment Processing
We're Sorry, but ...

ERROR: could not store comment (wait)

For your records, ..."
82. Dan Ragle
Admin
07/29/2008 01:04PM

39 total posts | view profile

v.962 Available

v.962, with a single bug fix, is now available. The bug had to do with which display name was saved on new OpenID logins that used an OP identifier (for example, if the user provided yahoo.com as their OpenID, and then chose their actual OpenID to use when they authenticated to Yahoo). V.961 was using the originally provided ID (yahoo.com, in this example) as the user's display name, instead of the OpenID that the user selected when they logged in; which would then cause confusion for the next person who tried to login using yahoo.com.
81. Dan Ragle
07/23/2008 09:17AM

39 total posts | view profile

V.960/V.961 now available

Hi folks,

Just a quick note to let you know v.960 (actually v.961 now) is now available. Key new features include OpenID support, header/footer templates, and support for article locking. Have a look, and enjoy!

Simple Comments v.960 release notes
77. david
06/26/2008 03:15AM
visitor registration

Hi Dan, congratulations on that impending 0.96.

I recently found that visitors could register and log in BEFORE completing the registration by clicking on the confirmation code. Registration is set to automatic, meaning not requiring my approval. I have looked through your config and do not see anywhere that allows this to be a choice. Obviously this means that a visitor can use a spurious email to register.

Can you confirm this?
78. Dan Ragle
Admin
06/26/2008 03:51PM

39 total posts | view profile

*sigh* That's another bug.

The way it was supposed to work was that yes, the user could log in prior to confirmation (only if you have require_registration_approval set to 0); but they couldn't actually do anything as both view_profile and comment submissions were supposed to be blocked for the user. In retrospect it looks like view profile is behaving correctly (it just acts like the user doesn't exist) but comment submissions are allowed which is a definite error. I'll get that cleaned up in .960.

In the mean time, if you wanted to prevent comment submissions from unconfirmed users you could just make this mod in Comments.pm:
if (($visitor->status eq 'blocked') ||
         ($visitor->status eq 'deleted')) {
   return 'Sorry, this account has been ' . $visitor->status .
          '. Please contact our administrator for assistance.';
}
elsif ($visitor->status eq 'new') {
   return 'Sorry, this account has not yet been confirmed.';
}


If you wanted to prevent them from logging in entirely, you could make mods to check_login in comments.pl; but you'd have to make several adjustments there.
79. david
06/26/2008 09:07PM
Dan, thanks again. I would suggest, if you are working on this, to disallow logging in if not active. This is because the visitor might not realize the need to activate until much later if they don't immediately comment. They log in just to ensure they are properly registered. By then the email for activation might have been lost. Another possibility is wrongly typed but valid email addresses. Registration goes through (they can log in) but they cannot find the activation email.

Preventing these visitors from commenting is not a big deal - for some reason your program thinks they are not logged in and so the comments need my OK. I have publish on submit=0 and publish visitor comments on submit=1. This was how I caught the bug BTW. My main concern right now is that the system does not weed out wrongly typed but valid/spurious email addresses. Correcting these later is messy.
80. Dan Ragle
Admin
06/27/2008 11:12AM

39 total posts | view profile

Agreed; in retrospect I can't think of a good reason why non-active accounts should be allowed to login. I've already made the change in the .960 code.

Cheers!
76. Dan Ragle
Admin
06/25/2008 04:41PM

39 total posts | view profile

Version .960 on tap

Hay everybody,

Just a quick note to let you know I've got version .960 up here on WebRef as a final test (the download version is still .950, but I'm running v.960 on the actual WebRef pages and on the test page). The primary new feature is OpenID support; but several other suggestions have been incorporated as well.

I hope to have release notes and the download file available in the next week or so. Stay tuned!
71. nicku
06/19/2008 06:10PM

3 total posts | view profile

Basic Authentication and Comment Submission

Dear Dan,

Thank you for a very nice piece of work.

I have written a program (mm_htaccess) to generate password files from Mailman passwords. I would like to use Apache Basic authentication to authenticate people submitting comments. Do you have a suggestion on how to go about that?

I was thinking of splitting comments.pl into two separate programs, one to display comments (to all visitors), and one to add new comments (made by authenticated visitors). Do you have any simpler suggestions?
72. Dan Ragle
Admin
06/20/2008 05:33PM

39 total posts | view profile

Hi nicku,

Do I understand you correctly in that you do not want visitor registrations (per se), you just want to force all submitters to pass through your Apache-based authentication prior to allowing comment submissions?

Short of editing the code I can't think of a graceful solution. You would have to post two separate copies of the script, as you suggest, but if you only do that you would not stop the bad guys from submitting comments (from their own manually crafted forms) to the public copy of comments.pl (and they could probably find where it was easy enough; since various actions--such as RSS feeds--require it to be hit directly).

So you would probably want to additionally make some slight modifications to the public version of the comments.pl, to make sure that only logged in users could submit comments. One idea that comes to mind is to just de-list the add, review, and submit actions; i.e., change this:
my @all_actions      = qw(add display review submit clear rss);

to this:
my @all_actions      = qw(display rss);

That's untested, but it should work. Unfortunately it will also disable user registrations in the public copy of the script; but if I'm reading you right you won't need those, anyways.

The other trick is that you will need to adjust the comment submission form so that it points literally to the private copy of comments.pl; otherwise it will pull the location of the comments script from the config file (which you should have set to the public comments.pl) and therefore won't actually allow any comment submissions!

Good luck!
73. nicku
06/21/2008 03:00PM

3 total posts | view profile

Thanks Dan, I've done it now.

Dear Dan,

Thank you very much indeed for your help.
I have done most of the work, and it seems to be working. I have more to do, and also intend to get the XHTML strict and CSS all validating again.

I also fixed one bug in Comments.pm: get_article_name(), where I simply added /s to the regular expression to allow titles that cover more than one line.

Can I make the code I have changed from yours available for download from my web site with attribution to you? May I make it available with a GPL license?
74. Dan Ragle
Admin
06/23/2008 09:38AM

39 total posts | view profile

Great, nicku, glad it's working for you. And thanks for the heads up on get_article_name, I hadn't considered multi-line titles. I should be able to get that fix added to the next release.

For now, I'd prefer you just link back to this site for the attribution, as opposed to posting your own version, if you don't mind. As you can tell, we haven't really settled on a license scheme for the code yet, so I don't think it would be appropriate to post a GPL version somewhere else. I have nothing against the GPL, but this code belongs to my employer, and as such I cannot make any forward-looking promises pertaining to future licensing.

Of course, if and when there is any change or concrete forward direction on licensing, I'll post it up here so that everybody will have the scoop.
75. nicku
06/23/2008 04:47PM

3 total posts | view profile

Thanks again, Dan.

Thank you for your response. And thanks for the good example of your code. I have learned much about using HTML::Template from your approach. I understand the nature of your problem with licensing and your employer, and you have my sympathies.

Because I like to use free software, and to make available the code I use and write, I hope to write a totally new comment system to meet my rather simple requirements, and publish that instead. It's just that it will take a lot more effort.
68. david
06/08/2008 01:55AM
error message

I have been consistently getting these error log messages recently: "Use of uninitialized value in string eq at /xchange/websites/www/cgi-bin/comments.pl line 1506". Using your original scripts made no difference, so I don't think it is because of changes I have introduced. Everything works, just has the error message in my error log. I don't have a similar error log message on my actual website (this error is on my home computer), leading me to think that this is because of a recent upgrade to perl 5.10. Any thoughts?

ps: that global comments page worked nicely... :)
69. Dan Ragle
Admin
06/09/2008 09:34AM

39 total posts | view profile

That's a bug. Harmless, other than filling your log with messages. To patch it, find this:
   if ($cgi->param('action') eq 'profile_logout') {

and change it to this:
   if ($cgi->param('action') &&
       ($cgi->param('action') eq 'profile_logout')) {

(careful with the parentheses).

Which machine was upgraded to 5.10, your Web site or your home machine? Now that you point it out I am seeing the error in a 5.6 log, but not in a 5.8 log.

Cheers!
70. david
06/09/2008 11:50AM
OK, thanks. :) Bugs just bug me, even when everything works and they are harmless. :) My home system was upgraded to 5.10 and logged the error. Not sure which perl my actual website has, but no error logged there.
65. david
05/27/2008 04:09AM
RSS and others

Dan, I notice the RSS option available. Does it take up much server time?

I am trying to find a way to consolidate all comments in different articles into 1 file (while keeping the current scheme as well). This way I can publish "recent comments" perhaps with link to related article on the front page.

One way I am exploring is that currently publish visitor comment on submit is ON. And I can amend the program so that it will ALSO write to waiting file. And if I can amend the "process waiting comments" subroutine to write to a specific xml file (instead of article name file) then I can have both worlds. Do you think this is workable? Or is there another way I can achieve this?
66. Dan Ragle
Admin
05/27/2008 09:51AM

39 total posts | view profile

The RSS file is produced in the same way that the in-page comments are; they're just outputted in a different format (and the content-type is set accordingly). So in terms of the juice it takes to create the file, it should be the same as it would be to display them within a page.

As far as creating a "global" recent comments RSS feed, I can't think of any built-in way to accomplish it, so you're method sounds like a reasonable approach. I think the way I would hack it in, though, is:

- Create a "dummy" page on your site that has a title descriptive of the global comments content (i.e., this title will be used in the resulting RSS file). You can always put this in a password protected area of the site, if you don't want people to find it (they don't have to have access to it, since it's just serving as a locatable container for the comments system).

- Adjust the write_live_comment routine in Comments.pm to write the comment (exactly as is) to both the original target file, and to this dummy file. I.E., right after this code:
      seek $livefile, 0, 0;
      print $livefile $live_comments;
      truncate ($livefile, tell $livefile);
      close $livefile;

add the code to open the dummy file's XML, read in the contents, push the new comment onto the stack, sort the stack, and write the result. All the necessary logic for that is already in write_live_comment, you would just need to piece it together to duplicate the work for the dummy file, instead. You wouldn't need to duplicate all the logic to for duplicate checking, or writing the comment to the user profile, etc. I like putting the adjustment in write_live_comments because that way you should get all of 'em; whether they were moderated, posted directly from the user, or admin replies.

- Adjust the RSS print routine in comments.pl to rewrite the feed link (in the comment loop) such that it is built individually per comment. Currently, it assumes the link to be provided for all comments is the same (differentiated only by comment number), since the current routine assumes that all the comments in a file--and thus an RSS feed--belong to the same article. Without this adjustment, all the links in the global RSS feed would point to the dummy file, instead of to their actual files.

Then you can "publish" the article file by just posting a link to comments.pl passing the action type of rss and the article key of your dummy file (see any existing RSS link on your site for the correct format). I think. From looking through it this morning I believe that's all you would need to do, but of course you'd have to test it out to be sure.

Of course, this will double your disk space; but the alternative of reading the files individually when the RSS file is built isn't pretty response-wise (that WOULD take a lot of time).

There are other issues with this that you might need to address depending on how thorough you want to be; such as tweaking the delete and edit routines in the maintenance screens to delete the matching comments in the dummy XML file, too; and/or somehow automatically cleaning the dummy XML file from time to time (since it will accumulate a copy of all comments in the system).

Good luck!
67. david
05/27/2008 11:04PM
Thanks, Dan. You have always been very helpful. And yes, I need all the luck I can get! :)
previous comments    next comments 

Please review our Comment Submission Policy before submitting comments to our site.
Your name:
 Your E-mail:
* Your URL:
* Your Subject:
(Maximum characters allowed: 200)
Your comment:
(Maximum characters allowed: 5000)
CAPTCHA Verification
Please enter the code displayed to the right in the box below:
CAPTCHA Image
Hear it!
  

* = optional field


home / programming / perl / simple comments

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: September 13, 2006
Revised: August 1, 2008

URL: http://webreference.com/programming/perl/comments/index.html