Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.extend(RegExp, {
- escape: function(text) {
- if (!arguments.callee.sRE) {
- var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^'];
- arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
- }
- return text.replace(arguments.callee.sRE, '\\$1');
- }
- });
- Object.extend(String, {
- reverse: function(text) {
- return text.split('').reverse().join('');
- }
- });
- var _chat = window.IPBoard;
- _chat.prototype.chat = {
- polling: 3,
- lastpolled: 0,
- lastMsgId: 0,
- lastTime: '',
- condenseTime: 0,
- maxMessages: 0,
- moderator: 0,
- private: 0,
- kicked: false,
- chattingUpdate: 60,
- bypassFlag: false,
- templates: [],
- emoticons: {},
- soundEnabled: 0,
- soundReady: false,
- soundOnImg: '',
- soundOffImg: '',
- nameFormatting: $H(),
- groups: $H(),
- windowHasFocus: true,
- activeTab: 'chatroom',
- forumIdMap: $H(),
- ignoreChats: $H(),
- privateChats: $H(),
- typedChats: $H(),
- unreadTabs: $H(),
- unreadCount: 0,
- badwords: $H(),
- noBuffer: 0,
- hideEnterExit: 0,
- inactiveKick: 0,
- lastAction: 0,
- lastUser: $H(),
- init: function() {
- Debug.write("Initializing ips.chat.js");
- document.observe("dom:loaded", function() {
- if (!ipb.vars['board_url'] && ipb.vars['base_url']) {
- ipb.vars['board_url'] = ipb.vars['base_url'].replace(/index\.php\?.*?$/, "");
- Debug.write("Set board_url to " + ipb.vars['board_url']);
- }
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- ipb.chat.drawIframes();
- Event.observe(window, 'message', function(e) {
- ipb.chat.handleMessageFromChild(e.data);
- });
- new PeriodicalExecuter(ipb.chat.getMessages, ipb.chat.polling);
- $('chat-submit').observe('click', ipb.chat.sendChat);
- Event.observe('message_textarea', 'keypress', ipb.chat.checkForSendChat);
- ipb.chat.ping();
- new PeriodicalExecuter(ipb.chat.ping, ipb.chat.chattingUpdate);
- if ($('sound_toggle')) {
- $('sound_toggle').observe('click', function(e) {
- if (ipb.chat.soundEnabled) {
- ipb.chat.soundEnabled = 0;
- ipb.Cookie.set('chat_sounds', 'off');
- Debug.write("Chat sounds disabled");
- $('sound_toggle_img').writeAttribute('src', ipb.chat.soundOffImg);
- } else {
- ipb.chat.soundEnabled = 1;
- ipb.Cookie.set('chat_sounds', 'on');
- Debug.write("Chat sounds enabled");
- $('sound_toggle_img').writeAttribute('src', ipb.chat.soundOnImg);
- }
- Event.stop(e);
- return false;
- });
- }
- $('leave_room').observe('click', function(e) {
- ipb.chat.templates['msg-K'] = new Template("");
- });
- ipb.chat.initKickLinks();
- soundManager.onready(function(oStatus) {
- if (oStatus.success) {
- ipb.chat.soundReady = true;
- if (isRTL) {
- $('sm2-container').setStyle({
- left: '0px',
- right: '-9999px'
- });
- }
- }
- });
- if (Prototype.Browser.IE) {
- document.onfocusin = function() {
- ipb.chat.cleanTitle();
- ipb.chat.windowHasFocus = true;
- };
- document.onfocusout = function() {
- ipb.chat.unreadCount = 0;
- ipb.chat.windowHasFocus = false;
- };
- } else {
- Event.observe(window, 'focus', function() {
- Debug.write('has focus');
- ipb.chat.cleanTitle();
- ipb.chat.windowHasFocus = true;
- });
- Event.observe(window, 'blur', function() {
- ipb.chat.unreadCount = 0;
- ipb.chat.windowHasFocus = false;
- });
- }
- $$('#chat-tab-holder a').each(function(elem) {
- id = elem.identify();
- if ($(id)) {
- $(id).observe("click", ipb.chat.switchTab);
- }
- });
- $$('.chatmodmenu').each(function(menu) {
- id = menu.identify();
- if ($(id + "_menucontent")) {
- new ipb.Menu(menu, $(id + "_menucontent"), {}, {
- afterOpen: ipb.chat.repositionModMenu
- });
- }
- });
- if ($('chat_new_window')) {
- $('chat_new_window').observe('click', ipb.chat.openInNewWindow);
- }
- if ($('emoticons_custom_menu_menucontent')) {
- $('emoticons_custom_menu_menucontent').on('click', 'a, img', ipb.chat.emoticonClick);
- }
- if (isMobile) {
- if ((navigator.userAgent.match(/iPhone OS 2/i)) || (navigator.userAgent.match(/iPhone OS 3/i)) || (navigator.userAgent.match(/iPhone OS 4/i))) {
- Event.observe(window, 'scroll', function() {
- $('chat-form').setStyle({
- top: (window.pageYOffset + window.innerHeight - 34) + 'px'
- });
- });
- }
- }
- });
- },
- emoticonClick: function(e) {
- $('emoticons_custom_menu_menucontent').hide();
- return true;
- },
- openInNewWindow: function(e) {
- var _url = document.location.toString();
- if (_url.charAt(_url.length - 1) == '#') {
- _url = _url.substr(0, _url.length - 1);
- }
- if (_url.indexOf('?') != '-1') {
- _url += '&_popup=1';
- } else {
- _url += '?_popup=1';
- }
- window.open(_url, "chatpopout", "status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,height=550,width=750");
- Event.stop(e);
- window.location = ipb.vars['board_url'];
- return false;
- },
- switchTab: function(e) {
- Event.stop(e);
- elem = Event.findElement(e);
- id = elem.identify();
- if (id.match(/close\-chat\-tab\-(.+?)/g)) {
- ipb.chat.closePrivateTab(id);
- return false;
- }
- rel = $(id).rel;
- if (rel == ipb.chat.activeTab) {
- Debug.write("Clicked on active tab");
- return false;
- }
- ipb.chat.switchToTab(rel);
- return false;
- },
- switchToTab: function(rel) {
- if ($('storage_' + rel)) {
- if ($F('message_textarea').strip()) {
- ipb.chat.typedChats.set(ipb.chat.activeTab, $F('message_textarea'));
- $('message_textarea').clear();
- }
- $('storage_container_' + ipb.chat.activeTab).update($('messages-display').innerHTML);
- $('messages-display').update($('storage_container_' + rel).innerHTML).addClassName('messages-list');
- $('storage_container_' + rel).update();
- $('tab-' + ipb.chat.activeTab).removeClassName('active');
- $('tab-' + rel).addClassName('active');
- ipb.chat.activeTab = rel;
- ipb.chat.updateTabUnreadCount();
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- if (ipb.chat.typedChats.get(ipb.chat.activeTab)) {
- $('message_textarea').value = ipb.chat.typedChats.get(ipb.chat.activeTab);
- ipb.chat.typedChats.unset(ipb.chat.activeTab);
- }
- if (!isMobile) {
- $('message_textarea').focus();
- }
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- }
- },
- buildTab: function(id) {
- if (!ipb.chat.nameFormatting.get(id)) {
- return false;
- }
- if ($("tab-" + id)) {
- if (!$("storage_" + id)) {
- var newOuter = new Element('div', {
- id: "storage_container_" + id
- }).addClassName('storage-container');
- var newStorage = new Element('ul', {
- id: "storage_" + id
- });
- $('iframeContainer').insert(newOuter.insert(newStorage));
- ipb.chat.typedChats.unset(id);
- }
- return true;
- }
- var name = ipb.chat.nameFormatting.get(id)[2].stripTags();
- var _existed = false;
- $('chat-tab-holder').childElements().each(function(elem) {
- var _thisId = $(elem).readAttribute('id').replace(/tab-/, '');
- var _name = $(elem).innerHTML.stripTags().strip().replace(/ /g, '');
- if (name == _name) {
- $(elem).writeAttribute('id', 'tab-' + id);
- $("storage_container_" + _thisId).writeAttribute('id', "storage_container_" + id);
- $("storage_" + _thisId).writeAttribute('id', "storage_" + id);
- if (ipb.chat.activeTab == _thisId) {
- ipb.chat.activeTab = id;
- }
- _existed = true;
- }
- });
- if (!_existed) {
- var newTab = new Element('li', {
- id: "tab-" + id
- });
- newTab.update(ipb.chat.templates['new-tab'].evaluate({
- id: id,
- name: name
- }));
- $('chat-tab-holder').insert({
- bottom: newTab
- });
- $('chat-room-list').style.display = '';
- }
- $$('#chat-tab-holder a').each(function(elem) {
- elem.stopObserving();
- _id = elem.identify();
- if ($(_id)) {
- $(_id).observe("click", ipb.chat.switchTab);
- }
- });
- if (!$("storage_" + id)) {
- var newOuter = new Element('div', {
- id: "storage_container_" + id
- }).addClassName('storage-container');
- var newStorage = new Element('ul', {
- id: "storage_" + id
- });
- $('iframeContainer').insert(newOuter.insert(newStorage));
- }
- return true;
- },
- closePrivateTab: function(id) {
- _rel = id.replace(/close-chat-tab-/, '');
- if (!_rel) {
- return false;
- }
- if (_rel == ipb.chat.activeTab) {
- ipb.chat.switchToTab('chatroom');
- }
- if ($("storage_container_" + _rel)) {
- $("storage_container_" + _rel).remove();
- }
- $("tab-" + _rel).remove();
- ipb.chat.typedChats.unset(_rel);
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- sendPrivateChat: function(id) {
- var message = $F("priv_chat_text_" + id).strip();
- if (message == '') {
- return false;
- }
- ipb.chat.privateChats.get('privchatwindow_' + id).hide();
- $("priv_chat_text_" + id).clear();
- if ($('storage_' + id)) {
- ipb.chat.switchToTab(id);
- $('storage_container_' + ipb.chat.activeTab).update($('messages-display').innerHTML);
- $('messages-display').update($('storage_container_' + id).innerHTML).addClassName('messages-list');
- $('storage_container_' + id).update();
- $('tab-' + ipb.chat.activeTab).removeClassName('active');
- $('tab-' + id).addClassName('active');
- ipb.chat.activeTab = id;
- } else {
- $('storage_container_' + ipb.chat.activeTab).update($('messages-display').innerHTML);
- ipb.chat.buildTab(id);
- ipb.chat.switchToTab(id);
- }
- message = ipb.chat.cleanMessage(message);
- if (ipb.chat.sendMessageToChild("server=" + serverHost + "&path=" + serverPath + "&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&lmsg=" + ipb.chat.lastMsgId + "&action=private&message=" + message + '&toUser=' + id + '&charset=' + ipb.vars['charset'])) {
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- message = message.escapeHTML();
- ipb.chat.bypassFlag = true;
- ipb.chat.updateMessages("1,0~~||~~" + Math.round(new Date().getTime() / 1000) + ",1," + userName.replace(',', '~~#~~') + "," + message + ",private=" + id + "," + userId + "~~||~~");
- ipb.chat.bypassFlag = false;
- }
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- Debug.write("Sending private chat to " + name);
- return false;
- },
- drawIframes: function() {
- if (window.postMessage) {
- var iframe = new Element('iframe', {
- 'id': 'chatProxy'
- });
- iframe.writeAttribute('src', 'http://' + serverHost + serverPath + 'web/postMessage.php?parent=' + ourUrl);
- iframe.setStyle('position', 'absolute');
- iframe.setStyle('left', '-150px');
- iframe.setStyle('top', '0px');
- iframe.setStyle('display', 'none');
- $('iframeContainer').insert(iframe);
- } else {
- var iframe = new Element('iframe', {
- 'id': 'chatProxy'
- });
- iframe.writeAttribute('src', 'http://' + serverHost + serverPath + 'web/iframeProxy.php?parent=' + ourUrl);
- iframe.setStyle('position', 'absolute');
- iframe.setStyle('left', '-150px');
- iframe.setStyle('top', '0px');
- iframe.setStyle('display', 'none');
- $('iframeContainer').insert(iframe);
- }
- },
- cleanTitle: function() {
- if (document.title.match(/\(\d+\) (.+?)/gi)) {
- setTimeout(function() {
- document.title = document.title.replace(/\(\d+\) (.+?)/gi, "$1")
- }, 200);
- }
- ipb.chat.unreadCount = 0;
- },
- triggerMessageSound: function() {
- if (ipb.chat.soundEnabled && ipb.chat.soundReady && !ipb.chat.bypassFlag) {
- soundManager.play('message', ipb.vars['board_url'] + '/public/sounds/message.mp3');
- }
- },
- triggerEnterSound: function() {
- if (ipb.chat.soundEnabled && ipb.chat.soundReady) {
- soundManager.play('enter', ipb.vars['board_url'] + '/public/sounds/enter.mp3');
- }
- },
- triggerLeaveSound: function() {
- if (ipb.chat.soundEnabled && ipb.chat.soundReady) {
- soundManager.play('leave', ipb.vars['board_url'] + '/public/sounds/leave.mp3');
- }
- },
- checkForSendPrivateChat: function(e) {
- if (e.keyCode == Event.KEY_RETURN) {
- Event.stop(e);
- elem = Event.findElement(e);
- id = elem.identify();
- _id = id.replace(/priv_chat_text_/, '');
- ipb.chat.sendPrivateChat(_id);
- return false;
- }
- return true;
- },
- checkForSendChat: function(e) {
- if (e.keyCode == Event.KEY_RETURN) {
- ipb.chat.sendChat(e);
- }
- },
- sendChat: function(e) {
- Event.stop(e);
- var chatPost = $F('message_textarea').strip();
- if (chatPost == '') {
- return false;
- }
- chatPost = ipb.chat.cleanMessage(chatPost);
- if (ipb.chat.activeTab != 'chatroom') {
- var _thisMessage = "&action=private&toUser=" + ipb.chat.activeTab;
- var _thisExtra = "private=" + ipb.chat.activeTab;
- } else {
- var _thisMessage = "&action=post";
- var _thisExtra = '0';
- }
- if (ipb.chat.sendMessageToChild("server=" + serverHost + "&path=" + serverPath + "&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&lmsg=" + ipb.chat.lastMsgId + _thisMessage + "&message=" + chatPost + '&charset=' + ipb.vars['charset'])) {
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- chatPost = chatPost.escapeHTML();
- ipb.chat.bypassFlag = true;
- ipb.chat.updateMessages("1,0~~||~~" + Math.round(new Date().getTime() / 1000) + ",1," + userName.replace(',', '~~#~~') + "," + chatPost + "," + _thisExtra + "," + userId + "~~||~~");
- ipb.chat.bypassFlag = false;
- }
- $('message_textarea').clear();
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- sendMessageToChild: function(message) {
- if (ipb.chat.kicked) {
- return false;
- }
- var elem = $('chatProxy').contentWindow;
- if (window.postMessage) {
- Debug.write("Using window.postMessage method");
- elem.postMessage(message, 'http://' + serverHost);
- } else {
- Debug.write("Using iframe hash method");
- elem.location = 'http://' + serverHost + serverPath + '/web/iframeProxy.php?parent=' + ourUrl + '#' + message + '×tamp=' + Math.round(new Date().getTime() / 1000);
- }
- return true;
- },
- handleMessageFromChild: function(message) {
- if (ipb.chat.kicked) {
- return false;
- }
- if (message.substr(0, 7) == 'height=') {
- return false;
- }
- if (message.length > 0) {
- if (message.substr(0, 8) == '__post__' || message.substr(0, 12) == '__moderate__') {
- ipb.chat.getMessages();
- } else {
- ipb.chat.updateMessages(message);
- }
- }
- },
- getMessages: function(pe) {
- curtime = parseInt(new Date().getTime().toString().substring(0, 10));
- ipb.chat.checkInactivity(curtime);
- if (ipb.chat.kicked) {
- pe.stop();
- return false;
- }
- if (curtime - ipb.chat.lastpolled < ipb.chat.polling) {
- return false;
- }
- ipb.chat.lastpolled = curtime;
- ipb.chat.sendMessageToChild("server=" + serverHost + "&path=" + serverPath + "&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&msg=" + ipb.chat.lastMsgId + "&charset=" + ipb.vars['charset']);
- },
- updateMessages: function(text) {
- if (!text) {
- return true;
- }
- if (text.substr(0, 2) != '0,' && text.substr(0, 2) != '1,') {
- return true;
- }
- var messages = text.split("~~||~~");
- var scrollBottom = false;
- try {
- var _borderTop = getComputedStyle($('messages-display'), '').getPropertyValue('border-top-width').replace('px', '');
- var _borderBottom = getComputedStyle($('messages-display'), '').getPropertyValue('border-bottom-width').replace('px', '');
- var _padTop = getComputedStyle($('messages-display'), '').getPropertyValue('padding-top').replace('px', '');
- var _padBottom = getComputedStyle($('messages-display'), '').getPropertyValue('padding-bottom').replace('px', '');
- } catch (e) {
- var _borderTop = $('messages-display').currentStyle.borderWidth.replace('px', '');
- var _borderBottom = $('messages-display').currentStyle.borderWidth.replace('px', '');
- var _padTop = $('messages-display').currentStyle.paddingTop.replace('px', '');
- var _padBottom = $('messages-display').currentStyle.paddingBottom.replace('px', '');
- }
- if (isNaN(_borderBottom) || isNaN(_borderTop)) {
- _borderBottom = convertToPixels(_borderBottom, '');
- _borderTop = convertToPixels(_borderTop, '');
- }
- var _totalOffset = parseInt(_borderTop) + parseInt(_borderBottom) + parseInt(_padTop) + parseInt(_padBottom);
- if (($('messages-display').getHeight() - _totalOffset + $('messages-display').scrollTop) >= ($('messages-display').scrollHeight - 10)) {
- scrollBottom = true;
- }
- var _updatedCount = 0;
- var _showOwn = false;
- var _initialEmpty = false;
- var _startLMI = ipb.chat.lastMsgId;
- for (var i = 0; i < messages.length; i++) {
- messages[i] = messages[i].replace(/%20/gi, ' ');
- messages[i] = messages[i].replace(/%23/gi, '#');
- messages[i] = messages[i].replace(/%22/gi, '"');
- messages[i] = messages[i].replace(/%3C/gi, '<');
- messages[i] = messages[i].replace(/%3E/gi, '>');
- messages[i] = messages[i].replace(/\</gi, '<');
- messages[i] = messages[i].replace(/\>/gi, '>');
- messages[i] = ipb.chat.manualDecode(messages[i]);
- var msgDetails = messages[i].split(',');
- if (i == 0) {
- if (msgDetails[0] != 1) {
- $$('.storage-container').each(function(elem) {
- var _id = $(elem).id.replace(/storage_container_/, '');
- var ulList = ipb.chat.getStorageContainer(_id);
- ulList.insert({
- bottom: ipb.chat.templates['msg-K'].evaluate()
- });
- if (_id != ipb.chat.activeTab) {
- $("storage_container_" + _id).update(ulList);
- } else {
- $('messages-display').update(ulList).addClassName('messages-list');
- }
- });
- if (!ipb.vars['member_id']) {}
- ipb.chat.kicked = true;
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- return true;
- } else {
- if (!ipb.chat.bypassFlag && msgDetails[1] == ipb.chat.lastMsgId) {
- if (ipb.chat.lastMsgId == 0) {
- ipb.chat.bypassFlag = true;
- ipb.chat.lastMsgId = 1;
- _initialEmpty = true;
- msgDetails[1] = 2;
- msgDetails[2] = userName;
- msgDetails[3] = '';
- msgDetails[4] = '1_' + userId;
- msgDetails[5] = userId;
- } else {
- return true;
- }
- }
- if (!ipb.chat.bypassFlag) {
- if (ipb.chat.lastMsgId == 0) {
- _showOwn = true;
- }
- ipb.chat.lastMsgId = msgDetails[1];
- }
- if (!_initialEmpty) {
- continue;
- }
- }
- }
- if (!_startLMI && ipb.chat.noBuffer) {
- continue;
- }
- if (msgDetails[1]) {
- if (!ipb.chat.bypassFlag && msgDetails[5] == userId && (msgDetails[1] == 1 || msgDetails[1] == 3) && !_showOwn) {
- continue;
- }
- var _thisRowId = 'chatroom';
- if (msgDetails[1] == 1) {
- if (msgDetails[4]) {
- var userDetails = msgDetails[4].split('=');
- if (userDetails[1]) {
- var _user = msgDetails[5] == userId ? userDetails[1] : msgDetails[5];
- if (!$('storage_' + _user)) {
- var _forumUser = ipb.chat.forumIdMap.get(_user);
- if (!_forumUser) {
- continue;
- }
- var _blocked = 0;
- if (_forumUser[0]) {
- _blocked = ipb.chat.ignoreChats.get(_forumUser[0]);
- } else {
- _blocked = ipb.chat.ignoreChats.get('g_' + _user);
- }
- if (_blocked) {
- continue;
- }
- if (!ipb.chat.buildTab(_user)) {
- continue;
- }
- ipb.chat.switchToTab(_user);
- }
- _thisRowId = _user;
- }
- }
- }
- var ulList = ipb.chat.getStorageContainer(_thisRowId);
- var alsoTo = null;
- var _itemDate = new Date();
- var _secs = parseInt(msgDetails[0]) ? parseInt(msgDetails[0]) : parseInt(new Date().getTime());
- _itemDate.setTime(_secs * 1000);
- var _hours = _itemDate.getHours();
- var _mins = _itemDate.getMinutes() + "";
- if (_mins.length == 1) {
- _mins = "0" + _mins;
- }
- if (ipb.chat.condenseTime) {
- var _minsLastChar = _mins.charAt(_mins.length - 1);
- if (_minsLastChar == 1 || _minsLastChar == 2 || _minsLastChar == 3 || _minsLastChar == 4) {
- _mins = _mins.charAt(0) + "" + 0;
- } else if (_minsLastChar == 6 || _minsLastChar == 7 || _minsLastChar == 8 || _minsLastChar == 9) {
- _mins = _mins.charAt(0) + "" + 5;
- }
- }
- if (ipb.chat.user24hour) {
- _itemDate = _hours + ':' + _mins;
- } else {
- if (_hours > 12) {
- _itemDate = (_hours - 12) + ':' + _mins + ' ' + ipb.lang['time_pm'];
- } else if (_hours == 0) {
- _itemDate = 12 + ':' + _mins + ' ' + ipb.lang['time_am'];
- } else if (_hours == 12) {
- _itemDate = _hours + ':' + _mins + ' ' + ipb.lang['time_pm'];
- } else {
- _itemDate = _hours + ':' + _mins + ' ' + ipb.lang['time_am'];
- }
- }
- if (_itemDate != ipb.chat.lastTime && !ipb.chat.bypassFlag) {
- var dateItem = new Element('li');
- dateItem.update("<div>" + _itemDate + "</div>").addClassName('chat-time');
- ulList.insert({
- bottom: dateItem
- });
- ipb.chat.lastUser.set(_thisRowId, 0);
- }
- var listItemVal = '';
- msgDetails[2] = msgDetails[2].replace('~~#~~', ",");
- msgDetails[2] = ipb.chat.unCleanMessage(msgDetails[2]);
- msgDetails[4] = msgDetails[4].replace('~~#~~', ",");
- msgDetails[3] = msgDetails[3].replace('~~#~~', ",");
- msgDetails[3] = ipb.chat.unCleanMessage(msgDetails[3]);
- msgDetails[3] = ipb.chat.parseEmoticonsAndBbcode(msgDetails[3], msgDetails[5]);
- if (msgDetails[1] == 1) {
- if (msgDetails[3].match(/^\/me /gi)) {
- msgDetails[1] = 3;
- msgDetails[3] = msgDetails[3].replace(/^\/me /gi, '');
- }
- }
- if (msgDetails[1] == 1) {
- msgDetails[2] = ipb.chat.formatName(msgDetails[5], msgDetails[2]);
- var _ownClass = '';
- if (msgDetails[5] == userId) {
- _ownClass = 'chat-myown';
- }
- if (msgDetails[5] == ipb.chat.lastUser.get(_thisRowId)) {
- listItemVal = ipb.chat.templates['msg-1-compound'].evaluate({
- date: _itemDate,
- username: msgDetails[2],
- photo: ipb.chat.nameFormatting.get(msgDetails[5]) ? ipb.chat.nameFormatting.get(msgDetails[5])[3] : '',
- message: msgDetails[3],
- ownclass: _ownClass
- });
- } else {
- listItemVal = ipb.chat.templates['msg-1'].evaluate({
- date: _itemDate,
- username: msgDetails[2],
- photo: ipb.chat.nameFormatting.get(msgDetails[5]) ? ipb.chat.nameFormatting.get(msgDetails[5])[3] : '',
- message: msgDetails[3],
- ownclass: _ownClass
- });
- }
- _updatedCount++;
- ipb.chat.unreadCount++;
- if (_thisRowId != ipb.chat.activeTab) {
- if (ipb.chat.unreadTabs.get(_thisRowId)) {
- ipb.chat.unreadTabs.set(_thisRowId, ipb.chat.unreadTabs.get(_thisRowId) + 1);
- } else {
- ipb.chat.unreadTabs.set(_thisRowId, 1);
- }
- }
- ipb.chat.lastUser.set(_thisRowId, msgDetails[5]);
- } else if (msgDetails[1] == 2) {
- var details = msgDetails[4].split('_');
- if (details[0] == 1) {
- var _action = ipb.lang['entered_room'];
- if (_startLMI > 0) {
- ipb.chat.addUserToList(details[1], msgDetails[2], details[2]);
- }
- var _details = ipb.chat.groups.get(details[3]);
- if (_details) {
- msgDetails[2] = _details[0].replace(/__DBQ__/g, '"') + msgDetails[2] + _details[1].replace(/__DBQ__/g, '"');
- }
- $('chat-tab-holder').childElements().each(function(elem) {
- var _thisId = $(elem).readAttribute('id').replace(/tab-/, '');
- var _name = $(elem).innerHTML.stripTags().strip().replace(/ /g, '');
- if (msgDetails[2] == _name) {
- $(elem).writeAttribute('id', 'tab-' + details[1]);
- $("storage_container_" + _thisId).writeAttribute('id', "storage_container_" + details[1]);
- $("storage_" + _thisId).writeAttribute('id', "storage_" + details[1]);
- if (ipb.chat.activeTab == _thisId) {
- ipb.chat.activeTab = details[1];
- }
- alsoTo = details[1];
- }
- });
- } else if (details[0] == 2) {
- var _action = ipb.lang['left_room'];
- if (_startLMI > 0) {
- ipb.chat.removeUserFromList(details[1], msgDetails[2]);
- }
- msgDetails[2] = ipb.chat.formatName(details[1], msgDetails[2]);
- if ($('storage_container_' + details[1])) {
- alsoTo = details[1];
- }
- }
- if (!ipb.chat.bypassFlag && ipb.chat.hideEnterExit) {
- continue;
- }
- var _photo = ipb.chat.nameFormatting.get(details[1]) ? ipb.chat.nameFormatting.get(details[1])[3] : '<!--uid' + details[1] + '-->';
- listItemVal = ipb.chat.templates['msg-2'].evaluate({
- date: _itemDate,
- username: msgDetails[2],
- photo: _photo,
- action: _action
- });
- ipb.chat.lastUser.set(_thisRowId, 0);
- } else if (msgDetails[1] == 3) {
- msgDetails[2] = ipb.chat.formatName(msgDetails[5], msgDetails[2]);
- listItemVal = ipb.chat.templates['msg-3'].evaluate({
- username: msgDetails[2],
- photo: ipb.chat.nameFormatting.get(msgDetails[5])[3],
- message: msgDetails[3]
- });
- _updatedCount++;
- ipb.chat.unreadCount++;
- if (_thisRowId != ipb.chat.activeTab) {
- if (ipb.chat.unreadTabs.get(_thisRowId)) {
- ipb.chat.unreadTabs.set(_thisRowId, parseInt(ipb.chat.unreadTabs.get(_thisRowId)) + 1);
- } else {
- ipb.chat.unreadTabs.set(_thisRowId, 1);
- }
- }
- ipb.chat.lastUser.set(_thisRowId, 0);
- } else if (msgDetails[1] == 4) {
- listItemVal = ipb.chat.templates['msg-4'].evaluate({
- message: msgDetails[3]
- });
- $$('.storage-container').each(function(elem) {
- var _id = $(elem).id.replace(/storage_/, '');
- if (_id != 'chatroom') {
- var _ulList = ipb.chat.getStorageContainer(_id);
- _ulList.insert({
- bottom: ipb.chat.templates['msg-K'].evaluate()
- });
- $(elem).update(_ulList);
- }
- });
- $('messages-display').update(ipb.chat.getStorageContainer(ipb.chat.activeTab)).addClassName('messages-list');
- _updatedCount++;
- ipb.chat.unreadCount++;
- if (_thisRowId != ipb.chat.activeTab) {
- if (ipb.chat.unreadTabs.get(_thisRowId)) {
- ipb.chat.unreadTabs.set(_thisRowId, parseInt(ipb.chat.unreadTabs.get(_thisRowId)) + 1);
- } else {
- ipb.chat.unreadTabs.set(_thisRowId, 1);
- }
- }
- ipb.chat.lastUser.set(_thisRowId, 0);
- } else if (msgDetails[1] == 5) {
- ipb.chat.removeUserFromList(msgDetails[4], msgDetails[3]);
- msgDetails[2] = ipb.chat.formatName(msgDetails[5], msgDetails[2]);
- msgDetails[3] = ipb.chat.formatName(msgDetails[4], msgDetails[3]);
- listItemVal = ipb.chat.templates['msg-5'].evaluate({
- username: msgDetails[2],
- date: _itemDate,
- extra: msgDetails[3]
- });
- ipb.chat.lastUser.set(_thisRowId, 0);
- }
- ulList.insert({
- bottom: listItemVal
- });
- if (ipb.chat.maxMessages > 0) {
- if (ulList.childElements().length > ipb.chat.maxMessages) {
- var _toRemove = ulList.childElements().length - ipb.chat.maxMessages;
- for (var tr = 0; tr < _toRemove; tr++) {
- ulList.firstDescendant().remove();
- }
- }
- }
- if (ipb.chat.activeTab != _thisRowId) {
- $('storage_container_' + _thisRowId).update(ulList);
- } else {
- $('messages-display').update(ulList).addClassName('messages-list');
- }
- if (alsoTo) {
- var otherUlList = ipb.chat.getStorageContainer(alsoTo);
- otherUlList.insert({
- bottom: listItemVal
- });
- if (ipb.chat.activeTab != alsoTo) {
- $('storage_container_' + alsoTo).update(otherUlList);
- } else {
- $('messages-display').update(otherUlList).addClassName('messages-list');
- }
- }
- if (!ipb.chat.bypassFlag) {
- ipb.chat.lastTime = _itemDate;
- }
- }
- }
- if (!ipb.chat.windowHasFocus && ipb.chat.unreadCount > 0) {
- if (document.title.match(/\(\d+\) (.+?)/gi)) {
- document.title = document.title.replace(/\(\d+\) (.+?)/gi, "(" + ipb.chat.unreadCount + ") $1");
- } else {
- document.title = "(" + ipb.chat.unreadCount + ") " + document.title;
- }
- }
- ipb.chat.updateTabUnreadCount();
- if (_updatedCount) {
- ipb.chat.triggerMessageSound();
- }
- if (_initialEmpty) {
- ipb.chat.bypassFlag = false;
- }
- if (ipb.chat.getStorageContainer('chatroom').empty()) {
- var _whateverItWas = ipb.chat.bypassFlag;
- ipb.chat.bypassFlag = true;
- ipb.chat.updateMessages("1," + ipb.chat.lastMsgId + "~~||~~" + Math.round(new Date().getTime() / 1000) + ",2," + userName.replace(',', '~~#~~') + ",,1_" + userId + "," + userId + "~~||~~");
- ipb.chat.bypassFlag = _whateverItWas;
- }
- if (scrollBottom) {
- Debug.write("Scrolling down to: " + $('messages-display').scrollHeight);
- $('messages-display').scrollTop = $('messages-display').scrollHeight + 500;
- }
- return true;
- },
- checkInactivity: function(timestamp) {
- if (!timestamp || !ipb.chat.inactiveKick) {
- return;
- }
- var _inactiveSeconds = ipb.chat.inactiveKick * 60;
- if (timestamp - ipb.chat.lastAction > _inactiveSeconds) {
- var _whateverItWas = ipb.chat.bypassFlag;
- ipb.chat.bypassFlag = true;
- ipb.chat.updateMessages("0," + ipb.chat.lastMsgId + "~~||~~" + Math.round(new Date().getTime() / 1000) + ",5," + userName.replace(',', '~~#~~') + ",,1_" + userId + "," + userId + "~~||~~");
- ipb.chat.bypassFlag = _whateverItWas;
- ipb.chat.kicked = true;
- }
- return;
- },
- updateTabUnreadCount: function() {
- ipb.chat.unreadTabs.set(ipb.chat.activeTab, 0);
- ipb.chat.unreadTabs.each(function(pair) {
- if (pair.key == ipb.chat.activeTab) {
- var _thisHtml = $('tab-' + pair.key).innerHTML;
- if (_thisHtml.match(/(.+?) \(\d+\)\<\/a\>/gi)) {
- _thisHtml = _thisHtml.replace(/(.+?) \(\d+\)\<\/a\>/gi, "$1</a>");
- }
- $('tab-' + pair.key).update(_thisHtml);
- return;
- }
- if (!$('tab-' + pair.key) || !pair.value) {
- return;
- }
- var _thisHtml = $('tab-' + pair.key).innerHTML;
- if (_thisHtml.match(/(.+?) \(\d+\)\<\/a\>/gi)) {
- _thisHtml = _thisHtml.replace(/(.+?) \(\d+\)\<\/a\>/gi, "$1 (" + pair.value + ")</a>");
- } else {
- _thisHtml = _thisHtml.replace(/\<\/a\>/i, '') + " (" + pair.value + ")</a>";
- }
- $('tab-' + pair.key).update(_thisHtml);
- });
- $$('#chat-tab-holder a').each(function(elem) {
- id = elem.identify();
- if ($(id)) {
- $(id).stopObserving('click');
- $(id).observe("click", ipb.chat.switchTab);
- }
- });
- },
- getStorageContainer: function(tab) {
- if (!$('storage_' + tab)) {
- return new Element('ul', {
- id: 'storage_' + tab
- });
- } else {
- return new Element('ul', {
- id: 'storage_' + tab
- }).update($('storage_' + tab).innerHTML);
- }
- },
- addUserToList: function(user_id, username, forum_user_id) {
- if (!$('user_' + user_id) && !$('link_' + forum_user_id)) {
- var htmlFragment = new Element('li', {
- id: 'user_' + user_id
- });
- new Ajax.Request(ipb.vars['base_url'] + "&app=ipchat&module=ajax§ion=adduser&md5check=" + ipb.vars['secure_hash'] + "&id=" + forum_user_id + "&user=" + user_id + '&_nocache=' + new Date().getTime(), {
- method: 'get',
- onSuccess: function(t) {
- if (Object.isUndefined(t.responseJSON)) {
- Debug.error("Invalid response returned from the server");
- return;
- }
- htmlFragment.update(t.responseJSON['html']);
- ipb.chat.nameFormatting.set(user_id, [t.responseJSON['prefix'], t.responseJSON['suffix'], t.responseJSON['name'], "<img class='ipsUserPhoto ipsUserPhoto_mini' src='" + t.responseJSON['pp_small_photo'] + "' />"]);
- ipb.chat.forumIdMap.set(user_id, [forum_user_id, t.responseJSON['_canBeIgnored'], t.responseJSON['g_id']]);
- $('online-chat-count').innerHTML = parseInt($('online-chat-count').innerHTML) + 1;
- var modMenu = new Element('ul', {
- 'class': 'kickmenu',
- id: 'mod_link_' + user_id + '_menucontent'
- });
- if (isMobile) {
- if (user_id != userId) {
- if (ipb.chat.moderator) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'kick_user_' + user_id,
- 'class': 'kick_user',
- href: '#',
- title: ipb.lang['chat_kick_user']
- });
- modMenu = modMenu.update(modML.update(modLink.update(ipb.lang['chat_kick_user'])));
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'ban_user_' + user_id + '_' + forum_user_id,
- 'class': 'ban_user',
- href: '#',
- title: ipb.lang['chat_ban_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update(ipb.lang['chat_ban_user']))
- });
- }
- if (ipb.chat.private) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'priv_user_' + user_id + '_' + forum_user_id,
- 'class': 'priv_user',
- href: '#',
- title: ipb.lang['chat_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update(ipb.lang['chat_priv_user']))
- });
- }
- if (ipb.chat.ignoreChats.get(forum_user_id ? forum_user_id : 'g_' + user_id)) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'unblock_user_' + user_id + '_' + forum_user_id,
- 'class': 'block_user',
- href: '#',
- title: ipb.lang['unblock_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update(ipb.lang['unblock_priv_user']))
- });
- } else {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'block_user_' + user_id + '_' + forum_user_id,
- 'class': 'block_user',
- href: '#',
- title: ipb.lang['block_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update(ipb.lang['block_priv_user']))
- });
- }
- } else {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'leave_room',
- href: ipb.vars['base_url'] + "module=ipschat§ion=chat&do=leave&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&secure_key=" + ipb.vars['secure_hash'],
- title: ipb.lang['leave_room']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update(ipb.lang['leave_room']))
- });
- }
- } else {
- if (user_id != userId) {
- if (ipb.chat.moderator) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'kick_user_' + user_id,
- 'class': 'kick_user',
- href: '#',
- title: ipb.lang['chat_kick_user']
- });
- modMenu = modMenu.update(modML.update(modLink.update("<img src='" + ipb.vars['img_url'] + "/user_delete.png' /> " + ipb.lang['chat_kick_user'])));
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'ban_user_' + user_id + '_' + forum_user_id,
- 'class': 'ban_user',
- href: '#',
- title: ipb.lang['chat_ban_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update("<img src='" + ipb.vars['img_url'] + "/user_delete.png' /> " + ipb.lang['chat_ban_user']))
- });
- }
- if (ipb.chat.private) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'priv_user_' + user_id + '_' + forum_user_id,
- 'class': 'priv_user',
- href: '#',
- title: ipb.lang['chat_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update("<img src='" + ipb.vars['img_url'] + "/user_comment.png' /> " + ipb.lang['chat_priv_user']))
- });
- }
- if (ipb.chat.ignoreChats.get(forum_user_id ? forum_user_id : 'g_' + user_id)) {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'unblock_user_' + user_id + '_' + forum_user_id,
- 'class': 'block_user',
- href: '#',
- title: ipb.lang['unblock_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update("<img src='" + ipb.vars['img_url'] + "/comments_ignore.png' /> " + ipb.lang['unblock_priv_user']))
- });
- } else {
- var modML = new Element('li');
- var modLink = new Element('a', {
- id: 'block_user_' + user_id + '_' + forum_user_id,
- 'class': 'block_user',
- href: '#',
- title: ipb.lang['block_priv_user']
- });
- modMenu = modMenu.insert({
- bottom: modML.update(modLink.update("<img src='" + ipb.vars['img_url'] + "/comments_ignore.png' /> " + ipb.lang['block_priv_user']))
- });
- }
- } else {
- var modML = new Element('li');
- modMenu = modMenu.update(modML.update('<em>' + ipb.lang['cant_kick_self'] + '</em>'));
- }
- $('mod-menu-container').insert({
- bottom: modMenu
- });
- }
- var _hasBeenInserted = false;
- $$('#chatters-online > li').each(function(elem) {
- if (!_hasBeenInserted) {
- if (ipb.chat.moderator) {
- var _name = $(elem).firstDescendant().next().innerHTML.stripTags().replace(/\<\!--.+?--\>/ig, "").strip();
- if (username.toLowerCase() < _name.toLowerCase()) {
- $(elem).insert({
- before: htmlFragment
- });
- _hasBeenInserted = true;
- }
- } else {
- var _name = $(elem).innerHTML.stripTags().replace(/\<\!--.+?--\>/ig, "").strip();
- if (username.toLowerCase() < _name.toLowerCase()) {
- $(elem).insert({
- before: htmlFragment
- });
- _hasBeenInserted = true;
- }
- }
- }
- });
- if (!_hasBeenInserted) {
- $('chatters-online').insert({
- bottom: htmlFragment
- });
- }
- if (isMobile) {
- $('user_' + user_id).insert({
- bottom: modMenu
- });
- }
- $('storage_chatroom').innerHTML = $('storage_chatroom').innerHTML.replace('<!--uid' + user_id + '-->', ipb.chat.nameFormatting.get(user_id)[3]);
- if (!isMobile) {
- new ipb.Menu($('mod_link_' + user_id), $('mod_link_' + user_id + '_menucontent'), {}, {
- afterOpen: ipb.chat.repositionModMenu
- });
- }
- ipb.chat.initKickLinks();
- ipb.chat.triggerEnterSound();
- if ($('chat-tab-count')) {
- var _curCount = parseInt($('chat-tab-count').innerHTML);
- var _newCount = _curCount + 1;
- $('chat-tab-count').update(_newCount);
- $('chat-tab-count').writeAttribute('title', ipb.chat.templates['count-title'].evaluate({
- count: _newCount
- }));
- }
- }
- });
- }
- },
- removeUserFromList: function(user_id, username) {
- if ($('user_' + user_id)) {
- $('user_' + user_id).remove();
- if ($('mod_link_' + user_id + '_menucontent')) {
- $('mod_link_' + user_id + '_menucontent').remove();
- }
- $('online-chat-count').innerHTML = parseInt($('online-chat-count').innerHTML) - 1;
- ipb.chat.triggerLeaveSound();
- if ($('chat-tab-count')) {
- var _curCount = parseInt($('chat-tab-count').innerHTML);
- var _newCount = _curCount - 1;
- $('chat-tab-count').update(_newCount);
- $('chat-tab-count').writeAttribute('title', ipb.chat.templates['count-title'].evaluate({
- count: _newCount
- }));
- }
- }
- },
- initKickLinks: function() {
- $$('.kick_user', '.ban_user', '.priv_user', '.block_user', '.unblock_user').each(function(elem) {
- $(elem).stopObserving('click');
- });
- $$('.kick_user').each(function(elem) {
- $(elem).observe('click', ipb.chat.kickUser);
- });
- $$('.ban_user').each(function(elem) {
- $(elem).observe('click', ipb.chat.banUser);
- });
- $$('.priv_user').each(function(elem) {
- $(elem).observe('click', ipb.chat.privateChat);
- });
- $$('.block_user').each(function(elem) {
- $(elem).observe('click', ipb.chat.blockPrivateChats);
- });
- $$('.unblock_user').each(function(elem) {
- $(elem).observe('click', ipb.chat.unblockPrivateChats);
- });
- },
- unblockPrivateChats: function(e) {
- Event.stop(e);
- var elem = Event.findElement(e, 'a');
- var elemId = elem.id.replace("block_user_", "");
- var elemP = elemId.split('_');
- ipb.menus.closeAll();
- if (elemId == userId) {
- alert(ipb.lang['cant_kick_self']);
- return false;
- } else {
- Debug.write("Unblocked the user with id " + elemId);
- }
- if (elemP[1]) {
- new Ajax.Request(ipb.vars['base_url'] + "app=ipchat&module=ajax§ion=block&md5check=" + ipb.vars['secure_hash'] + "&id=" + elemP[1] + "&block=0&_nocache=" + new Date().getTime(), {
- method: 'post'
- });
- } else {
- var cookie = ipb.Cookie.get('chat_ignored_guests');
- if (cookie) {
- var cookies = cookie.split(',');
- var newCookies = new Array();
- for (var abcdefg = 0; abcdefg < cookies.length; abcdefg++) {
- if (cookies[abcdefg] && cookies[abcdefg] != elemP[0]) {
- newCookies.push(cookies[abcdefg]);
- }
- }
- ipb.Cookie.set('chat_ignored_guests', newCookies.join(','));
- }
- }
- ipb.chat.ignoreChats.unset(elemP[1] ? elemP[1] : 'g_' + elemP[0]);
- $(elem).removeClassName('unblock_user').addClassName('block_user');
- $(elem).writeAttribute({
- title: ipb.lang['block_priv_user']
- });
- if (isMobile) {
- $(elem).update(ipb.lang['block_priv_user']);
- } else {
- $(elem).update("<img src='" + ipb.vars['img_url'] + "/comments_ignore.png' /> " + ipb.lang['block_priv_user']);
- }
- ipb.chat.initKickLinks();
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- blockPrivateChats: function(e) {
- Event.stop(e);
- var elem = Event.findElement(e, 'a');
- var elemId = elem.id.replace("block_user_", "");
- var elemP = elemId.split('_');
- var _forumUser = ipb.chat.forumIdMap.get(elemP[0]);
- if (!_forumUser[1]) {
- alert(ipb.lang['cant_block_user']);
- return false;
- }
- ipb.menus.closeAll();
- if (elemId == userId) {
- alert(ipb.lang['cant_kick_self']);
- return false;
- } else {
- Debug.write("Blocked the user with id " + elemId);
- }
- if (elemP[1]) {
- new Ajax.Request(ipb.vars['base_url'] + "app=ipchat&module=ajax§ion=block&md5check=" + ipb.vars['secure_hash'] + "&id=" + elemP[1] + "&block=1&_nocache=" + new Date().getTime(), {
- method: 'post'
- });
- } else {
- var cookie = ipb.Cookie.get('chat_ignored_guests');
- var newCookies = new Array();
- if (cookie) {
- var cookies = cookie.split(',');
- for (var abcdefg = 0; abcdefg < cookies.length; abcdefg++) {
- if (cookies[abcdefg] && cookies[abcdefg] != elemP[0]) {
- newCookies.push(cookies[abcdefg]);
- }
- }
- }
- newCookies.push(elemP[0]);
- ipb.Cookie.set('chat_ignored_guests', newCookies.join(','));
- }
- var _thisid = elemP[1] ? elemP[1] : 'g_' + elemP[0];
- ipb.chat.ignoreChats.set(_thisid, _thisid);
- $(elem).removeClassName('block_user').addClassName('unblock_user');
- $(elem).writeAttribute({
- title: ipb.lang['unblock_priv_user']
- });
- if (isMobile) {
- $(elem).update(ipb.lang['unblock_priv_user']);
- } else {
- $(elem).update("<img src='" + ipb.vars['img_url'] + "/comments_ignore.png' /> " + ipb.lang['unblock_priv_user']);
- }
- ipb.chat.initKickLinks();
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- privateChat: function(e) {
- Event.stop(e);
- var elem = Event.findElement(e, 'a');
- var elemId = elem.id.replace("priv_user_", "");
- var elemP = elemId.split('_');
- ipb.menus.closeAll();
- if (elemP[0] == userId) {
- alert(ipb.lang['cant_kick_self']);
- return false;
- }
- if (ipb.chat.ignoreChats.get(elemP[1] ? elemP[1] : 'g_' + elemP[0])) {
- alert(ipb.lang['noprivate_withignored']);
- return false;
- }
- if (ipb.chat.privateChats.get('privchatwindow_' + elemP[0])) {
- ipb.chat.privateChats.get('privchatwindow_' + elemP[0]).show();
- } else {
- if (isMobile) {
- ipb.chat.privateChats.set('privchatwindow_' + elemP[0], new ipb.Popup('privchatwindow_' + elemP[0], {
- type: 'modal',
- modal: true,
- initial: ipb.chat.templates['send_private'].evaluate({
- id: elemP[0]
- }),
- stem: false,
- hideAtStart: false,
- attach: {
- target: $('mod_link_' + elemP[0]),
- position: 'auto'
- },
- w: '320px'
- }));
- $('priv_' + elemP[0] + '_wrap').scrollTo();
- } else {
- ipb.chat.privateChats.set('privchatwindow_' + elemP[0], new ipb.Popup('privchatwindow_' + elemP[0], {
- type: 'balloon',
- modal: false,
- initial: ipb.chat.templates['send_private'].evaluate({
- id: elemP[0]
- }),
- stem: true,
- hideAtStart: false,
- attach: {
- target: $('mod_link_' + elemP[0]),
- position: 'auto'
- },
- w: '400px'
- }));
- }
- Event.observe('priv_chat_text_' + elemP[0], 'keypress', ipb.chat.checkForSendPrivateChat);
- new ipb.Menu($('mod_link_' + elemP[0]), $('mod_link_' + elemP[0] + '_menucontent'), {}, {
- afterOpen: ipb.chat.repositionModMenu
- });
- ipb.chat.initKickLinks();
- }
- return false;
- },
- banUser: function(e) {
- Event.stop(e);
- if (!confirm(ipb.lang['ban_user_confirm'])) {
- return false;
- }
- var elem = Event.findElement(e, 'a');
- var elemId = elem.id.replace("ban_user_", "");
- var elemP = elemId.split('_');
- ipb.menus.closeAll();
- if (elemId == userId) {
- alert(ipb.lang['cant_kick_self']);
- return false;
- } else {
- Debug.write("Banned the user with id " + elemId);
- }
- new Ajax.Request(ipb.vars['base_url'] + "app=ipchat&module=ajax§ion=ban&md5check=" + ipb.vars['secure_hash'] + "&id=" + elemP[1] + '&_nocache=' + new Date().getTime(), {
- method: 'post'
- });
- ipb.chat.sendMessageToChild("server=" + serverHost + "&path=" + serverPath + "&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&action=kick&against=" + elemP[0]);
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- kickUser: function(e) {
- Event.stop(e);
- var elem = Event.findElement(e, 'a');
- var elemId = elem.id.replace("kick_user_", "");
- ipb.menus.closeAll();
- if (elemId == userId) {
- alert(ipb.lang['cant_kick_self']);
- return false;
- } else {
- Debug.write("Kicked the user with id " + elemId);
- }
- ipb.chat.sendMessageToChild("server=" + serverHost + "&path=" + serverPath + "&room=" + roomId + "&user=" + userId + "&access_key=" + accessKey + "&action=kick&against=" + elemId);
- ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10));
- return false;
- },
- cleanMessage: function(message) {
- message = message.replace(/\r/g, '');
- message = message.replace(/\n/g, "__N__");
- message = message.replace(/,/g, "__C__");
- message = message.replace(/=/g, "__E__");
- message = message.replace(/\+/g, "__PS__");
- message = message.replace(/&/g, "__A__");
- message = message.replace(/%/g, "__P__");
- return message;
- },
- unCleanMessage: function(message) {
- message = message.replace(/__PS__/g, "+");
- message = message.replace(/__P__/g, "%");
- message = message.replace(/__A__/g, "&");
- message = message.replace(/__E__/g, "=");
- message = message.replace(/__C__/g, ",");
- message = message.replace(/__N__/g, "<br />");
- return message;
- },
- isValidUrl: function(url) {
- Debug.write("Checking url: " + url);
- var regexp = /^(https?|ftp|file):\/\/([^<>\"\s]+|[a-z0-9/\._\-!&\#;,%\+\?:=])/i;
- return regexp.test(url);
- },
- parseEmoticonsAndBbcode: function(text, chatUserId) {
- var urlReplacements = $H();
- var iteration = 0;
- while (text.match(/\[url\](.+?)\[\/url\]/gi)) {
- var matches = /\[url\](.+?)\[\/url\]/gi.exec(text);
- if (matches != null) {
- matches[1] = matches[1].replace(/"/g, '');
- if (ipb.chat.isValidUrl(matches[1])) {
- urlReplacements.set("__URL" + iteration + "__", "<a target='_blank' class='bbc' href='" + matches[1] + "'>" + matches[1] + "</a>");
- text = text.replace(matches[0], "__URL" + iteration + "__");
- iteration++;
- } else {
- text = text.replace(matches[0], matches[1]);
- }
- }
- }
- while (text.match(/\[url=(.+?)\](.+?)\[\/url\]/gi)) {
- var matches = /\[url=(.+?)\](.+?)\[\/url\]/gi.exec(text);
- if (matches != null) {
- matches[1] = matches[1].replace(/"/g, '').replace(/"/g, '');
- if (ipb.chat.isValidUrl(matches[1])) {
- urlReplacements.set("__URL" + iteration + "__", "<a target='_blank' class='bbc' href='" + matches[1].replace(/"/gi, '').replace(/"/gi, '') + "'>" + matches[2] + "</a>");
- text = text.replace(matches[0], "__URL" + iteration + "__");
- iteration++;
- } else {
- text = text.replace(matches[0], matches[1]);
- }
- }
- }
- var exp = /(\b(https?|ftp|file):\/\/([^<>\"\s]+|[a-z0-9/\._\-!&\#;,%\+\?:=]+))/ig;
- text = text.replace(exp, "<a target='_blank' class='bbc' href='$1'>$1</a>");
- urlReplacements.each(function(pair) {
- text = text.replace(pair.key, pair.value);
- });
- text = text.replace(/\[b\](.+?)\[\/b\]/gi, "<strong class='bbc'>$1</strong>");
- text = text.replace(/\[i\](.+?)\[\/i\]/gi, "<em class='bbc'>$1</em>");
- text = text.replace(/\[u\](.+?)\[\/u\]/gi, "<u class='bbc'>$1</u>");
- text = text.replace('!', '!');
- ipb.chat.emoticons.each(function(emoticon) {
- var _tmp = emoticon.value.split(',');
- var img = "$1<img src='" + ipb.vars['emoticon_url'] + '/' + _tmp[1] + "' class='bbc' />$2";
- var _regexp = new RegExp("(^|\\s)" + RegExp.escape(emoticon.key) + "(\\s|$)", "gi");
- while (text.match(_regexp)) {
- text = text.replace(_regexp, img);
- }
- });
- if (chatUserId) {
- var groupId = ipb.chat.forumIdMap.get(chatUserId);
- if (groupId) {
- groupId = groupId[2];
- }
- }
- var bypass = false;
- if (groupId) {
- var bypass = ipb.chat.groups.get(groupId)[2];
- }
- var badwordReplacements = $H();
- var iteration = 0;
- if (!bypass) {
- ipb.chat.badwords.each(function(badword) {
- if (!badword.value[1]) {
- badword.value[1] = '######';
- }
- if (badword.key == 'ass') {
- if (badword.value[0]) {
- var pattern = '(\\b|!|\\?|\\.|,|$)' + RegExp.escape(String.reverse(badword.key)) + '(?!lc)(^|\\b|\\s)';
- } else {
- var pattern = RegExp.escape(String.reverse(badword.key)) + '(?!lc)';
- }
- var _test = String.reverse(text);
- var _regexp = new RegExp(pattern, "gi");
- while (matches = _regexp.exec(_test)) {
- if (matches != null) {
- if (badword.value[0]) {
- badwordReplacements.set("__BW" + iteration + "__", String.reverse(matches[2]) + badword.value[1] + String.reverse(matches[1]));
- } else {
- badwordReplacements.set("__BW" + iteration + "__", badword.value[1]);
- }
- _test = _test.replace(matches[0], "__" + iteration + "WB__");
- iteration++;
- }
- }
- text = String.reverse(_test);
- return;
- }
- if (badword.value[0]) {
- var pattern = '(^|\\b|\\s)' + RegExp.escape(badword.key) + '(\\b|!|\\?|\\.|,|$)';
- } else {
- var pattern = RegExp.escape(badword.key);
- }
- var _regexp = new RegExp(pattern, "gi");
- while (matches = _regexp.exec(text)) {
- if (matches != null) {
- if (badword.value[0]) {
- badwordReplacements.set("__BW" + iteration + "__", matches[1] + badword.value[1] + matches[2]);
- } else {
- badwordReplacements.set("__BW" + iteration + "__", badword.value[1]);
- }
- text = text.replace(matches[0], "__BW" + iteration + "__");
- iteration++;
- }
- }
- });
- badwordReplacements.each(function(pair) {
- text = text.replace(pair.key, pair.value);
- });
- }
- return text;
- },
- formatName: function(_user_id, _user_name) {
- var _details = ipb.chat.nameFormatting.get(_user_id);
- if (_details) {
- return _details[0].replace(/__DBQ__/g, '"') + _user_name + _details[1].replace(/__DBQ__/g, '"');
- }
- return _user_name;
- },
- ping: function(pe) {
- if (ipb.chat.kicked) {
- pe.stop();
- return false;
- }
- new Ajax.Request(ipb.vars['base_url'] + "app=ipchat&module=ajax§ion=update&md5check=" + ipb.vars['secure_hash'] + '&_nocache=' + new Date().getTime(), {
- method: 'get'
- });
- },
- manualDecode: function(string) {
- string = string.replace(/\%([a-zA-Z0-9]{2})/gi, function(hex) {
- return String.fromCharCode(parseInt(hex.replace('%', ''), 16));
- });
- return string;
- },
- repositionModMenu: function(menu) {
- var _top = $(menu.target).getStyle('top').replace(/px/, '');
- var _cont = $('chatters-online-wrap').scrollTop;
- Debug.write("Online chatters current top pos: " + _top);
- Debug.write("Online chatters scroll offset: " + _cont);
- Debug.write("New top pos: " + (_top - _cont));
- $(menu.target).setStyle('top:' + (_top - _cont) + 'px;');
- }
- };
- ipb.chat.init();
- function convertToPixels(_str, _context) {
- if (/px$/.test(_str)) {
- return parseInt(_str);
- }
- var tmp = document.createElement('div');
- tmp.style.visbility = 'hidden';
- tmp.style.position = 'absolute';
- tmp.style.lineHeight = '0';
- if (/%$/.test(_str)) {
- _context = _context.parentNode || _context;
- tmp.style.height = _str;
- } else {
- tmp.style.borderStyle = 'solid';
- tmp.style.borderBottomWidth = '0';
- tmp.style.borderTopWidth = _str;
- }
- if (!_context) {
- _context = document.body;
- }
- _context.appendChild(tmp);
- var px = tmp.offsetHeight;
- _context.removeChild(tmp);
- return px + 'px';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement