| 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. */ |
| | 7 | function hideDocumentElement(id) { return mtHide(id) } |
| | 8 | function showDocumentElement(id) { return mtShow(id) } |
| | 9 | function individualArchivesOnLoad() { return mtEntryOnLoad() } |
| | 10 | function writeCommenterGreeting() { return mtShowGreeting() } |
| | 11 | function rememberMe(f) { return mtRememberMe(f) } |
| | 12 | function forgetMe(f) { return mtForgetMe(f) } |
| | 13 | </mt:ignore> |
| | 14 | |
| | 15 | // The cookie name to use for storing the blog-side comment session cookie. |
| | 16 | var cookie_name = "mt_blog<$MTBlogID$>_user"; |
| | 17 | // The cookie path to use for storing the blog-side comment session cookie. |
| | 18 | var 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> |
| | 26 | function 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> |
| | 37 | function mtShow(id) { |
| | 38 | var el = (typeof id == "string") ? document.getElementById(id) : id; |
| | 39 | if (el) el.style.display = 'block'; |
| 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> |
| | 48 | function 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> |
| | 60 | function 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> |
| | 101 | function 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&_type=entry&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> |
| | 116 | function mtShowCaptcha() { |
| | 117 | if (captcha_timer) clearInterval(captcha_timer); |
| 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'); |
| | 144 | var 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> |
| | 151 | function 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> |
| | 165 | function mtEscapeJS(s) { |
| | 166 | s = s.replace(/'/g, "'"); |
| | 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> |
| | 176 | function mtUnescapeJS(s) { |
| | 177 | s = s.replace(/'/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> |
| | 186 | function 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> |
| | 209 | function 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; |
| 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> |
| | 239 | function 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> |
| | 262 | function 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> |
| | 272 | function 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> |
| | 288 | var mtRequestSubmitted = false; |
| | 289 | function 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> |
| | 318 | function 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'); |
| 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> |
| | 384 | function 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> |
| | 399 | function 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> |
| | 411 | function 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>'; |
| 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> |
| | 468 | function mtReplyCommentOnClick(parent_id, author) { |
| | 469 | mtShow('comment-form-reply'); |
| | 470 | |
| 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> |
| | 507 | function 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> |
| | 551 | function mtClearUser() { |
| | 552 | mtDeleteCookie(cookie_name, blog_path); |
| | 553 | } |
| | 554 | |
| | 555 | <mt:ignore> |
| | 556 | /*** |
| | 557 | * Sets a browser cookie. |
| | 558 | */ |
| | 559 | </mt:ignore> |
| | 560 | function 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> |
| | 574 | function 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> |
| | 591 | function 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 | |
| | 600 | function 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> |
| | 611 | function 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 | } |