| 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 mtCookieName = "<$mt:UserSessionCookieName$>"; |
|---|
| 17 | var mtCookieDomain = "<$mt:UserSessionCookieDomain$>"; |
|---|
| 18 | var mtCookiePath = "<$mt:UserSessionCookiePath$>"; |
|---|
| 19 | var mtCookieTimeout = <$mt:UserSessionCookieTimeout$>; |
|---|
| 20 | |
|---|
| 21 | <mt:Ignore> |
|---|
| 22 | /*** |
|---|
| 23 | * Simple routine for showing a DOM element (applying a CSS display |
|---|
| 24 | * attribute of 'none'). |
|---|
| 25 | */ |
|---|
| 26 | </mt:Ignore> |
|---|
| 27 | function mtHide(id) { |
|---|
| 28 | var el = (typeof id == "string") ? document.getElementById(id) : id; |
|---|
| 29 | if (el) el.style.display = 'none'; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | <mt:Ignore> |
|---|
| 33 | /*** |
|---|
| 34 | * Simple routine for showing a DOM element (applying a CSS display |
|---|
| 35 | * attribute of 'block'). |
|---|
| 36 | */ |
|---|
| 37 | </mt:Ignore> |
|---|
| 38 | function mtShow(id) { |
|---|
| 39 | var el = (typeof id == "string") ? document.getElementById(id) : id; |
|---|
| 40 | if (el) el.style.display = 'block'; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | <mt:Ignore> |
|---|
| 44 | /*** |
|---|
| 45 | * A utility function for assigning/adding handlers to window events. |
|---|
| 46 | */ |
|---|
| 47 | </mt:Ignore> |
|---|
| 48 | function mtAttachEvent(eventName,func) { |
|---|
| 49 | var onEventName = 'on' + eventName; |
|---|
| 50 | var old = window[onEventName]; |
|---|
| 51 | if( typeof old != 'function' ) |
|---|
| 52 | window[onEventName] = func; |
|---|
| 53 | else { |
|---|
| 54 | window[onEventName] = function( evt ) { |
|---|
| 55 | old( evt ); |
|---|
| 56 | return func( evt ); |
|---|
| 57 | }; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | <mt:Ignore> |
|---|
| 62 | /*** |
|---|
| 63 | * Calls the event named, if there are handlers for it. |
|---|
| 64 | */ |
|---|
| 65 | </mt:Ignore> |
|---|
| 66 | function mtFireEvent(eventName,param) { |
|---|
| 67 | var fn = window['on' + eventName]; |
|---|
| 68 | if (typeof fn == 'function') return fn(param); |
|---|
| 69 | return; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | <mt:Ignore> |
|---|
| 73 | /*** |
|---|
| 74 | * Displays a relative date. |
|---|
| 75 | * 'ts' is a Date object, 'fds' is a string of the date which |
|---|
| 76 | * will be displayed if the given date is older than 1 week. |
|---|
| 77 | */ |
|---|
| 78 | </mt:Ignore> |
|---|
| 79 | function mtRelativeDate(ts, fds) { |
|---|
| 80 | var now = new Date(); |
|---|
| 81 | var ref = ts; |
|---|
| 82 | var delta = Math.floor((now.getTime() - ref.getTime()) / 1000); |
|---|
| 83 | |
|---|
| 84 | var str; |
|---|
| 85 | if (delta < 60) { |
|---|
| 86 | str = '<__trans phrase="moments ago">'; |
|---|
| 87 | } else if (delta <= 86400) { |
|---|
| 88 | // less than 1 day |
|---|
| 89 | var hours = Math.floor(delta / 3600); |
|---|
| 90 | var min = Math.floor((delta % 3600) / 60); |
|---|
| 91 | if (hours == 1) |
|---|
| 92 | str = '<__trans phrase="[quant,_1,hour,hours] ago" params="1">'; |
|---|
| 93 | else if (hours > 1) |
|---|
| 94 | str = '<__trans phrase="[quant,_1,hour,hours] ago" params="2">'.replace(/2/, hours); |
|---|
| 95 | else if (min == 1) |
|---|
| 96 | str = '<__trans phrase="[quant,_1,minute,minutes] ago" params="1">'; |
|---|
| 97 | else |
|---|
| 98 | str = '<__trans phrase="[quant,_1,minute,minutes] ago" params="2">'.replace(/2/, min); |
|---|
| 99 | } else if (delta <= 604800) { |
|---|
| 100 | // less than 1 week |
|---|
| 101 | var days = Math.floor(delta / 86400); |
|---|
| 102 | var hours = Math.floor((delta % 86400) / 3600); |
|---|
| 103 | if (days == 1) |
|---|
| 104 | str = '<__trans phrase="[quant,_1,day,days] ago" params="1">'; |
|---|
| 105 | else if (days > 1) |
|---|
| 106 | str = '<__trans phrase="[quant,_1,day,days] ago" params="2">'.replace(/2/, days); |
|---|
| 107 | else if (hours == 1) |
|---|
| 108 | str = '<__trans phrase="[quant,_1,hour,hours] ago" params="1">'; |
|---|
| 109 | else |
|---|
| 110 | str = '<__trans phrase="[quant,_1,hour,hours] ago" params="2">'.replace(/2/, hours); |
|---|
| 111 | } |
|---|
| 112 | return str ? str : fds; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | <mt:Ignore> |
|---|
| 116 | /*** |
|---|
| 117 | * Used to display an edit link for the given entry. |
|---|
| 118 | */ |
|---|
| 119 | </mt:Ignore> |
|---|
| 120 | function mtEditLink(entry_id, author_id) { |
|---|
| 121 | var u = mtGetUser(); |
|---|
| 122 | if (! u) return; |
|---|
| 123 | if (! entry_id) return; |
|---|
| 124 | if (! author_id) return; |
|---|
| 125 | if (u.id != author_id) return; |
|---|
| 126 | var link = '<__trans phrase='<a href="[_1]">Edit</a>' params="<$mt:AdminScript$>?__mode=view&_type=entry&id=' + entry_id + '">'; |
|---|
| 127 | document.write(link); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | <mt:Ignore> |
|---|
| 131 | /*** |
|---|
| 132 | * Displays a captcha field for anonymous commenters. |
|---|
| 133 | */ |
|---|
| 134 | </mt:Ignore> |
|---|
| 135 | var mtCaptchaVisible = false; |
|---|
| 136 | function mtShowCaptcha() { |
|---|
| 137 | var u = mtGetUser(); |
|---|
| 138 | if ( u && u.is_authenticated ) return; |
|---|
| 139 | if (mtCaptchaVisible) return; |
|---|
| 140 | var div = document.getElementById('comments-open-captcha'); |
|---|
| 141 | if (div) { |
|---|
| 142 | div.innerHTML = '<$mt:CaptchaFields$>'; |
|---|
| 143 | mtCaptchaVisible = true; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | <mt:Ignore> |
|---|
| 148 | /* user object |
|---|
| 149 | -- saved in user cookie -- |
|---|
| 150 | u.name (display name) |
|---|
| 151 | u.url (link to home page) |
|---|
| 152 | u.email (for anonymous only) |
|---|
| 153 | u.userpic (url for commenter/author) |
|---|
| 154 | u.profile (link to profile) |
|---|
| 155 | u.is_trusted (boolean) |
|---|
| 156 | u.is_author (user has posting rights) |
|---|
| 157 | u.is_banned (banned status; neither post/comment perms) |
|---|
| 158 | u.can_post (has permission to post) |
|---|
| 159 | u.can_comment (has permission to comment) |
|---|
| 160 | |
|---|
| 161 | -- status fields -- |
|---|
| 162 | u.is_authenticated (boolean) |
|---|
| 163 | u.is_anonymous (user is anonymous) |
|---|
| 164 | */ |
|---|
| 165 | </mt:Ignore> |
|---|
| 166 | |
|---|
| 167 | var is_preview; |
|---|
| 168 | var user; |
|---|
| 169 | <mt:Ignore> |
|---|
| 170 | /*** |
|---|
| 171 | * Assigns a user object as the actively logged in user; also saves the |
|---|
| 172 | * user information in a browser cookie. |
|---|
| 173 | */ |
|---|
| 174 | </mt:Ignore> |
|---|
| 175 | function mtSetUser(u) { |
|---|
| 176 | if (u) { |
|---|
| 177 | // persist this |
|---|
| 178 | user = u; |
|---|
| 179 | mtSaveUser(); |
|---|
| 180 | // sync up user greeting |
|---|
| 181 | mtFireEvent('usersignin'); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | <mt:Ignore> |
|---|
| 186 | /*** |
|---|
| 187 | * Simple function that escapes single quote characters for storing |
|---|
| 188 | * in a cookie. |
|---|
| 189 | */ |
|---|
| 190 | </mt:Ignore> |
|---|
| 191 | function mtEscapeJS(s) { |
|---|
| 192 | s = s.replace(/'/g, "'"); |
|---|
| 193 | return s; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | <mt:Ignore> |
|---|
| 197 | /*** |
|---|
| 198 | * Simple function that unescapes single quote characters that were |
|---|
| 199 | * stored in a cookie. |
|---|
| 200 | */ |
|---|
| 201 | </mt:Ignore> |
|---|
| 202 | function mtUnescapeJS(s) { |
|---|
| 203 | s = s.replace(/'/g, "'"); |
|---|
| 204 | return s; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | <mt:Ignore> |
|---|
| 208 | /*** |
|---|
| 209 | * Serializes a user object into a string, suitable for storing as a cookie. |
|---|
| 210 | */ |
|---|
| 211 | </mt:Ignore> |
|---|
| 212 | function mtBakeUserCookie(u) { |
|---|
| 213 | var str = ""; |
|---|
| 214 | if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';"; |
|---|
| 215 | if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';"; |
|---|
| 216 | if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';"; |
|---|
| 217 | if (u.is_authenticated) str += "is_authenticated:'1';"; |
|---|
| 218 | if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';"; |
|---|
| 219 | if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';"; |
|---|
| 220 | str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';"; |
|---|
| 221 | str += "is_author:'" + (u.is_author ? "1" : "0") + "';"; |
|---|
| 222 | str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';"; |
|---|
| 223 | str += "can_post:'" + (u.can_post ? "1" : "0") + "';"; |
|---|
| 224 | str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';"; |
|---|
| 225 | str = str.replace(/;$/, ''); |
|---|
| 226 | return str; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | <mt:Ignore> |
|---|
| 230 | /*** |
|---|
| 231 | * Unserializes a user cookie and returns a user object with the restored |
|---|
| 232 | * state. |
|---|
| 233 | */ |
|---|
| 234 | </mt:Ignore> |
|---|
| 235 | function mtUnbakeUserCookie(s) { |
|---|
| 236 | if (!s) return; |
|---|
| 237 | |
|---|
| 238 | var u = {}; |
|---|
| 239 | var m; |
|---|
| 240 | while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { |
|---|
| 241 | s = s.substring(m[1].length); |
|---|
| 242 | if (m[2].match(/^(is|can)_/)) // boolean fields |
|---|
| 243 | u[m[2]] = m[3] == '1' ? true : false; |
|---|
| 244 | else |
|---|
| 245 | u[m[2]] = mtUnescapeJS(m[3]); |
|---|
| 246 | } |
|---|
| 247 | if (u.is_authenticated) { |
|---|
| 248 | u.is_anonymous = false; |
|---|
| 249 | } else { |
|---|
| 250 | u.is_anonymous = true; |
|---|
| 251 | u.can_post = false; |
|---|
| 252 | u.is_author = false; |
|---|
| 253 | u.is_banned = false; |
|---|
| 254 | u.is_trusted = false; |
|---|
| 255 | } |
|---|
| 256 | return u; |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | <mt:Ignore> |
|---|
| 260 | /*** |
|---|
| 261 | * Retrieves an object of the currently logged in user's state. |
|---|
| 262 | * If no user is logged in or cookied, this will return null. |
|---|
| 263 | */ |
|---|
| 264 | </mt:Ignore> |
|---|
| 265 | function mtGetUser() { |
|---|
| 266 | if (!user) { |
|---|
| 267 | var cookie = mtGetCookie(mtCookieName); |
|---|
| 268 | if (!cookie) return; |
|---|
| 269 | user = mtUnbakeUserCookie(cookie); |
|---|
| 270 | if (! user) { |
|---|
| 271 | user = {}; |
|---|
| 272 | user.is_anonymous = true; |
|---|
| 273 | user.can_post = false; |
|---|
| 274 | user.is_author = false; |
|---|
| 275 | user.is_banned = false; |
|---|
| 276 | user.is_trusted = false; |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | return user; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | <mt:Ignore> |
|---|
| 283 | /*** |
|---|
| 284 | * Issues a request to the MT comment script to retrieve the currently |
|---|
| 285 | * logged-in user (if any). |
|---|
| 286 | */ |
|---|
| 287 | </mt:Ignore> |
|---|
| 288 | function mtFetchUser(cb) { |
|---|
| 289 | if (!cb) cb = 'mtSetUser'; |
|---|
| 290 | if ( ( cb == 'mtSetUser' ) && mtGetUser() ) { |
|---|
| 291 | var url = document.URL; |
|---|
| 292 | url = url.replace(/#.+$/, ''); |
|---|
| 293 | url += '#comments-open'; |
|---|
| 294 | location.href = url; |
|---|
| 295 | } else { |
|---|
| 296 | // we aren't using AJAX for this, since we may have to request |
|---|
| 297 | // from a different domain. JSONP to the rescue. |
|---|
| 298 | var script = document.createElement('script'); |
|---|
| 299 | script.src = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=session_js&blog_id=<$mt:BlogID$>&jsonp=' + cb; |
|---|
| 300 | (document.getElementsByTagName('head'))[0].appendChild(script); |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | <mt:Ignore> |
|---|
| 305 | /*** |
|---|
| 306 | * Called when the 'Remember me' checkbox is changed. If the checkbox |
|---|
| 307 | * is cleared, the cached user cookie is immediately cleared. |
|---|
| 308 | */ |
|---|
| 309 | </mt:Ignore> |
|---|
| 310 | function mtRememberMeOnClick(b) { |
|---|
| 311 | if (!b.checked) |
|---|
| 312 | mtClearUser(b.form); |
|---|
| 313 | return true; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | <mt:Ignore> |
|---|
| 317 | /*** |
|---|
| 318 | * Called when comment form is sent. |
|---|
| 319 | * Required parameter: Form DOM object of comment form. |
|---|
| 320 | * If form has a 'bakecookie' member, it will be used to signal |
|---|
| 321 | * storing the anonymous commenter information to a cookie. |
|---|
| 322 | * If form has a 'armor' member, it will be used to store |
|---|
| 323 | * a token that is checked by the comment script. |
|---|
| 324 | */ |
|---|
| 325 | </mt:Ignore> |
|---|
| 326 | var mtRequestSubmitted = false; |
|---|
| 327 | function mtCommentOnSubmit(f) { |
|---|
| 328 | if (!mtRequestSubmitted) { |
|---|
| 329 | mtRequestSubmitted = true; |
|---|
| 330 | |
|---|
| 331 | if (f.armor) |
|---|
| 332 | f.armor.value = '<$mt:BlogSitePath encode_sha1="1"$>'; |
|---|
| 333 | if (f.bakecookie && f.bakecookie.checked) |
|---|
| 334 | mtSaveUser(f); |
|---|
| 335 | |
|---|
| 336 | // disable submit buttons |
|---|
| 337 | if (f.preview_button) f.preview_button.disabled = true; |
|---|
| 338 | if (f.post) f.post.disabled = true; |
|---|
| 339 | return true; |
|---|
| 340 | } |
|---|
| 341 | return false; |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | function mtUserOnLoad() { |
|---|
| 345 | var u = mtGetUser(); |
|---|
| 346 | |
|---|
| 347 | // if the user is authenticated, hide the 'anonymous' fields |
|---|
| 348 | // and any captcha input if already shown |
|---|
| 349 | if ( document.getElementById('comments-form')) { |
|---|
| 350 | if ( u && u.is_authenticated ) { |
|---|
| 351 | mtShow('comments-form'); |
|---|
| 352 | mtHide('comments-open-data'); |
|---|
| 353 | if (mtCaptchaVisible) |
|---|
| 354 | mtHide('comments-open-captcha'); |
|---|
| 355 | } else { |
|---|
| 356 | <mt:IfRegistrationRequired> |
|---|
| 357 | mtHide('comments-form'); |
|---|
| 358 | </mt:IfRegistrationRequired> |
|---|
| 359 | } |
|---|
| 360 | if ( u && u.is_banned ) |
|---|
| 361 | mtHide('comments-form'); |
|---|
| 362 | |
|---|
| 363 | // if we're previewing a comment, make sure the captcha |
|---|
| 364 | // field is visible |
|---|
| 365 | if (is_preview) |
|---|
| 366 | mtShowCaptcha(); |
|---|
| 367 | else |
|---|
| 368 | mtShowGreeting(); |
|---|
| 369 | |
|---|
| 370 | // populate anonymous comment fields if user is cookied as anonymous |
|---|
| 371 | var cf = document['comments_form']; |
|---|
| 372 | if (cf) { |
|---|
| 373 | if (u && u.is_anonymous) { |
|---|
| 374 | if (u.email) cf.email.value = u.email; |
|---|
| 375 | if (u.name) cf.author.value = u.name; |
|---|
| 376 | if (u.url) cf.url.value = u.url; |
|---|
| 377 | if (cf.bakecookie) |
|---|
| 378 | cf.bakecookie.checked = u.name || u.email; |
|---|
| 379 | } |
|---|
| 380 | if (cf.post.disabled) { |
|---|
| 381 | cf.post.disabled = false; |
|---|
| 382 | cf.post.value = '<__trans phrase="Submit">'; |
|---|
| 383 | } |
|---|
| 384 | if (cf.preview_button.disabled) { |
|---|
| 385 | cf.preview_button.disabled = false; |
|---|
| 386 | cf.preview_button.value = '<__trans phrase="Preview">'; |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | <mt:Ignore> |
|---|
| 393 | /*** |
|---|
| 394 | * Called when an entry archive page is loaded. |
|---|
| 395 | * This routine controls which elements of the comment form are shown |
|---|
| 396 | * or hidden, depending on commenter type and blog configuration. |
|---|
| 397 | */ |
|---|
| 398 | </mt:Ignore> |
|---|
| 399 | function mtEntryOnLoad() { |
|---|
| 400 | <mt:Unless tag="IfPingsAccepted">mtHide('trackbacks-info');</mt:Unless> |
|---|
| 401 | <mt:Unless tag="IfCommentsAccepted">mtHide('comments-open');</mt:Unless> |
|---|
| 402 | mtFireEvent('usersignin'); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | mtAttachEvent('usersignin', mtUserOnLoad); |
|---|
| 406 | |
|---|
| 407 | <mt:Ignore> |
|---|
| 408 | /*** |
|---|
| 409 | * Handles the action of the "Sign in" link. First clears any existing |
|---|
| 410 | * user cookie, then directs to the MT comment script to sign the user in. |
|---|
| 411 | */ |
|---|
| 412 | </mt:Ignore> |
|---|
| 413 | function mtSignIn() { |
|---|
| 414 | var doc_url = document.URL; |
|---|
| 415 | doc_url = doc_url.replace(/#.+/, ''); |
|---|
| 416 | var url = '<$mt:SignInLink$>'; |
|---|
| 417 | url += '&return_url=' + encodeURIComponent(doc_url); |
|---|
| 418 | mtClearUser(); |
|---|
| 419 | location.href = url; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | function mtSignInOnClick(sign_in_element) { |
|---|
| 423 | var el; |
|---|
| 424 | if (sign_in_element) { |
|---|
| 425 | // display throbber |
|---|
| 426 | el = document.getElementById(sign_in_element); |
|---|
| 427 | if (!el) // legacy MT 4.x element id |
|---|
| 428 | el = document.getElementById('comment-form-external-auth'); |
|---|
| 429 | } |
|---|
| 430 | if (el) |
|---|
| 431 | el.innerHTML = '<__trans phrase="Signing in..."> <img src="<$mt:StaticWebPath$>images/indicator.white.gif" height="16" width="16" alt="" />'; |
|---|
| 432 | |
|---|
| 433 | mtClearUser(); // clear any 'anonymous' user cookie to allow sign in |
|---|
| 434 | mtFetchUser('mtSetUserOrLogin'); |
|---|
| 435 | return false; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | function mtSetUserOrLogin(u) { |
|---|
| 439 | if (u && u.is_authenticated) { |
|---|
| 440 | mtSetUser(u); |
|---|
| 441 | } else { |
|---|
| 442 | // user really isn't logged in; so let's do this! |
|---|
| 443 | mtSignIn(); |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | <mt:Ignore> |
|---|
| 448 | /*** |
|---|
| 449 | * Handles sign out from the web site. |
|---|
| 450 | * First clears any existing user cookie, then direts to the MT comment |
|---|
| 451 | * script to sign the user out. |
|---|
| 452 | */ |
|---|
| 453 | </mt:Ignore> |
|---|
| 454 | function mtSignOut(entry_id) { |
|---|
| 455 | mtClearUser(); |
|---|
| 456 | var url = '<$mt:SignOutLink$>&return_to=' + encodeURIComponent(location.href); |
|---|
| 457 | location.href = url; |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | <mt:Ignore> |
|---|
| 461 | /*** |
|---|
| 462 | * Handles the action of the "Sign out" link. |
|---|
| 463 | */ |
|---|
| 464 | </mt:Ignore> |
|---|
| 465 | function mtSignOutOnClick() { |
|---|
| 466 | mtSignOut(); |
|---|
| 467 | return false; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | <mt:Ignore> |
|---|
| 471 | /*** |
|---|
| 472 | * Handles the display of the greeting message, depending on what kind of |
|---|
| 473 | * user is logged in and blog comment policy. |
|---|
| 474 | */ |
|---|
| 475 | </mt:Ignore> |
|---|
| 476 | function mtShowGreeting() { |
|---|
| 477 | <mt:IfRegistrationAllowed> |
|---|
| 478 | var reg_reqd = <mt:IfRegistrationRequired>true<mt:Else>false</mt:IfRegistrationRequired>; |
|---|
| 479 | |
|---|
| 480 | var cf = document.comments_form; |
|---|
| 481 | if (!cf) return; |
|---|
| 482 | |
|---|
| 483 | var el = document.getElementById('comment-greeting'); |
|---|
| 484 | if (!el) // legacy MT 4.x element id |
|---|
| 485 | el = document.getElementById('comment-form-external-auth'); |
|---|
| 486 | if (!el) return; |
|---|
| 487 | |
|---|
| 488 | var eid = cf.entry_id; |
|---|
| 489 | var entry_id; |
|---|
| 490 | if (eid) entry_id = eid.value; |
|---|
| 491 | |
|---|
| 492 | var phrase; |
|---|
| 493 | var u = mtGetUser(); |
|---|
| 494 | |
|---|
| 495 | if ( u && u.is_authenticated ) { |
|---|
| 496 | if ( u.is_banned ) { |
|---|
| 497 | phrase = '<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="javascript:void(0);" onclick="return mtSignOutOnClick();">%%</a>">'; |
|---|
| 498 | } else { |
|---|
| 499 | var user_link; |
|---|
| 500 | if ( u.is_author ) { |
|---|
| 501 | user_link = '<a href="<$mt:CGIPath$><$mt:CommentScript$>?__mode=edit_profile&blog_id=<$mt:BlogID$>'; |
|---|
| 502 | if (entry_id) |
|---|
| 503 | user_link += '&entry_id=' + entry_id; |
|---|
| 504 | user_link += '">' + u.name + '</a>'; |
|---|
| 505 | } else { |
|---|
| 506 | // registered user, but not a user with posting rights |
|---|
| 507 | if (u.url) |
|---|
| 508 | user_link = '<a href="' + u.url + '">' + u.name + '</a>'; |
|---|
| 509 | else |
|---|
| 510 | user_link = u.name; |
|---|
| 511 | } |
|---|
| 512 | // TBD: supplement phrase with userpic if one is available. |
|---|
| 513 | phrase = '<__trans phrase="Thanks for signing in, [_1]. ([_2]sign out[_3])" params="' + user_link + '%%<a href="javascript:void(0)" onclick="return mtSignOutOnClick();">%%</a>">'; |
|---|
| 514 | } |
|---|
| 515 | } else { |
|---|
| 516 | if (reg_reqd) { |
|---|
| 517 | phrase = '<__trans phrase="[_1]Sign in[_2] to comment." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'comment-greeting\')">%%</a>">'; |
|---|
| 518 | } else { |
|---|
| 519 | phrase = '<__trans phrase="[_1]Sign in[_2] to comment, or comment anonymously." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'comment-greeting\')">%%</a>">'; |
|---|
| 520 | } |
|---|
| 521 | } |
|---|
| 522 | el.innerHTML = phrase; |
|---|
| 523 | <mt:Else> |
|---|
| 524 | mtShowCaptcha(); |
|---|
| 525 | </mt:IfRegistrationAllowed> |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | <mt:Ignore> |
|---|
| 529 | /*** |
|---|
| 530 | * Handles the action of the 'Reply' links. |
|---|
| 531 | */ |
|---|
| 532 | </mt:Ignore> |
|---|
| 533 | function mtReplyCommentOnClick(parent_id, author) { |
|---|
| 534 | mtShow('comment-form-reply'); |
|---|
| 535 | |
|---|
| 536 | var checkbox = document.getElementById('comment-reply'); |
|---|
| 537 | var label = document.getElementById('comment-reply-label'); |
|---|
| 538 | var text = document.getElementById('comment-text'); |
|---|
| 539 | |
|---|
| 540 | // Populate label with new values |
|---|
| 541 | var reply_text = '<__trans phrase="Replying to <a href="[_1]" onclick="[_2]">comment from [_3]</a>" params="#comment-'+ parent_id +'%%location.href=this.href; return false%%'+ author +'">'; |
|---|
| 542 | label.innerHTML = reply_text; |
|---|
| 543 | |
|---|
| 544 | checkbox.value = parent_id; |
|---|
| 545 | checkbox.checked = true; |
|---|
| 546 | text.focus(); |
|---|
| 547 | |
|---|
| 548 | mtSetCommentParentID(); |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | <mt:Ignore> |
|---|
| 552 | /*** |
|---|
| 553 | * Sets the parent comment ID when replying to a comment. |
|---|
| 554 | */ |
|---|
| 555 | </mt:Ignore> |
|---|
| 556 | function mtSetCommentParentID() { |
|---|
| 557 | var checkbox = document.getElementById('comment-reply'); |
|---|
| 558 | var parent_id_field = document.getElementById('comment-parent-id'); |
|---|
| 559 | if (!checkbox || !parent_id_field) return; |
|---|
| 560 | |
|---|
| 561 | var pid = 0; |
|---|
| 562 | if (checkbox.checked == true) |
|---|
| 563 | pid = checkbox.value; |
|---|
| 564 | parent_id_field.value = pid; |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | <mt:Ignore> |
|---|
| 568 | /*** |
|---|
| 569 | * Persists a copy of the current user cookie into the browser cookie stash. |
|---|
| 570 | */ |
|---|
| 571 | </mt:Ignore> |
|---|
| 572 | function mtSaveUser(f) { |
|---|
| 573 | // We can't reliably store the user cookie during a preview. |
|---|
| 574 | if (is_preview) return; |
|---|
| 575 | |
|---|
| 576 | var u = mtGetUser(); |
|---|
| 577 | |
|---|
| 578 | if (f && (!u || u.is_anonymous)) { |
|---|
| 579 | if ( !u ) { |
|---|
| 580 | u = {}; |
|---|
| 581 | u.is_authenticated = false; |
|---|
| 582 | u.can_comment = true; |
|---|
| 583 | u.is_author = false; |
|---|
| 584 | u.is_banned = false; |
|---|
| 585 | u.is_anonymous = true; |
|---|
| 586 | u.is_trusted = false; |
|---|
| 587 | } |
|---|
| 588 | if (f.author != undefined) u.name = f.author.value; |
|---|
| 589 | if (f.email != undefined) u.email = f.email.value; |
|---|
| 590 | if (f.url != undefined) u.url = f.url.value; |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | if (!u) return; |
|---|
| 594 | |
|---|
| 595 | var cache_period = mtCookieTimeout * 1000; |
|---|
| 596 | |
|---|
| 597 | // cache anonymous user info for a long period if the |
|---|
| 598 | // user has requested to be remembered |
|---|
| 599 | if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked) |
|---|
| 600 | cache_period = 365 * 24 * 60 * 60 * 1000; |
|---|
| 601 | |
|---|
| 602 | var now = new Date(); |
|---|
| 603 | mtFixDate(now); |
|---|
| 604 | now.setTime(now.getTime() + cache_period); |
|---|
| 605 | |
|---|
| 606 | var cmtcookie = mtBakeUserCookie(u); |
|---|
| 607 | mtSetCookie(mtCookieName, cmtcookie, now, mtCookiePath, mtCookieDomain, |
|---|
| 608 | location.protocol == 'https:'); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | <mt:Ignore> |
|---|
| 612 | /*** |
|---|
| 613 | * Clears the blog-side user cookie. |
|---|
| 614 | */ |
|---|
| 615 | </mt:Ignore> |
|---|
| 616 | function mtClearUser() { |
|---|
| 617 | mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain, |
|---|
| 618 | location.protocol == 'https:'); |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | <mt:Ignore> |
|---|
| 622 | /*** |
|---|
| 623 | * Sets a browser cookie. |
|---|
| 624 | */ |
|---|
| 625 | </mt:Ignore> |
|---|
| 626 | function mtSetCookie(name, value, expires, path, domain, secure) { |
|---|
| 627 | if (domain && domain.match(/^\.?localhost$/)) |
|---|
| 628 | domain = null; |
|---|
| 629 | var curCookie = name + "=" + escape(value) + |
|---|
| 630 | (expires ? "; expires=" + expires.toGMTString() : "") + |
|---|
| 631 | (path ? "; path=" + path : "") + |
|---|
| 632 | (domain ? "; domain=" + domain : "") + |
|---|
| 633 | (secure ? "; secure" : ""); |
|---|
| 634 | document.cookie = curCookie; |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | <mt:Ignore> |
|---|
| 638 | /*** |
|---|
| 639 | * Retrieves a browser cookie. |
|---|
| 640 | */ |
|---|
| 641 | </mt:Ignore> |
|---|
| 642 | function mtGetCookie(name) { |
|---|
| 643 | var prefix = name + '='; |
|---|
| 644 | var c = document.cookie; |
|---|
| 645 | var cookieStartIndex = c.indexOf(prefix); |
|---|
| 646 | if (cookieStartIndex == -1) |
|---|
| 647 | return ''; |
|---|
| 648 | var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); |
|---|
| 649 | if (cookieEndIndex == -1) |
|---|
| 650 | cookieEndIndex = c.length; |
|---|
| 651 | return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | <mt:Ignore> |
|---|
| 655 | /*** |
|---|
| 656 | * Deletes a browser cookie. |
|---|
| 657 | */ |
|---|
| 658 | </mt:Ignore> |
|---|
| 659 | function mtDeleteCookie(name, path, domain, secure) { |
|---|
| 660 | if (mtGetCookie(name)) { |
|---|
| 661 | if (domain && domain.match(/^\.?localhost$/)) |
|---|
| 662 | domain = null; |
|---|
| 663 | document.cookie = name + "=" + |
|---|
| 664 | (path ? "; path=" + path : "") + |
|---|
| 665 | (domain ? "; domain=" + domain : "") + |
|---|
| 666 | (secure ? "; secure" : "") + |
|---|
| 667 | "; expires=Thu, 01-Jan-70 00:00:01 GMT"; |
|---|
| 668 | } |
|---|
| 669 | } |
|---|
| 670 | |
|---|
| 671 | function mtFixDate(date) { |
|---|
| 672 | var skew = (new Date(0)).getTime(); |
|---|
| 673 | if (skew > 0) |
|---|
| 674 | date.setTime(date.getTime() - skew); |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | <mt:Ignore> |
|---|
| 678 | /*** |
|---|
| 679 | * Returns a XMLHttpRequest object (for Ajax operations). |
|---|
| 680 | */ |
|---|
| 681 | </mt:Ignore> |
|---|
| 682 | function mtGetXmlHttp() { |
|---|
| 683 | if ( !window.XMLHttpRequest ) { |
|---|
| 684 | window.XMLHttpRequest = function() { |
|---|
| 685 | var types = [ |
|---|
| 686 | "Microsoft.XMLHTTP", |
|---|
| 687 | "MSXML2.XMLHTTP.5.0", |
|---|
| 688 | "MSXML2.XMLHTTP.4.0", |
|---|
| 689 | "MSXML2.XMLHTTP.3.0", |
|---|
| 690 | "MSXML2.XMLHTTP" |
|---|
| 691 | ]; |
|---|
| 692 | |
|---|
| 693 | for ( var i = 0; i < types.length; i++ ) { |
|---|
| 694 | try { |
|---|
| 695 | return new ActiveXObject( types[ i ] ); |
|---|
| 696 | } catch( e ) {} |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | return undefined; |
|---|
| 700 | }; |
|---|
| 701 | } |
|---|
| 702 | if ( window.XMLHttpRequest ) |
|---|
| 703 | return new XMLHttpRequest(); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | // BEGIN: fast browser onload init |
|---|
| 707 | // Modifications by David Davis, DWD |
|---|
| 708 | // Dean Edwards/Matthias Miller/John Resig |
|---|
| 709 | // http://dean.edwards.name/weblog/2006/06/again/?full#comment5338 |
|---|
| 710 | |
|---|
| 711 | function mtInit() { |
|---|
| 712 | // quit if this function has already been called |
|---|
| 713 | if (arguments.callee.done) return; |
|---|
| 714 | |
|---|
| 715 | // flag this function so we don't do the same thing twice |
|---|
| 716 | arguments.callee.done = true; |
|---|
| 717 | |
|---|
| 718 | // kill the timer |
|---|
| 719 | // DWD - check against window |
|---|
| 720 | if ( window._timer ) clearInterval(window._timer); |
|---|
| 721 | |
|---|
| 722 | // DWD - fire the window onload now, and replace it |
|---|
| 723 | if ( window.onload && ( window.onload !== window.mtInit ) ) { |
|---|
| 724 | window.onload(); |
|---|
| 725 | window.onload = function() {}; |
|---|
| 726 | } |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | /* for Mozilla/Opera9 */ |
|---|
| 730 | if (document.addEventListener) { |
|---|
| 731 | document.addEventListener("DOMContentLoaded", mtInit, false); |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | /* for Internet Explorer */ |
|---|
| 735 | /*@cc_on @*/ |
|---|
| 736 | /*@if (@_win32) |
|---|
| 737 | document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); |
|---|
| 738 | var script = document.getElementById("__ie_onload"); |
|---|
| 739 | script.onreadystatechange = function() { |
|---|
| 740 | if (this.readyState == "complete") { |
|---|
| 741 | mtInit(); // call the onload handler |
|---|
| 742 | } |
|---|
| 743 | }; |
|---|
| 744 | /*@end @*/ |
|---|
| 745 | |
|---|
| 746 | /* for Safari */ |
|---|
| 747 | if (/WebKit/i.test(navigator.userAgent)) { // sniff |
|---|
| 748 | _timer = setInterval(function() { |
|---|
| 749 | if (/loaded|complete/.test(document.readyState)) { |
|---|
| 750 | mtInit(); // call the onload handler |
|---|
| 751 | } |
|---|
| 752 | }, 10); |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | /* for other browsers */ |
|---|
| 756 | window.onload = mtInit; |
|---|
| 757 | |
|---|
| 758 | // END: fast browser onload init |
|---|
| 759 | |
|---|
| 760 | <mt:IfRegistrationAllowed> |
|---|
| 761 | /*** |
|---|
| 762 | * If request contains a '#_login' or '#_logout' hash, use this to |
|---|
| 763 | * also delete the blog-side user cookie, since we're coming back from |
|---|
| 764 | * a login, logout or edit profile operation. |
|---|
| 765 | */ |
|---|
| 766 | var clearCookie = ( window.location.hash && window.location.hash.match( /^#_log(in|out)/ ) ) ? true : false; |
|---|
| 767 | if (clearCookie) { |
|---|
| 768 | // clear any logged in state |
|---|
| 769 | mtClearUser(); |
|---|
| 770 | if (RegExp.$1 == 'in') |
|---|
| 771 | mtFetchUser(); |
|---|
| 772 | } else { |
|---|
| 773 | <mt:Ignore> |
|---|
| 774 | /*** |
|---|
| 775 | * Uncondition this call to fetch the current user state (if available) |
|---|
| 776 | * from MT upon page load if no user cookie is already present. |
|---|
| 777 | * This is okay if you have a private install, such as an Intranet; |
|---|
| 778 | * not recommended for public web sites! |
|---|
| 779 | */ |
|---|
| 780 | </mt:Ignore> |
|---|
| 781 | if ( is_preview ) |
|---|
| 782 | mtFetchUser(); |
|---|
| 783 | } |
|---|
| 784 | </mt:IfRegistrationAllowed> |
|---|