Because of the complicated logic necessary to integrate TypeKey authentication into MT3D's template code for comments, a new template tag was created to automatically generate all of the necessary code - <MTCommentFields>. This new tag can be seen on the default Comment Listing, Comment Preview, and Comment Error templates for MT3D. Interestingly, this new tag was not used on the default Individual Entry Archive template.
Unfortunately, this tag has a few problems:
- Comment entry fields (Name, E-mail, URL, Comment text) are not remembered when a comment is previewed or a comment error occurs.
- Some of the code produced is not valid XHTML.
- The code produced cannot be edited, unless you're up to hacking /lib/MT/Template/Context.pm.
- There's actually two comment forms within the code; one is chosen for display depending on whether TypeKey registration is required. The forms are not identical, even taking into account the differences that should be there.
I liked the idea of the <MTCommentFields> tag, but not the fact that it was somewhat broken and extremely difficult to fix. So I came up with the following workaround until (hopefully) the next release of MT3 fixes these problems.
The first thing you need to do is to create a new template module in your weblog. Name the module "CommentFields". Click on or download the CommentFields.txt link, paste the code from that file into the Module Body, and save the module.
Next, you need to replace the <MTCommentFields> template tag with an <MTSetVar> and <MTInclude> tag to use the module code instead of the built-in MT code.
On the Comment Listing, Comment Preview, and Comment Error templates, locate the <MTCommentFields> tag and replace it with the code shown below.
The code below can also be used on the Individual Entry Archive template, but on that template, all of the code between and including the <MTIfRegistrationRequired> and </MTIfRegistrationRequired> tags (over 100 lines of code) needs to be deleted and replaced with the code below. Additionally the template code between and including the <script> and </script> tags immediately following the </MTIfCommentsAllowed> tag needs to be deleted as well.
The new code to replace the <MTCommentFields> tag:
<$MTSetVar name="preview" value="0"$> <$MTInclude module="CommentFields"$>
- On the Comment Listing and Individual Entry Archive templates, set the 'value' attribute in the <$MTSetVar$> tag to "0".
- On the Comment Preview and Comment Error templates, set the 'value' attribute in the <$MTSetVar$> tag to "1".
New addition for popup comments: The Comment Listing template requires one more MTSetVar tag to properly set the "static" parameter in its comment form and TypeKey links. Use the code below only in the Comment Listing template:
<$MTSetVar name="static" value="0"$> <$MTSetVar name="preview" value="0"$> <$MTInclude module="CommentFields"$>
Save the templates, and rebuild the Individual Entry Archives if that template was modified to use the CommentFields template module.
The code I supplied in the CommentFields.txt file fixes the Comment Preview problem, the obvious invalid XHTML I spotted, plus makes both comment forms in the code as nearly equal as I could make them. The code can now be edited (if you desire) by editing the CommentFields module instead of hacking lib/MT/Template/Context.pm.
I haven't thoroughly tested the code in all scenarios. It seems to work using MT3D's default of inline, non-dynamic comments (which is how I am using it now). This is something else that hopefully will be fixed in the next version of MT3, but the Comment Preview not remembering the fields really bugged me and I didn't want to wait for the next release of MT3.
I have mixed feelings on sharing it - it is a lot of code that may or may not work for everyone and there's a lot that can go wrong as someone tries to implement it. If you can use it and make it work, great! If not, I'll try to help the best I can but there's no guarantees.
Update 02-Jun-2004: I discovered something odd in the comment forms while I was writing a comment this morning. I wrote one HTML and one MT tag in the comment text, both surrounded by escaped angle brackets (< and >). When I previewed the comment, MT decoded the angle brackets so they were no longer escaped (< and >). If I previewed the comment a second time, MT's sanitize function removed the tags from the comment.
MT seemed to be performing a 'decode_html' on the MTCommentPreviewBody text. I added an encode_html="1" attribute to the MTCommentPreviewBody tag in each of the CommentFields module's forms to re-encode it back. With the encode_html attribute, MT no longer decodes HTML entities that are in the comment text when it is previewed.
Update 23-Jun-2004: CommentFields module code updated to (hopefully) work with popup comments:
- Requires addition of
<$MTSetVar name="static" value="0"$>tag to Comment Listing template. If tag is omitted (such as on Individual Entry Archive template), module code will use a default "static" value of "1".
- Module code now looks at <$MTCommentPreviewIsStatic$> tag on Comment Preview and Comment Error templates (where preview="1") to determine proper "static" value (so above MTSetVar tag is not required on Comment Preview and Comment Error templates).
- Links to sign in and out of TypeKey updated to properly reflect static value and return user to appropriate page after signing in and out.