X-Comment
<< X-Gallery | Cookbook-V1 | Comments >>
Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
Introduction
X-Comment allows you to place a comment form any where on your WikiPage. Users can leave comments using the form (instead of editing the page in the usual way). Comments are appended to the bottom of the page, just below the comment form. Newest comments are listed last.
Goal
Actually, the purpose of this add-on was to add commenting ability to my X-Gallery? script. I wanted a very slim, and light-weight method for users to leave comments, so I wrote this script.
Features
- WikiMarkup is supported
- The form is templated for easy customization
- CSS is also supported for a fancier looking form
Download & Installation
- Download the file Attach:x-comment.php.txt
- Rename the file to
x-comment.php
on your system - Place the file in your
local/scripts
directory - Add this line to your config.php
include_once('local/scripts/x-comment.php');
- That's it!
Usage
Just put the <#>?
directive anywhere on your WikiPage. It will be replaced with the comment form. You can include any WikiMarkup that you would normally include while editing pages.
Customize It
There are two parts you can customize, the comment form itself, and how the comments will be displayed.
Customizing the Comment Form
If you can understand html, then you can probably customize this form pretty easily. Only thing to note is the use of some internal php variables contained in the $xCommentParams array. These are optional, you can hard-code what you like; reason I used variables here is for a future release that I'm working on that will take parameters from the user. For example, user might be able to specify [[x-comment: width=50]] to make a comment form with a width of 50 characters on the page. Other user-configurable variables might include bgcolor, height, and text labels.
$xCommentVars['form_template'] = "<table align=center style='border:1px solid black; background-color:#FFC000;' width='100%'> <form action='\$PageUrl' method='post'> <tr> <td class='x_comment' align='right'>Put your comments here</td> <td><textarea name='text' rows='" . $xCommentParams['height'] . "' cols='" . $xCommentParams['width'] . "' wrap='" . $xCommentParams['wrap'] . "'></textarea> </td> </tr> <tr> <td class='x_comment' align='right'>Sign your name here</td> <td><input type='text' name='author' value='' size='32' /> <input type='submit' value=' Post ' /> <input type='reset' value='Reset' /> <input type='hidden' name='pagename' value='$PageName' /> <input type='hidden' name='action' value='post_x_comment' /></td> </tr> </form> </table>";
Customizing the Comment
You can also customize the way the comments are output. I won't go in to any great detail about how to do this because I think the example below is pretty self-explanatory. The output uses basic PmWiki markup.
$xCommentVars['comment_template'] = "\$Comment[[<<]] [+-\$Author+] [-(\$Date, \$Time)-] ---- [[x-comment:]]";
Limitations
You can't use this form in your GroupHeader or GroupFooter because of the way it works. It looks for the <#>? directive so it knows where to start adding the next comment. Since the directive won't appear in the page itself (but in the Header/Footer), it won't be found, thus, the comment won't get added.
I changed a bit of code (at line ~94) to make it possible:
if (strpos ($text, "[[x-comment:]]") === false) { $text = $text."\n----\n".$comment."[[<<]]%gray%[-[=-".$author."-][-("=] ^ This should be: $text = $text."\n----\n".$comment."[[<<]]%gray%[-[=-".$author."-][-(=]" -- Christian Helft - June 30 2004 .$date.", ".$time.")-]%%"; } else { $text = preg_replace("/\\[\\[x-comment:(.*?)\\]\\]/", $template, $text); }
If markup for X-Comment not found, add comment at end of page, otherwise proceed old way. Not the best implementation but an easy workaround for header/footer usage.
Greetz Mazet
Customization can only be done directly in the x-comment.php file. Setting the variables in config.php does not work. Also if an edit password has been set within PmWiki, you have to enter it before a comment could be added -- Klonk
- You can quite easily allow comments on a locked page by replacing
HandlePost($pagename);
withHandlePostNoAuth($pagename);
and adding Attach:handle-post-no-auth.txt to your X-Comment script. HandlePostNoAuth is an adaption of HandlePost to allow postings without authentication. The code even adds an entry to RecentChanges. --thom
See also
There is another comment/guestbook script available in the Cookbook. It's a bigger script, but it has more features, so if you are looking for something with more configuration options, you might give that a try.
Copyright
Script written by Steven Leite. This script is release under the same terms and conditions as PmWiki (GNU GPL). pmwiki-2.3.38 -- Last modified by {{Ian MacGregor}}