1// The cookie name to use for storing the blog-side comment session cookie. 2var mtCookieName = "mt_blog_user"; 3var mtCookieDomain = ".claw.ru"; 4var mtCookiePath = "/"; 5var mtCookieTimeout = 14400; 6 7 8function mtHide(id) { 9 var el = (typeof id == "string") ? document.getElementById(id) : id; 10 if (el) el.style.display = 'none'; 11} 12 13 14function mtShow(id) { 15 var el = (typeof id == "string") ? document.getElementById(id) : id; 16 if (el) el.style.display = 'block'; 17} 18 19 20function mtAttachEvent(eventName,func) { 21 var onEventName = 'on' + eventName; 22 var old = window[onEventName]; 23 if( typeof old != 'function' ) 24 window[onEventName] = func; 25 else { 26 window[onEventName] = function( evt ) { 27 old( evt ); 28 return func( evt ); 29 }; 30 } 31} 32 33 34function mtFireEvent(eventName,param) { 35 var fn = window['on' + eventName]; 36 if (typeof fn == 'function') return fn(param); 37 return; 38} 39 40 41function mtRelativeDate(ts, fds) { 42 var now = new Date(); 43 var ref = ts; 44 var delta = Math.floor((now.getTime() - ref.getTime()) / 1000); 45 46 var str; 47 if (delta < 60) { 48 str = 'ÑовÑем недавно'; 49 } else if (delta <= 86400) { 50 // less than 1 day 51 var hours = Math.floor(delta / 3600); 52 var min = Math.floor((delta % 3600) / 60); 53 if (hours == 1) 54 str = '1 ÑÐ°Ñ Ð½Ð°Ð·Ð°Ð´'; 55 else if (hours > 1) 56 str = '2 ÑаÑа назад'.replace(/2/, hours); 57 else if (min == 1) 58 str = '1 минÑÑÑ Ð½Ð°Ð·Ð°Ð´'; 59 else 60 str = '2 минÑÑÑ Ð½Ð°Ð·Ð°Ð´'.replace(/2/, min); 61 } else if (delta <= 604800) { 62 // less than 1 week 63 var days = Math.floor(delta / 86400); 64 var hours = Math.floor((delta % 86400) / 3600); 65 if (days == 1) 66 str = '1 Ð´ÐµÐ½Ñ Ð½Ð°Ð·Ð°Ð´'; 67 else if (days > 1) 68 str = '2 Ð´Ð½Ñ Ð½Ð°Ð·Ð°Ð´'.replace(/2/, days); 69 else if (hours == 1) 70 str = '1 ÑÐ°Ñ Ð½Ð°Ð·Ð°Ð´'; 71 else 72 str = '2 ÑаÑа назад'.replace(/2/, hours); 73 } 74 return str ? str : fds; 75} 76 77 78function mtEditLink(entry_id, author_id) { 79 var u = mtGetUser(); 80 if (! u) return; 81 if (! entry_id) return; 82 if (! author_id) return; 83 if (u.id != author_id) return; 84 var link = '<a href="mt.cgi?__mode=view&_type=entry&id=' + entry_id + '">РедакÑиÑоваÑÑ</a>'; 85 document.write(link); 86} 87 88 89function mtCommentFormOnFocus() { 90 // if CAPTCHA is enabled, this causes the captcha image to be 91 // displayed if it hasn't been already. 92 mtShowCaptcha(); 93} 94 95 96var mtCaptchaVisible = false; 97function mtShowCaptcha() { 98 var u = mtGetUser(); 99 if ( u && u.is_authenticated ) return; 100 if (mtCaptchaVisible) return; 101 var div = document.getElementById('comments-open-captcha'); 102 if (div) { 103 div.innerHTML = ''; 104 mtCaptchaVisible = true; 105 } 106} 107 108 109 110var is_preview; 111var user; 112 113function mtSetUser(u) { 114 if (u) { 115 // persist this 116 user = u; 117 mtSaveUser(); 118 // sync up user greeting 119 mtFireEvent('usersignin'); 120 } 121} 122 123 124function mtEscapeJS(s) { 125 s = s.replace(/'/g, "'"); 126 return s; 127} 128 129 130function mtUnescapeJS(s) { 131 s = s.replace(/'/g, "'"); 132 return s; 133} 134 135 136function mtBakeUserCookie(u) { 137 var str = ""; 138 if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';"; 139 if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';"; 140 if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';"; 141 if (u.is_authenticated) str += "is_authenticated:'1';"; 142 if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';"; 143 if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';"; 144 if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';"; 145 str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';"; 146 str += "is_author:'" + (u.is_author ? "1" : "0") + "';"; 147 str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';"; 148 str += "can_post:'" + (u.can_post ? "1" : "0") + "';"; 149 str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';"; 150 str = str.replace(/;$/, ''); 151 return str; 152} 153 154 155function mtUnbakeUserCookie(s) { 156 if (!s) return; 157 158 var u = {}; 159 var m; 160 while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { 161 s = s.substring(m[1].length); 162 if (m[2].match(/^(is|can)_/)) // boolean fields 163 u[m[2]] = m[3] == '1' ? true : false;
164 else 165 u[m[2]] = mtUnescapeJS(m[3]); 166 } 167 if (u.is_authenticated) { 168 u.is_anonymous = false; 169 } else { 170 u.is_anonymous = true; 171 u.can_post = false; 172 u.is_author = false; 173 u.is_banned = false; 174 u.is_trusted = false; 175 } 176 return u; 177} 178 179 180function mtGetUser() { 181 if (!user) { 182 var cookie = mtGetCookie(mtCookieName); 183 if (!cookie) return; 184 user = mtUnbakeUserCookie(cookie); 185 if (! user) { 186 user = {}; 187 user.is_anonymous = true; 188 user.can_post = false; 189 user.is_author = false; 190 user.is_banned = false; 191 user.is_trusted = false; 192 } 193 } 194 return user; 195} 196 197 198var mtFetchedUser = false; 199 200function mtFetchUser(cb) { 201 if (!cb) cb = 'mtSetUser'; 202 if ( ( cb == 'mtSetUser' ) && mtGetUser() ) { 203 var url = document.URL; 204 url = url.replace(/#.+$/, ''); 205 url += '#comments-open'; 206 location.href = url; 207 } else { 208 // we aren't using AJAX for this, since we may have to request 209 // from a different domain. JSONP to the rescue. 210 mtFetchedUser = true; 211 var script = document.createElement('script'); 212 var ts = new Date().getTime(); 213 script.src = 'https://claw.ru/cgi-bin/mt/mt-comments.cgi?__mode=session_js&blog_id=9&jsonp=' + cb + '&ts=' + ts; 214 (document.getElementsByTagName('head'))[0].appendChild(script); 215 } 216} 217 218 219 220function mtRememberMeOnClick(b) { 221 if (!b.checked) 222 mtClearUser(b.form); 223 return true; 224} 225 226 227 228var mtRequestSubmitted = false; 229function mtCommentOnSubmit(f) { 230 if (!mtRequestSubmitted) { 231 mtRequestSubmitted = true; 232 233 if (f.armor) 234 f.armor.value = '1e129a688f5ca3c49cc3f89772c45c79c2d9e680'; 235 if (f.bakecookie && f.bakecookie.checked) 236 mtSaveUser(f); 237 238 // disable submit buttons 239 if (f.preview_button) f.preview_button.disabled = true; 240 if (f.post) f.post.disabled = true; 241 242 var u = mtGetUser(); 243 if ( !is_preview && ( u && u.is_authenticated ) ) { 244 // validate session; then submit 245 mtFetchedUser = false; 246 mtFetchUser('mtCommentSessionVerify'); 247 return false; 248 } 249 250 return true; 251 } 252 return false; 253} 254 255function mtCommentSessionVerify(app_user) { 256 var u = mtGetUser(); 257 var f = document['comments_form']; 258 if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) { 259 f.submit(); 260 } else { 261 alert('ÐаÑа ÑеÑÑÐ¸Ñ Ð¸ÑÑекла. ÐожалÑйÑÑа, авÑоÑизÑйÑеÑÑ ÐµÑÑ Ñаз.'); 262 mtClearUser(); 263 mtFireEvent('usersignin'); 264 265 } 266} 267 268function mtUserOnLoad() { 269 var u = mtGetUser(); 270 271 // if the user is authenticated, hide the 'anonymous' fields 272 // and any captcha input if already shown 273 if ( document.getElementById('comments-form')) { 274 if ( u && u.is_authenticated ) { 275 mtShow('comments-form'); 276 mtHide('comments-open-data'); 277 if (mtCaptchaVisible) 278 mtHide('comments-open-captcha'); 279 } else { 280 281 } 282 if ( u && u.is_banned ) 283 mtHide('comments-form'); 284 285 // if we're previewing a comment, make sure the captcha 286 // field is visible 287 if (is_preview) 288 mtShowCaptcha(); 289 else 290 mtShowGreeting(); 291 292 // populate anonymous comment fields if user is cookied as anonymous 293 var cf = document['comments_form']; 294 if (cf) { 295 if (u && u.is_anonymous) { 296 if (u.email) cf.email.value = u.email; 297 if (u.name) cf.author.value = u.name; 298 if (u.url) cf.url.value = u.url; 299 if (cf.bakecookie) 300 cf.bakecookie.checked = u.name || u.email; 301 } else { 302 if (u && u.sid && cf.sid) 303 cf.sid.value = u.sid; 304 } 305 if (cf.post.disabled) 306 cf.post.disabled = false; 307 if (cf.preview_button.disabled) 308 cf.preview_button.disabled = false;
309 mtRequestSubmitted = false; 310 } 311 } 312} 313 314 315 316 317function mtEntryOnLoad() { 318 mtHide('trackbacks-info'); 319 mtHide('comments-open'); 320 mtFireEvent('usersignin'); 321} 322 323function mtEntryOnUnload() { 324 if (mtRequestSubmitted) { 325 var cf = document['comments_form']; 326 if (cf) { 327 if (cf.post && cf.post.disabled) 328 cf.post.disabled = false; 329 if (cf.preview_button && cf.preview_button.disabled) 330 cf.preview_button.disabled = false; 331 } 332 mtRequestSubmitted = false; 333 } 334 return true; 335} 336 337mtAttachEvent('usersignin', mtUserOnLoad); 338 339 340 341function mtSignIn() { 342 var doc_url = document.URL; 343 doc_url = doc_url.replace(/#.+/, ''); 344 var url = 'https://claw.ru/cgi-bin/mt/mt-cp.cgi?__mode=login&blog_id=9'; 345 if (is_preview) { 346 if ( document['comments_form'] ) { 347 var entry_id = document['comments_form'].entry_id.value; 348 url += '&entry_id=' + entry_id; 349 } else { 350 url += '&return_url=https%3A%2F%2Fclaw.ru%2F'; 351 } 352 } else { 353 url += '&return_url=' + encodeURIComponent(doc_url); 354 } 355 mtClearUser(); 356 location.href = url; 357} 358 359function mtSignInOnClick(sign_in_element) { 360 var el; 361 if (sign_in_element) { 362 // display throbber 363 el = document.getElementById(sign_in_element); 364 if (!el) // legacy MT 4.x element id 365 el = document.getElementById('comment-form-external-auth'); 366 } 367 if (el) 368 el.innerHTML = 'ÐвÑоÑизаÑиÑ⦠<span class="status-indicator"> </span>'; 369 370 mtClearUser(); // clear any 'anonymous' user cookie to allow sign in 371 mtFetchUser('mtSetUserOrLogin'); 372 return false; 373} 374 375function mtSetUserOrLogin(u) { 376 if (u && u.is_authenticated) { 377 mtSetUser(u); 378 } else { 379 // user really isn't logged in; so let's do this! 380 mtSignIn(); 381 } 382} 383 384 385function mtSignOut(entry_id) { 386 mtClearUser(); 387 var doc_url = document.URL; 388 doc_url = doc_url.replace(/#.+/, ''); 389 var url = 'https://claw.ru/cgi-bin/mt/mt-cp.cgi?__mode=logout&static=0'; 390 if (is_preview) { 391 if ( document['comments_form'] ) { 392 var entry_id = document['comments_form'].entry_id.value; 393 url += '&entry_id=' + entry_id; 394 } else { 395 url += '&return_url=https%3A%2F%2Fclaw.ru%2F'; 396 } 397 } else { 398 url += '&return_url=' + encodeURIComponent(doc_url); 399 } 400 location.href = url; 401} 402 403 404function mtSignOutOnClick() { 405 mtSignOut(); 406 return false; 407} 408 409 410 411function mtShowGreeting() { 412 413 mtShowCaptcha(); 414 415} 416 417 418 419function mtReplyCommentOnClick(parent_id, author) { 420 mtShow('comment-form-reply'); 421 422 var checkbox = document.getElementById('comment-reply'); 423 var label = document.getElementById('comment-reply-label'); 424 var text = document.getElementById('comment-text'); 425 426 // Populate label with new values 427 var reply_text = 'ÐÑÐ²ÐµÑ Ð½Ð° комменÑаÑий Ð¾Ñ \<a href=\"#comment-__PARENT__\" onclick=\"location.href=this.href; return false\"\>__AUTHOR__\<\/a\>'; 428 reply_text = reply_text.replace(/__PARENT__/, parent_id); 429 reply_text = reply_text.replace(/__AUTHOR__/, author); 430 label.innerHTML = reply_text; 431 432 checkbox.value = parent_id; 433 checkbox.checked = true; 434 try { 435 // text field may be hidden 436 text.focus(); 437 } catch(e) { 438 } 439 440 mtSetCommentParentID(); 441} 442 443 444function mtSetCommentParentID() { 445 var checkbox = document.getElementById('comment-reply'); 446 var parent_id_field = document.getElementById('comment-parent-id'); 447 if (!checkbox || !parent_id_field) return; 448 449 var pid = 0; 450 if (checkbox.checked == true) 451 pid = checkbox.value; 452 parent_id_field.value = pid; 453} 454 455 456function mtSaveUser(f) { 457 // We can't reliably store the user cookie during a preview. 458 if (is_preview) return; 459 460 var u = mtGetUser(); 461 462 if (f && (!u || u.is_anonymous)) { 463 if ( !u ) { 464 u = {}; 465 u.is_authenticated = false; 466 u.can_comment = true; 467 u.is_author = false; 468 u.is_banned = false;
469 u.is_anonymous = true; 470 u.is_trusted = false; 471 } 472 if (f.author != undefined) u.name = f.author.value; 473 if (f.email != undefined) u.email = f.email.value; 474 if (f.url != undefined) u.url = f.url.value; 475 } 476 477 if (!u) return; 478 479 var cache_period = mtCookieTimeout * 1000; 480 481 // cache anonymous user info for a long period if the 482 // user has requested to be remembered 483 if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked) 484 cache_period = 365 * 24 * 60 * 60 * 1000; 485 486 var now = new Date(); 487 mtFixDate(now); 488 now.setTime(now.getTime() + cache_period); 489 490 var cmtcookie = mtBakeUserCookie(u); 491 mtSetCookie(mtCookieName, cmtcookie, now, mtCookiePath, mtCookieDomain, 492 location.protocol == 'https:'); 493} 494 495 496function mtClearUser() { 497 user = null; 498 mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain, 499 location.protocol == 'https:'); 500} 501 502 503function mtSetCookie(name, value, expires, path, domain, secure) { 504 if (domain && domain.match(/^\.?localhost$/)) 505 domain = null; 506 var curCookie = name + "=" + escape(value) + 507 (expires ? "; expires=" + expires.toGMTString() : "") + 508 (path ? "; path=" + path : "") + 509 (domain ? "; domain=" + domain : "") + 510 (secure ? "; secure" : ""); 511 document.cookie = curCookie; 512} 513 514 515function mtGetCookie(name) { 516 var prefix = name + '='; 517 var c = document.cookie; 518 var cookieStartIndex = c.indexOf(prefix); 519 if (cookieStartIndex == -1) 520 return ''; 521 var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); 522 if (cookieEndIndex == -1) 523 cookieEndIndex = c.length; 524 return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); 525} 526 527 528function mtDeleteCookie(name, path, domain, secure) { 529 if (mtGetCookie(name)) { 530 if (domain && domain.match(/^\.?localhost$/)) 531 domain = null; 532 document.cookie = name + "=" + 533 (path ? "; path=" + path : "") + 534 (domain ? "; domain=" + domain : "") + 535 (secure ? "; secure" : "") + 536 "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 537 } 538} 539 540function mtFixDate(date) { 541 var skew = (new Date(0)).getTime(); 542 if (skew > 0) 543 date.setTime(date.getTime() - skew); 544} 545 546 547function mtGetXmlHttp() { 548 if ( !window.XMLHttpRequest ) { 549 window.XMLHttpRequest = function() { 550 var types = [ 551 "Microsoft.XMLHTTP", 552 "MSXML2.XMLHTTP.5.0", 553 "MSXML2.XMLHTTP.4.0", 554 "MSXML2.XMLHTTP.3.0", 555 "MSXML2.XMLHTTP" 556 ]; 557 558 for ( var i = 0; i < types.length; i++ ) { 559 try { 560 return new ActiveXObject( types[ i ] ); 561 } catch( e ) {} 562 } 563 564 return undefined; 565 }; 566 } 567 if ( window.XMLHttpRequest ) 568 return new XMLHttpRequest(); 569} 570 571// BEGIN: fast browser onload init 572// Modifications by David Davis, DWD 573// Dean Edwards/Matthias Miller/John Resig 574// https://dean.edwards.name/weblog/2006/06/again/?full#comment5338 575 576function mtInit() { 577 // quit if this function has already been called 578 if (arguments.callee.done) return; 579 580 // flag this function so we don't do the same thing twice 581 arguments.callee.done = true; 582 583 // kill the timer 584 // DWD - check against window 585 if ( window._timer ) clearInterval(window._timer); 586 587 // DWD - fire the window onload now, and replace it 588 if ( window.onload && ( window.onload !== window.mtInit ) ) { 589 window.onload(); 590 window.onload = function() {}; 591 } 592} 593 594/* for Mozilla/Opera9 */ 595if (document.addEventListener) { 596 document.addEventListener("DOMContentLoaded", mtInit, false); 597} 598 599/* for Internet Explorer */ 600/*@cc_on @*/ 601/*@if (@_win32) 602document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); 603var script = document.getElementById("__ie_onload"); 604script.onreadystatechange = function() { 605 if (this.readyState == "complete") { 606 mtInit(); // call the onload handler 607 } 608}; 609/*@end @*/ 610 611/* for Safari */ 612if (/WebKit/i.test(navigator.userAgent)) { // sniff 613 _timer = setInterval(function() { 614 if (/loaded|complete/.test(document.readyState)) { 615 mtInit(); // call the onload handler 616 } 617 }, 10); 618} 619 620/* for other browsers */ 621window.onload = mtInit; 622 623// END: fast browser onload init 624 625 626 627 628 629
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.