Changeset 2062

Show
Ignore:
Timestamp:
04/24/08 21:16:21 (22 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

Location:
branches/release-36
Files:
2 added
19 modified

Legend:

Unmodified
Added
Removed
  • 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, author) { 
     469    mtShow('comment-form-reply'); 
     470 
    170471    var checkbox = document.getElementById('comment-reply'); 
    171472    var label = document.getElementById('comment-reply-label'); 
     
    180481    text.focus(); 
    181482 
    182     setCommentParentID(); 
    183 } 
    184  
    185 function setCommentParentID() { 
     483    mtSetCommentParentID(); 
     484} 
     485 
     486<mt:ignore> 
     487/*** 
     488 * Sets the parent comment ID when replying to a comment. 
     489 */ 
     490</mt:ignore> 
     491function mtSetCommentParentID() { 
    186492    var checkbox = document.getElementById('comment-reply'); 
    187493    var parent_id_field = document.getElementById('comment-parent-id'); 
     494    if (!checkbox || !parent_id_field) return; 
     495 
    188496    var pid = 0; 
    189      
    190     if(checkbox.checked == true) 
     497    if (checkbox.checked == true) 
    191498        pid = checkbox.value; 
    192      
    193499    parent_id_field.value = pid; 
    194500} 
    195501 
    196  
    197 // Copyright (c) 1996-1997 Athenia Associates. 
    198 // http://www.webreference.com/js/ 
    199 // License is granted if and only if this entire 
    200 // copyright notice is included. By Tomer Shiran. 
    201  
    202     function setCookie (name, value, expires, path, domain, secure) { 
    203         var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") + 
    204             (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : ""); 
    205         document.cookie = curCookie; 
    206     } 
    207  
    208     function getCookie (name) { 
    209         var prefix = name + '='; 
    210         var c = document.cookie; 
    211         var nullstring = ''; 
    212         var cookieStartIndex = c.indexOf(prefix); 
    213         if (cookieStartIndex == -1) 
    214             return nullstring; 
    215         var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); 
    216         if (cookieEndIndex == -1) 
    217             cookieEndIndex = c.length; 
    218         return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); 
    219     } 
    220  
    221     function deleteCookie (name, path, domain) { 
    222         if (getCookie(name)) 
    223             document.cookie = name + "=" + ((path) ? "; path=" + path : "") + 
    224                 ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
    225     } 
    226  
    227     function fixDate (date) { 
    228         var base = new Date(0); 
    229         var skew = base.getTime(); 
    230         if (skew > 0) 
    231             date.setTime(date.getTime() - skew); 
    232     } 
    233  
    234     function rememberMe (f) { 
    235         var now = new Date(); 
    236         fixDate(now); 
    237         now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); 
    238         if (f.author != undefined) 
    239            setCookie('mtcmtauth', f.author.value, now, '/', '', ''); 
    240         if (f.email != undefined) 
    241            setCookie('mtcmtmail', f.email.value, now, '/', '', ''); 
    242         if (f.url != undefined) 
    243            setCookie('mtcmthome', f.url.value, now, '/', '', ''); 
    244     } 
    245  
    246     function forgetMe (f) { 
    247         deleteCookie('mtcmtmail', '/', ''); 
    248         deleteCookie('mtcmthome', '/', ''); 
    249         deleteCookie('mtcmtauth', '/', ''); 
    250     } 
    251  
     502<mt:ignore> 
     503/*** 
     504 * Persists a copy of the current user cookie into the browser cookie stash. 
     505 */ 
     506</mt:ignore> 
     507function mtSaveUser(f) { 
     508    // We can't reliably store the user cookie during a preview. 
     509    if (is_preview) return; 
     510 
     511    var u = mtGetUser(); 
     512 
     513    if (f && (!u || u.is_anonymous)) { 
     514        if ( !u ) { 
     515            u = {}; 
     516            u.is_authenticated = false; 
     517            u.can_comment = true; 
     518            u.is_author = false; 
     519            u.is_banned = false; 
     520            u.is_anonymous = true; 
     521            u.is_trusted = false; 
     522        } 
     523        if (f.author != undefined) u.name = f.author.value; 
     524        if (f.email != undefined) u.email = f.email.value; 
     525        if (f.url != undefined) u.url = f.url.value; 
     526    } 
     527 
     528    if (!u) return; 
     529 
     530    var cache_period = 60 * 60 * 1000; // 1 hour 
     531 
     532    // cache anonymous user info for a long period if the 
     533    // user has requested to be remembered 
     534    if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked) 
     535        cache_period = 365 * 24 * 60 * 60 * 1000; 
     536 
     537    var now = new Date(); 
     538    mtFixDate(now); 
     539    now.setTime(now.getTime() + cache_period); 
     540 
     541    var cmtcookie = mtBakeUserCookie(u); 
     542    mtSetCookie(cookie_name, cmtcookie, now, blog_path, null, 
     543        location.protocol == 'https:'); 
     544} 
     545 
     546<mt:ignore> 
     547/*** 
     548 * Clears the blog-side user cookie. 
     549 */ 
     550</mt:ignore> 
     551function mtClearUser() { 
     552    mtDeleteCookie(cookie_name, blog_path); 
     553} 
     554 
     555<mt:ignore> 
     556/*** 
     557 * Sets a browser cookie. 
     558 */ 
     559</mt:ignore> 
     560function mtSetCookie(name, value, expires, path, domain, secure) { 
     561    var curCookie = name + "=" + escape(value) + 
     562        (expires ? "; expires=" + expires.toGMTString() : "") + 
     563        (path ? "; path=" + path : "") + 
     564        (domain ? "; domain=" + domain : "") + 
     565        (secure ? "; secure" : ""); 
     566    document.cookie = curCookie; 
     567} 
     568 
     569<mt:ignore> 
     570/*** 
     571 * Retrieves a browser cookie. 
     572 */ 
     573</mt:ignore> 
     574function mtGetCookie (name) { 
     575    var prefix = name + '='; 
     576    var c = document.cookie; 
     577    var cookieStartIndex = c.indexOf(prefix); 
     578    if (cookieStartIndex == -1) 
     579        return ''; 
     580    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); 
     581    if (cookieEndIndex == -1) 
     582        cookieEndIndex = c.length; 
     583    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); 
     584} 
     585 
     586<mt:ignore> 
     587/*** 
     588 * Deletes a browser cookie. 
     589 */ 
     590</mt:ignore> 
     591function mtDeleteCookie (name, path, domain, secure) { 
     592    if (mtGetCookie(name)) 
     593        document.cookie = name + "=" + 
     594            (path ? "; path=" + path : "") + 
     595            (domain ? "; domain=" + domain : "") + 
     596            (secure ? "; secure" : "") + 
     597            "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
     598} 
     599 
     600function mtFixDate(date) { 
     601    var skew = (new Date(0)).getTime(); 
     602    if (skew > 0) 
     603        date.setTime(date.getTime() - skew); 
     604} 
     605 
     606<mt:ignore> 
     607/*** 
     608 * Returns a XMLHttpRequest object (for Ajax operations). 
     609 */ 
     610</mt:ignore> 
     611function mtGetXmlHttp() { 
     612    if ( !window.XMLHttpRequest ) { 
     613        window.XMLHttpRequest = function() { 
     614            var types = [ 
     615                "Microsoft.XMLHTTP", 
     616                "MSXML2.XMLHTTP.5.0", 
     617                "MSXML2.XMLHTTP.4.0", 
     618                "MSXML2.XMLHTTP.3.0", 
     619                "MSXML2.XMLHTTP" 
     620            ]; 
     621 
     622            for ( var i = 0; i < types.length; i++ ) { 
     623                try { 
     624                    return new ActiveXObject( types[ i ] ); 
     625                } catch( e ) {} 
     626            } 
     627 
     628            return undefined; 
     629        }; 
     630    } 
     631    if ( window.XMLHttpRequest ) 
     632        return new XMLHttpRequest(); 
     633} 
    252634 
    253635// BEGIN: fast browser onload init 
     
    256638// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338 
    257639 
    258 function init() { 
    259   // quit if this function has already been called 
    260   if (arguments.callee.done) return; 
    261  
    262   // flag this function so we don't do the same thing twice 
    263   arguments.callee.done = true; 
    264  
    265   // kill the timer 
    266   // DWD - check against window 
    267   if ( window._timer ) clearInterval(window._timer); 
    268    
    269   // DWD - fire the window onload now, and replace it 
    270   if ( window.onload && ( window.onload !== window.init ) ) { 
    271     window.onload(); 
    272     window.onload = function() {}; 
    273   } 
    274 }; 
     640function mtInit() { 
     641    // quit if this function has already been called 
     642    if (arguments.callee.done) return; 
     643 
     644    // flag this function so we don't do the same thing twice 
     645    arguments.callee.done = true; 
     646 
     647    // kill the timer 
     648    // DWD - check against window 
     649    if ( window._timer ) clearInterval(window._timer); 
     650 
     651    // DWD - fire the window onload now, and replace it 
     652    if ( window.onload && ( window.onload !== window.mtInit ) ) { 
     653        window.onload(); 
     654        window.onload = function() {}; 
     655    } 
     656} 
    275657 
    276658/* for Mozilla/Opera9 */ 
    277659if (document.addEventListener) { 
    278   document.addEventListener("DOMContentLoaded", init, false); 
     660    document.addEventListener("DOMContentLoaded", mtInit, false); 
    279661} 
    280662 
     
    282664/*@cc_on @*/ 
    283665/*@if (@_win32) 
    284   document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); 
    285   var script = document.getElementById("__ie_onload"); 
    286   script.onreadystatechange = function() { 
     666document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); 
     667var script = document.getElementById("__ie_onload"); 
     668script.onreadystatechange = function() { 
    287669    if (this.readyState == "complete") { 
    288       init(); // call the onload handler 
    289     } 
    290   }; 
     670        mtInit(); // call the onload handler 
     671    } 
     672}; 
    291673/*@end @*/ 
    292674 
    293675/* for Safari */ 
    294676if (/WebKit/i.test(navigator.userAgent)) { // sniff 
    295   _timer = setInterval(function() { 
    296     if (/loaded|complete/.test(document.readyState)) { 
    297       init(); // call the onload handler 
    298     } 
    299   }, 10); 
     677    _timer = setInterval(function() { 
     678        if (/loaded|complete/.test(document.readyState)) { 
     679            mtInit(); // call the onload handler 
     680        } 
     681    }, 10); 
    300682} 
    301683 
    302684/* for other browsers */ 
    303 window.onload = init; 
     685window.onload = mtInit; 
    304686 
    305687// END: fast browser onload init 
    306688 
     689<mt:IfRegistrationAllowed> 
     690/*** 
     691 * If request contains a '#_login' or '#_logout' hash, use this to 
     692 * also delete the blog-side user cookie, since we're coming back from 
     693 * a login, logout or edit profile operation. 
     694 */ 
     695var clearCookie = ( window.location.hash && window.location.hash.match( /^#_log(in|out)/ ) ) ? true : false; 
     696if (clearCookie) { 
     697    // clear any logged in state 
     698    mtClearUser(); 
     699    if (RegExp.$1 == 'in') 
     700        mtFetchUser(); 
     701} else if (! mtGetUser()) { 
     702    // gather user info 
     703    mtFetchUser(); 
     704} 
     705</mt:IfRegistrationAllowed> 
  • branches/release-36/default_templates/main_index.mtml

    r1923 r2062  
    66    <$mt:include module="<__trans phrase="HTML Head">"$> 
    77    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="<$MTLink template="rsd"$>" /> 
     8    <script type="text/javascript" src="<$MTLink template="javascript"$>"></script> 
    89</head> 
    910<body id="<$mt:BlogTemplateSetID$>" class="mt-main-index <$MTVar name="page_layout"$>"> 
  • branches/release-36/default_templates/page.mtml

    r1964 r2062  
    88    <script type="text/javascript" src="<$MTLink template="javascript"$>"></script> 
    99</head> 
    10 <body id="<$mt:BlogTemplateSetID$>" class="mt-page-archive <$MTVar name="page_layout"$>" onload="individualArchivesOnLoad(commenter_name)"> 
     10<body id="<$mt:BlogTemplateSetID$>" class="mt-page-archive <$MTVar name="page_layout"$>" onload="mtEntryOnLoad()"> 
    1111    <div id="container"> 
    1212        <div id="container-inner"> 
  • branches/release-36/default_templates/search_results.mtml

    r1961 r2062  
    77    <MTIgnore>Below Javascript adds ajax search capability</MTIgnore> 
    88    <script type="text/javascript"> 
    9     <!-- 
     9    /* <![CDATA[ */ 
    1010    <MTIfMoreResults> 
    11     function getXmlHttp() { 
    12         if ( !window.XMLHttpRequest ) { 
    13             window.XMLHttpRequest = function() { 
    14                 var types = [ 
    15                     "Microsoft.XMLHTTP", 
    16                     "MSXML2.XMLHTTP.5.0", 
    17                     "MSXML2.XMLHTTP.4.0", 
    18                     "MSXML2.XMLHTTP.3.0", 
    19                     "MSXML2.XMLHTTP" 
    20                 ]; 
    21  
    22                 for ( var i = 0; i < types.length; i++ ) { 
    23                     try { 
    24                         return new ActiveXObject( types[ i ] ); 
    25                     } catch( e ) {} 
    26                 } 
    27  
    28                 return undefined; 
    29             }; 
    30         } 
    31         if ( window.XMLHttpRequest ) 
    32             return new XMLHttpRequest(); 
    33     } 
    34  
    3511    function getResults(page) { 
    3612        page = parseInt(page); 
    3713        if (timer) window.clearTimeout(timer); 
    38         var xh = getXmlHttp(); 
     14        var xh = mtGetXmlHttp(); 
    3915        if (!xh) return false; 
    4016        var res = results[page]; 
     
    8258    }</MTIfPreviousResults> 
    8359    </MTIfMoreResults> 
    84     //--> 
     60    /* ]]> */ 
    8561    </script> 
     62    <script type="text/javascript" src="<$MTLink template="javascript"$>"></script> 
    8663</head> 
    8764<body id="<$mt:BlogTemplateSetID$>" class="mt-search-results <$MTVar name="page_layout"$>"> 
  • branches/release-36/default_templates/trackbacks.mtml

    r1976 r2062  
    22<MTIfPingsActive> 
    33<div id="trackbacks" class="trackbacks"> 
    4     <h2 class="trackbacks-header"><$MTEntryTrackbackCount singular="<__trans phrase="1 TrackBack">" plural="<__trans phrase="# TrackBacks">"$></h2> 
     4    <h2 class="trackbacks-header"><$MTEntryTrackbackCount singular="<__trans phrase="1 TrackBack">" plural="<__trans phrase="# TrackBacks">" none="<__trans phrase="No TrackBacks">"$></h2> 
    55 
    66    <mt:ignore><!-- Display TrackBack details if TrackBacks are being accepted --></mt:ignore> 
     
    2121                <div class="trackback-header"> 
    2222                    <div class="asset-meta"> 
    23                         <__trans phrase="<a href="[_1]">[_2]</a> from [_3] on <a href="[_4]">[_5]</a>" params="<$MTPingURL$>%%<$MTPingTitle$>%%<$MTPingBlogName$>%%#ping-<$MTPingID$>%%<$MTPingDate$>"> 
     23                        <__trans phrase="<a href="[_1]">[_2]</a> from [_3] on <a href="[_4]">[_5]</a>" params="<$MTPingURL$>%%<$MTPingTitle$>%%<$MTPingBlogName$>%%#ping-<$MTPingID$>%%<$MTPingDate relative="js"$>"> 
    2424                    </div> 
    2525                </div> 
  • branches/release-36/extras/examples/plugins/CommentByGoogleAccount/lib/CommentByGoogleAccount.pm

    r1174 r2062  
    3939        my $nick_escaped = escape_unicode($nick); 
    4040        $nick = encode_text($nick, 'utf-8', undef); 
    41         $session = $app->_make_commenter_session($app->make_magic_token, $email, 
     41        $session = $app->make_commenter_session($app->make_magic_token, $email, 
    4242                                                 $name, $nick_escaped); 
    4343        unless ($session) { 
  • branches/release-36/lib/MT/App.pm

    r2024 r2062  
    277277 
    278278    my $class = $app->model($type) or return; 
    279     my $list_pref = $app->list_pref($type); 
     279    my $list_pref = $app->list_pref($type) if $app->can('list_pref'); 
    280280    $param->{$_} = $list_pref->{$_} for keys %$list_pref; 
    281281    my $limit = $list_pref->{rows}; 
     
    938938sub is_authorized { 1 } 
    939939 
     940sub commenter_cookie { COMMENTER_COOKIE_NAME() } 
     941 
    940942sub user_cookie { $COOKIE_NAME } 
    941943 
    942944sub user { 
    943945    my $app = shift; 
    944     $app->{author} = $app->{$COOKIE_NAME} = $_[0] if @_; 
     946    $app->{author} = $app->{ $app->user_cookie } = $_[0] if @_; 
    945947    return $app->{author}; 
    946948} 
     
    10131015} 
    10141016 
    1015 sub _make_commenter_session { 
     1017sub make_commenter_session { 
    10161018    my $app = shift; 
    10171019    my ($session_key, $email, $name, $nick, $id, $url, $timeout, $blog_id) = @_; 
     
    10211023    my $nick_escaped = MT::Util::escape_unicode( $nick ); 
    10221024 
    1023     $timeout = '+' . $app->{cfg}->CommentSessionTimeout . 's' unless defined $timeout; 
     1025    $timeout = '+' . $app->config->CommentSessionTimeout . 's' unless defined $timeout; 
    10241026    my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
    10251027                  -value => $session_key, 
     
    10331035    $app->bake_cookie(%name_kookee); 
    10341036    if (defined $id) { 
    1035         my $blog_ids; 
    1036         if ($app->user && $app->user->is_superuser) { 
    1037             # Do not send blog ids in cookie because it may become huge. 
    1038             $blog_ids = 'S'; 
    1039         } 
    1040         else { 
    1041             my @blogs = $app->model('blog')->load(undef, 
    1042               { 
    1043                 fetchonly => [ 'id' ], 
    1044                 join => MT::Permission->join_on('blog_id', 
    1045                   { 
    1046                     permissions => "\%'comment'\%", 
    1047                     author_id   => $id 
    1048                   }, 
    1049                   { 'like' => { 'permissions' => 1 } } 
    1050                 ) 
    1051               } 
    1052             ); 
    1053  
    1054             # Has permissions to 20+ blogs - do not send these ids in cookie. 
    1055             $blog_ids = 20 < scalar(@blogs) 
    1056               ? 'N' 
    1057               : @blogs 
    1058                 ? "'" . join("','", map { $_->id } @blogs) . "'"  
    1059                 : ''; 
    1060         } 
    1061  
    1062         if ( $blog_ids ne 'S' && $blog_ids ne 'N' ) { 
    1063             my $perm = MT::Permission->load({ blog_id => $blog_id, author_id => $id }); 
    1064             if ($perm) { 
    1065                 # double-check to see if this user hasn't been denied commenting 
    1066                 # permission. user has 'comment' permission through a role, 
    1067                 # but check for a restriction to comment on this blog 
    1068                 if ($perm->is_restricted('comment')) { 
    1069                     $blog_ids =~ s/(,|^)'$blog_id'(,|$)//; 
    1070                 } 
    1071  
    1072                 # But if the permission carries a 'can administer' permission 
    1073                 # they should be allowed 
    1074                 if ($blog_id && ($blog_ids !~ m/(,|^)'$blog_id'(,|$)/)) { 
    1075                     if ($perm->can_administer_blog()) { 
    1076                         # user is a blog administrator, so yes, they can comment too 
    1077                         $blog_ids .= ($blog_ids ne '' ? ',' : '') 
    1078                             . "'" . $blog_id . "'"; 
    1079                     } 
    1080                 } 
    1081             } 
    1082             else { 
    1083                 if ($blog_id && ($blog_ids !~ m/(,|^)'$blog_id'(,|$)/)) { 
    1084                     # extra check to see if this user can comment on requested 
    1085                     # blog; this is specific to the Comment application, so 
    1086                     # only do this if we're running the comments app. 
    1087                     if ( $app->isa( 'MT::App::Comments' )) { 
    1088                         if ( $app->_check_commenter_author($app->user, $blog_id) ) { 
    1089                             # is this blog open to commenting from registered users? 
    1090                             # if so, this user really can comment, even though they 
    1091                             # don't have explicit permissions for it 
    1092                             $blog_ids .= ($blog_ids ne '' ? ',' : '') 
    1093                                 . "'" . $blog_id . "'"; 
    1094                         } 
    1095                     } 
    1096                 } 
    1097             } 
    1098         } 
    1099  
    1100         my %id_kookee = (-name => "commenter_id", 
    1101                            -value => $id . ':' . $blog_ids, 
    1102                            -path => '/', 
    1103                            ($timeout ? (-expires => $timeout) : ())); 
    1104         $app->bake_cookie(%id_kookee); 
    1105     } 
    1106     if (defined($url) && $url) { 
    1107         my %id_kookee = (-name => "commenter_url", 
    1108                            -value => $url, 
    1109                            -path => '/', 
    1110                            ($timeout ? (-expires => $timeout) : ())); 
    1111         $app->bake_cookie(%id_kookee); 
    1112     } 
     1037        my $banned = 0; 
     1038        my $perm = MT::Permission->load({ blog_id => $blog_id, author_id => $id }); 
     1039        if ($perm) { 
     1040            if (!$perm->can_administer_blog && $perm->is_restricted('comment')) { 
     1041                $banned = 1; 
     1042            } 
     1043        } 
     1044 
     1045        # my %id_kookee = (-name => "commenter_id", 
     1046        #                    -value => $id . ':' . $blog_ids, 
     1047        #                    -path => '/', 
     1048        #                    ($timeout ? (-expires => $timeout) : ())); 
     1049        # $app->bake_cookie(%id_kookee); 
     1050    } 
     1051    # if (defined($url) && $url) { 
     1052    #     my %id_kookee = (-name => "commenter_url", 
     1053    #                        -value => $url, 
     1054    #                        -path => '/', 
     1055    #                        ($timeout ? (-expires => $timeout) : ())); 
     1056    #     $app->bake_cookie(%id_kookee); 
     1057    # } 
    11131058 
    11141059    require MT::Session; 
     
    11351080    my $sess_obj = MT::Session->load({id => $session }); 
    11361081    $sess_obj->remove() if ($sess_obj); 
    1137      
    1138     my $timeout = $app->{cfg}->CommentSessionTimeout; 
    1139  
    1140     my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
    1141                   -value => '', 
    1142                   -path => '/', 
    1143                   -expires => "+${timeout}s"); 
    1144     $app->bake_cookie(%kookee); 
    1145     my %url_kookee = (-name => 'commenter_url', 
    1146                        -value => '', 
    1147                        -path => '/', 
    1148                        -expires => "+${timeout}s"); 
    1149     $app->bake_cookie(%url_kookee); 
    1150     my %name_kookee = (-name => 'commenter_name', 
    1151                        -value => '', 
    1152                        -path => '/', 
    1153                        -expires => "+${timeout}s"); 
    1154     $app->bake_cookie(%name_kookee); 
    1155     my %id_kookee = (-name => 'commenter_id', 
    1156                        -value => '', 
    1157                        -path => '/', 
    1158                        -expires => "+${timeout}s"); 
    1159     $app->bake_cookie(%id_kookee); 
     1082 
     1083    $app->logout(); 
     1084 
     1085    # my $timeout = $app->config->CommentSessionTimeout; 
     1086    # my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
     1087    #               -value => '', 
     1088    #               -path => '/', 
     1089    #               -expires => "+${timeout}s"); 
     1090    # $app->bake_cookie(%kookee); 
     1091    # my %url_kookee = (-name => 'commenter_url', 
     1092    #                    -value => '', 
     1093    #                    -path => '/', 
     1094    #                    -expires => "+${timeout}s"); 
     1095    # $app->bake_cookie(%url_kookee); 
     1096    # my %name_kookee = (-name => 'commenter_name', 
     1097    #                    -value => '', 
     1098    #                    -path => '/', 
     1099    #                    -expires => "+${timeout}s"); 
     1100    # $app->bake_cookie(%name_kookee); 
     1101    # my %id_kookee = (-name => 'commenter_id', 
     1102    #                    -value => '', 
     1103    #                    -path => '/', 
     1104    #                    -expires => "+${timeout}s"); 
     1105    # $app->bake_cookie(%id_kookee); 
    11601106} 
    11611107 
     
    11691115    } 
    11701116    my $session = make_session($author, $remember); 
    1171     my %arg = (-name => $COOKIE_NAME, 
     1117    my %arg = (-name => $app->user_cookie, 
    11721118               -value => join('::', 
    11731119                              $author->name, 
     
    15011447                # Presence of 'password' indicates this is a login request; 
    15021448                # do session/cookie management. 
    1503                 $app->_make_commenter_session( 
     1449                $app->make_commenter_session( 
    15041450                    $app->make_magic_token,  
    15051451                    $author->email,  
     
    15791525 
    15801526    MT::Auth->invalidate_credentials({ app => $app }); 
    1581     my %cookies = $app->cookies(); 
    1582     $app->_invalidate_commenter_session(\%cookies); 
     1527    # my %cookies = $app->cookies(); 
     1528    # $app->_invalidate_commenter_session(\%cookies); 
    15831529 
    15841530    # The login box should only be displayed in the event of non-delegated auth 
     
    18841830sub clear_login_cookie { 
    18851831    my $app = shift; 
    1886     $app->bake_cookie(-name => $COOKIE_NAME, -value => '', -expires => '-1y', 
     1832    $app->bake_cookie(-name => $app->user_cookie, -value => '', -expires => '-1y', 
    18871833        -path => $app->config->CookiePath || $app->mt_path); 
    18881834} 
  • branches/release-36/lib/MT/App/Comments.pm

    r1924 r2062  
    3434        post             => \&post, 
    3535        handle_sign_in   => \&handle_sign_in, 
    36         cmtr_name_js     => \&commenter_name_js, 
    37         cmtr_status_js   => \&commenter_status_js, 
     36        session_js       => \&session_js, 
    3837        edit_profile     => \&edit_commenter_profile, 
    3938        save_profile     => \&save_commenter_profile, 
    4039        red              => \&do_red, 
    4140        generate_captcha => \&generate_captcha, 
     41 
     42        # deprecated 
     43        cmtr_name_js     => \&commenter_name_js, 
     44        cmtr_status_js   => \&commenter_status_js, 
    4245    ); 
    4346    $app->{template_dir} = 'comment'; 
     
    8891 
    8992# 
    90 # $app->_get_commenter_session() # 
     93# $app->_get_commenter_session() 
    9194# Creates a commenter record based on the cookies in the $app, if 
    9295# one already exists corresponding to the browser's session. 
     
    103106    my $session_key; 
    104107 
     108    # First, check for a real MT user login. If one exists, 
     109    # return that as the commenter identity 
     110    my ($user, $first_time) = $app->SUPER::login(); 
     111    if ( $user ) { 
     112        my $sess = $app->session; 
     113        return ( $sess->id, $user ); 
     114    } 
     115 
    105116    my %cookies = $app->cookies(); 
    106     my $cookie_name = MT::App::COMMENTER_COOKIE_NAME(); 
     117    my $cookie_name = $app->commenter_cookie; 
    107118    if ( !$cookies{$cookie_name} ) { 
    108119        return ( undef, undef ); 
     
    115126    my $timeout = $cfg->CommentSessionTimeout; 
    116127    my $user; 
    117  
     128     
    118129    if ( $sess_obj 
    119130        && ( $user = MT::Author->load( { name => $sess_obj->name } ) ) ) 
     
    123134    if (   !$sess_obj 
    124135        || ( $sess_obj->start() + $timeout < time ) 
    125         || ( $q->param('email') && ( $sess_obj->email ne $q->param('email') ) ) 
    126         || ( $q->param('author') && ( $user->nickname ne $q->param('author') ) ) 
    127136      ) 
    128137    { 
     
    131140    } 
    132141    else { 
    133  
    134142        # session is valid! 
    135143        return ( $session_key, $user ); 
     
    283291        MT::Auth->new_login( $app, $commenter ); 
    284292        if ( $app->_check_commenter_author( $commenter, $blog_id ) ) { 
    285             $app->_make_commenter_session( $app->make_magic_token, 
     293            $app->make_commenter_session( $app->make_magic_token, 
    286294                $commenter->email, $commenter->name, 
    287295                ($commenter->nickname || $app->translate('(Display Name not set)')), 
    288296                $commenter->id, undef, $ctx->{permanent} ? '+10y' : 0, $blog_id ); 
    289             #$app->start_session( $commenter, $ctx->{permanent} ? 1 : 0 ); 
    290297            return $app->redirect_to_target; 
    291298        } 
     
    766773      if $app->request_method() ne 'POST'; 
    767774 
    768     my $entry_id = $q->param('entry_id') 
     775    my $entry_id = int($q->param('entry_id')) 
    769776      or return $app->error( $app->translate("No entry_id") ); 
    770777    require MT::Entry; 
     
    787794        if ( $app->remote_ip =~ /$banned_ip/ ) { 
    788795            return $app->handle_error( 
    789                 $app->translate("You are not allowed to add comments.") ); 
     796                $app->translate("Invalid request") ); 
     797        } 
     798    } 
     799 
     800    my $blog = $app->model('blog')->load( $entry->blog_id ) 
     801        or return $app->error($app->translate('Can\'t load blog #[_1].', $entry->blog_id)); 
     802 
     803    my $armor = $q->param('armor'); 
     804    if (defined $armor) { 
     805        # For this to work, we must create a site path exactly like 
     806        # <MTBlogSitePath> does. 
     807        my $path = $blog->site_path; 
     808        $path .= '/' unless $path =~ m!/$!; 
     809        my $site_path_sha1 = MT::Util::perl_sha1_digest_hex($path); 
     810        if ($armor ne $site_path_sha1) { 
     811            return $app->handle_error($app->translate("Invalid request; $armor != $site_path_sha1")); 
    790812        } 
    791813    } 
     
    813835            $app->translate("Comments are not allowed on this entry.") ); 
    814836    } 
    815  
    816     my $blog = $app->model('blog')->load( $entry->blog_id ) 
    817         or return $app->error($app->translate('Can\'t load blog #[_1].', $entry->blog_id)); 
    818837 
    819838    my $text = $q->param('text') || ''; 
     
    923942        ); 
    924943    } 
    925     if ($commenter) { 
    926         $commenter->url( $comment->url ) 
    927           if $comment->url && $commenter->type != MT::Author::COMMENTER(); 
    928         $commenter->save 
    929           or $app->log( 
    930             { 
    931                 message => $app->translate( 
    932                     "Commenter save failed with [_1]", 
    933                     $commenter->errstr 
    934                 ), 
    935                 class   => 'system', 
    936                 blog_id => $blog->id, 
    937                 level   => MT::Log::ERROR() 
    938             } 
    939           ); 
    940     } 
    941  
    942     #    return $app->handle_error($app->errstr()) unless $comment; 
    943944 
    944945    # Form a link to the comment 
     
    947948        my $url = $app->base . $app->uri; 
    948949        $url .= '?entry_id=' . $q->param('entry_id'); 
    949         $url .= '&static=0&arch=1' if ( $q->param('arch') ); 
    950950        $comment_link = $url; 
    951951    } 
     
    953953        my $static = $q->param('static'); 
    954954        if ( $static eq '1' ) { 
    955  
    956955            # I think what we really want is the individual archive. 
    957956            $comment_link = $entry->permalink; 
     
    959958        else { 
    960959            $static =~ s/[\r\n].*$//s; 
    961             $comment_link = $static . '#' . $comment->id; 
     960            $comment_link = $static . '#comment-' . $comment->id; 
    962961        } 
    963962    } 
     
    968967        # redirected to the indiv. page it will be up-to-date. 
    969968        $app->rebuild_entry( Entry => $entry->id ) 
    970           or return $app->error( 
     969          or return $app->handle_error( 
    971970            $app->translate( "Publish failed: [_1]", $app->errstr ) ); 
    972971    } 
     
    10011000            require MT::DefaultTemplates; 
    10021001            $tmpl = MT::DefaultTemplates->load({ type => 'comment_response' }) 
    1003                 or return $app->error($app->translate("Can\'t load template")); 
     1002                or return $app->handle_error($app->translate("Can\'t load template")); 
    10041003            $tmpl->text( $app->translate_templatized( $tmpl->text ) ); 
    10051004        } 
     
    10971096    my %param       = @_; 
    10981097    my %cookies     = $app->cookies(); 
    1099     my $cookie_name = MT::App::COMMENTER_COOKIE_NAME(); 
     1098    my $cookie_name = $app->commenter_cookie_name; 
    11001099    my $session_key = $cookies{$cookie_name}->value() || ""; 
    11011100    $session_key =~ y/+/ /; 
     
    11411140    # INACTIVE == BANNED 
    11421141    return 0 if $status == MT::Author::BANNED(); 
     1142    return 0 if $commenter->status == MT::Author::BANNED(); 
    11431143 
    11441144    # NOT using $status for this test, since $status may be 
     
    11681168                or return $app->error($app->translate('Can\'t load blog #[_1].', $blog_id)); 
    11691169            if ( $registration->{Allow} && $blog->allow_commenter_regist ) { 
    1170                 my $perm = $commenter->blog_perm($blog_id); 
    1171                 return 0 unless $perm->is_empty; 
    1172                 require MT::Role; 
    1173                 require MT::Association; 
    1174                 my $role = MT::Role->load_same( undef, undef, 1, 'comment' ); 
    1175                 if ( $role && $blog ) { 
    1176                     MT::Association->link( $commenter => $role => $blog ); 
    1177                 } 
    1178                 else { 
    1179                     # FIXME: In this case, we should probably return 0 
    1180                     # here, since no permission was actually granted. 
    1181                     $app->log( 
    1182                         { 
    1183                             message => MT->translate( 
    1184 "Error assigning commenting rights to user '[_1] (ID: [_2])' for weblog '[_3] (ID: [_4])'. No suitable commenting role was found.", 
    1185                                 $commenter->name, $commenter->id, 
    1186                                 $blog->name,      $blog->id, 
    1187                             ), 
    1188                             level    => MT::Log::ERROR(), 
    1189                             class    => 'system', 
    1190                             category => 'new' 
    1191                         } 
    1192                     ); 
    1193                 } 
     1170                # By policy, this blog permits this type of user 
     1171                # and they are not banned (as they have no blog perms/ 
     1172                # restrictions, so permit this comment) 
    11941173                return 1; 
    11951174            } 
     
    13681347    if ( $q->param('logout') ) { 
    13691348        my ( $s, $commenter ) = $app->_get_commenter_session(); 
    1370         #if ($commenter) { 
    1371         #    require MT::Auth; 
    1372         #    my $ctx = MT::Auth->fetch_credentials( { app => $app } ); 
    1373         #    my $cmntr_sess = 
    1374         #      $app->session_user( $commenter, $ctx->{session_id}, 
    1375         #        permanent => $ctx->{permanent} ); 
    1376         #    if ($cmntr_sess) { 
    1377         #        $app->user($commenter); 
    1378         #        MT::Auth->invalidate_credentials( { app => $app } ); 
    1379         #    } 
    1380         #} 
     1349 
     1350        # invalidate credentials in auth layer 
     1351        if ($commenter) { 
     1352           require MT::Auth; 
     1353           my $ctx = MT::Auth->fetch_credentials( { app => $app } ); 
     1354           my $cmntr_sess = 
     1355             $app->session_user( $commenter, $ctx->{session_id}, 
     1356               permanent => $ctx->{permanent} ); 
     1357           if ($cmntr_sess) { 
     1358               $app->user($commenter); 
     1359               MT::Auth->invalidate_credentials( { app => $app } ); 
     1360           } 
     1361        } 
    13811362 
    13821363        my %cookies = $app->cookies(); 
    13831364        $app->_invalidate_commenter_session( \%cookies ); 
    1384         if ( $commenter && ( 'TypeKey' ne $commenter->auth_type ) ) { 
    1385             # Remove logout parameter so MT does not go to TypeKey 
    1386             # when unnecessary. 
    1387             $app->param( 'logout', 0 ); 
    1388         } 
     1365        $app->user($commenter) if $commenter; 
    13891366        $result = 1; 
    13901367    } 
     
    14151392    my $target; 
    14161393    require MT::Util; 
    1417     if ( $q->param('static') ) { 
    1418         if ( $q->param('static') eq 1 ) { 
    1419             require MT::Entry; 
    1420             my $entry = MT::Entry->load( $q->param('entry_id') ) 
    1421                 or return $app->error($app->translate('Can\'t load entry #[_1].', $q->param('entry_id'))); 
    1422             $target = $entry->archive_url; 
    1423             my $blog = MT::Blog->load( $entry->blog_id ); 
    1424             $target = MT::Util::strip_index( $target, $blog ); 
    1425         } 
    1426         else { 
    1427             $target = $q->param('static'); 
    1428         } 
    1429     } 
    1430     else { 
    1431         $target = 
    1432           (     $cfg->CGIPath 
    1433               . $cfg->CommentScript 
    1434               . "?entry_id=" 
    1435               . $q->param('entry_id') 
    1436               . ( $q->param('arch') ? '&static=0&arch=1' : '' ) ); 
     1394    my $static = $q->param('static') || ''; 
     1395 
     1396    if ( ($static eq '') || ($static eq 1) ) { 
     1397        require MT::Entry; 
     1398        my $entry = MT::Entry->load( $q->param('entry_id') || 0 ) 
     1399            or return $app->error($app->translate('Can\'t load entry #[_1].', $q->param('entry_id'))); 
     1400        $target = $entry->archive_url; 
     1401        my $blog = MT::Blog->load( $entry->blog_id ); 
     1402        $target = MT::Util::strip_index( $target, $blog ); 
     1403    } 
     1404    elsif ($static ne '') { 
     1405        $target = $static; 
    14371406    } 
    14381407    if ( $q->param('logout') ) { 
    1439         return $app->redirect( 
    1440             $cfg->SignOffURL . "&_return=" . MT::Util::encode_url($target), 
    1441             UseMeta => 1 ); 
    1442     } 
    1443     else { 
    1444         return $app->redirect( $target, UseMeta => 1 ); 
    1445     } 
     1408        if ( $app->user && 
     1409            ( 'TypeKey' eq $app->user->auth_type ) ) { 
     1410            return $app->redirect( 
     1411                $cfg->SignOffURL . "&_return=" . 
     1412                MT::Util::encode_url($target . '#_logout'), 
     1413                UseMeta => 1 ); 
     1414        } 
     1415    } 
     1416    return $app->redirect( $target . '#_' . 
     1417        ($q->param('logout') ? 'logout' :  'login'), UseMeta => 1 ); 
    14461418} 
    14471419 
     
    14851457} 
    14861458 
     1459sub session_js { 
     1460    my $app = shift; 
     1461    my $blog_id = int($app->param('blog_id')); 
     1462    my $blog = MT::Blog->load( $blog_id ) if $blog_id; 
     1463    my $jsonp = $app->param('jsonp'); 
     1464    $jsonp = undef if $jsonp !~ m/^\w+$/; 
     1465 
     1466    my $c; 
     1467    if ( $jsonp && $blog_id && $blog ) { 
     1468        my ( $session, $commenter ) = $app->_get_commenter_session(); 
     1469        if ( $session && $commenter ) { 
     1470            my $blog_perms = $commenter->blog_perm($blog_id); 
     1471            my $banned = $commenter->is_banned($blog_id) ? "1" : "0"; 
     1472            $banned = 0 if $blog_perms && $blog_perms->can_administer; 
     1473            $banned ||= 1 if $commenter->status == MT::Author::BANNED(); 
     1474 
     1475            my $sessobj = MT::Session->load($session); 
     1476            if ($banned) { 
     1477                $sessobj->remove; 
     1478            } else { 
     1479                $sessobj->start( time + 
     1480                    $app->config->CommentSessionTimeout); # extend by timeou 
     1481                $sessobj->save(); 
     1482            } 
     1483 
     1484            my $can_comment = $banned ? 0 : 1; 
     1485            $can_comment = 0 unless $blog->allow_unreg_comments || $blog->allow_reg_comments; 
     1486            my $can_post = ($blog_perms && $blog_perms->can_create_post) ? "1" : "0"; 
     1487            $c = { 
     1488                name => $commenter->nickname, 
     1489                url => $commenter->url, 
     1490                email => $commenter->email, 
     1491                userpic => scalar $commenter->userpic_url, 
     1492                profile => "", # profile link url 
     1493                is_authenticated => "1", 
     1494                is_trusted => ($commenter->is_trusted() ? "1" : "0"), 
     1495                is_author => ($commenter->type == MT::Author::AUTHOR() ? "1" : "0"), 
     1496                is_anonymous => "0", 
     1497                is_banned => $banned, 
     1498                can_comment => $can_comment, 
     1499                can_post => $can_post, 
     1500            }; 
     1501        } 
     1502    } 
     1503 
     1504    unless ($c) { 
     1505        my $can_comment = $blog->allow_anon_comments ? "1" : "0"; 
     1506        $c = { 
     1507            is_authenticated => "0", 
     1508            is_trusted => "0", 
     1509            is_anonymous => "1", 
     1510            can_post => "0", # no anonymous posts 
     1511            can_comment => $can_comment, 
     1512            is_banned => "0", 
     1513        }; 
     1514    } 
     1515 
     1516    require JSON; 
     1517    $app->{no_print_body} = 1; 
     1518    $app->send_http_header("text/javascript"); 
     1519    my $json = JSON::objToJson($c); 
     1520    $app->print("$jsonp(" . $json . ");\n"); 
     1521    return undef; 
     1522} 
     1523 
     1524# deprecated 
    14871525sub commenter_status_js { 
    14881526    local $SIG{__WARN__} = sub { }; 
     
    15061544} 
    15071545 
     1546# deprecated 
    15081547sub commenter_name_js { 
    15091548    local $SIG{__WARN__} = sub { }; 
     
    16561695    my $app = shift; 
    16571696 
    1658     my $id = $app->param('commenter'); 
    1659     return $app->handle_error( $app->translate('Invalid commenter ID') ) 
    1660       unless $id =~ /\d+/; 
    1661  
    1662     my $url; 
    1663     my $entry_id = $app->param('entry_id'); 
    1664     if ($entry_id) { 
    1665         my $entry = MT::Entry->load($entry_id); 
    1666         return $app->handle_error( $app->translate("No entry ID provided") ) 
    1667           unless $entry; 
    1668         $url = $entry->permalink; 
    1669     } 
    1670     else { 
    1671         $url = is_valid_url( $app->param('static') ); 
    1672     } 
    1673  
    16741697    my ( $session, $commenter ) = $app->_get_commenter_session(); 
    16751698    if ($commenter) { 
     1699        my $url; 
     1700        my $entry_id = $app->param('entry_id'); 
     1701        if ($entry_id) { 
     1702            my $entry = MT::Entry->load($entry_id); 
     1703            return $app->handle_error( $app->translate("Invalid entry ID provided") ) 
     1704              unless $entry; 
     1705            $url = $entry->permalink; 
     1706        } 
     1707        else { 
     1708            $url = is_valid_url( $app->param('static') ); 
     1709        } 
     1710 
    16761711        #require MT::Auth; 
    16771712        #my $ctx = MT::Auth->fetch_credentials( { app => $app } ); 
     
    16831718 
    16841719        my $blog_id = $app->param('blog_id'); 
    1685         return $app->handle_error( $app->translate('Permission denied') ) 
    1686           unless $commenter->blog_perm($blog_id)->can_comment; 
    1687  
    16881720        $app->user($commenter); 
    16891721        my $param = { 
     
    16961728            $entry_id ? ( entry_url => $url ) : ( return_url => $url ), 
    16971729        }; 
    1698         $param->{ 'auth_mode_' . $app->config->AuthenticationModule } = 1; 
     1730        $param->{ 'auth_mode_' . $commenter->auth_type } = 1; 
    16991731        require MT::Auth; 
    17001732        $param->{'email_required'} = MT::Auth->can_recover_password ? 1 : 0; 
     
    17111743      map { $_ => scalar( $q->param($_) ) } 
    17121744      qw( id name nickname email password pass_verify hint url entry_url return_url external_auth); 
    1713     $param{ 'auth_mode_' . $app->config->AuthenticationModule } = 1; 
    17141745 
    17151746    unless ( $param{id} =~ /\d+/ ) { 
     
    17241755    } 
    17251756 
    1726     #require MT::Auth; 
    1727     #my $ctx = MT::Auth->fetch_credentials( { app => $app } ); 
    1728     #my $cmntr_sess = 
     1757    $param{ 'auth_mode_' . $cmntr->auth_type } = 1; 
     1758 
     1759    # require MT::Auth; 
     1760    # my $ctx = MT::Auth->fetch_credentials( { app => $app } ); 
     1761    # my $cmntr_sess = 
    17291762    #  $app->session_user( $cmntr, $ctx->{session_id}, 
    17301763    #    permanent => $ctx->{permanent} ); 
    1731     #return $app->handle_error( $app->translate('Invalid login') ) 
     1764    # return $app->handle_error( $app->translate('Invalid login') ) 
    17321765    #  unless $cmntr_sess; 
    17331766 
     
    17741807    } 
    17751808    if ($renew_session) { 
    1776         $app->_make_commenter_session( $app->make_magic_token, $cmntr->email, 
     1809        $app->make_commenter_session( $app->make_magic_token, $cmntr->email, 
    17771810            $cmntr->name, 
    17781811            ($cmntr->nickname || $app->translate('(Display Name not set)')), 
    17791812            $cmntr->id ); 
    1780         #    $app->start_session( $cmntr, $ctx->{permanent} ); 
    1781     } 
    1782     $param{ 'auth_mode_' . $app->config->AuthenticationModule } = 1; 
     1813    } 
     1814 
    17831815    return $app->build_page( 'profile.tmpl', \%param ); 
    17841816} 
  • branches/release-36/lib/MT/Auth/MT.pm

    r1823 r2062  
    6666        $pass = $app->param('password'); 
    6767        $remember = $app->param('remember') ? 1 : 0; 
    68         return { %$ctx, username => $user, password => $pass, permanent => $remember }; 
     68        return { %$ctx, username => $user, password => $pass, permanent => $remember, auth_type => 'MT' }; 
    6969    } 
    7070    return undef; 
     
    7979    if ($cookies->{$app->user_cookie}) { 
    8080        my ($user, $session_id, $remember) = split /::/, $cookies->{$app->user_cookie}->value; 
    81         return { %$ctx, username => $user, session_id => $session_id, permanent => $remember }; 
     81        return { %$ctx, username => $user, session_id => $session_id, permanent => $remember, auth_type => 'MT' }; 
    8282    } 
    8383    return undef; 
     
    108108        # load author from db 
    109109        my $user_class = $app->user_class; 
    110         my ($author) = $user_class->search({ name => $username, type => AUTHOR }); 
     110        my ($author) = $user_class->search({ name => $username, type => AUTHOR, auth_type => 'MT' }); 
    111111 
    112112        if ($author) { 
  • branches/release-36/lib/MT/Auth/OpenID.pm

    r1914 r2062  
    117117        my $nick_escaped = escape_unicode($nick); 
    118118        $nick = encode_text($nick, 'utf-8', undef); 
    119         $session = $app->_make_commenter_session($app->make_magic_token, q(), 
     119        $session = $app->make_commenter_session($app->make_magic_token, q(), 
    120120                                                 $name, $nick_escaped, undef, $name); 
    121121        unless ($session) { 
  • branches/release-36/lib/MT/Auth/TypeKey.pm

    r1823 r2062  
    6262        my $nick_escaped = escape_unicode($nick); 
    6363        $nick = encode_text($nick, 'utf-8', undef); 
    64         $session = $app->_make_commenter_session($sig_str, $email, 
     64        $session = $app->make_commenter_session($sig_str, $email, 
    6565                                                 $name, $nick_escaped, undef, $url); 
    6666        unless ($session) { 
  • branches/release-36/lib/MT/Template/ContextHandlers.pm

    r2052 r2062  
    8282            Loop => \&_hdlr_loop, 
    8383            Section => \&_hdlr_section, 
    84             IfNonEmpty => \&_hdlr_if_nonempty, 
    85             IfNonZero => \&_hdlr_if_nonzero, 
    86  
    87             IfCommenterTrusted => \&_hdlr_commenter_trusted, 
    88             CommenterIfTrusted => \&_hdlr_commenter_trusted, 
    89             IfCommenterIsAuthor => \&_hdlr_commenter_isauthor, 
    90             IfCommenterIsEntryAuthor => \&_hdlr_commenter_isauthor, 
     84            'IfNonEmpty?' => \&_hdlr_if_nonempty, 
     85            'IfNonZero?' => \&_hdlr_if_nonzero, 
     86 
     87            'IfCommenterTrusted?' => \&_hdlr_commenter_trusted, 
     88            'CommenterIfTrusted?' => \&_hdlr_commenter_trusted, 
     89            'IfCommenterIsAuthor?' => \&_hdlr_commenter_isauthor, 
     90            'IfCommenterIsEntryAuthor?' => \&_hdlr_commenter_isauthor, 
    9191 
    9292            'IfBlog?' => \&_hdlr_blog_id, 
     
    105105            EntryCategories => \&_hdlr_entry_categories, 
    106106            EntryAdditionalCategories => \&_hdlr_entry_additional_categories, 
    107             BlogIfCommentsOpen => \&_hdlr_blog_if_comments_open, 
     107            'BlogIfCommentsOpen?' => \&_hdlr_blog_if_comments_open, 
    108108            EntryPrevious => \&_hdlr_entry_previous, 
    109109            EntryNext => \&_hdlr_entry_next, 
     
    124124            SetHashVar => \&_hdlr_set_hashvar, 
    125125 
    126             IfCommentsModerated => \&_hdlr_comments_moderated, 
    127             IfRegistrationRequired => \&_hdlr_reg_required, 
    128             IfRegistrationNotRequired => \&_hdlr_reg_not_required, 
    129             IfRegistrationAllowed => \&_hdlr_reg_allowed, 
    130  
    131             IfTypeKeyToken => \&_hdlr_if_typekey_token, 
     126            'IfCommentsModerated?' => \&_hdlr_comments_moderated, 
     127            'IfRegistrationRequired?' => \&_hdlr_reg_required, 
     128            'IfRegistrationNotRequired?' => \&_hdlr_reg_not_required, 
     129            'IfRegistrationAllowed?' => \&_hdlr_reg_allowed, 
     130 
     131            'IfTypeKeyToken?' => \&_hdlr_if_typekey_token, 
    132132 
    133133            Comments => \&_hdlr_comments, 
     
    135135            CommentsFooter => \&_hdlr_pass_tokens, 
    136136            CommentEntry => \&_hdlr_comment_entry, 
    137             CommentIfModerated => \&_hdlr_comment_if_moderated, 
     137            'CommentIfModerated?' => \&_hdlr_comment_if_moderated, 
    138138 
    139139            CommentParent => \&_hdlr_comment_parent, 
     
    159159 
    160160            Categories => \&_hdlr_categories, 
    161             CategoryIfAllowPings => \&_hdlr_category_allow_pings, 
     161            'CategoryIfAllowPings?' => \&_hdlr_category_allow_pings, 
    162162            CategoryPrevious => \&_hdlr_category_prevnext, 
    163163            CategoryNext => \&_hdlr_category_prevnext, 
     
    167167            PingEntry => \&_hdlr_ping_entry, 
    168168 
    169             IfAllowCommentHTML => \&_hdlr_if_allow_comment_html, 
    170             IfCommentsAllowed => \&_hdlr_if_comments_allowed, 
    171             IfCommentsAccepted => \&_hdlr_if_comments_accepted, 
    172             IfCommentsActive => \&_hdlr_if_comments_active, 
    173             IfPingsAllowed => \&_hdlr_if_pings_allowed, 
    174             IfPingsAccepted => \&_hdlr_if_pings_accepted, 
    175             IfPingsActive => \&_hdlr_if_pings_active, 
    176             IfPingsModerated => \&_hdlr_if_pings_moderated, 
    177             IfNeedEmail => \&_hdlr_if_need_email, 
    178             IfRequireCommentEmails => \&_hdlr_if_need_email, 
    179             EntryIfAllowComments => \&_hdlr_if_comments_active, 
    180             EntryIfCommentsOpen => \&_hdlr_entry_if_comments_open, 
    181             EntryIfAllowPings => \&_hdlr_entry_if_allow_pings, 
    182             EntryIfExtended => \&_hdlr_entry_if_extended, 
     169            'IfAllowCommentHTML?' => \&_hdlr_if_allow_comment_html, 
     170            'IfCommentsAllowed?' => \&_hdlr_if_comments_allowed, 
     171            'IfCommentsAccepted?' => \&_hdlr_if_comments_accepted, 
     172            'IfCommentsActive?' => \&_hdlr_if_comments_active, 
     173            'IfPingsAllowed?' => \&_hdlr_if_pings_allowed, 
     174            'IfPingsAccepted?' => \&_hdlr_if_pings_accepted, 
     175            'IfPingsActive?' => \&_hdlr_if_pings_active, 
     176            'IfPingsModerated?' => \&_hdlr_if_pings_moderated, 
     177            'IfNeedEmail?' => \&_hdlr_if_need_email, 
     178            'IfRequireCommentEmails?' => \&_hdlr_if_need_email, 
     179            'EntryIfAllowComments?' => \&_hdlr_entry_if_allow_comments, 
     180            'EntryIfCommentsOpen?' => \&_hdlr_entry_if_comments_open, 
     181            'EntryIfAllowPings?' => \&_hdlr_entry_if_allow_pings, 
     182            'EntryIfExtended?' => \&_hdlr_entry_if_extended, 
    183183 
    184184            SubCategories => \&_hdlr_sub_categories, 
     
    373373            RemoteSignOutLink => \&_hdlr_remote_sign_out_link, 
    374374            RemoteSignInLink => \&_hdlr_remote_sign_in_link, 
     375            SignOutLink => \&_hdlr_sign_out_link, 
     376            SignInLink => \&_hdlr_sign_in_link, 
    375377 
    376378            CommentID => \&_hdlr_comment_id, 
     
    14231425    elsif (defined(my $tag = $args->{tag})) { 
    14241426        $tag =~ s/^MT:?//i; 
    1425         my ($handler) = $ctx->handler_for($tag); 
     1427        my ($handler, $type) = $ctx->handler_for($tag); 
    14261428        if (defined($handler)) { 
    14271429            local $ctx->{__stash}{tag} = $args->{tag}; 
    14281430            $value = $handler->($ctx, { %$args }); 
    1429             if (my $ph = $ctx->post_process_handler) { 
    1430                 $value = $ph->($ctx, $args, $value); 
     1431            if ($type == 2) { # conditional tag; just use boolean 
     1432                $value = $value ? 1 : 0; 
     1433            } else { 
     1434                if (my $ph = $ctx->post_process_handler) { 
     1435                    $value = $ph->($ctx, $args, $value); 
     1436                } 
    14311437            } 
    14321438            $ctx->{__stash}{vars}{__cond_tag__} = $args->{tag}; 
     
    21862192    my $blog = $_[0]->stash('blog'); 
    21872193    if ($blog->remote_auth_token) { 
    2188         _hdlr_pass_tokens(@_); 
     2194        return 1; 
    21892195    } else { 
    2190         _hdlr_pass_tokens_else(@_); 
     2196        return 0; 
    21912197    } 
    21922198} 
     
    21952201    my $blog = $_[0]->stash('blog'); 
    21962202    if ($blog->moderate_unreg_comments || $blog->manual_approve_commenters) { 
    2197         _hdlr_pass_tokens(@_); 
     2203        return 1; 
    21982204    } else { 
    2199         _hdlr_pass_tokens_else(@_); 
     2205        return 0; 
    22002206    } 
    22012207} 
     
    22042210    my $blog = $_[0]->stash('blog'); 
    22052211    if ($blog->allow_reg_comments && $blog->commenter_authenticators) { 
    2206         _hdlr_pass_tokens(@_); 
     2212        return 1; 
    22072213    } else { 
    2208         _hdlr_pass_tokens_else(@_); 
     2214        return 0; 
    22092215    } 
    22102216} 
     
    22142220    if ( $blog->allow_reg_comments && $blog->commenter_authenticators 
    22152221        && ! $blog->allow_unreg_comments ) { 
    2216         _hdlr_pass_tokens(@_); 
     2222        return 1; 
    22172223    } else { 
    2218         _hdlr_pass_tokens_else(@_); 
     2224        return 0; 
    22192225    } 
    22202226} 
     
    22242230    if ($blog->allow_reg_comments && $blog->commenter_authenticators 
    22252231        && $blog->allow_unreg_comments) { 
    2226         _hdlr_pass_tokens(@_); 
     2232        return 1; 
    22272233    } else { 
    2228         _hdlr_pass_tokens_else(@_); 
     2234        return 0; 
    22292235    } 
    22302236} 
     
    22412247        (($blog->allow_reg_comments && $blog->effective_remote_auth_token) 
    22422248         || $blog->allow_unreg_comments)) { 
    2243         _hdlr_pass_tokens(@_); 
     2249        return 1; 
    22442250    } else { 
    2245         _hdlr_pass_tokens_else(@_); 
     2251        return 0; 
    22462252    } 
    22472253} 
     
    23842390 
    23852391    # Try to read from cache 
     2392    my $cache_expire_type = $tmpl->cache_expire_type || 0; 
    23862393    my $cache_enabled = 
    23872394         $blog 
     
    23912398        || $arg->{key} 
    23922399        || ( exists $arg->{ttl} ) 
    2393         || ( $tmpl->cache_expire_type != 0 ) ) ? 1 : 0; 
     2400        || ( $cache_expire_type != 0 ) ) ? 1 : 0; 
    23942401    my $cache_key = 
    23952402        ($arg->{cache_key} || $arg->{key}) 
     
    23982405    my $ttl = 
    23992406      exists $arg->{ttl} ? $arg->{ttl} 
    2400           : ( $tmpl->cache_expire_type == 1 ) ? $tmpl->cache_expire_interval 
    2401               : ( $tmpl->cache_expire_type == 2 ) ? 0 
     2407          : ( $cache_expire_type == 1 ) ? $tmpl->cache_expire_interval 
     2408              : ( $cache_expire_type == 2 ) ? 0 
    24022409                  :   60 * 60;    # default 60 min. 
    24032410 
    2404     if ( $tmpl->cache_expire_type == 2 ) { 
     2411    if ( $cache_expire_type == 2 ) { 
    24052412        my @types = split /,/, ($tmpl->cache_expire_event || ''); 
    24062413        if (@types) { 
     
    27362743    } 
    27372744    if (defined($value) && $value ne '') { # want to include "0" here 
    2738         _hdlr_pass_tokens($ctx, $args, $cond); 
     2745        return 1; 
    27392746    } else { 
    2740         _hdlr_pass_tokens_else($ctx, undef, $cond); 
     2747        return 0; 
    27412748    } 
    27422749} 
     
    27612768    } 
    27622769    if (defined($value) && $value) { 
    2763         _hdlr_pass_tokens($ctx, $args, $cond); 
     2770        return 1; 
    27642771    } else { 
    2765         _hdlr_pass_tokens_else($ctx, undef, $cond); 
     2772        return 0; 
    27662773    } 
    27672774} 
     
    40494056                } 
    40504057                $no_resort = 0; 
     4058            } elsif ($class->is_meta_column($args->{sort_by})) { 
     4059                $no_resort = 0; 
    40514060            } 
    40524061        } 
     
    41074116                if (my $def = $class->column_def($col)) { 
    41084117                    if ($def->{type} =~ m/^integer|float$/) { 
     4118                        @$entries = $so eq 'ascend' ? 
     4119                            sort { $a->$col() <=> $b->$col() } @$entries : 
     4120                            sort { $b->$col() <=> $a->$col() } @$entries; 
     4121                    } else { 
     4122                        @$entries = $so eq 'ascend' ? 
     4123                            sort { $a->$col() cmp $b->$col() } @$entries : 
     4124                            sort { $b->$col() cmp $a->$col() } @$entries; 
     4125                    } 
     4126                    $no_resort = 1; 
     4127                } elsif ($class->is_meta_column($col)) { 
     4128                    my $type = MT::Meta->metadata_by_name($class, $col); 
     4129                    no warnings; 
     4130                    if ($type->{type} =~ m/integer|float/) { 
    41094131                        @$entries = $so eq 'ascend' ? 
    41104132                            sort { $a->$col() <=> $b->$col() } @$entries : 
     
    42264248            if (my $def = $class->column_def($col)) { 
    42274249                if ($def->{type} =~ m/^integer|float$/) { 
     4250                    @entries = $so eq 'ascend' ? 
     4251                        sort { $a->$col() <=> $b->$col() } @entries : 
     4252                        sort { $b->$col() <=> $a->$col() } @entries; 
     4253                } else { 
     4254                    @entries = $so eq 'ascend' ? 
     4255                        sort { $a->$col() cmp $b->$col() } @entries : 
     4256                        sort { $b->$col() cmp $a->$col() } @entries; 
     4257                } 
     4258            } elsif ($class->is_meta_column($col)) { 
     4259                my $type = MT::Meta->metadata_by_name($class, $col); 
     4260                no warnings; 
     4261                if ($type->{type} =~ m/integer|float/) { 
    42284262                    @entries = $so eq 'ascend' ? 
    42294263                        sort { $a->$col() <=> $b->$col() } @entries : 
     
    47884822    my $builder = $ctx->stash('builder'); 
    47894823    my $tokens = $ctx->stash('tokens'); 
    4790     my $res; 
     4824    my $res = ''; 
    47914825    my $glue = $args->{glue}; 
    47924826    for my $cat (@$cats) { 
     
    48084842    my $tp_token = $blog->effective_remote_auth_token(); 
    48094843    return $tp_token; 
     4844} 
     4845 
     4846sub _hdlr_sign_in_link { 
     4847    my ($ctx, $args) = @_;     
     4848    my $cfg = $ctx->{config}; 
     4849    my $blog = $ctx->stash('blog'); 
     4850    my $path = _hdlr_cgi_path($ctx); 
     4851    $path .= '/' unless $path =~ m!/$!; 
     4852    my $comment_script = $cfg->CommentScript; 
     4853    my $static_arg = $args->{static} ? "&static=" . $args->{static} : "&static=0"; 
     4854    my $e = $ctx->stash('entry'); 
     4855    return "$path$comment_script?__mode=login$static_arg" . 
     4856        ($blog ? '&blog_id=' . $blog->id : '') . 
     4857        ($e ? '&entry_id=' . $e->id : ''); 
     4858} 
     4859 
     4860sub _hdlr_sign_out_link { 
     4861    my ($ctx, $args) = @_; 
     4862    my $cfg = $ctx->{config}; 
     4863    my $path = _hdlr_cgi_path($ctx); 
     4864    $path .= '/' unless $path =~ m!/$!; 
     4865    my $comment_script = $cfg->CommentScript; 
     4866    my $static_arg; 
     4867    if ($args->{no_static}) { 
     4868        $static_arg = q(); 
     4869    } else { 
     4870        my $url = $args->{static}; 
     4871        if ($url && ($url ne '1')) { 
     4872            $static_arg = "&static=" . MT::Util::encode_url($url); 
     4873        } elsif ($url) { 
     4874            $static_arg = "&static=1"; 
     4875        } else { 
     4876            $static_arg = "&static=0"; 
     4877        } 
     4878    } 
     4879    my $e = $_[0]->stash('entry'); 
     4880    return "$path$comment_script?__mode=handle_sign_in$static_arg&logout=1" . 
     4881        ($e ? "&amp;entry_id=" . $e->id : ''); 
    48104882} 
    48114883 
     
    49975069        if ($r eq 'js') { 
    49985070            # output javascript here to render relative date 
     5071            my($y, $mo, $d, $h, $m, $s) = $ts =~ /(\d\d\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)/; 
     5072            $mo--; 
     5073            my $fds = format_ts($args->{'format'}, $ts, $blog, $lang); 
     5074            my $js = <<EOT; 
     5075<script type="text/javascript"> 
     5076/* <![CDATA[ */ 
     5077document.write(mtRelativeDate(new Date($y,$mo,$d,$h,$m,$s), '$fds')); 
     5078/* ]]> */ 
     5079</script><noscript>$fds</noscript> 
     5080EOT 
     5081            return $js; 
    49995082        } else { 
    50005083            my $old_lang = MT->current_language; 
     
    53465429        or return $_[0]->_no_comment_error('MTCommentIfModerated'); 
    53475430    if ($c->visible) { 
    5348         return _hdlr_pass_tokens(@_); 
     5431        return 1; 
    53495432    } else { 
    5350         return _hdlr_pass_tokens_else(@_); 
     5433        return 0; 
    53515434    } 
    53525435} 
     
    55285611    my $label = $args->{label} || $args->{text} || MT->translate('Reply'); 
    55295612    my $comment_author = MT::Util::encode_js($comment->author); 
    5530  
    5531     return sprintf(qq(<a title="%s" href="javascript:void(0);" onclick="replyComment(%d, '%s')">%s</a>), 
     5613    my $onclick = $args->{onclick} || 'mtReplyCommentOnClick'; 
     5614 
     5615    return sprintf(qq(<a title="%s" href="javascript:void(0);" onclick="$onclick(%d, '%s')">%s</a>), 
    55325616                   $label, $comment->id, $comment_author, $label); 
    55335617} 
     
    55355619sub _hdlr_comment_parent_id { 
    55365620    my $args = $_[1]; 
    5537     my $c = $_[0]->stash('comment') 
    5538         or return $_[0]->_no_comment_error('MTCommentParentID'); 
     5621    my $c = $_[0]->stash('comment') or return ''; 
    55395622    my $id = $c->parent_id || 0; 
    55405623    $args && $args->{pad} ? (sprintf "%06d", $id) : ($id ? $id : ''); 
     
    57455828    return '' unless $a; 
    57465829    if ($a->is_trusted($ctx->stash('blog_id'))) { 
    5747         return _hdlr_pass_tokens(@_); 
     5830        return 1; 
    57485831    } else { 
    5749         return _hdlr_pass_tokens_else(@_); 
     5832        return 0; 
    57505833    } 
    57515834} 
     
    57545837    my ($ctx, $args, $cond) = @_; 
    57555838    my $a = $ctx->stash('commenter'); 
    5756     return _hdlr_pass_tokens_else(@_) 
    5757       unless $a; 
     5839    return 0 unless $a; 
    57585840    if ($a->type == MT::Author::AUTHOR()) { 
    57595841        my $tag = lc $ctx->stash('tag'); 
     
    57635845            if ($e) { 
    57645846                if ($e->author_id == $a->id) { 
    5765                     return _hdlr_pass_tokens(@_); 
     5847                    return 1; 
    57665848                } 
    57675849            } 
    57685850        } else { 
    5769             return _hdlr_pass_tokens(@_); 
    5770         } 
    5771     } 
    5772     return _hdlr_pass_tokens_else(@_); 
     5851            return 1; 
     5852        } 
     5853    } 
     5854    return 0; 
    57735855} 
    57745856 
     
    63786460    my $entry_class = MT->model( 
    63796461        $class_type eq 'category' ? 'entry' : 'page'); 
    6380      
     6462 
    63816463    my $iter = $class->load_iter(\%terms, \%args); 
    63826464    my $res = ''; 
     
    65786660    my $cat = $_[0]->stash('category') || $_[0]->stash('archive_category'); 
    65796661    if ($cat->allow_pings) { 
    6580         _hdlr_pass_tokens(@_); 
     6662        return 1; 
    65816663    } else { 
    6582         _hdlr_pass_tokens_else(@_); 
    6583     }                                  
     6664        return 0; 
     6665    } 
    65846666} 
    65856667 
     
    67066788    my $builder = $ctx->stash('builder'); 
    67076789    my $tokens = $ctx->stash('tokens'); 
    6708     my $res; 
     6790    my $res = ''; 
    67096791    my $glue = $args->{glue}; 
    67106792    for my $cat (@$cats) { 
     
    68586940    return '' unless $blog; 
    68596941    if ($blog->allow_comment_html) { 
    6860         return _hdlr_pass_tokens(@_); 
     6942        return 1; 
    68616943    } else { 
    6862         return _hdlr_pass_tokens_else(@_); 
     6944        return 0; 
    68636945    } 
    68646946} 
     
    68726954                                  && $blog->effective_remote_auth_token)))) 
    68736955        && $cfg->AllowComments) { 
    6874         return _hdlr_pass_tokens(@_); 
     6956        return 1; 
    68756957    } else { 
    6876         return _hdlr_pass_tokens_else(@_); 
     6958        return 0; 
    68776959    } 
    68786960} 
     
    68926974    } 
    68936975    if ($active) { 
    6894         return _hdlr_pass_tokens(@_); 
     6976        return 1; 
    68956977    } else { 
    6896         return _hdlr_pass_tokens_else(@_); 
     6978        return 0; 
    68976979    } 
    68986980} 
     
    69076989    $accepted = 0 if $entry && !$entry->allow_comments; 
    69086990    if ($accepted) { 
    6909         return _hdlr_pass_tokens(@_); 
     6991        return 1; 
    69106992    } else { 
    6911         return _hdlr_pass_tokens_else(@_); 
     6993        return 0; 
    69126994    } 
    69136995} 
     
    69237005    $active = 1 if !$active && $entry && $entry->ping_count; 
    69247006    if ($active) { 
    6925         return _hdlr_pass_tokens(@_); 
     7007        return 1; 
    69267008    } else { 
    6927         return _hdlr_pass_tokens_else(@_); 
     7009        return 0; 
    69287010    } 
    69297011} 
     
    69337015    my $blog = $ctx->stash('blog'); 
    69347016    if ($blog->moderate_pings) { 
    6935         return _hdlr_pass_tokens(@_); 
     7017        return 1; 
    69367018    } else { 
    6937         return _hdlr_pass_tokens_else(@_); 
     7019        return 0; 
    69387020    } 
    69397021} 
     
    69487030    $accepted = 0 if $entry && !$entry->allow_pings; 
    69497031    if ($accepted) {