Changeset 2062

Show
Ignore:
Timestamp:
04/24/08 21:16:21 (4 months ago)
Author:
bchoate
Message:

Updates to blog-side javascript regarding user state and permissions. BugId:79077,69644,67754,69814,79258,62643. Fixed declarations for conditional tags. BugId:79476. Display auth'd user nickname rather than name from comment object. BugId:79475

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-36/default_templates/comment_preview.mtml

    r1923 r2062  
    55    <title><$MTBlogName encode_html="1"$>: <__trans phrase="Previewing your Comment"></title> 
    66    <$mt:include module="<__trans phrase="HTML Head">"$> 
     7    <script type="text/javascript"> 
     8    /* <![CDATA[ */ 
     9    var is_preview = true; 
     10    /* ]]> */ 
     11    </script> 
    712    <script type="text/javascript" src="<$MTLink template="javascript"$>"></script> 
    813</head> 
    9 <body id="<$mt:BlogTemplateSetID$>" class="mt-comment-preview <$MTVar name="page_layout"$>" onload="individualArchivesOnLoad(commenter_name)"> 
     14<body id="<$mt:BlogTemplateSetID$>" class="mt-comment-preview <$MTVar name="page_layout"$>" onload="mtEntryOnLoad()"> 
    1015    <div id="container"> 
    1116        <div id="container-inner"> 
     
    2732 
    2833<mt:ignore><!-- Comment Preview --></mt:ignore> 
    29                             <div class="comment"<MTIfArchiveTypeEnabled archive_type="Individual"> id="comment-<$MTCommentID$>"</MTIfArchiveTypeEnabled>
     34                            <div class="comment" id="comment-<$MTCommentID$>"
    3035                                <div class="inner"> 
    3136                                    <div class="comment-header"> 
     
    3338                                            <span class="byline"> 
    3439                                                <mt:IfCommentParent> 
    35                                                     <__trans phrase="[_1] replied to <a href="[_2]">comment from [_3]</a>" params="<MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> <span class="vcard author"><$MTCommentAuthorLink default_name="Anonymous" show_email="0"$></span>%%<mt:CommentParent>#comment-<$MTCommentID$></mt:CommentParent>%%<mt:CommentParent><$MTCommentAuthor$></mt:CommentParent>"> 
     40                                                    <__trans phrase="[_1] replied to <a href="[_2]">comment from [_3]</a>" params="<$MTCommentAuthorIdentity$> <span class="vcard author"><$MTCommentAuthorLink$></span>%%<mt:CommentParent>#comment-<$MTCommentID$></mt:CommentParent>%%<mt:CommentParent><$MTCommentAuthor$></mt:CommentParent>"> 
    3641                                                <mt:else> 
    37                                                     <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> <span class="vcard author"><$MTCommentAuthorLink default_name="Anonymous" show_email="0"$></span> 
     42                                                    <$MTCommentAuthorIdentity$> 
     43                                                    <span class="vcard author"><$MTCommentAuthorLink$></span> 
    3844                                                </mt:IfCommentParent> 
    3945                                                | <a href="#comment-<$MTCommentID$>"><abbr class="published" title="<$MTCommentDate format_name="iso8601"$>"><$MTCommentDate$></abbr></a> 
    40                                                 <MTIfCommentsAccepted> | <$MTCommentReplyLink$></MTIfCommentsAccepted> 
    4146                                            </span> 
    4247                                        </div> 
     
    5055 
    5156<mt:ignore><!-- Comment Form --></mt:ignore> 
    52 <MTIfCommentsAccepted> 
    5357                            <div class="comments-open" id="comments-open"> 
    5458                                <h2 class="comments-open-header"><__trans phrase="Leave a comment"></h2> 
    5559                                <div class="comments-open-content"> 
    56     <MTIfRegistrationAllowed> 
    57                                         <div id="comment-form-external-auth"> 
    58                                             <script type="text/javascript"> 
    59                                             /* <![CDATA[ */ 
    60                                             is_preview = true; 
    61                                             writeCommenterGreeting(commenter_name, <$MTEntryID$>, <$MTEntryBlogID$>, commenter_id, commenter_url); 
    62                                             /* ]]> */ 
    63                                             </script> 
    64                                         </div> 
    65     </MTIfRegistrationAllowed> 
    66                                     <form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" id="comments-form" onsubmit="if (this.bakecookie.checked) rememberMe(this)"> 
     60                                    <div id="comment-greeting"></div> 
     61                                    <form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" id="comments-form" onsubmit="mtCommentOnSubmit(this)"> 
    6762                                        <input type="hidden" name="static" value="1" /> 
     63                                        <input type="hidden" name="armor" value="1" /> 
     64                                        <input type="hidden" name="preview" value="" /> 
    6865                                        <input type="hidden" name="entry_id" value="<$MTEntryID$>" /> 
    6966                                        <input type="hidden" name="__lang" value="<$MTBlogLanguage$>" /> 
     
    8178                                                <input id="comment-url" name="url" size="30" value="<$MTCommentURL encode_html="1"$>" /> 
    8279                                            </div> 
    83                                             <div id="comment-form-remember-me"> 
    84                                                 <label for="comment-bake-cookie"><input type="checkbox" id="comment-bake-cookie" name="bakecookie" onclick="if (!this.checked) forgetMe(document.comments_form)" value="1" /> 
    85                                                     <__trans phrase="Remember personal info?"></label> 
    86                                             </div> 
    8780                                        </div> 
    8881                                        <div id="comments-open-text"> 
     
    9083                                            <textarea id="comment-text" name="text" rows="15" cols="50"><$MTCommentBody autolink="0" sanitize="0" convert_breaks="0" encode_html="1"$></textarea> 
    9184                                        </div> 
    92     <MTIfNonEmpty tag="MTCaptchaFields"> 
    93                                         <MTIfCommentsAccepted><MTIfRegistrationAllowed><MTElse><$MTCaptchaFields$></MTIfRegistrationAllowed></MTIfCommentsAccepted> 
    94                                         <div id="comments-open-captcha"> 
    95                                         </div> 
    96     </MTIfNonEmpty> 
     85                                        <div id="comments-open-captcha"></div> 
    9786                                        <div id="comments-open-footer"> 
    98                                             <input type="submit" accesskey="v" name="preview" id="comment-preview" value="<__trans phrase="Preview">" /> 
     87                                            <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="<__trans phrase="Preview">" onclick="this.form.preview.value='1';" /> 
    9988                                            <input type="submit" accesskey="s" name="post" id="comment-submit" value="<__trans phrase="Submit">" /> 
    10089                                            <input type="button" name="cancel" id="comment-cancel" value="<__trans phrase="Cancel">" onclick="window.location='<$MTEntryPermalink$>'" /> 
     
    10392                                </div> 
    10493                            </div> 
    105 </MTIfCommentsAccepted> 
    10694                        </div> 
    10795                    </div> 
  • branches/release-36/default_templates/comments.mtml

    r1976 r2062  
    1 <mt:ignore><!-- Display comments for the entry/page or commenting form if entry/page is accepting comments --></mt:ignore> 
     1<mt:ignore> 
     2<!-- Display comments for the entry/page or commenting form if entry/page is accepting comments --> 
     3</mt:ignore> 
    24<MTIfCommentsActive> 
    35<div id="comments" class="comments"> 
    46 
    57 
    6     <mt:ignore><!-- Display comments --></mt:ignore> 
     8    <mt:ignore> 
     9    <!-- Display comments --> 
     10    </mt:ignore> 
    711    <MTComments> 
    812        <MTCommentsHeader> 
    9     <h2 class="comments-header"><$MTEntryCommentCount singular="<__trans phrase="1 Comment">" plural="<__trans phrase="# Comments">"$></h2> 
     13    <h2 class="comments-header"><$MTEntryCommentCount singular="<__trans phrase="1 Comment">" plural="<__trans phrase="# Comments">" none="<__trans phrase="No Comments">"$></h2> 
    1014    <div class="comments-content"> 
    1115        </MTCommentsHeader> 
    12         <div class="comment<mt:IfCommentParent> comment-reply</mt:IfCommentParent>"<MTIfArchiveTypeEnabled archive_type="Individual"> id="comment-<$MTCommentID$>"</MTIfArchiveTypeEnabled>
     16        <div class="comment<mt:IfCommentParent> comment-reply</mt:IfCommentParent>" id="comment-<$MTCommentID$>"
    1317            <div class="inner"> 
    1418                <div class="comment-header"> 
     
    1620                        <span class="byline"> 
    1721                            <mt:IfCommentParent> 
    18                                 <__trans phrase="[_1] replied to <a href="[_2]">comment from [_3]</a>" params="<MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> <span class="vcard author"><$MTCommentAuthorLink default_name="Anonymous" show_email="0"$></span>%%<mt:CommentParent>#comment-<$MTCommentID$></mt:CommentParent>%%<mt:CommentParent><$MTCommentAuthor$></mt:CommentParent>"> 
     22                                <__trans phrase="[_1] replied to <a href="[_2]">comment from [_3]</a>" params="<MTIf tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIf> <span class="vcard author"><$MTCommentAuthorLink$></span>%%<mt:CommentParent>#comment-<$MTCommentID$></mt:CommentParent>%%<mt:CommentParent><$MTCommentAuthor$></mt:CommentParent>"> 
    1923                            <mt:else> 
    20                                 <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> <span class="vcard author"><$MTCommentAuthorLink default_name="Anonymous" show_email="0"$></span> 
     24                                <$MTCommentAuthorIdentity$> 
     25                                <span class="vcard author"><$MTCommentAuthorLink$></span> 
    2126                            </mt:IfCommentParent> 
    22                             | <a href="#comment-<$MTCommentID$>"><abbr class="published" title="<$MTCommentDate format_name="iso8601"$>"><$MTCommentDate$></abbr></a> 
     27                            | <a href="#comment-<$MTCommentID$>"><abbr class="published" title="<$MTCommentDate format_name="iso8601"$>"><$MTCommentDate relative="js"$></abbr></a> 
    2328                            <MTIfCommentsAccepted> | <$MTCommentReplyLink$></MTIfCommentsAccepted> 
    2429                        </span> 
     
    3641 
    3742 
    38     <mt:ignore><!-- Display commenting form if entry/page is accepting comments --></mt:ignore> 
     43    <mt:ignore> 
     44    <!-- Display commenting form if entry/page is accepting comments --> 
     45    </mt:ignore> 
    3946    <MTIfCommentsAccepted> 
    4047    <div class="comments-open" id="comments-open"> 
     
    4249        <div class="comments-open-content"> 
    4350 
     51        <mt:ignore> 
     52        <!-- Display greeting for users if blog allows users to register locally --> 
     53        </mt:ignore> 
     54            <div id="comment-greeting"></div> 
    4455 
    45         <mt:ignore><!-- Display greeting for users if blog allows users to register locally --></mt:ignore> 
    46         <MTIfRegistrationAllowed> 
    47             <div id="comment-form-external-auth"> 
    48                 <script type="text/javascript"> 
    49                 /* <![CDATA[ */ 
    50                 writeCommenterGreeting(commenter_name, <$MTEntryID$>, <$MTEntryBlogID$>, commenter_id, commenter_url); 
    51                 /* ]]> */ 
    52                 </script> 
    53             </div> 
    54         </MTIfRegistrationAllowed> 
    55  
    56  
    57             <form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" id="comments-form" onsubmit="if (this.bakecookie.checked) rememberMe(this)"> 
     56            <form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form" id="comments-form" onsubmit="return mtCommentOnSubmit(this)"> 
    5857                <input type="hidden" name="static" value="1" /> 
    5958                <input type="hidden" name="entry_id" value="<$MTEntryID$>" /> 
    6059                <input type="hidden" name="__lang" value="<$MTBlogLanguage$>" /> 
    61                 <input type="hidden" name="parent_id" value="<MTIf name="comment_preview_template"><$MTCommentParentID$></MTIf>" id="comment-parent-id" /> 
     60                <input type="hidden" name="parent_id" value="<$MTCommentParentID$>" id="comment-parent-id" /> 
     61                <input type="hidden" name="armor" value="1" /> 
     62                <input type="hidden" name="preview" value="" /> 
    6263                <div id="comments-open-data"> 
    6364                    <div id="comment-form-name"> 
     
    7475                    </div> 
    7576                    <div id="comment-form-remember-me"> 
    76                         <input type="checkbox" id="comment-bake-cookie" name="bakecookie" onclick="if (!this.checked) forgetMe(document.comments_form)" value="1" /> 
     77                        <input type="checkbox" id="comment-bake-cookie" name="bakecookie" onclick="mtRememberMeOnClick(this)" value="1" accesskey="r" /> 
    7778                        <label for="comment-bake-cookie"><__trans phrase="Remember personal info?"></label> 
    7879                    </div> 
    79                     <div id="comment-form-reply"
    80                         <input type="checkbox" id="comment-reply" name="comment_reply" value="" onclick="setCommentParentID();" /
    81                         <label for="comment-reply" id="comment-reply-label"></label
    82                     </div
     80                </div
     81                <div id="comment-form-reply" style="display:none"
     82                    <input type="checkbox" id="comment-reply" name="comment_reply" value="" onclick="mtSetCommentParentID()" /
     83                    <label for="comment-reply" id="comment-reply-label"></label
    8384                </div> 
    8485                <div id="comments-open-text"> 
    85                     <label for="comment-text"><__trans phrase="Comments"> <MTIfAllowCommentHTML><__trans phrase="(You may use HTML tags for style)"></MTIfAllowCommentHTML></label> 
     86                    <label for="comment-text"><__trans phrase="Comments"> 
     87                    <MTIfAllowCommentHTML><__trans phrase="(You may use HTML tags for style)"></MTIfAllowCommentHTML></label> 
    8688                    <textarea id="comment-text" name="text" rows="15" cols="50"></textarea> 
    8789                </div> 
    88                 <MTIfNonEmpty tag="MTCaptchaFields"> 
    89                 <MTIfCommentsAccepted><MTIfRegistrationAllowed><MTElse><$MTCaptchaFields$></MTIfRegistrationAllowed></MTIfCommentsAccepted> 
    90                 <div id="comments-open-captcha"> 
    91                 </div> 
    92                 </MTIfNonEmpty> 
     90                <div id="comments-open-captcha"></div> 
    9391                <div id="comments-open-footer"> 
    94                     <input type="submit" accesskey="v" name="preview" id="comment-preview" value="<__trans phrase="Preview">" /> 
     92                    <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="<__trans phrase="Preview">" onclick="this.form.preview.value='1';" /> 
    9593                    <input type="submit" accesskey="s" name="post" id="comment-submit" value="<__trans phrase="Submit">" /> 
    9694                </div> 
  • branches/release-36/default_templates/entry.mtml

    r1983 r2062  
    1010    <script type="text/javascript" src="<$MTLink template="javascript"$>"></script> 
    1111</head> 
    12 <body id="<$mt:BlogTemplateSetID$>" class="mt-entry-archive <$MTVar name="page_layout"$>" onload="individualArchivesOnLoad(commenter_name)"> 
     12<body id="<$mt:BlogTemplateSetID$>" class="mt-entry-archive <$MTVar name="page_layout"$>" onload="mtEntryOnLoad()"> 
    1313    <div id="container"> 
    1414        <div id="container-inner"> 
     
    3232                                        <span class="byline"> 
    3333<MTIfNonEmpty tag="EntryAuthorDisplayName"> 
    34                                             <__trans phrase="By [_1] on [_2]" params="<span class="vcard author"><$MTEntryAuthorLink show_hcard="1"$></span>%%<abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$></abbr>"> 
     34                                            <__trans phrase="By [_1] on [_2]" params="<span class="vcard author"><$MTEntryAuthorLink show_hcard="1"$></span>%%<abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X" relative="js"$></abbr>"> 
    3535<MTElse> 
    36                                             <abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$></abbr> 
     36                                            <abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X" relative="js"$></abbr> 
    3737</MTIfNonEmpty> 
    3838                                        </span> 
  • branches/release-36/default_templates/entry_summary.mtml

    r1979 r2062  
    66            <span class="byline"> 
    77    <MTIfNonEmpty tag="EntryAuthorDisplayName"> 
    8                 <__trans phrase="By [_1] on [_2]" params="<span class="vcard author"><$MTEntryAuthorLink show_hcard="1"$></span>%%<abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$></abbr>"> 
     8                <__trans phrase="By [_1] on [_2]" params="<span class="vcard author"><$MTEntryAuthorLink show_hcard="1"$></span>%%<abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X" relative="js"$></abbr>"> 
    99    <MTElse> 
    10                 <abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X"$></abbr> 
     10                <abbr class="published" title="<$MTEntryDate format_name="iso8601"$>"><$MTEntryDate format="%x %X" relative="js"$></abbr> 
    1111    </MTIfNonEmpty> 
    1212            </span> 
  • branches/release-36/default_templates/javascript.mtml

    r1964 r2062  
    1 function hideDocumentElement(id) { 
    2     var el = document.getElementById(id); 
    3     if (el) 
    4         el.style.display = 'none'; 
    5 
    6  
    7 function showDocumentElement(id) { 
    8     var el = document.getElementById(id); 
    9     if (el) 
    10         el.style.display = 'block'; 
     1<mt:ignore> 
     2/* The following functions are here to support legacy MT templates. 
     3   If you have refreshed your JavaScript template but still use older 
     4   MT comment templates, you may need to uncomment this block in order 
     5   for those templates to work properly. Simply remove the wrapping 
     6   'mt:ignore' tag to do so. */ 
     7function hideDocumentElement(id) { return mtHide(id) } 
     8function showDocumentElement(id) { return mtShow(id) } 
     9function individualArchivesOnLoad() { return mtEntryOnLoad() } 
     10function writeCommenterGreeting() { return mtShowGreeting() } 
     11function rememberMe(f) { return mtRememberMe(f) } 
     12function forgetMe(f) { return mtForgetMe(f) } 
     13</mt:ignore> 
     14 
     15// The cookie name to use for storing the blog-side comment session cookie. 
     16var cookie_name = "mt_blog<$MTBlogID$>_user"; 
     17// The cookie path to use for storing the blog-side comment session cookie. 
     18var blog_path = "<$MTBlogURL$>".replace(/^.*?\/\/[^\/]+?\//, '/'); 
     19 
     20<mt:ignore> 
     21/*** 
     22 * Simple routine for showing a DOM element (applying a CSS display 
     23 * attribute of 'none'). 
     24 */ 
     25</mt:ignore> 
     26function mtHide(id) { 
     27    var el = (typeof id == "string") ? document.getElementById(id) : id; 
     28    if (el) el.style.display = 'none'; 
     29
     30 
     31<mt:ignore> 
     32/*** 
     33 * Simple routine for showing a DOM element (applying a CSS display 
     34 * attribute of 'block'). 
     35 */ 
     36</mt:ignore> 
     37function mtShow(id) { 
     38    var el = (typeof id == "string") ? document.getElementById(id) : id; 
     39    if (el) el.style.display = 'block'; 
    1140} 
    1241 
    1342var captcha_timer; 
    14 function showAnonymousForm() { 
    15     showDocumentElement('comments-form'); 
    16 <MTIfNonEmpty tag="MTCaptchaFields"> 
    17     captcha_timer = setInterval('delayShowCaptcha()', 1000); 
    18 </MTIfNonEmpty> 
    19 
    20 <MTIfNonEmpty tag="MTCaptchaFields"> 
    21 function delayShowCaptcha() { 
    22     clearInterval(captcha_timer); 
     43<mt:ignore> 
     44/*** 
     45 * Used to display the comment form and captcha field. 
     46 */ 
     47</mt:ignore> 
     48function mtShowAnonymousForm() { 
     49    mtShow('comments-form'); 
     50    captcha_timer = setInterval('mtShowCaptcha()', 1000); 
     51
     52 
     53<mt:ignore> 
     54/*** 
     55 * Displays a relative date. 
     56 * 'ts' is a Date object, 'fds' is a string of the date which 
     57 * will be displayed if the given date is older than 1 week. 
     58 */ 
     59</mt:ignore> 
     60function mtRelativeDate(ts, fds) { 
     61    var now = new Date(); 
     62    var ref = ts; 
     63    var delta = Math.floor((now.getTime() - ref.getTime()) / 1000); 
     64 
     65    var str; 
     66    if (delta < 60) { 
     67        str = '<__trans phrase="moments ago">'; 
     68    } else if (delta <= 86400) { 
     69        // less than 1 day 
     70        var hours = Math.floor(delta / 3600); 
     71        var min = Math.floor((delta % 3600) / 60); 
     72        if (hours == 1) 
     73            str = '<__trans phrase="[quant,_1,hour,hours] ago" params="1">'; 
     74        else if (hours > 1) 
     75            str = '<__trans phrase="[quant,_1,hour,hours] ago" params="2">'.replace(/2/, hours); 
     76        else if (min == 1) 
     77            str = '<__trans phrase="[quant,_1,minute,minutes] ago" params="1">'; 
     78        else 
     79            str = '<__trans phrase="[quant,_1,minute,minutes] ago" params="2">'.replace(/2/, min); 
     80    } else if (delta <= 604800) { 
     81        // less than 1 week 
     82        var days = Math.floor(delta / 86400); 
     83        var hours = Math.floor((delta % 86400) / 3600); 
     84        if (days == 1) 
     85            str = '<__trans phrase="[quant,_1,day,days] ago" params="1">'; 
     86        else if (days > 1) 
     87            str = '<__trans phrase="[quant,_1,day,days] ago" params="2">'.replace(/2/, days); 
     88        else if (hours == 1) 
     89            str = '<__trans phrase="[quant,_1,hour,hours] ago" params="1">'; 
     90        else 
     91            str = '<__trans phrase="[quant,_1,hour,hours] ago" params="2">'.replace(/2/, hours); 
     92    } 
     93    return str ? str : fds; 
     94
     95 
     96<mt:ignore> 
     97/*** 
     98 * Used to display an edit link for the given entry. 
     99 */ 
     100</mt:ignore> 
     101function mtEditLink(entry_id, author_id) { 
     102    var u = mtGetUser(); 
     103    if (! u) return; 
     104    if (! entry_id) return; 
     105    if (! author_id) return; 
     106    if (u.id != author_id) return; 
     107    var link = '<__trans phrase='<a href="[_1]">Edit</a>' params="<$MTAdminScript$>?__mode=view&amp;_type=entry&amp;id=' + entry_id + '">'; 
     108    document.write(link); 
     109
     110 
     111<mt:ignore> 
     112/*** 
     113 * Displays a captcha field for anonymous commenters. 
     114 */ 
     115</mt:ignore> 
     116function mtShowCaptcha() { 
     117    if (captcha_timer) clearInterval(captcha_timer); 
    23118    var div = document.getElementById('comments-open-captcha'); 
    24119    if (div) 
    25120        div.innerHTML = '<$MTCaptchaFields$>'; 
    26121} 
    27 </MTIfNonEmpty> 
    28  
    29 var AUTHOR = 1; 
    30 var COMMENTER = 2; 
    31 var commenter_name; 
    32 var commenter_status; 
    33 var commenter_id; 
    34 var commenter_url 
     122 
     123<mt:ignore> 
     124/* user object 
     125    -- saved in user cookie -- 
     126    u.name (display name) 
     127    u.url (link to home page) 
     128    u.email (for anonymous only) 
     129    u.userpic (url for commenter/author) 
     130    u.profile (link to profile) 
     131    u.is_trusted (boolean) 
     132    u.is_author (user has posting rights) 
     133    u.is_banned (banned status; neither post/comment perms) 
     134    u.can_post (has permission to post) 
     135    u.can_comment (has permission to comment) 
     136 
     137    -- status fields -- 
     138    u.is_authenticated (boolean) 
     139    u.is_anonymous (user is anonymous) 
     140*/ 
     141</mt:ignore> 
     142 
    35143var is_preview; 
    36 var mtcmtmail; 
    37 var mtcmtauth; 
    38 var mtcmthome; 
    39  
    40 function individualArchivesOnLoad(commenter_name) { 
    41     hideDocumentElement('comment-form-reply'); 
    42 <MTIfCommentsAccepted> 
    43 <MTElse> 
    44     hideDocumentElement('comments-open'); 
    45 </MTIfCommentsAccepted> 
    46 <MTIfPingsAccepted> 
    47 <MTElse> 
    48     hideDocumentElement('trackbacks-info'); 
    49 </MTIfPingsAccepted> 
    50 <MTIfRegistrationAllowed> 
    51     <MTIfRegistrationRequired> 
    52     if ( commenter_status > 0 ) { 
    53         hideDocumentElement('comment-form-name'); 
    54         hideDocumentElement('comment-form-email'); 
    55         hideDocumentElement('comment-form-url'); 
    56         hideDocumentElement('comment-form-remember-me'); 
    57         showDocumentElement('comments-open-text'); 
    58         showDocumentElement('comments-open-footer'); 
     144var user; 
     145<mt:ignore> 
     146/*** 
     147 * Assigns a user object as the actively logged in user; also saves the 
     148 * user information in a browser cookie. 
     149 */ 
     150</mt:ignore> 
     151function mtSetUser(u) { 
     152    if (u) { 
     153        // persist this 
     154        user = u; 
     155        mtSaveUser(); 
     156    } 
     157
     158 
     159<mt:ignore> 
     160/*** 
     161 * Simple function that escapes single quote characters for storing 
     162 * in a cookie. 
     163 */ 
     164</mt:ignore> 
     165function mtEscapeJS(s) { 
     166    s = s.replace(/'/g, "&apos;"); 
     167    return s; 
     168
     169 
     170<mt:ignore> 
     171/*** 
     172 * Simple function that unescapes single quote characters that were 
     173 * stored in a cookie. 
     174 */ 
     175</mt:ignore> 
     176function mtUnescapeJS(s) { 
     177    s = s.replace(/&apos;/g, "'"); 
     178    return s; 
     179
     180 
     181<mt:ignore> 
     182/*** 
     183 * Serializes a user object into a string, suitable for storing as a cookie. 
     184 */ 
     185</mt:ignore> 
     186function mtBakeUserCookie(u) { 
     187    var str = ""; 
     188    if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';"; 
     189    if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';"; 
     190    if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';"; 
     191    if (u.is_authenticated) str += "is_authenticated:'1';"; 
     192    if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';"; 
     193    if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';"; 
     194    str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';"; 
     195    str += "is_author:'" + (u.is_author ? "1" : "0") + "';"; 
     196    str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';"; 
     197    str += "can_post:'" + (u.can_post ? "1" : "0") + "';"; 
     198    str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';"; 
     199    str = str.replace(/;$/, ''); 
     200    return str; 
     201
     202 
     203<mt:ignore> 
     204/*** 
     205 * Unserializes a user cookie and returns a user object with the restored 
     206 * state. 
     207 */ 
     208</mt:ignore> 
     209function mtUnbakeUserCookie(s) { 
     210    if (!s) return; 
     211 
     212    var u = {}; 
     213    var m; 
     214    while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { 
     215        s = s.substring(m[1].length); 
     216        if (m[2].match(/^(is|can)_/)) // boolean fields 
     217            u[m[2]] = m[3] == '1' ? true : false; 
     218        else 
     219            u[m[2]] = mtUnescapeJS(m[3]); 
     220    } 
     221    if (u.is_authenticated) { 
     222        u.is_anonymous = false; 
    59223    } else { 
    60         hideDocumentElement('comments-open-data'); 
    61         hideDocumentElement('comments-open-text'); 
    62         hideDocumentElement('comments-open-footer'); 
    63     } 
    64     <MTElse> 
    65     // comments are allowed but registration not required 
    66     if ( commenter_status > 0 ) { 
    67         hideDocumentElement('comment-form-name'); 
    68         hideDocumentElement('comment-form-email'); 
    69     } else if (is_preview) { 
    70 <MTIfNonEmpty tag="MTCaptchaFields"> 
    71         delayShowCaptcha(); 
    72 </MTIfNonEmpty> 
     224        u.is_anonymous = true; 
     225        u.can_post = false; 
     226        u.is_author = false; 
     227        u.is_banned = false; 
     228        u.is_trusted = false; 
     229    } 
     230    return u; 
     231
     232 
     233<mt:ignore> 
     234/*** 
     235 * Retrieves an object of the currently logged in user's state. 
     236 * If no user is logged in or cookied, this will return null. 
     237 */ 
     238</mt:ignore> 
     239function mtGetUser() { 
     240    if (!user) { 
     241        var cookie = mtGetCookie(cookie_name); 
     242        if (!cookie) return; 
     243        user = mtUnbakeUserCookie(cookie); 
     244        if (! user) { 
     245            user = {}; 
     246            user.is_anonymous = true; 
     247            user.can_post = false; 
     248            user.is_author = false; 
     249            user.is_banned = false; 
     250            user.is_trusted = false; 
     251        } 
     252    } 
     253    return user; 
     254
     255 
     256<mt:ignore> 
     257/*** 
     258 * Issues a request to the MT comment script to retrieve the currently 
     259 * logged-in user (if any). 
     260 */ 
     261</mt:ignore> 
     262function mtFetchUser() { 
     263    document.write('<scr' + 'ipt src="<$MTCGIPath$><$MTCommentScript$>?__mode=session_js&blog_id=<$MTBlogID$>&jsonp=mtSetUser"></scr' + 'ipt>'); 
     264
     265 
     266<mt:ignore> 
     267/*** 
     268 * Called when the 'Remember me' checkbox is changed. If the checkbox 
     269 * is cleared, the cached user cookie is immediately cleared. 
     270 */ 
     271</mt:ignore> 
     272function mtRememberMeOnClick(b) { 
     273    if (!b.checked) 
     274        mtClearUser(b.form); 
     275    return true; 
     276
     277 
     278<mt:ignore> 
     279/*** 
     280 * Called when comment form is sent. 
     281 * Required parameter: Form DOM object of comment form. 
     282 * If form has a 'bakecookie' member, it will be used to signal 
     283 * storing the anonymous commenter information to a cookie. 
     284 * If form has a 'armor' member, it will be used to store 
     285 * a token that is checked by the comment script. 
     286 */ 
     287</mt:ignore> 
     288var mtRequestSubmitted = false; 
     289function mtCommentOnSubmit(f) { 
     290    if (!mtRequestSubmitted) { 
     291        mtRequestSubmitted = true; 
     292 
     293        if (f.armor) 
     294            f.armor.value = '<$MTBlogSitePath encode_sha1="1"$>'; 
     295        if (f.bakecookie && f.bakecookie.checked) 
     296            mtSaveUser(f); 
     297 
     298        // disable submit buttons 
     299        if (f.preview_button) f.preview_button.disabled = true; 
     300        if (f.post) f.post.disabled = true; 
     301        if (f.preview.value == '1') 
     302            f.preview_button.value = '<__trans phrase="Posting...">'; 
     303        else 
     304            f.post.value = '<__trans phrase="Posting...">'; 
     305 
     306        return true; 
     307    } 
     308    return false; 
     309
     310 
     311<mt:ignore> 
     312/*** 
     313 * Called when an entry archive page is loaded. 
     314 * This routine controls which elements of the comment form are shown 
     315 * or hidden, depending on commenter type and blog configuration. 
     316 */ 
     317</mt:ignore> 
     318function mtEntryOnLoad() { 
     319    var u = mtGetUser(); 
     320 
     321<mt:unless tag="IfCommentsAccepted"> 
     322    mtHide('comments-open'); 
     323</mt:unless> 
     324<mt:unless tag="IfPingsAccepted"> 
     325    mtHide('trackbacks-info'); 
     326</mt:unless> 
     327 
     328<mt:IfRegistrationRequired> 
     329    if ( !u || u.is_anonymous ) { 
     330        mtHide('comments-open-data'); 
     331        mtHide('comments-open-text'); 
     332        mtHide('comments-open-footer'); 
    73333    } else { 
    74         hideDocumentElement('comments-form'); 
    75     } 
    76     </MTIfRegistrationRequired> 
    77 </MTIfRegistrationAllowed> 
    78  
     334        mtHide('comments-open-data'); 
     335        mtShow('comments-open-text'); 
     336        mtShow('comments-open-footer'); 
     337    } 
     338<mt:else> 
     339<mt:IfRegistrationAllowed> 
     340    if (is_preview && u && u.is_anonymous) { 
     341        mtShowAnonymousForm(); 
     342    } else { 
     343        // comments are allowed but registration not required 
     344        if ( !u || u.is_anonymous ) 
     345            mtHide('comments-form'); 
     346        else 
     347            mtHide('comments-open-data'); 
     348    } 
     349<mt:else> 
     350    mtShowAnonymousForm(); 
     351</mt:IfRegistrationAllowed> 
     352</mt:IfRegistrationRequired> 
     353 
     354    mtShowGreeting(); 
     355 
     356    // populate anonymous comment fields if 
     357    // user is cookied as anonymous 
    79358    var cf = document.comments_form; 
    80359    if (cf) { 
    81         if (!commenter_name && (cf.email != undefined) && 
    82             (mtcmtmail = getCookie("mtcmtmail"))) 
    83             cf.email.value = mtcmtmail; 
    84         if (!commenter_name && (cf.author != undefined) && 
    85             (mtcmtauth = getCookie("mtcmtauth"))) 
    86             cf.author.value = mtcmtauth; 
    87         if (cf.url != undefined && 
    88             (mtcmthome = getCookie("mtcmthome"))) 
    89             cf.url.value = mtcmthome; 
    90         if (cf["bakecookie"]) { 
    91             if (mtcmtauth || mtcmthome) { 
    92                 cf.bakecookie.checked = true; 
     360        if (u && u.is_anonymous) { 
     361            if (u.email) cf.email.value = u.email; 
     362            if (u.name) cf.author.value = u.name; 
     363            if (u.url) cf.url.value = u.url; 
     364            if (cf.bakecookie) 
     365                cf.bakecookie.checked = u.name || u.email; 
     366        } 
     367        if (cf.post.disabled) { 
     368            cf.post.disabled = false; 
     369            cf.post.value = '<__trans phrase="Submit">'; 
     370        } 
     371        if (cf.preview_button.disabled) { 
     372            cf.preview_button.disabled = false; 
     373            cf.preview_button.value = '<__trans phrase="Preview">'; 
     374        } 
     375    } 
     376
     377 
     378<mt:ignore> 
     379/*** 
     380 * Handles the action of the "Sign in" link. First clears any existing 
     381 * user cookie, then directs to the MT comment script to sign the user in. 
     382 */ 
     383</mt:ignore> 
     384function mtSignIn(entry_id) { 
     385    var doc_url = document.URL; 
     386    doc_url = doc_url.replace(/#.+/, ''); 
     387    var url = '<$MTSignInLink$>&entry_id=' + entry_id + 
     388        '&return_to=' + encodeURIComponent(doc_url); 
     389    mtClearUser(); 
     390    location.href = url; 
     391
     392 
     393<mt:ignore> 
     394/*** 
     395 * Handles the action of the "Sign out" link. First clears any existing 
     396 * user cookie, then direts to the MT comment script to sign the user out. 
     397 */ 
     398</mt:ignore> 
     399function mtSignOut(entry_id) { 
     400    var url = '<$MTSignOutLink$>&entry_id=' + entry_id; 
     401    mtClearUser(); 
     402    location.href = url; 
     403
     404 
     405<mt:ignore> 
     406/*** 
     407 * Handles the display of the greeting message, depending on what kind of 
     408 * user is logged in and blog comment policy. 
     409 */ 
     410</mt:ignore> 
     411function mtShowGreeting() { 
     412<mt:IfRegistrationAllowed> 
     413    var reg_reqd = <mt:IfRegistrationRequired>true<mt:else>false</mt:IfRegistrationRequired>; 
     414 
     415    var cf = document.comments_form; 
     416    if (!cf) return; 
     417 
     418    var el = document.getElementById('comment-greeting'); 
     419    if (!el)  // legacy MT 4.x element id 
     420        el = document.getElementById('comment-form-external-auth'); 
     421    if (!el) return; 
     422 
     423    var eid = cf.entry_id; 
     424    var entry_id; 
     425    if (eid) entry_id = eid.value; 
     426 
     427    var phrase; 
     428    var u = mtGetUser(); 
     429 
     430    if ( u && u.is_authenticated ) { 
     431        if ( u.is_banned ) { 
     432            phrase = '<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="javascript:void(0);" onclick="mtSignOut(' + entry_id + ')">%%</a>">'; 
     433        } else { 
     434            var user_link; 
     435            if ( u.is_author ) { 
     436                user_link = '<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=edit_profile&blog_id=<$MTBlogID$>'; 
     437                if (entry_id) 
     438                    user_link += '&entry_id=' + entry_id; 
     439                user_link += '">' + u.name + '</a>'; 
    93440            } else { 
    94                 cf.bakecookie.checked = false; 
     441                // registered user, but not a user with posting rights 
     442                if (u.url) 
     443                    user_link = '<a href="' + u.url + '">' + u.name + '</a>'; 
     444                else 
     445                    user_link = u.name; 
    95446            } 
     447            // TBD: supplement phrase with userpic if one is available. 
     448            phrase = '<__trans phrase="Thanks for signing in, [_1]. ([_2]sign out[_3])" params="' + user_link + '%%<a href="javascript:void(0)" onclick="mtSignOut(' + entry_id + ')">%%</a>">'; 
    96449        } 
    97     } 
    98 
    99  
    100 function writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) { 
    101 <MTIfRegistrationAllowed> 
    102     if ( commenter_status > 0 ) { 
    103         var commenter_link; 
    104         if ( commenter_status == COMMENTER ) { 
    105             if (commenter_url) { 
    106                 commenter_link = '<a href="' + commenter_url + '">' + commenter_name + '</a>'; 
    107             } else { 
    108                 commenter_link = commenter_name; 
    109             } 
    110         } else if ( commenter_status == AUTHOR ) { 
    111             if (commenter_id) { 
    112                 commenter_link = '<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=edit_profile&commenter=' + commenter_id + '&blog_id=' + blog_id; 
    113                 if (entry_id) { 
    114                     commenter_link += '&entry_id=' + entry_id; 
    115                 } else { 
    116                     commenter_link += '&static=1'; 
    117                 } 
    118                 commenter_link += '">' + commenter_name + '</a>'; 
    119             } 
    120  
     450    } else { 
     451        if (reg_reqd) { 
     452            phrase = '<__trans phrase="[_1]Sign in[_2] to comment." params="<a href="javascript:void(0)" onclick="mtSignIn()">%%</a>">'; 
     453        } else { 
     454            phrase = '<__trans phrase="[_1]Sign in[_2] to comment, or [_3]comment anonymously[_2]." params="<a href="javascript:void(0)" onclick="mtSignIn(' + entry_id + ')">%%</a>%%<a href="javascript:void(0);" onclick="mtShowAnonymousForm();">">'; 
    121455        } 
    122         document.write( 
    123             '<__trans phrase="Thanks for signing in, [_1]. Now you can comment. ([_2]sign out[_3])" params="' + commenter_link + '%%<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">%%</a>">' 
    124         ); 
    125     } else if (commenter_name) { 
    126         document.write('<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">%%</a>">'); 
    127     } else { 
    128 <MTIfRegistrationRequired> 
    129         var phrase = '<__trans phrase="[_1]Sign in[_2] to comment on this entry." params="<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1&return_to=' + encodeURIComponent(document.URL) + '">%%</a>">'; 
    130 <MTElse> 
    131         var phrase = '<__trans phrase="[_1]Sign in[_2] to comment on this entry, or [_3]comment anonymously[_2]." params="<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1&return_to=' + encodeURIComponent(document.URL) + '">%%</a>%%<a href="javascript:void(0);" onclick="showAnonymousForm();">">'; 
    132 </MTIfRegistrationRequired> 
    133         document.write(phrase); 
    134     } 
    135 </MTIfRegistrationAllowed> 
    136 
    137  
    138 <MTIfRegistrationAllowed> 
    139 <$MTCGIHost exclude_port="1" setvar="cgi_host"$><$MTBlogHost exclude_port="1" setvar="blog_host"$> 
    140 <MTIf name="cgi_host" eq="$blog_host"> 
    141 commenter_name = getCookie('commenter_name'); 
    142 commenter_url = getCookie('commenter_url'); 
    143 ids = getCookie('commenter_id').split(':'); 
    144 commenter_id = ids[0]; 
    145 if ( ids[1] == 'S' ) { 
    146     commenter_status = AUTHOR; 
    147 
    148 else if ( ids[1] == 'N' ) { 
    149     document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_status_js&blog_id=<$MTBlogID$>"></script>'); 
    150 
    151 else if ( commenter_name && !commenter_id ) { 
    152     commenter_status = COMMENTER; 
    153 
    154 else if ( commenter_name  
    155   && commenter_id 
    156   && ( ids[1].indexOf("'<$MTBlogID$>'") > -1 ) ) { 
    157     commenter_status = AUTHOR; 
    158 
    159 else { 
    160     commenter_status = 0; 
    161 
    162 <MTElse> 
    163 document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_name_js&blog_id=<$MTBlogID$>"></script>'); 
    164 </MTIf> 
    165 </MTIfRegistrationAllowed> 
    166  
    167 function replyComment(parent_id, author) { 
    168     showDocumentElement('comment-form-reply'); 
    169      
     456    } 
     457    el.innerHTML = phrase; 
     458<mt:else> 
     459    mtShowCaptcha(); 
     460</mt:IfRegistrationAllowed> 
     461
     462 
     463<mt:ignore> 
     464/*** 
     465 * Handles the action of the 'Reply' links. 
     466 */ 
     467</mt:ignore> 
     468function mtReplyCommentOnClick(parent_id, auth