I can't tell you how many times I've left a comment on a blog, and even though I had previewed it, noticed about ten spelling errors just as soon as I pressed the 'submit' button.
I decided to fix this problem, at least on my blog, by letting users modify their comments for a designated period of time. I decided to share the code in case anyone else wants to implement this. It works directly with the MySQL database, so obviously it requires a MySQL-powered Movable Type blog.
Features
* Set the number of minutes your users have to go back in and edit their comments
* Set an optional maximum number of edits for any one comment
* Comments will have the time of the edit added to the bottom (but this text will be stripped out from the user's view if he/she goes in again to edit)
* Authentication based on IP address, so users don't have to set or remember a password
* Easy to integrate with existing before/after PHP includes system you may be using
* While users are editing their comment, they see a timer that counts down how much editable time they have remaining, and pops up a warning when they have 30 seconds left (although it's a bit of a white lie, they really have 60 seconds left at that time)
* PHP code included in readme for inserting the "Edit This Comment" PHP code into your Movable Type templates so that the link will only show up next to the user's own comments, while they are still editable
* NO hacking of Movable Type code required
Requirements
* Movable Type 2.64 or higher (possibly works on older versions)
* MySQL database system being used for Movable Type installation
* PHP enabled on web server (version 4.3.0 or higher would be nice… it's been tested on 4.3.4)
* PHP enabled on entry pages (for dynamic displaying of the "Edit This Comment" link)
Download
Latest version of user_editable_comments;
Installation
1. Open up editcomment_settings.php
– Enter your database information
– Enter in your timezone offset. This is used it your server's timezone
doesn't match the timezone as set in your blog. If your server is set
to -05 GMT (eastern time) but your blog is set to -06 GMT (central
time), you'd set this to -1.
– Enter in the future location of your mt-rebuild-entry.cgi file.
It goes in the same directory as your main Movable Type CGI files.
http://www.yoursite.com/cgi-bin/mt/mt-rebuild-entry.cgi is a common
one.
– Change your comment editing settings, $minutes_until_lockout is
required, and will control the amount of time your users have to
edit their comments. $max_edits is optional, and will limit users
to a certain number of edits within the $minutes_until_lockout time.
– Set your include/insert settings. There are three types:
'before,' 'after,' and 'before_modify,' and they each come in include
and insert flavors. 'Before' is put in before the form, 'after' is put
in after, and 'before_modify' is put in right before the entry edit
textarea and will only show up when an entry is called up. This would
be a perfect place to put some clickable smilies code.
– For the JavaScript countdown timer to work, you must either place the
following line within an included $include_before file within the HEAD
section: <script type="text/javascript" src="js_countdown.js"&rt;</script&rt;
You can also put that reference within the HEAD section if you are using
$insert_before, or in either case, you can copy the contents of
js_countdown.js and paste them in the HEAD section between SCRIPT tags.
– Save the changes you have made to editcomment_settings.php
2. Decide on where you want the script to go (site root is fine, but you
may want it in a subfolder). Upload to that location the following files:
– editcomment.php
– editcomment_settings.php
– js_countdown.js
3. Upload mt-rebuild-entry.cgi to your main Movable Type CGI directory.
Set the file's permissions to match those of mt.cgi
4. You can now access the comment editing script by typing in the location
of the editcomment.php script followed by ?comment_id=X where X is a
valid comment ID. But the coolest thing to do is to add "Edit This
Comment" links next to comments before they've expired. You can do that
with this PHP code:
<?php
if ('<$MTCommentIP$>' == $_SERVER['REMOTE_ADDR']){
$user_edit_link = ' | <a href="http://www.txfx.net/php/editcomment.php?comment_id=<$MTCommentID$>">Edit This Comment</a>';
$c_date = array(<$MTCommentDate format="'%H','%M','%S','%m','%d','%Y'"$>);
for($i = 0; $i < 6; $i++){
preg_match("/(0*)(.*)/i", $c_date[$i], $match);
$c_date[$i]= (int) $match[2];
}
$date_difference = mktime() – mktime($c_date[0], $c_date[1], $c_date[2], $c_date[3], $c_date[4], $c_date[5]);
if (floor($date_difference/60) < 30) {
echo $user_edit_link;
} // end if 30 minutes has passed
} // end if IP address matches
?>
This can go anywhere within the <MTComments> </MTComments> tags, but
it will look the best if you place it like so:
<span class="comments-post">Posted by: <$MTCommentAuthorLink spam_protect="1"$> at <$MTCommentDate$>++CODE GOES HERE++</span>
And then you should be ready to go!
If you have any comments, suggestions, bug reports please email me!