Hi there,

The content on this blog is all archival, it's no longer active and you won't be able to post comments or trackbacks. If you're looking for active content from the same source, you should check out Nick's Vox blog.

« Two Days | Main | Apple-y Goodness! »

MT3 Comment Template Changes

April 22, 2004

There has been some confusion about the new comment template for MT3 and how it's similar and different to the last comment template. I've created this updated version (for the MT3D public release) that should shed some light on the process of converting your current individual archive pages (or wherever else your comments appear) to the new format.

For anyone who had their site templates done by someone else and for some reason can't get them to do it for them, I provide the service of converting your templates for a measly $20. Feel free to do it yourself - that's why I have this post here - but if you can't, you have another option. Find my email on the about page.

First of all, there are suble changes in the Athenia cookie script at the top of the page, I don't know if they're important changes but I'd use the newer one if I were you. It looks like this

<script type="text/javascript" language="javascript">
<!--

var HOST = '<$MTBlogHost$>';

// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") + (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
document.cookie = curCookie;
}

function getCookie (name) {
var prefix = name + '=';
var c = document.cookie;
var nullstring = '';
var cookieStartIndex = c.indexOf(prefix);
if (cookieStartIndex == -1)
return nullstring;
var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
if (cookieEndIndex == -1)
cookieEndIndex = c.length;
return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
if (getCookie(name))
document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
if (f.author != undefined)
setCookie('mtcmtauth', f.author.value, now, '/', HOST, '');
if (f.email != undefined)
setCookie('mtcmtmail', f.email.value, now, '/', HOST, '');
if (f.url != undefined)
setCookie('mtcmthome', f.url.value, now, '/', HOST, '');
}

function forgetMe (f) {
deleteCookie('mtcmtmail', '', HOST);
deleteCookie('mtcmthome', '', HOST);
deleteCookie('mtcmtauth', '', HOST);
f.email.value = '';
f.author.value = '';
f.url.value = '';
}

//-->
</script>


And that goes in the <head> section of your template.

There has been some confusion about the new comment template for MT3 and how it's similar and different to the last comment template. I've created this updated version (for the MT3D public release) that should shed some light on the process of converting your current individual archive pages (or wherever else your comments appear) to the new format.

<MTEntryIfAllowComments>

<h2><a id="comments"></a>Comments</h2>

<MTComments>
<a id="c<$MTCommentID$>"></a>
<$MTCommentBody$>
<p class="posted">Posted by: <$MTCommentAuthorLink spam_protect="1"$> <MTCommentAuthorIdentity> at <$MTCommentDate$></p>
</MTComments>

<MTEntryIfCommentsOpen>
<MTIfCommentsAllowed>

<h2>Post a comment</h2>


This first part simple introduces comments on your page and displays all the previously posted comments. The only new part is the <MTCommentAuthorIdentity> tag which displays the TypeKey profile icon and link if the poster was logged on to TypeKey.
The last part has two conditional tags (both of which are required if you want to be able to turn off commenting or close comments) and introduces the section of your site where people can post a new comment.

<MTIfRegistrationRequired>

