Edit: I was really shocked to see how little interest there was in this snippet over the past couple of days. I really thought more people would want to be able to view their visitor’s comments as collapsible folders in their document tree, for easy viewing, editing, and deleting. In addition, formatting comments to a template on the way into the DB, so that their style is semi-hardcoded, is, IMO, contrary to the spirit of MODx, which is a great, open, flexible platform that let’s you do practically anything you want at anytime. That’s why I changed the UserComments snippet to format to a specified template on the way to the page.
I’m wondering if perhaps the name of the snippet was misleading. So I’ve changed it from UserCommentsDB, to UserCommentDocs.
I’ve done some major modifications to the UserComments snippet. UserCommentsDB has the following features:
- Comments are stored in a folder underneath the designated folder, or underneath the document if no folder is specified.
- Each comment is stored as a separate document in the folder which corresponds with the appropriate document. This is the main reason why I altered the snippet. This makes comments much easier to edit and delete when necessary.
- The comment folder and the comments are stored as unpublished, so that they cannot be viewed directly, even if the address is entered manually. The snippet however, looks for comments as unpublished, so they can be listed on the document they belong to (or any document that calls them through the snippet).
- Comments are formatted to the template on the way out of the database, not on the way in.
- The default form contains an author field, so that non-members can comment without having to be anonymous. I plan to add a condition to the snippet which makes the author field uneditable with the name of the signed in user if the user is logged in.
- The author field is stored as the description of the document for the time being. I don’t know of a better way to do this without altering the database. Suggestions are welcome, but I think this suffices.
- If the user is signed in, their ID is assigned to the ’createdby’ field of the comment document.
There may be some other features and differences I haven’t mentioned, but I commented my changes pretty extensively, and I’ll answer any questions.
This snippet has only undergone minor testing. I whipped it together pretty quick this evening, and I’m actually in a hurry to hit the sack. Please run this through the gauntlet and let me know about any problems or concerns you have. You’re also, obviously, welcome to make alterations yourself and post suggested revisions.
As far as I know, I’ve kept the functionality of all the parameters of the original snippet. Let me know if you notice any parameters that are broken.
One major point I need to mention is that I did not use the UserComments snippet that emails notifications. I think this needs to be added to the snippet, and if someone doesn’t beat me to it, I will have it added soon.
For now, I’m tired, it’s late, my wife is very attractive, so I’m off.
Edit: I’ve revised the form template so that it uses divs instead of spans. I realized that this made the form look strange until it was styled. Divs keep the standard look of a form going, even without styling. So I advise downloading version 0.2 with this minor change.
Edit: Found another silly bug; left the subject tag replacement line out of the template formatting code. I’m going to remove all versions except the latest, which works the best.
Edit: Found a couple more small bugs. I had inadvertently broke the [+altrow+] and [+authorclass+] tag replacement lines. Fixed now.