| 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); |
|---|
| 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 | |
|---|
| 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'); |
|---|
| 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 |
|---|
| 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>'; |
|---|
| 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();">">'; |
|---|
| 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, auth |
|---|