<MTIfNonEmpty tag="MTTypeKeyToken">
<div id="thanks">
<p>Thanks for signing in,
<script type="text/javascript" src="<MTCGIPath><MTCommentScript>?__mode=cmtr_name_js"></script> <script>document.write(commenter_name);</script>.
Now you can comment. (<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=handle_sign_in» &static=1&entry_id=<$MTEntryID$>&logout=1">sign out</a>)</p>

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

<form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" onsubmit="if (this.bakecookie[0].checked) rememberMe(this)">
<input type="hidden" name="static" value="1" />
<input type="hidden" name="entry_id" value="<$MTEntryID$>" />

<p><label for="url">URL:</label><br />
<input tabindex="1" type="text" name="url" id="url" />
Remember me?
<input type="radio" id="remember" name="bakecookie" /><label for="bakecookie"><label for="remember">Yes</label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget">No</label><br style="clear: both;" />

</p>

<p><label for="text">Comments:</label><br />
<textarea tabindex="2" id="text" name="text" rows="10" cols="50"></textarea></p>

<div align="center">
<input type="submit" tabindex="3" name="preview" value=" Preview " />
<input style="font-weight: bold;" tabindex="4" type="submit" name="post" value=" Post " />
</div>
</form>

</div>

<script language="javascript" type="text/javascript">
<!--
if (commenter_name) {
document.getElementById('thanks').style.display = 'block';
} else {
document.write('You are not signed in. You need to be registered to comment on this site. <a href="<$MTSignOnURL$>&<MTIfNeedEmail>need_email=1&</MTIfNeedEmail>t=» <MTTypeKeyToken>&_return=<$MTCGIPath$><MTCommentScript>%3f__mode=» handle_sign_in%26static=1%26entry_id=<$MTEntryID$>"> Sign in</a>');
document.getElementById('thanks').style.display = 'none';
}
// -->
</script>

<MTElse>
! Comment registration is required but no TypeKey token has been given in weblog configuration!
</MTElse>
</MTIfNonEmpty>


This section is fairly large but it's also pretty easy to understand. This entire section is under the control of <MTIfRegistrationRequired> which regulates code if you want people only to sign in with TypeKey. If you never want to do this, you can omit this part but you must be sure to remove the corresponding 'else' statements. I'll try my best to point them out.
MT constantly checks for a TypeKey token and these can be removed if you don't want them there - just remember to have a token installed. Next is a thank you note for signing in - you might wonder why we're thanking people when we don't even know if they've signed in or not yet but that's under the control of a script at the end of this section which regulates the visibility of this thank you note (and everything else in id="thanks") if your MT install detects a cookie. You may edit the HTML that the javascript outputs but I recomend keeping the javascript itself intact.
The comment form is next - there's no name and email field because they're taken from TypeKey when you're logged in and this section requires you to be logged in. The form is the same as it was in MT 2.661. The end script controls visibility as I stated before. Edit the HTML but leave the underlying javascript alone (remember to escape single quotes in html like this: \').
Finially, the <MTElse> tag is connected to the tag above which checks for your TypeKey Token. If you delete the check above, be sure to delete the two <MTElse>s here and the end of the <MTIfNonEmpty> tag.

<MTElse> <MTIfNonEmpty tag="MTTypeKeyToken"> <script type="text/javascript" src="<MTCGIPath><MTCommentScript>?__mode=cmtr_name_js"></script> <script language="javascript" type="text/javascript"> <!-- if (commenter_name) { document.write('Thanks for signing in, ', commenter_name, '. Now you can comment. (<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=handle_sign_in&static=1» &entry_id=<$MTEntryID$>&logout=1">sign out</a>)'); } else { document.write('If you have a TypeKey identity, you can <a href="<$MTSignOnURL$>&<MTIfNeedEmail>need_email=1&</MTIfNeedEmail>t=» <MTTypeKeyToken>&_return=<$MTCGIPath$><MTCommentScript>%3f__mode=» handle_sign_in%26static=1%26entry_id=<$MTEntryID$>"> sign in</a> to use it here.'); } // --> </script> </MTIfNonEmpty>

<form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" onsubmit="if (this.bakecookie[0].checked) rememberMe(this)">
<input type="hidden" name="static" value="1" />
<input type="hidden" name="entry_id" value="<$MTEntryID$>" />

<div id="name_email">
<p><label for="author">Name:</label><br />
<input tabindex="1" id="author" name="author" /></p>

<p><label for="email">Email Address:</label><br />
<input tabindex="2" id="email" name="email" /></p>
</div>

<MTIfNonEmpty tag="MTTypeKeyToken">
<script language="javascript" type="text/javascript">
<!--
if (commenter_name) {
document.getElementById('name_email').style.display = 'none';
}
// -->
</script>
</MTIfNonEmpty>

<p><label for="url">URL:</label><br />
<input tabindex="3" type="text" name="url" id="url" />
Remember Me?
<input type="radio" id="remember" onClick="rememberMe(this.form)" name="bakecookie" /><label for="bakecookie"><label for="remember">Yes</label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget">No</label><br style="clear: both;" />
</p>

<p><label for="text">Comments:</label> <MTIfAllowCommentHTML>
(you may use HTML tags for style)</MTIfAllowCommentHTML><br/>
<textarea tabindex="4" id="text" name="text" rows="10" cols="50"></textarea></p>

<div align="center">
<input type="submit" name="preview" tabindex="5"
value=" Preview " />
<input style="font-weight: bold;" type="submit" name="post"
tabindex="6" value=" Post " />
</div>
</form>

</MTElse>


This next else is a little different. It controls the opposite of the Registration Required check which means if registration IS NOT required (you're not using TypeKey or you're using regular comments AND TypeKey) then use this section. If you're completely omited the registration section above, start with this section and be sure to remove the <MTElse> tag at the begining and end of this section.
Again, the MT install checks for your TypeKey token and then uses some javascript to check if you're logged in to TypeKey. The second javascript bit displays a 'thank you' if you're logged in and asks you to log in if you're not. Feel free to edit the HTML that is output by this script but make sure to keep the sign-in and sign-out links they point to.
We move on to your typical form. The only thing different here is that the 'name' and 'email' input boxes MUST BE UNDER THE SAME ID (in this case, 'name_email') so that the script right after them can remove them from the page if you're logged in to TypeKey. The rest of this form is identical to the form you're already using except, perhaps, for the <MTIfAllowCommentHTML> container tag which regulates some text if you allow HTML in your comments. Be sure to remove the end of the <MTElse> tag at the end of this section if you have not included the registration required section.

</MTIfRegistrationRequired> </MTIfCommentsAllowed>

<script type="text/javascript" language="javascript">
<!--
if (document.comments_form.email != undefined)
document.comments_form.email.value = getCookie("mtcmtmail");
if (document.comments_form.author != undefined)
document.comments_form.author.value = getCookie("mtcmtauth");
if (document.comments_form.url != undefined)
document.comments_form.url.value = getCookie("mtcmthome");
if (getCookie("mtcmtauth") || getCookie("mtcmthome")) {
document.comments_form.bakecookie[0].checked = true;
} else {
document.comments_form.bakecookie[1].checked = true;
}
//-->
</script>
</MTEntryIfCommentsOpen>
</MTEntryIfAllowComments>


The end of this is pretty basic. We close the <MTIfRegistrationRequired> tag (if we've used it above) and the <MTIfCommentsAllowed> tag. This next script is for replacing 'remembered' names in the name, email and URL fields. We use </MTEntryIfCommentsOpen> to close the open comments section and </MTEntryIfAllowComments> to close the entire comments section (the specific uses of each of these tags are sometimes cryptic - as long as they go in the correct order I wouldn't worry too much about them).
You're finished upgrading your templates. If you still can't get it and want some help, try the MT support boards (specifically the MT3D board) or you could even email me as a last resort. If you just want me to convert your templates and not deal with them yourself, it's a service I do for $20. It's a quick solution if you're stuck. Find my email address on the about page of this site.

warning - I had to add spaces to some of the long URLs so that they didn't extend my design. PLEASE double check if you have strange spaces in long URLs if you're going to copy and paste the code directly. ***Now the spaces are noted with » - check for those.

Additions or corrections are welcome.

Considering the nice amount of visits I've recieved on this post (I've been Jay-Allened and kadyellebee'd, I suppose), I've updated this to a 'quick-and-simple' version which is easier for people to deal with than my other format, I think. It's really just a commented version of the default code.

Posted with ecto

TrackBack

Listed below are links to weblogs that reference MT3 Comment Template Changes:

» Overview: MT 3 template changes from Jay's Super Secret Test Blog
From authenticgeek: Ok, some people seem to be having issues with the new MT3 Comment Template code and I think I have a pretty good grasp of what's going on so I'm going to give a little help. You can... [Read More]

» Gak! from IMR: Extras: Weblog
If you're using Movable Type and held at version 2.661 because of that whole licensing... [Read More]

Comments

hee hee - "kadyellebee'd" - That's fun, I don't think I've ever had my site sound so, well, famous before. :giggle:

I think the major problem that people will have with this is that with other installations of mt, the comments were popup. Its difficult to figure out which templates to add the new code to with popup comments.

I agree that it's a little different but once you figure out that people can post (usually) from the Comment Listing Template and the Comment Preview Template, replacing the code is roughly the same.

Post a comment

Nick O'Neill

 

 

 

 

 

powered by movabletype